/* ============================================================
   M&P Case Manager — Design System v2 (Modern Professional)
   Deep navy primary · warm gold accent · Inter font · subtle shadows
   ============================================================ */

:root {
  /* Defaults — overridden by [data-palette] + [data-tone] + [data-brightness] + [data-text] below */

  /* Palette (Navy = default) */
  --primary: #1e293b;
  --primary-hover: #0f172a;
  --accent: #b45309;
  --accent-hover: #92400e;
  --accent-tint: #fef3c7;

  /* Surface tone variables — used by HSL-based brightness levels */
  --hue: 215;
  --sat: 22%;

  /* Brightness (Dim = default — see [data-brightness] rules below) */
  --bg: hsl(var(--hue) var(--sat) 85%);
  --surface: hsl(var(--hue) var(--sat) 92%);
  --surface-2: hsl(var(--hue) var(--sat) 88%);
  --border: hsl(var(--hue) var(--sat) 75%);
  --border-strong: hsl(var(--hue) var(--sat) 65%);
  --primary-tint: hsl(var(--hue) var(--sat) 81%);

  /* Text */
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --muted-2: #94a3b8;

  /* Status */
  --success: #15803d;
  --success-tint: #dcfce7;
  --warning: #b45309;
  --warning-tint: #fef3c7;
  --danger: #b91c1c;
  --danger-tint: #fee2e2;
  --info: #1d4ed8;
  --info-tint: #dbeafe;

  /* Shadows */
  --shadow-xs: 0 1px 1px rgba(15, 23, 42, 0.03);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 1px rgba(15, 23, 42, 0.03);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.07), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 8px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 24px -6px rgba(15, 23, 42, 0.10), 0 4px 8px -4px rgba(15, 23, 42, 0.04);

  /* Radius */
  --r-xs: 3px;
  --r-sm: 4px;
  --r: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-pill: 999px;

  /* Spacing */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px;

  /* Transitions */
  --t-fast: 0.12s ease;
  --t: 0.18s ease;
}

