:root {
  --orange: #e95e27;
  --orange-dark: #bd4316;
  --navy: #233b45;
  --ink: #2f454e;
  --muted: #5f7178;
  --line: #dfe6e8;
  --surface: #ffffff;
  --background: #f4f6f5;
  --green: #1f765e;
  --amber: #8a5500;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--background);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--background); }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:where(a, button, input, select, summary):focus-visible { outline: 3px solid var(--orange-dark); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { transition: none !important; } }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(145deg, #edf1f2, #f9faf9); }
.auth-card { width: min(430px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: 0 22px 65px rgba(35,59,69,.13); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; color: var(--navy); }
.auth-brand strong, .auth-brand span { display: block; }
.auth-brand span { color: var(--muted); font-size: 12px; }
.auth-intro { margin-bottom: 24px; color: var(--muted); }
#login-form { display: grid; gap: 16px; }
#login-button { margin-top: 4px; }
.account-actions { display: flex; align-items: center; gap: 10px; }
.client-context { margin: 0; color: var(--muted); font-size: 13px; }
.client-context strong { color: var(--navy); }

.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; color: white; background: var(--orange); font-size: 22px; font-weight: 800; }
.eyebrow { margin: 0 0 5px; color: var(--orange-dark); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; color: var(--navy); font-size: clamp(26px, 3vw, 36px); }
h2 { margin-bottom: 0; color: var(--navy); font-size: 25px; }
h3 { margin-bottom: 4px; color: var(--navy); font-size: 16px; }
.muted, .panel-heading p { color: var(--muted); }
label { color: var(--navy); font-size: 12px; font-weight: 700; }
input, select { width: 100%; min-height: 42px; margin-top: 6px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: white; }
input:focus { border-color: var(--orange-dark); }
.dashboard-error { padding: 10px 13px; border-radius: 9px; color: #991b1b; background: #fee2e2; font-size: 13px; }

.button { min-height: 40px; padding: 9px 16px; border: 1px solid transparent; border-radius: 10px; font-weight: 750; transition: transform .15s ease, background .15s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .45; transform: none; }
.button--primary { color: white; background: var(--orange-dark); }
.button--primary:hover { background: #96340f; }
.button--ghost { border-color: var(--line); color: var(--navy); background: white; }
.button--range { min-height: 34px; padding: 6px 10px; border-color: var(--line); color: var(--navy); background: white; font-size: 12px; }
.button--range[aria-pressed="true"] { border-color: var(--orange-dark); color: white; background: var(--orange-dark); }

.app-shell { min-height: 100vh; }
.skip-link { position: fixed; z-index: 30; top: 8px; left: 8px; padding: 9px 12px; border-radius: 8px; color: white; background: var(--navy); transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }
.skip-link:focus-visible, .sidebar .nav-link:focus-visible { outline-color: white; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 235px; display: flex; flex-direction: column; padding: 28px 20px; color: white; background: var(--navy); }
.brand-row { display: flex; align-items: center; gap: 12px; margin-bottom: 46px; }
.brand-row strong, .brand-row span { display: block; }
.brand-row span { color: #b8c5ca; font-size: 12px; }
.sidebar nav { display: grid; gap: 8px; }
.nav-link { padding: 11px 13px; border-radius: 9px; color: #cbd6da; text-decoration: none; font-size: 14px; font-weight: 650; }
.nav-link:hover, .nav-link.active { color: white; background: rgba(255,255,255,.1); }

.content { margin-left: 235px; padding: 32px clamp(24px, 4vw, 60px) 80px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 25px; }
.filters { display: grid; grid-template-columns: auto 150px 150px auto auto; align-items: end; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: white; box-shadow: 0 3px 12px rgba(35,59,69,.04); }
.range-presets { display: flex; align-items: center; gap: 6px; min-height: 42px; }
.loading { margin-top: 15px; padding: 11px 15px; border-radius: 9px; background: #fff5f0; color: var(--orange-dark); }
.dashboard-error { margin-top: 15px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 42px 0 16px; }
.pill { display: inline-flex; align-items: center; min-height: 28px; padding: 5px 10px; border-radius: 999px; color: var(--muted); background: #e8eeee; font-size: 11px; font-weight: 750; }
.local-badge { color: #11634f; background: #dff5ee; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi, .panel { border: 1px solid var(--line); border-radius: 15px; background: var(--surface); box-shadow: 0 4px 18px rgba(35,59,69,.04); }
.kpi { display: grid; gap: 7px; padding: 20px; }
.kpi > span { color: var(--muted); font-size: 12px; font-weight: 700; }
.kpi strong { color: var(--navy); font-size: 31px; line-height: 1; }
.kpi small { color: var(--muted); font-size: 11px; }
.panel { padding: 21px; }
.chart-panel { margin-top: 14px; }
.panel-heading { display: flex; justify-content: space-between; align-items: start; gap: 20px; margin-bottom: 18px; }
.panel-heading p { margin: 0; font-size: 12px; }
.trend-chart { display: block; width: 100%; min-height: 240px; overflow: visible; }
.chart-axis { stroke: #dfe6e8; stroke-width: 1; }
.chart-line { fill: none; stroke: var(--orange); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: url(#trend-gradient); }
.chart-point { fill: white; stroke: var(--orange); stroke-width: 3; }
.chart-label { fill: var(--muted); font-size: 11px; }

.topic-list { display: grid; gap: 16px; }
.topic-row { display: grid; grid-template-columns: minmax(130px, 220px) 1fr 72px; align-items: center; gap: 14px; }
.topic-name strong, .topic-name span { display: block; }
.topic-name span { margin-top: 3px; color: var(--muted); font-size: 10px; }
.topic-track { height: 9px; overflow: hidden; border-radius: 99px; background: #edf1f2; }
.topic-fill { height: 100%; min-width: 3px; border-radius: inherit; background: var(--orange); }
.topic-value { text-align: right; color: var(--navy); font-weight: 800; }
.empty-state { padding: 35px 15px; color: var(--muted); text-align: center; }

.insight-strip { display: grid; grid-template-columns: 150px 150px minmax(240px, 1fr) auto; align-items: center; gap: 0; margin-top: 14px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.72); }
.insight-strip > div { display: grid; gap: 3px; min-height: 58px; padding: 13px 16px; border-right: 1px solid var(--line); }
.insight-strip span { color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
.insight-strip strong { color: var(--navy); font-size: 12px; }
.insight-strip details { position: relative; padding: 13px 16px; color: var(--orange-dark); font-size: 11px; font-weight: 750; }
.insight-strip summary { cursor: pointer; white-space: nowrap; }
.methodology-copy { position: absolute; z-index: 3; top: calc(100% + 10px); right: 0; width: min(440px, 80vw); padding: 18px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: white; box-shadow: 0 16px 45px rgba(35,59,69,.16); font-weight: 400; line-height: 1.55; }
.methodology-copy p:last-child { margin-bottom: 0; }

.history-grid { display: grid; grid-template-columns: minmax(250px, .7fr) minmax(360px, 1.3fr); gap: 14px; }
.history-index, .history-transcript { min-height: 430px; }
.history-list { display: grid; gap: 8px; max-height: 560px; overflow: auto; }
.history-date-heading { position: sticky; top: 0; z-index: 1; margin: 8px 0 0; padding: 7px 3px; color: var(--muted); background: white; font-size: 11px; letter-spacing: .03em; }
.history-item { display: grid; gap: 4px; width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--navy); background: #fbfcfc; text-align: left; }
.history-item:hover { border-color: var(--orange-dark); background: #fff7f3; }
.history-item[aria-pressed="true"] { border-color: var(--orange-dark); background: #fff0e9; box-shadow: inset 4px 0 0 var(--orange-dark); }
.history-item span { color: var(--muted); font-size: 11px; }
.history-pagination { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; margin-top: 14px; }
.history-pagination .button { min-height: 34px; padding: 6px 10px; }
.history-pagination span { color: var(--muted); font-size: 11px; text-align: center; }
.history-detail-status p { margin-bottom: 14px; }
.history-messages { display: grid; gap: 12px; max-height: 540px; overflow: auto; padding-right: 6px; }
.history-message { max-width: 85%; padding: 12px 14px; border-radius: 13px; background: #edf1f2; }
.history-message--user { justify-self: end; color: white; background: var(--navy); }
.history-message--assistant { justify-self: start; }
.history-message strong { display: block; margin-bottom: 5px; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; opacity: .72; }
.history-message p { margin: 0; white-space: pre-wrap; line-height: 1.5; font-size: 13px; }

.panel-grid { display: grid; gap: 14px; margin-top: 14px; }
.panel-grid--two { grid-template-columns: repeat(2, 1fr); }
.panel-grid--three { grid-template-columns: repeat(3, 1fr); }
.distribution-list { display: grid; gap: 14px; }
.distribution-row { display: grid; gap: 7px; }
.distribution-row > div:first-child { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 11px; }
.distribution-row strong { color: var(--navy); font-size: 12px; }
.distribution-track { height: 7px; overflow: hidden; border-radius: 99px; background: #edf1f2; }
.distribution-track span { display: block; height: 100%; border-radius: inherit; background: var(--orange); }
.weekday-list { min-height: 150px; display: grid; grid-template-columns: repeat(7, 1fr); align-items: end; gap: 9px; padding-top: 15px; }
.weekday-item { height: 135px; display: grid; grid-template-rows: 20px 1fr 18px; justify-items: center; align-items: end; gap: 5px; }
.weekday-item strong { color: var(--navy); font-size: 11px; }
.weekday-item > span { width: min(28px, 75%); min-height: 3px; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, var(--orange), #f2916b); }
.weekday-item small { color: var(--muted); font-size: 10px; font-weight: 700; }

.topic-panel { margin-top: 0; }
.topic-row--other .topic-fill { background: #9aabb1; }

.legal-footer { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-top: 56px; padding-top: 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.legal-footer > div { display: flex; gap: 18px; }
.legal-link { padding: 3px 0; border: 0; color: var(--navy); background: transparent; font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.legal-link:hover { color: var(--orange-dark); }
.legal-dialog { width: min(760px, calc(100vw - 32px)); max-height: min(82vh, 900px); padding: 0; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: white; box-shadow: 0 24px 80px rgba(35,59,69,.28); }
.legal-dialog::backdrop { background: rgba(20,37,44,.62); }
.legal-dialog-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 20px 24px; border-bottom: 1px solid var(--line); background: white; }
.legal-dialog-header .eyebrow { margin-bottom: 3px; }
.legal-updated { margin: 0; padding: 16px 24px 0; color: var(--muted); font-size: 11px; }
.legal-content { padding: 16px 24px 28px; line-height: 1.65; }
.legal-content .legal-intro { padding: 14px; border-left: 4px solid var(--orange-dark); background: #fff7f3; font-weight: 650; }
.legal-content section { margin-top: 26px; }
.legal-content h3 { margin-bottom: 9px; }
.legal-content p, .legal-content li { font-size: 13px; }
.legal-content ul { padding-left: 22px; }
.legal-content li + li { margin-top: 7px; }
.change--up { color: var(--green) !important; }
.change--down { color: var(--amber) !important; }

@media (max-width: 1050px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .insight-strip { grid-template-columns: repeat(2, 1fr); }
  .insight-strip > div { border-bottom: 1px solid var(--line); }
  .insight-strip details { justify-self: end; }
  .panel-grid--three { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 780px) {
  .sidebar { position: sticky; top: 0; z-index: 10; width: auto; padding: 14px 16px 12px; gap: 11px; }
  .brand-row { margin: 0; }
  .sidebar nav { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
  .nav-link { flex: 0 0 auto; padding: 8px 10px; font-size: 12px; }
  .content { margin-left: 0; padding: 22px 16px 60px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters label:first-child { grid-column: 1 / -1; }
  .range-presets { grid-column: 1 / -1; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .history-grid, .panel-grid--two, .panel-grid--three { grid-template-columns: 1fr; }
  .topic-row { grid-template-columns: 130px 1fr 55px; }
}
@media (max-width: 520px) {
  .topbar { align-items: start; flex-direction: column; }
  .account-actions { width: 100%; justify-content: space-between; }
  .legal-footer { align-items: flex-start; flex-direction: column; }
  .legal-dialog-header, .legal-content { padding-right: 18px; padding-left: 18px; }
  .filters, .kpi-grid, .insight-strip { grid-template-columns: 1fr; }
  .filters label:first-child, .range-presets { grid-column: auto; }
  .insight-strip > div { border-right: 0; }
  .insight-strip details { justify-self: stretch; }
  .topic-row { grid-template-columns: 1fr 55px; }
  .topic-track { grid-column: 1 / -1; grid-row: 2; }
}
