:root {
  --ink-950: #0b1720;
  --ink-900: #14232e;
  --ink-800: #253641;
  --ink-700: #384b58;
  --ink-600: #4a5e6c;
  --ink-500: #566a77;
  --ink-400: #637682;
  --ink-300: #a9b6be;
  --ink-200: #cfd8de;
  --ink-150: #e1e7eb;
  --ink-100: #edf2f5;
  --ink-50: #f7f9fb;
  --white: #ffffff;

  --brand-950: #011a36;
  --brand-900: #002b57;
  --brand-800: #003a73;
  --brand-700: #0b4b8e;
  --brand-600: #0f61a0;
  --brand-500: #116eb6;
  --brand-400: #297dbd;
  --brand-300: #70a8d3;
  --brand-200: #c6dced;
  --brand-100: #d9e8f3;
  --brand-50: #f1f6fb;

  --amber-700: #915c0a;
  --amber-500: #d28a18;
  --amber-100: #fff0ce;
  --amber-50: #fff8e8;
  --red-700: #a43f3b;
  --red-500: #d85b55;
  --red-100: #fbe1df;
  --red-50: #fff3f2;
  --blue-700: #0b4b8e;
  --blue-100: #d9e8f3;
  --blue-50: #f1f6fb;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

:root,
:root[data-theme="light"] {
  color-scheme: light;
  --surface: var(--ink-50);
  --surface-raised: var(--white);
  --surface-sunken: var(--ink-100);
  --surface-inverse: var(--brand-950);
  --text: var(--ink-900);
  --text-strong: var(--ink-950);
  --text-muted: var(--ink-500);
  --text-faint: var(--ink-400);
  --text-inverse: var(--white);
  --border: var(--ink-150);
  --border-strong: var(--ink-200);
  --border-hover: var(--ink-300);
  --accent: var(--brand-500);
  --accent-strong: var(--brand-700);
  --accent-soft: var(--brand-50);
  --accent-soft-border: var(--brand-100);
  --accent-on-inverse: var(--brand-200);
  --focus-ring: var(--brand-500);
  --shadow-xs: 0 1px 2px rgba(1, 26, 54, .05);
  --shadow-sm: 0 2px 8px rgba(1, 26, 54, .07), 0 1px 2px rgba(1, 26, 54, .05);
  --shadow-md: 0 14px 38px rgba(1, 26, 54, .13), 0 3px 8px rgba(1, 26, 54, .07);
  --scrim: rgba(1, 26, 54, .6);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: var(--brand-950);
  --surface-raised: #06223f;
  --surface-sunken: #001428;
  --surface-inverse: var(--ink-50);
  --text: #e8eff7;
  --text-strong: var(--white);
  --text-muted: #9fb4c8;
  --text-faint: #7d93a8;
  --text-inverse: var(--ink-950);
  --border: rgba(198, 220, 237, .16);
  --border-strong: rgba(198, 220, 237, .26);
  --border-hover: rgba(198, 220, 237, .38);
  --accent: var(--brand-300);
  --accent-strong: var(--brand-200);
  --accent-soft: rgba(17, 110, 182, .18);
  --accent-soft-border: rgba(112, 168, 211, .32);
  --accent-on-inverse: var(--brand-700);
  --focus-ring: var(--brand-300);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .4), 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 14px 38px rgba(0, 0, 0, .5), 0 3px 8px rgba(0, 0, 0, .35);
  --scrim: rgba(0, 8, 18, .72);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--surface); color: var(--text); font-size: 14px; line-height: 1.5; }