/* ===== Reset / Base ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 16px; line-height: 1.5;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--info); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--primary); text-decoration: underline; }

h1 { margin: 0 0 var(--s-2); font-size: 28px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
h2 { margin: var(--s-6) 0 var(--s-3); font-size: 22px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
h3 { margin: 0 0 var(--s-2); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.subtitle { color: var(--muted); margin: 0 0 var(--s-5); font-size: 14px; }
.muted { color: var(--muted); }
small { color: var(--muted); font-size: 12px; }
code { font-family: 'JetBrains Mono', ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 13px; background: var(--primary-tint); padding: 2px 5px; border-radius: var(--r-xs); color: var(--primary); }

.lucide, [data-lucide] { vertical-align: middle; flex-shrink: 0; }
svg.lucide { display: inline-block; }

/* ===== Top bar ===== */
.topbar {
  background: var(--primary); color: #f8fafc;
  padding: 0 var(--s-8);
  display: flex; align-items: center; gap: var(--s-6);
  height: 64px;
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 100;
}
.brand { flex-shrink: 0; }
.brand a {
  font-weight: 700; font-size: 18px; color: #f8fafc;
  letter-spacing: -0.01em; display: flex; align-items: center; gap: var(--s-2);
  white-space: nowrap;
}
.brand a:hover { text-decoration: none; color: #fff; }
.brand .accent-bar { width: 4px; height: 26px; background: var(--accent); border-radius: 2px; display: inline-block; flex-shrink: 0; }
.brand .brand-short { display: none; }
.brand .brand-sub { color: rgba(248, 250, 252, 0.65); font-weight: 400; font-size: 13px; margin-left: 4px; }

.mainnav { display: flex; gap: 3px; flex: 1; }
.mainnav a {
  color: rgba(248, 250, 252, 0.82); font-weight: 500; font-size: 14px;
  padding: 8px 14px; border-radius: var(--r-sm);
  display: inline-flex; align-items: center; gap: 7px;
  transition: all var(--t-fast);
}
.mainnav a svg { width: 17px; height: 17px; }
.mainnav a:hover { color: #fff; background: rgba(248, 250, 252, 0.1); text-decoration: none; }
.mainnav a.active { color: #fff; background: rgba(248, 250, 252, 0.15); }

.userbar { display: flex; align-items: center; gap: var(--s-3); font-size: 14px; }
.userbar .who { color: rgba(248, 250, 252, 0.85); }
.userbar .who small { color: rgba(248, 250, 252, 0.55); font-size: 12px; margin-left: 4px; }
.userbar .profile-link { color: rgba(248, 250, 252, 0.85); }
.userbar .profile-link:hover { color: #fff; text-decoration: none; }

form.inline { display: inline; margin: 0; }
button.link {
  background: transparent; border: none; color: rgba(248, 250, 252, 0.85);
  cursor: pointer; font-size: 13px; padding: 0; font-family: inherit;
}
button.link:hover { color: #fff; text-decoration: underline; }
.topbar button.link { color: rgba(248, 250, 252, 0.85); }

/* ===== Layout ===== */
.content { width: 100%; margin: 0; padding: var(--s-5) var(--s-6) var(--s-6); }
/* Forms and reading content are still capped for readability */
.record-form, form.stacked { max-width: 1240px; }
.footer { text-align: center; padding: var(--s-4); color: var(--muted); font-size: 11px; }
.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: var(--s-4); margin-bottom: var(--s-5);
}
.page-head .header-actions { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }

/* ===== Login ===== */
.login-body {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  display: flex; align-items: center; justify-content: center; min-height: 100vh; margin: 0;
}
.login-card {
  background: var(--surface); padding: var(--s-8); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); width: 380px;
}
.login-card .login-brand {
  text-align: center; margin-bottom: var(--s-6); padding-bottom: var(--s-5);
  border-bottom: 1px solid var(--border);
}
.login-card .login-brand h1 {
  color: var(--primary); margin-bottom: 4px; font-size: 22px;
  letter-spacing: -0.02em; display: inline-flex; align-items: center; gap: 8px;
}
.login-card .login-brand h1 .accent-bar { width: 3px; height: 24px; background: var(--accent); border-radius: 2px; }
.login-card .login-brand p { margin: 0; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; }
.login-card form { display: flex; flex-direction: column; gap: var(--s-4); }
.login-card form button[type=submit] { margin-top: var(--s-2); }

/* ===== Forms ===== */
label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 13px; font-weight: 600; color: var(--text-2); letter-spacing: 0.01em;
}
label.checkbox { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=time], input[type=url], input[type=tel],
select, textarea {
  padding: 9px 12px; font-size: 15px; border: 1px solid var(--border);
  border-radius: var(--r-sm); background: var(--surface); color: var(--text);
  font-family: inherit; transition: all var(--t-fast); font-weight: 400;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 41, 59, 0.08);
}
input:disabled { background: var(--primary-tint); color: var(--muted); }
textarea { resize: vertical; min-height: 70px; }

form.stacked {
  display: flex; flex-direction: column; gap: var(--s-4); max-width: 480px;
  background: var(--surface); padding: var(--s-5); border-radius: var(--r);
  border: 1px solid var(--border); box-shadow: var(--shadow-xs);
}
.form-actions {
  display: flex; gap: var(--s-2); align-items: center;
  margin-top: var(--s-4);
  padding: var(--s-3) var(--s-2);
  border-top: 1px solid var(--border);
  position: sticky; bottom: 0; z-index: 40;
  background: var(--bg);
  box-shadow: 0 -6px 12px -8px rgba(15, 23, 42, 0.18);
}

.record-form { max-width: 1240px; }
.record-form fieldset {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0 var(--s-6) var(--s-5);
  margin: 0 0 var(--s-3) 0;
  box-shadow: var(--shadow-xs);
  min-width: 0;  /* fix flex child overflow on Chrome */
}
.record-form legend {
  /* Force legend to act like a normal block header inside the fieldset */
  float: left; width: 100%;
  padding: var(--s-3) 0;
  margin: 0 0 var(--s-4) 0;
  font-size: 12px; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
}
.record-form fieldset > *:first-of-type:not(legend) { clear: both; }
.record-form label { margin-bottom: var(--s-3); }
.form-grid { display: grid; gap: var(--s-3); margin-bottom: var(--s-3); }
.form-grid.two   { grid-template-columns: 1fr 1fr; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
.form-grid.four  { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 700px) {
  .form-grid.two, .form-grid.three, .form-grid.four { grid-template-columns: 1fr; }
}

.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px; margin: 8px 0 14px; }
.checkbox-tile {
  display: flex; align-items: center; gap: 6px; padding: 5px 8px;
  border: 1px solid var(--border); border-radius: var(--r-xs);
  background: var(--surface); font-size: 12px; cursor: pointer;
  transition: all var(--t-fast); font-weight: 500;
}
.checkbox-tile:hover { background: var(--primary-tint); border-color: var(--border-strong); }
.checkbox-tile input { margin: 0; }

/* ===== Buttons ===== */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; font-size: 14px; font-weight: 500;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: var(--r-sm); cursor: pointer; text-decoration: none;
  font-family: inherit; transition: all var(--t-fast);
  white-space: nowrap;
}
button:hover, .btn:hover {
  background: var(--surface-2); border-color: var(--border-strong);
  text-decoration: none;
}
button.primary, .btn.primary {
  background: var(--primary); border-color: var(--primary); color: #fff;
  box-shadow: var(--shadow-sm);
}
button.primary:hover, .btn.primary:hover {
  background: var(--primary-hover); border-color: var(--primary-hover);
}
button.accent, .btn.accent {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: var(--shadow-sm);
}
button.accent:hover, .btn.accent:hover {
  background: var(--accent-hover); border-color: var(--accent-hover);
}
button.danger, .btn.danger {
  background: var(--danger); border-color: var(--danger); color: #fff;
}
.btn.notes-btn {
  background: var(--accent-tint); color: var(--accent-hover);
  border-color: #fde68a; font-weight: 600;
}
.btn.notes-btn:hover { background: #fde68a; border-color: #fcd34d; }

/* ===== Tables ===== */
table.data {
  width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r);
  border-collapse: separate; border-spacing: 0;
  box-shadow: var(--shadow-xs);
}
table.data th {
  background: var(--surface-2); text-align: left; padding: 9px 14px;
  font-weight: 600; font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 64px; z-index: 5;
  box-shadow: inset 0 -1px 0 var(--border), 0 1px 4px rgba(15, 23, 42, 0.06);
}
table.data thead th:first-child { border-top-left-radius: var(--r); }
table.data thead th:last-child { border-top-right-radius: var(--r); }
table.data td { padding: 8px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
table.data tbody tr:nth-child(even) td { background: var(--surface-2); }
table.data tbody tr:hover td { background: var(--primary-tint); }
table.data th a.th-sort {
  color: var(--muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.06em;
  display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
}
table.data th a.th-sort:hover { color: var(--text); text-decoration: none; }
/* Active column gets brighter text + bolder arrow */
table.data th a.th-sort.is-active { color: var(--text); }
table.data th a.th-sort.is-active .sort-arrow { color: var(--accent); font-size: 10px; font-weight: bold; }
/* Inactive columns show a faint ⇅ to telegraph "click me to sort" */
.sort-arrow { color: var(--muted); font-size: 10px; opacity: 0.5; }
table.data th a.th-sort:hover .sort-arrow { opacity: 1; }
table.data tr:last-child td { border-bottom: none; }
table.data a { color: var(--text); font-weight: 500; }
table.data a:hover { color: var(--primary); }
table.data strong { font-weight: 600; }

/* ===== Cards ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: var(--s-4) var(--s-5);
  margin-bottom: var(--s-3); box-shadow: var(--shadow-xs);
}
.dashboard-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--s-3); margin-bottom: var(--s-5);
}
.cards-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--s-3); margin-bottom: var(--s-4);
}
.cards-row .card { margin-bottom: 0; font-size: 13px; }
.cards-row .card div { margin-bottom: 3px; }

.stat-card { position: relative; overflow: hidden; display: flex; flex-direction: column; gap: var(--s-2); }
.stat-card .stat-icon {
  position: absolute; top: var(--s-3); right: var(--s-3);
  width: 32px; height: 32px; color: var(--muted-2);
  background: var(--primary-tint); border-radius: var(--r);
  display: flex; align-items: center; justify-content: center;
}
.stat-card .stat-value {
  font-size: 30px; font-weight: 700; color: var(--text);
  letter-spacing: -0.03em; line-height: 1.1; margin: 4px 0;
}
.stat-card .stat-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted);
}
.stat-card .stat-sub { font-size: 12px; color: var(--muted); margin-top: auto; padding-top: var(--s-2); }

.notes-summary-card { display: flex; flex-direction: column; }
.notes-summary-card .big-stat {
  font-size: 32px; font-weight: 700; color: var(--primary);
  margin: 4px 0 var(--s-2); letter-spacing: -0.02em;
}
.notes-summary-card .card-actions { display: flex; gap: 6px; margin-bottom: 6px; }
.notes-summary-card .recent-note-line { margin-top: 4px; }

.big-stat { font-size: 30px; font-weight: 700; color: var(--primary); margin: 4px 0 var(--s-2); letter-spacing: -0.02em; }

/* ===== Filter bar ===== */
.filter-bar {
  display: flex; gap: 8px; align-items: center; margin-bottom: var(--s-4);
  flex-wrap: wrap; background: var(--surface); padding: 10px var(--s-3);
  border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow-xs);
}
.filter-bar input[type=text] { flex: 1; min-width: 200px; }
.filter-bar select { min-width: 140px; }

/* ===== Pagination ===== */
.pagination { display: flex; gap: var(--s-4); align-items: center; justify-content: center; margin: var(--s-5) 0; font-size: 13px; }
.pagination span { color: var(--muted); }

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: var(--r-pill);
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--primary-tint); color: var(--text-2);
}
.badge.admin     { background: var(--danger-tint); color: var(--danger); }
.badge.attorney  { background: var(--info-tint); color: var(--info); }
.badge.paralegal { background: var(--warning-tint); color: var(--warning); }
.badge.secretary { background: #e0e7ff; color: #4338ca; }
.badge.wc      { background: var(--info-tint); color: var(--info); }
.badge.pi      { background: var(--warning-tint); color: var(--warning); }
.badge.other   { background: #e0e7ff; color: #4338ca; }
.badge.event   { background: var(--info-tint); color: var(--info); }
.badge.task    { background: var(--warning-tint); color: var(--warning); }
.badge.deadline { background: var(--danger-tint); color: var(--danger); }

/* ===== Alerts ===== */
.alert {
  padding: 10px 14px; border-radius: var(--r-sm); margin-bottom: var(--s-4);
  font-size: 13px; border: 1px solid transparent;
}
.alert.error   { background: var(--danger-tint); color: var(--danger); border-color: #fecaca; }
.alert.success { background: var(--success-tint); color: var(--success); border-color: #a7f3d0; }
.alert.warning { background: var(--warning-tint); color: var(--warning); border-color: #fde68a; }
.alert.info    { background: var(--info-tint); color: var(--info); border-color: #bfdbfe; }

/* ===== Notes timeline ===== */
.notes-timeline { display: flex; flex-direction: column; gap: var(--s-3); margin-bottom: var(--s-5); }
.notes-fullpage { gap: var(--s-4); }
.note-card {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--r); padding: var(--s-4) var(--s-5);
  box-shadow: var(--shadow-xs); transition: box-shadow var(--t-fast);
}
.note-card:hover { box-shadow: var(--shadow); }
.note-card.pinned { border-left-color: var(--accent); background: linear-gradient(to right, var(--accent-tint) 0, var(--surface) 8%); }
.note-meta {
  display: flex; align-items: center; gap: var(--s-3); font-size: 12px; color: var(--muted);
  padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 10px; flex-wrap: wrap;
}
.note-date { font-weight: 600; color: var(--text); }
.note-category {
  background: var(--info-tint); color: var(--info); padding: 2px 8px; border-radius: var(--r-pill);
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; font-size: 10px;
}
.note-author {
  background: var(--primary); color: white; width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700;
}
.note-pin-flag { color: var(--accent); font-size: 14px; }

.note-actions {
  margin-left: auto; display: flex; gap: var(--s-3); font-size: 12px;
  user-select: none; -webkit-user-select: none;
  opacity: 0.55; transition: opacity var(--t-fast); /* readable at rest, full on hover */
}
.note-card:hover .note-actions, .note-card:focus-within .note-actions { opacity: 1; }
.note-actions a, .note-actions button.link { font-size: 12px; }

.note-subject { font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.note-body { font-size: 13.5px; line-height: 1.6; color: var(--text-2); }
.notes-fullpage .note-body { font-size: 14px; }
.note-body p { margin: 0 0 6px; }
.note-body p:last-child { margin-bottom: 0; }
.note-body ul, .note-body ol { margin: 4px 0 6px; padding-left: 24px; }
.note-body blockquote { border-left: 3px solid var(--border); padding: 4px 12px; margin: 6px 0; color: var(--muted); }
.note-followup {
  margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--border);
  font-size: 12px; color: var(--warning);
}

.notes-page-head .header-actions { display: flex; gap: 8px; }
.copy-status { min-height: 20px; padding: 4px 0; font-size: 13px; }
.copy-status.success { color: var(--success); font-weight: 600; }
.copy-status.error { color: var(--danger); }

/* ===== Print ===== */
@media print {
  .topbar, .footer, .filter-bar, .pagination, .no-print,
  .note-actions, .page-head .header-actions { display: none !important; }
  body { background: white; }
  .note-card { break-inside: avoid; border-left-width: 1px; }
  .content { max-width: 100%; padding: 0; }
}

/* ===== Documents ===== */
.docs-grid { display: grid; grid-template-columns: 240px 1fr; gap: var(--s-4); }
@media (max-width: 800px) { .docs-grid { grid-template-columns: 1fr; } }
.docs-sidebar {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: var(--s-3); height: fit-content; position: sticky; top: 70px;
  box-shadow: var(--shadow-xs);
}
.docs-sidebar h3 { margin: 0 0 8px; padding: 0 8px; }
.folder-nav { list-style: none; padding: 0; margin: 0; }
.folder-nav li { margin: 2px 0; }
.folder-nav a {
  display: block; padding: 6px 10px; border-radius: var(--r-xs); color: var(--text-2);
  font-size: 13px; text-decoration: none; transition: all var(--t-fast);
}
.folder-nav a:hover { background: var(--primary-tint); text-decoration: none; color: var(--text); }
.folder-nav a.active { background: var(--primary); color: white; font-weight: 500; }
.folder-nav .muted { font-size: 11px; }

.doc-folder { margin-bottom: var(--s-5); }
.folder-heading {
  font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 8px;
  padding-bottom: 6px; border-bottom: 2px solid var(--accent);
  display: inline-block;
}
.folder-heading small { color: var(--muted); font-weight: 400; }
.doc-actions { user-select: none; -webkit-user-select: none; opacity: 0.4; transition: opacity var(--t-fast); }
.doc-actions a, .doc-actions button.link { margin-right: 8px; font-size: 12px; }
table.data tr:hover .doc-actions,
table.data tr:focus-within .doc-actions { opacity: 1; } /* keyboard users see them too */

/* ===== Dashboard lists ===== */
.dash-list { list-style: none; padding: 0; margin: 4px 0 0; }
.dash-list li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.dash-list li:last-child { border-bottom: none; }
.dash-list.compact li { padding: 4px 0; font-size: 12px; }
.dash-list .muted { font-size: 11px; }
.dash-list a { color: var(--text); }
.dash-list a:hover { color: var(--primary); text-decoration: none; }

/* ===== Matter picker ===== */
.matter-picker { position: relative; }
.matter-picker-input { padding-right: 30px !important; width: 100%; }
.matter-picker-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
  font-size: 20px; line-height: 1; padding: 0 4px;
}
.matter-picker-clear:hover { color: var(--text); }
.matter-picker-results {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--r-sm) var(--r-sm); box-shadow: var(--shadow-md);
  max-height: 320px; overflow-y: auto;
}
.matter-picker-result {
  display: block; width: 100%; text-align: left; background: var(--surface);
  border: none; border-bottom: 1px solid var(--border); padding: 8px 12px;
  cursor: pointer; font-family: inherit; font-size: 13px; color: var(--text);
}
.matter-picker-result:last-child { border-bottom: none; }
.matter-picker-result:hover { background: var(--primary-tint); }
.matter-picker-result .matter-picker-client { font-weight: 600; color: var(--text); }
.matter-picker-result .matter-picker-name { color: var(--text-2); margin-left: 6px; }
.matter-picker-result .matter-picker-meta {
  display: block; color: var(--muted); font-size: 10px; margin-top: 2px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.matter-picker-empty { padding: 10px 12px; color: var(--muted); font-size: 13px; font-style: italic; }

/* ===== Template picker tiles ===== */
.template-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--s-2); }
.template-tile {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 10px 12px; cursor: pointer; font-weight: normal;
  transition: all var(--t-fast);
}
.template-tile:hover { border-color: var(--primary); background: var(--surface-2); box-shadow: var(--shadow-xs); }
.template-tile input[type=radio]:checked + div { color: var(--primary); }
.template-tile input[type=radio] { margin-top: 3px; }

/* ===== PI sub-nav ===== */
.pi-subnav {
  display: flex; gap: 4px; align-items: center; margin-bottom: var(--s-4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 5px; font-size: 13px; box-shadow: var(--shadow-xs);
}
.pi-subnav a {
  padding: 6px 12px; border-radius: var(--r-xs); color: var(--text-2);
  display: inline-flex; align-items: center; gap: 5px; font-weight: 500;
  transition: all var(--t-fast);
}
.pi-subnav a:hover { background: var(--primary-tint); text-decoration: none; color: var(--text); }
.pi-subnav a.active { background: var(--primary); color: white; }
.pi-subnav .back-link { color: var(--muted); margin-right: 8px; padding-left: 4px; }
.pi-subnav .back-link:hover { color: var(--primary); background: transparent; }

/* ===== Reports landing ===== */
.reports-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--s-3); margin-bottom: var(--s-6);
}
.report-card {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: var(--s-4) var(--s-5);
  text-decoration: none; color: var(--text);
  transition: all var(--t-fast); position: relative; overflow: hidden;
  box-shadow: var(--shadow-xs);
}
.report-card:hover {
  border-color: var(--primary); transform: translateY(-2px);
  box-shadow: var(--shadow-md); text-decoration: none;
}
.report-card .report-icon {
  width: 32px; height: 32px; color: var(--accent); margin-bottom: 8px;
}
.report-card h3 { color: var(--primary); font-size: 14px; text-transform: none; letter-spacing: 0; margin-bottom: 4px; font-weight: 600; }
.report-card p { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.report-card.alert-card { border-left: 3px solid var(--danger); }
.report-card.alert-card h3 { color: var(--danger); }
.report-card.alert-card .report-icon { color: var(--danger); }

/* ===== Quick actions ===== */
.quick-actions { display: flex; flex-direction: column; gap: 6px; }
.quick-actions .btn { justify-content: flex-start; gap: 8px; }

/* ===== Section heads ===== */
.section-head { display: flex; justify-content: space-between; align-items: center; margin: var(--s-6) 0 var(--s-3); }
.section-head h2 { margin: 0; }
.section-head .btn { margin-left: 8px; }

/* ===== Misc ===== */
.ok { color: var(--success); font-weight: 600; font-size: 11px; padding: 2px 6px; background: var(--success-tint); border-radius: var(--r-xs); margin-left: 6px; }
hr { border: none; border-top: 1px solid var(--border); margin: var(--s-5) 0; }

kbd {
  display: inline-block; padding: 1px 6px; font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 600; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 3px; min-width: 18px; text-align: center;
}

/* ============================================================
   FORM TABS — convert <fieldset> sections into clickable tabs
   ============================================================ */
.form-tab-nav {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-bottom: var(--s-4); padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-sm);
  position: sticky; top: 70px; z-index: 60;
}
.form-tab-btn {
  background: transparent; border: 0; cursor: pointer;
  padding: 8px 14px; font-size: 13px; font-weight: 500;
  color: var(--text-2); border-radius: var(--r-xs);
  font-family: inherit; white-space: nowrap;
  transition: all var(--t-fast); display: inline-flex; align-items: center; gap: 6px;
}
.form-tab-btn:hover { background: var(--primary-tint); color: var(--text); }
.form-tab-btn.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-xs); }
[data-theme="dark"] .form-tab-btn.active { background: var(--accent); color: #1e293b; }
.form-tab-btn .form-tab-num {
  background: rgba(0,0,0,0.08); color: inherit; padding: 1px 6px;
  border-radius: 8px; font-size: 10px; font-weight: 700;
}
.form-tab-btn.active .form-tab-num { background: rgba(255,255,255,0.2); }
[data-theme="dark"] .form-tab-btn.active .form-tab-num { background: rgba(0,0,0,0.15); }

/* ============================================================
   GLOBAL SEARCH (top bar)
   ============================================================ */
.topbar-search {
  position: relative; display: flex; align-items: center; gap: 6px;
  background: rgba(248, 250, 252, 0.1); border-radius: var(--r-sm);
  padding: 0 10px; min-width: 260px; max-width: 380px; flex: 0 1 360px;
  border: 1px solid rgba(248, 250, 252, 0.1);
  transition: all var(--t-fast);
}
.topbar-search:focus-within {
  background: rgba(248, 250, 252, 0.18);
  border-color: rgba(248, 250, 252, 0.3);
}
.topbar-search svg { color: rgba(248, 250, 252, 0.6); }
.topbar-search input {
  flex: 1; background: transparent; border: 0; color: #f8fafc;
  padding: 8px 0; font-size: 14px; outline: none;
}
.topbar-search input::placeholder { color: rgba(248, 250, 252, 0.5); }
.search-kbd {
  background: rgba(248, 250, 252, 0.15); color: rgba(248, 250, 252, 0.7);
  border: 1px solid rgba(248, 250, 252, 0.15); border-bottom-width: 1px;
  font-size: 10px; padding: 1px 5px;
}

.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-lg);
  max-height: 70vh; overflow-y: auto; z-index: 200;
  min-width: 360px;
}
.search-group { padding: 4px 0; }
.search-group-label {
  font-size: 10px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 8px 14px 4px; background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.search-result {
  display: block; padding: 8px 14px; border-bottom: 1px solid var(--border);
  color: var(--text); transition: background var(--t-fast); text-decoration: none;
}
.search-result:hover,
.search-result.selected { background: var(--primary-tint); text-decoration: none; }
.search-result.selected { box-shadow: inset 3px 0 0 var(--accent); }
.search-result:last-child { border-bottom: none; }
.search-result-title { font-weight: 500; font-size: 14px; color: var(--text); }
.search-result-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.search-empty { padding: 14px; color: var(--muted); font-size: 13px; text-align: center; font-style: italic; }

/* ============================================================
   TOPBAR DROPDOWN (Recent matters)
   ============================================================ */
.topbar-dropdown { position: relative; }
.topbar-dropdown-btn {
  background: rgba(248, 250, 252, 0.1); border: 1px solid rgba(248, 250, 252, 0.1);
  color: rgba(248, 250, 252, 0.85); font-size: 13px;
  padding: 6px 12px; border-radius: var(--r-sm); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.topbar-dropdown-btn:hover { background: rgba(248, 250, 252, 0.18); color: #fff; }
.topbar-dropdown-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 150;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-lg);
  min-width: 320px; padding: 6px 0;
  display: none;
}
.topbar-dropdown.open .topbar-dropdown-menu { display: block; }
.dropdown-heading {
  font-size: 10px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 8px 12px 4px;
}
.dropdown-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; color: var(--text); font-size: 13px;
  transition: background var(--t-fast);
}
.dropdown-item:hover { background: var(--primary-tint); text-decoration: none; }
.dropdown-item-text { flex: 1; font-weight: 500; }
.dropdown-item small { color: var(--muted); font-family: 'JetBrains Mono', monospace; font-size: 11px; }

