/* ==========================================================================
   upscale-data.css — premium polish pass for the DATA rooms: Metrics,
   Energy, Audit, Safety test, Governance, Geometry, Media.

   Loaded last so it can refine (never replace) app.css/kits.css/next.css.
   Every colour here is one of the shared tokens from css/kits.css /
   css/app.css (--accent, --accent-2, --kit-accent-grad, --glow-rgb, --bg,
   --panel, --border, --text, --text-muted) — nothing national or
   hard-coded. No numbers are invented anywhere below; this file only
   changes layout, motion and colour, never content.
   ========================================================================== */

/* -------------------------------------------------------------------- */
/* 1. Consistent room header: title + subtitle left, actions right,      */
/*    stacked neatly on phones (defect #4).                              */
/* -------------------------------------------------------------------- */

.room-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px 14px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(var(--glow-rgb), 0.05), transparent 70%);
}
/* flex-basis is a LENGTH along the flex container's main axis — once
   .room-header switches to flex-direction:column below 560px, a basis of
   "240px" stops being a hint about available width and instead becomes a
   240px-tall minimum, opening a large empty gap above the tiles. Use
   flex-grow/shrink with an auto basis instead; min-width:0 still lets long
   text wrap/ellipsize rather than push the actions off-screen. */
.room-header-text { min-width: 0; flex: 1 1 auto; }
.room-header-text .view-title {
  font-size: 23px;
  line-height: 1.2;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.room-header-text .view-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
  max-width: 62ch;
}
.room-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
@media (max-width: 559.98px) {
  .room-header { flex-direction: column; align-items: stretch; padding: 16px 14px 12px; }
  .room-header-actions { width: 100%; }
  .room-header-actions .print-pdf-btn { width: 100%; justify-content: center; }
}

/* The room wraps no longer carry their own duplicate <h1>; every room now
   gets its title/subtitle from .room-header-text once. Reclaim the top
   padding the old stacked-title layout used to need. */
.metrics-wrap, .energy-wrap, .audit-wrap, .gov-wrap, .geometry-wrap, .media-wrap, .safety-test-wrap {
  padding-top: 16px;
}
.metrics-wrap .view-title, .energy-wrap .view-title, .audit-wrap .view-title,
.gov-wrap .view-title, .geometry-wrap .view-title, .media-wrap .view-title,
.safety-test-wrap .view-title { display: none; }
.geometry-wrap > .view-sub, .safety-test-wrap > .view-sub { display: none; }

/* -------------------------------------------------------------------- */
/* 1B. Metrics room — compact, dense, premium: fits one screen at        */
/*     1280x800 with no scroll, and reads well at 375. Smaller tiles,    */
/*     modest chart heights, a slim verdict bar, no large empty panels.  */
/* -------------------------------------------------------------------- */

.metrics-wrap-compact { padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); }

