/* catharsiA — green/white clinical design system · v4 */

:root {
  --bg:           #F4F4F5;
  --surface:      #FFFFFF;
  --surface-2:    #FAFAFA;
  --surface-3:    #F4F4F5;
  --ink:          #09090B;
  --ink-2:        #27272A;
  --muted:        #71717A;
  --muted-2:      #A1A1AA;
  --border:       rgba(0,0,0,0.05);
  --border-strong:rgba(0,0,0,0.1);
  --accent:       #10B981;
  --accent-2:     #059669;
  --accent-deep:  #047857;
  --accent-ink:   #FFFFFF;
  --accent-soft:  #D1FAE5;
  --accent-tint:  #ECFDF5;
  --ok:           #10B981;
  --ok-soft:      #D1FAE5;
  --warn:         #F59E0B;
  --warn-soft:    #FEF3C7;
  --danger:       #EF4444;
  --danger-soft:  #FEE2E2;
  --ai:           #6366F1;
  --ai-soft:      #E0E7FF;
  --teal:         #14B8A6;
  --teal-soft:    #CCFBF1;
  --info:         #3B82F6;
  --info-soft:    #DBEAFE;
  --shadow-sm:    0 2px 4px rgba(0,0,0,0.02), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:       0 4px 12px rgba(0,0,0,0.03), 0 2px 4px rgba(0,0,0,0.04), 0 0 0 1px rgba(0,0,0,0.02) inset;
  --shadow-md:    0 12px 24px -4px rgba(0,0,0,0.05), 0 8px 16px -4px rgba(0,0,0,0.04), 0 0 0 1px rgba(0,0,0,0.02) inset;
  --shadow-lg:    0 24px 48px -12px rgba(0,0,0,0.15), 0 12px 24px -8px rgba(0,0,0,0.1), 0 0 0 1px rgba(0,0,0,0.02) inset;
  --shadow-focus: 0 0 0 3px rgba(16,185,129,0.25);
  --radius-sm:    12px;
  --radius:       20px;
  --radius-lg:    28px;
  --font-serif:   'Newsreader', Georgia, serif;
  --font-sans:    'Instrument Sans', 'Inter', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, monospace;
}

[data-theme="dark"] {
  --bg:           #000000;
  --surface:      #09090B;
  --surface-2:    #18181B;
  --surface-3:    #27272A;
  --ink:          #FAFAFA;
  --ink-2:        #E4E4E7;
  --muted:        #A1A1AA;
  --muted-2:      #71717A;
  --border:       rgba(255,255,255,0.08);
  --border-strong:rgba(255,255,255,0.12);
  --accent:       #34D399;
  --accent-2:     #10B981;
  --accent-deep:  #059669;
  --accent-ink:   #000000;
  --accent-soft:  #064E3B;
  --accent-tint:  #022C22;
  --ok:           #34D399;
  --ok-soft:      #064E3B;
  --warn:         #FBBF24;
  --warn-soft:    #78350F;
  --danger:       #F87171;
  --danger-soft:  #7F1D1D;
  --ai:           #818CF8;
  --ai-soft:      #312E81;
  --teal:         #2DD4BF;
  --teal-soft:    #134E4A;
  --info:         #60A5FA;
  --info-soft:    #1E3A8A;
  --shadow-sm:    0 2px 4px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.6);
  --shadow:       0 4px 12px rgba(0,0,0,0.6), 0 2px 4px rgba(0,0,0,0.8), 0 0 0 1px rgba(255,255,255,0.03) inset;
  --shadow-md:    0 12px 24px -4px rgba(0,0,0,0.8), 0 8px 16px -4px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.03) inset;
  --shadow-lg:    0 24px 48px -12px rgba(0,0,0,1), 0 12px 24px -8px rgba(0,0,0,0.8), 0 0 0 1px rgba(255,255,255,0.03) inset;
  --shadow-focus: 0 0 0 3px rgba(52,211,153,0.25);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  background-image: radial-gradient(circle at 50% 0%, rgba(16, 185, 129, 0.03), transparent 60%), radial-gradient(circle at 0% 100%, rgba(99, 102, 241, 0.02), transparent 50%);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  position: relative;
}
body::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
  opacity: 0.035;
}
[data-theme="dark"] body::before { opacity: 0.055; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.serif { font-family: var(--font-serif); font-weight: 400; letter-spacing: -0.01em; }
.mono  { font-family: var(--font-mono); font-feature-settings: "zero"; }

/* ---- App shell ---- */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh; width: 100vw;
  min-height: 0;
}

