/* ------------ Theme tokens ------------ */
[data-theme="dark"] {
    --bg: #0f1117;
    --surface-1: #161b22;
    --surface-2: #21262d;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --text-ghost: #484f58;
    --main: #3b82f6;
    --ok: #00c98e;
    --err: #ef4444;
    --radius-sm: 6px;
}

[data-theme="light"] {
    --bg: #f6f8fa;
    --surface-1: #ffffff;
    --surface-2: #f0f2f5;
    --border: #d0d7de;
    --text: #1f2937;
    --text-muted: #57606a;
    --text-ghost: #8b949e;
    --main: #3b82f6;
    --ok: #16a34a;
    --err: #dc2626;
    --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
}

#app { height: 100%; }

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

code {
    font-family: 'Cascadia Code', Consolas, monospace;
    font-size: 12px;
    background: var(--surface-2);
    padding: 1px 5px;
    border-radius: 4px;
}

input, select, button {
    font: inherit;
}

input[type=text], input[type=email], input[type=password], input[type=number], select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text);
    width: 100%;
}

label {
    display: block;
    font-size: 11px;
    color: var(--text-ghost);
    margin: 10px 0 4px 0;
}

label.checkbox {
    display: inline-flex; align-items: center; gap: 6px;
    color: var(--text);
    font-size: 13px;
}

.btn-primary, .btn-secondary {
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: pointer;
}
.btn-primary {
    background: var(--main); color: #fff; border-color: var(--main);
}
.btn-primary:hover { background: color-mix(in srgb, var(--main), black 15%); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--surface-1); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }

.muted { color: var(--text-muted); }
.ok    { color: var(--ok); margin-top: 8px; font-size: 12px; }
.err   { color: var(--err); margin-top: 8px; font-size: 12px; }

.boot-loader {
    height: 100vh;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
}

/* ------------ App shell (post-setup) ------------ */
.app-shell { height: 100vh; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center;
    height: 48px;
    padding: 0 16px;
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.brand-mark {
    background: var(--main); color: #fff;
    width: 26px; height: 26px;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; border-radius: var(--radius-sm);
}
.brand-name { font-weight: 600; letter-spacing: 0.3px; }
.topbar-tabs { display: flex; gap: 4px; flex: 1; justify-content: center; }
.tab {
    padding: 6px 14px; border-radius: 999px;
    color: var(--text-muted); font-weight: 500;
}
.tab:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.topbar-right { min-width: 140px; display: flex; justify-content: flex-end; }
.user-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--surface-2); color: var(--text);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600;
}
.app-main { flex: 1; overflow: auto; padding: 24px; }

.placeholder-page h1 { margin: 0 0 8px; font-size: 20px; }
.not-found { color: var(--text-muted); padding: 24px; }

/* ------------ Setup wizard ------------ */
.setup-shell {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    background: radial-gradient(at 50% 0%, color-mix(in srgb, var(--main), transparent 92%), transparent 60%), var(--bg);
}
.setup-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 32px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.35);
}
.setup-brand {
    display: flex; flex-direction: column; align-items: center;
    gap: 6px; margin-bottom: 24px;
}
.setup-brand .brand-mark { width: 40px; height: 40px; font-size: 16px; }
.setup-brand h1 { margin: 4px 0 0; font-size: 22px; letter-spacing: 0.5px; }
.setup-subtitle { color: var(--text-muted); margin: 0; font-size: 12px; }

.setup-step-content h2 { margin: 0 0 4px; font-size: 17px; font-weight: 600; }
.setup-step-content > .muted { margin: 0 0 16px; font-size: 12px; }

.step-actions {
    display: flex; justify-content: space-between; gap: 8px;
    margin-top: 22px;
}
.step-actions .btn-primary { margin-left: auto; }

.step-dots {
    display: flex; justify-content: center; gap: 6px;
    margin-top: 24px;
}
.dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--surface-2); border: 1px solid var(--border);
}
.dot.on { background: var(--main); border-color: var(--main); }

