/* portal/static/portal.css
 * Design tokens + component classes extracted from the approved design
 * (docs/design/alex-portal.dc.html). Keep hex values and sizes in sync with
 * that file -- it is the source of truth, this file just de-duplicates its
 * inline styles into reusable tokens/classes.
 */

:root {
  /* sticky .app-header height — chart tooltips and sticky sub-navs offset by it */
  --header-h: 63px;  /* 14px padding x2 + 34px content + 1px border */
  /* --- core palette (brief-mandated names) --- */
  --bg: #FCFBF9;
  --ink: #26251F;
  --muted: #6B675C;
  --faint: #6E6A60;
  --hairline: #EBE7DE;
  --accent: #E8734A;
  --card: #fff;

  /* --- extended palette (derived from the same design file) --- */
  --dim: #A39E92;
  --ink-hover: #3A382F;
  --accent-hover: #D8623A;
  --link: #B85C38;
  --link-hover: #8F4527;
  --hover-bg: #F3EFE7;
  --input-border: #E3DFD5;
  --input-border-hover: #C9C3B4;
  --avatar-bg: #4C9A8F;
  --login-bg: #F7F4EC;
  --danger: #C24A38;
  --success: #3E8E5A;
  --success-bg: #E9F4EC;
  --warn: #8A6A1B;
  --warn-bg: #FBF3DE;
  --warn-border: #EEDFB4;
  --panel-bg: #FAF8F3;
  --panel-border: #EFEBE0;
  --card-shadow: 0 4px 18px rgba(38, 37, 31, .06);

  /* --- radii --- */
  --radius-pill: 99px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --radius-xs: 8px;
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

body {
  margin: 0;
  background: var(--bg);
  font-family: Figtree, system-ui, sans-serif;
  color: var(--ink);
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); }

/* ---------------------------------------------------------------------- *
 * Auth pages (login / check-email) — centered card on a tinted background
 * ---------------------------------------------------------------------- */

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--login-bg);
}

.auth-card {
  width: 400px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 36px 36px 32px;
  box-shadow: var(--card-shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.auth-mark {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
}

.auth-title {
  font-weight: 700;
  font-size: 17px;
}

.auth-subtitle {
  font-size: 12px;
  font-weight: 500;
  color: var(--faint);
}

.auth-copy {
  font-size: 14px;
  color: var(--muted);
  margin: 22px 0 16px;
  line-height: 1.5;
}

.auth-input {
  width: 100%;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  font-family: Figtree, sans-serif;
  outline: none;
}

.auth-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}

.btn-primary {
  margin-top: 12px;
  background: var(--ink);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  font-family: Figtree, sans-serif;
}
.btn-primary:hover { background: var(--ink-hover); }
.btn-primary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.check-title {
  margin: 22px 0 6px;
  font-weight: 700;
  font-size: 15px;
}

.check-copy {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.55;
}

/* ---------------------------------------------------------------------- *
 * Signed-in app shell — top nav
 * ---------------------------------------------------------------------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  background: var(--card);
  border-bottom: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header-left {
  display: flex;
  align-items: center;
  gap: 28px;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-mark {
  width: 30px;
  height: 30px;
  background: var(--accent);
  border-radius: var(--radius-xs);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 12px;
}

.app-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
}

.app-title-sub {
  color: var(--dim);
  font-weight: 500;
}

.nav-tabs {
  display: flex;
  gap: 4px;
}

.nav-tab {
  padding: 7px 14px;
  border-radius: var(--radius-xs);
  font-weight: 500;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  border: 2px solid transparent;
}
.nav-tab:hover { background: var(--hover-bg); }
.nav-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.nav-tab--active {
  background: var(--hover-bg);
  color: var(--ink);
  font-weight: 700;
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.fresh-stamp {
  font-size: 12px;
  color: var(--faint);
}

.sign-out-link {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.sign-out-link:hover { color: var(--ink); }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--avatar-bg);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
}

/* ---------------------------------------------------------------------- *
 * Generic page/card scaffolding
 * ---------------------------------------------------------------------- */

.page-content {
  max-width: 860px;
  margin: 0 auto;
  padding: 26px 32px 40px;
}

.page-title {
  font-weight: 800;
  font-size: 22px;
}

.page-subtitle {
  font-size: 12.5px;
  color: var(--faint);
  margin-top: 4px;
}

.card {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
}

/* ---------------------------------------------------------------------- *
 * "Arriving soon" placeholder state (channels / insights / chat) and the
 * marked-but-empty containers overview reserves for Task 13's KPI/chart
 * markup.
 * ---------------------------------------------------------------------- */

.coming-soon-card {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  margin-top: 18px;
  padding: 40px 32px;
  text-align: center;
}

.coming-soon-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
}

