/*  The one place the app's look is defined.
 *
 *  Served from /vendor/, which nginx already maps to deploy/web for every
 *  page -- the atlas, /field, /admin and /login have four different roots but
 *  one shared asset path, which is how Leaflet is already loaded.
 *
 *  WHY THE OLD TOKEN NAMES SURVIVE. The design ships its own palette as
 *  --a-bg, --a-surf, --a-ink and so on. Renaming every token would mean
 *  touching every rule in four files for no behavioural gain, so the design's
 *  VALUES are bound to the names the pages already use. A page picks up the
 *  new look without a single rule changing. The design's names are also
 *  defined, as aliases, so markup pasted from the prototypes works unedited.
 *
 *  WHY THE FONTS ARE VENDORED. Three reasons, in order of how much they cost:
 *
 *    1. They were not loading. field.html, admin.html and login.html named
 *       Archivo in --font-ui and never loaded it, so on any device without
 *       Archivo installed -- which is every phone -- they rendered in Segoe UI
 *       while the atlas, which did link Google Fonts, rendered in Archivo.
 *       One app, two typefaces, and nothing in the page said so.
 *    2. A field app should not need a third party reachable to draw its own
 *       text. This is the same decision as vendoring Leaflet, and for the same
 *       reason: a rep in a parking lot with no signal.
 *    3. A wrong CDN integrity hash silently blocked leaflet.css once and cost
 *       an afternoon. One console line was the only evidence.
 *
 *  109 KB for the whole typography system, cached 30 days by the /vendor/
 *  rules. The icon font is SUBSET to the 26 glyphs the designs actually use:
 *  6 KB instead of roughly 300 KB for the full variable font.
 */

/* ---------------------------------------------------------------- the fonts */

/*  One file for every weight 400-700: Google serves IBM Plex Sans as a
 *  variable font, and the four weights downloaded separately were byte for
 *  byte identical (sha256 e2291e84...). Declaring the range rather than four
 *  faces is the same bytes and one request.
 */
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-var.woff2') format('woff2');
}

