/* =============================================================================
 * TWE UI — base.css   v2.1.0   2026-09-04
 * The reset, the type system, and "not default anything".
 *
 * LOAD ORDER: tokens.css -> base.css -> everything else. Written at zero or
 * near-zero specificity (:where(), bare element and universal selectors) so
 * every sibling sheet overrides it without !important — if a component file
 * needs !important, base.css got too specific, so fix it here. Corollary for
 * sibling authors: declare a control's border-radius at class specificity, NOT
 * inside :where(), or the global focus rule in §3 outranks it.
 *
 * SCOPE: browser defaults only. Buttons, inputs, selects, cards, tables, modals
 * and toasts belong to sibling files — two sheets fighting over one control is
 * how the fleet forked the first time.
 *
 * FLOOR: Chromium 120 (Tatara / Electron 28). Everything mandatory works at
 * 120; modern-only rules live in @supports (§10) and are never the sole styling
 * for anything, because an unguarded modern rule degrades to a native OS
 * widget — the exact complaint this kit exists to fix.
 * ========================================================================== */

/* ------------------------------------------------------------- 1. reset ----- */
*, *::before, *::after { box-sizing: border-box; margin: 0; }

/* min-width:auto on a flex/grid item REFUSES to shrink below its content — the
 * most common overflow bug in the fleet (a long project name blowing out a
 * sidebar instead of ellipsing). Elsewhere min-width already computes to 0, so
 * this is a targeted fix wearing a broad selector.
 * scrollbar-width does not inherit, hence it rides along here (see §2). */
:where(*) { min-width: 0; scrollbar-width: thin; }

html {
  /* html IS :root. Cheapest global win in this file: themes every native
   * checkbox, radio, range and progress we have not hand-styled yet, so a
   * half-finished screen still reads as ours. */
  accent-color: var(--twe-accent);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;          /* tokens.css forces auto under reduced-motion */
  scrollbar-gutter: stable;         /* page must not shift when a scrollbar appears */
  scrollbar-color: var(--twe-scrollbar-thumb) var(--twe-scrollbar-track);

  /* DELIBERATE, and specifically a Windows decision: DirectWrite renders Outfit
   * heavier and darker than CoreText does on the designer's Mac, and at the
   * 125%/150% per-monitor DPI normal on TWE workstations the stems bloat
   * further. antialiased restores the intended weight. Removing this makes the
   * type look muddy on every desk in the firm. */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--twe-font-sans);
  font-size: var(--twe-text-base);
  line-height: var(--twe-leading-body);
  color: var(--twe-text);
  background-color: var(--twe-bg);
  min-height: 100vh;
  min-height: 100dvh;               /* dvh = tablet URL-bar-safe */

  /* Only weight 400 is vendored for either family (tokens.css §0), so
   * font-synthesis:none makes a missing weight FAIL VISIBLY here instead of
   * shipping smeared fake bold across 30 tools. §9 holds the one scoped
   * exception, which exists for an accessibility reason. */
  font-synthesis: none;
}

/* Replaced elements are inline by default — that is the phantom 4px baseline
 * gap under every image inside a card. */
:where(img, svg, video, canvas, audio, iframe, embed, object) {
  display: block;
  max-width: 100%;
}
:where(img, video) { height: auto; }

/* Controls do NOT inherit type from the page; that UA rule is why a legacy
 * tool's inputs are 13px Segoe inside a 14px Outfit shell. Font inheritance
 * only — appearance, colour and geometry belong to controls.css. */
:where(input, button, textarea, select, optgroup) {
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
}
:where(textarea) { resize: vertical; }   /* horizontal resize always breaks layout */

:where(button, select, summary, label[for], [role='button'], [role='tab'],
       input[type='checkbox'], input[type='radio'], input[type='file']) {
  cursor: pointer;
}
:where(:disabled, [aria-disabled='true']) { cursor: not-allowed; }

