/* Shared dashboard pieces: page frame, stat tiles, panels, charts, tables, chips. */
:root {
  /* Chart series, validated for the dark surface (lightness band, colour-blind separation, contrast). */
  --series-1: #b98d1f;
  --series-2: #4a8bd0;
  --series-3: #c75a8f;
  --good: #7fe0a8;
  --bad: #ff9a8a;
  --tile-min: 190px;
  --tiles-reserve: 118px;
  --panel-reserve: 200px;
  --panel-min: 380px;
  --chart-h: 240px;
  --axis-w: 64px;
  --col-max: 28px;
  --bar-h: 10px;
  --bar-label-w: 124px;
  --kpi: clamp(28px, 3.4vw, 40px);
  --page-title: clamp(34px, 5vw, 56px);
  --tip-w: 240px;
  --thumb-w: 52px;
  --tip-shadow: 0 10px 30px var(--shadow);
}

.dash { padding: var(--sp-24) var(--gutter) var(--sp-64); display: grid; gap: var(--sp-24); }
.dash-head { display: flex; flex-wrap: wrap; gap: var(--sp-12) var(--sp-24); align-items: end; justify-content: space-between; }
.dash-head h1 { font: var(--page-title)/.95 var(--display); letter-spacing: .01em; }
.dash-head p { color: var(--muted); }
.demo-note { color: var(--muted); font-size: var(--fs-13); }
.segmented { display: flex; gap: var(--sp-6); flex-wrap: wrap; }

.tiles { display: grid; gap: var(--sp-12); grid-template-columns: repeat(auto-fit, minmax(var(--tile-min), 1fr)); }
.tile-stat { padding: var(--sp-16); border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface); display: grid; gap: var(--sp-4); }
.tile-stat dt { color: var(--muted); font-size: var(--fs-14); }
.tile-stat dd { margin: 0; display: grid; gap: var(--sp-4); }
.tile-stat dd strong { font: 900 var(--kpi)/1.1 var(--body); font-variant-numeric: tabular-nums; }
.tile-stat small { color: var(--muted); font-size: var(--fs-13); }
/* Figures arrive after the catalog loads: hold their space so the page does not jump. */
.tiles:empty { min-height: var(--tiles-reserve); }
.panel > div:empty, .panel > ul:empty { min-height: var(--panel-reserve); }
.dash-head p:empty { min-height: 1.5em; }
/* Direction is carried by the arrow and the words, not by colour alone. */
.delta { font-weight: 700; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

/* min(100%, …) lets a panel shrink below its preferred width on phones instead of overflowing. */
.panels { display: grid; gap: var(--sp-16); grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--panel-min)), 1fr)); align-items: start; }
.panel { padding: var(--sp-20); border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface); display: grid; gap: var(--sp-14); min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
.panel h2 { font: 700 var(--fs-20)/1.2 var(--body); }
.panel .sub { color: var(--muted); font-size: var(--fs-14); margin-top: calc(var(--sp-10) * -1); }

.legend { list-style: none; display: flex; gap: var(--sp-16); padding: 0; margin: 0; font-size: var(--fs-14); color: var(--text-soft); }
.legend li { display: flex; align-items: center; gap: var(--sp-6); }
.swatch { width: var(--sp-12); height: var(--sp-12); border-radius: var(--sp-2); }
.s1 { background: var(--series-1); }
.s2 { background: var(--series-2); }
.s3 { background: var(--series-3); }

.chart { position: relative; height: var(--chart-h); padding-left: var(--axis-w); }
.chart-grid { position: absolute; inset: 0 0 var(--sp-24) 0; display: flex; flex-direction: column; justify-content: space-between; }
.chart-grid span { border-top: 1px solid var(--hairline); color: var(--muted); font-size: var(--fs-12); line-height: 1; padding-top: var(--sp-2); font-variant-numeric: tabular-nums; }
.columns { position: relative; height: 100%; display: flex; gap: var(--sp-2); align-items: stretch; }
.col { flex: 1; min-width: 0; display: grid; grid-template-rows: 1fr var(--sp-24); justify-items: center; }
.col .stack { align-self: end; width: min(100%, var(--col-max)); display: flex; flex-direction: column; gap: var(--sp-2); }
.seg { display: block; min-height: 1px; }
.seg:first-child { border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.col:hover .stack, .col:focus-visible .stack { filter: brightness(1.25); }
.tick { align-self: end; color: var(--muted); font-size: var(--fs-12); white-space: nowrap; }

.bars { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--sp-10); }
.bars li { display: grid; grid-template-columns: var(--bar-label-w) minmax(0, 1fr) auto; gap: var(--sp-12); align-items: center; font-size: var(--fs-14); }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: var(--bar-h); border-radius: var(--pill); background: var(--surface-2); overflow: hidden; }
.bar-track i { display: block; height: 100%; border-radius: var(--pill); background: var(--series-1); }
.bar-value { color: var(--text-soft); font-variant-numeric: tabular-nums; }

.tip {
  position: fixed; z-index: 40; max-width: var(--tip-w); padding: var(--sp-8) var(--sp-12);
  border: 1px solid var(--line); border-radius: var(--sp-8); background: var(--surface-2);
  font-size: var(--fs-13); white-space: pre-line; pointer-events: none; box-shadow: var(--tip-shadow);
}

.chart-table summary { cursor: pointer; color: var(--muted); font-size: var(--fs-13); min-height: var(--control-sm); display: flex; align-items: center; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-14); font-variant-numeric: tabular-nums; }
th, td { padding: var(--sp-8) var(--sp-10); border-bottom: 1px solid var(--line); text-align: right; }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--muted); font-weight: 700; }
tbody th { font-weight: 400; }
.table-scroll { overflow-x: auto; }

.progress { height: var(--sp-12); border-radius: var(--pill); background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: var(--pill); background: var(--gold); }
.split { display: flex; gap: var(--sp-2); height: var(--sp-16); border-radius: var(--radius-sm); overflow: hidden; }
.split i { display: block; }

.notes { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--sp-10); }
.notes li { padding: var(--sp-10) var(--sp-12); border-left: var(--focus-w) solid var(--gold); background: var(--surface-2); border-radius: 0 var(--sp-8) var(--sp-8) 0; font-size: var(--fs-14); }
.notes strong { display: block; }

.visits { list-style: none; padding: 0; margin: 0; display: grid; }
.visits li { display: grid; grid-template-columns: var(--thumb-w) minmax(0, 1fr) auto; gap: var(--sp-14); align-items: center; padding: var(--sp-10) 0; border-top: 1px solid var(--line); }
.visits .poster { border-radius: var(--sp-6); }
.visits small { display: block; color: var(--muted); }
.visits .score { color: var(--text-soft); font-size: var(--fs-14); text-align: right; }
.chips { display: flex; gap: var(--sp-8); flex-wrap: wrap; }
fieldset.group { border: 0; padding: 0; margin: 0; display: grid; gap: var(--sp-8); min-width: 0; }
fieldset.group legend { padding: 0; font-weight: 700; font-size: var(--fs-14); margin-bottom: var(--sp-8); }

@media (max-width: 720px) { /* ds-allow-hardcode: media queries cannot read custom properties */
  :root { --tiles-reserve: 380px; }
  .bars li { grid-template-columns: minmax(0, 1fr) auto; }
  .bars .bar-track { grid-column: 1 / -1; order: 3; }
}
