/* ============================================================================
   IAMD HMS — "Solace" theme
   Implements DESIGN_SYSTEM.md. Self-contained (does not depend on Bootstrap CSS/JS).
   Fonts (loaded in _Layout): Fraunces (display), Hanken Grotesk (UI), Spline Sans Mono.
   ============================================================================ */

:root {
  /* neutral chrome */
  --bg: #F4F7F7;
  --surface: #FFFFFF;
  --surface-2: #EFF4F4;
  --ink-900: #0F1B24;
  --ink-700: #2B3A45;
  --ink-500: #5A6B76;
  --ink-400: #8A99A3;
  --line: #E4E9EC;
  --line-strong: #D2DADF;

  /* brand */
  --primary: #0E7C7B;
  --primary-600: #0B6A69;
  --primary-700: #095755;
  --primary-050: #E7F2F1;
  --teal-bright: #34D1CC;

  /* status (canonical = PatientStatusMaster.BadgeHex) */
  --st-new: #475569;
  --st-upcoming: #1D4ED8;
  --st-active: #15803D;
  --st-online: #7C3AED;
  --st-hold: #B45309;
  --st-followup: #CA8A04;
  --st-rejected: #B91C1C;
  --st-expired: #374151;

  /* semantic + tints */
  --success: #15803D; --success-050: #E7F3EC;
  --danger: #B91C1C;  --danger-050: #F8E8E8;
  --warning: #B45309; --warning-050: #FBEDE0;
  --info: #1D4ED8;    --info-050: #E6ECFB;

  /* sidebar */
  --sidebar-bg: #0F1B24;
  --sidebar-fg: #9FB1BC;
  --sidebar-fg-strong: #FFFFFF;
  --sidebar-hover: rgba(255,255,255,.06);
  --sidebar-active: rgba(52,209,204,.14);

  /* spacing */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px;
  --space-6: 24px; --space-7: 32px; --space-8: 40px; --space-9: 48px; --space-10: 64px;

  /* radius */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-pill: 999px;

  /* legacy aliases (referenced by AJAX panels/forms — keep them resolving app-wide) */
  --border: var(--line); --border-strong: var(--line-strong); --radius: var(--r-md);

  /* elevation */
  --shadow-1: 0 1px 2px rgba(15,27,36,.04), 0 1px 3px rgba(15,27,36,.06);
  --shadow-2: 0 2px 8px rgba(15,27,36,.06), 0 8px 24px rgba(15,27,36,.05);
  --shadow-3: 0 12px 40px rgba(15,27,36,.16);
  --ring: 0 0 0 3px rgba(14,124,123,.28);

  /* type */
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-ui: "Hanken Grotesk", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* motion */
  --ease: cubic-bezier(.2,.7,.2,1);
  --t-fast: 120ms; --t: 200ms; --t-slow: 320ms;

  --sidebar-w: 264px;
  --sidebar-rail: 76px;
  --topbar-h: 64px;
}