/* ============================================================
   QUICK-ADD FLOATING ACTION BUTTON
   ============================================================ */
.fab-container { position: fixed; bottom: 22px; right: 22px; z-index: 90; }
.fab-button {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #1e293b; border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
  opacity: 0.55;
  transition: all var(--t);
}
.fab-button:hover { background: var(--accent-hover); transform: scale(1.08); opacity: 1; box-shadow: var(--shadow-lg); }
.fab-container.open .fab-button { transform: rotate(45deg); opacity: 1; box-shadow: var(--shadow-lg); }
.fab-menu {
  position: absolute; bottom: 56px; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-lg);
  min-width: 220px; padding: 6px 0;
  opacity: 0; transform: translateY(8px) scale(0.95);
  transform-origin: bottom right; pointer-events: none;
  transition: all var(--t-fast);
}
.fab-container.open .fab-menu { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.fab-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; color: var(--text); font-size: 14px; font-weight: 500;
  transition: background var(--t-fast);
}
.fab-item:hover { background: var(--primary-tint); text-decoration: none; color: var(--text); }

/* ============================================================
   MODAL (keyboard shortcuts help)
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6);
  z-index: 300; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none !important; }
.modal-card {
  background: var(--surface); border-radius: var(--r-md);
  padding: var(--s-6); max-width: 480px; width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal-card h2 { margin-top: 0; display: flex; align-items: center; gap: 8px; color: var(--accent); }
.shortcut-table { width: 100%; border-collapse: collapse; }
.shortcut-table td { padding: 6px 4px; font-size: 14px; }
.shortcut-table td:first-child { width: 100px; white-space: nowrap; }

/* ============================================================
   CONFLICT CHECK BOX (new client form)
   ============================================================ */