/* The UA <hr> is a 3D inset groove: legacy tell, and fractional at 150% DPI. */
:where(hr) { border: 0; border-block-start: var(--twe-border-width) solid var(--twe-border); }

/* margin:0 above stripped list indentation along with everything else. */
:where(ul, ol) { padding-inline-start: var(--twe-space-5); }

/* ------------------------------------------- 2. scrollbars (legacy tell #1) --
 * Present in 29 of 39 fleet tools: a chunky grey Windows scrollbar with arrow
 * buttons inside an otherwise modern panel. It is the first thing the eye lands
 * on and it dates the entire screen.
 *
 * Both layers are deliberate. ::-webkit-scrollbar is the MANDATORY one — the
 * only layer that works at the Chromium 120 floor, and Chromium honours these
 * pseudo-elements wherever they are present. scrollbar-width/-color (121+, set
 * in §1) are the forward-compatible fallback for any engine that prefers the
 * standard properties; both resolve to the same thin token-coloured result, so
 * the two layers can never disagree about the look. */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: var(--twe-scrollbar-track); }
*::-webkit-scrollbar-thumb {
  background-color: var(--twe-scrollbar-thumb);
  border-radius: var(--twe-radius-pill);
  /* Transparent border + padding-box clip floats the pill inside the gutter
   * instead of filling it edge to edge. This is the whole difference between
   * "designed scrollbar" and "OS scrollbar someone recoloured". */
  border: 2px solid transparent;
  background-clip: padding-box;
  transition: background-color var(--twe-dur-fast) var(--twe-ease);
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--twe-scrollbar-thumb-hover); }
*::-webkit-scrollbar-corner { background: var(--twe-scrollbar-track); }
/* Stepper arrows are the loudest part of the Windows scrollbar and nothing in
 * this system asks anyone to click them. */
*::-webkit-scrollbar-button { display: none; }

/* Dense panels (data grids, log tails, side rails). */
.twe-scroll--thin { scrollbar-gutter: stable; scrollbar-width: thin; }
.twe-scroll--thin::-webkit-scrollbar { width: 6px; height: 6px; }
.twe-scroll--thin::-webkit-scrollbar-thumb { border-width: 1px; }

/* Carousels and horizontal rails. The element STAYS scrollable, and it must
 * carry tabindex="0" so a keyboard user can scroll it — Chromium does not
 * focus scrollers by default, and the §3 ring then makes that focus visible.
 * Never let a hidden-scrollbar rail be the only route to content: pair it with
 * real prev/next controls. None of this needs JavaScript. */
.twe-scroll--none { scrollbar-width: none; scrollbar-gutter: auto; }
.twe-scroll--none::-webkit-scrollbar { width: 0; height: 0; }

/* ------------------------------------------------------- 3. the focus ring --
 * ONE global rule, on purpose. Panoptes shipped a hand-maintained selector
 * list (.btn, .input, .tab, ...) and every control added afterwards silently
 * shipped with no ring at all — an invisible, untestable a11y regression. A
 * hand-maintained list is guaranteed to rot. Do not reintroduce one.
 * border-radius:inherit lets the ring hug a rounded parent on elements that
 * declare no radius themselves; see the header note on specificity. */
:focus-visible {
  outline: 2px solid var(--twe-accent);
  outline-offset: 2px;
  border-radius: inherit;
}
/* Mouse users get no ring; keyboard users always do. Never write outline:none
 * without a :focus-visible replacement — that is a WCAG 2.4.7 failure. */
:focus:not(:focus-visible) { outline: none; }

/* --------------------------------------------- 4. text bits browsers own -----
 * Every selector below repaints a UA default that ignores our theme. */
::selection { background-color: var(--twe-accent-dim); color: var(--twe-text); }
:where(input, textarea, [contenteditable]) { caret-color: var(--twe-accent); }
::marker { color: var(--twe-text-muted); }

