/* ============================================================
   WiseDoctor — Component Library
   Consumes tokens.css exclusively. No raw color values here.
   Load order in every page: tokens.css THEN styles.css.
   ============================================================ */

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p, figure { margin: 0; }
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; }
:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--radius-sm);
}
.tnum { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.mono { font-family: var(--font-mono); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.sprite { display: none; }

/* ---------- Typographic helpers ---------- */
.eyebrow {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps); text-transform: uppercase;
  color: var(--color-text-muted);
}
.muted { color: var(--color-text-muted); }
.h1 { font-size: var(--text-3xl); font-weight: var(--weight-heavy); line-height: var(--leading-tight); letter-spacing: var(--tracking-tight); }
.h2 { font-size: var(--text-2xl); font-weight: var(--weight-bold); line-height: var(--leading-tight); letter-spacing: var(--tracking-tight); }
.h3 { font-size: var(--text-lg); font-weight: var(--weight-semibold); line-height: var(--leading-snug); }
.h4 { font-size: var(--text-md); font-weight: var(--weight-semibold); }
.lead { font-size: var(--text-md); color: var(--color-text-muted); line-height: var(--leading-normal); }
.icon { width: 1.15em; height: 1.15em; display: inline-block; vertical-align: -0.15em; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; }
.app-header {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-5);
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--color-border);
}
.brand { display: flex; align-items: center; gap: var(--space-3); font-weight: var(--weight-bold); color: var(--color-text); letter-spacing: var(--tracking-tight); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(140deg, var(--portal-accent), color-mix(in srgb, var(--portal-accent) 55%, var(--color-accent)));
  box-shadow: var(--shadow-sm);
}
.brand-mark .icon { stroke: #fff; stroke-width: 2; }
.brand-name { font-size: var(--text-md); }
.brand-name b { color: var(--portal-accent); }
.header-portal {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide); text-transform: uppercase;
  color: var(--portal-accent);
  padding: 3px 10px; border-radius: var(--radius-pill);
  background: var(--portal-accent-tint);
}
.header-spacer { flex: 1; }
.header-actions { display: flex; align-items: center; gap: var(--space-2); }

.app-body { display: flex; align-items: flex-start; }
.side-nav {
  position: sticky; top: var(--header-h);
  width: var(--nav-w); flex: none;
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: var(--space-5) var(--space-3);
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
}
.nav-group + .nav-group { margin-top: var(--space-5); }
.nav-label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps); text-transform: uppercase;
  color: var(--color-text-muted);
  padding: 0 var(--space-3) var(--space-2);
}
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text); font-weight: var(--weight-medium);
  font-size: var(--text-base);
  margin-bottom: 2px;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item:hover { background: var(--color-surface-2); text-decoration: none; }
.nav-item .icon { color: var(--color-text-muted); }
.nav-item[aria-current="page"] {
  background: var(--portal-accent-tint); color: var(--portal-accent); font-weight: var(--weight-semibold);
}
.nav-item[aria-current="page"] .icon { color: var(--portal-accent); }

.content { flex: 1; min-width: 0; padding: var(--space-6) var(--space-6); }
.content-inner { max-width: var(--content-max); margin: 0 auto; }
.page-head { margin-bottom: var(--space-6); }
.page-head .h1 { margin-bottom: var(--space-2); }
.page-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-4); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 9px 16px; border-radius: var(--radius-sm);
  font-size: var(--text-base); font-weight: var(--weight-semibold);
  border: 1px solid transparent; background: transparent; color: var(--color-text);
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn .icon { stroke-width: 2; }
.btn-primary { background: var(--portal-accent); color: #fff; box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: color-mix(in srgb, var(--portal-accent) 86%, #000); }
.btn-primary .icon { stroke: #fff; }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--color-surface-2); }
.btn-ghost { background: transparent; color: var(--color-text); }
.btn-ghost:hover { background: var(--color-surface-2); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--color-danger) 86%, #000); }
.btn-danger .icon { stroke: #fff; }
.btn-lg { padding: 13px 24px; font-size: var(--text-md); border-radius: var(--radius); }
.btn-sm { padding: 6px 11px; font-size: var(--text-sm); }
.btn-block { display: flex; width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  background: transparent; color: var(--color-text-muted);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--color-surface-2); color: var(--color-text); }

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}
.card-flush { padding: 0; overflow: hidden; }
.card-hover { transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--color-border-strong); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.card-title { font-size: var(--text-md); font-weight: var(--weight-semibold); }
.card-body + .card-body { margin-top: var(--space-4); }
.card-footer { margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--color-border); display: flex; gap: var(--space-2); }
.card-accent { border-top: 3px solid var(--portal-accent); }

