/* ===========================================================================
 * Dijiwa Design System — Global Stylesheet
 * ---------------------------------------------------------------------------
 * Applies tokens everywhere. Bridges tokens.css / motion.css / dye-palette.css
 * to the Tailwind utility classes already in use across the dashboard.
 *
 * Imported once on every dashboard HTML page (after tokens, motion, dye).
 * login.html does NOT load this file (it links tokens.css + its own login.css).
 *
 * LOOK (soft-UI refresh, 2026-10): a neutral grey canvas, flat white cards with
 * large corners, grey FILLS instead of bordered boxes for anything nested, pill
 * controls, ink primary actions, and heavy tight-tracked sans headings. The
 * measured reference and the reasoning are in docs/design-refresh/.
 * =========================================================================== */

/* ---- 2.1 Body baseline -------------------------------------------------- */
body {
  font-family: var(--font-body);
  background: var(--warm);
  color: var(--dark);
  font-size: var(--body-size);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---- 3.x Type scale — apply display role to every heading ---------------- */
h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--dark);
  margin: 0;
}

h1 { font-size: var(--h1-size); font-weight: var(--h1-weight); letter-spacing: var(--h1-track); }
h2 { font-size: var(--h2-size); font-weight: var(--h2-weight); letter-spacing: var(--h2-track); }
h3 { font-size: var(--h3-size); font-weight: var(--h3-weight); letter-spacing: var(--h3-track); }
h4 { font-size: var(--h4-size); font-weight: var(--h4-weight); letter-spacing: var(--h4-track); }

/* ---- 3.1 Fraunces serif helper (replaces the audit's silent-serif gap) ----
 * The audit caught `.serif { font-family: Helvetica Neue ... }` declared in
 * weekly-report.html:20 — that silently used the body face where a serif was
 * intended. Now points to Fraunces.
 * ------------------------------------------------------------------------ */
.serif {
  /* MISNOMER since the 2026-10 refresh: headings are Inter now, and this class
   * sits on ~100 headings, so it follows the heading face rather than being
   * renamed everywhere (same reasoning as --warm). For a real serif (printed
   * reports, brand moments) use .display-serif. */
  font-family: var(--font-heading);
  letter-spacing: -0.02em;
}
.display-serif {
  font-family: var(--font-display);
  font-optical-sizing: auto;
}

/* ===========================================================================
 * Brand Tailwind utility re-bindings
 *
 * The dashboard ships with Tailwind classes that hardcoded the prior
 * warm-gold chrome palette. These re-bindings flip them to the cool-pigment
 * tokens. No warm-gold hex is introduced here.
 * =========================================================================== */
.bg-brand         { background-color: var(--brand); }
.bg-brand-text    { background-color: var(--brand-text); }
.bg-warm          { background-color: var(--warm); }
.bg-dark          { background-color: var(--dark); }
.bg-surface-light { background-color: var(--surface-light); }
.bg-surface-dark  { background-color: var(--surface-dark); }
.bg-tint          { background-color: var(--tint); }
.bg-dijiwa-border { background-color: var(--dijiwa-border); }
.bg-lokalua-border{ background-color: var(--lokalua-border); }

.text-brand       { color: var(--brand); }
.text-brand-text  { color: var(--brand-text); }
.text-warm        { color: var(--warm); }
.text-dark        { color: var(--dark); }
.text-tint        { color: var(--tint); }
.text-dijiwa-border{ color: var(--dijiwa-border); }
.text-lokalua-border{ color: var(--lokalua-border); }

.border-brand     { border-color: var(--brand); }
.border-warm      { border-color: var(--warm); }
.border-dark      { border-color: var(--dark); }
.border-tint      { border-color: var(--tint); }
.border-dijiwa    { border-color: var(--dijiwa-border); }
.border-lokalua   { border-color: var(--lokalua-border); }

/* ===========================================================================
 * Type scale classes (3.2) — apply the project-locked scale to common HTML
 * =========================================================================== */
.eyebrow {
  font-size: var(--eyebrow-size);
  font-weight: var(--eyebrow-weight);
  letter-spacing: var(--eyebrow-track);
  text-transform: uppercase;
  color: var(--muted);
  font-family: var(--font-body);
}

