/* ============================================================================
   Onboarding Admin design system
   Tokens first, then layout, then components. Light and dark are driven by the
   data-theme attribute on <html>, which the server renders from the ob_theme
   cookie. "system" defers to the OS setting.
   ========================================================================= */

/* ---- Tokens -------------------------------------------------------------- */

:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #fafbfd;
    --surface-3: #f1f3f9;
    --border: #e5e8ef;
    --border-strong: #d2d7e3;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-subtle: #94a3b8;

    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-soft: #eef2ff;
    --accent-contrast: #ffffff;

    --success: #047857;
    --success-soft: #ecfdf5;
    --warning: #b45309;
    --warning-soft: #fffbeb;
    --danger: #b91c1c;
    --danger-soft: #fef2f2;
    --info: #0369a1;
    --info-soft: #f0f9ff;

    --shadow-sm: 0 1px 2px rgb(16 24 40 / .05);
    --shadow-md: 0 4px 12px -2px rgb(16 24 40 / .08), 0 2px 4px -2px rgb(16 24 40 / .04);
    --shadow-lg: 0 16px 40px -8px rgb(16 24 40 / .18), 0 4px 12px -4px rgb(16 24 40 / .08);

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;

    --sidebar-width: 268px;
    --topbar-height: 64px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
    --bg: #090d16;
    --surface: #111725;
    --surface-2: #161d2e;
    --surface-3: #1d2537;
    --border: #263048;
    --border-strong: #38445f;
    --text: #e8edf7;
    --text-muted: #94a3b8;
    --text-subtle: #64748b;

    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: #1e1b4b;
    --accent-contrast: #0b1020;

    --success: #34d399;
    --success-soft: #052e2b;
    --warning: #fbbf24;
    --warning-soft: #3a2a06;
    --danger: #f87171;
    --danger-soft: #3d1414;
    --info: #38bdf8;
    --info-soft: #082f42;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-md: 0 4px 12px -2px rgb(0 0 0 / .5);
    --shadow-lg: 0 16px 40px -8px rgb(0 0 0 / .65);
}

@media (prefers-color-scheme: dark) {
    :root[data-theme="system"] {
        --bg: #090d16;
        --surface: #111725;
        --surface-2: #161d2e;
        --surface-3: #1d2537;
        --border: #263048;
        --border-strong: #38445f;
        --text: #e8edf7;
        --text-muted: #94a3b8;
        --text-subtle: #64748b;

        --accent: #818cf8;
        --accent-hover: #a5b4fc;
        --accent-soft: #1e1b4b;
        --accent-contrast: #0b1020;

        --success: #34d399;
        --success-soft: #052e2b;
        --warning: #fbbf24;
        --warning-soft: #3a2a06;
        --danger: #f87171;
        --danger-soft: #3d1414;
        --info: #38bdf8;
        --info-soft: #082f42;

        --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
        --shadow-md: 0 4px 12px -2px rgb(0 0 0 / .5);
        --shadow-lg: 0 16px 40px -8px rgb(0 0 0 / .65);
    }
}

/* ---- Base ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

body { font-size: 14px; line-height: 1.55; }

h1, h2, h3, h4 { color: var(--text); margin: 0; line-height: 1.25; font-weight: 650; }
h1 { font-size: 26px; letter-spacing: -.02em; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1:focus { outline: none; }

.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.mono { font-family: var(--font-mono); font-size: 12px; }

.eyebrow {
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    margin: 0 0 6px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 8px;
    background: var(--surface);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    z-index: 100;
}
.skip-link:focus { left: 16px; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ---- Layout -------------------------------------------------------------- */

.page { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-height);
    flex: 0 0 var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-spacer { flex: 1; }

.content { flex: 1; min-width: 0; }

.admin-shell {
    display: grid;
    gap: 20px;
    padding: 24px;
    max-width: 1500px;
}