/* ---------- Layout utilities (grid/stack/cluster) ---------- */
.stack > * + * { margin-top: var(--space-4); }
.stack-sm > * + * { margin-top: var(--space-2); }
.stack-lg > * + * { margin-top: var(--space-6); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-sidebar { grid-template-columns: 1fr 320px; align-items: start; }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4, .grid-sidebar { grid-template-columns: 1fr; }
}

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  padding: 3px 10px; border-radius: var(--radius-pill);
  background: var(--color-surface-2); color: var(--color-text);
  white-space: nowrap; line-height: 1.4;
}
.badge .icon { width: 0.9em; height: 0.9em; stroke-width: 2.25; }
.badge-neutral { background: var(--color-surface-2); color: var(--color-text-muted); }
.badge-primary { background: var(--color-primary-tint); color: var(--color-primary); }
.badge-success { background: var(--color-success-tint); color: var(--color-success); }
.badge-warning { background: var(--color-warning-tint); color: var(--color-warning); }
.badge-danger  { background: var(--color-danger-tint);  color: var(--color-danger); }
.badge-info    { background: var(--color-info-tint);    color: var(--color-info); }
.badge-outline { background: transparent; border: 1px solid var(--color-border-strong); color: var(--color-text-muted); }

/* Verification + accreditation badges */
.badge-verified { background: var(--color-success-tint); color: var(--color-success); }
.badge-accredited { background: var(--color-accent-tint); color: var(--color-accent); }
.badge-pending { background: var(--color-warning-tint); color: var(--color-warning); }

/* Case-state badge — colored per state via data-state */
.state-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  letter-spacing: 0.01em;
  padding: 4px 11px 4px 9px; border-radius: var(--radius-pill);
  background: var(--_tint, var(--color-surface-2));
  color: var(--_ink, var(--color-text));
}
.state-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--_ink, var(--color-text-muted)); }
.state-badge[data-state="draft"]            { --_ink: var(--state-draft);            --_tint: var(--state-draft-tint); }
.state-badge[data-state="matched"]          { --_ink: var(--state-matched);          --_tint: var(--state-matched-tint); }
.state-badge[data-state="sent"]             { --_ink: var(--state-sent);             --_tint: var(--state-sent-tint); }
.state-badge[data-state="responses_in"]     { --_ink: var(--state-responses_in);     --_tint: var(--state-responses_in-tint); }
.state-badge[data-state="doctor_selected"]  { --_ink: var(--state-doctor_selected);  --_tint: var(--state-doctor_selected-tint); }
.state-badge[data-state="estimate_ready"]   { --_ink: var(--state-estimate_ready);   --_tint: var(--state-estimate_ready-tint); }
.state-badge[data-state="booked"]           { --_ink: var(--state-booked);           --_tint: var(--state-booked-tint); }
.state-badge[data-state="surgery_complete"] { --_ink: var(--state-surgery_complete); --_tint: var(--state-surgery_complete-tint); }
.state-badge[data-state="commission_paid"]  { --_ink: var(--state-commission_paid);  --_tint: var(--state-commission_paid-tint); }