.caption {
  font-size: var(--caption-size);
  font-weight: var(--caption-weight);
  color: var(--dark);
}

.small {
  font-size: var(--small-size);
  font-weight: var(--small-weight);
  color: var(--dark);
}

.num-hero {
  font-size: var(--num-hero-size);
  font-weight: var(--num-hero-weight);
  letter-spacing: var(--num-hero-track);
  color: var(--dark);
  /* proportional numerals — never tabular on the hero number */
  font-variant-numeric: proportional-nums;
  font-family: var(--font-heading);
  line-height: 1.05;
}

/* Tabular numerals helper — column-aligned numbers in tables / axis ticks /
 * stacked-bar segment labels. */
.tabular-nums { font-variant-numeric: tabular-nums; }

/* ===========================================================================
 * 5.3 Signature element — Carve-Lintel Booking Curve
 *
 * The single memorable moment of the dashboard. Tapered cyan-green stroke +
 * cyan-green wash + (hero only) 1px dashed filigree.
 * =========================================================================== */
.lintel-curve {
  fill: none;
  stroke: var(--brand);
  stroke-linecap: round;
}

.lintel-curve-path {
  fill: var(--brand);
  fill-opacity: 0.10;
  stroke: none;
}

.lintel-curve-filigree {
  stroke: var(--brand);
  stroke-opacity: 0.35;
  stroke-dasharray: 2 4;
  fill: none;
}

/* ---- Focus visibility (WCAG 2.4.7) --------------------------------------
 * Exactly one of ~220 buttons had a focus style before this. Keyboard users
 * got the UA default ring or nothing. :focus-visible (not :focus) so a mouse
 * click does not paint a ring, only keyboard/AT navigation does.
 * --------------------------------------------------------------------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 2px;
}
/* Dark surfaces need the light tint to stay visible. The sidebar and top bar
 * are LIGHT since the 2026-10 refresh, so only an explicit .bg-dark qualifies. */
:where(.bg-dark) :where(a, button, [tabindex]):focus-visible {
  outline-color: var(--tint);
}

/* ===========================================================================
 * Semantic surfaces — the radius/elevation scale, applied.
 * ---------------------------------------------------------------------------
 * Use ONE of these instead of hand-assembling `bg-white rounded-xl shadow`.
 * Which one you pick is a statement about HIERARCHY, so pick by what the thing
 * IS, not by what looks nice in isolation:
 *
 *   .surface-tile     a stat / KPI tile — a small peer in a row or grid.
 *                     WHITE when it sits on the canvas, a grey FILL when it sits
 *                     inside a white surface. Never a border, never a shadow.
 *   .surface-card     the primary content surface — a panel wrapping a chart,
 *                     a table, or a titled section. Flat white, large corners.
 *   .surface-popover  a dropdown, tooltip body, or menu — transient, above the
 *                     page but not blocking it. The first surface with a shadow.
 *   .surface-overlay  a modal, dialog, or slide-over — blocks the page; pair it
 *                     with a .scrim behind it.
 *
 * NO BORDERS, NO RESTING SHADOWS (2026-10 refresh). Separation comes from tone:
 * white on the grey canvas, grey fill on white. A hairline or a shadow on top of
 * a tone step is noise. Only what floats (popover, overlay) casts a shadow.
 *
 * CHARTS STAY ON WHITE. The chart palettes are validated against white, so a
 * surface that holds a <canvas> is never given the grey fill: a card nested in
 * a card that holds a chart keeps white and takes an inset hairline instead.
 *
 * Radius tracks hierarchy: 14px control -> 20px tile -> 24px card -> 28px overlay.
 *
 * LOAD-ORDER TRAP, measured 2026-08-19 — READ THIS BEFORE USING THESE CLASSES.
 * Tailwind is loaded from the CDN and injects its utilities into the document
 * AFTER this stylesheet. Tailwind utilities and these classes are both
 * single-class selectors, so they have EQUAL specificity and the later one wins:
 * Tailwind's. Verified live — an element with `class="surface-card rounded-xl
 * shadow"` computes Tailwind's radius, not the token.
 *
 * Consequence: you MUST DELETE the conflicting utilities (rounded-*, shadow-*,
 * bg-white, and any border-gray-*) when you apply a surface class. Adding the
 * class on top of them does nothing and FAILS SILENTLY.
 *
 * Do NOT "solve" this by doubling the selector (.surface-card.surface-card) or
 * with !important. Delete the utilities, then verify by reading COMPUTED style.
 * =========================================================================== */