.family-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 10px;
}
.family-head { display: flex; justify-content: space-between; align-items: center; }
.family-grid { margin-top: 8px; }

/* ------------ User menu ------------ */
.user-menu { position: relative; cursor: pointer; }
.user-dropdown {
    position: absolute; right: 0; top: calc(100% + 8px);
    background: var(--surface-1); border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    min-width: 220px; padding: 8px 0; z-index: 100;
}
.user-dropdown-name { padding: 4px 14px; font-weight: 600; color: var(--text); }
.user-dropdown-email { padding: 0 14px 6px; color: var(--text-muted); font-size: 11px; }
.user-dropdown hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.user-dropdown a {
    display: block; padding: 6px 14px; color: var(--text); font-size: 12px;
}
.user-dropdown a:hover { background: var(--surface-2); text-decoration: none; }
.user-dropdown-btn {
    width: 100%; text-align: left; padding: 6px 14px;
    background: transparent; border: 0; color: var(--text); font-size: 12px; cursor: pointer;
}
.user-dropdown-btn:hover { background: var(--surface-2); }

.sso-row { margin-top: 18px; display: flex; flex-direction: column; gap: 6px; }
.sso-link {
    display: block; padding: 8px 12px; text-align: center;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 12px; color: var(--text);
}
.sso-link:hover { background: color-mix(in srgb, var(--surface-2), var(--main) 10%); text-decoration: none; }

/* ------------ Common page layout ------------ */
.page-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}
.page-head h1 { margin: 0; font-size: 20px; }
.page-head .actions { display: flex; gap: 8px; }

.list-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.list-table th, .list-table td {
    text-align: left; padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}
.list-table th {
    background: var(--surface-2); color: var(--text-muted); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em; font-size: 11px;
}
.list-table tbody tr:hover { background: var(--surface-2); }
.list-table tr:last-child td { border-bottom: 0; }
.empty-state { color: var(--text-muted); padding: 24px; text-align: center; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-online { background: var(--ok); }
.status-offline { background: var(--text-ghost); }
.status-updating { background: #f59e0b; }
.status-error { background: var(--err); }

.badge {
    display: inline-block; padding: 1px 6px; border-radius: 999px;
    font-size: 10px; font-weight: 600; letter-spacing: 0.04em;
    background: color-mix(in srgb, var(--main), transparent 85%); color: var(--main);
}
.badge.green { background: color-mix(in srgb, var(--ok), transparent 85%); color: var(--ok); }
.badge.red { background: color-mix(in srgb, var(--err), transparent 85%); color: var(--err); }
.badge.amber { background: color-mix(in srgb, #f59e0b, transparent 85%); color: #f59e0b; }
.badge.muted { background: var(--surface-2); color: var(--text-muted); }

.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
}
.modal-card {
    background: var(--surface-1); border: 1px solid var(--border);
    border-radius: 8px; padding: 20px; width: 480px; max-width: 90vw;
    box-shadow: 0 16px 40px rgba(0,0,0,0.4);
}
.modal-card h3 { margin: 0 0 12px; font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.theme-toggle-fixed {
    position: fixed; top: 16px; right: 16px; z-index: 50;
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-1); color: var(--text);
    cursor: pointer;
    font-size: 16px;
    display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle-fixed:hover { background: var(--surface-2); }

/* ------------ Blazor error UI ------------ */
#blazor-error-ui {
    color: #1f2937;
    background: #fde68a;
    bottom: 0; left: 0;
    position: fixed; width: 100%;
    padding: 0.6rem 1rem;
    box-shadow: 0 -1px 4px rgba(0,0,0,0.3);
    display: none; z-index: 1000;
}
#blazor-error-ui .dismiss {
    cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem;
}
.blazor-error-boundary {
    background: #b32121; color: white; padding: 1rem;
}
.blazor-error-boundary::after { content: "An error has occurred."; }