/* opacity:1 is load-bearing: Firefox and older Chromium apply their own ~0.54
 * dim on top of the colour, dropping muted placeholder text below AA. */
::placeholder { color: var(--twe-text-muted); opacity: 1; }

/* Chromium paints these UA glyphs from the OS, not our palette. The per-theme
 * color-scheme in tokens.css already flips them light/dark, so these rules only
 * stop them shouting — no hardcoded colour required. */
::-webkit-calendar-picker-indicator {
  opacity: 0.6;
  cursor: pointer;
  border-radius: var(--twe-radius-xs);
  transition: opacity var(--twe-dur-fast) var(--twe-ease);
}
::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* The native search "x" is a fixed grey bitmap, so it is masked and painted
 * from a token instead. The data: URI is inline — no network, no CDN. NOTE the
 * %23000 inside it is an ALPHA STENCIL, not a theme colour: a mask reads only
 * opacity, and the visible colour is the background-color below. */
::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 0.75rem; height: 0.75rem;
  cursor: pointer;
  background-color: var(--twe-text-muted);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 2l8 8M10 2l-8 8' stroke='%23000' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 2l8 8M10 2l-8 8' stroke='%23000' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  -webkit-mask-size: contain; mask-size: contain;
}
::-webkit-search-cancel-button:hover { background-color: var(--twe-text); }

/* ---------------------------------------------------- 5. autofill override ---
 * Chromium paints autofilled fields a hard #E8F0FE and ignores `background`.
 * On a dark themed input that is a glowing yellow-white block — one of the
 * ugliest legacy tells in the fleet, and it lands on every login screen. The
 * only lever is an inset box-shadow big enough to cover the field.
 * The 100000s delay is a PAINT-SUPPRESSION HACK, not a motion duration — which
 * is why no --twe-dur-* token applies: it parks the UA's own background
 * transition far enough out that it never repaints over us. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 100px var(--twe-bg-input) inset;
  box-shadow: 0 0 0 100px var(--twe-bg-input) inset;
  -webkit-text-fill-color: var(--twe-text);
  caret-color: var(--twe-accent);
  transition-property: background-color, color;
  transition-delay: 100000s;
}

/* ---------------------------------------------------------- 6. typography ---
 * Hierarchy is carried by SIZE and SPACE, not weight: only weight 400 is
 * vendored and font-synthesis:none forbids faking the rest. Outfit is a
 * geometric display face and holds up at 400 in the large sizes. */
:where(h1, h2, h3, h4, h5, h6) {
  line-height: var(--twe-leading-tight);
  text-wrap: balance;               /* Chromium 114+, no ragged one-word last line */
}
:where(h1) { font-size: var(--twe-text-3xl); }
:where(h2) { font-size: var(--twe-text-2xl); }
:where(h3) { font-size: var(--twe-text-xl); }
:where(h4) { font-size: var(--twe-text-lg); line-height: var(--twe-leading-snug); }
:where(h5) { font-size: var(--twe-text-md); line-height: var(--twe-leading-snug); }
:where(h6) { font-size: var(--twe-text-base); line-height: var(--twe-leading-snug); }

/* 68ch measure: past ~75 characters the eye loses the line on its return
 * sweep. A measure is a typographic constant, not a themeable value, so it is
 * literal by design. Prose only — set max-width:none inside table/grid cells. */
:where(p) { text-wrap: pretty; max-width: 68ch; }

/* A muted sub-label. Sentence case, no tracking: the uppercase letter-spaced
 * kicker above a heading is a recognised AI-UI tell and was retired in 2.1.0.
 * Place it BELOW the heading as one line of context, never as a decorative
 * kicker above it. The class name stays for compatibility. */
.twe-eyebrow {
  font-size: var(--twe-text-xs);
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color: var(--twe-text-secondary);
  line-height: var(--twe-leading-snug);
}

