/* BI cockpit v1: app styles on top of the shared SDI Lab kit (ui.css, which owns hints, toasts,
   tap targets and page transitions). Only what the cockpit itself needs lives here. */

/* ---- Page morphs: tile <-> metric head (<= 400 ms), off with reduced motion ---- */
::view-transition-group(*) { animation-duration: 320ms; animation-timing-function: cubic-bezier(0.2, 0, 0, 1); }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 180ms; }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* ---- Helpers ---- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 20; background: var(--surface); padding: 6px 10px; border-radius: var(--radius-small); }
.skip-link:focus { left: 8px; }
.topbar .app-home { color: var(--text); text-decoration: none; }
main > section, main > details, main > .tabs { margin-top: 16px; }
p .hint, h1 .hint { margin-left: 4px; }
details > summary { cursor: pointer; font-weight: 600; }
details[open] > summary { margin-bottom: 10px; }
.btn[aria-disabled="true"] { opacity: 0.45; cursor: default; }
.footer a[aria-current="page"] { color: var(--text); text-decoration: none; }
.section-head { margin-bottom: 8px; }
.section-head h2 { margin: 0; }

/* ---- Month picker ---- */
.month-picker { display: flex; gap: 8px; align-items: center; }
.month-picker label { font-size: 0.86rem; color: var(--muted); }
.month-picker select { width: auto; min-width: 190px; }

/* ---- Overview tiles ---- */
.kpi-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr)); }
.kpi-grid > * { min-width: 0; }
.tile { display: flex; flex-direction: column; gap: 2px; }
.tile-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tile .kpi-value { margin: 6px 0 2px; }
.tile-foot { margin-top: 6px; }
.chart-spark { width: 100%; height: 44px; margin-top: 6px; }
.delta { font-weight: 600; color: var(--text); }
.referee-cta { margin: 20px 0 6px; font-size: 1.02rem; }

/* ---- Metric page ---- */
.metric-head { flex: 1 1 420px; }
.metric-head h1 { margin-bottom: 2px; }
.metric-head .kpi-value { font-size: 2.2rem; font-weight: 700; line-height: 1.1; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
.metric-head .kpi-meta { margin: 0; }
.as-table { margin-top: 10px; }

/* ---- "How it's calculated" (analyst detail behind a click) ---- */
.calc-panel pre { max-height: 360px; }
.sql-head { display: flex; align-items: center; gap: 8px; margin: 14px 0 6px; }
.sql-head h3 { margin: 0; }
.sql-head .copy-btn { margin-left: auto; }

/* ---- Rows ---- */
.rows-tools { margin: 0 0 10px; }
.rows-tools input[type="search"] { flex: 1 1 220px; max-width: 320px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 14px 0; }
.table-rows td { white-space: nowrap; }
th.basis, td.basis { background: var(--accent-weak); }
.table th.basis { color: var(--accent); }
.sort-link { color: inherit; text-decoration: none; display: inline-block; }
.sort-link:hover { text-decoration: underline; }
.table-compact th, .table-compact td { padding: 5px 8px; font-size: 0.84rem; white-space: nowrap; }
.csv-link { font-size: 0.9rem; }

/* ---- Referee ---- */
.headline .versus { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: center; }
.headline .vs { color: var(--muted); font-weight: 600; }
.headline .kpi-label { color: var(--muted); font-size: 0.9rem; }
.headline .kpi-value { font-size: 2rem; font-weight: 700; line-height: 1.1; margin: 4px 0; font-variant-numeric: tabular-nums; }
.headline .kpi-meta { color: var(--muted); font-size: 0.86rem; }
.gap-line { margin: 14px 0 0; font-weight: 600; }

.step-group { margin: 16px 0 4px; color: var(--muted); font-size: 0.86rem; font-weight: 600; }
.bridge-steps { list-style: none; margin: 0; padding: 0; }
.bridge-steps .step { padding: 10px 0; }
.bridge-steps .step + .step { border-top: 1px solid var(--border); }
.step-line { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.step-amt { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.step-minus .step-amt { color: var(--muted); }
.step-plus .step-amt { color: var(--accent); }
/* The inline bar: where the step sits between the two totals (same scale for every step). */
.step-track { height: 8px; margin: 6px 0 2px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.step-bar { display: block; height: 100%; min-width: 3px; border-radius: 4px; }
.step-minus .step-bar { background: var(--muted); opacity: 0.5; }
.step-plus .step-bar { background: var(--accent); opacity: 0.55; }
.samples { margin-top: 4px; }
.samples > summary { font-weight: 500; font-size: 0.86rem; color: var(--accent); }
.samples .table-wrap { margin-top: 6px; }
.tab-short { display: none; }

/* ---- Definitions / About ---- */
.catalogue tr:target td { background: var(--accent-weak); }
.catalogue td:first-child { width: 38%; }
.analysts .table-wrap { margin: 10px 0; }
.yaml { max-height: 520px; }
.flow { padding-left: 1.3em; }
.flow li + li { margin-top: 8px; }

@media (max-width: 640px) {
  .month-picker { width: 100%; }
  .month-picker select { flex: 1; min-width: 0; }
  .headline .versus { grid-template-columns: 1fr; gap: 10px; }
  .headline .vs { display: none; }
  .metric-head { flex-basis: 100%; }
  /* Tabs stay one row; the referee's pair tabs switch to short labels. */
  .tabs { flex-wrap: nowrap; }
  .tabs a { white-space: nowrap; }
  .pair-tabs .tab-long { display: none; }
  .pair-tabs .tab-short { display: inline; }
  /* Rows on phones: the metric's date, product and status; the rest on wider screens. */
  .phone-hide { display: none; }
}