/* ---- reset ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  font-size: .9375rem;
  line-height: 1.5;
  color: var(--ink-700);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-700); }
h1, h2, h3, h4 { font-family: var(--font-display); color: var(--ink-900); font-weight: 560; line-height: 1.15; margin: 0; letter-spacing: -.01em; }
button { font-family: inherit; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }
.mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1; }
.muted { color: var(--ink-400); }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ============================================================================
   APP SHELL
   ============================================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "sidebar topbar" "sidebar main";
  min-height: 100vh;
}
.app.is-collapsed { grid-template-columns: var(--sidebar-rail) 1fr; }

/* sidebar */
.sidebar {
  grid-area: sidebar;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 40;
  border-right: 1px solid rgba(255,255,255,.04);
}
.sidebar__brand {
  display: flex; align-items: center; gap: var(--space-3);
  height: var(--topbar-h); padding: 0 var(--space-5);
  color: #fff; flex: 0 0 auto;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar__mark {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--primary) 0%, var(--teal-bright) 100%);
  display: grid; place-items: center; color: #04201f; font-weight: 800;
  font-family: var(--font-display); box-shadow: inset 0 1px 0 rgba(255,255,255,.25);
}
.sidebar__word { font-family: var(--font-display); font-weight: 600; font-size: 1.0625rem; letter-spacing: -.01em; white-space: nowrap; }
.sidebar__word small { display: block; font-family: var(--font-ui); font-size: .625rem; letter-spacing: .14em; text-transform: uppercase; color: var(--sidebar-fg); font-weight: 600; }
.sidebar__nav { flex: 1 1 auto; overflow-y: auto; padding: var(--space-4) var(--space-3); }
.sidebar__group { margin-bottom: var(--space-5); }
.sidebar__label { font-size: .625rem; letter-spacing: .12em; text-transform: uppercase; color: #5f7480; padding: 0 var(--space-3); margin-bottom: var(--space-2); font-weight: 700; }
.navlink {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 10px var(--space-3); border-radius: var(--r-md);
  color: var(--sidebar-fg); font-weight: 500; font-size: .9375rem;
  position: relative; transition: background var(--t-fast), color var(--t-fast);
  white-space: nowrap;
}
.navlink svg { width: 19px; height: 19px; flex: 0 0 auto; opacity: .9; }
.navlink:hover { background: var(--sidebar-hover); color: #e7eef2; }
.navlink.is-active { background: var(--sidebar-active); color: #fff; }
.navlink.is-active::before {
  content: ""; position: absolute; left: -3px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--teal-bright);
}
.is-collapsed .sidebar__word, .is-collapsed .sidebar__label, .is-collapsed .navlink span { display: none; }
.is-collapsed .navlink { justify-content: center; }
.sidebar__foot { padding: var(--space-4); border-top: 1px solid rgba(255,255,255,.06); }

/* topbar */
.topbar {
  grid-area: topbar; position: sticky; top: 0; z-index: 30;
  background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-6); height: var(--topbar-h);
}
.topbar__crumbs { display: flex; align-items: center; gap: var(--space-2); color: var(--ink-400); font-size: .8125rem; }
.topbar__crumbs a { color: var(--ink-500); }
.topbar__crumbs .sep { color: var(--line-strong); }
.topbar__spacer { flex: 1 1 auto; }
.topbar__search { position: relative; width: min(360px, 38vw); }
.topbar__search input {
  width: 100%; height: 40px; border: 1px solid var(--line-strong); border-radius: var(--r-pill);
  padding: 0 var(--space-4) 0 40px; background: var(--surface-2); font-size: .875rem; color: var(--ink-700);
}
.topbar__search input:focus { background: #fff; border-color: var(--primary); box-shadow: var(--ring); }
.topbar__search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--ink-400); }
.iconbtn {
  width: 40px; height: 40px; border-radius: var(--r-md); border: 1px solid transparent;
  background: transparent; color: var(--ink-500); display: grid; place-items: center; cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink-900); }
.iconbtn svg { width: 20px; height: 20px; }
.hamburger { display: none; }

/* main / content */
.main { grid-area: main; min-width: 0; }
.container { max-width: 1320px; margin: 0 auto; padding: var(--space-6) var(--space-7); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); flex-wrap: wrap; }
.page-head h1 { font-size: 1.875rem; }
.page-head .sub { color: var(--ink-500); margin-top: 4px; font-size: .9375rem; }
.page-head__actions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }

/* ============================================================================
   BUTTONS
   ============================================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: 40px; padding: 0 var(--space-4); border-radius: var(--r-md);
  font-weight: 600; font-size: .875rem; line-height: 1; cursor: pointer;
  border: 1px solid transparent; background: var(--surface-2); color: var(--ink-700);
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  white-space: nowrap;
}
.btn svg { width: 17px; height: 17px; }
.btn:hover { background: var(--line); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-1); }
.btn-primary:hover { background: var(--primary-600); }
.btn-primary:active { background: var(--primary-700); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink-700); }
.btn-secondary:hover { background: var(--surface-2); }
/* Advance / money action — amber, distinct from the teal primary and grey ghost buttons */
.btn-advance { background: var(--warning); color: #fff; border-color: #92400E; box-shadow: var(--shadow-1); }
.btn-advance:hover { background: #92400E; }
.btn-advance:active { background: #7a3c06; }
/* Convert-to-patient — green terminal action */
.btn-success { background: var(--success); color: #fff; border-color: #166534; box-shadow: var(--shadow-1); }
.btn-success:hover { background: #166534; }
.btn-success:active { background: #14532d; }
/* Destructive confirm (e.g. Mark as expired) */
.btn-danger { background: var(--danger); color: #fff; border-color: #7f1d1d; box-shadow: var(--shadow-1); }
.btn-danger:hover { background: #991b1b; }
.btn-danger:active { background: #7f1d1d; }
.btn-ghost { background: transparent; color: var(--ink-500); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink-900); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); }
.btn-sm { height: 32px; padding: 0 var(--space-3); font-size: .8125rem; border-radius: var(--r-sm); }
.btn-lg { height: 48px; padding: 0 var(--space-6); font-size: .9375rem; }
.btn-block { width: 100%; }
.btn-icon { width: 40px; padding: 0; }
.btn[disabled], .btn:disabled { opacity: .55; cursor: not-allowed; }

/* ============================================================================
   CARDS / STAT TILES / QUICK ACTIONS
   ============================================================================ */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-5) var(--space-5) var(--space-4); border-bottom: 1px solid var(--line); }
.card-head h3 { font-size: 1.0625rem; }
.card-head .card-tools { display: flex; gap: var(--space-2); }
.card-body { padding: var(--space-5); }
.card-interactive { transition: transform var(--t), box-shadow var(--t); cursor: pointer; }
.card-interactive:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }

.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-4); }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--space-5); box-shadow: var(--shadow-1); display: flex; gap: var(--space-4); align-items: flex-start; justify-content: space-between; }
.stat__label { font-size: .6875rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-400); font-weight: 700; }
.stat__value { font-family: var(--font-display); font-size: 1.875rem; color: var(--ink-900); line-height: 1.1; margin-top: 6px; }
.stat__sub { font-size: .8125rem; color: var(--ink-500); margin-top: 4px; }
.stat__sub.up { color: var(--success); } .stat__sub.down { color: var(--danger); }
.chip-icon { width: 44px; height: 44px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--primary-050); color: var(--primary); flex: 0 0 auto; }
.chip-icon svg { width: 22px; height: 22px; }

