/* ── JGRG Unified Shell (Dark Editorial Ledger · Phase 4) ───────────────────
 *  Layered on top of tokens.css. Lifts the Suite top-strip, page header, .dr
 *  date-range component, source-badges, live indicator, section heads, panels,
 *  and the money-table utility.
 *
 *  Linked by every dashboard page. See handoff/docs/phase-4-sow.html PR-01.
 *
 *  ── Migration contract for PR-02..PR-09 (READ BEFORE ADDING THE <link>) ────
 *  Several unprefixed class names below (`.dr`, `.btn`, `.kpi-strip`) already
 *  exist with different inline rules in production HTML. When migrating a page
 *  to the shared shell, the worker MUST delete the inline duplicates in the
 *  same PR — otherwise the inline rules will win specificity battles against
 *  the shared shell and the unification breaks silently.
 *
 *  Known existing inline duplicates as of PR-01 (audit by Kimi 2026-05-23):
 *    .dr        — labour-dashboard.html, server-drill.html
 *    .btn       — heron.html, pre-service-briefing.html, cashout.html
 *    .kpi-strip — daily-ops.html, performance.html
 *
 *  PR-02 handles cashout / labour / server-drill (3 best-of-breed). PR-05
 *  through PR-09 each strip the duplicates from their target pages. The SoW's
 *  "Removes the inline copies of header / .dr CSS now living in jgrg-shell.css"
 *  bullet is the contract.
 *
 *  ── CSS-variable collision (discovered in PR-02) ──────────────────────────
 *  Several pages redefine `--ink` in their inline :root to mean "the text
 *  ink colour" (cream) — the opposite of how shared/tokens.css uses it
 *  ("the dark canvas"). Example: cashout.html L52 redefines --ink to point
 *  at --cream (page-level comment there annotates it "INVERTED, now text
 *  colour").
 *
 *  To avoid breaking those pages when they <link> this shell, every shared
 *  rule that means "the dark canvas" uses var(--canvas) — never var(--ink).
 *  --canvas resolves to #0c0c0a everywhere: pages either define it directly
 *  (cashout, labour, server-drill all do), or fall back through the alias
 *  block below which points --canvas at the shared tokens' --ink. PR-05..PR-09
 *  should NOT need to touch this; if you find a shell rule reaching for
 *  var(--ink), change it to var(--canvas).
 *  ───────────────────────────────────────────────────────────────────────── */

@import url('./tokens.css');

/* Legacy aliases so pages that still ref --canvas / --bg / --muted resolve.
   These alias to --ink (the shared tokens' dark canvas). Pages may override
   --canvas/--bg locally — that's fine, the alias only fires as a fallback. */
:root {
  --canvas: var(--ink);
  --bg:     var(--ink);
  --muted:  var(--mute-2);
  --text:   var(--cream);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--canvas); color: var(--cream); font-family: var(--sans); font-size: 14px; line-height: 1.55; }
.num { font-variant-numeric: tabular-nums; }

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; color: inherit; }

