/* =========================================================================
   insights — CVTA staff dashboard (BRIEF §14 Batch C).
   Owns every .ins-* class. Layout and surfaces come from css/app.css tokens;
   the only thing defined here is the five-step chart palette, which is
   redefined for dark mode so the charts stay legible on a dark surface
   (navy on near-black is unreadable, so the dark ramp is the light one
   lifted toward the blues).
   ========================================================================= */

.ins-figure {
  --ins-1: var(--navy);
  --ins-2: var(--blue);
  --ins-3: var(--slate);
  --ins-4: var(--orange);
  --ins-5: var(--red);
  --ins-axis: var(--muted);
  --ins-grid: var(--line);
  --ins-track: var(--surface-2);
  --ins-band: rgba(70, 123, 184, .12);
  margin: 0;
}

.ins-kpi,
.ins-legend { --ins-1: var(--navy); --ins-2: var(--blue); --ins-3: var(--slate); --ins-4: var(--orange); --ins-5: var(--red); }

@media (prefers-color-scheme: dark) {
  .ins-figure,
  .ins-kpi,
  .ins-legend {
    --ins-1: #7fa8ee;
    --ins-2: #5b9ae0;
    --ins-3: #6fb6c9;
    --ins-4: #ffa165;
    --ins-5: #ff7f7f;
  }
  .ins-figure {
    --ins-grid: var(--line-strong);
    --ins-track: var(--surface-3);
    --ins-band: rgba(127, 168, 238, .14);
  }
}

/* ---------------------------------------------------------------- header */

.ins-head .section-head { margin-bottom: var(--s-2); }

.ins-lede {
  margin: 0 0 var(--s-3);
  font-size: .88rem;
  line-height: 1.5;
  color: var(--ink-2);
}

.ins-head-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}

.ins-meta-pill {
  padding: 3px 10px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}

.ins-tabs { margin-bottom: var(--s-4); }
.ins-ranges { margin-bottom: var(--s-3); }

/* ------------------------------------------------------------------- KPIs */

.ins-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: var(--s-3);
  margin: 0 0 var(--s-4);
}

.card .ins-kpis { margin-bottom: 0; }

.ins-kpi {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--sh-1);
  overflow: hidden;
}

/* A 3px colour rail instead of a tinted card: it reads as a set at a glance
   and never fights the text contrast in either theme. */
.ins-kpi::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--ins-1);
}
.ins-kpi-2::before { background: var(--ins-2); }
.ins-kpi-3::before { background: var(--ins-3); }
.ins-kpi-4::before { background: var(--ins-4); }
.ins-kpi-5::before { background: var(--ins-5); }

.ins-kpi-label {
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

.ins-kpi-value {
  font-size: 1.5rem;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.ins-kpi-delta {
  font-size: .76rem;
  font-weight: 700;
  color: var(--muted);
}
.ins-kpi-delta.is-up { color: var(--success); }
.ins-kpi-delta.is-down { color: var(--danger); }

.ins-kpi-note {
  font-size: .76rem;
  color: var(--muted);
}

/* ----------------------------------------------------------------- charts */

.ins-chart-wrap {
  width: 100%;
  overflow: hidden;
}

/* viewBox + width:100% + height:auto keeps the aspect ratio, so nothing in the
   SVG (labels especially) is ever stretched. */
.ins-chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.ins-grid {
  stroke: var(--ins-grid);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.ins-axis {
  fill: var(--ins-axis);
  font-size: 11px;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}

.ins-band { fill: var(--ins-band); }

.ins-area { opacity: .16; stroke: none; }

.ins-line {
  fill: none;
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.ins-trend {
  fill: none;
  stroke: var(--ins-axis);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
  opacity: .85;
  vector-effect: non-scaling-stroke;
}

.ins-dot { stroke: var(--surface); stroke-width: 2; }

.ins-track { fill: var(--ins-track); }
/* capacity behind the real bar: same hue, heavily faded */
.ins-ghost { opacity: .28; }

.ins-bar-label {
  fill: var(--ink);
  font-size: 12.5px;
  font-family: var(--font);
  font-weight: 600;
}

.ins-bar-value {
  fill: var(--ink-2);
  font-size: 12.5px;
  font-family: var(--font);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* palette hooks — every fill/stroke in a chart comes from one of these */
.ins-fill-1 { fill: var(--ins-1); }
.ins-fill-2 { fill: var(--ins-2); }
.ins-fill-3 { fill: var(--ins-3); }
.ins-fill-4 { fill: var(--ins-4); }
.ins-fill-5 { fill: var(--ins-5); }
.ins-stroke-1 { stroke: var(--ins-1); }
.ins-stroke-2 { stroke: var(--ins-2); }
.ins-stroke-3 { stroke: var(--ins-3); }
.ins-stroke-4 { stroke: var(--ins-4); }
.ins-stroke-5 { stroke: var(--ins-5); }

/* ------------------------------------------------------------------ donut */

.ins-donut {
  max-width: 260px;
  margin: 0 auto;
}

.ins-donut-track { stroke: var(--ins-track); }
.ins-donut-seg { stroke-linecap: butt; }

.ins-donut-total {
  fill: var(--ink);
  font-family: var(--font);
  font-size: 26px;
  font-weight: 800;
}

.ins-donut-sub {
  fill: var(--muted);
  font-family: var(--font);
  font-size: 12px;
}

/* ----------------------------------------------------------------- legend */

.ins-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-4);
  margin: var(--s-2) 0 0;
  font-size: .8rem;
  color: var(--ink-2);
}

.ins-legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--s-2);
}

.ins-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.ins-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: 0 0 auto;
  background: var(--ins-1);
}
.ins-bg-1 { background: var(--ins-1); }
.ins-bg-2 { background: var(--ins-2); }
.ins-bg-3 { background: var(--ins-3); }
.ins-bg-4 { background: var(--ins-4); }
.ins-bg-5 { background: var(--ins-5); }