.action-card { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-5); text-align: left; }
.action-card h4 { font-family: var(--font-ui); font-weight: 700; font-size: .9375rem; color: var(--ink-900); margin: 0; }
.action-card p { margin: 2px 0 0; font-size: .8125rem; color: var(--ink-500); }
.action-card .go { margin-left: auto; color: var(--ink-400); }

/* ============================================================================
   TABLES
   ============================================================================ */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); overflow: hidden; }
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table thead th {
  text-align: left; font-size: .6875rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-500); font-weight: 700; background: var(--surface-2);
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table tbody td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); color: var(--ink-700); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr.is-selected { background: var(--primary-050); }
.table .num, .table .amount { font-family: var(--font-mono); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .col-actions { text-align: right; white-space: nowrap; }

/* ============================================================================
   BADGES / CHIPS / DOTS
   ============================================================================ */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 10px; border-radius: var(--r-pill); font-size: .6875rem; font-weight: 700; letter-spacing: .02em; color: #fff; text-transform: uppercase; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.is-new { background: var(--st-new); }
.badge.is-upcoming { background: var(--st-upcoming); }
.badge.is-active { background: var(--st-active); }
.badge.is-online { background: var(--st-online); }
.badge.is-hold { background: var(--st-hold); }
.badge.is-followup { background: var(--st-followup); color: #221900; } /* gold needs dark text */
.badge.is-rejected { background: var(--st-rejected); }
.badge.is-expired { background: var(--st-expired); }
.badge.is-muted { background: var(--surface-2); color: var(--ink-500); }

.chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--r-pill); font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--ink-700); }
.chip.tint-teal { background: var(--primary-050); color: var(--primary-700); }
.chip.tint-info { background: var(--info-050); color: var(--info); }
.chip.tint-success { background: var(--success-050); color: var(--success); }
.chip.tint-warning { background: var(--warning-050); color: var(--warning); }
.chip.tint-danger { background: var(--danger-050); color: var(--danger); }
.dot-status { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ============================================================================
   FORMS
   ============================================================================ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4) var(--space-5); }
.form-grid .col-span-2 { grid-column: 1 / -1; }
.form-section { margin-bottom: var(--space-7); }
.form-section > .section-title { font-size: .6875rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-400); font-weight: 700; padding-bottom: var(--space-3); margin-bottom: var(--space-5); border-bottom: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: .8125rem; font-weight: 600; color: var(--ink-700); }
.field .req { color: var(--danger); margin-left: 2px; }
.field .hint { font-size: .75rem; color: var(--ink-400); }
.field .error { font-size: .75rem; color: var(--danger); }
.input, .select, .textarea {
  width: 100%; height: 42px; padding: 0 var(--space-3); border: 1px solid var(--line-strong);
  border-radius: var(--r-md); background: var(--surface); color: var(--ink-900); font-size: .9375rem; font-family: inherit;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.textarea { height: auto; min-height: 96px; padding: var(--space-3); resize: vertical; }
.select { 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='%235A6B76' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: var(--ring); }
.input::placeholder, .textarea::placeholder { color: var(--ink-400); }
/* File inputs: the fixed 42px text-input height leaves a tall empty box; size to content + theme the picker button */
input[type="file"].input { height: auto; min-height: 42px; padding: 7px var(--space-3); line-height: 1.5; color: var(--ink-500); font-size: .875rem; display: flex; align-items: center; }
input[type="file"].input::-webkit-file-upload-button,
input[type="file"].input::file-selector-button {
  margin-right: var(--space-3); padding: 6px 12px; border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink-700); font: inherit; cursor: pointer;
}
input[type="file"].input::-webkit-file-upload-button:hover,
input[type="file"].input::file-selector-button:hover { background: var(--line); }
/* "View current file" link shown under a file input when an upload already exists (edit enquiry) */
.enq-file-link { display: inline-flex; align-items: center; gap: 5px; margin-top: 6px; color: var(--primary); font-size: .8125rem; font-weight: 600; text-decoration: none; }
.enq-file-link:hover { text-decoration: underline; }
.enq-file-link svg { width: 14px; height: 14px; }
/* patient auto-suggest dropdown (Medical History) */
.medhist-suggest { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md); box-shadow: var(--shadow-3); max-height: 300px; overflow-y: auto; margin-top: 4px; padding: 4px; }
.medhist-suggest .opt { padding: 9px 12px; cursor: pointer; font-size: .9rem; border-radius: var(--r-sm); }
.medhist-suggest .opt + .opt { margin-top: 1px; }
.medhist-suggest .opt:hover { background: var(--primary-050); }
.medhist-suggest .opt strong { font-weight: 600; color: var(--ink-900); }