.conflict-check {
  margin-top: var(--s-3);
  padding: 12px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--warning);
  background: var(--warning-tint);
  color: var(--text-2);
  font-size: 13px;
}
.conflict-check.conflict-high {
  border-color: var(--danger);
  background: var(--danger-tint);
}
.conflict-check .conflict-strong { color: var(--danger); font-weight: 600; margin-bottom: 6px; }
.conflict-list { margin: 6px 0 0 18px; padding: 0; }
.conflict-list li { margin: 2px 0; font-size: 13px; }
.conflict-list code { font-size: 11px; }

/* ============================================================
   SPLIT-VIEW (Clients master/detail)
   ============================================================ */
.split-view {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: var(--s-3);
  height: calc(100vh - 64px - 40px - var(--s-8) * 2);
  min-height: 540px;
}
.split-list-pane {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}
.split-filter-bar {
  margin: 0; border-radius: 0;
  border-top: 0; border-left: 0; border-right: 0;
  border-bottom: 1px solid var(--border);
  box-shadow: none;
  padding: 8px;
  gap: 6px;
}
.split-filter-bar input[type=text] { min-width: 0; flex: 1; }
.split-filter-bar button, .split-filter-bar .btn { padding: 6px 10px; }
.split-filter-bar label.checkbox { font-size: 12px; }

/* Wrapper around the scrollable list + count (swapped by live search) —
   must pass the flex sizing through so the list keeps its scroll height. */
#client-results {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.split-list {
  flex: 1; overflow-y: auto;
  background: var(--surface);
}
.split-list-row {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast);
}
.split-list-row:hover { background: var(--primary-tint); }
.split-list-row.active {
  background: var(--info-tint);
  border-left: 3px solid var(--info);
  padding-left: 11px;
}
[data-theme="dark"] .split-list-row.active { background: rgba(96, 165, 250, 0.15); }
.split-list-row .row-id {
  font-size: 11px; color: var(--muted); margin-bottom: 1px;
}
.split-list-row .row-id code { background: transparent; padding: 0; }
.split-list-row .row-name {
  font-size: 13.5px; font-weight: 500; color: var(--text); line-height: 1.3;
}
.split-list-row.active .row-name { color: var(--info); font-weight: 600; }
.split-list-row .row-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.split-list-row .row-inactive {
  font-size: 10px; color: var(--muted); margin-left: 4px;
  background: var(--primary-tint); padding: 1px 5px; border-radius: var(--r-pill);
  font-weight: 600; text-transform: uppercase;
}
.split-empty { padding: var(--s-5); text-align: center; }

.split-pagination {
  display: flex; gap: 12px; justify-content: center; align-items: center;
  padding: 8px; background: var(--surface-2);
  border-top: 1px solid var(--border); font-size: 12px;
}