/* ---------- Stat tiles ---------- */
.stat-tiles { display: grid; gap: var(--space-4); grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .stat-tiles { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .stat-tiles { grid-template-columns: 1fr; } }
.stat {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: var(--space-4) var(--space-5);
}
.stat-label { font-size: var(--text-xs); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-text-muted); }
.stat-value { font-size: var(--text-2xl); font-weight: var(--weight-heavy); letter-spacing: var(--tracking-tight); margin-top: 4px; }
.stat-delta { font-size: var(--text-sm); font-weight: var(--weight-medium); margin-top: 2px; }
.stat-delta.up { color: var(--color-success); }
.stat-delta.down { color: var(--color-danger); }

/* ============================================================
   SIGNATURE ELEMENT — Case-state stepper
   The 9-stage patient journey rail. Invest boldness here.
   ============================================================ */
.stepper { list-style: none; margin: 0; padding: 0; display: flex; gap: 0; overflow-x: auto; }
.stepper li {
  position: relative; flex: 1 1 0; min-width: 96px;
  padding-top: 34px; text-align: center;
}
.stepper .step-node {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--color-surface); border: 2px solid var(--color-border-strong);
  display: grid; place-items: center; z-index: 2;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.stepper .step-node .icon { width: 12px; height: 12px; stroke: #fff; stroke-width: 3; opacity: 0; }
/* connector line */
.stepper li::before {
  content: ""; position: absolute; top: 10px; left: -50%; width: 100%; height: 2px;
  background: var(--color-border); z-index: 1;
}
.stepper li:first-child::before { display: none; }
.stepper .step-label { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--color-text-muted); line-height: 1.3; }

/* done steps */
.stepper li.is-done .step-node { background: var(--portal-accent); border-color: var(--portal-accent); }
.stepper li.is-done .step-node .icon { opacity: 1; }
.stepper li.is-done::before { background: var(--portal-accent); }
.stepper li.is-done .step-label { color: var(--color-text); }
/* current step */
.stepper li.is-current .step-node {
  background: var(--color-surface); border-color: var(--portal-accent);
  transform: translateX(-50%) scale(1.18);
  box-shadow: 0 0 0 4px var(--portal-accent-tint);
}
.stepper li.is-current .step-node::after {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--portal-accent);
}
.stepper li.is-current .step-label { color: var(--portal-accent); font-weight: var(--weight-semibold); }