/* ---- Brand and navigation ------------------------------------------------ */

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 20px;
    height: var(--topbar-height);
    flex: 0 0 var(--topbar-height);
    border-bottom: 1px solid var(--border);
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 12px;
    letter-spacing: .04em;
    flex: 0 0 auto;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; font-weight: 700; }
.brand-text small { color: var(--text-subtle); font-size: 11px; }

.nav { padding: 14px 12px 24px; display: flex; flex-direction: column; gap: 2px; }

.nav-group-label {
    color: var(--text-subtle);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    padding: 16px 10px 6px;
    margin: 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 10px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-weight: 500;
    transition: background .12s ease, color .12s ease;
}

.nav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }

.nav-link.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.nav-icon { flex: 0 0 18px; height: 18px; display: grid; place-items: center; }
.nav-icon svg { width: 18px; height: 18px; }

.nav-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.nav-text small { color: var(--text-subtle); font-size: 11px; font-weight: 400; }
.nav-link.active .nav-text small { color: color-mix(in srgb, var(--accent) 70%, var(--text-subtle)); }

/* ---- Page headers -------------------------------------------------------- */

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.page-sub { color: var(--text-muted); margin-top: 4px; max-width: 68ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Buttons ------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s ease, border-color .12s ease, color .12s ease, opacity .12s ease;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }

.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(1.08); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-icon { width: 20px; height: 20px; }
.btn svg { width: 15px; height: 15px; flex: 0 0 15px; }

/* ---- Toolbar ------------------------------------------------------------- */

.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: 0;
    flex-wrap: wrap;
}

.toolbar-divider {
    width: 1px;
    height: 22px;
    background: var(--border);
    margin: 0 2px;
}

.toolbar-spacer { flex: 1; }

.toolbar-hint {
    color: var(--text-subtle);
    font-size: 12px;
    padding-left: 4px;
}

/* ---- Cards --------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}

.card > h2 { margin-bottom: 4px; }
.card > h2 + .muted { margin-bottom: 14px; }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.card-head h2 { margin: 0; }

/* ---- Metrics ------------------------------------------------------------- */

.metrics {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.metric {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
}

.metric span { color: var(--text-muted); font-size: 12.5px; font-weight: 500; display: block; }
.metric strong { display: block; font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; }
.metric small { color: var(--text-subtle); font-size: 11.5px; }

/* ---- Tables and grids ---------------------------------------------------- */

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
}

.toolbar + .table-wrap { border-radius: 0 0 var(--radius) var(--radius); }

table { border-collapse: collapse; width: 100%; font-size: 13px; }

thead th {
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .1s ease; }
tbody tr:hover { background: var(--surface-2); }

td small { color: var(--text-subtle); display: block; font-size: 11.5px; }
td strong { font-weight: 600; }

/* Row selection for the grid-first screens */
.grid-row { cursor: pointer; }
.grid-row.selected { background: var(--accent-soft); }
.grid-row.selected:hover { background: var(--accent-soft); }
.grid-row.selected td { border-color: color-mix(in srgb, var(--accent) 25%, var(--border)); }

.row-radio { accent-color: var(--accent); cursor: pointer; }

.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.col-narrow { width: 1%; white-space: nowrap; }
.text-right { text-align: right; }

/* ---- Loading states ------------------------------------------------------ */