/* ---- Sidebar ---- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 12px 12px;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 6px 14px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  display: grid; place-items: center;
  color: white; font-family: var(--font-serif); font-style: italic;
  font-size: 17px; flex-shrink: 0;
  box-shadow: 0 2px 6px -2px rgba(22,163,74,0.5), inset 0 1px 0 rgba(255,255,255,0.18);
}
.brand-name { font-family: var(--font-serif); font-size: 20px; letter-spacing: -0.02em; color: var(--ink); }
.brand-name em { font-style: italic; color: var(--accent); }
.brand-sub { margin-left: auto; font-family: var(--font-mono); font-size: 10px; color: var(--muted); letter-spacing: 0.08em; }

.nav-section-label, .nav-group-label {
  font-family: var(--font-mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--muted); padding: 0 8px; margin-bottom: 4px;
}
.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-size: 13.5px; cursor: pointer;
  position: relative;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active {
  background: var(--accent-soft); color: var(--accent-2); font-weight: 500;
}
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 6px; bottom: 6px;
  width: 3px; background: var(--accent); border-radius: 0 3px 3px 0;
}
.nav-item .count {
  margin-left: auto; font-family: var(--font-mono); font-size: 11px;
  color: var(--muted); background: var(--surface-2);
  padding: 1px 7px; border-radius: 999px;
}
.nav-item.active .count { background: var(--surface); color: var(--accent-2); }

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 6px; border-radius: var(--radius-sm); cursor: pointer;
}
.user-card:hover { background: var(--surface-2); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  font-family: var(--font-serif); font-size: 12px; font-weight: 500; flex-shrink: 0;
}
.user-meta .n { font-size: 13px; font-weight: 500; }
.user-meta .r { font-size: 11px; color: var(--muted); }

.sync-row {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 6px; font-family: var(--font-mono);
  font-size: 10.5px; color: var(--muted);
}
.sync-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); flex-shrink: 0; }
.sync-dot.pending { background: var(--warn); }
.sync-dot.offline { background: var(--muted); }

/* ---- Main ---- */
.main { display: grid; grid-template-rows: 52px 1fr; min-width: 0; min-height: 0; }
.topbar {
  border-bottom: 1px solid var(--border);
  padding: 0 24px; display: flex; align-items: center; gap: 14px;
  background: var(--surface);
}
.breadcrumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.breadcrumbs .cur { color: var(--ink); font-weight: 500; }
.breadcrumbs .sep { color: var(--muted-2); }

.search {
  margin-left: auto; display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; width: 300px;
  transition: border-color 0.15s, background 0.15s;
}
.search:hover { border-color: var(--border-strong); }
.search:focus-within { border-color: var(--accent); background: var(--surface); box-shadow: var(--shadow-focus); }
.search input { background: none; border: 0; outline: 0; flex: 1; font-size: 13px; }
.search input::placeholder { color: var(--muted); }
.search kbd {
  font-family: var(--font-mono); font-size: 10px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px;
  background: var(--surface);
}
.topbar-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: var(--radius-sm); color: var(--muted);
  transition: background 0.12s, color 0.12s;
}
.topbar-btn:hover { background: var(--surface-2); color: var(--accent-2); }

.content { overflow-y: auto; overflow-x: hidden; padding: 24px 32px 80px; -webkit-overflow-scrolling: touch; min-height: 0; }