/* Medical History detail — masonry-style columns so uneven cards don't leave a big gap */
.detail-columns { column-gap: var(--space-5); }
@media (min-width: 1100px) { .detail-columns { column-count: 2; } }
.detail-columns > .card { break-inside: avoid; -webkit-column-break-inside: avoid; page-break-inside: avoid; margin: 0 0 var(--space-5); display: inline-block; width: 100%; }

/* compact progress bar (list) — clickable, opens the View screen */
.progress-mini { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; cursor: pointer; }
.progress-mini .bar { display: block; width: 120px; height: 10px; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; }
.progress-mini .bar > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .2s; }
.progress-mini .lbl { font-size: .78rem; font-weight: 600; color: var(--ink-700); font-variant-numeric: tabular-nums; }
a.progress-mini:hover .bar { box-shadow: 0 0 0 2px var(--primary-050); border-color: var(--primary); }
a.progress-mini:hover .lbl { color: var(--primary); }

/* pedigree (genogram) legend */
.ped-legend { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-top: var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--line); font-size: .8125rem; color: var(--ink-500); }
.ped-legend span { display: inline-flex; align-items: center; gap: 6px; }
#pedigreeChart svg { max-width: none; }
.field.invalid .input, .field.invalid .select, .field.invalid .textarea, .input-validation-error { border-color: var(--danger) !important; background: var(--danger-050); }
.field-validation-error { color: var(--danger); font-size: .75rem; }
.validation-summary-errors { background: var(--danger-050); border: 1px solid #f0c8c8; color: #8a1414; border-radius: var(--r-md); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4); font-size: .875rem; }
.validation-summary-errors ul { margin: 0; padding-left: 18px; }
.check { display: inline-flex; align-items: center; gap: var(--space-2); font-size: .875rem; color: var(--ink-700); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }

/* dropzone */
.dropzone { border: 1.5px dashed var(--line-strong); border-radius: var(--r-md); background: var(--surface-2); padding: var(--space-6); text-align: center; cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast); }
.dropzone:hover, .dropzone.is-drag { border-color: var(--primary); background: var(--primary-050); }
.dropzone .dz-icon { width: 44px; height: 44px; border-radius: var(--r-md); background: var(--surface); display: grid; place-items: center; margin: 0 auto var(--space-3); color: var(--primary); box-shadow: var(--shadow-1); }
.dropzone .dz-title { font-weight: 600; color: var(--ink-700); font-size: .875rem; }
.dropzone .dz-hint { font-size: .75rem; color: var(--ink-400); margin-top: 2px; }
.file-chip { display: inline-flex; align-items: center; gap: var(--space-2); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 5px 6px 5px 12px; font-size: .8125rem; margin: var(--space-2) var(--space-2) 0 0; }
.file-chip .x { width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--ink-500); cursor: pointer; display: grid; place-items: center; }

/* ============================================================================
   TABS
   ============================================================================ */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); }
.tab { position: relative; display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-4); border: 0; background: transparent; color: var(--ink-500); font-weight: 600; font-size: .875rem; cursor: pointer; white-space: nowrap; border-radius: var(--r-sm) var(--r-sm) 0 0; }
.tab:hover { color: var(--ink-900); background: var(--surface-2); }
.tab .count { font-family: var(--font-mono); font-size: .75rem; background: var(--surface-2); color: var(--ink-500); border-radius: var(--r-pill); padding: 1px 8px; }
.tab.is-active { color: var(--ink-900); }
.tab.is-active::after { content: ""; position: absolute; left: var(--space-3); right: var(--space-3); bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--tab-color, var(--primary)); }
.tab.is-active .count { background: var(--tab-color, var(--primary)); color: #fff; }

/* Reusable filter/search bar — inputs + actions on one wrapping row, left-aligned (no dead space).
   Use everywhere a list has a date/search filter: <form class="filter-bar"> … <div class="filter-actions">buttons</div> */
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-4); }
.filter-bar > .field { margin: 0; flex: 0 0 auto; min-width: 180px; }
.filter-bar .filter-actions { display: flex; gap: .6rem; align-items: flex-end; flex-shrink: 0; }