/* Active/Closed/All filter chips */
.status-chips {
  display: flex; gap: 4px; padding: 6px 8px;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.status-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 500; color: var(--text-2);
  text-decoration: none; transition: all var(--t-fast);
}
.status-chip span {
  background: var(--primary-tint); color: var(--text-2);
  padding: 0 6px; border-radius: var(--r-pill);
  font-size: 10px; font-weight: 700;
}
.status-chip:hover { background: var(--primary-tint); color: var(--text); text-decoration: none; }
.status-chip.active { background: var(--primary); color: #fff; }
.status-chip.active span { background: rgba(255,255,255,0.25); color: #fff; }
[data-theme="dark"] .status-chip.active { background: var(--accent); color: #1e293b; }
[data-theme="dark"] .status-chip.active span { background: rgba(0,0,0,0.2); color: #1e293b; }

/* Sort row under the filter chips */
.sort-row {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 6px 10px; border-bottom: 1px solid var(--border);
  font-size: 11px; background: var(--surface);
}
.sort-row span { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; margin-right: 2px; }
.sort-link {
  padding: 3px 8px; border-radius: var(--r-xs);
  font-size: 11px; color: var(--text-2); text-decoration: none;
  border: 1px solid transparent;
  transition: all var(--t-fast);
}
.sort-link:hover { background: var(--primary-tint); color: var(--text); text-decoration: none; }
.sort-link.active {
  background: var(--accent-tint); color: var(--accent-hover);
  border-color: var(--accent); font-weight: 600;
}
[data-theme="dark"] .sort-link.active { background: rgba(251, 191, 36, 0.15); color: var(--accent); border-color: var(--accent); }

.split-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow-y: auto;
  box-shadow: var(--shadow-xs);
}
.split-preview-empty {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--muted); padding: var(--s-6);
}
.split-preview-empty svg { color: var(--muted-2); margin-bottom: 12px; }

.preview-content { padding: var(--s-5) var(--s-6); }
.preview-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: var(--s-4); margin-bottom: var(--s-5);
  padding-bottom: var(--s-4); border-bottom: 1px solid var(--border);
}
.preview-header h2 { margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
.preview-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.preview-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s-4); margin-bottom: var(--s-5);
}
.preview-section h3 {
  display: flex; align-items: center; gap: 5px;
  margin-bottom: 8px;
}
.preview-address { font-size: 13px; line-height: 1.55; color: var(--text-2); }