.page-head {
  display: flex; align-items: flex-end; gap: 20px;
  margin-bottom: 24px; padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.page-title {
  font-family: var(--font-serif); font-size: 40px;
  letter-spacing: -0.03em; font-weight: 500; line-height: 1.1;
  color: var(--ink);
}
.page-title em { font-style: italic; color: var(--accent); }
.page-sub { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  font-size: 13.5px; font-weight: 500; white-space: nowrap; color: var(--ink-2);
  transition: all 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
  box-shadow: var(--shadow-sm);
}
.btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--ink);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  letter-spacing: 0.01em;
}
.btn:active { transform: translateY(1px) scale(0.97); }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: var(--accent-ink); border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(16,185,129,0.3), inset 0 1px 0 rgba(255,255,255,0.2);
}
.btn.primary:hover {
  background: linear-gradient(180deg, var(--accent-2), var(--accent-deep));
  border-color: var(--accent-2);
  color: var(--accent-ink);
  box-shadow: 0 6px 16px rgba(16,185,129,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
}
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-2); box-shadow: none; transform: none; }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.teal { background: var(--ai); color: white; border-color: var(--ai); }
.btn.teal:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
.btn.sm { padding: 5px 10px; font-size: 12px; }

/* ---- Chips ---- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; font-size: 11.5px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  font-weight: 500; line-height: 1.4;
}
.chip.ok     { background: var(--ok-soft);     color: var(--ok);     border-color: transparent; }
.chip.warn   { background: var(--warn-soft);   color: var(--warn);   border-color: transparent; }
.chip.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip.ai     { background: var(--ai-soft);     color: var(--ai);     border-color: transparent; }
.chip.teal   { background: var(--teal-soft);   color: var(--teal);   border-color: transparent; }
.chip.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.info   { background: var(--info-soft);   color: var(--info);   border-color: transparent; }
.chip.solid  { background: var(--ink); color: var(--surface); border-color: var(--ink); }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1), box-shadow 0.4s ease, border-color 0.2s;
  animation: card-enter 0.6s cubic-bezier(0.2, 0.9, 0.3, 1) backwards;
}
@keyframes card-enter {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-4px) scale(1.005);
}
.card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.card-head h3 { font-size: 13.5px; font-weight: 500; letter-spacing: -0.005em; color: var(--ink); }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card.elevated { box-shadow: var(--shadow-md); border-color: transparent; }
.card.accent {
  background: linear-gradient(135deg, var(--accent-tint), var(--surface));
  border-color: var(--accent-soft);
}

/* ---- AI callout ---- */
.ai-note {
  border: 1px solid var(--ai-soft);
  background: linear-gradient(135deg, var(--ai-soft), var(--surface));
  border-radius: var(--radius); padding: 12px 14px;
  font-size: 13px; color: var(--ink-2);
  display: flex; gap: 12px; align-items: flex-start;
  position: relative;
}
.ai-note::before {
  content: ""; position: absolute; left: 0; top: 12px; bottom: 12px;
  width: 3px; background: var(--ai); border-radius: 0 2px 2px 0;
}
.ai-note .glyph { color: var(--ai); font-family: var(--font-serif); font-size: 16px; line-height: 1; flex-shrink: 0; }
.ai-note .label {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ai); margin-bottom: 4px; display: block;
  font-weight: 600;
}
.ai-note .actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Tables ---- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-weight: 600; color: var(--muted);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr { cursor: pointer; transition: background 0.1s; }
.table tbody tr:hover { background: var(--accent-tint); }
.table tbody tr:last-child td { border-bottom: 0; }
/* Table scroll wrapper — keeps tables fluid inside cards on narrow viewports */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap > .table { min-width: max-content; }

/* Patient mobile card list (alternative to data table) */
.patient-cards { display: flex; flex-direction: column; gap: 12px; }
.patient-card { cursor: pointer; transition: border-color 0.12s, transform 0.12s; }
.patient-card:hover { border-color: var(--accent-soft); }
.patient-card:active { transform: scale(0.995); }
.patients-search { width: 220px; }