/* ============================================================================
   STEPPER (6-step journey)
   ============================================================================ */
.stepper { display: flex; align-items: flex-start; gap: 0; }
.step { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; text-align: center; position: relative; min-width: 0; }
.step::before, .step::after { content: ""; position: absolute; top: 17px; height: 2px; background: var(--line-strong); z-index: 0; }
.step::before { left: 0; right: 50%; } .step::after { left: 50%; right: 0; }
.step:first-child::before, .step:last-child::after { display: none; }
.step.is-done::before, .step.is-done::after, .step.is-current::before { background: var(--primary); }
.step__node { position: relative; z-index: 1; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 2px solid var(--line-strong); color: var(--ink-400); font-weight: 700; font-size: .875rem; }
.step.is-done .step__node { background: var(--primary); border-color: var(--primary); color: #fff; }
.step.is-current .step__node { border-color: var(--primary); color: var(--primary); box-shadow: var(--ring); }
.step.is-na .step__node { border-style: dashed; }
.step__label { font-size: .75rem; color: var(--ink-500); margin-top: var(--space-2); font-weight: 600; padding: 0 4px; }
.step.is-current .step__label, .step.is-done .step__label { color: var(--ink-900); }

/* ============================================================================
   TIMELINE (audit / approval)
   ============================================================================ */
.timeline { position: relative; padding-left: var(--space-6); }
.timeline::before { content: ""; position: absolute; left: 7px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding-bottom: var(--space-5); }
.tl-item:last-child { padding-bottom: 0; }
.tl-item .tl-dot { position: absolute; left: calc(-1 * var(--space-6) + 1px); top: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--ink-400); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.tl-item.ok .tl-dot { background: var(--success); } .tl-item.no .tl-dot { background: var(--danger); } .tl-item.wait .tl-dot { background: var(--ink-400); }
.tl-item .tl-time { font-family: var(--font-mono); font-size: .75rem; color: var(--ink-400); }
.tl-item .tl-title { font-weight: 600; color: var(--ink-900); font-size: .875rem; }
.tl-item .tl-meta { font-size: .8125rem; color: var(--ink-500); }
.tl-item .tl-body { font-size: .8125rem; color: var(--ink-700); margin-top: 4px; background: var(--surface-2); border-radius: var(--r-sm); padding: var(--space-2) var(--space-3); }

/* ============================================================================
   SCHEDULE GRID
   ============================================================================ */
.sched-toolbar { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--primary-050); border: 1px solid var(--primary-100, #cfe6e5); border-radius: var(--r-md); margin-bottom: var(--space-4); }
.sched-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); }
.sched { border-collapse: separate; border-spacing: 0; font-size: .8125rem; min-width: 720px; }
.sched th, .sched td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: var(--space-2) var(--space-3); white-space: nowrap; }
.sched thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); font-size: .6875rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-500); }
.sched .patient-col { position: sticky; left: 0; z-index: 1; background: var(--surface); min-width: 200px; box-shadow: 1px 0 0 var(--line); }
.sched thead .patient-col { z-index: 3; background: var(--surface-2); }
.cell-session { display: inline-flex; align-items: center; justify-content: center; min-width: 64px; height: 26px; border-radius: var(--r-sm); font-weight: 700; font-size: .6875rem; cursor: pointer; border: 1px solid transparent; }
.cell-session.hydro { background: var(--info-050); color: var(--info); }
.cell-session.physio { background: var(--primary-050); color: var(--primary-700); }
.cell-session.rest { background: var(--surface-2); color: var(--ink-500); }
.cell-session.both { background: linear-gradient(135deg, var(--info-050) 50%, var(--primary-050) 50%); color: var(--ink-700); }
.cell-session.empty { color: var(--ink-400); border: 1px dashed var(--line-strong); background: transparent; }

/* ============================================================================
   PATIENT CARD + DOCTOR BOARD
   ============================================================================ */