.surface-tile {
  background-color: var(--surface-light);
  border: 0;
  border-radius: var(--radius-tile);
  box-shadow: var(--elev-flat);
}
/* A tile inside a white surface is a grey fill (it would vanish as white-on-white). */
:is(.surface-card, .surface-overlay, .surface-popover, .bg-white) .surface-tile {
  background-color: var(--fill);
}

.surface-card {
  background-color: var(--surface-light);
  border: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-raised);
}
/* A card nested in a white surface: grey fill — unless it holds a chart. */
:is(.surface-card, .surface-overlay) .surface-card {
  background-color: var(--fill);
  border-radius: var(--radius-tile);
}
:is(.surface-card, .surface-overlay) .surface-card:has(canvas) {
  background-color: var(--surface-light);
  box-shadow: inset 0 0 0 1px var(--hairline);
}

.surface-popover {
  background-color: var(--surface-light);
  border: 0;
  border-radius: var(--radius-md);
  box-shadow: var(--elev-popover);
}

.surface-overlay {
  background-color: var(--surface-light);
  border: 0;
  border-radius: var(--radius-xl);
  box-shadow: var(--elev-overlay);
}

/* The dim layer behind an overlay. No blur: the page stays readable behind it. */
.scrim { background-color: var(--scrim); }

/* A slide-over is flush to a viewport edge, so rounding every corner is wrong —
 * it rounds only the two corners that face into the page. */
.surface-overlay--drawer-right {
  border-radius: var(--radius-xl) 0 0 var(--radius-xl);
  border-right: 0;
}
.surface-overlay--drawer-left {
  border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
  border-left: 0;
}

/* Control + inline-mark radii, so a page never needs a raw px value again. */
.r-sm   { border-radius: var(--radius-sm); }
.r-md   { border-radius: var(--radius-md); }
.r-lg   { border-radius: var(--radius-lg); }
.r-xl   { border-radius: var(--radius-xl); }
.r-pill { border-radius: var(--radius-pill); }

/* ===========================================================================
 * Controls (soft-UI refresh, 2026-10) — use these for NEW markup.
 * ---------------------------------------------------------------------------
 * Buttons are capsules. ONE primary action per view, in ink; everything else is
 * a grey capsule or plain text. Brand green is an ACCENT (active icon, link,
 * focus ring, data), not a button colour.
 *
 * Feedback is deliberately quiet: the ink button dims to 92% on hover, every
 * button scales to --scale-press while held (motion.css owns that rule and its
 * reduced-motion gate), and nothing changes colour on hover except a grey
 * capsule going one step darker.
 * =========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: transform var(--dur-press) var(--ease-out), opacity 200ms ease, background-color 200ms ease;
}
.btn-sm { height: 36px; padding: 0 14px; font-size: 13px; }
.btn-lg { height: 56px; padding: 0 24px; font-size: 16px; }
.btn-block { width: 100%; }

.btn-primary           { background-color: var(--dark); color: #FFFFFF; }
.btn-primary:hover     { opacity: .92; }
.btn-secondary         { background-color: var(--fill-2); color: var(--dark); }
.btn-secondary:hover   { background-color: #DFDFE2; }
.btn-ghost             { background-color: transparent; color: var(--dark); }
.btn-ghost:hover       { background-color: var(--fill-2); }
.btn-danger            { background-color: #FEE2E2; color: #991B1B; }
.btn-danger:hover      { background-color: #FECACA; }
.btn:disabled,
.btn[aria-disabled="true"] {
  background-color: var(--fill-2);
  color: var(--faint);
  cursor: not-allowed;
  opacity: 1;
}

/* A round icon-only button: close, back, row chevron. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-pill);
  background-color: var(--fill);
  color: var(--dark);
  cursor: pointer;
}
.icon-btn:hover { background-color: var(--fill-2); }

/* Text field / select: a fill, not an outlined box. 16px text stops iOS zooming
 * on focus. The visible focus ring comes from the global :focus-visible rule. */
