/* ==========================================================================
   Clearbrook CDC — product UI
   Chart tokens follow the validated data-viz palette (light + selected dark).
   ========================================================================== */

:root {
  color-scheme: light;
  --page: #f3f2ed;
  --page-deep: #e9e7df;
  --surface: #fcfcfb;
  --surface-2: #f7f6f1;
  --surface-3: #efeee8;
  --ink: #14211d;
  --ink-2: #46534f;
  --muted: #75817c;
  --line: #e1e0d8;
  --line-strong: #cac9c0;
  --brand: #103d34;
  --brand-2: #17584a;
  --brand-soft: #e2eee9;
  --brand-ink: #f8fbfa;
  --accent: #b65f34;
  --accent-soft: #f6e9e1;
  --focus: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #1baf7a;
  --series-3: #eda100;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --good-ink: #006300;
  --good-soft: #e8f4e7;
  --warning-ink: #7a5600;
  --warning-soft: #fff5dc;
  --serious-ink: #803817;
  --serious-soft: #fcebe3;
  --critical-ink: #9d2929;
  --critical-soft: #fbe9e9;
  --info-ink: #1f5c9f;
  --info-soft: #e8f1fb;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --range-band: rgba(12, 163, 12, 0.075);
  --tooltip-bg: #17201d;
  --tooltip-ink: #fbfcfb;
  --sidebar: #102e28;
  --sidebar-2: #0b241f;
  --sidebar-ink: #edf5f2;
  --sidebar-muted: #9db4ad;
  --sidebar-line: rgba(255, 255, 255, 0.09);
  --sidebar-active: #1b443a;
  --scrim: rgba(8, 19, 16, 0.52);
  --shadow-sm: 0 1px 2px rgba(19, 33, 28, 0.04);
  --shadow: 0 1px 2px rgba(19, 33, 28, 0.04), 0 12px 32px rgba(19, 33, 28, 0.055);
  --shadow-lg: 0 24px 70px rgba(10, 25, 20, 0.19);
  --radius-sm: 9px;
  --radius: 14px;
  --radius-lg: 20px;
  --font: "Segoe UI Variable", "Segoe UI", "Aptos", "PingFang SC", "Microsoft YaHei",
    "Noto Sans SC", system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --page-deep: #080909;
  --surface: #1a1a19;
  --surface-2: #222220;
  --surface-3: #292927;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #99978f;
  --line: #2c2c2a;
  --line-strong: #3b3b38;
  --brand: #86c7b4;
  --brand-2: #a5dccb;
  --brand-soft: #1d312b;
  --brand-ink: #0b211b;
  --accent: #e29a70;
  --accent-soft: #33241c;
  --focus: #5598e7;
  --series-1: #3987e5;
  --series-2: #199e70;
  --series-3: #c98500;
  --good-ink: #61d661;
  --good-soft: #152b15;
  --warning-ink: #f5cd70;
  --warning-soft: #2f2714;
  --serious-ink: #f0a182;
  --serious-soft: #31211a;
  --critical-ink: #f08e8e;
  --critical-soft: #311d1d;
  --info-ink: #8bbcef;
  --info-soft: #172638;
  --grid: #2c2c2a;
  --axis: #383835;
  --range-band: rgba(12, 163, 12, 0.12);
  --tooltip-bg: #f3f2ec;
  --tooltip-ink: #101713;
  --sidebar: #101715;
  --sidebar-2: #0b1110;
  --sidebar-ink: #edf5f2;
  --sidebar-muted: #91a29c;
  --sidebar-line: rgba(255, 255, 255, 0.08);
  --sidebar-active: #1e332d;
  --scrim: rgba(0, 0, 0, 0.64);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.24), 0 16px 40px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 28px 80px rgba(0, 0, 0, 0.55);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 86% -8%, rgba(27, 175, 122, 0.055), transparent 34rem),
    var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
img, svg { max-width: 100%; }
svg { flex-shrink: 0; }
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -0.022em; }
ul, ol { margin: 0; padding: 0; list-style: none; }
table { border-collapse: collapse; width: 100%; }
::selection { background: rgba(42, 120, 214, 0.2); }

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

* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 300;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  transform: translateY(-150%);
  box-shadow: var(--shadow);
}
.skip-link:focus { transform: translateY(0); }

.hidden { display: none !important; }
.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;
}
.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--critical-ink); }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-5 { margin-top: 24px; }
.full { grid-column: 1 / -1; }

/* ----------------------------------------------------------------- boot/login */
.boot-screen {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 13px;
}
.boot-mark { animation: bootPulse 1.8s ease-in-out infinite; }
@keyframes bootPulse {
  0%, 100% { transform: translateY(0); opacity: 0.75; }
  50% { transform: translateY(-4px); opacity: 1; }
}