.loader-card {
    display: grid;
    place-items: center;
    gap: 12px;
    padding: 48px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.loader-card p { color: var(--text-muted); font-size: 13px; }

.spinner {
    width: 26px;
    height: 26px;
    border: 2.5px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.skeleton-table { width: 100%; }
.skeleton-table td { padding: 14px; border-bottom: 1px solid var(--border); }
.skeleton-table tr:last-child td { border-bottom: 0; }

.skeleton-bar {
    display: block;
    height: 11px;
    border-radius: 999px;
    background: linear-gradient(90deg,
        var(--surface-3) 25%,
        color-mix(in srgb, var(--surface-3) 55%, var(--border-strong)) 37%,
        var(--surface-3) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

.loader-caption {
    color: var(--text-subtle);
    font-size: 12px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    margin: 0;
}

.inline-spinner {
    width: 13px;
    height: 13px;
    border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
    border-top-color: currentColor;
    border-radius: 50%;
    display: inline-block;
    animation: spin .7s linear infinite;
    vertical-align: -2px;
}

@media (prefers-reduced-motion: reduce) {
    .spinner, .inline-spinner, .skeleton-bar, .json-live::before { animation: none; }
}

/* ---- Column filters ------------------------------------------------------ */

.filter-row td {
    padding: 6px 8px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.col-filter {
    width: 100%;
    padding: 5px 8px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
}

.col-filter:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent);
}

.col-filter::placeholder { color: var(--text-subtle); font-size: 11.5px; }

.filter-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--accent-soft);
    color: var(--accent);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
}

.filter-summary button {
    margin-left: auto;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
    padding: 2px 4px;
}

/* ---- Chips and status ---------------------------------------------------- */

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    background: var(--surface-3);
    color: var(--text-muted);
    white-space: nowrap;
}

.chip-role { background: var(--accent-soft); color: var(--accent); text-transform: capitalize; }
.chip-success { background: var(--success-soft); color: var(--success); }
.chip-warning { background: var(--warning-soft); color: var(--warning); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }
.chip-info { background: var(--info-soft); color: var(--info); }
.chip-muted { background: var(--surface-3); color: var(--text-subtle); }
.chip-current { background: var(--surface-3); color: var(--text-muted); }

.chip-removable { padding-right: 4px; }
.chip-remove {
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font: inherit;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 999px;
    opacity: .65;
}
.chip-remove:hover { opacity: 1; background: rgb(0 0 0 / .08); }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.role-chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }

/* Version and workflow status */
.status { display: inline-flex; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.status-draft { background: var(--surface-3); color: var(--text-muted); }
.status-pendingapproval { background: var(--warning-soft); color: var(--warning); }
.status-approved { background: var(--info-soft); color: var(--info); }
.status-published { background: var(--success-soft); color: var(--success); }
/* Superseded, not failed: muted rather than red, and visibly distinct from Draft. */
.status-outdated { background: var(--surface-3); color: var(--text-subtle); text-decoration: line-through; }
.status-retired { background: var(--danger-soft); color: var(--danger); }

/* ---- Forms --------------------------------------------------------------- */

.form-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.form-grid .wide { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }

.field > label, .form-grid label > span:first-child {
    color: var(--text);
    font-size: 12.5px;
    font-weight: 600;
}

.field-hint { color: var(--text-subtle); font-size: 11.5px; }
.field-error, .validation-message { color: var(--danger); font-size: 12px; }

.input, input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="url"], select, textarea {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    transition: border-color .12s ease, box-shadow .12s ease;
}

.input:focus, input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

input::placeholder, textarea::placeholder { color: var(--text-subtle); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-3); color: var(--text-subtle); cursor: not-allowed; }
input[readonly] { background: var(--surface-3); color: var(--text-muted); }

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%2364748b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='m2.5 4.5 3.5 3.5 3.5-3.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    background-size: 12px;
    padding-right: 30px;
}

textarea { min-height: 92px; resize: vertical; }
textarea.code { font-family: var(--font-mono); font-size: 12px; line-height: 1.6; }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.checkbox-row input { width: auto; accent-color: var(--accent); }

.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
}
.switch-row:last-child { border-bottom: 0; }

.rtl-input {
    direction: rtl;
    font-family: Tahoma, "Segoe UI", Arial, sans-serif;
    line-height: 1.8;
    text-align: right;
    unicode-bidi: plaintext;
}

.valid.modified:not([type=checkbox]) { border-color: var(--success); }
.invalid { border-color: var(--danger); }

/* ---- Alerts -------------------------------------------------------------- */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    border: 1px solid transparent;
}

.alert-icon {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: 800;
    background: currentColor;
    margin-top: 1px;
}
.alert-icon::first-letter { color: var(--surface); }

.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.alert-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }

.alert span:last-child { color: var(--text); }

