/*
 * Appreciation dashboard.
 *
 * Colour roles come from a validated categorical palette — two series slots
 * (blue, orange) plus chrome and status. Both modes are selected rather than
 * flipped: the dark column is the same hues re-stepped for the dark surface.
 * Every pair clears the CVD, normal-vision and contrast gates in both modes.
 * If you change a series hex, re-run the palette validator before shipping it.
 */

:root {
  color-scheme: light;

  --plane: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);

  --series-1: #2a78d6;
  --series-2: #eb6834;

  /* Meter track: a lighter step of the fill's own ramp, so state reads across
     the whole bar rather than only where it happens to be filled. */
  --meter-track: #cde2fb;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --success-text: #006300;

  --radius: 10px;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-2: #d95926;
    --meter-track: #184f95;
    --success-text: #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface-1: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;
  --series-2: #d95926;
  --meter-track: #184f95;
  --success-text: #0ca30c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 1.25rem 4rem;
  background: var(--plane);
  color: var(--text-primary);
  font: 15px/1.55 var(--sans);
}

.wrap { max-width: 72rem; margin: 0 auto; }

/* ── header & filters ─────────────────────────────────────────────── */

header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  padding: 2rem 0 1rem;
}
header h1 { margin: 0; font-size: 1.35rem; font-weight: 600; }
header .site { color: var(--text-secondary); font-size: 0.95rem; }
header .spacer { flex: 1; }

/* One filter row, above everything it scopes — never per-card. */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 1.25rem;
}
.filters .label { color: var(--text-muted); font-size: 0.85rem; margin-right: 0.25rem; }
.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-1);
  margin-right: 0.5rem;
}
.segmented button {
  border: 0;
  background: transparent;
  border-radius: 7px;
  padding: 0.28rem 0.75rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
}
.segmented button[aria-pressed="true"] {
  background: var(--text-primary);
  color: var(--plane);
  font-weight: 600;
}
[data-section][hidden] { display: none; }
.info-note { font-size: 0.8rem; color: var(--text-muted); }
.info-note summary { cursor: pointer; list-style: none; text-decoration: underline; text-underline-offset: 2px; }
.info-note summary::-webkit-details-marker { display: none; }
.info-note .note { margin: 0.5rem 0 0.75rem; color: var(--text-secondary); font-size: 0.84rem; max-width: 60ch; }

button, select, input, textarea {
  font: inherit;
  color: inherit;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
}
button { cursor: pointer; }
button:hover { background: var(--plane); }
button[aria-pressed="true"] {
  border-color: var(--series-1);
  color: var(--series-1);
  font-weight: 600;
}
button.primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.08); }
button.danger { border-color: var(--status-critical); color: var(--status-critical); }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

/* ── cards ────────────────────────────────────────────────────────── */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.card > h2 {
  margin: 0 0 0.15rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.card > .note {
  margin: 0 0 1rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  max-width: 58ch;
}
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr)); gap: 1.25rem; }

/* Refetch keeps the frame: hold the previous render, no skeleton flash. */
.loading { opacity: 0.45; transition: opacity 120ms ease; }

/* ── hero & stat tiles ────────────────────────────────────────────── */

.hero { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1.5rem 2.5rem; }
.hero .figure {
  /* Proportional figures, not tabular: at display size tabular digits read loose. */
  font-size: 3.25rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
}
.hero .caption { color: var(--text-secondary); font-size: 0.9rem; max-width: 34ch; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 1.25rem; }
.kpi .k-label { color: var(--text-muted); font-size: 0.8rem; }
.kpi .k-value { font-size: 1.5rem; font-weight: 600; line-height: 1.25; }
.kpi .k-sub { color: var(--text-secondary); font-size: 0.8rem; }
/* Marks a figure Analytics Engine sampled, so it reads as an estimate rather
   than sitting in the same typeface as the exact counts beside it. */
.kpi .k-value .est { color: var(--text-muted); font-weight: 400; }

/* ── arm comparison ───────────────────────────────────────────────── */

.arms { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.arm { border: 1px solid var(--border); border-radius: 8px; padding: 0.85rem 1rem; }
.arm h3 { margin: 0 0 0.5rem; font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); }
.arm dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 0.3rem 1rem; }
.arm dt { color: var(--text-secondary); font-size: 0.85rem; }
.arm dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.arm .structural { color: var(--text-muted); font-style: italic; }

