/* ═══ The control tower overview (#/v/tower, views/tower; docs/UI_CONTROL_TOWER.md 5.2, in the brand of
   docs/UI_BRAND.md 8.2) ══════════════════════════════════════════════════════════════════════════════════════════════
   Only what no primitive covers: the page head's band with its eyebrow and line of scope, a balanced KPI strip, card
   rows of equal height, the agent's notes, links on chart marks, the scorecard's bar cells, and the phone rules. The
   jump tiles, KPI cells, cards and charts take the brand from the primitives and the kit. Tokens only (light and dark). */

/* the page head on a quiet band, the website's hero light: white running into ice, a soft turquoise light at the right,
   the turquoise-tinted hairline and the teal shadow of a card; the eyebrow sits over the line of scope */
.tw-root .page-h.tw-head,
.app.shell.desk .screen .tw-root .page-h.tw-head.ph-done {
  align-items: center; margin-bottom: 0; padding: 10px 14px 11px; border: 1px solid var(--line); border-radius: var(--r-md);
  background: radial-gradient(60% 190% at 100% 0%, var(--ice-2), transparent 72%), linear-gradient(100deg, var(--surface) 40%, var(--ice-1)), var(--surface);
  box-shadow: var(--e1), var(--highlight);
}
.tw-head .ph-eyebrow { margin-bottom: 4px; }
/* the line of scope stays under the eyebrow (the desk shell otherwise moves it into the title's tooltip), a size up,
   each part's count in bold ink */