.tile-grid-compact {
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
@media (min-width: 560px) { .tile-grid-compact { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1024px) { .tile-grid-compact { grid-template-columns: repeat(8, 1fr); } }

.tile-compact {
  padding: 10px 12px;
  gap: 1px;
  border-radius: var(--radius-sm);
}
.tile-compact .tile-label { font-size: 9.5px; letter-spacing: 0.03em; }
.tile-compact .tile-title { font-size: 11px; margin-top: 1px; }
.tile-compact .tile-value { font-size: 21px; margin-top: 1px; text-shadow: none; }
.tile-compact .tile-sub { font-size: 10.5px; }
@media (min-width: 1024px) {
  .tile-compact .tile-value { font-size: 23px; }
}

/* Tokens-by-day and Requests-by-verdict sit side by side on a wide
   screen so the room reads as one dense dashboard, not a long scroll of
   full-width cards; they stack on narrow screens. */
.metrics-chart-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
@media (min-width: 860px) {
  .metrics-chart-row { grid-template-columns: 1.6fr 1fr; align-items: stretch; }
}

.chart-card-compact { padding: 12px 14px 13px; margin-bottom: 0; }
.chart-card-compact .chart-card-head { margin-bottom: 6px; }
.chart-card-compact .chart-card-head h2 { font-size: 12px; }
.chart-svg-compact { max-height: 130px; }
.chart-card-verdict { display: flex; flex-direction: column; justify-content: center; }
.chart-svg-slim { max-height: 40px; }
.chart-legend-compact { margin-top: 6px; gap: 6px 10px; }
.chart-legend-compact .legend-item { font-size: 10.5px; gap: 5px; }
.chart-legend-compact .legend-swatch { width: 8px; height: 8px; }

/* -------------------------------------------------------------------- */
/* 2. Spacing rhythm — 4/8px grid on the tile and chart grids.            */
/* -------------------------------------------------------------------- */

.tile-grid { gap: 12px; margin-bottom: 24px; }
.chart-card { margin-bottom: 20px; padding: 16px 18px 18px; }
.chart-card-head { margin-bottom: 12px; }
.chart-card-head h2 { font-size: 14px; letter-spacing: 0.01em; }
.tile { padding: 16px 18px; gap: 4px; transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease; }
.tile:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.tile-value { font-size: 27px; letter-spacing: -0.01em; }
.tile-sub { line-height: 1.5; }

/* -------------------------------------------------------------------- */
/* 3. Skeleton shimmer while a room's data is loading.                   */
/*    app.js toggles .is-skeleton on the room's <section id="view-*">.   */
/* -------------------------------------------------------------------- */

.is-skeleton .tile-value,
.is-skeleton .energy-headline-value,
.is-skeleton .st-headline-value,
.is-skeleton .chart-svg,
.is-skeleton .ledger-badge,
.is-skeleton .gov-card,
.is-skeleton .media-item {
  position: relative;
  color: transparent !important;
  border-color: var(--border) !important;
  overflow: hidden;
}
.is-skeleton .tile-value::after,
.is-skeleton .energy-headline-value::after,
.is-skeleton .st-headline-value::after,
.is-skeleton .chart-svg::after,
.is-skeleton .ledger-badge::after,
.is-skeleton .gov-card::after,
.is-skeleton .media-item::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    100deg,
    rgba(var(--glow-rgb), 0.05) 20%,
    rgba(var(--glow-rgb), 0.16) 42%,
    rgba(var(--glow-rgb), 0.05) 64%
  );
  background-size: 200% 100%;
  animation: upscale-shimmer 1.3s ease-in-out infinite;
}
.is-skeleton .chart-svg { border-radius: var(--radius-sm); background: var(--bg-sunken); }
@keyframes upscale-shimmer {
  0% { background-position: 140% 0; }
  100% { background-position: -60% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .is-skeleton .tile-value::after,
  .is-skeleton .energy-headline-value::after,
  .is-skeleton .st-headline-value::after,
  .is-skeleton .chart-svg::after,
  .is-skeleton .ledger-badge::after,
  .is-skeleton .gov-card::after,
  .is-skeleton .media-item::after {
    animation: none;
    background-position: 40% 0;
  }
}

/* -------------------------------------------------------------------- */
/* 4. Charts — grid, bars, dots, tooltip (defect #1).                    */
/* -------------------------------------------------------------------- */

.chart-svg { overflow: visible; }
.chart-bar { transition: opacity 0.12s ease, filter 0.12s ease; cursor: pointer; }
.chart-bar:hover, .chart-bar.is-hovered, .chart-bar:focus-visible {
  opacity: 1 !important;
  filter: drop-shadow(0 0 6px rgba(var(--glow-rgb), 0.35));
}
.chart-bar:focus-visible, .chart-dot:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.chart-dot { cursor: pointer; transition: r 0.12s ease, filter 0.12s ease; }
.chart-dot:hover, .chart-dot.is-hovered { filter: drop-shadow(0 0 6px rgba(var(--glow-rgb), 0.45)); }
.chart-grid text { font-family: var(--font-mono); user-select: none; }

.chart-card { position: relative; }
.chart-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 6px 10px;
  font-size: 11px;
  line-height: 1.4;
  white-space: nowrap;
  max-width: 220px;
  white-space: normal;
}
.chart-tooltip-label { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.02em; }
.chart-tooltip-value { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; margin-top: 2px; }
.chart-tooltip-pct { color: var(--text-faint); font-size: 10px; margin-top: 1px; }
.chart-tooltip-swatch { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

.chart-legend { row-gap: 6px; }
.legend-item { padding: 2px 0; }

/* -------------------------------------------------------------------- */
/* 5. Energy room (defect #2): neutral signed net, proper time tile.     */
/* -------------------------------------------------------------------- */

.energy-headline {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(var(--glow-rgb), 0.08);
}
.energy-headline-value.is-neutral { color: var(--accent-strong); }
.energy-headline-value { font-variant-numeric: tabular-nums; }
#energy-time-spent-note { display: block; margin-top: 2px; }
.method-panel { line-height: 1.6; }

/* -------------------------------------------------------------------- */
/* 6. Audit room (defect #3): status badge, verdict chips, table fit,    */
/*    drawer summary.                                                    */
/* -------------------------------------------------------------------- */

.audit-ledger-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}
.ledger-badge { box-shadow: 0 0 0 1px rgba(var(--glow-rgb), 0.35), 0 0 18px rgba(var(--glow-rgb), 0.18); }

.audit-table .verdict-chip,
.audit-card .verdict-chip {
  min-height: 0;
  height: 20px;
  padding: 0 9px;
  font-size: 10.5px;
  cursor: inherit;
}
.audit-col-chip { width: 1%; white-space: nowrap; }
.audit-col-time { width: 1%; white-space: nowrap; }
.audit-col-room { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-col-verdict { width: 1%; white-space: nowrap; }
.audit-col-hash { width: 1%; white-space: nowrap; text-align: right; }
.audit-table-full { table-layout: auto; }
.audit-table tbody tr { cursor: pointer; transition: background 0.1s ease; }
.audit-table tbody tr:hover, .audit-table tbody tr:focus-visible { background: var(--bg-sunken); outline: none; }
.audit-table tbody tr:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }

.audit-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.audit-card-actor { color: var(--text-muted); font-size: 11.5px; margin-top: 2px; }

.audit-drawer-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-sunken);
  font-size: 12px;
}
.audit-drawer-label { display: block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-faint); margin-bottom: 2px; }
@media (max-width: 480px) {
  .audit-drawer-summary { grid-template-columns: 1fr; }
}

/* -------------------------------------------------------------------- */
/* 7. Safety test room: about panel + mini bars.                         */
/* -------------------------------------------------------------------- */

.st-about {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel);
  padding: 16px 18px;
  margin-bottom: 18px;
}
.st-about h2 { font-size: 14.5px; margin: 0 0 8px; }
.st-about p { font-size: 12.5px; color: var(--text-muted); margin: 0 0 10px; line-height: 1.6; }
.st-about-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 12px; }
.st-about-list dt { font-weight: 700; color: var(--text); white-space: nowrap; }
.st-about-list dd { margin: 0; color: var(--text-muted); }

#st-run-meta { display: block; font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }

.st-table { table-layout: auto; }
.st-col-bar { width: 90px; }
.st-mini-bar {
  --pct: 0%;
  position: relative;
  display: block;
  height: 6px;
  border-radius: 999px;
  background: var(--bg-sunken);
  overflow: hidden;
}
.st-mini-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--pct);
  background: var(--kit-accent-grad, linear-gradient(90deg, var(--accent), var(--accent-2)));
  border-radius: inherit;
}
.st-headline-value { font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------------- */
/* 8. Governance — constitution stack cards feel like one system.        */
/* -------------------------------------------------------------------- */

.gov-stack { display: flex; flex-direction: column; gap: 10px; }
.gov-card { transition: border-color 0.15s ease, box-shadow 0.15s ease; }
.gov-card:hover { border-color: var(--border-strong); }
.gov-tier-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11.5px; color: var(--text-muted); }

/* -------------------------------------------------------------------- */
/* 9. Geometry — tabs and detail panel read as one coherent figure.      */
/* -------------------------------------------------------------------- */

.geometry-figure { position: relative; }
.geometry-detail:empty::before {
  content: "Select a shape for detail.";
  color: var(--text-faint);
  font-size: 12px;
}

/* -------------------------------------------------------------------- */
/* 10. Media — tidy item cards.                                          */
/* -------------------------------------------------------------------- */

.media-list { display: flex; flex-direction: column; gap: 14px; }
.media-item { padding: 16px 18px; }
.media-item h3 { margin: 0 0 8px; font-size: 14px; }
.media-item audio, .media-item video { width: 100%; display: block; border-radius: var(--radius-sm); }
.media-item video { max-height: 360px; background: var(--bg-sunken); }
.media-transcript { margin-top: 10px; font-size: 12px; color: var(--text-muted); line-height: 1.6; max-height: 160px; overflow-y: auto; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--bg-sunken); }

/* -------------------------------------------------------------------- */
/* 11. Number count-up respects tabular alignment while animating.       */
/* -------------------------------------------------------------------- */

.tile-value, .st-headline-value, .metric-value, .energy-headline-value {
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------------- */
/* 12. Accessible focus rings everywhere in the data rooms (AA).         */
/* -------------------------------------------------------------------- */

.view-metrics a:focus-visible,
.view-energy a:focus-visible,
.view-audit a:focus-visible, .view-audit button:focus-visible, .view-audit input:focus-visible, .view-audit select:focus-visible,
.view-safety-test a:focus-visible, .view-safety-test button:focus-visible, .view-safety-test select:focus-visible,
.view-governance a:focus-visible, .view-governance button:focus-visible,
.view-geometry button:focus-visible,
.view-media a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* -------------------------------------------------------------------- */
/* 13. Layout correctness at 375 / 768 / 1280.                           */
/* -------------------------------------------------------------------- */

@media (min-width: 768px) {
  .st-about-list { grid-template-columns: 140px 1fr; }
}

@media (min-width: 1024px) {
  .tile-grid { grid-template-columns: repeat(4, 1fr); }
  .audit-drawer { max-width: 720px; }
}

@media (max-width: 374.98px) {
  .room-header-text .view-title { font-size: 21px; }
  .tile-value { font-size: 24px; }
}

/* No page in this file introduces horizontal scroll: every grid and flex
   row wraps, and long monospace cells (hash, short id) get a min width
   instead of forcing the table wider than the viewport. */
.cell-mono { word-break: break-word; }
@media (max-width: 899.98px) {
  .audit-table-full { display: none; }
}