.meter { margin-top: 1rem; }
.meter .track {
  height: 10px;
  border-radius: 999px;
  background: var(--meter-track);
  overflow: hidden;
}
.meter .fill { height: 100%; border-radius: 999px; background: var(--series-1); }
.meter .fill.warn { background: var(--status-critical); }
.meter .legend {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.4rem;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

/* Status never rides on colour alone — icon plus label, always. */
.status { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.status.good .dot { background: var(--status-good); }
.status.warn .dot { background: var(--status-critical); }
.status.idle .dot { background: var(--text-muted); }

/* ── charts ───────────────────────────────────────────────────────── */

.chart-head { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.chart-head .spacer { flex: 1; }
.chart-head button { font-size: 0.8rem; padding: 0.15rem 0.55rem; }

.legend-row { display: flex; flex-wrap: wrap; gap: 0.15rem 1rem; margin: 0.25rem 0 0.5rem; }
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; color: var(--text-secondary); }
/* Lines get a line key, areas/bars a swatch — the legend mirrors the mark. */
.legend-item .key { width: 14px; height: 2px; border-radius: 1px; flex: none; }

/* The container includes the x-axis band, so no nested scrollbar appears. */
.plot { width: 100%; height: 232px; display: block; overflow: visible; touch-action: pan-y; }
.plot .gridline { stroke: var(--grid); stroke-width: 1; }
.plot .axis { stroke: var(--axis); stroke-width: 1; }
.plot .tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.plot .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.plot .end-dot { stroke: var(--surface-1); stroke-width: 2; }
.plot .end-label { fill: var(--text-secondary); font-size: 11px; }
.plot .crosshair { stroke: var(--axis); stroke-width: 1; }
.plot .hit { fill: transparent; }

.tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font-size: 0.82rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  min-width: 10rem;
}
.tooltip .t-when { color: var(--text-muted); margin-bottom: 0.3rem; }
.tooltip .t-row { display: flex; align-items: center; gap: 0.45rem; }
.tooltip .t-row .key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
/* Values lead, labels follow: here the reader has the series and wants the number. */
.tooltip .t-row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip .t-row .n { color: var(--text-secondary); }

.plot-wrap { position: relative; }

/* ── tables ───────────────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.4rem 0.6rem 0.4rem 0; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 500; font-size: 0.8rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.page { max-width: 26rem; overflow-wrap: anywhere; }
tbody tr:last-child td { border-bottom: 0; }

.bar-cell { display: flex; align-items: center; gap: 0.6rem; justify-content: flex-end; }
.bar-cell .v { font-variant-numeric: tabular-nums; }
/* One track per row so the column reads as a single comparison. */
.bar-cell .bar-track { width: 84px; flex: none; }
.bar-cell .bar {
  height: 8px;
  /* Square at the baseline, 4px rounded at the data end. */
  border-radius: 0 4px 4px 0;
  background: var(--series-1);
}
/* Below the evidence floor the mark is present but visibly discounted. */
.bar-cell .bar-track.provisional .bar { opacity: 0.3; }
th:last-child, td:last-child { padding-right: 0; }
.badge {
  font-size: 0.72rem;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 0.45rem;
  white-space: nowrap;
}
.badge.warn {
  border-color: var(--status-warning);
  color: var(--text-primary);
}

.table-view[hidden] { display: none; }
.scroll { overflow-x: auto; }
/* Free-text detail column: keep it readable and scroll at narrow widths. */
.integrity-table table { min-width: 36rem; }

/* ── config form & messages ───────────────────────────────────────── */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr)); gap: 0.9rem 1.25rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label { font-size: 0.82rem; color: var(--text-secondary); }
.field .hint { font-size: 0.76rem; color: var(--text-muted); }
.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field select,
.field textarea { width: 100%; }
.checks { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.checks label { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.88rem; }

.msg { border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.85rem; margin-top: 0.9rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.85rem; }
.msg .alert-action { font-size: 0.8rem; padding: 0.2rem 0.55rem; margin-left: auto; }
.msg.ok {
  border: 1px solid var(--status-good);
  border-left: 3px solid var(--status-good);
  background: color-mix(in srgb, var(--status-good) 8%, transparent);
  color: var(--success-text);
}
.msg.err {
  border: 1px solid var(--status-critical);
  border-left: 3px solid var(--status-critical);
  background: color-mix(in srgb, var(--status-critical) 10%, transparent);
}
.msg.warn {
  border: 1px solid var(--status-warning);
  border-left: 3px solid var(--status-warning);
  background: color-mix(in srgb, var(--status-warning) 10%, transparent);
}
.msg ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }

.empty { color: var(--text-secondary); font-size: 0.88rem; padding: 0.75rem 0; }

/* ── setup & demo ─────────────────────────────────────────────────── */

.setup { max-width: 34rem; }
.setup .field { margin-bottom: 0.85rem; }
.setup-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; align-items: center; }
.demo-badge {
  border-color: var(--series-1);
  color: var(--series-1);
  font-weight: 600;
  padding: 0.1rem 0.55rem;
}

/* ── sponsor media kit & creatives ────────────────────────────────── */

