:root {
    color-scheme: light;
    --ink: #243447;
    --muted: #59697b;
    --line: #dce4eb;
    --control-line: #8796a7;
    --surface: #ffffff;
    --surface-alt: #eef3f7;
    --canvas: #f5f7fa;
    --accent: #376d83;
    --accent-dark: #2a566a;
    --accent-soft: #e6f0f4;
    --on-accent: #ffffff;
    --focus: #4c7e96;
    --accent-shadow: rgba(55,109,131,.12);
    --success: #246a51;
    --success-bg: #e9f3ed;
    --success-line: #b2cfbf;
    --danger: #a43c44;
    --danger-bg: #faeded;
    --danger-line: #ddb9bd;
    --warning: #886021;
    --chart: #52859a;
    --chart-unknown: #8c9bab;
    --page-gutter: clamp(16px, 2vw, 48px);
    --shadow: 0 6px 22px rgba(34,52,71,.045);
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --ink: #e0e7ef;
    --muted: #a6b4c6;
    --line: #334256;
    --control-line: #71849a;
    --surface: #1c2837;
    --surface-alt: #243346;
    --canvas: #141e2b;
    --accent: #85bdce;
    --accent-dark: #a6d2df;
    --accent-soft: #263f4c;
    --on-accent: #132229;
    --focus: #a6d2df;
    --accent-shadow: rgba(0,0,0,.08);
    --success: #95cbb0;
    --success-bg: #243b33;
    --success-line: #456756;
    --danger: #e5a0a6;
    --danger-bg: #422d36;
    --danger-line: #73515a;
    --warning: #d5b475;
    --chart: #85bdce;
    --chart-unknown: #8195ad;
    --shadow: 0 6px 22px rgba(0,0,0,.10);
}


* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--canvas); font: 14px/1.45 Inter, "Segoe UI", Arial, sans-serif; }
a { color: inherit; }
.topbar { min-height: 70px; padding: 12px var(--page-gutter); gap: 16px; flex-wrap: wrap; display: flex; align-items: center; justify-content: space-between; background: var(--surface); color: var(--ink); border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 12px; align-items: center; color: var(--ink); text-decoration: none; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; background: var(--surface); color: var(--accent-dark); border-radius: 11px; font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand small { color: var(--ink); font-size: 11px; margin-top: 1px; }
.user-menu { display: flex; align-items: center; gap: 18px; color: var(--ink); }
.user-menu form { margin: 0; }
.link-button { padding: 0; border: 0; background: transparent; color: var(--ink); cursor: pointer; font: inherit; }
.page-shell { width: 100%; min-width: 0; margin: 0; padding: 34px var(--page-gutter) 72px; }
.page-heading { margin-bottom: 24px; }
.page-heading h1 { margin: 4px 0 6px; font-size: clamp(27px, 3vw, 38px); line-height: 1.12; letter-spacing: -0.025em; }
.page-heading p { margin: 0; color: var(--muted); }
.page-heading.compact h1 { font-size: 30px; }
.split-heading { display: flex; justify-content: space-between; gap: 24px; align-items: end; }
.eyebrow, .record-id { color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.back-link { display: inline-block; margin-bottom: 10px; color: var(--muted); text-decoration: none; }
.button { min-height: 42px; padding: 10px 17px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 9px; text-decoration: none; cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 700; line-height: 1.2; }
.button.primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 4px 12px var(--accent-shadow); }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { border-color: var(--focus); color: var(--accent-dark); background: var(--accent-soft); }
.button.ghost { border-color: var(--line); color: var(--muted); background: var(--surface); }
.button.wide { width: 100%; }
.search-bar { display: flex; gap: 10px; margin-bottom: 20px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.search-bar input { flex: 1; min-width: 0; max-width: 100%; padding: 10px 12px; border: 0; outline: 0; font: inherit; }
.table-card { width: 100%; min-width: 0; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th { padding: 13px 15px; color: var(--muted); background: var(--surface-alt); border-bottom: 1px solid var(--line); font-size: 11px; text-align: left; text-transform: uppercase; letter-spacing: .055em; white-space: nowrap; }
td { padding: 15px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-alt); }
td small { display: block; color: var(--muted); margin-top: 3px; }
.subject-cell { min-width: 260px; }
.row-link { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); text-decoration: none; font-size: 19px; }
.empty-state { padding: 72px 24px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: 14px; }
.empty-state h2 { margin: 10px 0 4px; }
.empty-state p { color: var(--muted); margin: 0 0 20px; }
.empty-icon { color: var(--accent); font-size: 46px; }
.messages { margin-bottom: 18px; }
.message { padding: 12px 15px; border-radius: 9px; background: var(--success-bg); color: var(--success); border: 1px solid var(--success-line); }
.form-alert { margin-bottom: 18px; padding: 13px 15px; border-radius: 9px; color: var(--danger); background: var(--danger-bg); border: 1px solid var(--danger-line); }
.errorlist { margin: 5px 0 0; padding: 0; color: var(--danger); list-style: none; font-size: 12px; }
.form-section, .detail-section { margin-bottom: 18px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); }
.section-heading { display: flex; gap: 13px; align-items: flex-start; margin-bottom: 20px; }
.section-heading > span { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--accent); background: var(--accent-soft); font-weight: 800; font-size: 11px; }
.section-heading h2 { margin: 1px 0 2px; font-size: 18px; }
.section-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.field-grid, .detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.field.span-2, .detail-grid .wide { grid-column: span 2; }
.field.span-3 { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.form-control, .stack-form input, .readonly input { width: 100%; min-width: 0; max-width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid var(--control-line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; }
textarea.form-control { resize: vertical; }
.form-control:focus, .stack-form input:focus { outline: 2px solid var(--focus); border-color: var(--accent); }
.readonly input { color: var(--muted); background: var(--surface-alt); }
.checkbox-field { display: flex; align-items: center; gap: 9px; padding-top: 24px; }
.checkbox-field input { flex: 0 0 18px; width: 18px; height: 18px; accent-color: var(--accent); }
.checkbox-field label { margin: 0; }
.form-actions { position: sticky; bottom: 14px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); backdrop-filter: blur(8px); }
.detail-grid { margin: 0; }
.detail-grid div { min-height: 67px; padding: 13px 14px; border-radius: 9px; background: var(--surface-alt); }
.detail-grid dt { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.detail-grid dd { margin: 6px 0 0; white-space: pre-wrap; }
.detail-grid .pending { background: var(--accent-soft); }
.audit-list { display: grid; gap: 8px; }
.audit-list a { display: flex; justify-content: space-between; gap: 20px; padding: 12px 14px; color: inherit; background: var(--surface-alt); border-radius: 8px; text-decoration: none; }
.audit-list a span:last-child { color: var(--muted); }
.login-card { max-width: 460px; margin: 8vh auto 0; padding: 34px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.login-heading h1 { margin: 8px 0 5px; font-size: 30px; }
.login-heading p { margin: 0 0 24px; color: var(--muted); }
.stack-form { display: grid; gap: 10px; }
.stack-form label { margin-top: 5px; font-weight: 700; font-size: 12px; }
.stack-form .button { margin-top: 10px; }
.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; }

/* Allow controls and long content to shrink inside grid/flex tracks. */
.field, .detail-grid > div, .section-heading > div,
.split-heading > div, .brand > span, .user-menu { min-width: 0; }
.page-shell, .topbar { overflow-wrap: anywhere; }
.brand { min-width: 0; }
.brand-mark, .section-heading > span { flex-shrink: 0; }
.user-menu { flex-wrap: wrap; }
input[type="date"].form-control { display: block; min-inline-size: 0; }
.button { max-width: 100%; white-space: normal; }
@media (min-width: 1800px) {
    .field-grid, .detail-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    .field-grid, .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

}
@media (max-width: 620px) {
    .topbar { padding: 12px 16px; }
    .user-menu > span { max-width: 120px; overflow-wrap: anywhere; }
    .page-shell { padding: 24px 14px 56px; }
    .split-heading { align-items: stretch; flex-direction: column; }
    .search-bar { flex-wrap: wrap; }
    .search-bar input { flex-basis: 100%; }
    .field-grid, .detail-grid { grid-template-columns: minmax(0, 1fr); }
    .field.span-2, .field.span-3, .detail-grid .wide { grid-column: span 1; }
    .form-section, .detail-section { padding: 18px 15px; }
    .form-control, .stack-form input, .readonly input { font-size: 16px; }
    .search-bar input { font-size: 16px; }
    .search-bar .button { width: 100%; }
    .form-actions { position: static; }
    .form-actions > .button { flex: 1 1 110px; }
    .login-card { padding: 24px 18px; margin-top: 24px; }
    .checkbox-field { padding-top: 0; }
    .audit-list a { flex-direction: column; gap: 4px; }
}

/* Shared components use semantic theme tokens. */
a:focus-visible, button:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.topbar a:focus-visible, .topbar button:focus-visible { outline-color: var(--ink); }
.users-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 20px; }
.user-card { min-width: 0; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: 13px; box-shadow: var(--shadow); }
.user-card-heading { display: flex; align-items: center; gap: 14px; }
.user-card-heading > div { min-width: 0; }
.user-avatar { flex: 0 0 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--accent); background: var(--accent-soft); font-size: 20px; font-weight: 800; }
.user-card h2 { margin: 0; font-size: 18px; }
.user-card p { margin: 4px 0 0; color: var(--muted); }
.user-badges, .user-card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.status-badge, .role-badge { padding: 5px 9px; border-radius: 7px; font-size: 13px; background: var(--accent-soft); color: var(--accent-dark); }
.status-badge.active { background: var(--success-bg); color: var(--success); }
.status-badge.inactive { background: var(--surface-alt); color: var(--muted); }
.user-meta { margin: 20px 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 14px; }
.user-meta dt { color: var(--muted); }
.user-meta dd { margin: 0; }
.account-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.field-help { color: var(--muted); font-size: 13px; margin-top: 8px; overflow-wrap: anywhere; }
.field-help ul { padding-left: 20px; margin: 0; }
.account-checkbox input { width: 20px; height: 20px; accent-color: var(--accent); }
@media (max-width: 620px) {
    .account-fields { grid-template-columns: minmax(0, 1fr); }
    .user-card { padding: 18px; }
    .user-card-actions .button { flex: 1 1 140px; }
}

