/* =====================================================================
   ui.css - Artery's shared design foundations (premium redesign, v4.65+)
   Loaded FIRST by every page, before the page's own stylesheet, so a
   page's existing rules still win. Stage 1 only adds the typeface and the
   tokens below; later stages build the shared components on them.
   Plan: docs/premium-redesign/PREMIUM-REDESIGN-PLAN.md
   ===================================================================== */

/* ---- Typeface: Atkinson Hyperlegible Next, our own copy (SIL OFL 1.1,
   licence in atkinson-next-OFL.txt). Made by the Braille Institute for
   readers with low vision: letters that are hard to mix up (I l 1, O 0). */
@font-face { font-family: 'Atkinson Hyperlegible Next'; font-style: normal; font-weight: 400; font-display: swap; src: url('atkinson-next-400.woff2') format('woff2'); }
@font-face { font-family: 'Atkinson Hyperlegible Next'; font-style: normal; font-weight: 500; font-display: swap; src: url('atkinson-next-500.woff2') format('woff2'); }
@font-face { font-family: 'Atkinson Hyperlegible Next'; font-style: normal; font-weight: 600; font-display: swap; src: url('atkinson-next-600.woff2') format('woff2'); }
@font-face { font-family: 'Atkinson Hyperlegible Next'; font-style: normal; font-weight: 700; font-display: swap; src: url('atkinson-next-700.woff2') format('woff2'); }
@font-face { font-family: 'Atkinson Hyperlegible Next'; font-style: normal; font-weight: 800; font-display: swap; src: url('atkinson-next-800.woff2') format('woff2'); }