.coming-soon-copy {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.55;
}

.placeholder-row {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 40px 22px;
  margin-top: 14px;
  text-align: center;
}
.placeholder-row:first-child { margin-top: 18px; }

.placeholder-note {
  font-size: 12px;
  color: var(--faint);
}

/* ---------------------------------------------------------------------- *
 * Admin — user table, invite row, role toggle, audit log
 * ---------------------------------------------------------------------- */

.admin-table {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  margin-top: 18px;
  overflow: hidden;
  border-collapse: collapse;
  width: 100%;
}

.admin-table thead {
  display: table-header-group;
}

.admin-table thead tr {
  display: table-row;
}

.admin-table thead th {
  display: table-cell;
  padding: 12px 20px;
  border-bottom: 1px solid var(--hairline);
  font-size: 11px;
  font-weight: 700;
  color: var(--faint);
  letter-spacing: .04em;
  text-align: left;
}

.admin-table th:nth-child(1) { width: 2fr; }
.admin-table th:nth-child(2) { width: 1fr; }
.admin-table th:nth-child(3) { width: 1.2fr; }
.admin-table th:nth-child(4) { width: 90px; }

.admin-table tbody {
  display: table-row-group;
}

.admin-table tbody tr {
  display: table-row;
}

.admin-table tbody td {
  display: table-cell;
  padding: 13px 20px;
  border-bottom: 1px solid var(--hover-bg);
  font-size: 13px;
  vertical-align: middle;
}

.admin-table tbody tr:last-child td {
  border-bottom: none;
}

.admin-email { font-weight: 600; }
.admin-last-login { color: var(--muted); }

.role-badge {
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 3px 10px;
}
.role-badge--admin { color: var(--link); background: #FDF1EB; }
.role-badge--viewer { color: var(--muted); background: var(--hover-bg); }

.admin-remove {
  font-size: 12px;
  font-weight: 700;
  color: var(--danger);
  cursor: pointer;
  text-align: right;
  background: none;
  border: 0;
  font-family: Figtree, sans-serif;
}
.admin-remove:hover { text-decoration: underline; }
.admin-remove:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.invite-row {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  background: var(--panel-bg);
  align-items: center;
}

.invite-input {
  flex: 1;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-xs);
  padding: 9px 13px;
  font-size: 13px;
  font-family: Figtree, sans-serif;
  outline: none;
}

.invite-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.role-toggle {
  display: flex;
  background: #fff;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-xs);
  padding: 2px;
}

.role-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.role-toggle label {
  padding: 6px 12px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
}

.role-toggle input:checked + label {
  background: var(--hover-bg);
  color: var(--ink);
  font-weight: 700;
}

.role-toggle input:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-invite {
  background: var(--ink);
  color: #fff;
  border: 0;
  border-radius: var(--radius-xs);
  padding: 9px 18px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  font-family: Figtree, sans-serif;
}
.btn-invite:hover { background: var(--ink-hover); }
.btn-invite:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.section-heading {
  font-weight: 700;
  font-size: 15px;
  margin: 28px 0 10px;
  color: var(--muted);
}

.audit-log {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 6px 20px;
}

.audit-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 0;
  border-bottom: 1px solid var(--hover-bg);
  font-size: 12.5px;
}
.audit-row:last-child { border-bottom: none; }