/* ---------------------------------------------------------------- caption */

.ins-caption {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--s-2);
}

.ins-caption-text {
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-2);
}

.ins-caption-note {
  font-size: .76rem;
  color: var(--muted);
}

/* ------------------------------------------------------------ data tables */

.ins-data { margin-top: var(--s-2); }

.ins-data > summary {
  cursor: pointer;
  padding: 6px 0;
  font-size: .8rem;
  font-weight: 600;
  color: var(--blue);
  list-style: none;
}
.ins-data > summary::-webkit-details-marker { display: none; }
.ins-data > summary::before { content: '▸ '; }
.ins-data[open] > summary::before { content: '▾ '; }
.ins-data > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-xs); }

.ins-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}

.ins-table th,
.ins-table td {
  padding: 7px var(--s-2);
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.ins-table thead th {
  color: var(--muted);
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.ins-table th[scope='row'] {
  text-align: left;
  font-weight: 600;
  color: var(--ink);
  white-space: normal;
  min-width: 10ch;
}

.ins-table tbody tr:last-child th,
.ins-table tbody tr:last-child td { border-bottom: 0; }

.ins-table-card .card-title { margin-bottom: var(--s-3); }

/* A wide table on a 390px phone scrolls inside its own box, never the page. */
.ins-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.ins-table-full { min-width: 480px; }

.ins-foot {
  margin: var(--s-3) 0 0;
  font-size: .76rem;
  line-height: 1.5;
  color: var(--muted);
}

/* ------------------------------------------------------------ people/events */

.ins-people .ins-person { cursor: pointer; }
.ins-people .ins-person:hover { background: var(--surface-2); }
.ins-people .ins-person:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
  border-radius: var(--r-sm);
}

.ins-event {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) auto;
  gap: var(--s-2);
  align-items: baseline;
}

.ins-event-name {
  font-weight: 600;
  font-size: .88rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ins-event-screen {
  font-size: .8rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ins-event-time {
  font-size: .76rem;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}

.ins-live-card { opacity: .96; }

/* ------------------------------------------------------------- narrow phones */

/* An SVG's text scales with its viewBox, so on a phone a 680-unit-wide chart is
   drawn at roughly 0.55x and 12.5px labels arrive as 7px. The sizes below are in
   user units, so bumping them here is what keeps chart text readable once the
   chart has been scaled down. */
@media (max-width: 760px) {
  .ins-bar-label,
  .ins-bar-value { font-size: 19px; }
  .ins-axis { font-size: 17px; }
}

@media (max-width: 380px) {
  .ins-kpis { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
  .ins-kpi-value { font-size: 1.32rem; }
  .ins-event { grid-template-columns: minmax(0, 1fr) auto; }
  .ins-event-screen { display: none; }
}

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