/* ---------- Price-transparency treatment (itemized estimate) ---------- */
.price-table { display: grid; gap: var(--space-3); }
.price-row { display: grid; grid-template-columns: 150px 1fr 132px; align-items: center; gap: var(--space-4); }
.price-row .price-name { font-weight: var(--weight-medium); }
.price-bar { position: relative; height: 10px; border-radius: var(--radius-pill); background: var(--color-surface-2); overflow: hidden; }
.price-bar span {
  position: absolute; top: 0; bottom: 0; border-radius: var(--radius-pill);
  background: linear-gradient(90deg, color-mix(in srgb, var(--portal-accent) 45%, transparent), var(--portal-accent));
}
.price-range { text-align: right; font-family: var(--font-mono); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.price-total { display: flex; align-items: baseline; justify-content: space-between; padding-top: var(--space-4); margin-top: var(--space-2); border-top: 2px solid var(--color-border); }
.price-total .price-total-value { font-size: var(--text-xl); font-weight: var(--weight-heavy); font-variant-numeric: tabular-nums; letter-spacing: var(--tracking-tight); }
@media (max-width: 640px) { .price-row { grid-template-columns: 1fr; gap: var(--space-1); } .price-range { text-align: left; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
table.data th, table.data td { padding: var(--space-3) var(--space-4); text-align: left; }
table.data thead th {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps); text-transform: uppercase;
  color: var(--color-text-muted); border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-2);
}
table.data tbody tr { border-top: 1px solid var(--color-border); }
table.data tbody tr:first-child { border-top: none; }
table.data tbody tr:hover { background: var(--color-surface-2); }
table.data td.num { font-variant-numeric: tabular-nums; text-align: right; font-family: var(--font-mono); font-size: var(--text-sm); }
table.data th.num { text-align: right; }

/* ---------- Forms ---------- */
.field { display: block; }
.field + .field { margin-top: var(--space-4); }
.label { display: block; font-size: var(--text-sm); font-weight: var(--weight-semibold); margin-bottom: 6px; }
.hint { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: 5px; }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px;
  font: inherit; color: var(--color-text);
  background: var(--color-surface); border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--color-text-muted); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--portal-accent);
  box-shadow: 0 0 0 3px var(--portal-accent-tint);
}
.textarea { min-height: 108px; resize: vertical; line-height: var(--leading-normal); }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23566A69' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px;
}
.input-group { display: flex; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .select { width: auto; border-left: none; border-top-left-radius: 0; border-bottom-left-radius: 0; }

/* Dropzone */
.dropzone {
  display: block; width: 100%; box-sizing: border-box;
  border: 2px dashed var(--color-border-strong); border-radius: var(--radius);
  background: var(--color-surface-2);
  padding: var(--space-6); text-align: center; color: var(--color-text-muted);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.dropzone:hover, .dropzone.is-over { border-color: var(--portal-accent); background: var(--portal-accent-tint); }
.dropzone .icon { width: 32px; height: 32px; color: var(--portal-accent); margin-bottom: var(--space-2); }
.dropzone strong { color: var(--color-text); display: block; font-size: var(--text-md); }

/* Consent checkbox */
.consent {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-4); border: 1px solid var(--color-border);
  border-radius: var(--radius); background: var(--color-surface);
}
.consent input[type="checkbox"] {
  appearance: none; flex: none; width: 22px; height: 22px; margin-top: 1px;
  border: 2px solid var(--color-border-strong); border-radius: 6px; background: var(--color-surface);
  display: grid; place-items: center; transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.consent input[type="checkbox"]:checked { background: var(--portal-accent); border-color: var(--portal-accent); }
.consent input[type="checkbox"]:checked::after {
  content: ""; width: 11px; height: 6px; border-left: 2.5px solid #fff; border-bottom: 2.5px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
}
.consent input[type="checkbox"]:focus-visible { box-shadow: var(--shadow-focus); }
.consent label { font-size: var(--text-sm); line-height: var(--leading-snug); color: var(--color-text); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--color-border); margin-bottom: var(--space-5); }
.tab {
  padding: var(--space-3) var(--space-3); font-weight: var(--weight-medium); font-size: var(--text-base);
  color: var(--color-text-muted); background: none; border: none; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.tab:hover { color: var(--color-text); }
.tab[aria-selected="true"] { color: var(--portal-accent); border-bottom-color: var(--portal-accent); font-weight: var(--weight-semibold); }

/* ---------- Filter rail ---------- */
.filter-rail { position: sticky; top: calc(var(--header-h) + var(--space-5)); }
.filter-group + .filter-group { margin-top: var(--space-5); padding-top: var(--space-5); border-top: 1px solid var(--color-border); }
.filter-group h4 { font-size: var(--text-sm); font-weight: var(--weight-semibold); margin-bottom: var(--space-3); }
.check-row { display: flex; align-items: center; gap: var(--space-2); padding: 4px 0; font-size: var(--text-base); color: var(--color-text); cursor: pointer; }
.check-row input { accent-color: var(--portal-accent); width: 16px; height: 16px; }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr); gap: var(--space-4); overflow-x: auto; padding-bottom: var(--space-3); align-items: start; }
.kanban-col { background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius); padding: var(--space-3); }
.kanban-col-head { display: flex; align-items: center; justify-content: space-between; padding: 2px var(--space-2) var(--space-3); }
.kanban-col-head h4 { font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.kanban-count { font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--color-text-muted); background: var(--color-surface); border-radius: var(--radius-pill); padding: 1px 8px; }
.kanban-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: var(--space-3); box-shadow: var(--shadow-xs); margin-bottom: var(--space-2); }
.kanban-card:hover { box-shadow: var(--shadow-sm); }