/* ---- Avatar and user menu ------------------------------------------------ */

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 700;
    flex: 0 0 auto;
    letter-spacing: .02em;
}

.avatar-lg { width: 42px; height: 42px; font-size: 15px; }
.avatar-xl { width: 72px; height: 72px; font-size: 26px; }

.user-menu { position: relative; }

.avatar-button {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 5px 9px 5px 5px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    transition: background .12s ease, border-color .12s ease;
}
.avatar-button:hover { background: var(--surface-3); border-color: var(--border); }

.avatar-name { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25; }
.avatar-name strong { font-size: 13px; font-weight: 600; }
.avatar-name small { color: var(--text-subtle); font-size: 11px; }

.chevron {
    width: 8px;
    height: 8px;
    border-right: 1.8px solid var(--text-subtle);
    border-bottom: 1.8px solid var(--text-subtle);
    transform: rotate(45deg) translate(-2px, -2px);
    transition: transform .15s ease;
}
.chevron.up { transform: rotate(-135deg) translate(-2px, -2px); }

.menu-backdrop { position: fixed; inset: 0; z-index: 40; }

.menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 288px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 50;
    animation: menu-in .12s ease-out;
}

@keyframes menu-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.menu-identity { display: flex; gap: 11px; padding: 10px; align-items: flex-start; }
.menu-identity strong { display: block; font-size: 13.5px; }
.menu-identity small { color: var(--text-subtle); font-size: 11.5px; word-break: break-all; }
.menu-identity .role-chips { margin-bottom: 0; }

.menu-divider { height: 1px; background: var(--border); margin: 5px 2px; }

.menu-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
}
.menu-item:hover { background: var(--surface-3); text-decoration: none; }
.menu-item-danger { color: var(--danger); }
.menu-item-danger:hover { background: var(--danger-soft); }
.menu-icon { width: 16px; text-align: center; opacity: .8; }
.menu-form { margin: 0; }

.menu-section { padding: 6px 10px 10px; }
.menu-section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.menu-label { color: var(--text-subtle); font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }

.theme-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }

.theme-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 9px 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-muted);
    font: inherit;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.theme-option:hover { border-color: var(--border-strong); color: var(--text); }