/*  IBM Plex Mono is not variable, so it is four static faces. It carries
 *  every number in the app -- freight estimates, ETAs, distances, counts --
 *  because a figure that does not shift as the digits change is the
 *  difference between a column you can scan and one you cannot.
 */
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 400; font-display: swap; src: url('fonts/ibm-plex-mono-400.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 500; font-display: swap; src: url('fonts/ibm-plex-mono-500.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 600; font-display: swap; src: url('fonts/ibm-plex-mono-600.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 700; font-display: swap; src: url('fonts/ibm-plex-mono-700.woff2') format('woff2'); }

/* --------------------------------------------------------------- the tokens */

:root {
  --bg:#EDF0F3; --surface:#FFFFFF; --surface-2:#F5F7F9; --line:#D9DFE6;
  --fg:#0E1A2B; --fg-dim:#566376; --fg-faint:#637085;
  --accent:#1D5FB4; --accent-dim:#E2EBF7; --on-accent:#FFFFFF;
  --ok:#1C7550; --ok-dim:#DFF0E7;
  --warn:#93570A; --warn-dim:#FAEDD6;
  /*  Danger, which the design has no token for but three pages already
   *  use: a company a rep must NOT call on -- marked nofit, or asked not
   *  to be contacted again. Kept at the values the pages already had
   *  (7.8:1 light, 6.7:1 dark) because they were right; a working colour
   *  is not worth churning for consistency with a palette that omits it.
   */
  --stop:#A11B20; --stop-dim:#F7E2E2;
  /*  The design has ONE blue and uses it for both action and information.
   *  Keeping --info as a separate hue would reintroduce the two-blue problem
   *  the palette exists to remove, so it is bound to the accent. Anything
   *  that needs to read as "not a button" should differ by weight or fill,
   *  not by hue.
   */
  --info:#1D5FB4; --info-dim:#E2EBF7;
  /*  The map is a surface, not a brand colour: a grid that reads as paper
   *  under the pins rather than competing with them.
   */
  --map:#E3E8ED; --map-line:#D0D8E0; --road:#F4F6F8;
  --shadow:0 1px 2px rgba(16,24,32,.07), 0 1px 1px rgba(16,24,32,.04);
  --shadow-lift:0 4px 12px rgba(8,18,36,.15);
  --shadow-sheet:0 -8px 24px rgba(8,18,36,.12);
  --font-ui:'IBM Plex Sans',system-ui,-apple-system,'Segoe UI',sans-serif;
  --font-mono:'IBM Plex Mono',ui-monospace,Consolas,monospace;
  --safe-bottom:env(safe-area-inset-bottom, 0px);
  --safe-top:env(safe-area-inset-top, 0px);
}

/*  Three declarations, not one, and the order matters. The media query is
 *  guarded by :not([data-theme="light"]) so an explicit light choice beats
 *  the device preference, and the [data-theme="dark"] block repeats the
 *  values so an explicit dark choice works on a device set to light.
 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#0A111C; --surface:#111A28; --surface-2:#182335; --line:#243248;
    --fg:#E7EDF5; --fg-dim:#93A1B6; --fg-faint:#8191A8;
    --accent:#76AAF3; --accent-dim:#17304F; --on-accent:#06101D;
    --ok:#62C99A; --ok-dim:#10301F;
    --warn:#E6AA52; --warn-dim:#33240D;
    --stop:#F08080; --stop-dim:#35201F;
    --info:#76AAF3; --info-dim:#17304F;
    --map:#121C2A; --map-line:#1C293B; --road:#1E2A39;
    --shadow:0 1px 2px rgba(0,0,0,.4);
    --shadow-lift:0 4px 12px rgba(0,0,0,.45);
    --shadow-sheet:0 -8px 24px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg:#0A111C; --surface:#111A28; --surface-2:#182335; --line:#243248;
  --fg:#E7EDF5; --fg-dim:#93A1B6; --fg-faint:#8191A8;
  --accent:#76AAF3; --accent-dim:#17304F; --on-accent:#06101D;
  --ok:#62C99A; --ok-dim:#10301F;
  --warn:#E6AA52; --warn-dim:#33240D;
  --stop:#F08080; --stop-dim:#35201F;
  --info:#76AAF3; --info-dim:#17304F;
  --map:#121C2A; --map-line:#1C293B; --road:#1E2A39;
  --shadow:0 1px 2px rgba(0,0,0,.4);
  --shadow-lift:0 4px 12px rgba(0,0,0,.45);
  --shadow-sheet:0 -8px 24px rgba(0,0,0,.4);
  color-scheme: dark;
}

/*  The design's own names, so markup copied from the prototypes renders
 *  without being rewritten first. Aliases only -- the values above are the
 *  single source.
 */
:root {
  --a-bg:var(--bg); --a-surf:var(--surface); --a-surf2:var(--surface-2);
  --a-line:var(--line); --a-ink:var(--fg); --a-mut:var(--fg-dim);
  --a-acc:var(--accent); --a-accsoft:var(--accent-dim);
  --a-onacc:var(--on-accent);
  --a-good:var(--ok); --a-goodsoft:var(--ok-dim);
  --a-warn:var(--warn); --a-warnsoft:var(--warn-dim);
  --a-map:var(--map); --a-mapline:var(--map-line);
}

/* --------------------------------------------------------- shared behaviour */

/*  An author rule -- including one inside a media query -- outranks the
 *  hidden attribute, whose only power is display:none from the user-agent
 *  sheet. That cost an afternoon once: a fixed full-viewport backdrop kept
 *  display:block in a compact block, sat at z-index 40 over every phone, and
 *  ate every tap while the page looked completely correct. This rule is why
 *  it cannot happen again, and tests fail if a new display escapes it.
 */
[hidden] { display:none !important; }


/* --------------------------------------------------------- the page shell */
/*  The header every section page wears: the wordmark, the desktop section
 *  row, and the column the page's content sits in.
 *
 *  Five pages carried their own copy of these five rules and they had already
 *  drifted -- admin's wordmark had lost its letter-spacing, the page title was
 *  19px on two pages and 28px on two others, and the subtitle came in four
 *  sizes. None of that was decided; it is what copying a block does. The
 *  28px/-.02em title and the 14px subtitle are the design's.
 *
 *  Scoped to `body[data-tab]`, which is exactly the set of pages that have a
 *  section: the login page shares this stylesheet, has no navigation and must
 *  keep its own, larger, centred title.
 */
body[data-tab] .shell {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-top);
}
body[data-tab] .shell-in {
  max-width: 1120px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
body[data-tab] .brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.01em;
}
body[data-tab] .brand span { color: var(--accent); }

body[data-tab] .wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px;
}
/*  Prose, not a workspace: a column of explanation set to a readable measure
 *  rather than stretched across a desktop. */
body[data-tab] .wrap.narrow { max-width: 720px; }

body[data-tab] h1 {
  margin: 4px 0 6px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.02em;
}
body[data-tab] .sub {
  margin: 0 0 16px;
  color: var(--fg-dim);
  font-size: 14px;
}