/* ---------- Avatars ---------- */
.avatar {
  --_size: 40px; width: var(--_size); height: var(--_size); flex: none;
  border-radius: 50%; display: inline-grid; place-items: center;
  font-size: calc(var(--_size) * 0.38); font-weight: var(--weight-semibold); color: #fff;
  background: var(--portal-accent); letter-spacing: 0.01em; overflow: hidden;
}
.avatar-sm { --_size: 28px; }
.avatar-lg { --_size: 64px; }
.avatar-xl { --_size: 96px; }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { border: 2px solid var(--color-surface); margin-left: -10px; }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* ---------- Media object (doctor row etc.) ---------- */
.media { display: flex; gap: var(--space-3); align-items: center; }
.media-body { min-width: 0; }
.media-title { font-weight: var(--weight-semibold); }
.media-sub { font-size: var(--text-sm); color: var(--color-text-muted); }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: color-mix(in srgb, var(--color-text) 45%, transparent);
  backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: var(--space-5);
}
.modal {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; padding: var(--space-6);
  animation: modal-in var(--dur) var(--ease);
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-6); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: none; } }

/* ---------- Toasts ---------- */
.toast-region { position: fixed; z-index: 100; bottom: var(--space-5); right: var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); max-width: 360px; }
.toast {
  display: flex; align-items: flex-start; gap: var(--space-3);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-left: 3px solid var(--portal-accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: var(--space-3) var(--space-4); font-size: var(--text-base);
  animation: toast-in var(--dur) var(--ease);
}
.toast.is-hiding { animation: toast-out var(--dur) var(--ease) forwards; }
.toast .icon { color: var(--portal-accent); flex: none; margin-top: 2px; }
.toast-success { border-left-color: var(--color-success); }
.toast-success .icon { color: var(--color-success); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: var(--space-8) var(--space-5); color: var(--color-text-muted); }
.empty .empty-icon { width: 52px; height: 52px; margin: 0 auto var(--space-4); color: var(--color-border-strong); display: grid; place-items: center; }
.empty .empty-icon .icon { width: 52px; height: 52px; }
.empty h3 { color: var(--color-text); font-size: var(--text-md); font-weight: var(--weight-semibold); margin-bottom: var(--space-2); }
.empty p { max-width: 42ch; margin: 0 auto var(--space-4); }

/* ---------- Masked-contact banner (anti-disintermediation) ---------- */
.masked-banner {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm);
  background: var(--color-warning-tint); color: var(--color-warning);
  font-size: var(--text-sm); font-weight: var(--weight-medium);
}
.masked-banner .icon { flex: none; }

/* ---------- Disclaimer ---------- */
.disclaimer { font-size: var(--text-sm); color: var(--color-text-muted); display: flex; gap: var(--space-2); align-items: flex-start; }
.disclaimer .icon { flex: none; margin-top: 2px; color: var(--color-text-muted); }

/* ---------- Message thread ---------- */
.thread { display: flex; flex-direction: column; gap: var(--space-3); }
.bubble { max-width: 76%; padding: var(--space-3) var(--space-4); border-radius: var(--radius); font-size: var(--text-base); line-height: var(--leading-snug); }
.bubble-in { align-self: flex-start; background: var(--color-surface-2); border-bottom-left-radius: var(--radius-sm); }
.bubble-out { align-self: flex-end; background: var(--portal-accent); color: #fff; border-bottom-right-radius: var(--radius-sm); }
.bubble-meta { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 4px; }

/* ---------- Theme toggle ---------- */
.theme-toggle .icon.sun { display: none; }
[data-theme="dark"] .theme-toggle .icon.sun { display: inline-block; }
[data-theme="dark"] .theme-toggle .icon.moon { display: none; }

/* ---------- Divider ---------- */
.divider { height: 1px; background: var(--color-border); border: none; margin: var(--space-5) 0; }

/* ---------- Responsive shell ---------- */
@media (max-width: 860px) {
  .side-nav {
    position: fixed; left: 0; top: var(--header-h); bottom: 0; z-index: 45;
    transform: translateX(-100%); transition: transform var(--dur) var(--ease);
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .side-nav { transform: none; }
  .content { padding: var(--space-5) var(--space-4); }
  .nav-toggle { display: inline-grid !important; }
}
.nav-toggle { display: none; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}