/* ---- Live session (mobile) ---- */
.overlay.live-mobile {
  position: fixed; inset: 0;
  display: block;
  padding: 0;
  place-items: initial;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.live-topbar-mobile {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.live-more-menu {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.live-more-menu .btn { justify-content: flex-start; padding: 10px 12px; }
.btn.icon {
  width: 34px; height: 34px;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn.icon svg { margin: 0; }

.live-session-shell {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr);
  background: var(--bg);
  min-height: 0;
}

.live-session-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}

.live-session-main {
  overflow: auto;
  padding: 28px 40px;
  min-height: 0;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}

.live-session-side {
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.live-session-transcript {
  padding: 18px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* SUD multi-grid responsive */
@media (max-width: 720px) {
  .sud-grid { grid-template-columns: 80px repeat(3, 1fr) !important; gap: 6px !important; }
  .sud-grid input[type="number"] { width: 32px !important; font-size: 11.5px !important; }
}

/* ---- Tabs ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 16px; font-size: 13px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer;
  transition: color 0.3s, border-color 0.3s, background 0.3s;
  position: relative;
}
.tab:hover {
  color: var(--ink);
  background: var(--surface-2);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.tab.active { color: var(--accent-2); border-bottom-color: var(--accent); font-weight: 500; }

/* ---- Grid helpers ---- */
.grid   { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.row    { display: flex; align-items: center; gap: 10px; }
.col    { display: flex; flex-direction: column; gap: 10px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mt-4{margin-top:4px} .mt-8{margin-top:8px} .mt-12{margin-top:12px} .mt-16{margin-top:16px} .mt-24{margin-top:24px}
.mb-4{margin-bottom:4px} .mb-8{margin-bottom:8px} .mb-12{margin-bottom:12px} .mb-16{margin-bottom:16px} .mb-24{margin-bottom:24px}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny  { font-size: 11px; }
.tnum  { font-variant-numeric: tabular-nums; }

/* ---- Progress bar ---- */
.prog { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.prog > div { height: 100%; background: var(--accent); border-radius: 3px; }

/* ---- Forms ---- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; color: var(--muted); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 500; }
.input, textarea.input, select.input {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px;
  font-size: 13px; outline: 0; resize: vertical;
  transition: border-color 0.12s, box-shadow 0.12s;
  width: 100%; box-sizing: border-box; display: block;
}
.input:hover { border-color: var(--border-strong); }
.input:focus, textarea.input:focus, select.input:focus {
  border-color: var(--accent); background: var(--surface);
  box-shadow: var(--shadow-focus);
}
textarea.input { min-height: 90px; line-height: 1.5; }

/* ---- SOAP blocks ---- */
.soap-block { border-left: 2px solid var(--accent-soft); padding: 2px 0 2px 14px; margin-bottom: 18px; }
.soap-block .lbl {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted);
  display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
}
.soap-block .lbl .letter {
  width: 18px; height: 18px; border-radius: 4px; background: var(--accent-soft);
  display: grid; place-items: center; color: var(--accent);
  font-weight: 600; font-family: var(--font-serif); font-size: 11px;
}
.soap-block textarea {
  width: 100%; border: 0; background: transparent; outline: 0;
  font-size: 14px; line-height: 1.6; color: var(--ink); resize: vertical; min-height: 64px;
}
.soap-block textarea::placeholder { color: var(--muted-2); }

/* ---- Timeline ---- */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: ""; position: absolute; left: 9px; top: 8px; bottom: 8px;
  width: 1px; background: var(--border);
}
.tl-item { position: relative; padding: 10px 0; }
.tl-item .dot {
  position: absolute; left: -24px; top: 14px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface); border: 1.5px solid var(--border-strong);
}
.tl-item.trauma      .dot { border-color: var(--danger); background: var(--danger-soft); }
.tl-item.eval        .dot { border-color: var(--accent); background: var(--accent-soft); }
.tl-item.session     .dot { border-color: var(--ink); background: var(--ink); }
.tl-item.crisis      .dot { border-color: var(--danger); background: var(--danger); }
.tl-item.intervention .dot { border-color: var(--ok); background: var(--ok-soft); }
.tl-item.note .dot { border-color: var(--info); background: var(--info-soft); }
.tl-date  { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.tl-title { font-size: 13.5px; color: var(--ink); margin-bottom: 2px; }
.tl-body  { font-size: 12.5px; color: var(--muted); }

/* ---- Intensity bar ---- */
.intensity { display: inline-flex; gap: 2px; }
.intensity .seg { width: 5px; height: 10px; border-radius: 1px; background: var(--border); }
.intensity .seg.on { background: var(--accent); }
.intensity.danger .seg.on { background: var(--danger); }
.intensity.warn   .seg.on { background: var(--warn); }
.intensity.ok     .seg.on { background: var(--ok); }

/* ---- Seg ctrl ---- */
.seg-ctrl {
  display: inline-flex; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px;
}
.seg-ctrl button { padding: 3px 8px; font-size: 11px; border-radius: 4px; color: var(--muted); }
.seg-ctrl button.on { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); font-weight: 500; }

/* ---- KV list ---- */
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); font-size: 12px; }

/* ---- Crisis FAB ---- */
.crisis-fab {
  position: fixed; bottom: 22px; right: 22px;
  background: var(--surface); border: 1px solid var(--danger-soft);
  color: var(--danger); border-radius: 999px; padding: 10px 18px;
  font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-lg); z-index: 50;
  transition: background 0.15s, transform 0.1s;
}
.crisis-fab:hover { background: var(--danger-soft); transform: translateY(-1px); }
.crisis-fab .pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--danger); position: relative;
}
.crisis-fab .pulse::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 1px solid var(--danger);
  animation: pulse-ring 2s ease-out infinite; opacity: 0.6;
}
@keyframes pulse-ring { 0%{transform:scale(0.8);opacity:0.6} 100%{transform:scale(1.8);opacity:0} }