.theme-option.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.theme-swatch { width: 100%; height: 20px; border-radius: 4px; border: 1px solid var(--border-strong); }
.theme-swatch.light { background: linear-gradient(135deg, #ffffff 50%, #e5e8ef 50%); }
.theme-swatch.dark { background: linear-gradient(135deg, #111725 50%, #263048 50%); }
.theme-swatch.system { background: linear-gradient(135deg, #ffffff 50%, #111725 50%); }

/* ---- Auth page ----------------------------------------------------------- */

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(1000px 600px at 15% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
        radial-gradient(800px 500px at 90% 110%, color-mix(in srgb, #8b5cf6 14%, transparent), transparent 70%),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 408px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 30px;
}

.auth-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 24px; }
.auth-brand h1 { font-size: 20px; }
.auth-brand p { color: var(--text-muted); font-size: 12.5px; margin-top: 3px; }

.auth-logo {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 15px;
    flex: 0 0 auto;
}

.auth-form { display: flex; flex-direction: column; gap: 15px; margin-top: 18px; }
.auth-form .btn { margin-top: 4px; padding: 10px; }
.auth-card .alert { margin-top: 4px; }

/* ---- Break-glass banner -------------------------------------------------- */

.backdoor-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 24px;
    background: var(--warning-soft);
    color: var(--warning);
    border-bottom: 1px solid color-mix(in srgb, var(--warning) 30%, transparent);
    font-size: 12.5px;
    font-weight: 500;
}

.backdoor-banner a {
    margin-left: auto;
    color: inherit;
    font-weight: 700;
    text-decoration: underline;
    white-space: nowrap;
}

/* ---- Empty states -------------------------------------------------------- */

.empty-state {
    display: grid;
    place-items: center;
    gap: 10px;
    text-align: center;
    padding: 56px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.empty-state p { color: var(--text-muted); max-width: 52ch; }
.empty-state .btn { margin-top: 6px; }
.empty-icon { font-size: 30px; opacity: .5; }

.empty-row { text-align: center; color: var(--text-muted); padding: 36px 16px !important; }

/* ---- Detail lists -------------------------------------------------------- */

.detail-list { display: grid; gap: 12px; margin: 0; }
.detail-list > div { display: grid; gap: 2px; }
.detail-list dt { color: var(--text-subtle); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.detail-list dd { margin: 0; font-size: 13.5px; }

/* ---- Profile ------------------------------------------------------------- */

.profile-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); align-items: start; }

.profile-identity { display: grid; justify-items: center; text-align: center; gap: 8px; padding: 28px 18px; }
.profile-identity h2 { font-size: 19px; }

.permission-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.permission-list li { display: flex; align-items: flex-start; gap: 10px; padding: 9px 11px; border-radius: var(--radius-sm); background: var(--surface-2); }
.permission-list strong { display: block; font-size: 13px; }
.permission-list small { color: var(--text-subtle); font-size: 11.5px; }
.permission-list .permission-mark { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; font-weight: 800; flex: 0 0 18px; margin-top: 2px; }
.permission-list .granted .permission-mark { background: var(--success-soft); color: var(--success); }
.permission-list .denied { opacity: .6; }
.permission-list .denied .permission-mark { background: var(--surface-3); color: var(--text-subtle); }

/* ---- Permission matrix --------------------------------------------------- */

.matrix-cell { text-align: center; }
.matrix-cell input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }
.matrix-cell input:disabled { cursor: not-allowed; }

/* ---- Modal --------------------------------------------------------------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgb(9 13 22 / .55);
    backdrop-filter: blur(2px);
    display: grid;
    place-items: center;
    padding: 24px;
    z-index: 60;
    animation: fade-in .12s ease-out;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: menu-in .14s ease-out;
}

.modal-wide { max-width: 760px; }

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-head h2 { font-size: 16px; }
.modal-head p { color: var(--text-muted); font-size: 12.5px; margin-top: 3px; }

.modal-close {
    border: 0;
    background: transparent;
    color: var(--text-subtle);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 7px;
    border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface-3); color: var(--text); }

.modal-body { padding: 20px; }

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    position: sticky;
    bottom: 0;
}

/* ---- Split panels -------------------------------------------------------- */

.split { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.stack { display: grid; gap: 16px; }

/* ---- JSON preview -------------------------------------------------------- */

.json-preview {
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.65;
    white-space: pre;
    overflow-x: auto;
    margin: 0;
    color: var(--text);
}

.json-live {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--success);
    font-size: 11px;
    font-weight: 600;
}
.json-live::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* ---- Steps list ---------------------------------------------------------- */

.step-order {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    display: inline-grid;
    place-items: center;
    font-size: 11.5px;
    font-weight: 700;
}

/* ---- Error UI ------------------------------------------------------------ */

#blazor-error-ui {
    background: var(--warning-soft);
    color: var(--warning);
    bottom: 0;
    display: none;
    left: 0;
    padding: 12px 18px;
    position: fixed;
    width: 100%;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    font-size: 13px;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 16px; top: 10px; }

.blazor-error-boundary { background: var(--danger); color: #fff; padding: 14px 18px; border-radius: var(--radius); }
.blazor-error-boundary::after { content: "An error has occurred."; }

/* ---- Responsive ---------------------------------------------------------- */

@media (max-width: 1100px) {
    .split { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
    .page { flex-direction: column; }

    .sidebar {
        width: 100%;
        flex: none;
        height: auto;
        position: static;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .nav { flex-direction: row; overflow-x: auto; padding: 10px; }
    .nav-group-label { display: none; }
    .nav-link { white-space: nowrap; }
    .nav-text small { display: none; }

    .admin-shell { padding: 16px; }
    .avatar-name { display: none; }
    .profile-grid { grid-template-columns: 1fr; }
}