.audit-what { color: #55524A; }
.audit-when { color: var(--dim); white-space: nowrap; }
.audit-empty { color: var(--faint); font-size: 12.5px; padding: 11px 0; }

/* ---------------------------------------------------------------------- *
 * Overview (Task 13) -- live KPI cards + charts, populated by
 * portal/static/overview.js. This region deliberately does NOT use
 * .page-content: the approved design's Overview is full-width (5-col KPI
 * grid, 32px side padding), unlike the other pages' centered 860px column.
 * ---------------------------------------------------------------------- */

.overview-main { width: 100%; }

.degraded-banner {
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-border);
  color: var(--warn);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 32px;
}
.degraded-banner[hidden] { display: none; }

.basis-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px 0;
}

.basis-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.basis-toggle {
  display: flex;
  background: var(--card);
  border: 1px solid var(--input-border);
  border-radius: 9px;
  padding: 3px;
}

.basis-btn {
  padding: 6px 14px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: Figtree, sans-serif;
}
.basis-btn--active { background: var(--hover-bg); color: var(--ink); }
.basis-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.basis-note {
  font-size: 11.5px;
  color: var(--faint);
  max-width: 400px;
}

.month-range { position: relative; }

.month-range-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--input-border);
  border-radius: 9px;
  padding: 8px 14px;
}

.month-range-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-family: Figtree, sans-serif;
}
.month-range-btn:hover { border-color: var(--input-border-hover); }
.month-range-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.month-range-caret { font-size: 10px; color: var(--dim); }

.month-range-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  padding: 14px 16px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 240px;
}
.month-range-pop[hidden] { display: none; }

.month-range-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.month-range-input {
  border: 1px solid var(--input-border);
  border-radius: var(--radius-xs);
  padding: 7px 10px;
  font-size: 12.5px;
  font-family: Figtree, sans-serif;
}
.month-range-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.month-range-mode { align-self: stretch; }
.month-range-mode .basis-btn { flex: 1; }

.month-range-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.month-range-fields[hidden] { display: none; }

.month-range-error { color: var(--danger); font-size: 12px; font-weight: 600; }
.month-range-error[hidden] { display: none; }

.month-range-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  padding: 18px 32px 0;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}

.kpi-badge-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.kpi-label { font-size: 12px; font-weight: 600; color: var(--faint); }

.kpi-badge {
  font-size: 10.5px;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 2px 8px;
  white-space: nowrap;
}
.kpi-badge--healthy { color: var(--success); background: var(--success-bg); }
.kpi-badge--watch { color: var(--warn); background: var(--warn-bg); }

.kpi-value { font-size: 27px; font-weight: 800; margin-top: 6px; }
.kpi-value-suffix { font-size: 14px; font-weight: 600; color: var(--faint); margin-left: 2px; }

.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi-sub--positive { color: var(--success); font-weight: 600; }
.kpi-sub--negative { color: var(--danger); font-weight: 600; }

.kpi-goal-track {
  height: 6px;
  background: var(--hover-bg);
  border-radius: var(--radius-pill);
  margin-top: 8px;
}
.kpi-goal-fill {
  height: 6px;
  background: var(--accent);
  border-radius: var(--radius-pill);
}

.chart-row {
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: 14px;
  padding: 14px 32px 28px;
}

.chart-card { padding: 20px 22px; }

.chart-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.chart-card-title { font-weight: 700; font-size: 14.5px; }
.chart-card-hint { font-size: 11.5px; color: var(--faint); }

.chart-card-actions { display: flex; align-items: center; gap: 8px; }

.monthly-bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 214px;
  margin-top: 18px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  gap: 6px;
  height: 214px;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  font-family: Figtree, sans-serif;
}
.bar-col:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar-rect { width: 100%; border-radius: 4px 4px 2px 2px; }
.bar-col:hover .bar-rect,
.bar-col:focus-visible .bar-rect { background: var(--accent) !important; }

