/* ══════════════════════════════════════════════════════════════════════════
   Pheasyo — physiotherapy clinic network
   "Clinical & calm" theme: teal interface, soft neutrals, light + dark.
   Chart colors are deliberately separate from the interface color: teal
   belongs to the UI, blue/orange/green belong to the data.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── 1. Tokens ─────────────────────────────────────────────────────────── */
:root {
  color-scheme: light;

  --bg:            #eaf1f1;
  --bg-2:          #dfe9e9;
  --surface:       #ffffff;
  --surface-2:     #f5f9f9;
  --surface-3:     #eaf1f1;
  --surface-inv:   #0e1a1a;

  --border:        rgba(13, 32, 32, .11);
  --border-strong: rgba(13, 32, 32, .20);

  --text:          #0e1414;
  --text-2:        #4d5a5a;
  --muted:         #788787;

  --accent:        #0f766e;
  --accent-hover:  #0b5f58;
  --accent-soft:   #dcefec;
  --accent-ink:    #0a5750;
  --on-accent:     #ffffff;
  --focus:         #0f766e;

  /* Status palette — fixed, never carries meaning alone (always icon + label) */
  --good:          #0ca30c;
  --good-ink:      #006300;
  --good-soft:     #e2f5e2;
  --warning:       #fab219;
  --warning-ink:   #8a5a00;
  --warning-soft:  #fdf1d8;
  --serious:       #ec835a;
  --serious-ink:   #9a4418;
  --serious-soft:  #fceadf;
  --critical:      #d03b3b;
  --critical-ink:  #a92b2b;
  --critical-soft: #fbe4e4;
  --neutral-soft:  #eceff0;

  /* Charts — validated categorical palette (validate_palette.js, surface #ffffff) */
  --series-1:      #2a78d6;
  --series-2:      #eb6834;
  --series-3:      #1baf7a;
  --seq-100:       #cde2fb;
  --seq-250:       #86b6ef;
  --seq-450:       #2a78d6;
  --track:         #cde2fb;
  --grid:          #e3eaea;
  --axis:          #c6d2d2;
  --chart-surface: #ffffff;

  --r-xs: 5px; --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-full: 999px;

  --sh-1: 0 1px 2px rgba(13,32,32,.05), 0 1px 3px rgba(13,32,32,.04);
  --sh-2: 0 4px 14px rgba(13,32,32,.07), 0 1px 3px rgba(13,32,32,.05);
  --sh-3: 0 24px 60px rgba(13,32,32,.20), 0 4px 12px rgba(13,32,32,.10);

  --sidebar-w: 256px;
  --topbar-h: 60px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:            #0b1011;
    --bg-2:          #080c0d;
    --surface:       #141a1b;
    --surface-2:     #1b2223;
    --surface-3:     #232b2c;
    --surface-inv:   #eaf1f1;
    --border:        rgba(255,255,255,.10);
    --border-strong: rgba(255,255,255,.20);
    --text:          #eef4f4;
    --text-2:        #b0bfbf;
    --muted:         #8b9a9a;
    --accent:        #2dd4bf;
    --accent-hover:  #5ee0d0;
    --accent-soft:   rgba(45,212,191,.14);
    --accent-ink:    #7ce7da;
    --on-accent:     #04211f;
    --focus:         #2dd4bf;
    --good:          #0ca30c; --good-ink: #37c437; --good-soft: rgba(12,163,12,.16);
    --warning:       #fab219; --warning-ink: #f0b53c; --warning-soft: rgba(250,178,25,.15);
    --serious:       #ec835a; --serious-ink: #f09a78; --serious-soft: rgba(236,131,90,.15);
    --critical:      #d03b3b; --critical-ink: #ef6b6b; --critical-soft: rgba(208,59,59,.17);
    --neutral-soft:  rgba(255,255,255,.07);
    --series-1:      #3987e5;
    --series-2:      #d95926;
    --series-3:      #199e70;
    --seq-100:       #184f95;
    --seq-250:       #256abf;
    --seq-450:       #3987e5;
    --track:         #0d366b;
    --grid:          #263031;
    --axis:          #344041;
    --chart-surface: #141a1b;
    --sh-1: 0 1px 2px rgba(0,0,0,.35);
    --sh-2: 0 4px 14px rgba(0,0,0,.40);
    --sh-3: 0 24px 60px rgba(0,0,0,.60);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:            #0b1011;
  --bg-2:          #080c0d;
  --surface:       #141a1b;
  --surface-2:     #1b2223;
  --surface-3:     #232b2c;
  --surface-inv:   #eaf1f1;
  --border:        rgba(255,255,255,.10);
  --border-strong: rgba(255,255,255,.20);
  --text:          #eef4f4;
  --text-2:        #b0bfbf;
  --muted:         #8b9a9a;
  --accent:        #2dd4bf;
  --accent-hover:  #5ee0d0;
  --accent-soft:   rgba(45,212,191,.14);
  --accent-ink:    #7ce7da;
  --on-accent:     #04211f;
  --focus:         #2dd4bf;
  --good:          #0ca30c; --good-ink: #37c437; --good-soft: rgba(12,163,12,.16);
  --warning:       #fab219; --warning-ink: #f0b53c; --warning-soft: rgba(250,178,25,.15);
  --serious:       #ec835a; --serious-ink: #f09a78; --serious-soft: rgba(236,131,90,.15);
  --critical:      #d03b3b; --critical-ink: #ef6b6b; --critical-soft: rgba(208,59,59,.17);
  --neutral-soft:  rgba(255,255,255,.07);
  --series-1:      #3987e5;
  --series-2:      #d95926;
  --series-3:      #199e70;
  --seq-100:       #184f95;
  --seq-250:       #256abf;
  --seq-450:       #3987e5;
  --track:         #0d366b;
  --grid:          #263031;
  --axis:          #344041;
  --chart-surface: #141a1b;
  --sh-1: 0 1px 2px rgba(0,0,0,.35);
  --sh-2: 0 4px 14px rgba(0,0,0,.40);
  --sh-3: 0 24px 60px rgba(0,0,0,.60);
}