button, input, select, textarea { color: inherit; font: inherit; }
button, select { cursor: pointer; }
button:disabled, select:disabled { cursor: not-allowed; opacity: .55; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { letter-spacing: -.025em; }
code { border-radius: 5px; color: var(--text-muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: .82rem; }
::selection { background: var(--accent-soft); color: var(--text-strong); }
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.sr-only { height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; }
.wrap { overflow-wrap: anywhere; }
.no-wrap { white-space: nowrap; }

.brand { align-items: center; display: flex; gap: 11px; min-width: 0; }
.brand-mark { align-items: center; background: var(--surface-raised); border: 1px solid var(--accent-soft-border); border-radius: 10px; box-shadow: var(--shadow-xs); display: inline-flex; flex: 0 0 auto; height: 36px; justify-content: center; overflow: hidden; width: 36px; }
.brand > div:last-child { display: flex; flex-direction: column; line-height: 1.18; }
.brand strong { font-size: .96rem; letter-spacing: -.02em; }
.brand span { color: var(--text-muted); font-size: .7rem; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span, .fieldset > legend { color: var(--text-muted); font-size: .76rem; font-weight: 650; }
.field small { color: var(--text-muted); font-size: .71rem; line-height: 1.45; }
.field input, .field select, .field textarea, .search-field input {
  appearance: none; background: var(--surface-raised); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); min-height: 42px; outline: none; padding: 9px 11px;
  transition: border-color .15s, box-shadow .15s; width: 100%;
}
.field input:hover, .field select:hover, .field textarea:hover, .search-field:hover { border-color: var(--border-hover); }
.field input:focus, .field select:focus, .field textarea:focus, .search-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-stack { display: flex; flex-direction: column; gap: 18px; }
.form-grid { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius-md); margin: 0; padding: 17px; }
.fieldset > legend { padding: 0 7px; }

.button {
  align-items: center; background: none; border: 1px solid transparent; border-radius: var(--radius-sm);
  display: inline-flex; font-size: .78rem; font-weight: 650; gap: 7px; justify-content: center;
  line-height: 1; min-height: 38px; padding: 9px 14px; text-decoration: none;
  transition: background .15s, border-color .15s, box-shadow .15s, color .15s, transform .1s; white-space: nowrap;
}
.button:active:not(:disabled) { transform: translateY(1px); }
.button-large { font-size: .84rem; min-height: 48px; padding: 12px 18px; }
.button-small { font-size: .71rem; min-height: 31px; padding: 6px 9px; }
.button-primary { background: var(--accent); box-shadow: var(--shadow-xs); color: var(--white); }
.button-primary:hover:not(:disabled) { background: var(--accent-strong); }
.button-secondary { background: var(--surface-raised); border-color: var(--border-strong); box-shadow: var(--shadow-xs); color: var(--text); }
.button-secondary:hover:not(:disabled) { background: var(--surface-sunken); border-color: var(--border-hover); color: var(--text-strong); }
.button-ghost { color: var(--text-muted); }
.button-ghost:hover:not(:disabled) { background: var(--surface-sunken); color: var(--text-strong); }
.button-danger-ghost { color: var(--red-700); }
.button-danger-ghost:hover:not(:disabled) { background: var(--red-50); }
.icon-button { align-items: center; background: transparent; border: 0; border-radius: 8px; color: inherit; display: inline-flex; height: 36px; justify-content: center; padding: 0; width: 36px; }
.icon-button:hover { background: var(--surface-sunken); }

.alert { align-items: flex-start; border: 1px solid; border-radius: var(--radius-sm); display: flex; font-size: .78rem; gap: 9px; line-height: 1.45; padding: 11px 13px; }
.alert-error { background: var(--red-50); border-color: var(--red-100); color: var(--red-700); }
.alert-warning { background: var(--amber-50); border-color: var(--amber-100); color: var(--amber-700); }
.security-note { align-items: center; background: var(--accent-soft); border: 1px solid var(--accent-soft-border); border-radius: var(--radius-md); color: var(--accent-strong); display: flex; font-size: .77rem; gap: 10px; margin-bottom: 20px; padding: 12px 15px; }

.page-content { margin: 0 auto; max-width: 1440px; padding: 46px clamp(28px, 4.2vw, 68px) 70px; }
.page-header { align-items: flex-end; display: flex; gap: 24px; justify-content: space-between; margin-bottom: 30px; }
.page-header h1 { color: var(--text-strong); font-size: clamp(1.65rem, 3vw, 2.2rem); font-weight: 660; line-height: 1.14; margin: 7px 0 8px; }
.page-header p { color: var(--text-muted); font-size: .88rem; max-width: 680px; }
.page-actions { display: flex; flex: none; gap: 8px; }
.section-head { align-items: flex-end; display: flex; gap: 18px; justify-content: space-between; margin-bottom: 14px; }
.hint { color: var(--text-muted); font-size: .74rem; line-height: 1.45; }
.card { background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-xs); padding: 17px 19px; }
.summary-grid { display: grid; gap: 13px; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 24px; }
.summary-card { align-items: center; background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-xs); display: flex; gap: 13px; padding: 15px 17px; }
.summary-card strong { color: var(--text-strong); font-size: 1.3rem; line-height: 1.1; }
.summary-card span { color: var(--text-muted); font-size: .7rem; margin-top: 4px; }

.table-card { background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-xs); overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { background: var(--surface-sunken); color: var(--text-muted); font-size: .62rem; font-weight: 720; letter-spacing: .065em; padding: 11px 15px; text-align: left; text-transform: uppercase; }
td { border-top: 1px solid var(--border); color: var(--text); font-size: .73rem; padding: 13px 15px; vertical-align: middle; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-sunken); }
.primary-cell { display: flex; flex-direction: column; gap: 2px; }
.primary-cell strong { color: var(--text-strong); font-size: .75rem; font-weight: 650; }
.primary-cell span { color: var(--text-muted); font-size: .67rem; }
.empty-row td { color: var(--text-muted); text-align: center; }

