/* ==========================================================================
   Base — reset, typography, layout primitives, the ruler motif
   ========================================================================== */

*,
*::before,
*::after { box-sizing: border-box; }

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-gutter: stable;
}

body {
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  line-height: var(--lh-body);
  font-weight: 400;
  letter-spacing: 0;
  color: var(--ink);
  background: var(--desk);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  /* The page body never scrolls horizontally. Wide content scrolls inside
     its own container. */
  overflow-x: hidden;
}

/* Mobile bumps body text to 16px for readability */
@media (max-width: 768px) {
  body { font-size: var(--fs-md); }
}

img, video, canvas { display: block; max-width: 100%; }

/* Inline icons carry no width/height attributes, so give every SVG a sane
   default at the lowest possible specificity. Anything more specific
   (.btn svg, .chart, .brand-mark) still wins. */
svg { display: block; flex-shrink: 0; width: 16px; height: 16px; }
.chart { width: 100%; height: auto; }
.spark { width: 90px; height: 22px; }
.brand-mark { width: 24px; height: 24px; }
.empty-glyph { width: 34px; height: 34px; }

input, button, textarea, select {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button { background: none; border: none; padding: 0; }

/* ---- Headings ----------------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
  color: var(--ink);
}

/* Real jumps between levels. The old spread put the page title at 1.5× body
   and panel titles at the same weight as the page title — so nothing on screen
   ever commanded attention. */
h1 { font-size: var(--fs-2xl); font-weight: 650; letter-spacing: -0.018em; }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
h4 { font-size: var(--fs-sm); }

p { text-wrap: pretty; }

a {
  color: var(--primary-ink);
  text-decoration-color: color-mix(in oklch, currentColor 35%, transparent);
  text-underline-offset: 2px;
}
a:hover { text-decoration-color: currentColor; }

ul, ol { padding: 0; list-style: none; }

hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: var(--s-5) 0;
}

/* ---- Focus — visible on every interactive element ----------------------- */

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* Rows and cells get an inset ring instead, so the outline is never clipped
   by the table's own overflow container. */
tr:focus-visible,
td:focus-visible,
th:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

::selection {
  background: var(--primary-soft);
  color: var(--ink);
}

/* ---- Numeric type ------------------------------------------------------- */

/* Anything that carries a measurement, quantity, ID or money. Tabular so
   fraction columns align to the pixel down a 200-row table. */
.num,
.mono {
  font-family: var(--font-data);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'zero' 1;
  letter-spacing: -0.005em;
}

.num-lg { font-size: var(--fs-3xl); font-weight: 500; line-height: 1.1; }
.num-md { font-size: var(--fs-xl);  font-weight: 500; line-height: 1.15; }

/* The fractional part of an imperial dimension, set slightly smaller and
   lifted so `34 1/2"` reads as one number rather than three tokens. */
.frac {
  font-size: 0.86em;
  opacity: 0.88;
  padding-inline-start: 0.14em;
}

.neg { color: var(--critical); }

/* ---- Text utilities ----------------------------------------------------- */

.t-2xs { font-size: var(--fs-2xs); }
.t-xs  { font-size: var(--fs-xs); }
.t-sm  { font-size: var(--fs-sm); }
.t-md  { font-size: var(--fs-md); }
.t-lg  { font-size: var(--fs-lg); }

.t-muted   { color: var(--ink-muted); }
.t-faint   { color: var(--ink-faint); }
.t-2       { color: var(--ink-2); }
.t-ink     { color: var(--ink); }
.t-critical{ color: var(--critical); }
.t-warning { color: var(--warning-ink); }
.t-primary { color: var(--primary-ink); }
.t-accent  { color: var(--accent-ink); }

.t-med  { font-weight: 500; }
.t-semi { font-weight: 600; }

.t-right  { text-align: right; }
.t-center { text-align: center; }

.t-nowrap { white-space: nowrap; }
.t-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.prose { max-width: 68ch; line-height: var(--lh-prose); }

/* A field label. Small, medium weight, faint tracking — not an uppercase
   tracked eyebrow. */
.label {
  display: block;
  font-size: var(--fs-2xs);
  font-weight: 500;
  color: var(--ink-2);
  letter-spacing: var(--tracking-label);
  margin-bottom: var(--s-2);
}

/* ---- Layout primitives -------------------------------------------------- */

.stack   { display: flex; flex-direction: column; }
.row     { display: flex; align-items: center; }
.row-top { display: flex; align-items: flex-start; }
.wrap    { flex-wrap: wrap; }
.grow    { flex: 1 1 auto; min-width: 0; }
.shrink0 { flex-shrink: 0; }
.between { justify-content: space-between; }
.end     { justify-content: flex-end; }
.baseline{ align-items: baseline; }

.g-1 { gap: var(--s-1); }
.g-2 { gap: var(--s-2); }
.g-3 { gap: var(--s-3); }
.g-4 { gap: var(--s-4); }
.g-5 { gap: var(--s-5); }
.g-6 { gap: var(--s-6); }
.g-7 { gap: var(--s-7); }
.g-8 { gap: var(--s-8); }