/* ── 2. Reset & base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }

.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; stroke-width: 2; }
.icon-lg { width: 24px; height: 24px; }
.icon-xl { width: 34px; height: 34px; stroke-width: 1.5; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.mono-nums { font-variant-numeric: tabular-nums; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ── 3. App shell ──────────────────────────────────────────────────────── */
.app-root { min-height: 100dvh; }
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }

.sidebar {
  grid-row: 1; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px 14px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  background: linear-gradient(150deg, var(--accent), color-mix(in srgb, var(--accent) 62%, #38bdf8));
  color: var(--on-accent); display: grid; place-items: center; font-weight: 750; font-size: 17px;
  box-shadow: var(--sh-1);
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.02em; }
.brand-sub { font-size: 11.5px; color: var(--muted); letter-spacing: .02em; }

.nav { flex: 1; overflow-y: auto; padding: 6px 10px 14px; }
.nav-section { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: var(--r-sm);
  color: var(--text-2); font-weight: 500; font-size: 14.5px; cursor: pointer; border: 0; background: none;
  width: 100%; text-align: right; text-align: start; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 620; }
.nav-item.is-active .icon { color: var(--accent); }
.nav-badge { margin-inline-start: auto; font-size: 11.5px; font-weight: 650; background: var(--surface-3); color: var(--text-2); padding: 1px 7px; border-radius: var(--r-full); }
.nav-item.is-active .nav-badge { background: var(--surface); color: var(--accent-ink); }

.sidebar-foot { border-top: 1px solid var(--border); padding: 10px; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--r-sm); width: 100%; border: 0; background: none; cursor: pointer; text-align: start; }
.user-card:hover { background: var(--surface-3); }
.user-card .u-name { font-size: 13.5px; font-weight: 620; line-height: 1.25; }
.user-card .u-role { font-size: 11.5px; color: var(--muted); }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px; padding: 0 clamp(14px, 2.2vw, 26px);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 16.5px; font-weight: 680; letter-spacing: -.015em; }
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.hamburger { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.page { padding: clamp(14px, 2.2vw, 26px); padding-bottom: 64px; flex: 1; max-width: 1560px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 18px; }
.page-head .grow { flex: 1; min-width: 220px; }
.page-title { font-size: clamp(20px, 2.4vw, 25px); font-weight: 700; letter-spacing: -.022em; }
.page-sub { color: var(--text-2); font-size: 14px; margin-top: 3px; }
.section-title { font-size: 15px; font-weight: 670; letter-spacing: -.01em; }
.section-head { display: flex; align-items: center; gap: 10px; margin: 26px 0 12px; }
.section-head .grow { flex: 1; }

/* ── 4. Cards & grids ──────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-1); overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head .grow { flex: 1; min-width: 0; }
.card-title { font-size: 14.5px; font-weight: 660; letter-spacing: -.01em; }
.card-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.card-body { padding: 16px; }
.card-body.tight { padding: 10px 12px; }
.card-body.flush { padding: 0; }
.card-foot { padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }

.grid { display: grid; gap: 14px; }
.g-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.g-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.g-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.g-side { grid-template-columns: minmax(0, 1fr) minmax(0, 340px); }
@media (max-width: 1080px) { .g-side { grid-template-columns: 1fr; } }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; }

/* ── 5. Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--r-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 570;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-disabled { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-soft { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
.btn-soft:hover { background: color-mix(in srgb, var(--accent-soft) 70%, var(--accent) 12%); }
.btn-danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--critical) 85%, #000); }
.btn-danger-soft { background: var(--critical-soft); border-color: transparent; color: var(--critical-ink); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: var(--r-xs); }
.btn-lg { padding: 11px 20px; font-size: 15.5px; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }
.btn-block { width: 100%; }

.segmented { display: inline-flex; background: var(--surface-3); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: none; padding: 6px 12px; border-radius: 6px; font-size: 13.5px;
  font-weight: 560; color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.segmented button.is-on { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); font-weight: 640; }

/* ── 6. Forms ──────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.label { font-size: 12.5px; font-weight: 620; color: var(--text-2); }
.help { font-size: 12px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; padding: 8px 11px; border-radius: var(--r-sm); border: 1px solid var(--border-strong);
  background: var(--surface); font-size: 14.5px; transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.textarea { min-height: 82px; resize: vertical; line-height: 1.5; }
.select { appearance: none; padding-inline-end: 30px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) 51%, calc(100% - 11px) 51%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon .input { padding-inline-start: 34px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.form-grid .span-2 { grid-column: 1 / -1; }

/* ── 7. Badges, chips, avatars ─────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: var(--r-full);
  font-size: 12px; font-weight: 630; background: var(--neutral-soft); color: var(--text-2); white-space: nowrap;
}
.badge .icon { width: 13px; height: 13px; stroke-width: 2.4; }
.badge-good { background: var(--good-soft); color: var(--good-ink); }
.badge-warn { background: var(--warning-soft); color: var(--warning-ink); }
.badge-serious { background: var(--serious-soft); color: var(--serious-ink); }
.badge-crit { background: var(--critical-soft); color: var(--critical-ink); }
.badge-accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge-outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--surface-3); color: var(--text-2); font-size: 12.5px; font-weight: 700; letter-spacing: .01em;
  border: 1px solid var(--border);
}
.avatar-sm { width: 26px; height: 26px; font-size: 10.5px; }
.avatar-lg { width: 54px; height: 54px; font-size: 18px; }
.avatar-accent { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }

/* ── 8. Tables ─────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: start; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 9px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2);
}
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover { background: var(--surface-2); }
.tbl .num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .shrink { width: 1%; white-space: nowrap; }

@media (max-width: 760px) {
  .tbl--stack thead { display: none; }
  .tbl--stack tbody tr { display: block; border-bottom: 1px solid var(--border); padding: 10px 12px; }
  .tbl--stack tbody tr:last-child { border-bottom: 0; }
  .tbl--stack td { display: flex; gap: 12px; align-items: center; justify-content: space-between; border: 0; padding: 3px 0; }
  .tbl--stack td::before {
    content: attr(data-th); font-size: 11.5px; font-weight: 650; text-transform: uppercase;
    letter-spacing: .05em; color: var(--muted); flex: none;
  }
  .tbl--stack td[data-th=""]::before { content: none; }
  .tbl--stack td.num { text-align: end; }
  .tbl--stack td.cell-main { padding-bottom: 6px; }
}

/* ── 9. Lists ──────────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--border);
  text-align: start; background: none; border-inline: 0; border-top: 0; width: 100%; cursor: pointer; color: inherit;
}
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); text-decoration: none; }
.li-title { font-size: 14px; font-weight: 600; }
.li-sub { font-size: 12.5px; color: var(--muted); }
.li-end { margin-inline-start: auto; text-align: end; flex: none; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .icon-xl { margin: 0 auto 10px; color: var(--border-strong); }
.empty-title { font-size: 15px; font-weight: 620; color: var(--text-2); }
.empty-text { font-size: 13.5px; margin-top: 4px; }

/* ── 10. Tabs ──────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  padding: 10px 14px; border: 0; background: none; cursor: pointer; font-size: 14px; font-weight: 560;
  color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-on { color: var(--accent-ink); border-bottom-color: var(--accent); font-weight: 640; }

/* ── 11. KPIs & charts ─────────────────────────────────────────────────── */
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 15px 16px; box-shadow: var(--sh-1); }
.kpi-label { font-size: 12.5px; color: var(--text-2); font-weight: 560; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: clamp(24px, 3vw, 30px); font-weight: 700; letter-spacing: -.028em; margin-top: 5px; line-height: 1.1; }
.kpi-hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.kpi-delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 640; margin-top: 5px; }
.kpi-delta.up { color: var(--good-ink); }
.kpi-delta.down { color: var(--critical-ink); }
.kpi-delta.flat { color: var(--muted); }
.hero-figure { font-size: clamp(40px, 7vw, 56px); font-weight: 700; letter-spacing: -.035em; line-height: 1; }

