:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --muted: #64748b;
  --line: #e2e8f0;
  --border: var(--line); /* alias — newer sections referenced --border, which was undefined */
  --accent: #1d4ed8;
  --accent-dark: #1e3a8a;
  --accent-soft: #eff6ff;
  --good: #15803d;
  --good-bg: #dcfce7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --text: #0f172a;
  --surface: #f1f5f9;
  --surface-2: #f8fafc;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
  --shadow-md: 0 6px 18px rgba(15,23,42,.1);
  --shadow-lg: 0 20px 50px rgba(0,0,0,.35);
  --focus-ring: 0 0 0 3px rgba(29,78,216,.28);
  --speed: .15s;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--surface); color: var(--text); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
::selection { background: #bfdbfe; }

/* Keyboard-visible focus for every interactive element (a11y). */
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 6px; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { box-shadow: none; }

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

#app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, #0f172a, #1e293b);
  color: #e2e8f0; padding: 1.25rem 1rem; display: flex; flex-direction: column;
}
.brand { display: flex; gap: .6rem; align-items: center; margin-bottom: 1.5rem; }
.brand-mark { font-size: 1.7rem; }
.brand-name { font-weight: 700; font-size: 1.05rem; }
.brand-sub { font-size: .78rem; color: #94a3b8; }
/* Global search (sidebar) */
.sidebar-search { position: relative; margin-bottom: 1rem; }
.sidebar-search input {
  width: 100%; box-sizing: border-box; font: inherit; font-size: .85rem;
  padding: .5rem .7rem; border-radius: 8px; border: 1px solid #334155;
  background: #0b1220; color: #e2e8f0;
}
.sidebar-search input::placeholder { color: #64748b; }
.sidebar-search input:focus { outline: none; border-color: var(--accent); }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 60;
  background: var(--panel); color: var(--text, #0f172a); border: 1px solid var(--line);
  border-radius: 8px; max-height: 60vh; overflow: auto; box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.search-results a { display: block; padding: .5rem .7rem; text-decoration: none; color: inherit; border-bottom: 1px solid var(--line); }
.search-results a:last-child { border-bottom: none; }
.search-results a:hover { background: #f1f5f9; }
.search-results .sr-type { display: inline-block; font-size: .62rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; color: var(--accent); margin-right: .4rem; }
.search-results .sr-label { font-weight: 600; }
.search-results .sr-sub { display: block; font-size: .76rem; }
.search-results .sr-empty { padding: .6rem .7rem; font-size: .85rem; }
.nav { display: flex; flex-direction: column; gap: .25rem; }
.nav a {
  color: #cbd5e1; text-decoration: none; padding: .55rem .7rem; border-radius: 8px;
  font-size: .94rem; font-weight: 500; position: relative;
  transition: background var(--speed), color var(--speed);
}
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; }
.nav a.active::before {
  content: ""; position: absolute; left: -1rem; top: 20%; bottom: 20%; width: 3px;
  border-radius: 0 3px 3px 0; background: #93c5fd;
}
/* "New matter" is an action, not a place — style it as the sidebar's primary CTA. */
.nav a[data-nav="new"] {
  margin: .35rem 0; border: 1px dashed rgba(147,197,253,.55); color: #bfdbfe;
  font-weight: 600; text-align: center;
}
.nav a[data-nav="new"]::after { content: none; }
.nav a[data-nav="new"]::before { content: "+ "; position: static; background: none; font-weight: 700; }
.nav a[data-nav="new"]:hover { background: rgba(59,130,246,.18); border-color: #60a5fa; color: #fff; }
.nav a[data-nav="new"].active { background: var(--accent); border-color: var(--accent); color: #fff; }
.sidebar-foot { margin-top: auto; font-size: .72rem; color: #94a3b8; line-height: 1.4; padding-top: 1.5rem; }

/* Main */
.view { padding: 1.75rem 2rem; max-width: 1100px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 1.5rem; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: .2rem; }

/* Buttons */
.btn {
  font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: .5rem .95rem; border-radius: 8px; text-decoration: none; display: inline-flex;
  align-items: center; gap: .4rem;
  transition: background var(--speed), border-color var(--speed), box-shadow var(--speed), transform var(--speed);
}
.btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #fff; color: var(--accent); }
.btn.secondary:hover { background: #eff6ff; }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn.ghost:hover { background: #f8fafc; color: var(--text); }
.btn.danger { background: #fff; color: var(--bad); border-color: #fecaca; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.small { padding: .3rem .6rem; font-size: .82rem; }

/* Cards / panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.panel h2 { margin: 0 0 1rem; font-size: 1.1rem; }
.panel h3 { margin: 1.2rem 0 .6rem; font-size: .98rem; color: #334155; }

/* Dashboard cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.case-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; text-decoration: none; color: inherit; display: block;
  transition: box-shadow var(--speed), transform var(--speed), border-color var(--speed);
}
.case-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: #cbd5e1; }
.case-card .name { font-weight: 700; font-size: 1.05rem; }
.case-card .meta { color: var(--muted); font-size: .85rem; margin-top: .35rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }

/* Badges */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 700; letter-spacing: .02em; }
.badge.chapter { background: #e0e7ff; color: #3730a3; }
.badge.status-intake { background: #e2e8f0; color: #334155; }
.badge.status-review { background: #fef3c7; color: #92400e; }
.badge.status-ready { background: #dbeafe; color: #1e40af; }
.badge.status-filed { background: #dcfce7; color: #166534; }
.badge.status-discharged { background: #d1fae5; color: #065f46; }
.badge.status-dismissed, .badge.status-closed { background: #f1f5f9; color: #64748b; }

/* Tabs */
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 2px solid var(--line); margin-bottom: 1.25rem; }
.tabs button {
  font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; border: none; background: none;
  color: var(--muted); padding: .55rem .8rem; border-bottom: 2px solid transparent; margin-bottom: -2px;
  border-radius: 6px 6px 0 0; transition: color var(--speed), background var(--speed), border-color var(--speed);
}
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
/* Anchor-style tabs (Settings) reuse the same look as button tabs. */
.tabs a.tab {
  font-size: .88rem; font-weight: 600; text-decoration: none;
  color: var(--muted); padding: .55rem .8rem; border-bottom: 2px solid transparent; margin-bottom: -2px;
  border-radius: 6px 6px 0 0; transition: color var(--speed), background var(--speed), border-color var(--speed);
}
.tabs a.tab:hover { color: var(--text); background: var(--surface-2); }
.tabs a.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
/* Custom-category chips */
.cat-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.cat-chip .cat-del { background: none; border: none; cursor: pointer; color: inherit; font-size: .85em; opacity: .7; padding: 0 0 0 .15rem; }
.cat-chip .cat-del:hover { opacity: 1; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.nav-admin { margin-top: .35rem; border-top: 1px solid var(--line); padding-top: .55rem; }
.row-suspended { opacity: .6; }
.build-stamp { opacity: .6; font-variant-numeric: tabular-nums; margin-top: .3rem; }

/* Forms */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem 1.1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field label { font-size: .82rem; font-weight: 600; color: #475569; }
.field input, .field select, .field textarea {
  font: inherit; font-size: .92rem; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; color: var(--text); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
.field .hint { font-size: .74rem; color: var(--muted); }

/* Repeating list editor */
.list-editor table { width: 100%; border-collapse: collapse; }
.list-editor th { text-align: left; font-size: .78rem; color: var(--muted); padding: .3rem .4rem; font-weight: 600; }
.list-editor td { padding: .25rem .4rem; vertical-align: middle; }
.list-editor input, .list-editor select { width: 100%; font: inherit; font-size: .88rem; padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 6px; }
.list-editor .row-del { color: var(--bad); cursor: pointer; border: none; background: none; font-size: 1.1rem; padding: 0 .3rem; }
.list-editor .subtotal { font-weight: 700; padding: .4rem; text-align: right; color: #334155; }
.col-amt { width: 140px; }
.col-del { width: 34px; }

/* Sticky save bar */
.savebar {
  position: sticky; bottom: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(4px);
  border-top: 1px solid var(--line); padding: .8rem 0; margin-top: 1rem; display: flex;
  gap: .6rem; align-items: center;
}
.savebar .status { color: var(--muted); font-size: .85rem; margin-left: auto; }

/* Result / means test */
.result-banner { padding: 1rem 1.2rem; border-radius: var(--radius); font-weight: 700; font-size: 1.02rem; margin-bottom: 1rem; }
.result-banner.pass { background: var(--good-bg); color: var(--good); border: 1px solid #86efac; }
.result-banner.fail { background: var(--bad-bg); color: var(--bad); border: 1px solid #fca5a5; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.kpi { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: .7rem .8rem; }
.kpi .label { font-size: .76rem; color: var(--muted); }
.kpi .val { font-size: 1.15rem; font-weight: 700; margin-top: .15rem; }

/* Bar charts (dependency-free, scaled inline) */
.barchart { margin-top: .4rem; }
.bc-legend { font-size: .8rem; color: var(--muted); margin-bottom: .5rem; display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.bc-key { display: inline-block; width: .8rem; height: .8rem; border-radius: 2px; margin-right: .1rem; }
.bc-key.bc-b { margin-left: .8rem; }
.bc-cols { display: flex; align-items: flex-end; gap: .35rem; height: 160px; overflow-x: auto; padding-bottom: .2rem; }
.bc-col { flex: 1 0 28px; display: flex; flex-direction: column; align-items: center; height: 100%; }
.bc-bars { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; width: 100%; }
.bc-bar { width: 45%; min-height: 1px; border-radius: 2px 2px 0 0; }
.bc-bar.bc-a, .bc-key.bc-a { background: var(--accent, #2563eb); }
.bc-bar.bc-b, .bc-key.bc-b { background: #16a34a; }
.bc-x { font-size: .68rem; color: var(--muted); margin-top: .25rem; white-space: nowrap; }

/* Tables (read-only) */
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { border-bottom: 1px solid var(--line); padding: .5rem .6rem; text-align: left; }
table.data th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
table.data td.num, table.data th.num { text-align: right; }

/* Deadlines */
.deadline { display: flex; align-items: center; gap: .8rem; padding: .65rem .2rem; border-bottom: 1px solid var(--line); }
.deadline:last-child { border-bottom: none; }
.deadline .dl-check { width: 18px; height: 18px; }
.deadline .dl-main { flex: 1; }
.deadline .dl-label { font-weight: 600; }
.deadline .dl-basis { font-size: .76rem; color: var(--muted); margin-top: .1rem; }
.deadline .dl-date { font-weight: 700; white-space: nowrap; text-align: right; }
.deadline .dl-sub { font-size: .74rem; color: var(--muted); text-align: right; }
.deadline.overdue .dl-date { color: var(--bad); }
.deadline.soon .dl-date { color: var(--warn); }
.deadline.completed .dl-label { text-decoration: line-through; color: var(--muted); }
.pill { font-size: .68rem; font-weight: 700; padding: .1rem .4rem; border-radius: 5px; }
.pill.overdue { background: var(--bad-bg); color: var(--bad); }
.pill.soon { background: var(--warn-bg); color: var(--warn); }
.pill.est { background: #e2e8f0; color: #475569; }

/* Toast */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: .65rem 1.1rem; border-radius: 8px;
  font-size: .9rem; box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 50;
}
.toast.bad { background: var(--bad); }
.toast.good { background: var(--good); }

.notice {
  background: var(--warn-bg); border: 1px solid #fde68a; color: #92400e;
  padding: .55rem .8rem; border-radius: 8px; font-size: .8rem; line-height: 1.45; margin-bottom: 1rem;
}
.muted { color: var(--muted); }
.row-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.form-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); gap: .6rem; }
.form-links a { border: 1px solid var(--line); border-radius: 8px; padding: .7rem .8rem; text-decoration: none; color: var(--text); font-weight: 600; font-size: .9rem; background: #fff; }
.form-links a:hover { background: #eff6ff; border-color: var(--accent); }

/* Boot / auth */
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: linear-gradient(160deg, #0f172a, #1e293b); }
.auth-card { background: #fff; border-radius: 14px; padding: 1.6rem 1.7rem; width: 100%; max-width: 420px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.auth-brand { display: flex; gap: .6rem; align-items: center; margin-bottom: 1.2rem; }
.auth-brand .brand-name { font-weight: 700; font-size: 1.1rem; }
.auth-brand .brand-sub { font-size: .8rem; color: var(--muted); }
.auth-tabs { margin-bottom: 1.2rem; }
.auth-foot { color: #94a3b8; font-size: .78rem; margin-top: 1rem; text-align: center; }
.auth-hint { text-align: center; margin: .7rem 0 0; font-size: .85rem; }
.auth-hint a { color: var(--accent); text-decoration: none; }
.auth-hint a:hover { text-decoration: underline; }
.btn.block { display: flex; width: 100%; justify-content: center; margin-top: .4rem; }
.form-err { color: var(--bad); font-size: .85rem; min-height: 1.1rem; margin: .3rem 0; }

/* Plan chip in sidebar */
#planChip { margin: 0 0 1rem; }
.plan-chip { display: flex; justify-content: space-between; align-items: center; text-decoration: none; padding: .5rem .7rem; border-radius: 8px; background: rgba(255,255,255,.06); }
.plan-chip .pc-plan { color: #fff; font-weight: 700; font-size: .85rem; }
.plan-chip .pc-status { font-size: .7rem; font-weight: 700; text-transform: capitalize; padding: .1rem .45rem; border-radius: 999px; }
.plan-chip.ok .pc-status { background: #14532d; color: #bbf7d0; }
.plan-chip.warn { outline: 1px solid #b45309; }
.plan-chip.warn .pc-status { background: #7c2d12; color: #fed7aa; }

.sidebar-foot .who { margin-bottom: .5rem; }
.sidebar-foot .who-email { color: #e2e8f0; font-size: .82rem; font-weight: 600; word-break: break-all; }
.sidebar-foot .who-role { color: #94a3b8; font-size: .72rem; text-transform: capitalize; }
.btn.ghost.small.block { width: 100%; justify-content: center; color: #cbd5e1; border-color: rgba(255,255,255,.18); margin-bottom: .8rem; }
.btn.ghost.small.block:hover { background: rgba(255,255,255,.08); color: #fff; }

/* Usage meters */
.usage-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.usage-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: .8rem .9rem; }
.usage-card .label { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.usage-card .val { font-size: 1.25rem; font-weight: 700; margin-top: .15rem; }
.usage-card .bar { height: 6px; background: #e2e8f0; border-radius: 999px; margin-top: .5rem; overflow: hidden; }
.usage-card .bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.usage-card .bar span.near { background: var(--warn); }

/* CRM */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
.rowlink { cursor: pointer; }
.rowlink:hover td { background: #f8fafc; }
.badge.stage-lead { background: #e2e8f0; color: #334155; }
.badge.stage-consult { background: #fef3c7; color: #92400e; }
.badge.stage-retained { background: #dbeafe; color: #1e40af; }
.badge.stage-active { background: #dcfce7; color: #166534; }
.badge.stage-closed { background: #f1f5f9; color: #64748b; }
.badge.stage-lost { background: #fee2e2; color: #b91c1c; }
.linklist, .notelist, .tasklist { list-style: none; padding: 0; margin: 0; }
.linklist li { padding: .3rem 0; }
.notelist li { border-bottom: 1px solid var(--line); padding: .5rem 0; font-size: .9rem; }
.notelist li:last-child { border-bottom: none; }
.note-meta { font-size: .74rem; color: var(--muted); margin-bottom: .15rem; }
.tasklist li { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--line); }
.tasklist li:last-child { border-bottom: none; }
.tasklist li.done .t-title { text-decoration: line-through; color: var(--muted); }
.tasklist .t-title { flex: 1; }
.tasklist .t-due { font-size: .76rem; color: var(--warn); }
.addrow { display: flex; gap: .5rem; margin: .6rem 0; align-items: flex-start; }
.addrow input, .addrow textarea { font: inherit; font-size: .9rem; padding: .45rem .55rem; border: 1px solid var(--line); border-radius: 7px; flex: 1; }
.check { display: flex; gap: .5rem; align-items: flex-start; font-size: .88rem; line-height: 1.3; }
.check input { margin-top: .15rem; }
.consent-ok { color: var(--good); font-weight: 600; font-size: .88rem; margin-bottom: .6rem; }
.report-card { border: 1px solid var(--line); border-radius: 9px; padding: .7rem .8rem; margin-bottom: .7rem; }
.rc-head { font-size: .9rem; }
.rc-scores { font-size: .82rem; color: var(--accent-dark); font-weight: 600; margin: .2rem 0; }
.rc-totals { font-size: .85rem; margin-bottom: .5rem; }
.modal-inline { border: 2px solid var(--accent); border-radius: 9px; padding: .7rem .8rem; margin-bottom: .8rem; background: #f8fafc; }
.mi-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }

/* Bug reporter FAB + modal */
.report-fab { position: fixed; bottom: 1.25rem; right: 1.25rem; z-index: 40; border: 1px solid var(--accent-dark); background: var(--accent); color: #fff; font: inherit; font-weight: 700; font-size: .88rem; padding: .6rem 1rem; border-radius: 999px; cursor: pointer; box-shadow: 0 6px 18px rgba(15,23,42,.25); }
.report-fab:hover { background: var(--accent-dark); }
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 60; padding: 1.5rem; }
.modal-card { background: #fff; border-radius: 12px; padding: 1.25rem 1.4rem; width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.modal-card.wide { max-width: 720px; }
.modal-card .field, .modal-card textarea { margin-bottom: .2rem; }
.modal-card textarea { font: inherit; font-size: .92rem; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 7px; width: 100%; }
.kvs { display: flex; flex-direction: column; gap: .4rem; font-size: .9rem; }
.errpre { background: #0f172a; color: #e2e8f0; padding: .6rem .7rem; border-radius: 7px; font-size: .78rem; overflow: auto; max-height: 180px; white-space: pre-wrap; }

/* Dashboard filter bar */
.filter-bar { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 1rem; }
.filter-chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--muted); padding: .35rem .8rem; border-radius: 999px; transition: color var(--speed), background var(--speed), border-color var(--speed); }
.chip:hover { color: var(--text); border-color: #cbd5e1; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.filter-search { font: inherit; font-size: .9rem; padding: .5rem .8rem; border: 1px solid var(--line); border-radius: 8px; min-width: 220px; flex: 0 1 280px; }

/* Practice-area badges + settings */
.badge.pa-bankruptcy { background: #e0e7ff; color: #3730a3; }
.badge.pa-personal_injury { background: #fee2e2; color: #b91c1c; }
.badge.pa-family_law { background: #dcfce7; color: #166534; }
.badge.pa-estate_planning { background: #fef3c7; color: #92400e; }
.badge.pa-civil_litigation { background: #e2e8f0; color: #334155; }
.badge.pa-insurance { background: #cffafe; color: #155e75; }
.pa-list { display: flex; flex-direction: column; gap: .6rem; }
.pa-opt { display: flex; gap: .6rem; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; cursor: pointer; }
.pa-opt input { margin-top: .2rem; }
.pa-opt.soon { opacity: .8; }

/* AI Advisor */
.factors { display: flex; flex-direction: column; gap: .6rem; }
.factor { border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px; padding: .6rem .8rem; }
.factor.wt-high { border-left-color: var(--accent); }
.factor.wt-medium { border-left-color: #60a5fa; }
.factor.wt-low { border-left-color: #cbd5e1; }
.factor .f-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .2rem; }
.riskflags { display: flex; flex-direction: column; gap: .55rem; }
.riskflag { display: flex; gap: .7rem; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; }
.riskflag.sev-high { background: #fef2f2; border-color: #fecaca; }
.riskflag.sev-medium { background: #fffbeb; border-color: #fde68a; }
.riskflag.sev-low { background: #f8fafc; }
.rf-title { font-weight: 600; }
.sev-badge { font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; padding: .15rem .45rem; border-radius: 5px; white-space: nowrap; }
.sev-badge.sev-high { background: var(--bad-bg); color: var(--bad); }
.sev-badge.sev-medium { background: var(--warn-bg); color: var(--warn); }
.sev-badge.sev-low { background: #e2e8f0; color: #475569; }
.assessment { margin-top: 1rem; border: 1px solid var(--line); border-radius: 8px; padding: 1rem; background: #f8fafc; }
.assessment .a-src { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: .4rem; }
.assessment p { margin: 0; line-height: 1.6; }

/* Danger zone */
.danger-zone { margin-top: 1.2rem; border: 1px solid #fecaca; background: #fef2f2; border-radius: 10px; padding: 1rem 1.1rem; }
.danger-zone h3 { margin-top: 0; color: var(--bad); }

/* Plans */
.plans { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.plan-card { border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem; display: flex; flex-direction: column; }
.plan-card.current { border-color: var(--accent); box-shadow: 0 0 0 2px #bfdbfe inset; }
.pc-name { font-weight: 700; font-size: 1.05rem; }
.pc-price { font-size: 1.6rem; font-weight: 800; margin: .3rem 0; }
.pc-price span { font-size: .85rem; font-weight: 500; color: var(--muted); }
.pc-features { list-style: none; padding: 0; margin: .3rem 0 .8rem; font-size: .85rem; color: #334155; }
.pc-features li { padding: .15rem 0 .15rem 1.1rem; position: relative; }
.pc-features li::before { content: "✓"; position: absolute; left: 0; color: var(--good); font-weight: 700; }
.pc-limits { font-size: .78rem; margin-bottom: .7rem; }
.plan-card .btn { margin-top: auto; }

/* Mobile top bar + nav drawer (hidden on desktop) */
.topbar { display: none; }
.nav-scrim { display: none; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }

  .topbar {
    display: flex; align-items: center; gap: .75rem; position: sticky; top: 0; z-index: 45;
    background: #0f172a; color: #fff; padding: .6rem .9rem;
  }
  /* ≥44px touch target (WCAG 2.5.5) — the old .2/.4rem padding made a ~32×29px button. */
  .hamburger { font-size: 1.4rem; line-height: 1; background: none; border: none; color: #fff; cursor: pointer; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .topbar-title { font-weight: 700; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Sidebar becomes an off-canvas drawer */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 78%; max-width: 300px; z-index: 60;
    transform: translateX(-100%); transition: transform .22s ease; overflow-y: auto;
  }
  .nav-scrim {
    position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 55;
    opacity: 0; pointer-events: none; transition: opacity .22s ease;
  }
  #app.nav-open .sidebar { transform: translateX(0); }
  #app.nav-open .nav-scrim { display: block; opacity: 1; pointer-events: auto; }

  .nav a { padding: .75rem .8rem; font-size: 1rem; } /* larger touch targets */
  .view { padding: 1.1rem 1rem; }
  .page-head h1 { font-size: 1.25rem; }

  /* Wide tables and the case-tab bar scroll horizontally instead of overflowing */
  .panel { overflow-x: auto; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tabs button { white-space: nowrap; }
  .list-editor { overflow-x: auto; }

  .report-fab { bottom: .8rem; right: .8rem; padding: .55rem .8rem; }
  .grid { grid-template-columns: 1fr; }
  .kpis, .usage-row { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .modal-card { max-width: 100%; }
}

/* Very small phones */
@media (max-width: 420px) {
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-search { min-width: 0; width: 100%; }
  .page-head { flex-direction: column; align-items: flex-start; }
}

/* Per-matter activity timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .35rem 0; border-bottom: 1px solid var(--border, #e5e7eb); font-size: .88rem; display: flex; flex-wrap: wrap; gap: .5rem; }
.timeline li:last-child { border-bottom: none; }
.timeline .tl-when { color: #6b7280; min-width: 12rem; }
.timeline .tl-what { font-weight: 600; }

/* Firm-side secure message thread (client detail) */
.msg-thread-firm { display: flex; flex-direction: column; gap: .4rem; max-height: 40vh; overflow-y: auto; }
.pmsg { max-width: 85%; padding: .45rem .65rem; border-radius: 10px; font-size: .88rem; line-height: 1.4; }
.pmsg .who { font-size: .72rem; color: #64748b; margin-bottom: .15rem; }
.pmsg.in { align-self: flex-start; background: #eef2ff; }
.pmsg.out { align-self: flex-end; background: #dcfce7; }

/* Topbar notifications bell */
.notif-wrap { position: relative; margin-left: auto; }
.notif-bell { background: none; border: none; font-size: 1.15rem; cursor: pointer; position: relative; line-height: 1; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.notif-badge { position: absolute; top: -2px; right: -2px; background: #dc2626; color: #fff; font-size: .62rem; font-weight: 700; min-width: 1rem; height: 1rem; padding: 0 .2rem; border-radius: 1rem; display: inline-flex; align-items: center; justify-content: center; }
.notif-panel { position: absolute; right: 0; top: 2.1rem; width: min(22rem, 90vw); background: #fff; border: 1px solid var(--border, #e5e7eb); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.16); z-index: 60; overflow: hidden; }
.notif-head { padding: .5rem .8rem; font-weight: 700; font-size: .82rem; border-bottom: 1px solid var(--border, #e5e7eb); }
.notif-item { display: flex; gap: .5rem; padding: .5rem .8rem; font-size: .85rem; color: inherit; text-decoration: none; border-bottom: 1px solid #f1f5f9; cursor: pointer; }
.notif-item:hover { background: #f8fafc; }
.notif-ico { flex: none; }
.notif-foot { display: block; padding: .5rem .8rem; font-size: .82rem; font-weight: 600; color: inherit; text-decoration: none; cursor: pointer; }
.notif-foot:hover { background: #f8fafc; }
.notif-empty { padding: 1rem .8rem; text-align: center; font-size: .85rem; }