.board-bar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin: var(--space-4) 0; }
.board-bar .spacer { flex: 1 1 auto; }
.worklist-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--space-4); }
.pcard { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--ink-400); border-radius: var(--r-lg); box-shadow: var(--shadow-1); padding: var(--space-4); transition: transform var(--t), box-shadow var(--t); }
.pcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.pcard__top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.pcard__name { font-weight: 700; color: var(--ink-900); font-size: .9375rem; }
.pcard__no { font-size: .75rem; color: var(--ink-400); margin-top: 2px; }
.pcard__meta { font-size: .8125rem; color: var(--ink-500); margin: var(--space-3) 0; min-height: 18px; }
.pcard__foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding-top: var(--space-3); border-top: 1px solid var(--line); }
.skeleton-card { border-left-color: var(--line); }

/* journey two-column layout */
.journey { display: grid; grid-template-columns: 300px 1fr; gap: var(--space-5); align-items: start; }
.journey__aside { position: sticky; top: calc(var(--topbar-h) + var(--space-5)); }
@media (max-width: 1024px) { .journey { grid-template-columns: 1fr; } .journey__aside { position: static; } }
.profile-card .pc-avatar { width: 56px; height: 56px; border-radius: var(--r-md); background: var(--primary-050); color: var(--primary); display: grid; place-items: center; font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; }
.kv { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px dashed var(--line); font-size: .8125rem; }
.kv:last-child { border-bottom: 0; }
.kv dt { color: var(--ink-400); } .kv dd { margin: 0; color: var(--ink-900); font-weight: 600; text-align: right; }

/* ============================================================================
   MODAL
   ============================================================================ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,27,36,.45); backdrop-filter: blur(3px); display: none; align-items: center; justify-content: center; z-index: 100; padding: var(--space-4); }
.modal-backdrop.is-open { display: flex; }
.modal { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-3); width: min(560px, 100%); max-height: 90vh; display: flex; flex-direction: column; animation: pop var(--t) var(--ease); }
.modal.modal-lg { width: min(820px, 100%); }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-5); border-bottom: 1px solid var(--line); flex-shrink: 0; }
.modal__head h3 { font-size: 1.125rem; }
/* A <form> placed directly inside .modal becomes the flex body+foot wrapper, so a tall form scrolls internally and the footer stays pinned. The child combinator scopes this to direct-child forms only — AJAX modals (.modal > .modal__body) are untouched. */
.modal > form { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.modal__body { padding: var(--space-5); overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal__foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--line); flex-shrink: 0; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* ============================================================================
   TOASTS
   ============================================================================ */
.toast-stack { position: fixed; top: var(--space-5); right: var(--space-5); z-index: 200; display: flex; flex-direction: column; gap: var(--space-3); width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: var(--space-3); background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--ink-400); border-radius: var(--r-md); box-shadow: var(--shadow-2); padding: var(--space-3) var(--space-4); animation: slidein var(--t) var(--ease); }
.toast.is-success { border-left-color: var(--success); } .toast.is-success .toast__icon { color: var(--success); }
.toast.is-danger { border-left-color: var(--danger); } .toast.is-danger .toast__icon { color: var(--danger); }
.toast.is-info { border-left-color: var(--info); } .toast.is-info .toast__icon { color: var(--info); }
.toast.is-warning { border-left-color: var(--warning); } .toast.is-warning .toast__icon { color: var(--warning); }
.toast__icon { flex: 0 0 auto; margin-top: 1px; }
.toast__icon svg { width: 20px; height: 20px; }
.toast__msg { flex: 1 1 auto; font-size: .875rem; color: var(--ink-700); }
.toast__close { border: 0; background: transparent; color: var(--ink-400); cursor: pointer; }
@keyframes slidein { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* ============================================================================
   EMPTY / LOADING / SKELETON
   ============================================================================ */
.empty-state { text-align: center; padding: var(--space-9) var(--space-5); color: var(--ink-500); }
.empty-state .es-icon { width: 56px; height: 56px; border-radius: var(--r-lg); background: var(--surface-2); color: var(--ink-400); display: grid; place-items: center; margin: 0 auto var(--space-4); }
.empty-state h3 { font-family: var(--font-ui); font-weight: 700; color: var(--ink-700); font-size: 1rem; }
.empty-state p { margin: 4px 0 var(--space-4); font-size: .875rem; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, #e6edee 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--r-sm); height: 14px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.is-busy { position: relative; pointer-events: none; } .is-busy::after { content: ""; position: absolute; inset: 0; background: rgba(255,255,255,.6); }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--line-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================================
   PAGINATION + misc utilities
   ============================================================================ */
.pager { display: flex; gap: 4px; align-items: center; justify-content: flex-end; padding: var(--space-3) 0; }
.pager a, .pager span { min-width: 34px; height: 34px; padding: 0 8px; border-radius: var(--r-sm); display: inline-flex; align-items: center; justify-content: center; font-size: .8125rem; border: 1px solid var(--line); color: var(--ink-700); background: var(--surface); font-family: var(--font-mono); }
.pager .is-current { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager .disabled { opacity: .45; pointer-events: none; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.inline { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.mt-4 { margin-top: var(--space-4); } .mt-6 { margin-top: var(--space-6); } .mb-4 { margin-bottom: var(--space-4); }
.text-right { text-align: right; } .nowrap { white-space: nowrap; }

.alert-strip { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--r-md); font-size: .875rem; }
.alert-strip.warn { background: var(--warning-050); color: #7a3c06; border: 1px solid #efd6bb; }
.alert-strip.info { background: var(--info-050); color: #173a9e; border: 1px solid #c9d6f6; }

/* staggered page-load reveal */
.reveal { opacity: 0; transform: translateY(8px); animation: fadeup var(--t-slow) var(--ease) forwards; }
.reveal:nth-child(2){animation-delay:.04s}.reveal:nth-child(3){animation-delay:.08s}.reveal:nth-child(4){animation-delay:.12s}.reveal:nth-child(5){animation-delay:.16s}.reveal:nth-child(6){animation-delay:.2s}
@keyframes fadeup { to { opacity: 1; transform: none; } }

/* ============================================================================
   DROPDOWN (native <details>) / AVATAR / NOTIFICATION
   ============================================================================ */
.dropdown { position: relative; }
.dropdown > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: var(--space-2); }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown[open] > summary ~ .menu-pop { animation: pop var(--t-fast) var(--ease); }
.menu-pop { position: absolute; right: 0; top: calc(100% + 8px); min-width: 224px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-2); padding: 6px; z-index: 50; }
.menu-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r-sm); color: var(--ink-700); font-size: .875rem; width: 100%; background: transparent; border: 0; text-align: left; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); color: var(--ink-900); }
.menu-item svg { width: 17px; height: 17px; color: var(--ink-400); }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu-head { padding: 8px 10px; }
.menu-head .nm { font-weight: 700; color: var(--ink-900); font-size: .875rem; }
.menu-head .rl { font-size: .75rem; color: var(--ink-400); text-transform: uppercase; letter-spacing: .06em; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary-050); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: .8125rem; flex: 0 0 auto; }
.user-btn { padding: 4px 8px 4px 4px; border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--surface); }
.user-btn .un { font-size: .8125rem; font-weight: 600; color: var(--ink-900); line-height: 1.1; }
.user-btn .ur { font-size: .6875rem; color: var(--ink-400); }
.notif-dot { position: relative; }
.notif-dot .count { position: absolute; top: 3px; right: 3px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--r-pill); background: var(--danger); color: #fff; font-size: .625rem; font-weight: 700; display: grid; place-items: center; font-family: var(--font-mono); }
.notif-empty { padding: var(--space-5); text-align: center; color: var(--ink-400); font-size: .8125rem; }