/* Horizontal bars: single series, direct labels, no legend box */
.bars { display: flex; flex-direction: column; gap: 11px; }
.bar-row { display: grid; grid-template-columns: minmax(76px, var(--bar-label-w, 132px)) 1fr auto; align-items: center; gap: 10px; }
.bar-label { font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; line-height: 1.25; }
.bar-track { height: 20px; background: var(--surface-3); border-radius: 4px; position: relative; overflow: hidden; }
.bar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 3px; transition: width .5s cubic-bezier(.22,.8,.3,1); }
.bar-fill[data-side="start"] { border-radius: 4px 0 0 4px; }
.bar-value { font-size: 13px; font-weight: 640; font-variant-numeric: tabular-nums; color: var(--text); min-width: 56px; text-align: end; }

/* Utilisation meter — track is a lighter step of the fill's own ramp */
.meter { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--series-1); border-radius: 4px; }

/* Stacked bar with a 2px surface gap between segments */
.stack { display: flex; height: 22px; border-radius: 4px; overflow: hidden; gap: 2px; background: var(--chart-surface); }
.stack > span { display: block; height: 100%; min-width: 2px; }
.stack > span:first-child { border-radius: 4px 0 0 4px; }
.stack > span:last-child { border-radius: 0 4px 4px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); }
.legend-key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-val { font-weight: 650; color: var(--text); font-variant-numeric: tabular-nums; }