/* ════════════════════════════════════════════════════════════════════════ */
/* SUITE TOP-STRIP — global nav on every page                                */
/* ════════════════════════════════════════════════════════════════════════ */
.jgrg-suite-strip {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 24px; background: var(--navy);
  border-bottom: none; box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase;
  position: relative; z-index: 10;
}
.jgrg-suite-strip .home {
  display: inline-flex; align-items: center; gap: 8px;
  color: rgba(255,255,255,0.72); text-decoration: none; opacity: 1;
  padding: 4px 0; transition: color 0.15s;
}
.jgrg-suite-strip .home:hover { color: #fff; }
.jgrg-suite-strip .home .arrow { color: var(--gold); }
.jgrg-suite-strip .suite-tag {
  flex: 1; text-align: center;
  font-family: var(--serif); font-size: 13px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: none; color: #fff;
}
.jgrg-suite-strip .suite-tag em { color: var(--gold); font-style: normal; font-weight: 700; }
.jgrg-suite-strip nav {
  display: flex; gap: 18px; color: rgba(255,255,255,0.6);
}
.jgrg-suite-strip nav a { color: inherit; padding: 4px 0; transition: color 0.15s; }
.jgrg-suite-strip nav a:hover { color: #fff; }
.jgrg-suite-strip nav a.current { color: #fff; border-bottom: 1px solid var(--gold); }

/* Hamburger toggle — only visible on narrow viewports */
.jgrg-suite-strip .menu-toggle {
  display: none; appearance: none; background: transparent; border: none;
  color: rgba(255,255,255,0.85); padding: 4px 8px;
  font-family: var(--mono); font-size: 14px;
}
.jgrg-suite-strip .menu-toggle:hover { color: #fff; }

/* ════════════════════════════════════════════════════════════════════════ */
/* PAGE HEADER — page-name + meta-row                                        */
/* ════════════════════════════════════════════════════════════════════════ */
.jgrg-page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; padding: 28px 32px 22px;
  background: var(--canvas); border-bottom: 1px solid var(--border);
}
.jgrg-page-header .page-name {
  font-family: var(--serif); font-size: 30px; line-height: 1; font-weight: 400;
}
.jgrg-page-header .page-name em { color: var(--gold); font-style: normal; font-weight: 700; }
.jgrg-page-header .page-sub {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--mute-2); margin-top: 8px;
}
.jgrg-page-header .meta-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 10.5px;
}

/* ════════════════════════════════════════════════════════════════════════ */
/* BADGES — source + live indicator                                          */
/* ════════════════════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--border-2); border-radius: 999px;
  color: var(--cream-2);
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em;
  text-transform: uppercase; background: transparent;
}
.badge .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--gold);
  flex-shrink: 0;
}
.badge.src-auphan  .dot { background: var(--gold); }
.badge.src-7shifts .dot { background: var(--good); }
.badge.src-clover  .dot { background: var(--bramble); }
.badge.src-sheets  .dot { background: var(--k6); }

.badge.live {
  color: var(--good); border-color: var(--good-dim); background: var(--good-bg);
}
.badge.live .dot { background: var(--good); animation: jgrg-pulse 2s infinite; }
.badge.warn {
  color: var(--warn); border-color: var(--warn-dim); background: var(--warn-bg);
}
.badge.warn .dot { background: var(--warn); animation: jgrg-pulse 2s infinite; }
@keyframes jgrg-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ════════════════════════════════════════════════════════════════════════ */
/* .dr DATE-RANGE COMPONENT — hideable parts                                 */
/*   Slots:                                                                  */
/*   .dr-grain  · segmented Day/7d/30d/90d (hide on single-date pages)       */
/*   .dr-step-row · ‹ label › calendar (always present)                      */
/*   .dr-latest  · snap-to-now button   (hide on history-only pages)         */
/*   Locations can also hide the shift-select etc.                           */
/* ════════════════════════════════════════════════════════════════════════ */
.dr {
  display: flex; align-items: center; gap: 8px; padding: 12px 32px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.dr .dr-lhs {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--mute-2);
}
.dr .dr-grain {
  display: inline-flex; background: var(--surface-2);
  border: 1px solid var(--border-2); border-radius: 2px; padding: 2px;
}
.dr .dr-grain button {
  appearance: none; border: none; background: transparent;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--mute-2);
  padding: 6px 12px; border-radius: 1px; transition: all 0.12s;
}
.dr .dr-grain button.is-active {
  background: var(--gold); color: var(--canvas); font-weight: 500;
}
.dr .dr-grain button:hover:not(.is-active) { color: var(--cream); }

.dr .dr-step-row { display: inline-flex; align-items: center; gap: 4px; }
.dr .dr-step {
  appearance: none; width: 32px; height: 32px;
  background: transparent; border: 1px solid var(--border-2);
  border-radius: 2px; color: var(--cream);
  font-size: 14px; line-height: 1;
}
.dr .dr-step:hover { border-color: var(--gold); color: var(--gold); }
.dr .dr-label {
  padding: 6px 14px; min-width: 200px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 2px;
  font-family: var(--mono); font-size: 12px; color: var(--cream); cursor: pointer;
  transition: all 0.12s;
}
.dr .dr-label:hover { color: var(--gold); background: var(--surface-3); }
.dr .dr-cal {
  appearance: none; width: 32px; height: 32px;
  background: transparent; border: 1px solid var(--border-2);
  border-radius: 2px; color: var(--cream-2); font-size: 14px;
}
.dr .dr-cal:hover { color: var(--gold); border-color: var(--gold-soft); }

.dr .dr-grow { flex: 1; }

.dr .dr-latest {
  appearance: none; background: var(--gold-tint);
  border: 1px solid var(--gold-soft); color: var(--gold);
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em;
  padding: 7px 14px; border-radius: 2px;
  display: inline-flex; align-items: center; gap: 6px;
}
.dr .dr-latest .pulse {
  width: 6px; height: 6px; border-radius: 50%; background: var(--good);
  animation: jgrg-pulse 2s infinite;
}