/* Stage 1 bridge: hundreds of existing rules (and some inline styles drawn by
   the scripts) still name 'Inter', which used to come from Google Fonts. The
   same files are registered under that name too, so every one of them gets
   the new typeface without touching each rule, and nothing is fetched from
   Google. Later stages move rules over to var(--ui-font); remove this block
   only when no rule names 'Inter' any more. */
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url('atkinson-next-400.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 500; font-display: swap; src: url('atkinson-next-500.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap; src: url('atkinson-next-600.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap; src: url('atkinson-next-700.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 800; font-display: swap; src: url('atkinson-next-800.woff2') format('woff2'); }

/* ---- Tokens: light (the default) ---- */
:root {
    --ui-font: 'Atkinson Hyperlegible Next', system-ui, 'Segoe UI', Roboto, sans-serif;

    --ui-ground: #F3F6FA;        /* page background */
    --ui-surface: #FFFFFF;       /* cards, panels, bars */
    --ui-surface-2: #F8FAFC;     /* card footers, table stripes */
    --ui-ink: #0A1830;           /* text, title bar, strong marks */
    --ui-muted: #4A5A75;         /* secondary text */
    --ui-line: #DCE3ED;          /* borders */
    --ui-line-strong: #C9D3E1;   /* button outlines, dividers that must show */
    --ui-action: #1B4F9C;        /* primary buttons, links, selection */
    --ui-on-action: #FFFFFF;     /* text on --ui-action */
    --ui-action-tint: #E8F0FB;   /* selected nav item, info pills */
    --ui-go: #0E7A45;            /* "do this now" confirm actions, free status */
    --ui-on-go: #FFFFFF;         /* text on --ui-go */
    --ui-go-tint: #E3F4EA;
    --ui-wait: #D98200;          /* waiting on a human: marks */
    --ui-wait-text: #7A4100;     /* waiting on a human: text */
    --ui-wait-tint: #FFF1D6;
    --ui-alert: #C4122F;         /* urgent, late, SOS. Nothing else is red */
    --ui-alert-tint: #FCE8EB;
    --ui-sos: #D61F3A;           /* SOS fill, the same in both themes */
    --ui-on-sos: #FFFFFF;
    --ui-brand: #85221E;         /* the logo mark only */

    /* spacing */
    --ui-s1: 4px; --ui-s2: 8px; --ui-s3: 12px; --ui-s4: 16px; --ui-s5: 24px; --ui-s6: 32px;
    /* radius */
    --ui-r-sm: 8px; --ui-r: 12px; --ui-r-lg: 16px; --ui-r-pill: 999px;
    /* elevation */
    --ui-e1: 0 1px 2px rgba(10, 24, 48, .06);
    --ui-e2: 0 8px 22px rgba(10, 24, 48, .08);
    --ui-e3: 0 16px 40px rgba(10, 24, 48, .16);
    /* type scale, in rem so the text-size options scale everything */
    --ui-t12: .75rem; --ui-t13: .8125rem; --ui-t14: .875rem; --ui-t16: 1rem;
    --ui-t18: 1.125rem; --ui-t20: 1.25rem; --ui-t24: 1.5rem; --ui-t28: 1.75rem;
    /* layers, named once. The alarm layer is always the highest. */
    --ui-z-base: 1; --ui-z-sticky: 100; --ui-z-box: 1000; --ui-z-modal: 5000;
    --ui-z-toast: 8000; --ui-z-alarm: 10000;
    /* motion */
    --ui-fast: 150ms; --ui-slide: 220ms; --ui-ease: cubic-bezier(.2, .7, .2, 1);
}

/* ---- Tokens: dark (the portal at night; the consoles' dark option) ---- */
:root[data-theme="dark"] {
    --ui-ground: #0B1120;
    --ui-surface: #111B2E;
    --ui-surface-2: #16223A;
    --ui-ink: #EAF0F8;
    --ui-muted: #A3B3CC;
    --ui-line: #24344F;
    --ui-line-strong: #34486A;
    --ui-action: #6FA8F5;
    --ui-on-action: #0A1830;
    --ui-action-tint: #16294A;
    --ui-go: #35C27A;
    --ui-on-go: #0A1830;
    --ui-go-tint: #12301F;
    --ui-wait: #F5B93E;
    --ui-wait-text: #F5B93E;
    --ui-wait-tint: #33260C;
    --ui-alert: #FF5468;
    --ui-alert-tint: #3A1620;
    --ui-e1: 0 1px 2px rgba(0, 0, 0, .35);
    --ui-e2: 0 8px 22px rgba(0, 0, 0, .40);
    --ui-e3: 0 16px 40px rgba(0, 0, 0, .55);
    color-scheme: dark;
}

/* Icons from icons.js / icons.svg: solid drawings in the text's own colour.
   (Stage 2: the set is filled shapes, so no stroke; a stroke would fatten them.) */
.ui-icon { display: inline-block; flex: none; vertical-align: -0.2em; width: 20px; height: 20px;
    fill: currentColor; stroke: none; overflow: visible; }
.ui-icon-16 { width: 16px; height: 16px; }
.ui-icon-20 { width: 20px; height: 20px; }
.ui-icon-24 { width: 24px; height: 24px; }
.ui-icon-32 { width: 32px; height: 32px; }
/* The size of the words around it: replaces an emoji or Font Awesome glyph in a line. */
.ui-icon-t { width: 1.2em; height: 1.2em; vertical-align: -0.24em; }
/* Tones, for icons whose colour means something (an emoji's own colour did that before).
   Each shade passes 3:1 as a graphic on white and on the dark navy grounds. */
.ui-tone-alert { color: #E0313F; }
.ui-tone-go    { color: #1F9D57; }
.ui-tone-wait  { color: #C97A00; }
.ui-tone-info  { color: #2F74D0; }
.ui-tone-muted { opacity: .7; }
/* A turning icon for "loading" (the refresh drawing; replaced Font Awesome's spinner). */
.ui-spin { animation: ui-spin 1s linear infinite; transform-origin: 50% 50%; }
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* v4.66: the consoles' View -> Text size (textsize.js). Magnifies the whole page,
   like the portal's Account -> Text size, because most console sizes are fixed
   pixels. (The portal uses its own data-text attribute; this one is data-ctext.) */
html[data-ctext="large"] body { zoom: 1.125; }
html[data-ctext="xl"] body { zoom: 1.25; }
/* --ui-z is the same magnification. Anything sized by the screen (vh) inside a
   magnified page is magnified too and would spill off the bottom, so the
   consoles write those as calc(90vh / var(--ui-z, 1)): the same share of the
   screen at every text size. */
:root { --ui-z: 1; }
html[data-ctext="large"] { --ui-z: 1.125; }
html[data-ctext="xl"] { --ui-z: 1.25; }
.ctext-row { display: flex; align-items: center; gap: 6px; }
.ctext-row button[aria-pressed="true"] { outline: 2px solid currentColor; outline-offset: 1px; font-weight: 800; }

/* Numbers that line up: job numbers, times, counts. */
.ui-nums { font-variant-numeric: tabular-nums; }

/* =====================================================================
   Shared components (redesign stage 2, plan 5.4). One definition each.
   Nothing old uses these yet: each screen moves onto them as it is
   restyled in stages 3 to 6. All colours and sizes come from the tokens.
   ===================================================================== */

/* ---- Buttons: Primary, Confirm, Secondary, Quiet, Danger (+ SOS fill) ---- */
.ui-btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--ui-s2);
    min-height: 36px; padding: 0 var(--ui-s4); border-radius: var(--ui-r-sm);
    border: 1px solid transparent; font: inherit; font-weight: 700; line-height: 1.2;
    cursor: pointer; text-decoration: none; white-space: nowrap; user-select: none;
    transition: background-color var(--ui-fast) var(--ui-ease), border-color var(--ui-fast) var(--ui-ease),
                transform 80ms var(--ui-ease), box-shadow var(--ui-fast) var(--ui-ease); }
.ui-btn:active:not(:disabled) { transform: scale(.98); }
.ui-btn:focus-visible { outline: 2px solid var(--ui-action); outline-offset: 2px; }
.ui-btn:disabled, .ui-btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.ui-btn-primary   { background: var(--ui-action); color: var(--ui-on-action); }
.ui-btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.ui-btn-confirm   { background: var(--ui-go); color: var(--ui-on-go); }
.ui-btn-confirm:hover:not(:disabled) { filter: brightness(1.08); }
.ui-btn-secondary { background: var(--ui-surface); color: var(--ui-ink); border-color: var(--ui-line-strong); }
.ui-btn-secondary:hover:not(:disabled) { background: var(--ui-surface-2); }
.ui-btn-quiet     { background: transparent; color: var(--ui-action); padding: 0 var(--ui-s2); }
.ui-btn-quiet:hover:not(:disabled) { background: var(--ui-action-tint); }
.ui-btn-danger    { background: var(--ui-surface); color: var(--ui-alert); border-color: var(--ui-alert); }
.ui-btn-danger:hover:not(:disabled) { background: var(--ui-alert-tint); }
/* Filled red is kept for SOS and Stand down only. */
.ui-btn-sos       { background: var(--ui-sos); color: #FFFFFF; }
/* Heights: 40 console toolbar, 48 anything touched on a phone, 56 portal main action. */
.ui-btn-bar  { min-height: 40px; }
.ui-btn-tap  { min-height: 48px; }
.ui-btn-main { min-height: 56px; font-size: 1.1em; width: 100%; }
/* Icon-only button (always give it an aria-label). */
.ui-btn-icon { padding: 0; width: 36px; min-width: 36px; }
.ui-btn-icon.ui-btn-tap { width: 48px; min-width: 48px; }

/* ---- Pills: one shape, five tones. Text plus colour, never colour alone. ---- */
.ui-pill { display: inline-flex; align-items: center; gap: var(--ui-s1); padding: 2px 10px;
    border-radius: var(--ui-r-pill); font-size: .85em; font-weight: 700; line-height: 1.5;
    background: var(--ui-surface-2); color: var(--ui-muted); border: 1px solid var(--ui-line);
    white-space: nowrap; transition: background-color var(--ui-fast) var(--ui-ease), color var(--ui-fast) var(--ui-ease); }
.ui-pill-info  { background: var(--ui-action-tint); color: var(--ui-action); border-color: transparent; }
.ui-pill-go    { background: var(--ui-go-tint); color: var(--ui-go); border-color: transparent; }
.ui-pill-wait  { background: var(--ui-wait-tint); color: var(--ui-wait-text); border-color: transparent; }
.ui-pill-alert { background: var(--ui-alert-tint); color: var(--ui-alert); border-color: transparent; }

/* ---- Cards and panels ---- */
.ui-card { background: var(--ui-surface); color: var(--ui-ink); border: 1px solid var(--ui-line);
    border-radius: 14px; box-shadow: var(--ui-e1); padding: var(--ui-s4); }
.ui-card-attn  { box-shadow: var(--ui-e2); }        /* the one thing that needs attention */
.ui-card-float { box-shadow: var(--ui-e3); }        /* anything floating over the map */
.ui-card-foot { background: var(--ui-surface-2); border-top: 1px solid var(--ui-line);
    margin: var(--ui-s4) calc(-1 * var(--ui-s4)) calc(-1 * var(--ui-s4)); padding: var(--ui-s3) var(--ui-s4);
    border-radius: 0 0 14px 14px; }

/* ---- Forms: label above the box, error under it ---- */
.ui-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--ui-s4); }
.ui-field > label, .ui-label { font-weight: 700; color: var(--ui-ink); }
.ui-hint { color: var(--ui-muted); font-size: .9em; }
.ui-input, .ui-select, .ui-textarea { min-height: 44px; padding: 10px 12px; font: inherit;
    color: var(--ui-ink); background: var(--ui-surface); border: 1px solid var(--ui-line-strong);
    border-radius: var(--ui-r-sm); width: 100%; box-sizing: border-box; }
.ui-textarea { min-height: 88px; resize: vertical; }
.ui-input:focus-visible, .ui-select:focus-visible, .ui-textarea:focus-visible {
    outline: 2px solid var(--ui-action); outline-offset: 1px; border-color: var(--ui-action); }
.ui-field.has-error .ui-input, .ui-field.has-error .ui-select, .ui-field.has-error .ui-textarea { border-color: var(--ui-alert); }
.ui-error { color: var(--ui-alert); font-weight: 700; font-size: .9em; }
.ui-portal .ui-input, .ui-portal .ui-select { min-height: 48px; }

/* ---- Window header (boxes and modals): title left, pin / pop out / close right ---- */
.ui-winhead { display: flex; align-items: center; gap: var(--ui-s2); padding: var(--ui-s3) var(--ui-s4);
    border-bottom: 1px solid var(--ui-line); }
.ui-winhead-title { flex: 1; min-width: 0; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-winhead-tools { display: flex; gap: var(--ui-s1); }

/* ---- Empty state: one line saying what is not here, and the button that fixes it ---- */
.ui-empty { display: flex; flex-direction: column; align-items: center; gap: var(--ui-s3);
    padding: var(--ui-s5) var(--ui-s4); color: var(--ui-muted); text-align: center; }
.ui-empty .ui-icon { width: 32px; height: 32px; opacity: .6; }

/* ---- Skeleton rows while the first data load is in flight ---- */
.ui-skel { display: block; height: 14px; margin: 10px 0; border-radius: var(--ui-r-sm);
    background: linear-gradient(90deg, var(--ui-surface-2) 25%, var(--ui-line) 50%, var(--ui-surface-2) 75%);
    background-size: 200% 100%; animation: ui-skel 1.2s linear infinite; }
.ui-skel-w60 { width: 60%; } .ui-skel-w80 { width: 80%; }
@keyframes ui-skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
    :root { --ui-fast: 0ms; --ui-slide: 0ms; }
    .ui-skel { animation: none; }
    .ui-spin { animation-duration: 3s; }   /* still shows it is busy, much more gently */
    .ui-btn:active:not(:disabled) { transform: none; }
}