/* One native link per record: mouse, touch, keyboard and opening in a new tab. */
.registry { --registry-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1.2fr) minmax(0, .8fr) minmax(0, .8fr) minmax(0, 1fr); border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: var(--shadow); }
.registry-head, .registry-values { display: grid; grid-template-columns: var(--registry-columns); gap: 20px; padding: 18px 20px; }
.registry-head { color: var(--muted); background: var(--surface-alt); border-radius: 13px 13px 0 0; font-size: 12px; font-weight: 700; }
.registry-records { list-style: none; margin: 0; padding: 0; }
.registry-records li { min-width: 0; border-top: 1px solid var(--line); }
.registry-record { display: block; color: inherit; text-decoration: none; cursor: pointer; }
.registry-record:hover, .registry-record:focus-visible { background: var(--accent-soft); }
.registry-record:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.registry-records li:last-child .registry-record { border-radius: 0 0 13px 13px; }
.registry-values { margin: 0; }
.registry-values > div, .registry-head > span { min-width: 0; overflow-wrap: anywhere; }
.registry-values dt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.registry-values dd { margin: 0; white-space: pre-wrap; }
.registry-values small { display: block; color: var(--muted); margin-top: 4px; }
@media (max-width: 900px) {
    .registry { border: 0; box-shadow: none; background: transparent; }
    .registry-head { display: none; }
    .registry-records { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
    .registry-records li { border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: var(--shadow); }
    .registry-record, .registry-records li:last-child .registry-record { border-radius: 13px; }
    .registry-values { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 6px 18px; }
    .registry-values > div { padding: 12px 0; }
    .registry-values > div + div { border-top: 1px solid var(--line); }
    .registry-values dt { position: static; width: auto; height: auto; overflow: visible; clip-path: none; white-space: normal; color: var(--muted); font-size: 12px; font-weight: 700; margin-bottom: 5px; }
    .registry-values dd { font-size: 16px; }
}

/* Compact navigation rail; expanded panel overlays content on small screens. */
.has-sidebar { --sidebar-rail: 64px; --sidebar-width: var(--sidebar-rail); padding-left: var(--sidebar-width); }
.has-sidebar.sidebar-open { --sidebar-width: 224px; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--sidebar-width); padding: 12px 8px; background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto; }
.sidebar-toggle, .side-nav a { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 12px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.sidebar svg { flex: 0 0 24px; width: 24px; height: 24px; }
.sidebar .nav-label { display: none; white-space: nowrap; }
.sidebar-open .sidebar .nav-label { display: inline; }
.sidebar-open .sidebar-toggle svg { transform: rotate(180deg); }
.side-nav { display: grid; gap: 8px; margin-top: 20px; }
.side-nav a:hover, .sidebar-toggle:hover { background: var(--canvas); color: var(--ink); }
.side-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-dark); }
.sidebar-backdrop { display: none; }
@media (max-width: 900px) {
    .has-sidebar { padding-left: var(--sidebar-rail); }
    .has-sidebar.sidebar-open { --sidebar-width: min(224px, 85vw); }
    .sidebar-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 35; border: 0; background: rgba(23,32,51,.25); }
}
@media (max-width: 620px) {
    .has-sidebar { --sidebar-rail: 56px; }
    .sidebar { padding-inline: 4px; }
    .has-sidebar .topbar { padding: 12px; gap: 12px; }
    .has-sidebar .brand-mark { display: none; }
    .has-sidebar .page-heading.compact h1 { font-size: 26px; }
}