.dr select {
  appearance: none;
  font-family: var(--mono); font-size: 12px;
  background: var(--surface-2); color: var(--cream);
  border: 1px solid var(--border-2);
  padding: 7px 26px 7px 12px; border-radius: 2px;
  background-image: linear-gradient(45deg, transparent 50%, var(--mute-2) 50%),
                    linear-gradient(135deg, var(--mute-2) 50%, transparent 50%);
  background-position: calc(100% - 14px) 13px, calc(100% - 9px) 13px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.dr select:focus { outline: none; border-color: var(--gold); }

/* ════════════════════════════════════════════════════════════════════════ */
/* PAGE CONTAINER + SECTIONS                                                 */
/* ════════════════════════════════════════════════════════════════════════ */
.jgrg-container { max-width: 1440px; margin: 0 auto; padding: 32px 32px 80px; }
.jgrg-section { margin-bottom: 44px; }

.jgrg-section-head {
  display: flex; align-items: baseline; gap: 14px;
  padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 20px;
}
.jgrg-section-head h2 {
  font-family: var(--serif); font-size: 22px; font-weight: 400; letter-spacing: 0.005em;
}
.jgrg-section-head h2 em { color: var(--gold); font-style: normal; font-weight: 700; }
.jgrg-section-head .sub {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--mute-2);
}
.jgrg-section-head .right { margin-left: auto; }

.jgrg-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 18px 22px; box-shadow: 0 1px 3px rgba(13,31,45,0.06);
}
.jgrg-panel + .jgrg-panel { margin-top: 16px; }
.jgrg-panel h3 {
  font-family: var(--serif); font-size: 16px; font-weight: 400; color: var(--cream);
  margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: baseline;
}
.jgrg-panel h3 .sub {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--mute-2);
}

/* ════════════════════════════════════════════════════════════════════════ */
/* KPI STRIP                                                                  */
/* ════════════════════════════════════════════════════════════════════════ */
.kpi-strip {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
}
.kpi-strip .kpi {
  background: var(--surface); border: 1px solid var(--border);
  padding: 16px 20px; position: relative;
  border-radius: 8px; box-shadow: 0 1px 3px rgba(13,31,45,0.06);
}
.kpi-strip .kpi .kpi-lbl {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--mute-2);
}
.kpi-strip .kpi .kpi-val {
  font-family: var(--serif); font-size: 30px; line-height: 1;
  color: var(--cream); margin-top: 10px; font-variant-numeric: tabular-nums;
}
.kpi-strip .kpi .kpi-delta {
  font-family: var(--mono); font-size: 11px; margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.kpi-strip .kpi .kpi-delta.pos { color: var(--good); }
.kpi-strip .kpi .kpi-delta.neg { color: var(--warn); }
.kpi-strip .kpi .kpi-delta.bad { color: var(--bad); }

/* ════════════════════════════════════════════════════════════════════════ */
/* MONEY TABLE UTILITY                                                        */
/*   Column priorities: data-priority="1" stays visible the longest,         */
/*   priority="3" hides first when viewport narrows.                          */
/*   Money values are always tabular-nums, right-aligned, monospace, sign    */
/*   in front of digits.                                                      */
/* ════════════════════════════════════════════════════════════════════════ */
.money-table {
  width: 100%; border-collapse: collapse;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; box-shadow: 0 1px 3px rgba(13,31,45,0.06);
}
.money-table thead th {
  text-align: left; padding: 12px 14px;
  background: var(--surface-2); border-bottom: 1px solid var(--border-2);
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--mute-2); font-weight: 400;
}
.money-table thead th.num { text-align: right; }
.money-table tbody td {
  padding: 14px 14px; border-bottom: 1px solid var(--border);
  vertical-align: baseline; font-size: 13px;
}
.money-table tbody tr:last-child td { border-bottom: none; }
.money-table tbody tr:hover td { background: var(--surface-2); }
.money-table .name { font-family: var(--serif); font-size: 15px; color: var(--cream); }
.money-table .name .sub {
  display: block; font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--mute-2);
  margin-top: 2px;
}
.money-table .money {
  font-family: var(--mono); font-size: 13.5px; color: var(--cream);
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.money-table .money.muted { color: var(--cream-2); }
.money-table .delta {
  font-family: var(--mono); font-size: 11.5px; text-align: right;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.money-table .delta.pos { color: var(--good); }
.money-table .delta.neg { color: var(--warn); }
.money-table .delta.bad { color: var(--bad); }
.money-table .delta.flat { color: var(--mute-2); }

/* Location row variant — 3px left stripe via per-location class on tr */
.money-table tr.loc-bramble td:first-child { box-shadow: inset 3px 0 0 var(--bramble); }
.money-table tr.loc-heron   td:first-child { box-shadow: inset 3px 0 0 var(--heron); }
.money-table tr.loc-merlot  td:first-child { box-shadow: inset 3px 0 0 var(--merlot); }
.money-table tr.loc-k6      td:first-child { box-shadow: inset 3px 0 0 var(--k6); }

/* ════════════════════════════════════════════════════════════════════════ */
/* STATUS PILL — for non-money rows (verdicts, severities)                   */
/* ════════════════════════════════════════════════════════════════════════ */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.12em;
  text-transform: uppercase; font-weight: 500;
  border: 1px solid var(--border-2); background: transparent;
}
.pill.good { color: var(--good); border-color: var(--good-dim); background: var(--good-bg); }
.pill.warn { color: var(--warn); border-color: var(--warn-dim); background: var(--warn-bg); }
.pill.bad  { color: var(--bad);  border-color: var(--bad-dim);  background: var(--bad-bg); }

/* ════════════════════════════════════════════════════════════════════════ */
/* FORM CONTROLS — buttons, inputs, selects                                  */
/* ════════════════════════════════════════════════════════════════════════ */
.btn {
  appearance: none; background: transparent; color: var(--cream);
  border: 1px solid var(--border-2);
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em;
  padding: 8px 14px; border-radius: 2px;
  transition: all 0.12s;
}
.btn:hover { border-color: var(--gold); color: var(--gold); }
.btn.primary {
  background: var(--gold); color: var(--canvas); border-color: var(--gold); font-weight: 500;
}
.btn.primary:hover { background: var(--gold-strong); color: var(--canvas); border-color: var(--gold-strong); }
.btn.danger { color: var(--bad); border-color: var(--bad-dim); }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad); }