table.kv {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.kv th {
  text-align: left; padding: 3px 0; padding-right: 12px;
  font-weight: 500; color: var(--muted);
  font-size: 12px; vertical-align: top;
  width: 90px;
}
table.kv td { padding: 3px 0; color: var(--text-2); vertical-align: top; }

.preview-matters h3 { margin-bottom: 8px; }
.preview-matters { margin-bottom: var(--s-5); }

/* Stack on small screens */
@media (max-width: 900px) {
  .split-view { grid-template-columns: 1fr; height: auto; }
  .split-list { max-height: 50vh; }
}

/* ============================================================
   COLOR PALETTES (data-palette attribute on <html>)
   ============================================================ */
[data-palette="navy"], :root {
  --primary: #1e293b; --primary-hover: #0f172a;
  --accent: #b45309; --accent-hover: #92400e; --accent-tint: #fef3c7;
}
[data-palette="forest"] {
  --primary: #14532d; --primary-hover: #052e16;
  --accent: #b45309; --accent-hover: #92400e; --accent-tint: #fef3c7;
}
[data-palette="burgundy"] {
  --primary: #7f1d1d; --primary-hover: #450a0a;
  --accent: #ca8a04; --accent-hover: #a16207; --accent-tint: #fef9c3;
}
[data-palette="charcoal"] {
  --primary: #374151; --primary-hover: #1f2937;
  --accent: #d97706; --accent-hover: #b45309; --accent-tint: #fef3c7;
}
[data-palette="indigo"] {
  --primary: #3730a3; --primary-hover: #312e81;
  --accent: #ea580c; --accent-hover: #c2410c; --accent-tint: #ffedd5;
}
[data-palette="teal"] {
  --primary: #115e59; --primary-hover: #134e4a;
  --accent: #b45309; --accent-hover: #92400e; --accent-tint: #fef3c7;
}

/* ============================================================
   SURFACE TONE (data-tone attribute on <html>)
   Sets the hue + saturation. Brightness levels then use HSL with these.
   ============================================================ */
[data-tone="slate"], :root          { --hue: 215; --sat: 22%; }  /* cool blue-gray (default) */
[data-tone="warm"]                  { --hue: 32;  --sat: 28%; }  /* warm cream / paper */
[data-tone="neutral"]               { --hue: 220; --sat: 6%; }   /* near-pure gray */
[data-tone="sage"]                  { --hue: 145; --sat: 14%; }  /* soft green tint */
[data-tone="lavender"]              { --hue: 265; --sat: 14%; }  /* soft purple tint */
[data-tone="rose"]                  { --hue: 355; --sat: 18%; }  /* soft warm pink */

/* ============================================================
   BRIGHTNESS LEVELS (light mode — composed with tone via HSL)
   ============================================================ */
[data-brightness="bright"] {
  --bg:            hsl(var(--hue) var(--sat) 96%);
  --surface:       hsl(var(--hue) var(--sat) 100%);
  --surface-2:     hsl(var(--hue) var(--sat) 97%);
  --border:        hsl(var(--hue) var(--sat) 89%);
  --border-strong: hsl(var(--hue) var(--sat) 78%);
  --primary-tint:  hsl(var(--hue) var(--sat) 94%);
}
[data-brightness="default"] {
  --bg:            hsl(var(--hue) var(--sat) 92%);
  --surface:       hsl(var(--hue) var(--sat) 99%);
  --surface-2:     hsl(var(--hue) var(--sat) 95%);
  --border:        hsl(var(--hue) var(--sat) 84%);
  --border-strong: hsl(var(--hue) var(--sat) 72%);
  --primary-tint:  hsl(var(--hue) var(--sat) 89%);
}
[data-brightness="dim"], :root {
  --bg:            hsl(var(--hue) var(--sat) 85%);
  --surface:       hsl(var(--hue) var(--sat) 92%);
  --surface-2:     hsl(var(--hue) var(--sat) 88%);
  --border:        hsl(var(--hue) var(--sat) 75%);
  --border-strong: hsl(var(--hue) var(--sat) 65%);
  --primary-tint:  hsl(var(--hue) var(--sat) 81%);
}
[data-brightness="dimmer"] {
  --bg:            hsl(var(--hue) var(--sat) 78%);
  --surface:       hsl(var(--hue) var(--sat) 87%);
  --surface-2:     hsl(var(--hue) var(--sat) 82%);
  --border:        hsl(var(--hue) var(--sat) 68%);
  --border-strong: hsl(var(--hue) var(--sat) 58%);
  --primary-tint:  hsl(var(--hue) var(--sat) 75%);
}

/* ============================================================
   TEXT STYLE (data-text attribute on <html>)
   ============================================================ */
[data-text="default"], :root {
  --text: #0f172a; --text-2: #334155; --muted: #64748b;
}
[data-text="soft"] {
  --text: #1e293b; --text-2: #475569; --muted: #6b7280;
}
[data-text="sharp"] {
  --text: #000000; --text-2: #1f2937; --muted: #475569;
}
[data-text="sepia"] {
  --text: #3a2820; --text-2: #5c4234; --muted: #8a7666;
}

/* ============================================================
   DARK MODE
   ============================================================ */
[data-theme="dark"] {
  --primary-tint: hsl(var(--hue) var(--sat) 18%);
  --accent: #fbbf24;
  --accent-hover: #f59e0b;
  --accent-tint: #3a1d05;

  /* Dark mode surfaces also pick up the tone — subtle hue shift on near-black */
  --bg:            hsl(var(--hue) calc(var(--sat) * 0.6) 6%);
  --surface:       hsl(var(--hue) calc(var(--sat) * 0.5) 14%);
  --surface-2:     hsl(var(--hue) calc(var(--sat) * 0.5) 19%);
  --border:        hsl(var(--hue) calc(var(--sat) * 0.5) 24%);
  --border-strong: hsl(var(--hue) calc(var(--sat) * 0.5) 33%);

  --text: #f1f5f9;
  --text-2: #cbd5e1;
  --muted: #94a3b8;
  --muted-2: #64748b;

  --success: #4ade80;
  --success-tint: #052e16;
  --warning: #fbbf24;
  --warning-tint: #3a1d05;
  --danger: #f87171;
  --danger-tint: #2c0808;
  --info: #60a5fa;
  --info-tint: #172554;

  --shadow-xs: 0 1px 1px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 1px rgba(0, 0, 0, 0.25);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 8px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 24px -6px rgba(0, 0, 0, 0.6);
}

/* Primary buttons in dark mode use the gold accent for visibility */
[data-theme="dark"] button.primary,
[data-theme="dark"] .btn.primary {
  background: var(--accent); border-color: var(--accent); color: #1e293b;
}
[data-theme="dark"] button.primary:hover,
[data-theme="dark"] .btn.primary:hover {
  background: var(--accent-hover); border-color: var(--accent-hover); color: #0f172a;
}

/* Code blocks readable in dark mode */
[data-theme="dark"] code {
  background: rgba(96, 165, 250, 0.15);
  color: #93c5fd;
}

/* Note categories etc that use info-tint look better in dark */
[data-theme="dark"] .note-category {
  background: rgba(96, 165, 250, 0.18);
  color: #93c5fd;
}

/* Pinned note gradient */
[data-theme="dark"] .note-card.pinned {
  background: linear-gradient(to right, var(--accent-tint) 0, var(--surface) 12%);
  border-left-color: var(--accent);
}

/* PI subnav active state - in dark mode the navy doesn't pop, use accent */
[data-theme="dark"] .pi-subnav a.active { background: var(--accent); color: #1e293b; }
[data-theme="dark"] .folder-nav a.active { background: var(--accent); color: #1e293b; }

/* Quill editor in dark mode */
[data-theme="dark"] .ql-toolbar.ql-snow {
  background: var(--surface-2) !important;
  border-color: var(--border) !important;
}
[data-theme="dark"] .ql-toolbar.ql-snow button,
[data-theme="dark"] .ql-toolbar.ql-snow .ql-picker-label {
  color: var(--text) !important;
}
[data-theme="dark"] .ql-snow .ql-stroke { stroke: var(--text-2) !important; }
[data-theme="dark"] .ql-snow .ql-fill { fill: var(--text-2) !important; }
[data-theme="dark"] .ql-snow .ql-picker { color: var(--text-2) !important; }
[data-theme="dark"] .ql-snow .ql-picker-options {
  background: var(--surface) !important;
  border-color: var(--border) !important;
}
[data-theme="dark"] .ql-container.ql-snow {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
[data-theme="dark"] .ql-editor { color: var(--text); }
[data-theme="dark"] .ql-editor.ql-blank::before { color: var(--muted) !important; }
[data-theme="dark"] .note-editor { background: var(--surface) !important; }

/* FullCalendar dark mode */
[data-theme="dark"] .fc { color: var(--text); }
[data-theme="dark"] .fc-theme-standard td,
[data-theme="dark"] .fc-theme-standard th,
[data-theme="dark"] .fc-theme-standard .fc-scrollgrid,
[data-theme="dark"] .fc-theme-standard .fc-list,
[data-theme="dark"] .fc-list-day-cushion { border-color: var(--border) !important; background: transparent !important; }
[data-theme="dark"] .fc-day-today { background: rgba(251, 191, 36, 0.08) !important; }
[data-theme="dark"] .fc .fc-button-primary {
  background: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important;
}
[data-theme="dark"] .fc .fc-button-primary:hover { background: var(--surface-2) !important; }
[data-theme="dark"] .fc .fc-button-active,
[data-theme="dark"] .fc .fc-button-primary:not(:disabled).fc-button-active {
  background: var(--accent) !important; color: #1e293b !important; border-color: var(--accent) !important;
}
[data-theme="dark"] .fc-list-event:hover td { background: var(--surface-2) !important; }
[data-theme="dark"] .fc-col-header-cell-cushion,
[data-theme="dark"] .fc-daygrid-day-number { color: var(--text-2); }

/* Theme toggle button in topbar */
.theme-toggle {
  background: transparent; border: 0; cursor: pointer; padding: 4px 6px;
  color: rgba(248, 250, 252, 0.85); display: inline-flex; align-items: center;
  border-radius: var(--r-sm);
}
.theme-toggle:hover { color: #fff; background: rgba(248, 250, 252, 0.1); }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: inline-block; }

/* Appearance popover panel */
.appearance-wrap { position: relative; }
.appearance-panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 250;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  padding: var(--s-4); min-width: 320px; max-width: 380px;
  color: var(--text); max-height: 80vh; overflow-y: auto;
}
.appearance-panel[hidden] { display: none !important; }
.appearance-section { margin-bottom: var(--s-4); }
.appearance-section:last-child { margin-bottom: 0; }
.appearance-section > label {
  display: block; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
  margin-bottom: 6px;
}
.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: var(--r-sm); }
.seg button {
  flex: 1; padding: 6px 10px; font-size: 12px; font-weight: 500;
  background: transparent; border: 0; color: var(--text-2);
  border-radius: var(--r-xs); cursor: pointer; transition: all var(--t-fast);
  font-family: inherit;
}
.seg button:hover { background: var(--surface); color: var(--text); }
.seg button.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-xs); }

.palette-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.palette-swatch {
  position: relative; height: 38px; border-radius: var(--r-sm); border: 2px solid transparent;
  cursor: pointer; padding: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: rgba(255,255,255,0.85);
  text-transform: uppercase; letter-spacing: 0.05em;
  transition: transform var(--t-fast), border-color var(--t-fast);
}
.palette-swatch::after {
  content: ''; position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent-color);
}
.palette-swatch:hover { transform: scale(1.05); }
.palette-swatch.active { border-color: var(--text); }
[data-theme="dark"] .palette-swatch.active { border-color: #fff; }

/* Tone swatches — circle showing the bg color */
.tone-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.tone-swatch {
  height: 32px; border-radius: var(--r-sm); cursor: pointer; padding: 0;
  border: 2px solid transparent; transition: transform var(--t-fast), border-color var(--t-fast);
  font-size: 0;  /* hide text, just show color */
}
.tone-swatch:hover { transform: scale(1.05); }
.tone-swatch.active { border-color: var(--text); }
[data-theme="dark"] .tone-swatch.active { border-color: #fff; }

/* ===== Nav grouping ===== */
.nav-group { display: flex; gap: 3px; }
.nav-divider {
  width: 1px; align-self: center; height: 22px;
  background: rgba(248, 250, 252, 0.18); margin: 0 6px;
}

/* ===== Small / disabled buttons ===== */
.btn.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn.disabled { opacity: 0.4; cursor: default; pointer-events: none; }

/* ===== Empty states ===== */
.empty-state {
  color: var(--muted); font-size: 13px; background: var(--surface);
  border: 1px dashed var(--border); border-radius: var(--r);
  padding: var(--s-5); text-align: center;
}

/* ===== Improved empty states (with icon + primary action) ===== */
.empty-state-block {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--r);
  padding: 28px 20px;
  text-align: center;
  margin: 14px 0;
}
.empty-state-block .es-icon {
  font-size: 32px;
  line-height: 1;
  margin-bottom: 10px;
  opacity: 0.5;
}
.empty-state-block .es-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.empty-state-block .es-sub {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}
.empty-state-block .es-actions a.btn {
  display: inline-block;
}

/* ===== Status badges ===== */
.badge.status-intake     { background: #e0e7ff; color: #4338ca; }
.badge.status-active     { background: var(--success-tint); color: var(--success); }
.badge.status-litigation { background: var(--warning-tint); color: var(--warning); }
.badge.status-settlement { background: var(--info-tint); color: var(--info); }
.badge.status-closed     { background: var(--primary-tint); color: var(--text-2); }
.badge.status-inactive   { background: var(--primary-tint); color: var(--muted); }
.badge.secure   { background: var(--danger-tint); color: var(--danger); }
.badge.sol-warn { background: #fef3c7; color: #92400e; }

/* ===== Matter command-center header ===== */
.matter-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: var(--s-5); flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: var(--s-4) var(--s-5);
  margin-bottom: var(--s-3); box-shadow: var(--shadow-xs);
}
.matter-header-main { flex: 1; min-width: 280px; }
.matter-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.matter-title-row h1 { margin: 0; font-size: 22px; }
.matter-facts {
  display: flex; flex-wrap: wrap; gap: 4px 18px;
  margin-top: 8px; font-size: 13px; color: var(--text-2);
}
.matter-facts .mf-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin-right: 3px;
}
.matter-header-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.matter-status-reason { margin-top: 7px; font-size: 13px; color: var(--text-2); }
.matter-status-reason .mf-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin-right: 3px;
}

/* Structured "next step" box on the matter Overview */
.next-step-box {
  background: var(--accent-tint); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: var(--r-sm);
  padding: 10px 12px; margin-bottom: var(--s-4);
}
.next-step-box.is-overdue { border-left-color: var(--danger); background: var(--danger-tint); }
.next-step-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin-bottom: 3px;
}
.next-step-text { font-size: 14px; font-weight: 600; }
.next-step-meta { font-size: 12px; margin-top: 3px; }
.matter-sib-nav { display: flex; align-items: center; gap: 8px; font-size: 12px; }

/* ===== Matter tabs ===== */
.matter-tabs {
  display: flex; gap: 2px; flex-wrap: wrap; align-items: center;
  border-bottom: 2px solid var(--border); margin-bottom: var(--s-4);
  position: sticky; top: 64px; z-index: 50;
  background: var(--bg);
  box-shadow: 0 4px 6px -4px rgba(15, 23, 42, 0.12);
}
.mt-context {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 14px 6px 4px; min-width: 0; margin-right: 4px;
  border-right: 1px solid var(--border);
}
.mt-context strong {
  font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 320px;
}
@media (max-width: 700px) { .mt-context { display: none; } }
.matter-tab {
  background: transparent; border: none; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--muted); padding: 9px 16px;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.matter-tab:hover { color: var(--text); }
