/* QPS Watchhouse Data — v2 stylesheet
   Palette inspired by qpu.asn.au: deep navy header, white body, blue accents.
   Mobile first; everything stacks below 720px.                                */

:root {
  /* Palette matched to qpu.asn.au — navy headings, royal-blue accents. */
  --navy:        #002147;
  --navy-dark:   #00193a;
  --blue:        #3d5f9b;
  --blue-soft:   #eaf0f8;
  --ink:         #1f2a3a;
  --muted:       #5b6b80;
  --line:        #e2e6ee;
  --bg:          #f5f7fb;
  --card:        #ffffff;
  --safe:        #16a34a;
  --warn:        #f59e0b;
  --danger:      #d92d20;
  --safe-soft:   #e9f6ee;
  --warn-soft:   #fff4e0;
  --danger-soft: #fde7e6;
  --radius:      8px;
  --shadow:      0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 "Plus Jakarta Sans", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { max-width: 100%; height: auto; }

/* ------------------------------------------------------------------ Header */
.site-header {
  background: #fff;
  color: var(--navy);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}
.site-header .inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--navy);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  text-decoration: none;
}
.brand .badge {
  background: var(--navy);
  color: #fff;
  font-weight: 800;
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  padding: 6px 10px;
  border-radius: 4px;
  text-transform: uppercase;
}
.brand-sub { color: var(--muted); font-weight: 500; font-size: 0.92rem; }
.brand-logo { height: 52px; width: auto; display: block; flex: none; }
.site-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  flex-wrap: wrap;
}
.site-nav a {
  color: #d4e2fb;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 500;
}
.site-nav a:hover { background: rgba(255,255,255,0.08); text-decoration: none; color: #fff; }
.site-nav a.active { background: rgba(255,255,255,0.15); color: #fff; }

/* ----------------------------------------------------------------- Layout */
.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.page-head { margin: 0 0 28px; }
.page-head h1 {
  margin: 0 0 6px;
  font-size: clamp(1.6rem, 1rem + 1.6vw, 2.4rem);
  letter-spacing: -0.01em;
  color: var(--navy);
  line-height: 1.15;
}
.page-head p.lede {
  margin: 0;
  font-size: 1.05rem;
  color: var(--muted);
  max-width: 70ch;
}
.updated-at {
  display: inline-block;
  margin-top: 10px;
  padding: 4px 10px;
  background: var(--blue-soft);
  color: var(--navy);
  font-size: 0.82rem;
  border-radius: 999px;
  font-weight: 600;
}

/* ----------------------------------------------------------------- Cards  */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 22px; }

.card h2 {
  margin: 0 0 4px;
  font-size: 1.18rem;
  color: var(--navy);
}
.card .sub {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0 0 18px;
}

/* ---------------------------------------------------------------- KPI row */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin: 0 0 28px;
}
.kpis-tight { margin-top: 22px; }
.kpi .value-sub { font-size: 1.1rem; color: var(--muted); font-weight: 600; }
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi .label {
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.kpi .value {
  font-size: 2.1rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--navy);
  margin-top: 8px;
}
.kpi .hint {
  font-size: 0.86rem;
  color: var(--muted);
  margin-top: 6px;
}
.kpi.red    .value { color: var(--danger); }
.kpi.amber  .value { color: #b87100; }
.kpi.green  .value { color: var(--safe); }
.kpi .bar {
  position: absolute;
  inset: auto 0 0 0;
  height: 4px;
  background: var(--blue);
}
.kpi.red    .bar { background: var(--danger); }
.kpi.amber  .bar { background: var(--warn);   }
.kpi.green  .bar { background: var(--safe);   }

/* ----------------------------------------------------------------- Callout */
.callout {
  border-left: 4px solid var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin: 0 0 28px;
}
.callout h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  color: var(--danger);
  letter-spacing: 0.02em;
}
.callout p { margin: 6px 0; }
.callout a { color: var(--navy); font-weight: 600; }
.callout.info {
  border-left-color: var(--blue);
  background: var(--blue-soft);
}
.callout.info h3 { color: var(--navy); }