.bar-label {
  font-size: 10px;
  color: var(--dim);
  text-align: center;
  height: 12px;
  white-space: nowrap;
}

.chip-btn {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  cursor: pointer;
  background: #fff;
  font-family: Figtree, sans-serif;
}
.chip-btn:hover { background: var(--hover-bg); }
.chip-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip-btn[hidden] { display: none; }

.restate-badge {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--warn);
  background: var(--warn-bg);
  border-radius: var(--radius-pill);
  padding: 3px 9px;
  white-space: nowrap;
}

.daily-svg { margin-top: 18px; display: block; }

.daily-axis {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--dim);
  margin-top: 6px;
}

/* ---------------------------------------------------------------------- *
 * Channels (Stage 2 Task 3) -- monthly mix, attribution, trend cards,
 * cart funnel, net revenue. Populated by portal/static/channels.js.
 * ---------------------------------------------------------------------- */

.channels-row-top {
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: 14px;
  padding: 18px 32px 0;
}

.channels-row-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 14px 32px 28px;
}

.chart-card-sub { font-size: 11.5px; color: var(--faint); margin-top: 2px; }

.source-caption { font-size: 11px; color: var(--dim); margin-top: 14px; }

.mix-legend { display: flex; gap: 8px; flex-wrap: wrap; }

.legend-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-pill);
  padding: 4px 11px;
  cursor: pointer;
  background: #fff;
  font-family: Figtree, sans-serif;
}
.legend-chip:hover { background: var(--hover-bg); }
.legend-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.legend-chip--off { opacity: .45; }

.legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  display: inline-block;
  flex: none;
}

.mix-col { cursor: default; }

.mix-stack {
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
}

.mix-seg { width: 100%; border-radius: 3px; }

.attribution-list {
  display: flex;
  flex-direction: column;
  gap: 13px;
  margin-top: 18px;
}

.attr-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
}

.attr-val { color: var(--muted); font-weight: 500; white-space: nowrap; }

.attr-track {
  height: 8px;
  background: var(--hover-bg);
  border-radius: var(--radius-pill);
  margin-top: 5px;
}

.attr-fill { height: 8px; border-radius: var(--radius-pill); }

.trend-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding: 14px 32px 0;
}

.trend-card { padding: 16px 18px; }

.trend-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.trend-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-size: 13.5px;
}

.trend-delta { font-size: 12px; font-weight: 700; white-space: nowrap; }
.trend-delta--up { color: var(--success); }
.trend-delta--down { color: var(--danger); }

.trend-value { font-size: 22px; font-weight: 800; margin-top: 8px; }
.trend-value-caption { font-size: 12px; font-weight: 600; color: var(--faint); }

.trend-spark { width: 100%; margin-top: 10px; display: block; }

.funnel-headline { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.funnel-headline--good { color: var(--success); }
.funnel-headline--bad { color: var(--danger); }

.funnel-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.funnel-row {
  display: grid;
  grid-template-columns: 118px 1fr 150px;
  align-items: center;
  gap: 12px;
}

.funnel-name { font-size: 12.5px; font-weight: 600; color: var(--muted); }

.funnel-track {
  height: 26px;
  background: var(--hover-bg);
  border-radius: 7px;
  overflow: hidden;
}

.funnel-fill { height: 26px; background: var(--accent); border-radius: 7px; }

.funnel-val { font-size: 12.5px; font-weight: 700; text-align: right; white-space: nowrap; }

.net-table {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1.2fr 1fr 1fr;
  margin-top: 16px;
  font-size: 12.5px;
}

.net-th {
  font-weight: 700;
  color: var(--faint);
  font-size: 11px;
  padding: 8px 0;
  border-bottom: 1px solid var(--hairline);
  letter-spacing: .04em;
}

.net-td {
  padding: 11px 0;
  border-bottom: 1px solid var(--hover-bg);
}

.net-td--name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
}

.net-cell--num { text-align: right; }
.net-td--fees { color: var(--danger); }
.net-td--net { font-weight: 700; }