.tw-root .page-h.tw-head p.ph-desc,
.app.shell.desk .screen .tw-root .page-h.tw-head.ph-done p.ph-desc.ph-dup { display: block; margin: 0; color: var(--ink-2); font-size: var(--fs-mini); line-height: var(--lh-mini); }
.tw-head .ph-desc .tw-n { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums lining-nums; }
.tw-head .ph-actions { align-items: center; }
.tw-body { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.tw-body > .jump-tiles, .tw-body > .kpis { margin: 0; }
.tw-body .skel-card { min-height: 220px; }

/* jump tiles: the count badge keeps the top-right corner (the title stops short of it), the sub line may take two
   (wrapped "pretty", so a unit never sits alone on the second line: "within 8 / h") */
.tw-jump .jump { align-items: flex-start; }
.tw-jump .jump > svg { margin-top: 1px; }
.tw-jump .jump b { padding-right: 22px; }
.tw-jump .jump i { white-space: normal; text-wrap: pretty; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }

/* KPI cells: one delta line (cut with an ellipsis, the whole cell is a link with its "i" words), the sparkline under
   its right end as in the reference; the reason a number is missing reads as a note and may take two lines */
.tw-kpis .kpi .d { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tw-kpis .kpi .d.tw-d-why { white-space: normal; text-wrap: pretty; }
.tw-kpis .kpi .d .tw-why { color: var(--muted); }
.tw-kpis .kpi .d .money { font-weight: 600; color: var(--ink-2); }
/* a cell with a sparkline keeps a 20 px band for it under the delta line, so the line never runs through the words
   (the cells of a row share the height: about the reference's 91 px) */
.tw-kpis .kpi:has(> .spark) { padding-bottom: 27px; }
/* on a wide screen 9–14 cells split into two even rows (13 as 7 + 6, not 8 + 5 with a hole at the end) */
@media (min-width: 1280px) {
  .tw-kpis:has(> .kpi:nth-child(9):last-child), .tw-kpis:has(> .kpi:nth-child(10):last-child) { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .tw-kpis:has(> .kpi:nth-child(11):last-child), .tw-kpis:has(> .kpi:nth-child(12):last-child) { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .tw-kpis:has(> .kpi:nth-child(13):last-child), .tw-kpis:has(> .kpi:nth-child(14):last-child) { grid-template-columns: repeat(7, minmax(0, 1fr)); }
}
/* 768–1279 (the sidebar open or folded): the base rule's auto-fit left 13 cells as 6 + 6 + 1 or 8 + 5 and 7 jump tiles
   as 6 + 1 or 5 + 2. Here the column count only takes even-split values, chosen from the strip's own width: 13–14
   cells 7 a row where seven 128 px cells fit (944 px), else 5 (5 + 5 + 3); 11–12 cells 6 (808 px) else 4; 7 jump tiles
   all in one row where seven 150 px tiles fit (1,098 px), else 4 + 3; narrower than that, the base rule's 128 / 150 px
   floor. The third term of min() is huge below the breakpoint and negative above it; the half pixel keeps the count
   from rounding down */
@media (min-width: 768px) and (max-width: 1279px) {
  .tw-kpis:has(> .kpi:nth-child(13):last-child), .tw-kpis:has(> .kpi:nth-child(14):last-child) {
    grid-template-columns: repeat(auto-fit, minmax(max(128px, (100% - 48px) / 7 - .5px, min((100% - 32px) / 5 - .5px, (944px - 100%) * 1000)), 1fr));
  }
  .tw-kpis:has(> .kpi:nth-child(11):last-child), .tw-kpis:has(> .kpi:nth-child(12):last-child) {
    grid-template-columns: repeat(auto-fit, minmax(max(128px, (100% - 40px) / 6 - .5px, min((100% - 24px) / 4 - .5px, (808px - 100%) * 1000)), 1fr));
  }
  .tw-jump:has(> .jump:nth-child(7):last-child) {
    grid-template-columns: repeat(auto-fit, minmax(max(150px, (100% - 48px) / 7 - .5px, min((100% - 24px) / 4 - .5px, (1098px - 100%) * 1000)), 1fr));
  }
}

/* the chart grid: cards in a row share a height, charts sit centred in theirs */
.tw-grid { align-items: stretch; }
.tw-card .card-b { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.tw-card .card-cap { margin-top: auto; padding-top: 8px; }
/* a chart with nothing to draw (a new company sees these first): the brand's quiet empty box, the ice wash and the
   turquoise dashed edge of .empty with the short turquoise rule over its sentence, filling the chart's room */
.tw-card .card-b > .ck-empty {
  flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 96px; padding: 16px 14px;
  border: 1px dashed var(--accent-line); border-radius: var(--r-md); background: linear-gradient(180deg, var(--ice-1), var(--surface) 75%), var(--surface);
  color: var(--ink-2); line-height: var(--lh-small); text-wrap: balance;
}
.tw-card .card-b > .ck-empty::before { content: ""; width: 24px; height: 2px; border-radius: 2px; background: var(--rule); }
.tw-card .card-h .actions .btn.xs { text-decoration: none; }
/* the fleet donut keeps its legend beside it while the card is wide enough for both */
.tw-fleet .ck-pie { flex-wrap: wrap; }
.tw-fleet .ck-pie > svg { width: 200px; flex: none; }
.tw-fleet .ck-legend { flex: 1 1 150px; max-width: 220px; }
/* the ageing matrix stays near its drawn size (about 1.1 ×) so its row matches the radar and the beeswarm */
.tw-ageing .card-b > .ck-x { width: 100%; max-width: 310px; margin: 0 auto; }
.tw-daily-chart { min-width: 0; }
/* the radar's side labels ("Volume", "POD in") sit past its drawn square: room for them inside the narrow card */
.tw-radar .card-b > .ck-fig { padding: 0 22px; }

/* chart marks that open their screen */
.tw-root .tw-link { cursor: pointer; }
.tw-root .ck .tw-link:focus-visible { outline: none; }
.tw-root .ck .tw-link:focus-visible .ck-dot, .tw-root .ck .tw-link:focus-visible .ck-cell { stroke: var(--accent); stroke-width: 2; }
.tw-root .ck .tw-link:hover .ck-cell { stroke: var(--accent); }
/* a lane row: its whole band answers the pointer and shows the keyboard focus (the dot's ring alone is too small to see) */
.tw-root .ck .tw-link:hover .ck-hit { fill: var(--surface-2); }
.tw-root .ck .tw-link:focus-visible .ck-hit { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5px; }
.tw-fleet .ck-legend li.tw-link { border-radius: var(--r-xs); padding: 1px 3px; margin: 0 -3px; }
.tw-fleet .ck-legend li.tw-link:hover, .tw-fleet .ck-legend li.tw-link:focus-visible { background: var(--surface-2); outline: none; box-shadow: var(--focus-ring); }

/* what the agent noticed: agent colours (the violet beside the human teal), one box per finding; its rows' red and
   amber edges stay status */
.tw-ai .card-h::before { background: linear-gradient(var(--ai), var(--ai-text)); }
.tw-ai .card-h .sub { color: var(--ai-text); }
.tw-notes { display: flex; flex-direction: column; gap: 6px; }
.tw-note { display: flex; flex-direction: column; gap: 2px; padding: 7px 9px; border: 1px solid var(--ai-line); border-left-width: 3px; border-radius: var(--r-sm); background: var(--ai-soft); color: var(--ink); text-decoration: none; font-size: var(--fs-small); line-height: var(--lh-small); }
.tw-note.info { border-left-color: var(--ai); }
.tw-note.crit { border-left-color: var(--crit); }
.tw-note.warn { border-left-color: var(--warn); }
a.tw-note:hover { border-color: var(--ai); }
a.tw-note:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.tw-note-h { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--ai-text); }
.tw-note-h svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; flex: none; }
.tw-note-h b { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tw-note-v { margin-left: auto; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tw-note-t { color: var(--ink-2); overflow-wrap: anywhere; }
/* nothing noticed: the brand's empty state in the agent's colours */
.tw-ai .empty.tw-empty { background: linear-gradient(180deg, var(--ai-soft), var(--surface) 80%), var(--surface); border-color: var(--ai-line); }
.tw-ai .empty.tw-empty .empty-h { color: var(--ai-text); }

/* the scorecard: the table beside its side panel; bar cells hold a pill (good or bad) and a thin teal bar (how much) */
.tw-score .card-h { flex-wrap: wrap; row-gap: 6px; }
.tw-score .with-panel { align-items: start; }
.tw-score-tbl { max-height: 380px; }
.tw-score-tbl tr[data-row] { cursor: pointer; }
.tw-score-tbl tr[data-row]:focus-visible { outline: none; }
.tw-score-tbl tr[data-row]:focus-visible td { box-shadow: inset 0 -2px 0 var(--accent); }
.tw-score-tbl td.tw-barcell { min-width: 132px; }
.tw-score-tbl tr.sel td .sub, .tw-score-tbl tr.sel td .muted { color: var(--ink-2); } /* muted words read on the selected row's tint (dark) */
.tw-score-tbl td.tw-barcell .pill { min-width: 52px; justify-content: center; }
.tw-score-tbl td.tw-barcell .bar { display: inline-block; width: 64px; min-width: 0; margin-left: 8px; vertical-align: middle; }

/* phones: one column, wide charts scroll inside their card, the page never scrolls sideways */
/* between a phone and a wide screen the grid's own rule makes spans 4–11 full width and leaves the radar alone at a
   third: pair the two radial charts, and the radar with the beeswarm */
@media (min-width: 768px) and (max-width: 1100px) {
  .tw-root .tw-grid > .tw-sun, .tw-root .tw-grid > .tw-fleet { grid-column: span 6; }
  .tw-root .tw-grid > .tw-radar { grid-column: span 5; }
  .tw-root .tw-grid > .tw-margins { grid-column: span 7; }
}

@media (max-width: 767px) {
  .tw-root .tw-grid > .card { grid-column: 1 / -1; }
  .tw-root .page-h.tw-head, .app.shell.desk .screen .tw-root .page-h.tw-head.ph-done { align-items: flex-start; padding: 9px 12px 10px; }
  /* the buttons under the line of scope start at its left edge (the desk's own rule for a head's actions is flex-end) */
  .tw-head .ph-actions, .app.shell.desk .screen .tw-root .page-h.tw-head.ph-done .ph-actions { width: 100%; justify-content: flex-start; }
  .tw-kpis .kpi .spark { position: static; margin-top: 4px; }
  .tw-kpis .kpi:has(> .spark) { padding-bottom: 8px; } /* the sparkline flows under the words here: no band kept for it */
  .tw-ageing .ck-x .ck-heatmap { min-width: 300px; }
  .tw-score .card-h .actions { margin-left: 0; width: 100%; }
  .tw-score .sp-h .btn.xs { min-width: 36px; min-height: 36px; } /* the panel's close: a phone's small-button size */
  /* the fleet legend's rows open the fleet board: a finger's target, not 21 px rows touching each other */
  .tw-fleet .ck-legend li.tw-link { min-height: 32px; }
}
/* a phone held upright shows the tiles and the KPI cells two a row: an odd last one takes the whole row instead of
   leaving a hole beside it (7 jump tiles, 13 cells) */
@media (max-width: 431px) {
  .tw-jump > .jump:last-child:nth-child(odd), .tw-kpis > .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
}