.input {
  appearance: none; font-family: var(--mono); font-size: 12px;
  background: var(--surface-2); color: var(--cream);
  border: 1px solid var(--border-2);
  padding: 8px 12px; border-radius: 2px;
}
.input:focus { outline: none; border-color: var(--gold); }

/* ════════════════════════════════════════════════════════════════════════ */
/* RESPONSIVE                                                                 */
/* ════════════════════════════════════════════════════════════════════════ */

/* — Tablet ≥768 / <1024 ───────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .jgrg-container { padding: 24px 24px 64px; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .jgrg-page-header { padding: 24px 24px 18px; }
  .dr { padding: 12px 24px; }
  .jgrg-suite-strip { padding: 8px 20px; }
}

/* — Narrow tablet / wide phone ≥600 / <768 ────────────────────────────── */
@media (max-width: 768px) {
  .jgrg-suite-strip nav a:not(.current):not(.always-show) { display: none; }
  .jgrg-suite-strip .menu-toggle { display: inline-flex; }
  .jgrg-page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .jgrg-page-header .page-name { font-size: 26px; }
  .dr { gap: 6px; }
  .dr .dr-lhs { display: none; }
  .dr .dr-label { min-width: 0; flex: 1; }

  /* Money table: hide lowest-priority columns first */
  .money-table th[data-priority="3"], .money-table td[data-priority="3"] { display: none; }
}

/* — Phone <600 ───────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .kpi-strip { grid-template-columns: 1fr; }
  .jgrg-container { padding: 16px 16px 56px; }
  .jgrg-page-header { padding: 18px 16px 14px; }
  .jgrg-page-header .page-name { font-size: 22px; }
  .dr { padding: 10px 16px; }
  .jgrg-suite-strip { padding: 6px 16px; font-size: 10px; }
  .jgrg-suite-strip .suite-tag { display: none; }
  .jgrg-suite-strip nav { display: none; } /* fully hidden; menu-toggle is the affordance */

  /* Money table: hide priority-2 columns too */
  .money-table th[data-priority="2"], .money-table td[data-priority="2"] { display: none; }
  .money-table thead th { padding: 10px; font-size: 9.5px; }
  .money-table tbody td { padding: 12px 10px; font-size: 12.5px; }
  .money-table .money { font-size: 12.5px; }
}

/* — Print ────────────────────────────────────────────────────────────── */
@media print {
  html, body { background: #fff; color: #000; }
  .jgrg-suite-strip, .dr, .jgrg-page-header .meta-row { display: none; }
  .jgrg-page-header { padding: 0 0 16px; border-bottom: 1px solid #000; }
  .jgrg-page-header .page-name { color: #000; }
  .jgrg-page-header .page-name em { color: #555; }
  .money-table { background: #fff; border: 1px solid #ccc; }
  .money-table thead th { background: #f0f0f0; color: #000; border-color: #999; }
  .money-table tbody td { color: #000; border-color: #ccc; }
  .money-table .money { color: #000; }
  .badge, .pill { border-color: #999; color: #000; }
}