/* ---------------------------------------------------------------------- *
 * Chat -- ask-your-data over the analyst proxy (portal/static/chat.js)
 * ---------------------------------------------------------------------- */

/* Claude-style layout: the PAGE is viewport-locked (header stays sticky
 * above); the sidebar and the conversation each scroll independently, and
 * the composer is pinned by the flex layout — no position:fixed, so there
 * are no z-index or scroll-offset fights with the sticky header. */
.chat-main {
  display: flex;
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h)); /* mobile URL-bar resize */
  overflow: hidden;
}

.chat-layout {
  flex-direction: row;
  align-items: stretch;
  max-width: none;   /* opt out of .page-content's centered 860px column */
  padding: 0;
}

.chat-sidebar {
  width: 250px;
  flex-shrink: 0;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  border-right: 1px solid var(--hairline);
  background: var(--panel-bg);
}

.chat-panel {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* The only scrolling region for the conversation. */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
}

/* Keeps bubbles/input readable at full page width. */
.chat-thread-inner {
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  padding: 22px 24px 12px;
}

.chat-composer {
  border-top: 1px solid var(--hairline);
  background: var(--bg);
  padding: 14px 24px;
}
.chat-composer .chat-form {
  max-width: 720px;
  margin: 0 auto;
}

.chat-new-btn--sidebar {
  width: 100%;
  text-align: center;
  /* Survives a long conversation list: stays visible while the list scrolls. */
  position: sticky;
  top: 0;
  z-index: 1;
}

.chat-thread-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.chat-thread-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-thread-item:hover { background: var(--hover-bg); color: var(--ink); }
.chat-thread-item--active {
  background: var(--hover-bg);
  color: var(--ink);
  font-weight: 600;
}

@media (max-width: 720px) {
  /* Sidebar becomes a compact strip above the conversation; the page stays
   * viewport-locked so the composer remains reachable. */
  .chat-layout { flex-direction: column; }
  .chat-sidebar {
    width: 100%;
    height: auto;
    max-height: 170px;
    border-right: 0;
    border-bottom: 1px solid var(--hairline);
    padding: 12px 16px;
  }
  .chat-panel { height: auto; flex: 1; min-height: 0; }
  .chat-thread-list { max-height: 110px; }
  .chat-thread-inner { padding: 16px 16px 8px; }
  .chat-composer { padding: 10px 16px; }
}

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 22px;
}

.chat-bubble {
  max-width: 78%;
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.chat-bubble--user {
  align-self: flex-end;
  background: var(--ink);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble--answer {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-bottom-left-radius: 4px;
}

.chat-bubble--pending {
  align-self: flex-start;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--faint);
  font-style: italic;
}

.chat-bubble--error {
  align-self: flex-start;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn);
  font-weight: 600;
}

.chat-sql { margin-top: 10px; }

.chat-sql summary {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.chat-sql summary:hover { color: var(--ink); }

.chat-sql-block {
  margin: 8px 0 0;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 9px;
  padding: 12px 14px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11.5px;
  color: #55524A;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.chat-new-btn {
  padding: 7px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 9px;
  background: var(--panel-bg);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.chat-new-btn:hover { background: #fff; }

.chat-feedback {
  margin-top: 10px;
  display: flex;
  gap: 6px;
}

.chat-feedback-btn {
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  border-radius: 8px;
  padding: 3px 9px;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  filter: grayscale(1);
  opacity: 0.65;
}
.chat-feedback-btn:hover { opacity: 1; }

.chat-feedback-btn--on {
  filter: none;
  opacity: 1;
  border-color: var(--accent);
  background: #fff;
}

.chat-form {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 12px 0 16px;
}

.chat-input {
  flex: 1;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  font-family: Figtree, sans-serif;
  outline: none;
  background: var(--card);
}
.chat-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-row { grid-template-columns: 1fr; }
  .channels-row-top { grid-template-columns: 1fr; }
  .channels-row-bottom { grid-template-columns: 1fr; }
  .trend-cards { grid-template-columns: 1fr; }
}

/* Insights page — the nightly diagnostic briefing */
.insights-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.insight-group { margin-bottom: 28px; }
.insight-group-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }
.insight-card { padding: 16px 18px; margin-bottom: 10px; }
.insight-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.insight-headline { font-size: 15px; font-weight: 600; }
.insight-confidence { font-size: 11px; white-space: nowrap; padding: 2px 8px; border-radius: 999px; background: var(--hover-bg); color: var(--muted); }
.insight-confidence--high { background: var(--success-bg); color: var(--success); }
.insight-confidence--low { background: var(--warn-bg); color: var(--warn); }
.insight-narrative { font-size: 14px; line-height: 1.55; }
.insight-action { margin-top: 10px; font-size: 13.5px; line-height: 1.5; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--hover-bg); border-radius: 0 6px 6px 0; }
.insight-action-label { font-weight: 600; }