/* ---- Modal / Overlay ---- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(11,33,23,0.45); backdrop-filter: blur(6px);
  z-index: 100; display: grid; place-items: center; padding: 40px;
  animation: fadein 0.18s ease;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 640px; max-height: 88vh;
  display: flex; flex-direction: column; overflow: hidden;
  animation: modal-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.modal-body { padding: 20px; overflow: auto; flex: 1; }
.modal-foot {
  padding: 12px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* ---- Crisis overlay ---- */
.crisis-overlay {
  position: fixed; inset: 0;
  background: rgba(15,14,31,0.92); backdrop-filter: blur(12px);
  z-index: 200; display: grid; place-items: center; padding: 40px;
  animation: fadein 0.25s ease;
}
@keyframes fadein { from{opacity:0} to{opacity:1} }
.crisis-panel {
  width: 100%; max-width: 720px; background: var(--surface);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: 0 40px 80px rgba(0,0,0,0.5);
}

/* ---- Breathing ---- */
.breath-circle {
  width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle, var(--accent-soft), transparent 70%);
  border: 1.5px solid var(--accent);
  display: grid; place-items: center;
  font-family: var(--font-serif); font-size: 18px; color: var(--accent);
  animation: breathe 8s ease-in-out infinite;
}
@keyframes breathe { 0%,100%{transform:scale(0.85)} 50%{transform:scale(1.1)} }

/* ---- Likert ---- */
.lik { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.lik button {
  padding: 10px 6px; border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm); text-align: left; font-size: 12.5px;
  line-height: 1.3; color: var(--ink-2);
}
.lik button:hover { border-color: var(--accent); }
.lik button.sel { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.lik button .num { font-family: var(--font-mono); font-size: 11px; color: var(--muted); display: block; margin-bottom: 2px; }
.lik button.sel .num { color: var(--accent); }

/* ---- Spark ---- */
.spark { display: flex; align-items: flex-end; gap: 2px; height: 28px; }
.spark .bar { width: 4px; background: var(--accent); border-radius: 1px 1px 0 0; opacity: 0.85; }

/* ---- Recording dot ---- */
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); display: inline-block; animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* ---- Tweaks panel ---- */
.tweaks {
  position: fixed; bottom: 22px; left: 22px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 12px 14px; width: 280px; z-index: 60;
}
.tweaks .t-title { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.tweaks .t-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.tweaks .t-row:last-child { border-bottom: 0; }

/* ---- Scrollbars ---- */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: var(--accent-2); }
* { scrollbar-color: var(--border) transparent; scrollbar-width: thin; }

/* ---- Selection ---- */
::selection { background: var(--accent-soft); color: var(--accent-deep); }

/* ---- Stat card accent ---- */
.stat-accent {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
}

/* ---- Medication badge ---- */
.med-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--ai-soft); color: var(--ai);
  font-size: 12px; border: 1px solid transparent;
  font-weight: 500;
}

