:root {
    --ink: #16202b;
    --ink-soft: #3b4856;
    --muted: #5c6b7a;
    --paper: #f3f5f7;
    --surface: #ffffff;
    --line: #d8dee5;
    --line-strong: #b9c3ce;
    --rail: #10324a;
    --rail-ink: #d6e2ec;
    --rail-muted: #8fa8bb;
    --rail-active: #1a4562;
    --accent: #0b7a75;
    --accent-strong: #08625e;
    --accent-wash: #e3f2f1;
    --danger: #b3261e;
    --danger-wash: #fbeceb;
    --warn: #8a5a00;
    --warn-wash: #fdf3dc;
    --ok: #1f7a3a;
    --ok-wash: #e6f4ea;
    --focus: #2f6fdd;
    --radius-sm: 4px;
    --radius: 8px;
    --font: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-display: "IBM Plex Sans Condensed", "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 16px; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--ink);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; color: var(--ink); }
h1 { font-family: var(--font-display); font-size: 1.75rem; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 1.0625rem; font-weight: 600; }
h3 { font-size: 0.9375rem; font-weight: 600; }
p { margin: 0 0 0.75rem; max-width: 72ch; }
a { color: var(--accent-strong); }
a:hover { color: var(--ink); }
code { font-family: var(--font-mono); font-size: 0.85em; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1:focus { outline: none; }

.visually-hidden {
    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: 1rem; top: -3rem; z-index: 10;
    background: var(--surface); padding: 0.5rem 0.75rem; border-radius: var(--radius-sm);
}
.skip-link:focus { top: 1rem; }

.shell { display: grid; grid-template-columns: 15.5rem 1fr; min-height: 100vh; }
.content { padding: 2rem 2.5rem 4rem; min-width: 0; }

.rail {
    background: var(--rail);
    color: var(--rail-ink);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding: 1.25rem 0.75rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.wordmark {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.375rem;
    letter-spacing: 0.01em;
    text-decoration: none;
    margin: 0;
}
.rail .wordmark { color: #fff; padding: 0.25rem 0.75rem 0.5rem; }
.rail .wordmark:hover { color: #fff; }

.rail-group { display: flex; flex-direction: column; gap: 0.125rem; }
.rail-heading { font-size: 0.8125rem; color: var(--rail-muted); margin: 0 0 0.25rem; padding: 0 0.75rem; }

.rail-link {
    display: block;
    color: var(--rail-ink);
    text-decoration: none;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    border-left: 3px solid transparent;
}
.rail-link:hover { background: var(--rail-active); color: #fff; }
.rail-link.active { background: var(--rail-active); color: #fff; border-left-color: #5fd3c9; }
.rail-sub { display: flex; flex-direction: column; margin-left: 0.75rem; }
.rail-link-sub { font-size: 0.875rem; padding-block: 0.3rem; }

.rail-foot { margin-top: auto; border-top: 1px solid rgba(214, 226, 236, 0.18); padding-top: 1rem; display: flex; flex-direction: column; gap: 0.125rem; }
.rail-user { padding: 0 0.75rem 0.25rem; color: #fff; font-weight: 500; margin: 0; }
.rail-button { width: 100%; text-align: left; background: none; font: inherit; cursor: pointer; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.5rem; margin-bottom: 1.5rem; }
.lede { color: var(--muted); }
.crumbs { margin: 0 0 0.5rem; font-size: 0.875rem; }
.crumbs a::before { content: "‹ "; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.875rem; }

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
}
.panel + .panel { margin-top: 1.25rem; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.split-wide { grid-template-columns: minmax(0, 2fr) minmax(16rem, 1fr); }
.split > .panel + .panel { margin-top: 0; }
.panel + .table-wrap, .panel + .empty, .panel + .muted { margin-top: 1.25rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack > .panel + .panel { margin-top: 0; }
.stack-sm { display: flex; flex-direction: column; gap: 0.5rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem 1rem; margin-bottom: 0.75rem; }
.form-divider { border-top: 1px solid var(--line); margin-top: 1.25rem; padding-top: 1rem; }

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field > span:first-child { font-size: 0.875rem; font-weight: 500; color: var(--ink-soft); }
.field-inline { flex: 1 1 18rem; }

.input {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.65rem;
    width: 100%;
    min-height: 2.5rem;
}
.input:hover { border-color: var(--muted); }
.input:focus { border-color: var(--focus); outline: 2px solid color-mix(in srgb, var(--focus) 25%, transparent); outline-offset: 0; }
.input-code { font-family: var(--font-mono); font-size: 1.125rem; letter-spacing: 0.15em; }
.invalid { border-color: var(--danger); }
.validation-message { color: var(--danger); font-size: 0.8125rem; }

.check { display: flex; align-items: flex-start; gap: 0.5rem; cursor: pointer; }
.check input { margin-top: 0.3rem; accent-color: var(--accent); width: 1rem; height: 1rem; flex: none; }
.check > span { display: flex; flex-direction: column; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font: inherit;
    font-weight: 500;
    min-height: 2.5rem;
    padding: 0.45rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { border-color: var(--ink-soft); color: var(--ink); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--mix-base)); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: var(--on-accent); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--accent-strong); }
.btn-quiet:hover { background: var(--accent-wash); border-color: transparent; }
.btn-block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 1rem; }

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem 1.25rem; margin-bottom: 1rem; }
.toolbar-wrap .field { min-width: 10rem; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.7rem 1rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table thead th { font-size: 0.8125rem; font-weight: 600; color: var(--muted); background: var(--surface-2); }
.table tbody tr:last-child > * { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody th { font-weight: 400; }
.table-dense th, .table-dense td { padding: 0.45rem 0.75rem; font-size: 0.875rem; }
.matrix th[scope="row"] { width: 40%; }
.cell-title { display: block; font-weight: 500; }
.cell-sub { display: block; font-size: 0.8125rem; color: var(--muted); }
.cell-actions { white-space: nowrap; text-align: right; }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
    display: inline-flex; align-items: center; gap: 0.4rem;
    border: 1px solid var(--line-strong); border-radius: 999px;
    padding: 0.2rem 0.75rem 0.2rem 0.55rem; cursor: pointer; font-size: 0.875rem;
}
.chip input { accent-color: var(--accent); margin: 0; }
.chip:has(input:checked) { background: var(--accent-wash); border-color: var(--accent); }
.chip:has(input:disabled) { opacity: 0.6; cursor: not-allowed; }

.badge {
    display: inline-block; font-size: 0.75rem; font-weight: 500;
    padding: 0.1rem 0.5rem; border-radius: 999px; margin-right: 0.25rem;
    background: var(--fill); color: var(--ink-soft);
}
.badge-on { background: var(--ok-wash); color: var(--ok); }
.badge-off { background: var(--fill); color: var(--muted); }
.badge-warn { background: var(--warn-wash); color: var(--warn); }

.alert { border-radius: var(--radius); padding: 0.75rem 1rem; margin-bottom: 1rem; border: 1px solid; }
.alert p:last-child, .alert ul { margin-bottom: 0; }
.alert ul { padding-left: 1.25rem; margin-top: 0; }
.alert-danger { background: var(--danger-wash); border-color: color-mix(in srgb, var(--danger) 30%, var(--mix-base)); color: var(--danger-ink); }
.alert-success { background: var(--ok-wash); border-color: color-mix(in srgb, var(--ok) 30%, var(--mix-base)); color: var(--ok-ink); }
.alert-notice { background: var(--warn-wash); border-color: color-mix(in srgb, var(--warn) 35%, var(--mix-base)); color: var(--warn-ink); }

.secret {
    display: inline-block; font-family: var(--font-mono); font-size: 1rem;
    background: var(--surface); border: 1px dashed var(--line-strong);
    padding: 0.35rem 0.6rem; border-radius: var(--radius-sm); user-select: all;
}

.empty { background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 2rem; color: var(--ink-soft); }
.empty p { margin: 0; }

.pager { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; color: var(--muted); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; margin: 0 0 1.25rem; }
.facts dt { color: var(--muted); font-size: 0.875rem; }
.facts dd { margin: 0; }
.facts-row { grid-template-columns: repeat(6, max-content max-content); }

.pick-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.pick {
    width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
    background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm); padding: 0.5rem 0.75rem;
}
.pick:hover { background: var(--surface-hover); }
.pick.is-selected { background: var(--accent-wash); border-color: var(--accent); }

.tool-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); max-width: 56rem; }
.tool-list li { border-bottom: 1px solid var(--line); }
.tool {
    display: grid;
    grid-template-columns: minmax(10rem, 16rem) 1fr max-content;
    gap: 0.25rem 2rem;
    align-items: baseline;
    padding: 1.1rem 0.5rem;
    text-decoration: none;
    color: var(--ink);
}
.tool:hover { background: var(--surface); color: var(--ink); }
.tool:hover .tool-name { color: var(--accent-strong); }
.tool-name { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; }
.tool-desc { color: var(--ink-soft); }
.tool-access { font-size: 0.8125rem; color: var(--muted); }

.qr { width: 13rem; padding: 0.5rem; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 0.75rem; }
.qr svg { display: block; width: 100%; height: auto; }
.codes { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; grid-template-columns: repeat(2, max-content); gap: 0.35rem 1.5rem; }
.codes code { font-size: 1rem; }
.log { margin: 0 0 1rem; padding-left: 1.25rem; font-size: 0.875rem; max-height: 16rem; overflow-y: auto; }
.json { margin: 0.5rem 0 0; white-space: pre-wrap; word-break: break-word; font-size: 0.8125rem; max-width: 32rem; }

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
    background: linear-gradient(var(--rail) 0 14rem, var(--paper) 14rem);
}
.auth-panel {
    width: min(26rem, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 2rem;
}
.auth-panel .wordmark { color: var(--rail); margin-bottom: 1.5rem; }
.auth-panel h1 { font-size: 1.5rem; }

#blazor-error-ui {
    display: none;
    position: fixed; bottom: 1rem; right: 1rem; z-index: 1000;
    background: var(--danger-wash); color: var(--danger-ink); border: 1px solid var(--danger);
    border-radius: var(--radius); padding: 0.75rem 1rem;
}

@media (max-width: 960px) {
    .split, .split-wide { grid-template-columns: 1fr; }
    .facts-row { grid-template-columns: max-content 1fr; }
}

@media (max-width: 760px) {
    .shell { grid-template-columns: 1fr; }
    .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; gap: 0.5rem; padding: 0.75rem; }
    .rail-group { flex-direction: row; flex-wrap: wrap; }
    .rail-heading, .rail-sub { display: none; }
    .rail-foot { margin-top: 0; border-top: none; padding-top: 0; flex-direction: row; flex-wrap: wrap; }
    .content { padding: 1.25rem 1rem 3rem; }
    .grid-2 { grid-template-columns: 1fr; }
    .page-head { flex-direction: column; }
    .tool { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

:root {
    --rz-primary: #0b7a75;
    --rz-primary-light: #129089;
    --rz-primary-lighter: #e3f2f1;
    --rz-primary-dark: #08625e;
    --rz-primary-darker: #064b48;
    --rz-on-primary: #ffffff;
    --rz-text-font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
    --rz-body-font-size: 0.9375rem;
    --rz-base-background-color: #f3f5f7;
    --rz-border-radius: 6px;
}

.rz-card.panel { padding: 1.25rem 1.5rem; border: 1px solid var(--line); box-shadow: none; }
.rz-card.panel p { color: var(--ink-soft); }
.rz-card.panel h2 { margin-bottom: 0.75rem; }
.toolbar.rz-stack { margin-bottom: 1rem; }
.form-row { margin-top: 1rem; }
.detail-card { margin-top: 1.25rem; }
.rz-data-grid { border-radius: var(--radius); }
.rz-data-grid a { color: var(--accent-strong); }

.grant-list { display: flex; flex-direction: column; border-top: 1px solid var(--line); margin-bottom: 0.75rem; }
.grant-row {
    display: grid;
    grid-template-columns: minmax(10rem, 16rem) 1fr;
    gap: 0.5rem 1.5rem;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--line);
}
.grant-app { display: flex; flex-direction: column; gap: 0.15rem; align-items: flex-start; }

.file-input { display: block; margin: 0.5rem 0 1rem; font: inherit; }
.rail-link-external::after { content: " ↗"; color: var(--rail-muted); }

@media (max-width: 760px) {
    .grant-row { grid-template-columns: 1fr; }
}

/* ====================================================================
   Themes. Light is the default; dark applies when the person chose Dark,
   or chose nothing and their system is dark (see ThemePreference.cs).
   DocCentral.Portal uses the same values; keep them in step.
   ==================================================================== */

:root {
    color-scheme: light;
    --surface-2: #f8fafb;
    --surface-hover: #f5f7f9;
    --fill: #eef1f4;
    --on-accent: #ffffff;
    --mix-base: #ffffff;
    --danger-ink: #7a1a14;
    --ok-ink: #14532a;
    --warn-ink: #5c3c00;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --ink: #e4ebf2; --ink-soft: #c0cad4; --muted: #8fa0b1;
        --paper: #0a121a; --surface: #131e2a; --surface-2: #182533; --surface-hover: #1c2a39;
        --fill: #223142;
        --line: #253547; --line-strong: #3a4e65;
        --rail: #0e2131; --rail-active: #1a405c;
        --accent: #2bb3a8; --accent-strong: #5fd3c9; --accent-wash: #10322f;
        --danger: #f08a82; --danger-wash: #3a1b1a; --danger-ink: #fbd3cf;
        --warn: #e8b44f; --warn-wash: #33270e; --warn-ink: #f8e2b5;
        --ok: #5cc98a; --ok-wash: #11301e; --ok-ink: #c9f0d7;
        --focus: #6ea2ff; --on-accent: #08141e; --mix-base: #131e2a;
        --rz-primary: #2bb3a8; --rz-primary-light: #5fd3c9; --rz-primary-lighter: #10322f;
        --rz-primary-dark: #22968c; --rz-primary-darker: #1a7a72; --rz-on-primary: #08141e;
        --rz-base-background-color: #0a121a;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --ink: #e4ebf2; --ink-soft: #c0cad4; --muted: #8fa0b1;
    --paper: #0a121a; --surface: #131e2a; --surface-2: #182533; --surface-hover: #1c2a39;
    --fill: #223142;
    --line: #253547; --line-strong: #3a4e65;
    --rail: #0e2131; --rail-active: #1a405c;
    --accent: #2bb3a8; --accent-strong: #5fd3c9; --accent-wash: #10322f;
    --danger: #f08a82; --danger-wash: #3a1b1a; --danger-ink: #fbd3cf;
    --warn: #e8b44f; --warn-wash: #33270e; --warn-ink: #f8e2b5;
    --ok: #5cc98a; --ok-wash: #11301e; --ok-ink: #c9f0d7;
    --focus: #6ea2ff; --on-accent: #08141e; --mix-base: #131e2a;
    --rz-primary: #2bb3a8; --rz-primary-light: #5fd3c9; --rz-primary-lighter: #10322f;
    --rz-primary-dark: #22968c; --rz-primary-darker: #1a7a72; --rz-on-primary: #08141e;
    --rz-base-background-color: #0a121a;
}

/* The sign-in pages put the wordmark on the panel, not on the navy rail. */
.auth-panel .wordmark { color: var(--ink); }
.auth-panel .theme-switch { float: right; margin-top: -0.25rem; }

/* QR codes stay black on white so authenticator apps can read them in either theme. */
.qr { background: #ffffff; }

/* Theme switch: three links, so it also works on the sign-in pages, which load no script. */
.theme-switch { display: inline-flex; gap: 2px; padding: 2px; border-radius: 999px; border: 1px solid var(--line-strong); }
.theme-switch a {
    display: inline-grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 999px;
    color: var(--muted); text-decoration: none;
}
.theme-switch a:hover { background: var(--fill); color: var(--ink); }
.theme-switch a[aria-current="true"] { background: var(--accent-wash); color: var(--accent-strong); }
.theme-switch svg { width: 1rem; height: 1rem; }
.rail .theme-switch { margin: 0 0.75rem 0.5rem; align-self: flex-start; border-color: rgba(214, 226, 236, 0.25); }
.rail .theme-switch a { color: var(--rail-ink); }
.rail .theme-switch a:hover { background: var(--rail-active); color: #fff; }
.rail .theme-switch a[aria-current="true"] { background: rgba(255, 255, 255, 0.14); color: #fff; }