/* ============================================================================
   AUTH (login / change-password / error) — uses _LayoutAuth, no app chrome
   ============================================================================ */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; background: var(--bg); }
.auth__aside {
  position: relative; overflow: hidden; color: #eafaf9; padding: var(--space-9) var(--space-8);
  display: flex; flex-direction: column; justify-content: space-between;
  background:
    radial-gradient(1100px 600px at -10% -10%, rgba(52,209,204,.30), transparent 60%),
    radial-gradient(900px 700px at 120% 120%, rgba(14,124,123,.55), transparent 55%),
    linear-gradient(150deg, #0F1B24 0%, #0c2a2a 55%, #083e3c 100%);
}
.auth__aside::after {
  content: ""; position: absolute; inset: 0; opacity: .5; pointer-events: none;
  background-image: radial-gradient(rgba(255,255,255,.10) 1px, transparent 1.4px);
  background-size: 22px 22px; mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent);
}
.auth__brand { display: flex; align-items: center; gap: var(--space-3); position: relative; z-index: 1; }
.auth__mark { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, var(--primary) 0%, var(--teal-bright) 100%); display: grid; place-items: center; color: #04201f; font-family: var(--font-display); font-weight: 800; font-size: 1.25rem; box-shadow: inset 0 1px 0 rgba(255,255,255,.3); }
.auth__brand .w { font-family: var(--font-display); font-size: 1.25rem; color: #fff; line-height: 1; }
.auth__brand .w small { display: block; font-family: var(--font-ui); font-size: .625rem; letter-spacing: .16em; text-transform: uppercase; color: #9fded9; margin-top: 3px; }
.auth__pitch { position: relative; z-index: 1; max-width: 460px; }
.auth__pitch h2 { font-family: var(--font-display); font-size: 2.25rem; color: #fff; line-height: 1.12; letter-spacing: -.02em; }
.auth__pitch p { color: #b7d8d5; font-size: 1rem; margin-top: var(--space-3); }
.auth__points { list-style: none; margin: var(--space-6) 0 0; padding: 0; position: relative; z-index: 1; display: grid; gap: var(--space-3); }
.auth__points li { display: flex; align-items: center; gap: var(--space-3); color: #d6ecea; font-size: .9375rem; }
.auth__points svg { width: 18px; height: 18px; color: var(--teal-bright); flex: 0 0 auto; }
.auth__foot { position: relative; z-index: 1; color: #7fb3af; font-size: .75rem; }

.auth__main { display: grid; place-items: center; padding: var(--space-7) var(--space-5); }
.auth-card { width: min(420px, 100%); }
.auth-card .auth-head { margin-bottom: var(--space-6); }
.auth-card .auth-head h1 { font-size: 1.625rem; }
.auth-card .auth-head p { color: var(--ink-500); margin-top: 6px; font-size: .9375rem; }
.pw-wrap { position: relative; }
.pw-wrap .pw-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; }
.pw-wrap .pw-toggle.is-on { color: var(--primary); }
.auth-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.captcha-box { display: flex; align-items: center; gap: var(--space-3); }
.captcha-img { height: 46px; min-width: 130px; border-radius: var(--r-md); border: 1px solid var(--line-strong); background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 8px, #e6edee 8px, #e6edee 16px); display: grid; place-items: center; font-family: var(--font-mono); letter-spacing: .35em; color: var(--ink-500); font-weight: 600; user-select: none; }
.auth-aside-mini { display: none; }
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth__aside { display: none; }
  .auth-aside-mini { display: flex; align-items: center; gap: var(--space-3); justify-content: center; margin-bottom: var(--space-6); }
}

/* error pages reuse the auth canvas */
.errwrap { min-height: 100vh; display: grid; place-items: center; padding: var(--space-7); }
.errcard { text-align: center; max-width: 460px; }
.errcode { font-family: var(--font-display); font-size: 4.5rem; line-height: 1; color: var(--primary); }

/* ============================================================================
   RESPONSIVE
   ============================================================================ */
@media (max-width: 1024px) {
  .app, .app.is-collapsed { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
  .sidebar { position: fixed; left: 0; top: 0; width: var(--sidebar-w); transform: translateX(-100%); transition: transform var(--t) var(--ease); }
  .app.drawer-open .sidebar { transform: none; box-shadow: var(--shadow-3); }
  .scrim { position: fixed; inset: 0; background: rgba(15,27,36,.45); z-index: 35; display: none; }
  .app.drawer-open .scrim { display: block; }
  .hamburger { display: grid; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .container { padding: var(--space-5) var(--space-4); }
  .topbar__search { display: none; }
}
@media (max-width: 768px) {
  .form-grid { grid-template-columns: 1fr; }
  .stepper { flex-direction: column; align-items: stretch; gap: var(--space-2); }
  .step { flex-direction: row; align-items: center; gap: var(--space-3); text-align: left; }
  .step::before, .step::after { display: none; }
  .page-head { align-items: flex-start; }
}

@media print {
  .sidebar, .topbar, .page-head__actions, .toast-stack, .pager { display: none !important; }
  .app { display: block; } .container { max-width: none; padding: 0; }
  .card, .table-wrap { box-shadow: none; border-color: #ccc; }
}

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

/* ============================================================================
   BATCH 6 — sensitive reveal, notification list, validation states
   ============================================================================ */
.sensitive { display: inline-flex; align-items: center; gap: 6px; }
.masked-value { font-family: var(--font-mono); letter-spacing: .02em; }
.reveal-btn { width: 24px; height: 24px; border: 0; border-radius: 6px; background: var(--surface-2); color: var(--ink-500); cursor: pointer; display: inline-grid; place-items: center; padding: 0; }
.reveal-btn:hover { background: var(--primary-050); color: var(--primary); }

.notif-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 12px; border-radius: var(--r-sm); cursor: pointer; border-bottom: 1px solid var(--line); }
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread { background: var(--primary-050); }
.notif-item .ni-title { font-weight: 600; color: var(--ink-900); font-size: .8125rem; }
.notif-item .ni-body { color: var(--ink-500); font-size: .75rem; margin-top: 2px; }
.notif-item .ni-time { color: var(--ink-400); font-size: .6875rem; margin-top: 4px; font-family: var(--font-mono); }

/* jQuery Validate output: hide the valid placeholder, flag invalid controls */
.field-validation-valid { display: none; }
input.input-validation-error, select.input-validation-error, textarea.input-validation-error { border-color: var(--danger); background: var(--danger-050); }