/* Shared chart tooltip (Portal.tip) — fixed-position singleton on <body>,
 * above the sticky header (z 10) and the month-range popover (z 20). */
.chart-tip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 9px;
  box-shadow: var(--card-shadow);
  padding: 8px 11px;
  font-size: 12px;
  line-height: 1.45;
  max-width: 260px;
}
.chart-tip-title { font-weight: 700; color: var(--ink); margin-bottom: 3px; white-space: nowrap; }
.chart-tip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.chart-tip-label { color: var(--muted); }
.chart-tip-value { font-weight: 600; color: var(--ink); margin-left: auto; }
.chart-tip-swatch { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }

/* ---------------------------------------------------------------------- *
 * Ads — per-ad creative performance (portal/static/ads.js)
 * ---------------------------------------------------------------------- */

.ads-main { max-width: none; }  /* full-width, like .overview-main */

.ads-head { margin-bottom: 16px; }

/* Own-math context strip: the honest return before any Meta number. */
.ownmath-strip {
  display: flex;
  align-items: center;
  gap: 40px;
  padding: 18px 24px;
  flex-wrap: wrap;
}
.ownmath-lead { flex: 1; min-width: 260px; }
.ownmath-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.ownmath-value-row { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.ownmath-value { font-size: 34px; font-weight: 800; }
.ownmath-sub { font-size: 12px; color: var(--faint); margin-top: 2px; }
.ownmath-stat-value { font-size: 20px; font-weight: 700; }
.ownmath-stat .ownmath-label { text-transform: none; letter-spacing: 0; font-weight: 500; margin-top: 2px; }

/* Verdict chips — shared with the Insights redesign (PR 6). */
.verdict-chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.verdict-chip--scale { background: var(--success-bg); color: var(--success); }
.verdict-chip--watch { background: var(--warn-bg); color: var(--warn); }
.verdict-chip--fatigue { background: #FBEAE2; color: var(--accent-hover); }
.verdict-chip--kill { background: #F9E4E0; color: var(--danger); }
.verdict-chip--quiet { background: var(--hover-bg); color: var(--muted); }

.ad-group { margin-top: 26px; }
.ad-group-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.ad-group-count { font-size: 13px; font-weight: 700; color: var(--ink); }
.ad-group-hint { font-size: 12.5px; color: var(--faint); }

.ad-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.ad-card { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.ad-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.ad-name {
  font-size: 14.5px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.ad-chips { display: flex; gap: 5px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

.ad-stats { display: flex; gap: 22px; }
.ad-stat-value { font-size: 17px; font-weight: 700; }
.ad-stat-label { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* Funnel spine: width = share of the first stage; the biggest drop-off is
 * tinted. Hover/tap a stage for the exact count (Portal.tip). */
.ad-funnel { display: flex; flex-direction: column; gap: 5px; }
.ad-funnel-stage { display: grid; grid-template-columns: 1fr 132px; align-items: center; gap: 10px; }
.ad-funnel-bar {
  height: 10px;
  border-radius: 5px;
  background: #DAD4C6;
  min-width: 8px;
}
.ad-funnel-bar--leak { background: var(--accent); }
.ad-funnel-cap { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; }
.ad-funnel-stage-label { color: var(--muted); }
.ad-funnel-count { font-weight: 600; }

.ad-meters { display: flex; flex-direction: column; gap: 4px; }
.ad-meter { display: grid; grid-template-columns: 44px 1fr 46px; align-items: center; gap: 8px; font-size: 11.5px; }
.ad-meter-label { color: var(--muted); }
.ad-meter-track { height: 5px; border-radius: 3px; background: var(--hover-bg); overflow: hidden; }
.ad-meter-fill { height: 100%; border-radius: 3px; background: var(--avatar-bg); }
.ad-meter-value { font-weight: 600; text-align: right; }

.ad-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--hairline);
  padding-top: 10px;
  margin-top: auto;
  font-size: 12px;
}
.ad-foot-note { color: var(--faint); }

@media (max-width: 720px) {
  .ownmath-strip { gap: 18px; }
  .ad-grid { grid-template-columns: 1fr; }
}


/* ---------------------------------------------------------------------- *
 * Insights redesign — narrative + data-module bands (insights.js)
 * ---------------------------------------------------------------------- */

.insights-main { max-width: none; }

.insights-nav {
  position: sticky;
  top: var(--header-h);
  z-index: 9;               /* one below the sticky app header */
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px 0;
  margin-bottom: 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--hairline);
}
.insights-nav-pill {
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}
.insights-nav-pill:hover { background: var(--hover-bg); color: var(--ink); }
.insights-nav-pill--active { background: var(--hover-bg); color: var(--ink); }

.insight-band { margin-top: 30px; scroll-margin-top: calc(var(--header-h) + 58px); }
.insight-band-grid {
  display: grid;
  grid-template-columns: minmax(340px, 5fr) 7fr;
  gap: 18px;
  align-items: start;
}
.insight-band--full .insight-band-grid { grid-template-columns: 1fr; }
.insight-band-narrative { display: flex; flex-direction: column; gap: 10px; }
.insight-band-module { display: flex; flex-direction: column; gap: 12px; }

.insight-module { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.insight-module-title { font-size: 14px; font-weight: 700; }
.insight-module-sub { font-size: 11.5px; color: var(--faint); margin-top: 1px; }
.module-unavailable {
  border: 1px dashed var(--hairline);
  border-radius: var(--radius-md);
  padding: 22px;
  text-align: center;
  font-size: 12.5px;
  color: var(--faint);
}
.module-stat { display: flex; align-items: baseline; gap: 10px; }
.module-stat-value { font-size: 24px; font-weight: 800; }
.module-stat-label { font-size: 12px; color: var(--muted); }
.module-link { font-size: 13px; font-weight: 600; }

.verdict-rollup { display: flex; gap: 14px; flex-wrap: wrap; }
.verdict-rollup-item { display: flex; align-items: center; gap: 6px; }
.verdict-rollup-count { font-weight: 800; font-size: 16px; color: var(--ink); }

.miniad-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  font-size: 12.5px;
  padding: 6px 0;
  border-bottom: 1px solid var(--hairline);
}
.miniad-row:last-of-type { border-bottom: 0; }
.miniad-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.miniad-chips { display: flex; gap: 4px; }
.miniad-stats { color: var(--muted); white-space: nowrap; }

.halo-spark { width: 100%; height: auto; display: block; }

.insight-evidence-toggle { align-self: flex-start; margin-top: 10px; }
.insight-evidence { margin: 10px 0 0; }
.insight-evidence-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 12px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--hairline);
}
.insight-evidence-row dt { color: var(--muted); font-size: 11.5px; }
.insight-evidence-row dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }

@media (max-width: 980px) {
  .insight-band-grid { grid-template-columns: 1fr; }
}

/* Steady verdict (portal-only): above breakeven, holding — teal-tinted. */
.verdict-chip--steady { background: #E7F1EF; color: #337A70; }
.ads-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