.status-pill { align-items: center; background: var(--surface-sunken); border: 1px solid var(--border); border-radius: 999px; color: var(--text-muted); display: inline-flex; font-size: .6rem; font-weight: 670; letter-spacing: .015em; line-height: 1; min-height: 22px; padding: 4px 8px; white-space: nowrap; }
.status-positive { background: var(--accent-soft); border-color: var(--accent-soft-border); color: var(--accent-strong); }
.status-warning { background: var(--amber-50); border-color: var(--amber-100); color: var(--amber-700); }
.status-danger { background: var(--red-50); border-color: var(--red-100); color: var(--red-700); }
.status-info { background: var(--blue-50); border-color: var(--blue-100); color: var(--blue-700); }

.modal-backdrop { align-items: center; animation: fade-in .16s ease; background: var(--scrim); display: flex; inset: 0; justify-content: center; padding: 24px; position: fixed; z-index: 100; }
.modal { animation: modal-in .2s ease; background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); max-height: calc(100vh - 48px); overflow-y: auto; width: min(100%, 570px); }
.modal-header { align-items: flex-start; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; padding: 21px 23px 18px; }
.modal-header h2 { color: var(--text-strong); font-size: 1.15rem; font-weight: 680; }
.modal-body { padding: 21px 23px 23px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 5px; }
.toast-region { display: flex; flex-direction: column; gap: 9px; max-width: 390px; pointer-events: none; position: fixed; right: 22px; top: 22px; width: calc(100% - 44px); z-index: 200; }
.toast { align-items: center; animation: toast-in .25s ease; background: var(--surface-raised); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); box-shadow: var(--shadow-md); display: grid; font-size: .75rem; gap: 10px; grid-template-columns: 1fr auto; padding: 11px 10px 11px 12px; pointer-events: auto; }
.toast-error { border-left-color: var(--red-500); }
.state-card { align-items: center; background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-md); display: flex; flex-direction: column; padding: 46px 24px; text-align: center; }
.state-card h3 { font-size: .9rem; }
.state-card p { color: var(--text-muted); font-size: .74rem; margin: 5px 0 15px; max-width: 420px; }
.spinner { animation: spin .8s linear infinite; border: 2px solid var(--border-strong); border-radius: 50%; border-top-color: var(--accent); height: 24px; width: 24px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.985); } }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } }
@keyframes pulse { 50% { opacity: .55; } }

@media (max-width: 800px) {
  .form-grid, .summary-grid { grid-template-columns: 1fr; }
  .page-header { align-items: flex-start; flex-direction: column; gap: 14px; }
  .page-content { padding: 30px 18px 48px; }
}

.app-shell { display: flex; min-height: 100vh; }
.sidebar { background: var(--brand-950); color: var(--white); display: flex; flex: 0 0 248px; flex-direction: column; height: 100vh; left: 0; padding: 25px 16px 17px; position: sticky; top: 0; z-index: 20; }
.sidebar .brand { margin: 0 9px 28px; }
.sidebar .brand span { color: rgba(255,255,255,.72); }
.sidebar :focus-visible { outline-color: var(--brand-200); }
.sidebar nav { display: flex; flex: 1; flex-direction: column; gap: 24px; overflow-y: auto; }
.nav-group { display: flex; flex-direction: column; gap: 3px; }

.nav-label { color: rgba(255,255,255,.68); font-size: .61rem; font-weight: 700; letter-spacing: .13em; margin: 2px 11px 8px; text-transform: uppercase; }
.sidebar nav a { align-items: center; border-radius: 9px; color: rgba(255,255,255,.72); display: flex; font-size: .78rem; font-weight: 560; gap: 11px; min-height: 40px; padding: 9px 11px; text-decoration: none; transition: background .16s, color .16s; }
.sidebar nav a:hover { background: rgba(255,255,255,.055); color: var(--white); }
.sidebar nav a[aria-current] { background: rgba(217,232,243,.14); color: var(--brand-200); }
.nav-count { background: rgba(255,255,255,.1); border-radius: 999px; font-size: .6rem; font-weight: 700; margin-left: auto; min-width: 20px; padding: 2px 6px; text-align: center; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.09); color: rgba(255,255,255,.6); font-size: .65rem; line-height: 1.5; padding: 15px 4px 0; }
.app-main { display: flex; flex: 1; flex-direction: column; min-height: 100vh; min-width: 0; }
.app-main > main { flex: 1; min-height: 0; }

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { flex: none; height: auto; position: static; padding: 18px 14px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; gap: 14px; }
  .nav-group { flex: 1 1 160px; }
}

.session-strip { align-items: center; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 40px; padding-top: 16px; }
.session-strip p { color: var(--text-muted); font-size: .74rem; margin: 0; }
.session-strip button { background: var(--surface-raised); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); color: var(--text); cursor: pointer; font: inherit; font-size: .76rem; font-weight: 560; min-height: 36px; padding: 7px 14px; transition: background .16s, border-color .16s; }
.session-strip button:hover:not(:disabled) { background: var(--surface-sunken); border-color: var(--border-hover); }
.session-strip button:disabled { cursor: default; opacity: .55; }