.kit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr));
  gap: 0.9rem 1.25rem;
  margin-bottom: 1rem;
}
.kit-stat {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
}
.kit-stat .k-label { font-size: 0.78rem; color: var(--text-muted); }
.kit-stat .k-value { font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
.kit-stat .k-sub { font-size: 0.78rem; color: var(--text-secondary); }
.kit-top-title { font-size: 0.82rem; font-weight: 600; color: var(--text-secondary); margin: 0.5rem 0 0.4rem; }

.creative-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(18rem, 100%), 1fr));
  gap: 1rem;
}
.creative-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-width: 0;
}
.creative-card.paused { opacity: 0.65; }
.creative-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 0.75rem;
}
.creative-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}
.creative-frame {
  width: 100%;
  max-width: 420px;
  height: 140px;
  border: 0;
  display: block;
  border-radius: 10px;
  overflow: hidden;
}

.composer { margin-top: 1.15rem; border-top: 1px solid var(--border); padding-top: 0.9rem; }
.composer summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.composer-form { margin-top: 0.9rem; }
.composer-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; margin-top: 1rem; }
.creative-btns { display: inline-flex; gap: 0.4rem; }

.posture-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(13rem, 100%), 1fr));
  gap: 0.9rem 1.25rem;
}
.posture-tile {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.posture-tile.primary {
  border-color: var(--series-1);
}
.posture-tile .p-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.85rem;
}
.posture-tile .p-rate { font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.posture-tile .p-meta { font-size: 0.8rem; color: var(--text-secondary); }
.posture-tile .p-note { font-size: 0.75rem; color: var(--text-muted); }

.rails-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.rails-head button { font-size: 0.8rem; padding: 0.2rem 0.6rem; }
.rails-list { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 0.5rem; }
.rail-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(10.5rem, 100%), 1fr));
  gap: 0.65rem 0.9rem;
  align-items: end;
}
.rail-actions { display: flex; justify-content: flex-end; }
.field input[type="color"] { width: 3.5rem; height: 2.2rem; padding: 0.2rem; cursor: pointer; }

.pres-preview-wrap {
  margin-top: 0.9rem;
  padding: 0.85rem 1rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--plane);
}
.pres-preview-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
}
.pres-surface {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  text-align: center;
  max-width: 28rem;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.pres-title { font-size: 0.92rem; font-weight: 600; color: var(--text-primary); }
.pres-body { font-size: 0.82rem; color: var(--text-secondary); max-width: 40ch; }
.pres-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.6rem; margin-top: 0.25rem; }
.pres-action {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.38rem 0.85rem;
  border-radius: 8px;
  background: var(--text-primary);
  color: var(--plane);
}
.pres-dismiss { font-size: 0.78rem; color: var(--text-muted); text-decoration: underline; text-underline-offset: 2px; }
.pres-surface.minimal {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  max-width: 100%;
  margin: 0;
  padding: 0.75rem 0 0.15rem;
  gap: 0.5rem 0.75rem;
  background: none;
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
}
.pres-surface.minimal .pres-title { display: none; }
.pres-surface.minimal .pres-actions { display: contents; }
.pres-surface.minimal .pres-action { order: 1; border-radius: 999px; padding: 0.3rem 0.8rem; font-size: 0.8rem; flex: none; }
.pres-surface.minimal .pres-body { order: 2; flex: 1 1 11rem; max-width: none; font-size: 0.8rem; }
.pres-surface.minimal .pres-dismiss { order: 3; margin-left: auto; text-decoration: none; font-size: 1rem; line-height: 1; padding: 0.15rem 0.35rem; }

@media print {
  body { background: #fff; color: #000; padding: 0; }
  header, .filters, #alert, .card:not(#media-kit), #media-kit button, #media-kit-msg { display: none !important; }
  #media-kit { border: 0; margin: 0; padding: 0; }
}
code {
  background: color-mix(in srgb, var(--text-primary) 7%, transparent);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.88em;
}

@media (max-width: 640px) {
  .arms { grid-template-columns: 1fr; }
  .hero .figure { font-size: 2.5rem; }
  .creative-frame { height: 156px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ── accounts and proxy check ──────────────────────────────────────── */
.site-picker { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--text-secondary); }
.site-picker select { max-width: 12rem; }
#onboarding form { display: flex; flex-direction: column; gap: 0.9rem; }
.clause-list { list-style: none; margin: 0.75rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.clause-list li { display: flex; gap: 0.5rem; align-items: baseline; font-size: 0.88rem; overflow-wrap: anywhere; }
.clause-list .mark { flex: none; width: 1.2rem; font-weight: 700; }
.clause-list .pass .mark { color: var(--status-good); }
.clause-list .fail .mark { color: var(--status-critical); }