/* Responsive column grid without breakpoints.
   min() caps the track floor at the container width, so a --min wider than
   the viewport collapses to one column instead of forcing the page sideways. */
.autogrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(var(--min, 260px), 100%), 1fr));
  gap: var(--s-5);
}

.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-5); }
.cols-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-5); }
.cols-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-5); }

@media (max-width: 1100px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .cols-2, .cols-3, .cols-4 { grid-template-columns: minmax(0, 1fr); }
}

/* Split view: main content + fixed-width side rail */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rail, 340px);
  gap: var(--s-6);
  align-items: start;
}
@media (max-width: 1180px) {
  .split { grid-template-columns: minmax(0, 1fr); }
}

/* ==========================================================================
   The ruler motif
   Blinds are made to the sixteenth. Measurement is the product's soul, so
   the rule between sections is a real measuring scale — major ticks every
   fifth minor tick — not a plain 1px border.
   ========================================================================== */

.rule {
  height: 9px;
  border: none;
  margin: 0;
  border-top: 1px solid var(--line);
  background-image:
    repeating-linear-gradient(
      to right,
      var(--line-strong) 0 1px,
      transparent 1px 40px
    ),
    repeating-linear-gradient(
      to right,
      var(--line) 0 1px,
      transparent 1px 8px
    );
  background-size: 100% 9px, 100% 4px;
  background-repeat: repeat-x;
  background-position: top left;
}

/* Vertical variant, used down the left of the nesting strips */
.rule-v {
  width: 9px;
  border-left: 1px solid var(--line);
  background-image:
    repeating-linear-gradient(to bottom, var(--line-strong) 0 1px, transparent 1px 40px),
    repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px 8px);
  background-size: 9px 100%, 4px 100%;
  background-repeat: repeat-y;
}

/* Tick scale used as an axis under charts and nesting strips */
.tick-axis {
  position: relative;
  height: 14px;
  border-top: 1px solid var(--line-strong);
  background-image: repeating-linear-gradient(
    to right, var(--line-strong) 0 1px, transparent 1px var(--tick, 20px)
  );
  background-size: 100% 5px;
  background-repeat: repeat-x;
}

/* ---- Surfaces ----------------------------------------------------------- */

/* A panel is the workhorse container. It is white and it LIFTS off the desk —
   a hairline alone put it on the same plane as everything else. Still no
   rounding drama, and panels never nest. */
.panel {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
}

/* The header is chrome, so it gets a chrome surface. Previously transparent,
   which made a panel read as a plain box with a line drawn across it. */
.panel-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3) var(--s-4);
  flex-wrap: wrap;
  padding: var(--s-4) var(--s-5);
  background: linear-gradient(var(--shell), color-mix(in oklch, var(--shell) 55%, var(--raised)));
  border-bottom: 1px solid var(--line);
  border-radius: var(--r-md) var(--r-md) 0 0;
  min-height: 46px;
}
.panel-hd > * { min-width: 0; }

.panel-hd h2,
.panel-hd h3 {
  font-size: var(--fs-md);
  font-weight: 600;
  letter-spacing: -0.012em;
  color: var(--ink);
}

.panel-bd { padding: var(--s-5); }
.panel-bd-flush { padding: 0; }

.panel-ft {
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--line);
  background: var(--shell);
  border-radius: 0 0 var(--r-md) var(--r-md);
  font-size: var(--fs-2xs);
  color: var(--ink-muted);
}

/* ---- Accessibility helpers ---------------------------------------------- */

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: var(--s-3);
  left: var(--s-3);
  z-index: var(--z-tooltip);
  padding: var(--s-3) var(--s-4);
  background: var(--primary);
  color: var(--ink-inverse);
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  font-weight: 500;
  transform: translateY(-200%);
}
.skip-link:focus-visible { transform: translateY(0); }

/* ---- Scroll containers -------------------------------------------------- */

/* Wide content scrolls here, never on <body>. */
.scroll-x {
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.scroll-y {
  overflow-y: auto;
  overscroll-behavior-y: contain;
}

/* ---- Reduced motion ----------------------------------------------------- */

/* Fewer and gentler, not zero: opacity and colour transitions that aid
   comprehension survive; everything that moves does not. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  /* Keep the crossfades that carry meaning */
  .drawer,
  .dialog,
  .toast,
  .popover {
    transition: opacity 150ms linear !important;
    transform: none !important;
  }
}

/* ---- Print — cut sheets and pick lists get printed on the shop floor ----- */

@media print {
  .app-sidebar,
  .app-topbar,
  .no-print { display: none !important; }

  body { background: #fff; font-size: 10pt; }
  .app-main { margin: 0 !important; padding: 0 !important; }
  .panel { break-inside: avoid; border-color: #999; }
  a { text-decoration: none; color: inherit; }
}