.field {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-md);
  background-color: var(--fill-2);
  color: var(--dark);
  font-family: var(--font-body);
  font-size: 16px;
}
.field::placeholder { color: var(--faint); }
textarea.field { height: auto; min-height: 96px; padding: 14px 16px; }
.field-label { display: block; margin: 0 0 6px 4px; font-size: 13px; font-weight: 500; color: var(--muted); }

/* Segmented control: a grey track with one white thumb. The thumb is the only
 * resting shadow in the system. UI.seg() in ui-kit.js renders this shape. */
.seg-track {
  display: inline-flex;
  padding: 4px;
  border-radius: var(--radius-pill);
  background-color: var(--fill-2);
}
.seg-item {
  padding: 7px 16px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.seg-item:hover { color: var(--dark); }
.seg-item[aria-selected="true"],
.seg-item.is-active {
  background-color: #FFFFFF;
  color: var(--dark);
  font-weight: 600;
  box-shadow: var(--elev-thumb);
}

/* Grouped list: rows share ONE grey block and are divided by an inset hairline
 * that starts after the leading icon, instead of each row being its own card. */
.list-group {
  border-radius: var(--radius-lg);
  background-color: var(--fill);
  overflow: hidden;
}
.list-row {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 10px 16px;
}
.list-row + .list-row { box-shadow: inset 0 1px 0 var(--hairline); }
:is(a, button).list-row:hover { background-color: var(--fill-2); }

/* A neutral capsule for a short statement ("About the same as September"). */
.pill-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  background-color: var(--fill);
  color: var(--dark);
  font-size: 14px;
  font-weight: 500;
}

/* Overlay entrance. Opacity + a small rise; reduced motion keeps opacity only. */
@keyframes ui-rise {
  from { opacity: 0; transform: translateY(8px) scale(var(--scale-entry)); }
  to   { opacity: 1; transform: none; }
}
@keyframes ui-fade { from { opacity: 0; } to { opacity: 1; } }
.surface-overlay { animation: ui-rise var(--dur-modal) var(--ease-out) both; }
.scrim           { animation: ui-fade var(--dur-modal) ease both; }
@media (prefers-reduced-motion: reduce) {
  .surface-overlay { animation-name: ui-fade; }
}

/* ===========================================================================
 * LEGACY BRIDGE — hand-assembled Tailwind recipes, mapped to the new look.
 * ---------------------------------------------------------------------------
 * ~230 buttons and ~250 cards across the pages are still written as raw utility
 * strings (`bg-[#006E64] text-white rounded-lg`, `bg-white rounded-xl shadow
 * border border-gray-200`). nav.js remaps the Tailwind radius/shadow SCALE once
 * for every page; these few rules cover what a scale cannot express. They use
 * compound selectors on purpose (they must beat a Tailwind utility loaded after
 * this file) and match only the exact recipes named — the documented exception
 * to "never out-specify a utility" above.
 *
 * This block is a BRIDGE: when a page's markup moves to .btn / .surface-* the
 * rule stops matching it. Delete a rule once grep shows no remaining recipe.
 * =========================================================================== */

/* Primary buttons: brand-green fill -> ink. Only <button>/<a>: a green progress
 * bar, badge or dot is data/brand and stays green. */
:is(button, a).bg-brand,
:is(button, a).bg-\[\#006E64\],
:is(button, a).bg-\[\#006e64\] { background-color: var(--dark); }
:is(button, a).bg-brand:hover,
:is(button, a).bg-\[\#006E64\]:hover,
:is(button, a).bg-\[\#006e64\]:hover { background-color: var(--dark); opacity: .92; }

/* Buttons become capsules. Excludes block-level buttons (list rows, tiles and
 * full-width rows are written as <button class="w-full text-left ...">). */
button:is(.rounded, .rounded-md, .rounded-lg):not(.w-full):not(.text-left):not(.block) {
  border-radius: var(--radius-pill);
}

/* A white card sitting on the canvas drops its border (tone separates it). A
 * white card INSIDE a white surface keeps the hairline: with no border it
 * would disappear. */
.bg-white:is(.rounded-xl, .rounded-2xl).border { border-color: transparent; }
:is(.bg-white, .surface-card, .surface-overlay) .bg-white:is(.rounded-xl, .rounded-2xl).border {
  border-color: var(--hairline);
}