/* --------------------------------------------------------- Leaderboard table */
.leaderboard-wrap { overflow-x: auto; }
.pill.mini { font-size: 0.7rem; padding: 1px 7px; margin-left: 6px; vertical-align: middle; }
table.leaderboard {
  width: 100%;
  border-collapse: collapse;
}
table.leaderboard th,
table.leaderboard td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
table.leaderboard th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  background: #fafbfd;
}
table.leaderboard td.num,
table.leaderboard th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.leaderboard tbody tr:hover { background: #fafbfd; }
table.leaderboard .name a { color: var(--ink); font-weight: 600; }
table.leaderboard .name a:hover { color: var(--blue); }
.pct-bar {
  position: relative;
  background: #eef0f5;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  min-width: 80px;
}
.pct-bar > span {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  background: var(--blue);
  transition: width 200ms ease;
}
.pct-bar.red   > span { background: var(--danger); }
.pct-bar.amber > span { background: var(--warn);   }
.pct-bar.green > span { background: var(--safe);   }
.pct-bar.muted > span { background: #cfd5e0;       }

/* -------------------------------------------------------------- Pill / tags */
.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: #eef1f6;
  color: var(--muted);
  white-space: nowrap;
}
.pill.red    { background: var(--danger-soft); color: var(--danger); }
.pill.amber  { background: var(--warn-soft);   color: #b87100;       }
.pill.green  { background: var(--safe-soft);   color: var(--safe);   }
.pill.muted  { background: #eef1f6;            color: var(--muted);  }

/* ------------------------------------------------------------- Buttons */
.btn {
  display: inline-block;
  padding: 9px 16px;
  background: var(--blue);
  color: #fff;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid var(--blue);
  cursor: pointer;
}
.btn:hover { background: #324e80; border-color: #324e80; text-decoration: none; color: #fff; }
.btn.ghost { background: transparent; color: var(--navy); border-color: var(--line); }
.btn.ghost:hover { background: var(--blue-soft); }

/* --------------------------------------------------------- Chart containers */
.chart {
  position: relative;
  width: 100%;
  margin-top: 12px;
}
.chart-tall   { height: 420px; }
.chart-medium { height: 320px; }
.chart-short  { height: 220px; }

/* Heatmap (custom CSS grid implementation) ------------------------------- */
.heatmap-card .heatmap-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  flex-wrap: wrap; margin-bottom: 12px;
}
.heatmap-card h2 { margin: 0; }
.heatmap-card .sub { margin: 4px 0 0; }
.range { display: flex; gap: 6px; flex-wrap: wrap; }
.range-btn {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
  background: #fff;
}
.range-btn:hover { color: var(--navy); border-color: var(--blue); text-decoration: none; }
.range-btn.on { background: var(--navy); color: #fff; border-color: var(--navy); }

.heatmap-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  border-radius: 6px;
}
.heatmap-wrap::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 28px;
  pointer-events: none;
  background: linear-gradient(to left, rgba(255,255,255,0.95), rgba(255,255,255,0));
  border-radius: 0 6px 6px 0;
}
/* Two stacked sticky header tiers. Tier 1 (day/date groups) sticks at the very
   top; tier 2 (AM/PM) sticks immediately beneath it via a calc() offset derived
   from --hm-day-h (+ the 1px grid gap), so the tiers abut without overlap. Both
   height and min-height are pinned on the header tiers so they beat the base
   .cell min-height and the rendered height matches the sticky offset exactly.
   Column 1 (watchhouse names) is a fixed width so it can't get squeezed when
   there are many snapshot columns (Month/All); long names wrap instead. */
.heatmap {
  --hm-gap: 1px;
  --hm-label-w: 160px;  /* fixed width of the watchhouse-name column           */
  --hm-day-h: 26px;     /* height of the day (tier-1) header row               */
  --hm-ampm-h: 20px;    /* height of the AM/PM (tier-2) header row             */
  display: grid;
  /* Size the grid to its content when it overflows, so the sticky first column
     (Watchhouse names) has a full-width containing block and stays pinned across
     the WHOLE horizontal scroll. Without this the grid shrinks to the scroll
     container's width and the sticky column drifts off after ~one screen.
     Still fills the container (columns stretch via 1fr) when content is narrow. */
  min-width: max-content;
  gap: var(--hm-gap);
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 0.65rem;
}
.heatmap .cell {
  background: #fff;
  padding: 3px 1px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  min-height: 28px;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
/* Shared header look (both tiers); each tier sets its own sticky top. */
.heatmap .cell.header {
  background: #f6f8fc;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  flex-direction: column;
  line-height: 1.1;
}
/* Tier 1: day groups (top row), sticky at the very top. */
.heatmap .cell.day-group {
  top: 0;
  z-index: 4;
  height: var(--hm-day-h);
  min-height: var(--hm-day-h);
  padding: 0 4px;
  overflow: hidden;
}
.heatmap .cell.day-group .m { font-size: 0.56rem; color: var(--navy); font-weight: 700; letter-spacing: 0.02em; line-height: 1; }
.heatmap .cell.day-group .d { font-size: 0.74rem; color: var(--navy); font-weight: 800; letter-spacing: 0; text-transform: none; white-space: nowrap; line-height: 1.1; }
/* Tier 2: AM/PM (second row), sticks BELOW the day row. */
.heatmap .cell.ampm {
  top: calc(var(--hm-day-h) + var(--hm-gap));
  z-index: 4;
  height: var(--hm-ampm-h);
  min-height: var(--hm-ampm-h);
  padding: 2px 2px 3px;
}
.heatmap .cell.ampm .t { font-size: 0.6rem; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.heatmap .cell.ampm.pm .t { color: var(--ink); }
/* The two corner cells (column 1): pinned top-left. */
.heatmap .cell.corner-day {
  top: 0;
  left: 0;
  z-index: 7;
  height: var(--hm-day-h);
  min-height: var(--hm-day-h);
  padding: 0;
  background: #f6f8fc;
  box-shadow: 1px 0 0 var(--line), 3px 0 6px -2px rgba(15, 23, 42, 0.10);
}
.heatmap .cell.corner-ampm {
  top: calc(var(--hm-day-h) + var(--hm-gap));
}
/* Day-boundary vertical separators (kept on all three rows). */
.heatmap .cell.day-start { box-shadow: inset 1px 0 0 var(--line); }
/* Sticky left watchhouse label column (data rows). Fixed-width column, so long
   names wrap to a second line instead of overflowing into the data cells. */
.heatmap .cell.row-label {
  background: #f6f8fc;
  font-weight: 700;
  color: var(--ink);
  text-align: left;
  padding: 6px 10px;
  position: sticky;
  left: 0;
  z-index: 3;
  white-space: normal;
  overflow-wrap: anywhere;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  line-height: 1.15;
  font-size: 0.78rem;
  box-shadow: 1px 0 0 var(--line), 3px 0 6px -2px rgba(15, 23, 42, 0.10);
}
/* corner-ampm is ALSO a .row-label; this combined selector (specificity 0,4,0)
   is the authoritative place for its top + z-index, so neither .corner-ampm nor
   the later .row-label rule can clobber it via source order. z-index 6 keeps the
   corner above the AM/PM tier (z 4) on horizontal scroll. */
.heatmap .cell.corner-ampm.row-label {
  top: calc(var(--hm-day-h) + var(--hm-gap));
  z-index: 6;
  flex-direction: row;
  align-items: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-size: 0.66rem;
  padding: 2px 10px;
}
.heatmap .cell.row-label .cap { font-weight: 500; font-size: 0.66rem; color: var(--muted); display:inline-flex; align-items:center; gap:4px; text-transform: none; letter-spacing: 0; }
.heatmap .cell.row-label .cap .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--muted); }
.heatmap .cell.red    { background: var(--danger); color: #fff; font-weight: 700; }
.heatmap .cell.amber  { background: var(--warn);   color: #fff; font-weight: 700; }
.heatmap .cell.green  { background: var(--safe-soft); color: var(--safe); }
.heatmap .cell.muted  { background: #f0f2f6; color: #c0c5cf; }

.legend {
  display: flex; gap: 18px; flex-wrap: wrap;
  margin-top: 14px;
  font-size: 0.82rem; color: var(--muted);
}
.legend .sw {
  display: inline-block; width: 14px; height: 14px; border-radius: 3px;
  vertical-align: middle; margin-right: 6px;
}
.legend .sw.red   { background: var(--danger); }
.legend .sw.amber { background: var(--warn); }
.legend .sw.green { background: var(--safe-soft); border: 1px solid var(--line); }
.legend .sw.muted { background: #f0f2f6; border: 1px solid var(--line); }

/* ----------------------------------------------------------- Drilldown page */
.dd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}
.dd-grid > .span-2 { grid-column: 1 / -1; }
.dd-stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.dd-stat .label { font-size: 0.78rem; text-transform: uppercase; color: var(--muted); letter-spacing: 0.06em; font-weight: 700; }
.dd-stat .value { font-size: 1.8rem; font-weight: 800; color: var(--navy); margin-top: 6px; }

.drilldown-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 28px;
  gap: 12px;
}

/* ----------------------------------------------------------------- Footer */
.site-footer {
  margin-top: 64px;
  padding: 36px 0;
  background: var(--navy-dark);
  color: rgba(255,255,255,0.75);
  font-size: 0.92rem;
}
.site-footer .inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
}
.site-footer a { color: #b8cdf2; }

/* ------------------------------------------------------------- Misc bits  */
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
hr.soft { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
.muted { color: var(--muted); }
.tight { margin: 0; }

.hide-sm { /* default: visible */ }

/* --------------------------------------------------------- View switcher */
.viz-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.viz-head h2 { margin: 0; }
.viz-head .sub { margin: 4px 0 0; max-width: 72ch; }

.view-tabs {
  display: none;                      /* shown only when JS is on (.js) */
  gap: 4px;
  background: #eef1f6;
  padding: 4px;
  border-radius: 999px;
  margin: 0 0 20px;
  flex-wrap: wrap;
}
.js .view-tabs { display: flex; }
.view-tab {
  border: 0;
  background: transparent;
  padding: 8px 18px;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--muted);
  cursor: pointer;
  flex: 1 1 auto;
  white-space: nowrap;
}
.view-tab:hover { color: var(--navy); }
.view-tab.is-active { background: #fff; color: var(--navy); box-shadow: var(--shadow); }

/* Without JS every panel just stacks (a separator keeps them distinct). */
.view-panel + .view-panel { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line); }
.panel-head-text { margin: 0 0 16px; }
.js .view-panel { display: none; }
.js .view-panel.is-active { display: block; }
.js .view-panel + .view-panel { margin-top: 0; padding-top: 0; border-top: 0; }

.heatmap-card .panel-head,
.view-panel .panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.view-panel .panel-head .sub { margin: 0; }

/* --------------------------------------------------------- Ranked bars view */
.ranked { display: flex; flex-direction: column; gap: 10px; }
.ranked-row {
  display: grid;
  grid-template-columns: minmax(120px, 200px) 1fr 52px;
  gap: 12px;
  align-items: center;
}
.ranked-name { font-weight: 600; font-size: 0.9rem; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ranked-name .cap { font-weight: 500; font-size: 0.76rem; color: var(--muted); }
.ranked-track {
  position: relative;
  background: #eef0f5;
  height: 26px;
  border-radius: 6px;
  overflow: hidden;
}
.ranked-fill {
  position: absolute; inset: 0 auto 0 0;
  border-radius: 6px 0 0 6px;
  background: var(--blue);
  transition: width 0.4s ease;
}
.ranked-fill.red   { background: var(--danger); }
.ranked-fill.amber { background: var(--warn);   }
.ranked-fill.green { background: var(--safe);   }
.ranked-fill.muted { background: #cfd5e0;       }
.ranked-track .cap-line {            /* 100% capacity marker (track max = 150%) */
  position: absolute; top: -2px; bottom: -2px; left: 66.667%;
  width: 0; border-left: 2px dashed rgba(15, 23, 42, 0.5);
}
.ranked-val { text-align: right; font-weight: 800; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.ranked-val.red { color: var(--danger); } .ranked-val.amber { color: #b87100; } .ranked-val.green { color: var(--safe); }

/* --------------------------------------------------------- Watchhouse select */
.wh-select {
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  min-width: 260px;
  max-width: 100%;
  font-size: 0.95rem;
  background: #fff;
  color: var(--ink);
}

/* Per-watch-house PDF report controls */
.report-controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.report-controls .wh-select { flex: 1 1 280px; min-width: 0; }
.report-controls .btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ------------------------------------------------------------ Responsive  */
@media (max-width: 1080px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .site-header .inner { gap: 8px; padding: 14px 18px; }
  .site-nav { margin-left: 0; width: 100%; }
  .site-nav a { padding: 6px 10px; font-size: 0.92rem; }
  .container { padding: 22px 14px 40px; }
  .kpi .value { font-size: 1.7rem; }
  .dd-grid { grid-template-columns: 1fr; }
  .card { padding: 16px 14px; }
  .heatmap {
    font-size: 0.58rem;
    --hm-label-w: 116px;
    --hm-day-h: 22px;
    --hm-ampm-h: 16px;
  }
  .heatmap .cell { padding: 3px 1px; min-height: 22px; }
  .heatmap .cell.row-label { font-size: 0.72rem; padding: 4px 8px; }
  .heatmap .cell.corner-ampm.row-label { font-size: 0.56rem; padding: 1px 8px; }
  .heatmap .cell.day-group { padding: 0 2px; }
  .heatmap .cell.day-group .m { font-size: 0.48rem; }
  .heatmap .cell.day-group .d { font-size: 0.62rem; }
  .heatmap .cell.ampm .t { font-size: 0.52rem; }
  table.leaderboard th,
  table.leaderboard td { padding: 8px 8px; font-size: 0.92rem; }
  .hide-sm { display: none !important; }
  .pill.mini { display: inline-block; margin-top: 2px; margin-left: 0; }
  .heatmap-wrap::after { width: 18px; }
  .brand { font-size: 1rem; }
  .brand-sub { display: none; }
  .brand-logo { height: 40px; }
  .view-tab { padding: 8px 12px; font-size: 0.85rem; }
}

@media (max-width: 560px) {
  /* Ranked bars stack: name on its own line, track + value beneath. */
  .ranked-row { grid-template-columns: 1fr 48px; row-gap: 5px; }
  .ranked-name { grid-column: 1 / -1; }
  .view-tabs { width: 100%; }
  .view-tab { flex: 1 1 40%; }
}
