:root {
    --bg: #f5f5f0;
    --surface: #ffffff;
    --surface-alt: #ecebe5;
    --text: #2c2c2a;
    --text-muted: #5f5e5a;
    --border: rgba(0, 0, 0, 0.12);
    --border-strong: rgba(0, 0, 0, 0.2);
    --primary: #185fa5;
    --primary-hover: #0c447c;
    --error-bg: #fcebeb;
    --error-text: #791f1f;
    --success-bg: #e4f1e2;
    --success-text: #1f6420;
    --warn-bg: #fdf0da;
    --warn-text: #7d4d15;
    --danger: #c23a3a;
    --danger-hover: #9a2a2a;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1a1a19;
        --surface: #2c2c2a;
        --surface-alt: #242422;
        --text: #e5e4df;
        --text-muted: #b4b2a9;
        --border: rgba(255, 255, 255, 0.12);
        --border-strong: rgba(255, 255, 255, 0.25);
        --primary: #378add;
        --primary-hover: #85b7eb;
        --error-bg: #501313;
        --error-text: #f7c1c1;
        --success-bg: #1d3b1d;
        --success-text: #c1e8c1;
        --warn-bg: #4a3611;
        --warn-text: #f4d79b;
        --danger: #e05b5b;
        --danger-hover: #ef8a8a;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

h1 { font-size: 22px; font-weight: 500; margin: 0 0 8px; }
h2 { font-size: 18px; font-weight: 500; margin: 0 0 12px; }
h3 { font-size: 16px; font-weight: 500; margin: 0 0 10px; }

.subtitle {
    color: var(--text-muted);
    margin: 0 0 20px;
    font-size: 14px;
}

.muted { color: var(--text-muted); }

code {
    font-family: ui-monospace, "SF Mono", Consolas, monospace;
    font-size: 13px;
    background: var(--surface-alt);
    padding: 1px 6px;
    border-radius: 4px;
}

.code-block {
    display: block;
    background: var(--surface-alt);
    padding: 10px 12px;
    border-radius: 6px;
    font-family: ui-monospace, "SF Mono", Consolas, monospace;
    font-size: 13px;
    word-break: break-all;
    border: 1px solid var(--border);
}

/* ============ Auth pages ============ */

.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.auth-card form { display: flex; flex-direction: column; }

/* ============ Forms ============ */

label {
    font-size: 14px;
    font-weight: 500;
    margin-top: 14px;
    margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"] {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
}

input:focus {
    border-color: var(--primary);
}

input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.form-grid {
    display: flex;
    flex-direction: column;
}

.form-hint {
    color: var(--text-muted);
    font-size: 13px;
    margin: 4px 0 0;
}

.form-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

button, .button {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
    text-decoration: none;
    display: inline-block;
}

button:hover, .button:hover {
    background: var(--primary-hover);
    text-decoration: none;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button.btn-danger, .button.btn-danger {
    background: var(--danger);
}
button.btn-danger:hover { background: var(--danger-hover); }

/* Auth forms use bigger button */
.auth-card button {
    margin-top: 24px;
    padding: 12px;
    font-size: 15px;
}

/* ============ Alerts ============ */

.alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}
.alert-error   { background: var(--error-bg);   color: var(--error-text);   }
.alert-ok      { background: var(--success-bg); color: var(--success-text); }
.alert-warn    { background: var(--warn-bg);    color: var(--warn-text);    }

/* ============ Topbar ============ */

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.brand {
    font-weight: 500;
    font-size: 16px;
    color: var(--text);
}
.brand:hover { text-decoration: none; }

.topbar nav {
    display: flex;
    gap: 16px;
    align-items: center;
    font-size: 14px;
}

.topbar nav a.active {
    color: var(--text);
    font-weight: 500;
}

/* ============ Container ============ */

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 24px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-top: 20px;
    box-shadow: var(--shadow);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ Tabs ============ */

.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-top: 20px;
    flex-wrap: wrap;
}

.tab {
    padding: 10px 16px;
    font-size: 14px;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.15s;
}

.tab:hover {
    color: var(--text);
    text-decoration: none;
}

.tab-active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 500;
}

.tab-content {
    min-height: 200px;
}

/* ============ Badges ============ */

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}
.badge-ok   { background: var(--success-bg); color: var(--success-text); }
.badge-warn { background: var(--warn-bg);    color: var(--warn-text); }
.badge-todo { background: var(--surface-alt); color: var(--text-muted); }

/* ============ Integrations ============ */

.integration-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.integration-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    background: var(--surface-alt);
    border-radius: 8px;
}

.integration-name {
    font-weight: 500;
    min-width: 180px;
}

.mini-link {
    margin-left: auto;
    font-size: 13px;
    color: var(--text-muted);
}

.status-line { font-size: 14px; }
.status-ok { color: var(--success-text); }

/* ============ QR & misc ============ */

.qr-wrapper {
    text-align: center;
    margin: 20px 0;
    padding: 16px;
    background: white;
    border-radius: var(--radius);
}

.qr {
    max-width: 200px;
    width: 100%;
    height: auto;
}

.secret-details {
    margin-bottom: 16px;
    font-size: 14px;
}

.secret-details summary {
    cursor: pointer;
    color: var(--text-muted);
    padding: 6px 0;
}

.secret-code {
    display: block;
    background: var(--bg);
    padding: 10px 12px;
    border-radius: 6px;
    font-family: ui-monospace, "SF Mono", Consolas, monospace;
    font-size: 13px;
    word-break: break-all;
    margin-top: 6px;
}

.phase-list {
    margin: 12px 0 0;
    padding-left: 20px;
    color: var(--text-muted);
}
.phase-list li { margin-bottom: 6px; }