.search-bar input { background: var(--surface); color: var(--ink); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
.brand small { color: var(--muted); }
.brand-mark { background: var(--accent-soft); color: var(--accent-dark); }
.theme-toggle { display: inline-grid; place-items: center; flex: 0 0 42px; width: 42px; height: 42px; padding: 9px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--surface); cursor: pointer; }
.theme-toggle:hover { background: var(--surface-alt); }
.theme-toggle svg { width: 22px; height: 22px; }
.theme-sun, :root[data-theme="dark"] .theme-moon { display: none; }
:root[data-theme="dark"] .theme-sun { display: block; }
.dashboard-updated { color: var(--muted); font-size: 13px; }
.portfolio-summary { display: flex; justify-content: space-between; align-items: center; gap: 32px; margin-bottom: 24px; padding: clamp(22px, 3vw, 36px); border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.portfolio-summary h2 { margin: 0; font-size: 16px; font-weight: 600; color: var(--muted); }
.portfolio-number { display: block; margin: 8px 0; font-size: clamp(44px, 5vw, 64px); line-height: 1.1; font-weight: 650; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.portfolio-summary p { margin: 0; color: var(--muted); }
.portfolio-summary-note { max-width: 440px; }
.portfolio-summary-note .button { margin-top: 16px; gap: 12px; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
.chart-card { min-width: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); padding: clamp(18px, 2vw, 30px); }
.chart-heading { margin-bottom: 28px; }
.chart-heading h2 { margin: 6px 0; font-size: 22px; line-height: 1.25; }
.chart-heading p { margin: 0; color: var(--muted); }
.bar-chart { list-style: none; padding: 0; margin: 0; display: grid; gap: 22px; }
.bar-caption { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 8px; }
.bar-caption > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.bar-value { flex-shrink: 0; display: inline-flex; align-items: baseline; gap: 10px; font-variant-numeric: tabular-nums; }
.bar-value small { color: var(--muted); min-width: 44px; text-align: right; }
.bar-track { height: 10px; background: var(--surface-alt); border-radius: 6px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: inherit; background: var(--chart); }
.bar-overdue .bar-fill { background: var(--danger); }
.bar-today .bar-fill, .bar-week .bar-fill { background: var(--warning); }
.bar-unknown .bar-fill { background: var(--chart-unknown); }
.chart-note { margin: 26px 0 0; padding: 14px 16px; border-radius: 10px; background: var(--surface-alt); color: var(--muted); font-size: 13px; }
.chart-empty { padding: 36px 8px; color: var(--muted); text-align: center; }
.chart-empty p { margin: 0 0 8px; font-size: 18px; color: var(--ink); }
.chart-empty span { display: block; }
.chart-empty .button { margin-top: 20px; }
@media (max-width: 1100px) {
    .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 620px) {
    .portfolio-summary { align-items: stretch; flex-direction: column; gap: 20px; }
    .bar-caption { gap: 8px; }
    .bar-value { gap: 6px; }
    .user-menu { gap: 10px; }
    .chart-heading h2 { font-size: 20px; }
}

.settings-tabs { display: flex; gap: 6px; margin: -10px 0 28px; padding: 5px; width: fit-content; max-width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.settings-tabs a { min-height: 40px; padding: 10px 16px; border-radius: 8px; color: var(--muted); font-weight: 700; text-decoration: none; }
.settings-tabs a:hover { background: var(--surface-alt); color: var(--ink); }
.settings-tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-dark); }
.dictionary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: 18px; }
.dictionary-card { display: flex; align-items: center; justify-content: space-between; gap: 24px; min-width: 0; padding: 24px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); text-decoration: none; }
.dictionary-card:hover { border-color: var(--accent); }
.dictionary-card > div { min-width: 0; }
.dictionary-card h2, .term-card h2 { margin: 0; font-size: 18px; }
.dictionary-card p, .term-card p { margin: 5px 0 0; color: var(--muted); }
.dictionary-count { flex-shrink: 0; min-width: 74px; padding: 12px; border-radius: 10px; background: var(--surface-alt); color: var(--accent-dark); font-size: 22px; font-weight: 700; text-align: center; }
.dictionary-count small { display: block; color: var(--muted); font-size: 11px; font-weight: 600; }
.terms-list { display: grid; gap: 12px; }
.term-card { display: flex; align-items: center; justify-content: space-between; gap: 24px; min-width: 0; padding: 18px 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.term-card.is-inactive { opacity: .7; }
.term-main, .term-actions { display: flex; align-items: center; gap: 14px; min-width: 0; }
.term-main > div { min-width: 0; }
.term-order { flex: 0 0 42px; height: 42px; display: grid; place-items: center; border-radius: 9px; background: var(--surface-alt); color: var(--muted); font-variant-numeric: tabular-nums; }
.term-actions { flex-shrink: 0; }
.term-actions form { margin: 0; }
@media (max-width: 620px) {
    .settings-tabs { width: 100%; }
    .settings-tabs a { flex: 1; text-align: center; }
    .dictionary-card, .term-card { align-items: stretch; flex-direction: column; gap: 16px; }
    .dictionary-count { align-self: flex-start; }
    .term-actions { flex-wrap: wrap; }
    .term-actions .button { flex: 1 1 130px; }
    .term-actions form { display: flex; flex: 1 1 130px; }
    .term-actions form .button { width: 100%; }
}