.login-page {
  min-height: 100vh;
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(420px, 0.94fr);
  gap: 18px;
  background: var(--page);
}
.login-art {
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  padding: clamp(28px, 4vw, 56px);
  background:
    radial-gradient(circle at 78% 16%, rgba(80, 167, 139, 0.26), transparent 22rem),
    radial-gradient(circle at 4% 92%, rgba(201, 109, 63, 0.18), transparent 20rem),
    linear-gradient(145deg, #123c33 0%, #0c2b25 58%, #09231e 100%);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: calc(100vh - 36px);
}
.login-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(circle at 72% 36%, black, transparent 68%);
  pointer-events: none;
}
.login-art > * { position: relative; z-index: 1; }
.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.13);
  color: #fff;
  flex: 0 0 auto;
}
.brand-name {
  display: block;
  font-size: 17px;
  font-weight: 680;
  letter-spacing: -0.02em;
  color: inherit;
}
.brand-sub {
  display: block;
  margin-top: 1px;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
}
.login-copy {
  max-width: 650px;
  padding: clamp(36px, 8vh, 100px) 0 28px;
}
.login-copy .eyebrow { color: #b7d9ce; }
.login-copy h1 {
  margin: 14px 0 18px;
  font-size: clamp(36px, 4.5vw, 66px);
  line-height: 1.07;
  letter-spacing: -0.045em;
  font-weight: 660;
  color: #f7fbf9;
}
.login-copy h1 .soft { color: #a3c9bd; }
.login-copy p {
  max-width: 520px;
  color: #b9cec7;
  font-size: 15px;
  line-height: 1.7;
}
.login-art-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  color: #9fbab2;
  font-size: 12px;
}
.login-art-footer .dot-sep { width: 3px; height: 3px; border-radius: 50%; background: #5f7f75; }
.login-vitals {
  position: absolute;
  right: clamp(26px, 5vw, 72px);
  top: 26%;
  width: min(46%, 430px);
  opacity: 0.35;
  pointer-events: none;
}
.login-vitals .ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(173, 218, 204, 0.35);
  inset: 0;
}
.login-vitals .ring.two { inset: 13%; }
.login-vitals .ring.three { inset: 26%; }
.login-vitals .pulse {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
}
.login-vitals .pulse svg { width: 100%; height: 100%; }

.login-panel {
  display: grid;
  place-items: center;
  padding: clamp(18px, 4vw, 48px);
  min-height: calc(100vh - 36px);
}
.login-card {
  width: min(100%, 418px);
  padding: 30px 30px 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.login-card .mobile-brand { display: none; }
.login-title {
  font-size: 25px;
  font-weight: 660;
  letter-spacing: -0.03em;
}
.login-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.login-form { margin-top: 26px; display: grid; gap: 16px; }
.login-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}
.login-submit { width: 100%; height: 44px; }
.demo-accounts {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.demo-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .03em;
}
.demo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.demo-btn {
  text-align: left;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, transform .16s ease;
}
.demo-btn:hover { border-color: var(--line-strong); background: var(--brand-soft); transform: translateY(-1px); }
.demo-btn strong { display: block; font-size: 12px; font-weight: 650; }
.demo-btn span { display: block; color: var(--muted); font-size: 10.5px; margin-top: 1px; }
.login-foot {
  margin-top: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}
.theme-login {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 3;
}

/* ---------------------------------------------------------------- app shell */
.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 0% 0%, rgba(64, 132, 111, 0.2), transparent 22rem),
    linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
  color: var(--sidebar-ink);
  border-right: 1px solid rgba(255,255,255,.04);
  z-index: 50;
}
.sidebar-top {
  padding: 22px 20px 16px;
}
.sidebar .brand-mark { background: rgba(255,255,255,.09); }
.sidebar .brand-name { font-size: 16px; }
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 16px;
}
.nav-group + .nav-group { margin-top: 20px; }
.nav-label {
  padding: 0 12px 7px;
  color: var(--sidebar-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 40px;
  padding: 9px 12px;
  margin: 2px 0;
  border-radius: 9px;
  color: var(--sidebar-muted);
  font-size: 13px;
  font-weight: 520;
  transition: color .16s ease, background .16s ease;
}
.nav-item svg { width: 17px; height: 17px; opacity: .88; }
.nav-item:hover { color: var(--sidebar-ink); background: rgba(255,255,255,.055); }
.nav-item.is-active {
  color: var(--sidebar-ink);
  background: var(--sidebar-active);
}
.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 11px;
  bottom: 11px;
  width: 2px;
  border-radius: 2px;
  background: #8bd4bd;
}
.nav-item .nav-count {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(255,255,255,.09);
  color: #d8e8e2;
  font-size: 10px;
}
.sidebar-bottom {
  padding: 12px;
  border-top: 1px solid var(--sidebar-line);
}
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px;
  border-radius: 11px;
  min-width: 0;
}
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: #dceae4;
  color: #1a493b;
  font-size: 12px;
  font-weight: 700;
}
[data-theme="dark"] .user-avatar { background: #27463d; color: #d7f1e7; }
.user-meta { min-width: 0; flex: 1; }
.user-meta strong { display: block; font-size: 12.5px; font-weight: 600; color: var(--sidebar-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { display: block; font-size: 10.5px; color: var(--sidebar-muted); margin-top: 1px; }
.sidebar-actions { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.sidebar-actions .icon-btn { color: var(--sidebar-muted); }
.sidebar-actions .icon-btn:hover { color: var(--sidebar-ink); background: rgba(255,255,255,.07); }
.sidebar-foot-note { padding: 4px 10px 2px; color: #77958c; font-size: 10px; }
.sidebar-scrim {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: var(--scrim);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
body.nav-open .sidebar-scrim { opacity: 1; pointer-events: auto; }

.main-shell { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  background: color-mix(in srgb, var(--page) 86%, transparent);
  backdrop-filter: blur(16px) saturate(120%);
}
.topbar-inner {
  min-height: 72px;
  padding: 12px clamp(20px, 2.6vw, 36px);
  display: flex;
  align-items: center;
  gap: 14px;
}
.icon-btn.menu-btn { display: none; }
.topbar-copy { min-width: 0; flex: 1; }
.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.topbar-title {
  margin-top: 1px;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.025em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-sub { display: none; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.today-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: 11.5px;
  white-space: nowrap;
}
.today-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--status-good); box-shadow: 0 0 0 3px rgba(12,163,12,.12); }
.view {
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: clamp(20px, 2.4vw, 34px) clamp(20px, 2.6vw, 36px) 56px;
}
.view.is-loading .dashboard-content { opacity: .48; transition: opacity .18s ease; }

/* ------------------------------------------------------------------ buttons */
.btn {
  --btn-bg: var(--surface);
  --btn-border: var(--line);
  --btn-ink: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 39px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font-size: 12.5px;
  font-weight: 580;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease, opacity .15s ease;
}
.btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; }
.btn-primary {
  --btn-bg: var(--brand);
  --btn-border: var(--brand);
  --btn-ink: #f8fbfa;
  background: var(--brand);
  border-color: var(--brand);
  color: #f8fbfa;
}
[data-theme="dark"] .btn-primary { --btn-ink: #0b211b; color: #0b211b; }
.btn-primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn-danger {
  --btn-bg: transparent;
  --btn-border: color-mix(in srgb, var(--status-critical) 38%, var(--line));
  --btn-ink: var(--critical-ink);
  color: var(--critical-ink);
}
.btn-danger:hover { background: var(--critical-soft); border-color: var(--status-critical); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--ink); }
.btn.danger { color: var(--critical-ink); }
.btn.danger:hover { background: var(--critical-soft); border-color: transparent; color: var(--critical-ink); }
.btn-sm { min-height: 32px; padding: 6px 10px; font-size: 11.5px; border-radius: 8px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { min-height: 44px; padding: 10px 18px; font-size: 13px; }
.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.bordered { border-color: var(--line); background: var(--surface); }
.icon-btn.danger { color: var(--critical-ink); }
.icon-btn.danger:hover { background: var(--critical-soft); }
.link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--info-ink);
  font-weight: 560;
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
}
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.link svg { width: 13px; height: 13px; }

/* ------------------------------------------------------------------ filters */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar-left { flex: 1 1 auto; min-width: 0; }
.toolbar-right { flex: 0 0 auto; }
.range-control {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.range-control button {
  min-height: 30px;
  padding: 4px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 560;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.range-control button:hover { color: var(--ink); background: var(--surface-2); }
.range-control button[aria-pressed="true"] {
  background: var(--brand-soft);
  color: var(--brand);
}
[data-theme="dark"] .range-control button[aria-pressed="true"] { color: #b8ead9; }
.filter-context { color: var(--muted); font-size: 11.5px; }
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  min-width: min(280px, 100%);
}
.search-box svg {
  position: absolute;
  left: 11px;
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  height: 39px;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
}
.search-box input::placeholder { color: var(--muted); }
.select-control {
  height: 39px;
  padding: 7px 32px 7px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2375817c' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.select-control.small { height: 34px; font-size: 11.5px; }

/* --------------------------------------------------------------------- KPI */
.kpi-layout {
  display: grid;
  grid-template-columns: minmax(310px, 1.35fr) repeat(3, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-layout.ops { grid-template-columns: minmax(280px, 1.25fr) repeat(3, minmax(150px, 1fr)); }
.hero-card {
  position: relative;
  overflow: hidden;
  min-height: 194px;
  padding: 22px 24px;
  border-radius: var(--radius-lg);
  color: #eff8f4;
  background:
    radial-gradient(circle at 92% 10%, rgba(106, 197, 168, 0.34), transparent 17rem),
    linear-gradient(135deg, #17493d 0%, #10362e 58%, #0a2a23 100%);
  box-shadow: 0 16px 34px rgba(16, 61, 52, 0.16);
  display: flex;
  flex-direction: column;
}
.hero-card::after {
  content: "";
  position: absolute;
  right: -38px;
  top: -58px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.11);
  box-shadow: 0 0 0 34px rgba(255,255,255,.025), 0 0 0 70px rgba(255,255,255,.018);
  pointer-events: none;
}
.hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.kicker {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: .11em;
  text-transform: uppercase;
}
.hero-card .kicker { color: #a9c8bd; }
.hero-period {
  position: relative;
  z-index: 1;
  padding: 3px 8px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  color: #b7d2c8;
  font-size: 10px;
  letter-spacing: .02em;
  background: rgba(255,255,255,.04);
}
.hero-value {
  position: relative;
  z-index: 1;
  margin-top: 9px;
  font-size: clamp(48px, 5.4vw, 62px);
  line-height: 1;
  font-weight: 640;
  letter-spacing: -0.055em;
  color: #f8fcfa;
  font-variant-numeric: proportional-nums;
}
.hero-value .suffix { font-size: 0.38em; font-weight: 540; letter-spacing: -0.01em; margin-left: 3px; color: #bad4ca; }
.hero-under {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 9px;
  font-size: 11px;
  color: #b6cec5;
}
.hero-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255,255,255,.1);
  color: #eff8f4;
  font-weight: 600;
  font-size: 10.5px;
}
.hero-delta svg { width: 12px; height: 12px; }
.hero-delta.good { background: rgba(107, 214, 154, .16); color: #b9f1cc; }
.hero-delta.bad { background: rgba(240, 142, 142, .15); color: #ffd0d0; }
.hero-breakdown {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  color: #d3e5de;
  font-size: 10.5px;
}
.hero-breakdown span { display: inline-flex; align-items: center; gap: 6px; }
.hero-breakdown i { width: 6px; height: 6px; border-radius: 50%; background: #a8d9c5; }
.hero-breakdown .is-low i { background: #f3b47b; }
.hero-breakdown .is-high i { background: #f0ce72; }
.hero-card .hero-footnote {
  margin-top: 9px;
  color: #91b2a6;
  font-size: 10px;
}
.stat-card {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 194px;
}
.stat-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.stat-icon {
  width: 33px;
  height: 33px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-2);
}
.stat-icon svg { width: 16px; height: 16px; }
.stat-icon.blue { background: var(--info-soft); color: var(--info-ink); }
.stat-icon.green { background: var(--good-soft); color: var(--good-ink); }
.stat-icon.clay { background: var(--accent-soft); color: var(--accent); }
.stat-label { color: var(--muted); font-size: 11px; font-weight: 540; }
.stat-value {
  margin-top: 12px;
  font-size: clamp(27px, 2.2vw, 34px);
  line-height: 1.05;
  font-weight: 640;
  letter-spacing: -0.04em;
  font-variant-numeric: proportional-nums;
}
.stat-value .unit { margin-left: 3px; color: var(--muted); font-size: 10.5px; font-weight: 520; letter-spacing: 0; }
.stat-foot {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.4;
}
.delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-weight: 620;
  font-size: 10.5px;
}
.delta svg { width: 11px; height: 11px; }
.delta.good { color: var(--good-ink); }
.delta.bad { color: var(--critical-ink); }
.delta.neutral { color: var(--muted); }

/* ------------------------------------------------------------------- cards */
.card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px 0;
}
.card-head.with-border { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.card-title {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.015em;
}
.card-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.5;
}
.card-tools { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.card-body { padding: 16px 20px 20px; }
.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}
.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.62fr) minmax(300px, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}
.dashboard-grid > .card { min-height: 100%; }
.chart-card .card-body { padding-top: 10px; }
.chart-card.is-table .chart-frame { display: none; }
.chart-card.is-table .chart-table { display: block; }
.chart-card .chart-table { display: none; }
.chart-frame { position: relative; min-width: 0; min-height: 240px; }
.chart-frame.line-frame { min-height: 310px; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart-axis-line { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart-axis-text {
  fill: var(--muted);
  font-family: var(--font);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}
.chart-band { fill: var(--range-band); }
.chart-band-text { fill: var(--muted); font-family: var(--font); font-size: 9.5px; }
.chart-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: var(--series-1); opacity: .1; }
.chart-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart-direct-label {
  fill: var(--ink);
  font-family: var(--font);
  font-size: 10.5px;
  font-weight: 650;
}
.chart-bar { fill: var(--series-1); }
.chart-bar-hit { fill: transparent; cursor: pointer; }
.chart-bar-hit:focus-visible { outline: none; }
.chart-bar.is-active { filter: brightness(1.08); }
.chart-limit { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 0; opacity: .55; }
.chart-limit-label { fill: var(--muted); font-family: var(--font); font-size: 9.5px; }
.chart-crosshair { stroke: var(--axis); stroke-width: 1; }
.chart-crosshair-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart-empty {
  min-height: 230px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.chart-empty svg { width: 28px; height: 28px; opacity: .65; }
.chart-note {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 4px;
  color: var(--muted);
  font-size: 10px;
}
.legend-inline { display: inline-flex; align-items: center; gap: 5px; }
.legend-inline .swatch { width: 8px; height: 8px; border-radius: 2px; }
.legend-inline .swatch.band { background: var(--range-band); }
.chart-tooltip {
  position: absolute;
  z-index: 6;
  min-width: 132px;
  max-width: 220px;
  padding: 9px 11px;
  border-radius: 9px;
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  box-shadow: 0 10px 28px rgba(0,0,0,.22);
  font-size: 11px;
  line-height: 1.45;
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity .1s ease, transform .1s ease;
}
.chart-tooltip.is-visible { opacity: 1; transform: translateY(0); }
.chart-tooltip .tt-date { font-size: 9.5px; letter-spacing: .04em; opacity: .7; margin-bottom: 4px; }
.chart-tooltip .tt-value { display: flex; align-items: baseline; gap: 4px; font-size: 15px; font-weight: 650; }
.chart-tooltip .tt-value span { font-size: 9.5px; font-weight: 500; opacity: .72; }
.chart-tooltip .tt-meta { margin-top: 3px; opacity: .76; font-size: 10px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; color: inherit; font-size: 10px; }
.chart-tooltip .tt-key { width: 12px; height: 2px; border-radius: 2px; background: var(--series-1); }
.chart-table-wrap { max-height: 310px; overflow: auto; }
.chart-table { width: 100%; font-size: 11px; }
.chart-table th {
  position: sticky; top: 0;
  background: var(--surface);
  padding: 7px 9px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-align: left;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .03em;
  white-space: nowrap;
}
.chart-table td { padding: 7px 9px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.chart-table tr:last-child td { border-bottom: 0; }

/* ---------------------------------------------------------------- nutrition */
.nutrition-shell { padding-top: 6px; }
.macro-bar {
  display: flex;
  gap: 2px;
  height: 20px;
  margin: 10px 0 16px;
  border-radius: 5px;
  background: var(--surface-2);
}
.macro-seg {
  height: 100%;
  min-width: 2px;
  padding: 0;
  border: 0;
  cursor: pointer;
  transition: filter .14s ease;
}
.macro-seg:first-child { border-radius: 5px 2px 2px 5px; }
.macro-seg:last-child { border-radius: 2px 5px 5px 2px; }
.macro-seg:hover, .macro-seg:focus-visible { filter: brightness(1.1); outline-offset: 1px; }
.macro-legend { display: grid; gap: 9px; }
.macro-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; }
.macro-name { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 11.5px; }
.macro-name i { width: 8px; height: 8px; border-radius: 2px; }
.macro-value { font-size: 11.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.nutrition-meta {
  margin-top: 16px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 10.5px;
}
.nutrition-meta strong { color: var(--ink); font-weight: 650; font-size: 13px; }
.macro-tooltip-anchor { position: relative; }

/* ------------------------------------------------------------------- alerts */
.alert-list { display: flex; flex-direction: column; }
.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.alert-item:last-child { border-bottom: 0; padding-bottom: 3px; }
.alert-icon {
  width: 29px;
  height: 29px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--ink-2);
}
.alert-icon.is-high { background: var(--warning-soft); color: var(--warning-ink); }
.alert-icon.is-low { background: var(--serious-soft); color: var(--serious-ink); }
.alert-icon.is-critical { background: var(--critical-soft); color: var(--critical-ink); }
.alert-icon svg { width: 14px; height: 14px; }
.alert-main { flex: 1; min-width: 0; }
.alert-line { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.alert-name { font-size: 12px; font-weight: 580; }
.alert-value { font-size: 12.5px; font-weight: 680; font-variant-numeric: tabular-nums; }
.alert-value small { color: var(--muted); font-size: 9.5px; font-weight: 500; }
.alert-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 2px; color: var(--muted); font-size: 10px; }
.alert-note {
  margin-top: 5px;
  color: var(--ink-2);
  font-size: 10.5px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ------------------------------------------------------------------ tables */
.table-wrap {
  overflow-x: auto;
  border-radius: 0 0 var(--radius) var(--radius);
}
.table-wrap.scroll-y {
  max-height: 560px;
  overflow: auto;
}
.table-wrap.scroll-y thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
}
.table-wrap.flush { border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.data-table { min-width: 680px; font-size: 12px; }
.data-table th {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-align: left;
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: .05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr { transition: background .13s ease; }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 65%, transparent); }
.data-table .num, .data-table .value-cell { font-variant-numeric: tabular-nums; }
.cell-primary { font-weight: 580; color: var(--ink); }
.cell-secondary { color: var(--muted); font-size: 10.5px; margin-top: 1px; }
.cell-stack { display: flex; flex-direction: column; min-width: 0; }
.cell-inline { display: flex; align-items: center; gap: 8px; min-width: 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 3px; }
.table-date-row td {
  padding: 9px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 10.5px;
  font-weight: 600;
}
.table-date-row .count { color: var(--muted); font-weight: 500; margin-left: 6px; }
.avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 10.5px;
  font-weight: 700;
}
.patient-cell { display: flex; align-items: center; gap: 9px; min-width: 0; }
.patient-cell-text { min-width: 0; }
.appointment-mini-list { display: grid; }
.appointment-mini {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.appointment-mini:last-child { border-bottom: 0; padding-bottom: 4px; }
.appointment-mini-when {
  flex: 0 0 88px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.appointment-mini-when strong { font-size: 11.5px; font-weight: 650; }
.appointment-mini-when span { color: var(--muted); font-size: 9.5px; white-space: nowrap; }
.appointment-mini-main { min-width: 0; flex: 1; }
.appointment-mini-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.appointment-mini-meta { color: var(--muted); font-size: 10px; line-height: 1.5; margin-top: 3px; }
.reading-value {
  font-size: 15px;
  font-weight: 680;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.reading-value small { color: var(--muted); font-size: 9.5px; font-weight: 500; margin-left: 2px; letter-spacing: 0; }
.value-and-status { display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; }
.table-toolbar {
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.table-toolbar .tt-title { font-size: 12px; font-weight: 600; }
.table-toolbar .tt-count { color: var(--muted); font-weight: 500; font-size: 10.5px; margin-left: 5px; }
.empty-table { padding: 46px 20px; }

/* ------------------------------------------------------------------ badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 580;
  line-height: 1.2;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge svg { width: 11px; height: 11px; }
.badge.neutral { background: var(--surface-2); color: var(--ink-2); border-color: var(--line); }
.badge.good { background: var(--good-soft); color: var(--good-ink); }
.badge.warning { background: var(--warning-soft); color: var(--warning-ink); }
.badge.serious { background: var(--serious-soft); color: var(--serious-ink); }
.badge.critical { background: var(--critical-soft); color: var(--critical-ink); }
.badge.info { background: var(--info-soft); color: var(--info-ink); }
.badge.outline { background: transparent; border-color: var(--line); color: var(--ink-2); }
.badge .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.status-dot.good { background: var(--status-good); }
.status-dot.warning { background: var(--status-warning); }
.status-dot.serious { background: var(--status-serious); }
.status-dot.critical { background: var(--status-critical); }
.status-dot.info { background: var(--series-1); }
.tag-credential {
  display: inline-flex;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 9.5px;
  white-space: nowrap;
}
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------------------------------------------------------------- empty/error */
.empty-state {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 7px;
  padding: 38px 20px;
  color: var(--muted);
}
.empty-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  margin-bottom: 3px;
  border-radius: 13px;
  background: var(--surface-2);
  color: var(--ink-2);
}
.empty-icon svg { width: 19px; height: 19px; }
.empty-title { color: var(--ink); font-size: 13px; font-weight: 600; }
.empty-desc { max-width: 340px; font-size: 11px; line-height: 1.6; }
.error-state {
  margin: 40px auto;
  max-width: 520px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.error-state .empty-icon { margin-inline: auto; margin-bottom: 12px; color: var(--critical-ink); background: var(--critical-soft); }
.error-state h2 { font-size: 17px; margin-bottom: 6px; }
.error-state p { color: var(--muted); font-size: 12px; }
.error-state .btn { margin-top: 16px; }
.skeleton {
  border-radius: 8px;
  background: linear-gradient(90deg, var(--surface-2) 20%, var(--surface-3) 50%, var(--surface-2) 80%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton-kpis { display: grid; grid-template-columns: 1.35fr repeat(3, 1fr); gap: 14px; }
.skeleton-kpi { height: 194px; border-radius: var(--radius-lg); }
.skeleton-grid { display: grid; grid-template-columns: 1.62fr 1fr; gap: 14px; margin-top: 14px; }
.skeleton-card { height: 350px; border-radius: var(--radius); }

/* ------------------------------------------------------------------- tabs */
.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  min-height: 43px;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 560;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s ease;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); font-weight: 630; }
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--brand);
}
[data-theme="dark"] .tab[aria-selected="true"]::after { background: #8bd4bd; }
.tab-panel { animation: fadeUp .18s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }

/* ----------------------------------------------------------- patient detail */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
}
.back-link:hover { color: var(--ink); }
.back-link svg { width: 13px; height: 13px; }
.patient-hero {
  position: relative;
  padding: 22px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 92% -20%, rgba(27,175,122,.09), transparent 22rem),
    var(--surface);
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}
.patient-identity { display: flex; align-items: center; gap: 15px; min-width: 0; }
.patient-avatar {
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 17px;
  font-weight: 700;
}
[data-theme="dark"] .patient-avatar { color: #b8ead9; }
.patient-name-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.patient-name-line h1 { font-size: 23px; font-weight: 660; letter-spacing: -0.03em; }
.patient-meta { margin-top: 4px; display: flex; align-items: center; flex-wrap: wrap; gap: 5px 12px; color: var(--muted); font-size: 11px; }
.patient-meta span { display: inline-flex; align-items: center; gap: 4px; }
.patient-meta svg { width: 12px; height: 12px; }
.patient-hero-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.patient-snapshot {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.snapshot-item {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.snapshot-label { color: var(--muted); font-size: 10px; }
.snapshot-value { margin-top: 4px; font-size: 20px; font-weight: 650; letter-spacing: -0.03em; }
.snapshot-value small { color: var(--muted); font-size: 9.5px; font-weight: 500; margin-left: 2px; letter-spacing: 0; }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr); gap: 14px; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.info-item { min-width: 0; }
.info-label { color: var(--muted); font-size: 9.5px; letter-spacing: .04em; text-transform: uppercase; }
.info-value { margin-top: 3px; color: var(--ink); font-size: 12px; line-height: 1.5; word-break: break-word; }
.complication-list { display: flex; flex-direction: column; gap: 8px; }
.complication-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.complication-icon {
  width: 27px;
  height: 27px;
  flex: 0 0 auto;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--critical-soft);
  color: var(--critical-ink);
}
.complication-icon svg { width: 13px; height: 13px; }
.complication-body { flex: 1; min-width: 0; }
.complication-name { font-size: 11.5px; font-weight: 600; }
.complication-meta { color: var(--muted); font-size: 9.5px; margin-top: 1px; }
.complication-note { color: var(--ink-2); font-size: 10.5px; margin-top: 4px; line-height: 1.45; }
.mini-macros { display: flex; gap: 2px; height: 5px; width: 100px; border-radius: 4px; overflow: hidden; }
.mini-macros i { display: block; height: 100%; }
.detail-note { color: var(--ink-2); font-size: 10.5px; line-height: 1.5; max-width: 280px; }
.insulin-day-note { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 10px; }
.detail-section + .detail-section { margin-top: 14px; }

/* ------------------------------------------------------------ appointments */
.appointment-date {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 78px;
}
.appointment-date strong { font-size: 12px; font-weight: 620; }
.appointment-date span { color: var(--muted); font-size: 10px; }
.appointment-status-line { display: flex; align-items: center; gap: 6px; }
.center-room { display: flex; flex-direction: column; min-width: 0; }
.center-room strong { font-weight: 560; font-size: 11.5px; }
.center-room span { color: var(--muted); font-size: 10px; }
.status-rail {
  display: grid;
  gap: 9px;
  padding: 2px 0;
}
.status-rail-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 11.5px; }
.status-rail-label { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.status-rail-value { font-weight: 650; font-variant-numeric: tabular-nums; }
.status-rail-bar { grid-column: 1 / -1; height: 5px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: -4px; }
.status-rail-fill { height: 100%; border-radius: 999px; background: currentColor; }

/* -------------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label {
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}
.required-mark { color: var(--critical-ink); font-size: 11px; line-height: 1; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
  transition: border-color .14s ease, box-shadow .14s ease;
}
.field textarea { resize: vertical; min-height: 82px; line-height: 1.55; }
.field select {
  appearance: none;
  padding-right: 32px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2375817c' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 16%, transparent);
}
.field input::placeholder, .field textarea::placeholder { color: var(--muted); }
.field input:disabled, .field select:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.field.is-invalid input, .field.is-invalid select, .field.is-invalid textarea { border-color: var(--status-critical); }
.field-error { color: var(--critical-ink); font-size: 10px; line-height: 1.4; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-section-title {
  grid-column: 1 / -1;
  margin-top: 2px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 630;
}
.form-section-title:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.form-hint { color: var(--muted); font-size: 10px; line-height: 1.5; }
.form-alert {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--status-critical) 32%, var(--line));
  border-radius: 9px;
  background: var(--critical-soft);
  color: var(--critical-ink);
  font-size: 11px;
  line-height: 1.5;
}
.checkbox-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.checkbox-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  font-size: 11.5px;
  transition: border-color .14s ease, background .14s ease;
}
.checkbox-chip:hover { border-color: var(--line-strong); }
.checkbox-chip input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--brand);
}
.checkbox-chip:has(input:checked) { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); background: var(--brand-soft); color: var(--brand); }
[data-theme="dark"] .checkbox-chip:has(input:checked) { color: #b8ead9; }
.form-row-inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 58px; }
.input-suffix .suffix {
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 10px;
  pointer-events: none;
}
.ratio-sum {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  margin-top: 2px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.5px;
}
.ratio-sum strong { color: var(--ink); font-variant-numeric: tabular-nums; font-size: 12px; }
.ratio-sum.is-invalid strong { color: var(--critical-ink); }
.glucose-hint {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  color: var(--muted);
  font-size: 10.5px;
}
.glucose-hint .badge { min-height: 20px; }
.date-time-summary {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 11px 13px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 11.5px;
}
.date-time-summary svg { width: 15px; height: 15px; color: var(--muted); }

/* ------------------------------------------------------------------- modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  padding: 20px;
  display: grid;
  place-items: center;
  background: var(--scrim);
  backdrop-filter: blur(4px);
  animation: modalFade .18s ease;
}
@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: min(100%, 610px);
  max-height: min(88vh, 860px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modalRise .2s ease;
  overflow: hidden;
}
.modal.wide { width: min(100%, 760px); }
@keyframes modalRise { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 15px;
  border-bottom: 1px solid var(--line);
}
.modal-title { font-size: 17px; font-weight: 650; letter-spacing: -0.025em; }
.modal-sub { margin-top: 3px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-2) 60%, var(--surface));
}
.modal-foot .foot-spacer { flex: 1; }
.modal-close { margin-top: -4px; margin-right: -5px; }
.confirm-copy { color: var(--ink-2); font-size: 12.5px; line-height: 1.65; }
.confirm-copy strong { color: var(--ink); }
.detail-list { display: grid; gap: 10px; }
.detail-list-row { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 9px; border-bottom: 1px solid var(--line); font-size: 11.5px; }
.detail-list-row:last-child { border-bottom: 0; padding-bottom: 0; }
.detail-list-row span { color: var(--muted); }
.detail-list-row strong { font-weight: 580; text-align: right; }
.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------- toasts */
.toast-root {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 12px 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  font-size: 12px;
  line-height: 1.5;
  animation: toastIn .2s ease;
  pointer-events: auto;
}
.toast.is-out { animation: toastOut .2s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }
.toast svg { width: 16px; height: 16px; margin-top: 1px; flex: 0 0 auto; }
.toast.success svg { color: var(--good-ink); }
.toast.error svg { color: var(--critical-ink); }
.toast.info svg { color: var(--info-ink); }
.toast-close { margin-left: auto; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; }

/* ------------------------------------------------------------------- pages */
.section-stack { display: flex; flex-direction: column; gap: 14px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, 1fr); gap: 14px; align-items: start; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.center-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.center-card { padding: 18px; }
.center-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.center-card h3 { font-size: 14px; font-weight: 650; }
.center-card .center-address { margin-top: 4px; color: var(--muted); font-size: 10.5px; line-height: 1.5; }
.center-facts { margin-top: 16px; padding-top: 13px; border-top: 1px solid var(--line); display: flex; gap: 18px; }
.center-fact strong { display: block; font-size: 18px; font-weight: 650; letter-spacing: -0.02em; }
.center-fact span { color: var(--muted); font-size: 9.5px; }
.analysis-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.analysis-controls { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.patient-picker { min-width: 210px; }
.analysis-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(290px, 1fr); gap: 14px; margin-bottom: 14px; }
.range-split { display: flex; gap: 2px; height: 26px; border-radius: 5px; overflow: hidden; margin: 14px 0 15px; background: var(--surface-2); }
.range-split span { display: block; height: 100%; min-width: 2px; }
.range-split span:first-child { border-radius: 5px 2px 2px 5px; }
.range-split span:last-child { border-radius: 2px 5px 5px 2px; }
.range-legend { display: grid; gap: 9px; }
.range-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 11.5px; }
.range-name { display: flex; align-items: center; gap: 7px; color: var(--ink-2); }
.range-value { font-weight: 650; font-variant-numeric: tabular-nums; }
.range-pct { color: var(--muted); font-weight: 500; margin-left: 5px; font-size: 9.5px; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.quick-action {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-2);
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 540;
  transition: border-color .14s ease, background .14s ease;
}
.quick-action:hover { border-color: var(--line-strong); background: var(--surface); }
.quick-action svg { width: 15px; height: 15px; color: var(--muted); }
.profile-details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px 20px; }
.profile-detail .info-label { font-size: 9px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1240px) {
  .kpi-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-card { grid-column: 1 / -1; min-height: 178px; }
  .stat-card { min-height: 156px; }
  .kpi-layout.ops .stat-card:last-child { grid-column: 1 / -1; }
  .dashboard-grid { grid-template-columns: minmax(0, 1.35fr) minmax(280px, 1fr); }
}
@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 228px minmax(0, 1fr); }
  .dashboard-grid, .analysis-grid, .two-col, .overview-grid { grid-template-columns: minmax(0, 1fr); }
  .three-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .patient-snapshot { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .app-shell { display: block; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 264px;
    transform: translateX(-104%);
    transition: transform .22s ease;
    box-shadow: 20px 0 60px rgba(0,0,0,.25);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .icon-btn.menu-btn { display: inline-grid; }
  .view { padding-top: 22px; }
  .login-page { grid-template-columns: 1fr; padding: 12px; }
  .login-art { display: none; }
  .login-panel { min-height: calc(100vh - 24px); }
  .login-card .mobile-brand { display: inline-flex; margin-bottom: 24px; }
  .login-card .mobile-brand .brand-name { color: var(--ink); }
  .login-card .mobile-brand .brand-sub { color: var(--muted); }
  .login-card .mobile-brand .brand-mark { background: var(--brand); color: #fff; border-color: transparent; }
}
@media (max-width: 760px) {
  .topbar-inner { min-height: 64px; padding: 10px 18px; }
  .topbar-title { font-size: 18px; }
  .today-chip .full-date { display: none; }
  .view { padding: 18px 18px 48px; }
  .kpi-layout { grid-template-columns: 1fr; }
  .hero-card { grid-column: auto; min-height: 176px; }
  .stat-card { min-height: 140px; }
  .kpi-layout.ops .stat-card:last-child { grid-column: auto; }
  .three-col, .patient-snapshot { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .info-grid, .profile-details { grid-template-columns: 1fr; }
  .toolbar { align-items: stretch; }
  .toolbar-left, .toolbar-right { width: 100%; }
  .toolbar-right { justify-content: flex-end; }
  .search-box { min-width: 0; flex: 1; }
  .select-control { flex: 1; min-width: 0; }
  .patient-hero { padding: 18px; }
  .patient-hero-actions { width: 100%; }
  .patient-hero-actions .btn { flex: 1; }
  .modal-backdrop { padding: 10px; place-items: end center; }
  .modal { width: 100%; max-height: 92vh; border-radius: 18px 18px 8px 8px; }
  .toast-root { right: 16px; bottom: 16px; }
  .analysis-head { align-items: stretch; }
  .analysis-controls { width: 100%; }
  .patient-picker { flex: 1; }
  .chart-frame.line-frame { min-height: 270px; }
  .login-card { padding: 24px 20px 20px; }
  .login-page { padding: 8px; }
  .login-panel { min-height: calc(100vh - 16px); padding: 12px; }
  .card-head { padding: 16px 16px 0; }
  .card-body { padding: 14px 16px 17px; }
  .card-footer { padding: 12px 16px; }
  .data-table th, .data-table td { padding: 10px 12px; }
  .table-toolbar { padding: 12px; }
}
@media (max-width: 520px) {
  .demo-grid { grid-template-columns: 1fr; }
  .topbar-right .today-chip { display: none; }
  .hero-card { padding: 20px; }
  .hero-breakdown { gap: 7px 12px; }
  .hero-value { font-size: 52px; }
  .skeleton-kpis { grid-template-columns: 1fr; }
  .skeleton-grid { grid-template-columns: 1fr; }
  .status-rail-row { font-size: 11px; }
  .chart-card .card-head { gap: 8px; }
  .row-actions .btn span { display: none; }
  .row-actions .btn { width: 32px; padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .sidebar, .topbar, .toolbar, .card-tools, .row-actions, .toast-root { display: none !important; }
  .app-shell { display: block; }
  .view { max-width: none; padding: 0; }
  body { background: #fff; color: #000; }
  .card, .patient-hero { box-shadow: none; break-inside: avoid; }
}