:where(code, kbd, samp, pre) { font-family: var(--twe-font-mono); font-size: var(--twe-text-sm); }
/* Bare UA mono on the page background reads as unfinished markup. */
:where(code) {
  background-color: var(--twe-bg-inset);
  border-radius: var(--twe-radius-xs);
  padding: var(--twe-space-1) var(--twe-space-2);
}
:where(pre) {
  background-color: var(--twe-bg-inset);
  border-radius: var(--twe-radius-xs);
  padding: var(--twe-space-3);
  overflow-x: auto;
  scrollbar-gutter: stable;
}
:where(pre) > :where(code) { background: none; padding: 0; }

/* MANDATORY on every numeric cell, metric readout, ID, coordinate, currency and
 * timestamp. Outfit has NO tabular figures, so a column of numbers set in it
 * will not align — digits jitter row to row, which on a geotech report table
 * looks like a data error rather than a font problem. */
/* Three spellings, one behaviour. `.num` is the short form the style guide and
 * the sync script teach, because it gets typed on hundreds of cells and brevity
 * decides whether it actually gets used. `.twe-num` is the prefixed alias for a
 * tool that already owns a `.num` class of its own — an unprefixed utility in a
 * VENDORED stylesheet is a real collision risk, and the alias costs nothing.
 * `[data-twe-num]` covers server-rendered markup where a template writes an
 * attribute more naturally than a class.
 *
 * print.css:223 already listed all three; without this rule two of them were
 * screen-mode no-ops that nonetheless grepped as real API — i.e. they taught
 * future agents a class that did nothing. Found during the v2.0.0 build. */
.num,
.twe-num,
[data-twe-num] {
  font-family: var(--twe-font-mono);
  font-variant-numeric: var(--twe-nums);
  letter-spacing: normal;           /* Outfit's tracking must not leak in */
}

/* ------------------------------------------------------------ 7. utilities --
 * clip-path, NOT display:none — display:none removes the element from the
 * accessibility tree, which defeats the whole purpose. Reveals on focus so
 * skip links work. */
.twe-visually-hidden:not(:focus):not(:active) {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------- 8. legacy tag salvage ----
 * The audit found these in hand-written and AI-generated fleet markup. They are
 * styled so old pages do not look broken, NOT so they stay in use: replace them
 * in markup (b -> strong, i -> em, center -> a flex/grid container, font -> a
 * class). Presentational attributes on <font> are UA hints and lose to these. */
:where(center) { display: block; text-align: center; }
:where(font) { font: inherit; color: inherit; }

/* ------------------------------------------------------------ 9. emphasis ---
 * The one scoped exception to font-synthesis:none, and it is an accessibility
 * call: with no 600/700 face vendored, <strong> and <em> would render pixel-
 * identical to body text — emphasis carried by nothing at all, failing WCAG
 * 1.3.1 and our own "never encode meaning in a single channel" rule. Synthetic
 * bold is ugly; invisible emphasis is broken. DELETE THIS BLOCK the day the
 * variable faces are vendored (tokens.css §0) — that is the real fix. */
:where(strong, b) { font-synthesis: weight; font-weight: 600; }
:where(em, i, cite, var, dfn) { font-synthesis: style; font-style: italic; }

/* ---------------------------------- 10. progressive enhancement (guarded) ---
 * Each block must upgrade something already complete above. If a control only
 * looks right inside one of these, it is a bug at the floor.
 *
 * Chromium 139+. Squircle corners — continuous curvature, the detail that
 * separates an Apple-looking radius from a CSS one. Pure polish: the pill
 * radius in §2 is the shipped look on the other four Chromium versions.
 *
 * NOTE: base.css intentionally has no @starting-style / transition-behavior
 * block. Both are safe at the floor (117+), but nothing in this layer enters or
 * leaves the page, so they belong to the sheets owning overlays, toasts and
 * popovers. A decorative use here would be dead code. */
@supports (corner-shape: superellipse(2)) {
  *::-webkit-scrollbar-thumb { corner-shape: superellipse(2); }
}