.matter-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.matter-tab .tab-count {
  display: inline-block; background: var(--primary-tint); color: var(--text-2);
  font-size: 11px; font-weight: 700; padding: 1px 7px;
  border-radius: var(--r-pill); margin-left: 4px;
}
.tab-panel[hidden] { display: none; }
.panel-actions { display: flex; gap: var(--s-2); margin-bottom: var(--s-3); }

/* ===== Overview layout ===== */
.overview-grid {
  display: grid; grid-template-columns: 320px 1fr;
  gap: var(--s-4); align-items: start;
}
@media (max-width: 900px) { .overview-grid { grid-template-columns: 1fr; } }
.next-actions-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: var(--s-4) var(--s-5);
  box-shadow: var(--shadow-xs);
}
.next-actions-panel h3 {
  margin: 0 0 var(--s-3); font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.next-actions-list { list-style: none; margin: 0; padding: 0; }
.next-actions-list li {
  padding: 8px 10px; margin-bottom: 6px; font-size: 13px;
  border-radius: var(--r-sm); border-left: 3px solid var(--border);
  background: var(--bg);
}
.next-actions-list li.na-warn  { border-left-color: var(--warning); background: var(--warning-tint); }
.next-actions-list li.na-info  { border-left-color: var(--info); background: var(--info-tint); }
.next-actions-list li.na-event { border-left-color: var(--success); background: var(--success-tint); }
.next-actions-list li strong { font-weight: 600; }
.next-actions-list li .muted { font-size: 12px; }

/* Linked-contact info embedded in WC detail cards */
.linked-contact-inline {
  margin-top: 6px; padding-top: 6px;
  border-top: 1px dashed var(--border); font-size: 13px;
}

/* ===== Matter timeline ===== */
.timeline { display: flex; flex-direction: column; }
.tl-entry {
  display: grid;
  grid-template-columns: 100px 130px minmax(0, 1fr) 170px;
  gap: 12px; padding: 9px 4px;
  border-bottom: 1px solid var(--border);
  align-items: start; font-size: 13px;
}
.tl-entry:last-child { border-bottom: none; }
.tl-date { color: var(--muted); font-weight: 500; white-space: nowrap; }
.tl-badge { font-size: 10px; }
.tl-body .tl-title { font-weight: 600; }
.tl-body .tl-summary {
  color: var(--text-2); font-size: 12px; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.tl-meta { color: var(--muted); font-size: 11px; text-align: right; white-space: nowrap; }
.tl-badge.tl-badge-note     { background: var(--info-tint);    color: var(--info); }
.tl-badge.tl-badge-document { background: var(--success-tint); color: var(--success); }
.tl-badge.tl-badge-event    { background: var(--info-tint);    color: var(--info); }
.tl-badge.tl-badge-task     { background: var(--warning-tint); color: var(--warning); }
.tl-badge.tl-badge-deadline { background: var(--danger-tint);  color: var(--danger); }
.tl-badge.tl-badge-records  { background: #e0e7ff; color: #4338ca; }
.tl-badge.tl-badge-motion   { background: var(--warning-tint); color: var(--warning); }
.tl-badge.tl-badge-doc_gen  { background: #f3e8ff; color: #6b21a8; }
.tl-badge.tl-badge-audit    { background: var(--primary-tint); color: var(--muted); }
@media (max-width: 900px) {
  .tl-entry { grid-template-columns: 1fr; gap: 4px; }
  .tl-meta { text-align: left; }
}

/* ===== Recent activity feed (audit trail) ===== */
.activity-feed { list-style: none; margin: 0; padding: 0; }
.activity-feed li {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.activity-feed li:last-child { border-bottom: none; }
.activity-action {
  flex-shrink: 0; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; padding: 2px 7px; border-radius: var(--r-pill);
  background: var(--primary-tint); color: var(--text-2);
}
.activity-action.act-create { background: var(--success-tint); color: var(--success); }
.activity-action.act-update { background: var(--info-tint); color: var(--info); }
.activity-action.act-delete { background: var(--danger-tint); color: var(--danger); }
.activity-action.act-view   { background: var(--primary-tint); color: var(--muted); }
.activity-text { flex: 1; min-width: 200px; }
.activity-meta { font-size: 12px; white-space: nowrap; }

/* ===== Needs Attention page ===== */
.att-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: var(--s-5); }
.att-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-pill); padding: 6px 14px;
  font-size: 13px; font-weight: 500; color: var(--text-2);
}
.att-chip b { font-size: 15px; font-weight: 700; color: var(--text); }
.att-chip:hover { border-color: var(--accent); text-decoration: none; }
.att-chip.is-zero { opacity: 0.5; }
.att-section { margin-bottom: var(--s-6); scroll-margin-top: 84px; }
.att-section h2 {
  display: flex; align-items: center; gap: 8px;
  font-size: 17px; margin-bottom: 4px;
}
.att-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-danger { background: var(--danger); }
.dot-warning { background: var(--warning); }
.dot-info { background: var(--info); }
.att-count {
  font-size: 12px; font-weight: 700; background: var(--primary-tint);
  color: var(--text-2); border-radius: var(--r-pill); padding: 1px 9px;
}
.att-note { font-size: 12px; margin: 0 0 8px; }
.badge.att-overdue { background: var(--danger-tint); color: var(--danger); }
.badge.att-soon { background: var(--warning-tint); color: var(--warning); }

/* ===== Unified deadline / SOL badges =====
   One consistent vocabulary used wherever a date is displayed:
     .dl-verified  — case is filed, statute satisfied (green check)
     .dl-met       — same as verified for non-SOL dates
     .dl-ok        — date set, far from due (default tone)
     .dl-estimated — date is auto-computed not manually verified (amber-ish)
     .dl-soon-30   — due within 30 days (amber)
     .dl-soon-7    — due within 7 days (orange)
     .dl-overdue   — past due (red)
     .dl-missing   — no date on file (grey)
*/
.dl-badge {
  display: inline-block; padding: 1px 7px; border-radius: 3px;
  font-size: 10px; font-weight: 600; letter-spacing: 0.04em;
  line-height: 1.4; white-space: nowrap; vertical-align: middle;
}
/* Theme variables (not literal hex) so these stay readable in dark mode —
   the deadline/SOL badges are scanned daily and used to go light-on-light. */
.dl-badge.dl-verified  { background: var(--success-tint); color: var(--success); }
.dl-badge.dl-met       { background: var(--success-tint); color: var(--success); }
.dl-badge.dl-ok        { background: var(--surface-2); color: var(--text-2); }
.dl-badge.dl-estimated { background: var(--warning-tint); color: var(--warning); }
.dl-badge.dl-soon-30   { background: var(--warning-tint); color: var(--warning); }
.dl-badge.dl-soon-7    { background: #ffedd5; color: #c2410c; }
.dl-badge.dl-overdue   { background: var(--danger-tint); color: var(--danger); border: 1px solid var(--danger); }
.dl-badge.dl-missing   { background: var(--surface-2); color: var(--muted); font-style: italic; }
[data-theme="dark"] .dl-badge.dl-soon-7 { background: #431407; color: #fdba74; }

/* Dashboard "needs attention" banner */
.att-banner {
  display: flex; align-items: center; gap: var(--s-3);
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--warning); border-radius: var(--r);
  padding: var(--s-3) var(--s-4); margin-bottom: var(--s-4);
  box-shadow: var(--shadow-xs);
}
.att-banner.has-urgent { border-left-color: var(--danger); }
.att-banner .att-banner-text { flex: 1; font-size: 14px; }
.att-banner .att-banner-text strong { font-weight: 600; }

/* Document-assembly preflight (missing-merge-field warning) */
.preflight-warning {
  background: var(--warning-tint); border: 1px solid var(--warning);
  border-left: 4px solid var(--warning); border-radius: var(--r);
  padding: var(--s-3) var(--s-4); margin: var(--s-3) 0;
}
.preflight-warning .preflight-head { font-size: 14px; margin-bottom: 6px; }
.preflight-warning .preflight-list {
  margin: 6px 0 8px 18px; padding: 0; font-size: 13px; columns: 2; column-gap: 24px;
}
.preflight-warning .preflight-list li { break-inside: avoid; margin-bottom: 3px; }
.preflight-warning .preflight-list code {
  font-size: 11px; background: rgba(0,0,0,0.04); padding: 1px 4px; border-radius: 3px;
}
.preflight-warning .preflight-foot { font-size: 12px; margin-top: 6px; }
.preflight-warning .preflight-fix {
  margin-left: 6px; font-size: 11px; color: var(--primary);
  text-decoration: none; white-space: nowrap;
}
.preflight-warning .preflight-fix:hover { text-decoration: underline; }
/* Consolidation banner on the matter view */
.consolidation-banner {
  background: var(--info-tint, #e0f2fe);
  border: 1px solid var(--info, #0284c7);
  border-left: 4px solid var(--info, #0284c7);
  border-radius: var(--r);
  padding: var(--s-3) var(--s-4);
  margin: 8px 0 16px;
  font-size: 13px;
}
.consolidation-banner.is-lead {
  border-left-color: var(--accent, #b45309);
  border-color: var(--accent, #b45309);
  background: var(--accent-tint, #fef3c7);
}
.consolidation-banner summary { font-weight: 600; }
.consolidation-banner ul { color: var(--text); }
.consolidation-add summary:hover { color: var(--primary); }

.preflight-ok {
  background: var(--success-tint, #e7f7ec); border: 1px solid var(--success, #15803d);
  border-left: 4px solid var(--success, #15803d); border-radius: var(--r);
  padding: var(--s-2) var(--s-4); margin: var(--s-3) 0;
  font-size: 13px; color: var(--success, #15803d);
}

/* ===== Generic dropdown menu (Actions, etc.) ===== */
.dropdown { position: relative; display: inline-block; }
.dropdown-toggle { cursor: pointer; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-sm); box-shadow: var(--shadow-lg);
  min-width: 190px; z-index: 60; padding: 4px;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a {
  display: block; padding: 8px 11px; font-size: 13px; font-weight: 500;
  color: var(--text); border-radius: var(--r-xs); white-space: nowrap;
}
.dropdown-menu a:hover { background: var(--primary-tint); text-decoration: none; }

/* ===== Admin "More" dropdown in the top nav ===== */
.nav-more-toggle {
  color: rgba(248, 250, 252, 0.82); font-weight: 500; font-size: 14px;
  padding: 8px 12px; border-radius: var(--r-sm);
  display: inline-flex; align-items: center; gap: 7px;
  background: transparent; border: none; cursor: pointer; font-family: inherit;
  transition: all var(--t-fast);
}
.nav-more-toggle svg { width: 17px; height: 17px; }
.nav-more-toggle .caret { font-size: 10px; opacity: 0.7; }
.nav-more-toggle:hover { color: #fff; background: rgba(248, 250, 252, 0.1); }
.nav-more-toggle.active { color: #fff; background: rgba(248, 250, 252, 0.15); }

/* ===== Responsive top bar — collapse labels to icons on smaller laptops ===== */
@media (max-width: 1450px) {
  .brand .brand-sub { display: none; }
  .nav-secondary a span { display: none; }
  .nav-secondary a { padding: 8px 10px; }
}
@media (max-width: 1150px) {
  .brand .brand-full { display: none; }
  .brand .brand-short { display: inline; }
  .nav-primary a span { display: none; }
  .nav-primary a { padding: 8px 10px; }
  .nav-more-toggle .nav-more-label { display: none; }
  .userbar .who { display: none; }
  .topbar { gap: var(--s-3); }
}

/* Blocks that exist only for the printed page (see print.css, which flips
   these to visible). Used for report letterhead lines that would be
   redundant on screen, where the top bar already shows the firm name. */
.print-only { display: none; }

/* ── Notes density modes ───────────────────────────────────────────────────
   Long case histories were unreadable: every note rendered full-length, so a
   12-page intake summary buried the one-line phone notes around it. Three
   modes, set by a class on .notes-timeline and remembered per browser:

     density-comfortable  full text, no clipping  (identical to the original
                          rendering — this is the "put it back" option)
     density-cozy         long bodies clipped with a fade + Show more (default)
     density-compact      one line per note; click a row to expand it

   All clipping is CSS-only, so the full text always remains in the DOM for
   copy-all, print, and browser find-in-page. */

.note-preview { display: none; }

/* --- Cozy: clip only bodies that actually overflow ----------------------- */
.density-cozy .note-body { position: relative; max-height: 11rem; overflow: hidden; }
.density-cozy .note-card.is-expanded .note-body { max-height: none; overflow: visible; }
/* Fade-out over the clipped edge. Sits above the text, below the button. */
.density-cozy .note-card.is-clipped:not(.is-expanded) .note-body::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3.2rem;
  background: linear-gradient(to bottom, transparent, var(--surface));
  pointer-events: none;
}
.density-cozy .note-card.pinned.is-clipped:not(.is-expanded) .note-body::after {
  background: linear-gradient(to bottom, transparent, var(--surface));
}

/* --- Compact: one line per note ----------------------------------------- */
.density-compact { gap: 0 !important; }
.density-compact .note-card {
  padding: 7px var(--s-4); border-radius: 0; margin: 0;
  border-top: none; box-shadow: none;
}
.density-compact .note-card + .note-card { border-top: 1px solid var(--border); }
.density-compact .note-card:not(.is-expanded) .note-meta {
  padding-bottom: 0; border-bottom: none; margin-bottom: 0; flex-wrap: nowrap;
}
.density-compact .note-card:not(.is-expanded) .note-body,
.density-compact .note-card:not(.is-expanded) .note-subject,
.density-compact .note-card:not(.is-expanded) .note-followup { display: none; }
.density-compact .note-card:not(.is-expanded) .note-preview {
  display: block; font-size: 13px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
/* The whole compact row is the expand target. */
.density-compact .note-card:not(.is-expanded) { cursor: pointer; }
.density-compact .note-card:hover { background: var(--surface-2, var(--bg)); }
.density-compact .note-card.is-expanded { padding-bottom: var(--s-4); }

/* --- Show more / less --------------------------------------------------- */
.note-more {
  display: none; margin-top: 6px; font-size: 12.5px; font-weight: 600;
  color: var(--primary); background: none; border: 0; padding: 2px 0; cursor: pointer;
}
.note-more:hover { text-decoration: underline; }
.density-cozy .note-card.is-clipped .note-more { display: inline-block; }

/* --- Density switch in the toolbar -------------------------------------- */
.density-switch { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.density-switch button {
  border: 0; background: var(--surface); color: var(--muted);
  font-size: 12px; padding: 5px 10px; cursor: pointer;
}
.density-switch button + button { border-left: 1px solid var(--border); }
.density-switch button[aria-pressed="true"] { background: var(--primary); color: #fff; }

/* ── Notes pager (rendered above and below the list) ───────────────────── */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); flex-wrap: wrap;
  padding: 8px 0; margin: 0 0 var(--s-3);
}
.pager-bottom { margin: var(--s-3) 0 0; border-top: 1px solid var(--border); }
.pager-top { border-bottom: 1px solid var(--border); }
.pager-pages { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.pager-pages a, .pager-pages span {
  min-width: 30px; text-align: center;
  padding: 4px 8px; border-radius: var(--r-sm, 4px);
  font-size: 13px; line-height: 1.4; text-decoration: none;
}
.pager-pages a { color: var(--primary); border: 1px solid var(--border); background: var(--surface); }
.pager-pages a:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager-pages .current {
  background: var(--primary); color: #fff; border: 1px solid var(--primary); font-weight: 700;
}
.pager-pages .disabled { color: var(--muted); border: 1px solid transparent; opacity: .5; }
.pager-pages .gap { color: var(--muted); min-width: 16px; padding: 4px 2px; }
.pager-meta { display: flex; align-items: center; gap: var(--s-3); font-size: 12.5px; }
.pager-size { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.pager-size select { padding: 3px 6px; font-size: 12.5px; }
@media (max-width: 640px) {
  .pager { justify-content: center; }
  .pager-pages a, .pager-pages span { min-width: 26px; padding: 4px 6px; font-size: 12px; }
}

/* Expand-all toggle inside the notes pager. Pressed state is deliberately
   obvious: it persists across pages, so it must never look like a plain
   button that did nothing. */
.pager-expand {
  border: 1px solid var(--border); background: var(--surface); color: var(--primary);
  font-size: 12.5px; font-weight: 600; padding: 4px 10px;
  border-radius: var(--r-sm, 4px); cursor: pointer; white-space: nowrap;
}
.pager-expand:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager-expand[aria-pressed="true"] {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