.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-grid line { stroke: var(--grid); stroke-width: 1; }
.chart-axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--series-1); opacity: .10; }
/* Markers carry a 2px ring in the surface color so they stay legible where
   they cross the line. Intermediate dots appear on hover; the endpoint keeps
   its marker permanently and is the one point that is directly labelled. */
.chart-dot { fill: var(--series-1); stroke: var(--chart-surface); stroke-width: 2; r: 0; transition: r .1s; }
.chart-dot.end { r: 4.5; }
.chart-cross { stroke: var(--axis); stroke-width: 1; opacity: 0; }
.chart-hit { fill: transparent; cursor: crosshair; }
.pt:hover .chart-dot { r: 5; }
.pt:hover .chart-cross { opacity: 1; }
.chart-axis .chart-end { fill: var(--text); font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }

.tip {
  position: fixed; z-index: 200; pointer-events: none; background: var(--surface-inv);
  color: var(--bg); padding: 7px 10px; border-radius: var(--r-sm); font-size: 12.5px; line-height: 1.45;
  box-shadow: var(--sh-2); max-width: 260px;
}
.tip b { font-weight: 700; }
:root[data-theme="dark"] .tip { color: #0b1011; }

/* ── 12. Schedule (day / week grid) ────────────────────────────────────── */
.sched-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--sh-1); max-height: calc(100dvh - 210px); }
.sched { display: grid; grid-template-columns: 58px repeat(var(--cols), minmax(var(--colw, 168px), 1fr)); min-width: max-content; position: relative; }
.sched-hcell {
  position: sticky; top: 0; z-index: 6; background: var(--surface); border-bottom: 1px solid var(--border);
  border-inline-start: 1px solid var(--border); padding: 8px 10px; display: flex; align-items: center; gap: 8px; min-height: 54px;
}
.sched-hcell.corner { inset-inline-start: 0; z-index: 8; border-inline-start: 0; }
.sched-h-name { font-size: 13px; font-weight: 650; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-h-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-times { position: sticky; inset-inline-start: 0; z-index: 5; background: var(--surface); border-inline-end: 1px solid var(--border); }
.sched-time { height: var(--rowh); font-size: 11px; color: var(--muted); text-align: end; padding-inline-end: 7px; transform: translateY(-7px); font-variant-numeric: tabular-nums; }
.sched-time.half { color: transparent; }
.sched-col { position: relative; border-inline-start: 1px solid var(--border); }
.sched-slot { height: var(--rowh); border-bottom: 1px solid var(--grid); cursor: pointer; }
.sched-slot.hour { border-bottom-color: var(--border); }
.sched-slot:hover { background: var(--accent-soft); }
.sched-slot.is-off { background: repeating-linear-gradient(135deg, transparent, transparent 6px, var(--surface-2) 6px, var(--surface-2) 12px); cursor: not-allowed; }
.sched-slot.is-off:hover { background: repeating-linear-gradient(135deg, transparent, transparent 6px, var(--surface-2) 6px, var(--surface-2) 12px); }
.sched-slot.drop-on { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }

.sched-appt {
  position: absolute; inset-inline: 3px; border-radius: 7px; padding: 4px 7px; overflow: hidden; cursor: pointer;
  border: 1px solid transparent; border-inline-start-width: 3px; font-size: 12px; line-height: 1.3;
  background: var(--surface-3); color: var(--text); z-index: 2; transition: box-shadow .12s, transform .06s;
}
.sched-appt:hover { box-shadow: var(--sh-2); z-index: 3; }
.sched-appt.dragging { opacity: .4; }
.sched-appt .a-time { font-size: 10.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.sched-appt .a-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-appt .a-meta { font-size: 10.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-appt .a-flags { display: flex; gap: 3px; align-items: center; margin-top: 1px; }
.sched-appt .icon { width: 12px; height: 12px; stroke-width: 2.2; }

.st-scheduled { background: color-mix(in srgb, var(--series-1) 12%, var(--surface)); border-inline-start-color: var(--series-1); }
.st-completed { background: var(--good-soft); border-inline-start-color: var(--good); }
.st-cancelled { background: var(--surface-2); border-inline-start-color: var(--axis); opacity: .72; }
.st-cancelled .a-name { text-decoration: line-through; }
.st-no_show   { background: var(--critical-soft); border-inline-start-color: var(--critical); }
/* Location is a second, independent fact — it must not overwrite the status
   colour. A home visit keeps its status fill and gains an orange trailing
   edge plus the house icon, so both read at once. */
.sched-appt.is-house { box-shadow: inset -4px 0 0 var(--series-2); }
.sched-appt.is-house .icon { color: var(--serious-ink); }
.sched-appt.is-selected { box-shadow: 0 0 0 2px var(--accent), var(--sh-2); z-index: 4; }
/* Keep the home-visit edge visible through hover and selection states */
.sched-appt.is-house:hover { box-shadow: inset -4px 0 0 var(--series-2), var(--sh-2); }
.sched-appt.is-house.is-selected { box-shadow: inset -4px 0 0 var(--series-2), 0 0 0 2px var(--accent), var(--sh-2); }

.sched-now { position: absolute; inset-inline: 0; height: 0; border-top: 2px solid var(--critical); z-index: 4; pointer-events: none; }
.sched-now::before { content: ""; position: absolute; inset-inline-start: -4px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--critical); }

/* Agenda (list view — the mobile default) */
.agenda-day { border-bottom: 1px solid var(--border); }
.agenda-head { position: sticky; top: 0; background: var(--surface-2); padding: 7px 16px; font-size: 12.5px; font-weight: 660; color: var(--text-2); z-index: 2; border-bottom: 1px solid var(--border); }
.agenda-item { display: flex; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: flex-start; width: 100%; text-align: start; background: none; border-inline: 0; border-top: 0; color: inherit; }
.agenda-item:last-child { border-bottom: 0; }
.agenda-item:hover { background: var(--surface-2); }
.agenda-time { font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 650; width: 46px; flex: none; padding-top: 1px; }
.agenda-rail { width: 3px; border-radius: 2px; align-self: stretch; flex: none; background: var(--axis); }

/* ── 13. Modal ─────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(8, 20, 20, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  backdrop-filter: blur(2px); animation: fade .16s ease;
}
.modal {
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--sh-3); width: min(100%, 560px);
  max-height: min(92dvh, 900px); display: flex; flex-direction: column; overflow: hidden; animation: pop .18s cubic-bezier(.2,.9,.3,1.1);
}
.modal.w-lg { width: min(100%, 820px); }
.modal.w-xl { width: min(100%, 1040px); }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px 12px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 17px; font-weight: 680; letter-spacing: -.015em; }
.modal-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.modal-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; background: var(--surface-2); }
.modal-foot .grow { flex: 1; }
@keyframes fade { from { opacity: 0 } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.985) } }
@media (max-width: 560px) {
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { width: 100%; max-height: 94dvh; border-radius: var(--r-xl) var(--r-xl) 0 0; }
}

/* Toasts */
.toast-root { position: fixed; z-index: 300; bottom: 18px; inset-inline-end: 18px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 9px; background: var(--surface-inv); color: var(--bg);
  padding: 10px 14px; border-radius: var(--r-md); box-shadow: var(--sh-3); font-size: 13.5px; font-weight: 540;
  max-width: min(92vw, 400px); animation: pop .18s cubic-bezier(.2,.9,.3,1.1); pointer-events: auto;
}
:root[data-theme="dark"] .toast { color: #0b1011; }
.toast .icon { width: 17px; height: 17px; }
.toast.ok .icon { color: var(--good); }
.toast.err .icon { color: var(--critical); }
.toast.warn .icon { color: var(--warning); }
@media (max-width: 560px) { .toast-root { inset-inline: 12px; bottom: calc(66px + env(safe-area-inset-bottom)); align-items: stretch; } }

/* ── 14. Inline notices ────────────────────────────────────────────────── */
.note { display: flex; gap: 10px; padding: 11px 13px; border-radius: var(--r-md); font-size: 13.5px; line-height: 1.5; }
.note .icon { flex: none; margin-top: 1px; }
.note-info { background: var(--accent-soft); color: var(--accent-ink); }
.note-warn { background: var(--warning-soft); color: var(--warning-ink); }
.note-err  { background: var(--critical-soft); color: var(--critical-ink); }
.note-good { background: var(--good-soft); color: var(--good-ink); }
.note-muted { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

/* ── 15. Login screen ──────────────────────────────────────────────────── */
.login-wrap { min-height: 100dvh; display: grid; grid-template-columns: 1fr; place-items: center; padding: 24px 16px 48px; background:
  radial-gradient(1100px 620px at 78% -8%, color-mix(in srgb, var(--accent) 15%, transparent), transparent 62%),
  radial-gradient(900px 520px at 8% 108%, color-mix(in srgb, var(--series-1) 13%, transparent), transparent 60%), var(--bg); }
.login-card { width: min(100%, 940px); }
.login-brand { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 8px; }
.login-title { font-size: clamp(23px, 3.6vw, 31px); font-weight: 720; letter-spacing: -.03em; text-align: center; }
.login-sub { text-align: center; color: var(--text-2); max-width: 620px; margin: 6px auto 26px; font-size: 14.5px; }
.persona-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.persona {
  text-align: start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 16px; cursor: pointer; box-shadow: var(--sh-1); transition: transform .12s, box-shadow .12s, border-color .12s;
  display: flex; flex-direction: column; gap: 9px;
}
.persona:hover { transform: translateY(-2px); box-shadow: var(--sh-2); border-color: var(--accent); }
.persona-role { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--accent-ink); }
.persona-name { font-size: 15.5px; font-weight: 670; letter-spacing: -.015em; }
.persona-desc { font-size: 13px; color: var(--text-2); line-height: 1.45; }
.persona-perks { display: flex; flex-wrap: wrap; gap: 5px; margin-top: auto; padding-top: 4px; }

/* ── 16. Permission matrix ─────────────────────────────────────────────── */
.perm-grid { display: grid; gap: 8px; }
.perm-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--r-sm); background: var(--surface-2); font-size: 13.5px; }
.perm-row .icon { flex: none; }
.perm-yes { color: var(--good-ink); }
.perm-no { color: var(--muted); }
.perm-row.no { opacity: .72; }

/* ── 17. Misc utilities ────────────────────────────────────────────────── */
.kv { display: grid; grid-template-columns: minmax(96px, auto) 1fr; gap: 7px 14px; font-size: 13.5px; align-items: baseline; }
.kv dt { color: var(--muted); font-size: 12.5px; }
.kv dd { margin: 0; font-weight: 540; }
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { display: grid; grid-template-columns: 20px 1fr; gap: 12px; padding-bottom: 14px; position: relative; }
.tl-item::before { content: ""; position: absolute; inset-inline-start: 9px; top: 18px; bottom: 0; width: 2px; background: var(--border); }
.tl-item:last-child::before { display: none; }
.tl-dot { width: 20px; height: 20px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; color: var(--text-2); z-index: 1; }
.tl-dot .icon { width: 12px; height: 12px; stroke-width: 2.4; }
.exercise { display: flex; gap: 11px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.exercise:last-child { border-bottom: 0; }
.ex-num { width: 24px; height: 24px; border-radius: 7px; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.pain-scale { display: flex; gap: 3px; align-items: center; }
.pain-seg { width: 11px; height: 6px; border-radius: 2px; background: var(--surface-3); }
.pain-seg.on { background: var(--serious); }
.pain-seg.on.hi { background: var(--critical); }
.pain-seg.on.lo { background: var(--good); }
.scroll-x { overflow-x: auto; }
.stat-strip { display: flex; gap: 20px; flex-wrap: wrap; }
.stat-strip > div { min-width: 92px; }
.stat-strip .s-label { font-size: 12px; color: var(--muted); }
.stat-strip .s-value { font-size: 18px; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 12.5px; }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0 } .mt-1 { margin-top: 8px } .mt-2 { margin-top: 16px } .mt-3 { margin-top: 24px }
.mb-1 { margin-bottom: 8px } .mb-2 { margin-bottom: 16px }
.hr { height: 1px; background: var(--border); margin: 14px 0; border: 0; }

/* ── 18. Responsive: drawer + bottom nav ───────────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(8,20,20,.45); z-index: 39; animation: fade .16s ease; }
.bottom-nav { display: none; }

@media (max-width: 1024px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; width: 280px; z-index: 41;
    transform: translateX(-102%); transition: transform .22s cubic-bezier(.3,.9,.3,1); box-shadow: var(--sh-3);
  }
  .sidebar.is-open { transform: none; }
  .hamburger { display: inline-flex; }
  .sched-wrap { max-height: calc(100dvh - 250px); }
}

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .page { padding: 12px; padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 38; background: var(--surface);
    border-top: 1px solid var(--border); padding: 5px 4px calc(5px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 12px rgba(13,32,32,.06);
  }
  .bn-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px;
    border: 0; background: none; color: var(--muted); font-size: 10.5px; font-weight: 570; cursor: pointer; border-radius: var(--r-sm); min-width: 0;
  }
  .bn-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .bn-item.is-active { color: var(--accent-ink); }
  .bn-item.is-active .icon { color: var(--accent); }
  .card { border-radius: var(--r-md); }
  .kpi { padding: 12px 13px; border-radius: var(--r-md); }
  .kpi-value { font-size: 22px; }
  .grid { gap: 10px; }
  .g-4 { grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); }
  .sched-wrap { max-height: none; }
  .sched { --colw: 148px; }
  .page-head { margin-bottom: 12px; }
  .bar-row { grid-template-columns: minmax(64px, 96px) 1fr auto; gap: 8px; }
  .toast-root { z-index: 300; }
}

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