/* ---- Sleep bars ---- */
.sleep-bar {
  height: 10px; background: var(--border); border-radius: 5px; overflow: hidden;
}
.sleep-bar .fill { height: 100%; background: var(--accent); border-radius: 5px; }
.sleep-bar .fill.poor { background: var(--danger); }
.sleep-bar .fill.fair { background: var(--warn); }
.sleep-bar .fill.good { background: var(--ok); }

/* ---- Quick note ---- */
.quick-note {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  background: var(--surface);
  transition: border-color 0.2s;
}
.quick-note:focus-within { border-color: var(--accent); }
.quick-note textarea {
  width: 100%; border: 0; outline: 0; resize: none;
  background: transparent; font-size: 13px; line-height: 1.5;
  color: var(--ink); min-height: 56px;
}
.quick-note textarea::placeholder { color: var(--muted); }

/* ---- Sessions enhanced workflow ---- */
.session-metric {
  position: relative;
  overflow: hidden;
}
.session-metric::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
}
.session-metric.tone-ok::before { background: var(--ok); }
.session-metric.tone-ai::before { background: var(--ai); }
.session-metric.tone-warn::before { background: var(--warn); }
.session-metric.tone-info::before { background: var(--info); }

.session-draft-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--surface), var(--surface-2));
  padding: 14px;
  text-align: left;
  transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
.session-draft-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.session-panel {
  border-color: var(--border);
}

