:root {
  color-scheme: light;
  --canvas: #f5f7fa;
  --surface: #ffffff;
  --surface-muted: #f0f4f7;
  --ink: #172b4d;
  --muted: #5e6c84;
  --line: #dfe4ea;
  --teal: #087f8c;
  --teal-dark: #056572;
  --teal-soft: #e6f5f6;
  --amber: #a66300;
  --amber-soft: #fff4df;
  --red: #b42318;
  --red-soft: #fff0ee;
  --green: #16794a;
  --green-soft: #e8f6ef;
  --shadow: 0 1px 2px rgba(23, 43, 77, 0.08);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--canvas); }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--canvas); }
button, input, select, textarea { font: inherit; }
/* ── Button hierarchy: neutral by default, teal reserved for primary ── */
button, .button-link {
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  padding: 0.5rem 0.875rem;
  text-decoration: none;
}
button:hover, .button-link:hover { border-color: var(--teal); color: var(--teal-dark); background: var(--surface); }
button[type="submit"], button.primary, .button-link.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}
button[type="submit"]:hover, button.primary:hover, .button-link.primary:hover {
  background: var(--teal-dark); border-color: var(--teal-dark); color: #fff;
}
button:disabled { cursor: not-allowed; opacity: 0.48; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid rgba(8, 127, 140, 0.35); outline-offset: 2px; }
button.secondary, .text-button, .ghost-button { background: var(--surface); border-color: var(--line); color: var(--ink); }
button.secondary:hover, .text-button:hover, .ghost-button:hover { border-color: var(--teal); color: var(--teal-dark); }
.text-button, .ghost-button { min-height: 2rem; padding: 0.25rem 0.5rem; font-size: 0.875rem; }
.danger, .danger-button { color: var(--red) !important; }
.danger-button { background: var(--red-soft); border-color: #f1b7b1; }
.danger-button:hover { background: var(--red); border-color: var(--red); color: #fff !important; }
input, select, textarea { width: 100%; min-width: 0; border: 1px solid #bcc5d0; border-radius: 0.5rem; background: var(--surface); color: var(--ink); padding: 0.625rem 0.75rem; }
label.changed > span::after { content: " · changed"; color: var(--amber); font-weight: 800; }
label.changed input, label.changed select { border-color: var(--amber); background: var(--amber-soft); }
textarea { resize: vertical; }
label { display: grid; gap: 0.375rem; color: var(--muted); font-size: 0.875rem; font-weight: 650; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0.375rem; font-size: clamp(1.75rem, 3vw, 2.375rem); line-height: 1.15; letter-spacing: -0.035em; }
h2 { margin-bottom: 0.5rem; font-size: 1.125rem; line-height: 1.3; }
h3 { margin-bottom: 0.375rem; font-size: 1rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.skip-link { position: fixed; top: -4rem; left: 1rem; z-index: 100; background: var(--ink); color: #fff; padding: 0.75rem; }
.skip-link:focus { top: 1rem; }
.muted, small { color: var(--muted); }
.eyebrow { margin-bottom: 0.375rem; color: var(--teal-dark); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; display: flex; width: 16rem; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); padding: 1.5rem 1rem; }
.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand > div { display: grid; }
.brand span { color: var(--muted); font-size: 0.75rem; }
.brand-mark { display: grid; width: 2.25rem; height: 2.25rem; place-items: center; border-radius: 0.625rem; background: var(--teal); color: #fff !important; font-size: 1.125rem !important; font-weight: 850; }
.primary-nav { display: grid; gap: 0.25rem; margin-top: 2rem; }
.primary-nav a { display: flex; min-height: 2.75rem; align-items: center; justify-content: space-between; border-radius: 0.5rem; color: var(--muted); font-weight: 650; padding: 0.625rem 0.75rem; text-decoration: none; }
.primary-nav a:hover { background: var(--surface-muted); color: var(--ink); }
.primary-nav a.active { background: var(--teal-soft); color: var(--teal-dark); box-shadow: inset 3px 0 var(--teal); }
.nav-badge { border-radius: 999px; background: var(--amber); color: #fff; font-size: 0.75rem; padding: 0.125rem 0.5rem; }
.sidebar-footer { display: grid; gap: 0.5rem; margin-top: auto; border-top: 1px solid var(--line); padding-top: 1rem; }
.auth-state { color: var(--muted); font-size: 0.8125rem; overflow-wrap: anywhere; }
.workspace { margin-left: 16rem; min-height: 100vh; padding: 2.5rem clamp(1.25rem, 4vw, 4rem); }
.mobile-header { display: none; }
.page { width: min(76rem, 100%); margin: 0 auto; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-heading p:not(.eyebrow) { max-width: 46rem; margin-bottom: 0; color: var(--muted); }

.card { min-width: 0; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--surface); box-shadow: var(--shadow); padding: 1.25rem; }
.card-heading, .inline-actions, .pager, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.inline-actions { flex-wrap: wrap; justify-content: flex-start; }
.metric-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 1.25rem; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--surface); box-shadow: var(--shadow); }
.metric-strip article { display: grid; gap: 0.125rem; min-width: 0; padding: 1.25rem; }
.metric-strip article + article { border-left: 1px solid var(--line); }
.metric-strip span { color: var(--muted); font-size: 0.8125rem; font-weight: 650; }
.metric-strip strong { font-size: clamp(1.5rem, 3vw, 2rem); font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.metric-ok { color: var(--green); }
.metric-warn { color: var(--amber); }
.metric-bad { color: var(--red); }
/* Overview tiles double as shortcuts into the matching filtered list. */
.metric-link { display: grid; gap: 0.125rem; min-width: 0; color: inherit; text-decoration: none; }
.metric-link:hover strong, .metric-link:focus-visible strong { color: var(--teal-dark); text-decoration: underline; text-underline-offset: 0.15em; }
.metric-link small { color: var(--muted); }
.metric-link[aria-disabled="true"] { cursor: default; opacity: 0.75; }
.metric-link[aria-disabled="true"]:hover strong { color: inherit; text-decoration: none; }
/* Trend line under each overview tile, and the outbox age. */
.metric-delta { min-height: 1.1rem; font-size: 0.75rem; font-weight: 700; }
.metric-delta.metric-flat { color: var(--muted); }
.metric-strip .segmented button[aria-pressed="true"] { background: var(--teal-soft); color: var(--teal-dark); font-weight: 800; }
.page-heading .segmented { flex: 0 0 auto; }
.tz-toggle { grid-template-columns: auto; gap: 0.25rem; }
/* Number input paired with a unit picker. */
.unit-input { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0.375rem; }
.unit-input select { width: auto; padding: 0.5rem 0.4rem; font-size: 0.8125rem; }
.tz-toggle select { width: auto; min-width: 8rem; padding: 0.4rem 0.5rem; font-size: 0.8125rem; }
.overview-grid, .report-grid, .two-column { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.attention-card { border-left: 4px solid var(--amber); }
.state { border-radius: 0.5rem; background: var(--surface-muted); color: var(--muted); margin: 0.75rem 0; padding: 0.875rem; }
.state.error, .error { background: var(--red-soft); color: var(--red); }

.filter-bar, .period-controls { display: grid; grid-template-columns: 2fr repeat(3, minmax(8rem, 1fr)) auto; align-items: end; gap: 0.75rem; margin-bottom: 1.25rem; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--surface); padding: 1rem; }
.filter-actions { display: flex; gap: 0.5rem; }
.split-view { display: grid; grid-template-columns: minmax(18rem, 0.8fr) minmax(24rem, 1.2fr); gap: 1.25rem; align-items: start; }
.list-pane, .detail-pane { min-height: 32rem; }
.audit-details { grid-template-columns: minmax(6rem, auto) minmax(0, 1fr); align-items: baseline; }
.audit-details dt.meta-label { align-self: center; }
.audit-details dd { margin: 0; overflow-wrap: anywhere; }
.result-list { display: grid; gap: 0.5rem; }
.result-card { display: grid; gap: 0.375rem; width: 100%; border: 1px solid var(--line); border-left: 4px solid var(--teal); border-radius: 0.5rem; background: var(--surface); color: var(--ink); padding: 0.875rem; text-align: left; }
button.result-card:hover, button.result-card.active { background: var(--teal-soft); border-color: var(--teal); color: var(--ink); }
.result-card.status-error { border-left-color: var(--red); }
.result-card.status-bypass { border-left-color: var(--amber); }
.result-title { font-weight: 750; overflow-wrap: anywhere; }
/* Session ids are long and opaque: one truncated line, full id on hover. */
.result-card .session-id { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.75rem; }
/* Compact identity line replacing the old stacked email + full-id heading. */
.session-identity { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.75rem; }
.session-identity .session-id { flex: 1 1 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8125rem; }
.turn-tools { gap: 0.5rem; }
.turn-meta { flex: 1 1 100%; }
.result-meta { display: flex; flex-wrap: wrap; gap: 0.375rem 0.75rem; color: var(--muted); font-size: 0.8125rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
.pill { display: inline-flex; align-items: center; border-radius: 999px; font-size: 0.75rem; font-weight: 750; padding: 0.15rem 0.5rem; }
.pill-success { background: var(--green-soft); color: var(--green); }
.pill-error { background: var(--red-soft); color: var(--red); }
.pill-bypass { background: var(--amber-soft); color: var(--amber); }
.pill-route-full { background: var(--teal-soft); color: var(--teal-dark); }
.pill-route-light { background: var(--amber-soft); color: var(--amber); }
.pill-route-bypass { background: var(--surface-muted); color: var(--muted); border: 1px solid var(--line); }
.turn-sources { flex: 1 1 100%; overflow-wrap: anywhere; }
.result-count { min-height: 1.5rem; margin-bottom: 0.5rem; color: var(--muted); font-size: 0.875rem; }
.result-note { border-left: 3px solid var(--line); color: var(--muted); font-size: 0.8125rem; padding-left: 0.5rem; }

/* Review-queue keyboard flow. */
.shortcut-hint { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.4rem; margin: -0.5rem 0 1rem; color: var(--muted); font-size: 0.8125rem; }
.shortcut-hint kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 0.25rem; background: var(--surface-muted); color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.75rem; font-weight: 700; padding: 0.1rem 0.35rem; }
.result-list[role="listbox"] { gap: 0.5rem; }
/* Selection must not rely on colour alone. */
.result-list[role="listbox"] .result-card[aria-selected="true"] { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.result-list[role="listbox"] .result-card:focus-visible { outline: 3px solid rgba(8, 127, 140, 0.45); outline-offset: 2px; }
.pager { margin-top: 1rem; }
.pager button { flex: 1; }
.session-detail, .response-detail { display: grid; gap: 0.75rem; }
.turn-list { display: grid; gap: 1rem; }
.turn-row { display: grid; gap: 0.5rem; }
.turn-row .pill { justify-self: start; }
.message { max-width: 92%; border-radius: 0.75rem; padding: 0.875rem 1rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-user { justify-self: end; background: var(--surface-muted); }
.message-assistant { border: 1px solid #b8dddf; background: var(--teal-soft); }
.turn-question, .turn-answer { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
/* A hard cut mid-sentence reads as broken; fade the last line instead. */
.turn-row:not(.expanded) .turn-question, .turn-row:not(.expanded) .turn-answer {
  -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);
}
/* An expanded turn opts out of the clamp entirely. */
.turn-row.expanded .turn-question, .turn-row.expanded .turn-answer { display: block; -webkit-line-clamp: unset; overflow: visible; }
.response-panel { margin-top: 1.25rem; }
.qa-grid { display: grid; gap: 0.75rem; }
.qa-grid p, .reasoning, .chunk-card p { white-space: pre-wrap; overflow-wrap: anywhere; }
/* Rendered markdown inside messages and the answer view. */
.message p, .qa-text p { margin: 0 0 0.5rem; }
.message p:last-child, .qa-text p:last-child { margin-bottom: 0; }
.message ul, .message ol, .qa-text ul, .qa-text ol { margin: 0 0 0.5rem; padding-left: 1.25rem; }
.message li, .qa-text li { margin-bottom: 0.25rem; }
.message h4, .message h5, .message h6, .qa-text h4, .qa-text h5, .qa-text h6 { margin: 0.75rem 0 0.375rem; }
.message code, .qa-text code { border-radius: 0.25rem; background: rgba(0, 0, 0, 0.12); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.875em; padding: 0.1rem 0.3rem; }
.message pre, .qa-text pre { overflow-x: auto; border-radius: 0.5rem; background: rgba(0, 0, 0, 0.18); padding: 0.75rem; }
.message pre code, .qa-text pre code { background: none; padding: 0; }
.message blockquote, .qa-text blockquote { margin: 0 0 0.5rem; border-left: 3px solid var(--teal); padding-left: 0.75rem; color: var(--muted); }
.message a, .qa-text a { color: var(--teal-dark); font-weight: 650; }
html[data-theme="dark"] .message a, html[data-theme="dark"] .qa-text a { color: var(--teal); }
.message table, .qa-text table { display: block; overflow-x: auto; }
.qa-text { display: grid; gap: 0.25rem; }
/* Answer metrics + thinking lead the detail: meta-grid carries the numbers. */
.answer-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.thinking-block { display: grid; gap: 0.5rem; border: 1px solid var(--line); border-left: 4px solid var(--teal); border-radius: 0.5rem; background: var(--surface); padding: 0.875rem 1rem; }
.thinking-block h3 { margin: 0; font-size: 0.8125rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--teal-dark); }
.thinking-block .reasoning { margin: 0; max-height: 16rem; overflow-y: auto; }
.thinking-block .state { margin: 0; }
/* Sources render as their own visible section, matching the thinking block. */
.sources-block { display: grid; gap: 0.5rem; border: 1px solid var(--line); border-radius: 0.5rem; background: var(--surface); padding: 0.875rem 1rem; }
.sources-block h3 { margin: 0; font-size: 0.8125rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.sources-block .state { margin: 0; }
.sources-block .chunk-card p { max-height: 10rem; overflow-y: auto; }
.meta-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; }
.meta-item { display: grid; gap: 0.125rem; border-radius: 0.5rem; background: var(--surface-muted); padding: 0.625rem; }
.meta-label { color: var(--muted); font-size: 0.7rem; font-weight: 750; letter-spacing: 0.04em; text-transform: uppercase; }
.chunk-list { display: grid; gap: 0.5rem; }
.chunk-card { border-left: 3px solid var(--teal); background: var(--surface-muted); padding: 0.75rem; }
.chunk-head { display: flex; gap: 0.5rem; align-items: baseline; }
.rank-pill { color: var(--teal-dark); font-weight: 800; }
.chunk-score { margin-left: auto; }
.chunk-card pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.75rem; }
.review-form { display: grid; gap: 1rem; margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: 1.25rem; }
.review-form button[type="submit"] { background: var(--teal); color: #fff; }
.review-form fieldset { margin: 0; border: 0; padding: 0; }
.review-form legend { margin-bottom: 0.5rem; font-weight: 750; }
.rating-options { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.rating-options label { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 0.5rem; background: var(--surface); color: var(--ink); cursor: pointer; padding: 0.5rem 0.75rem; }
.rating-options label:has(input:checked) { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-dark); }
.rating-options input { width: auto; }

.narrow-card { max-width: 42rem; }
/* Quota summary: labelled rows beat a dot-separated sentence. */
.quota-summary { display: grid; gap: 0.75rem; }
.quota-identity { display: grid; gap: 0.125rem; margin: 0; overflow-wrap: anywhere; }
.quota-identity .muted { font-size: 0.8125rem; }
.quota-summary .meta-grid { grid-template-columns: minmax(8rem, auto) minmax(0, 1fr); align-items: baseline; }
.quota-summary dt.meta-label { align-self: center; }
.quota-summary dd { margin: 0; overflow-wrap: anywhere; }
.quota-summary dd.pill { justify-self: start; }
/* Settings provenance: the value you are editing, and what it replaced. */
.setting-current { color: var(--muted); font-size: 0.8125rem; font-weight: 650; }
.setting-revert { min-height: 1.75rem; align-self: end; justify-self: start; font-size: 0.8125rem; }
.sticky-actions .pending-count { color: var(--amber); font-weight: 750; }
.stack-form { display: grid; gap: 1rem; }
.period-controls { grid-template-columns: auto 1fr 1fr auto; }
.segmented { display: flex; border: 1px solid var(--line); border-radius: 0.5rem; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; background: var(--surface); color: var(--muted); }
.segmented button.active { background: var(--teal-soft); color: var(--teal-dark); }
.report-grid { margin: 1.25rem 0; }
.bar-chart { position: relative; display: flex; height: 16rem; align-items: end; gap: 0.5rem; border-bottom: 1px solid var(--line); padding-top: 1rem; }
.bar-column { display: grid; flex: 1; height: 100%; grid-template-rows: 1fr auto auto; align-items: end; gap: 0.25rem; text-align: center; }
.bar { min-height: 2px; background: var(--teal); border-radius: 0.25rem 0.25rem 0 0; }
.bar-value { color: var(--ink); font-size: 0.6875rem; font-variant-numeric: tabular-nums; font-weight: 700; }
.bar-label { color: var(--muted); font-size: 0.6875rem; }
.bar-scale { position: absolute; top: 0; left: 0; color: var(--muted); font-size: 0.6875rem; }
/* 30 daily columns cannot all show both value and date legibly. */
@media (max-width: 760px) { .bar-value { display: none; } }
.distribution { display: grid; gap: 0.75rem; }
.distribution-row { display: grid; grid-template-columns: 5.5rem 1fr 2rem; align-items: center; gap: 0.5rem; }
.distribution-track { height: 0.625rem; border-radius: 999px; background: var(--surface-muted); overflow: hidden; }
.distribution-fill { height: 100%; background: var(--amber); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: 0.75rem; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; }

.settings-layout { display: grid; gap: 1.25rem; }
.settings-layout > .card > label { max-width: 24rem; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary span { display: grid; }
.advanced-content { margin-top: 1.25rem; }
.retention-actions { display: flex; gap: 0.75rem; margin-top: 1rem; }
.sticky-actions { position: sticky; bottom: 1rem; display: flex; align-items: center; gap: 0.75rem; border: 1px solid var(--line); border-radius: 0.75rem; background: rgba(255, 255, 255, 0.96); box-shadow: 0 8px 30px rgba(23, 43, 77, 0.12); padding: 0.75rem; }
.sticky-actions .muted { margin-right: auto; }

.auth-panel { position: fixed; right: 1rem; bottom: 1rem; z-index: 40; width: min(24rem, calc(100vw - 2rem)); border: 1px solid #f1b7b1; border-radius: 0.75rem; background: var(--surface); box-shadow: 0 12px 40px rgba(23, 43, 77, 0.18); padding: 1.25rem; }
.auth-panel a { color: var(--teal-dark); font-weight: 750; }
/* No session at all: take over the page instead of floating over a
   shell that looks live but cannot load anything. */
.auth-panel-blocking { position: fixed; inset: 0; z-index: 60; display: grid; width: auto; max-width: 30rem; height: fit-content; align-content: center; justify-self: center; margin: auto; border-color: var(--line); box-shadow: 0 24px 70px rgba(23, 43, 77, 0.24); }
dialog { width: min(32rem, calc(100vw - 2rem)); border: 0; border-radius: 0.75rem; box-shadow: 0 20px 60px rgba(23, 43, 77, 0.28); padding: 1.5rem; }
dialog::backdrop { background: rgba(23, 43, 77, 0.48); }
.impact-preview { margin: 1rem 0; border-left: 4px solid var(--amber); background: var(--amber-soft); color: var(--amber); padding: 0.75rem; }
.dialog-actions { justify-content: flex-end; }

@media (max-width: 1080px) {
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-field, .filter-actions { grid-column: 1 / -1; }
  .split-view { grid-template-columns: 1fr; }
  .list-pane, .detail-pane { min-height: auto; }
}

/* Compatibility selectors retained for the static UI contract. */
.panel.metrics-panel { min-height: 0; }
.filters { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.filters > * { min-width: 0; }

@media (max-width: 760px) {
  .sidebar { position: fixed; inset: 4.25rem 0 auto 0; display: none; width: 100%; border-bottom: 1px solid var(--line); padding: 1rem; }
  .sidebar.open { display: block; }
  .sidebar > .brand, .sidebar-footer { display: none; }
  .primary-nav { margin-top: 0; }
  .workspace { margin-left: 0; padding: 1.25rem; }
  .mobile-header { display: flex; align-items: center; justify-content: space-between; margin: -1.25rem -1.25rem 1.5rem; border-bottom: 1px solid var(--line); background: var(--surface); padding: 1rem 1.25rem; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .metric-strip, .overview-grid, .report-grid, .two-column, .form-grid { grid-template-columns: 1fr 1fr; }
  .metric-strip article:nth-child(3) { border-left: 0; }
  .metric-strip article:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .period-controls { grid-template-columns: 1fr 1fr; }
  .segmented { grid-column: 1 / -1; }
  .sticky-actions { position: static; align-items: stretch; flex-direction: column; }
}

@media (max-width: 480px) {
  .workspace { padding: 1rem; }
  .mobile-header { margin: -1rem -1rem 1.25rem; }
  .metric-strip, .overview-grid, .report-grid, .two-column, .form-grid, .filter-bar, .period-controls { grid-template-columns: 1fr; }
  .metric-strip article + article { border-left: 0; border-top: 1px solid var(--line); }
  .filter-bar > *, .search-field, .filter-actions, .segmented { grid-column: 1; }
  .filter-actions, .retention-actions, .dialog-actions { align-items: stretch; flex-direction: column; }
  .inline-actions { align-items: stretch; }
  .inline-actions button { flex: 1; }
  .card { padding: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .skeleton-row { animation: none; }
}

/* ── Collapsible sidebar (desktop): collapse to a topbar Menu button ── */
#sidebar-expand { display: none; }
@media (min-width: 761px) {
  .app-shell.sidebar-collapsed .sidebar { display: none; }
  .app-shell.sidebar-collapsed .workspace { margin-left: 0; }
  .app-shell.sidebar-collapsed #sidebar-expand { display: inline-flex; }
}
@media (max-width: 760px) {
  #sidebar-expand { display: none !important; }
}

/* ── Wave 4 responsive polish for the new shell ── */
@media (max-width: 1080px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .search-trigger { min-width: 0; width: 100%; }
}
@media (max-width: 760px) {
  .palette { width: calc(100vw - 2rem); margin: 1rem auto; }
  .detail-tabs { overflow-x: auto; }
  .saved-views { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.25rem; }
  .breadcrumbs { font-size: 0.8125rem; }
  .toast-region { right: 0.5rem; left: 0.5rem; width: auto; }
}

/* ── Dark theme (in-memory toggle; nothing persisted to web storage) ── */
html[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0f1720;
  --surface: #182430;
  --surface-muted: #202f3f;
  --ink: #e8eef4;
  --muted: #9fb0c3;
  --line: #2c3d52;
  --teal: #3fb3c0;
  --teal-dark: #7cd4dc;
  --teal-soft: #14333a;
  --amber: #e8a838;
  --amber-soft: #3a2c12;
  --red: #f0877f;
  --red-soft: #3d1e1c;
  --green: #5fd39a;
  --green-soft: #123626;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
html[data-theme="dark"] .message-user { background: var(--surface-muted); }
html[data-theme="dark"] .message-assistant { border-color: #2a5a61; }
html[data-theme="dark"] .sticky-actions { background: rgba(24, 36, 48, 0.96); }
html[data-theme="dark"] input, html[data-theme="dark"] select, html[data-theme="dark"] textarea { background: var(--surface); border-color: var(--line); color: var(--ink); }
html[data-theme="dark"] dialog { background: var(--surface); color: var(--ink); }

/* ── Grouped nav + topbar shell (Wave 1) ── */
.nav-section { margin: 1rem 0 0.25rem; color: var(--muted); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.nav-section:first-child { margin-top: 1.25rem; }
.sidebar-section { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 0.75rem; }
.recent-list { display: grid; gap: 0.375rem; }
.recent-list button { min-height: 2rem; padding: 0.25rem 0.5rem; font-size: 0.8125rem; font-weight: 600; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-actions { display: flex; gap: 0.5rem; }
.sidebar-actions button { flex: 1; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; color: var(--muted); font-size: 0.875rem; }
.breadcrumbs a { color: var(--teal-dark); font-weight: 650; text-decoration: none; }
html[data-theme="dark"] .breadcrumbs a { color: var(--teal); }
.breadcrumbs a:hover { text-decoration: underline; }
.breadcrumbs [aria-current="page"] { color: var(--ink); font-weight: 750; }
.breadcrumb-sep { opacity: 0.6; }
.topbar-actions { display: flex; gap: 0.5rem; }
.search-trigger { min-width: min(22rem, 40vw); justify-content: flex-start; color: var(--muted); font-weight: 600; }
.search-trigger span { border: 1px solid var(--line); border-radius: 0.25rem; background: var(--surface-muted); font-size: 0.75rem; padding: 0.1rem 0.35rem; }

/* ── Command palette + toasts + skeletons ── */
.palette { width: min(36rem, calc(100vw - 2rem)); border: 1px solid var(--line); border-radius: 0.75rem; padding: 1rem; }
.palette-form { display: grid; gap: 0.75rem; }
.palette-results { display: grid; gap: 0.375rem; max-height: 22rem; overflow-y: auto; }
.palette-item { display: grid; gap: 0.125rem; width: 100%; text-align: left; border: 1px solid var(--line); border-radius: 0.5rem; background: var(--surface); padding: 0.625rem 0.75rem; }
.palette-item.active, .palette-item:hover { border-color: var(--teal); background: var(--teal-soft); }
.palette-item .muted { font-size: 0.75rem; }
.toast-region { position: fixed; right: 1rem; bottom: 1rem; z-index: 70; display: grid; gap: 0.5rem; width: min(24rem, calc(100vw - 2rem)); }
.toast { border: 1px solid var(--line); border-radius: 0.5rem; background: var(--surface); box-shadow: 0 12px 40px rgba(23, 43, 77, 0.18); color: var(--ink); padding: 0.75rem 1rem; }
.toast.toast-error { border-color: #f1b7b1; background: var(--red-soft); color: var(--red); }
.skeleton { display: grid; gap: 0.5rem; }
.skeleton-row { height: 3.25rem; border-radius: 0.5rem; background: linear-gradient(90deg, var(--surface-muted) 25%, var(--line) 50%, var(--surface-muted) 75%); background-size: 200% 100%; animation: skeleton-shimmer 1.2s infinite; }
@keyframes skeleton-shimmer { to { background-position: -200% 0; } }

/* ── Saved views + User 360 + master-detail tabs (filled in Waves 2-3) ── */
.saved-views { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.saved-views button[aria-pressed="true"] { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-dark); }
.active-filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: -0.5rem 0 1rem; }
.active-filters:empty { display: none; }
.filter-chip { display: inline-flex; align-items: center; gap: 0.375rem; min-height: 2rem; border-radius: 999px; background: var(--teal-soft); border-color: var(--teal); color: var(--teal-dark); font-size: 0.8125rem; font-weight: 650; padding: 0.25rem 0.625rem; }
.filter-chip:hover { background: var(--teal-soft); border-color: var(--teal-dark); color: var(--teal-dark); }
.filter-chip .chip-clear { font-weight: 800; }
.user360-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 1.25rem; align-items: start; }
.detail-tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.detail-tabs button { border: 0; border-radius: 0.5rem 0.5rem 0 0; background: transparent; color: var(--muted); }
.detail-tabs button[aria-selected="true"] { background: var(--teal-soft); color: var(--teal-dark); box-shadow: inset 0 -2px var(--teal); }
@media (max-width: 1080px) { .user360-grid { grid-template-columns: 1fr; } .search-trigger { min-width: 0; flex: 1; } }