.session-subcard,
.session-stat {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 12px;
}
.session-subtitle {
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.session-insight-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.session-snippets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.session-snippets .chip {
  cursor: pointer;
}

.session-checklist {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.session-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 12.5px;
}
.session-check input {
  accent-color: var(--accent);
}

/* ---- Auth ---- */
.auth-shell {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(22,163,74,0.12), transparent 34%),
    radial-gradient(circle at bottom right, rgba(15,118,110,0.12), transparent 28%),
    var(--bg);
  padding: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-panel {
  width: min(1080px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 20px;
}
.auth-hero,
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
[data-theme="dark"] .auth-hero,
[data-theme="dark"] .auth-card {
  background: var(--surface-2);
  border-color: var(--border);
}
.auth-hero {
  padding: 34px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 20px;
}
.auth-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.auth-card {
  padding: 26px;
}
.auth-form {
  display: grid;
  gap: 12px;
}
.auth-error {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
  border: 1px solid rgba(190,18,60,0.12);
}
.auth-foot {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.auth-user-list {
  display: grid;
  gap: 8px;
}
.auth-user-chip {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color 0.12s ease, background 0.12s ease;
}
.auth-user-chip:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}

/* ---- Heatmap ---- */
.heatmap { display: grid; grid-template-columns: repeat(14, 1fr); gap: 3px; }
.heatmap .cell { aspect-ratio: 1; background: var(--border); border-radius: 2px; }
.heatmap .cell.l1 { background: var(--accent-soft); }
.heatmap .cell.l2 { background: var(--accent-2); opacity: 0.5; }
.heatmap .cell.l3 { background: var(--accent); opacity: 0.7; }
.heatmap .cell.l4 { background: var(--accent); }

/* ---- Mobile menu toggle ---- */
.menu-toggle { display: none; }

/* ============================================================
   Responsive — tablet ≤ 1024, phone ≤ 720
   ============================================================ */

@media (max-width: 1024px) {
  .app { grid-template-columns: 64px 1fr; }
  .auth-panel { grid-template-columns: 1fr; }
  .sidebar { padding: 12px 6px; gap: 10px; }
  .brand-name, .brand-sub, .nav-section-label, .nav-group-label,
  .sidebar .nav-item span:not(.count), .user-meta, .sync-row span:not(.sync-dot) { display: none; }
  .sidebar .nav-item { justify-content: center; padding: 10px 6px; }
  .sidebar .nav-item.active::before { left: -6px; }
  .sidebar .nav-item .count {
    position: absolute; top: 2px; right: 2px;
    background: var(--accent); color: white; font-size: 9px;
    padding: 1px 4px; border-radius: 6px; margin: 0;
  }
  .brand { justify-content: center; padding: 4px 0 10px; }
  .user-card { justify-content: center; padding: 4px; }
  .sync-row { justify-content: center; padding: 0; }

  .topbar { padding: 0 12px; gap: 8px; }
  .breadcrumbs { font-size: 12px; max-width: 220px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .breadcrumbs > span:not(.cur):not(:first-child) { display: none; }
  .breadcrumbs .sep:not(:nth-last-child(2)) { display: none; }
  .search { width: 160px; }
  .search input { font-size: 12px; }

  .content { padding: 16px 16px 100px; }
  .page-head { flex-wrap: wrap; gap: 12px; }
  .page-title { font-size: 22px; }
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
  .kv { grid-template-columns: 100px 1fr; }
  .session-insight-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  body { font-size: 13.5px; }
  .auth-shell { padding: 14px; align-items: stretch; }
  .auth-panel { gap: 14px; }
  .auth-hero, .auth-card { padding: 18px; }
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 64px;
    height: 100dvh;
  }
  .sidebar {
    grid-row: 2;
    flex-direction: row;
    overflow-x: auto; overflow-y: hidden;
    padding: 8px 10px;
    border-top: 1px solid var(--border); border-right: 0;
    gap: 4px;
    background: var(--surface);
    box-shadow: 0 -2px 12px rgba(11,33,23,0.06);
    scroll-snap-type: x proximity;
  }
  .brand, .nav-section-label, .nav-group-label, .sidebar-footer { display: none; }
  .sidebar .nav-group { flex-direction: row; gap: 2px; }
  .sidebar .nav-item {
    padding: 8px 14px; flex-shrink: 0;
    flex-direction: column; gap: 2px;
    font-size: 10px; min-width: 56px;
    border-radius: var(--radius-sm);
    scroll-snap-align: center;
  }
  .sidebar .nav-item svg { width: 20px; height: 20px; }
  .sidebar .nav-item.active::before { display: none; }
  .sidebar .nav-item.active {
    background: var(--accent-soft); color: var(--accent-2);
    font-weight: 600;
  }
  .sidebar .nav-item.active svg { color: var(--accent); }
  .sidebar .nav-item .count {
    position: absolute; top: 2px; right: 6px;
    background: var(--accent); color: white;
    padding: 0 5px; min-width: 14px; height: 14px;
    line-height: 14px; font-size: 9px;
    border-radius: 999px; margin: 0; text-align: center;
  }
  .sidebar .nav-item.active .count { background: var(--accent-deep); color: white; }

  .main { grid-row: 1; grid-template-rows: 52px 1fr; min-height: 0; }
  .topbar {
    padding: 0 14px; gap: 8px; height: 52px;
    position: sticky; top: 0; z-index: 40;
    background: var(--surface);
  }
  .topbar .breadcrumbs { font-size: 13px; flex: 1; min-width: 0; }
  .topbar .search { display: none; }
  .topbar-btn { width: 34px; height: 34px; }
  .topbar .btn.danger {
    padding: 6px 10px; font-size: 0;
    width: 34px; height: 34px; justify-content: center;
    border-radius: var(--radius-sm);
  }
  .topbar .btn.danger svg { margin: 0; }

  .content { padding: 16px 14px 24px; }
  .page-head {
    padding-bottom: 14px; margin-bottom: 16px;
    flex-direction: column; align-items: flex-start; gap: 10px;
  }
  .page-head > div:last-child { width: 100%; flex-wrap: wrap; gap: 8px; }
  .page-title { font-size: 24px; line-height: 1.05; }
  .page-sub { font-size: 12.5px; }

  /* Force any inline 2-col grid down to 1 col */
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; }
  .grid[style*="grid-template-columns"],
  .grid[style*="gridTemplateColumns"] { grid-template-columns: 1fr !important; }
  div[style*="grid-template-columns: 1.4fr"],
  div[style*="grid-template-columns: 1.5fr"],
  div[style*="grid-template-columns: 1.2fr"],
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns: 1fr 280px"],
  div[style*="grid-template-columns: 1fr 300px"],
  div[style*="grid-template-columns: 1fr 320px"],
  div[style*="grid-template-columns: 1fr 340px"],
  div[style*="grid-template-columns: 260px 1fr"] { grid-template-columns: 1fr !important; }

  /* Prevent grid blow-out: large content (timer text, long words) must shrink */
  .grid > *, .col > *, .row > * { min-width: 0; }
  .card { max-width: 100%; min-width: 0; }
  .card-body, .card-head { min-width: 0; }
  /* Long unbreakable words/numbers (e.g. timer 50:00 at fs 96) — scale */
  .serif[style*="font-size: 96"] { font-size: 64px !important; }
  .serif[style*="font-size: 72"] { font-size: 48px !important; }
  .serif[style*="font-size: 64"] { font-size: 44px !important; }
  /* Buttons in card-body rows wrap nicely */
  .card-body .row { flex-wrap: wrap; }
  .card-body .between { flex-wrap: wrap; gap: 8px; }
  /* Card-head can wrap title + actions */
  .card-head { flex-wrap: wrap; gap: 6px; }
  .card-head h3 { min-width: 0; }
  /* Selects don't bust width */
  .input, select.input { max-width: 100%; }
  /* Generic content overflow safety */
  .canvas, .content, .main { overflow-x: hidden; }
  /* Allow pre/code-like blocks scrolling */
  pre, code { overflow-x: auto; max-width: 100%; }

  .grid { gap: 12px; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .session-checklist,
  .session-insight-grid { grid-template-columns: 1fr 1fr; }
  .kv dt { margin-top: 10px; font-weight: 500; }
  .card-body { padding: 14px; }
  .card-head { padding: 12px 14px; }

  /* Tables: scroll horizontally inside their card body or wrapper */
  .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { font-size: 12.5px; min-width: max-content; }
  .table th, .table td { padding: 9px 10px; white-space: nowrap; }
  /* Search input full-width on phones */
  .patients-search { width: 100%; }
  .seg-ctrl { flex-wrap: wrap; }

  /* Modals: bottom-sheet pattern */
  .modal {
    max-width: 100%; max-height: 90vh;
    border-radius: 16px 16px 0 0;
    align-self: flex-end;
    animation: sheet-in 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
  }
  .modal::before {
    content: ""; display: block; width: 36px; height: 4px;
    background: var(--border-strong); border-radius: 2px;
    margin: 8px auto 0;
  }
  @keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
  .overlay { padding: 0; align-items: flex-end; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px env(safe-area-inset-bottom, 12px); }

  /* On mobile the topbar already has a crisis button; hide the FAB version */
  .crisis-fab:not([style*="right: 180"]) { display: none; }
  /* Keep Cortex IA as a compact pill above the bottom nav */
  .crisis-fab[style*="right: 180"] {
    right: 14px !important; bottom: 80px !important;
    padding: 8px 14px !important; font-size: 12px;
    box-shadow: var(--shadow-md);
  }

  .tweaks { left: 14px; right: 14px; bottom: 80px; width: auto; }

  /* Live session: stack panels on phones */
  .overlay div[style*="grid-template-columns: 1fr 340px"] {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto auto;
  }
  .live-session-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }
  .live-session-main {
    padding: 18px 14px 24px;
  }
  .live-session-side {
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  /* Tabs scroll horizontally */
  .tabs {
    overflow-x: auto; flex-wrap: nowrap;
    margin-left: -14px; margin-right: -14px;
    padding: 0 14px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex-shrink: 0; padding: 10px 12px; }

  /* Heatmap: smaller on phone */
  .heatmap { grid-template-columns: repeat(7, 1fr); }

  /* Likert: 2 col on phone */
  .lik { grid-template-columns: 1fr 1fr; }

  .session-snippets { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .session-snippets .chip { flex-shrink: 0; }
}

/* Very small phones */
@media (max-width: 380px) {
  .sidebar .nav-item { min-width: 50px; padding: 6px 8px; font-size: 9px; }
  .topbar .btn.danger { width: 32px; height: 32px; }
  .crisis-fab { padding: 9px 12px; font-size: 12px; }
  .page-title { font-size: 22px; }
  .session-checklist,
  .session-insight-grid { grid-template-columns: 1fr; }
}

/* Touch targets */
@media (pointer: coarse) {
  .btn, .nav-item, .tab, .topbar-btn { min-height: 36px; }
  .btn.sm { min-height: 30px; }
}

/* Print */
@media print {
  .sidebar, .topbar, .crisis-fab, .tweaks { display: none; }
  .app { grid-template-columns: 1fr; }
  .content { overflow: visible; padding: 0; }
}
