/* FareSentry — the one stylesheet, and the one palette.
   ===========================================================================
   LIGHT IS THE DEFAULT (owner, 2026-10-12: "make the color to be like the
   nftc.digital not dark mode always so its whitemode by default but user can
   do dark mode"). The temperament is nftc.digital's: a soft grey page, white
   surfaces, hairline borders, dark text, colour reserved for state. FareSentry
   keeps its own identity — transit yellow #F2A900 is still the single accent,
   and ink navy #16212E is now the TEXT colour instead of the background.

   HOW THEMING WORKS
   -----------------
   1. Bare `:root` holds the COMPLETE palette — the LIGHT set. Nothing below
      this block may contain a literal colour; every rule reads a token.
   2. `:root[data-theme="dark"]` redefines ONLY the tokens, to the values the
      app shipped with, so yesterday's dark console is still available verbatim.
   3. A visitor who has never chosen gets their OS preference via
      `@media (prefers-color-scheme: dark)`, guarded with
      `:not([data-theme="light"])` so an explicit "light" always wins.
   4. No attribute + no OS preference = LIGHT.

   The attribute is written by includes/partials/theme_toggle.php (an inline
   pre-paint bootstrap) and assets/theme.js (persist + toggle). Absent
   attribute means "the user has not chosen" — that state is deliberate.

   WHY SEMANTIC NAMES. The old names (--navy, --navy-raised) described a colour,
   not a job, and would read as a lie the moment --navy became #F1F3F6. Each
   token below names the ROLE, so both themes can tell the truth.

   A state family is three tokens: `--x` is the INK, `--x-tint` the ground it
   sits on, `--x-edge` its border. The inks are re-picked per theme because a
   hue tuned for navy is unreadable on paper-white and vice versa — every pair
   in here is measured at >=4.5:1 ink-on-its-own-tint (see the build report).
   =========================================================================== */

:root {
    color-scheme: light;

    /* --- structure ----------------------------------------------------- */
    --bg:             #F1F3F6;   /* the page ground */
    --surface:        #FFFFFF;   /* cards, topbar, tiles — raised above the page */
    --surface-sunken: #F5F7FA;   /* panels INSIDE a card; recessed, not raised */
    --surface-hover:  #EAEEF3;   /* hover ground for a neutral control */
    --field:          #FFFFFF;   /* text inputs, selects, textareas */
    --line:           #DCE2E9;   /* the default hairline */
    --line-soft:      #E7ECF1;   /* a quieter divider inside a panel */
    --line-strong:    #B9C4D0;   /* hover border, swatch ring */
    --line-faint:     #E2E7ED;   /* dashed placeholder cells */
    --thead-bg:       #F7F9FB;   /* table head ground (nftc's frozen-pane grey) */
    --shadow-card:    0 1px 3px rgba(22, 33, 46, .06);
    --shadow-pop:     0 6px 20px rgba(22, 33, 46, .16);
    --radius:         10px;

    /* --- text ---------------------------------------------------------- */
    --ink:     #16212E;          /* 16.3:1 on --surface */
    --ink-dim: #55657A;          /*  5.9:1 on --surface */

    /* --- the one accent ------------------------------------------------ */
    /* --accent and --on-accent are IDENTICAL in both themes: transit yellow is
       the brand, and ink navy on it measures 8.1:1 either way. Only the accent
       as TEXT has to move, because #F2A900 on white is 1.9:1 — unreadable. */
    --accent:           #F2A900;
    --on-accent:        #16212E;
    --accent-ink:       #8A5A00; /* accent used as text/link */
    --accent-tint:      #FFF3D6;
    --accent-edge:      #C08A1E; /* chip + alert trim */
    /* The accent at HAIRLINE scale — a 1px panel frame, a 3px rule, a 7px
       dot. #F2A900 is 1.9:1 on white, so a yellow frame on paper simply is
       not there; this is the same amber, dark enough to read. In DARK it
       stays solid #F2A900 — what those frames have always been, while
       --accent-edge goes translucent, because a pill's trim wants less
       weight on a tinted dark ground than a panel's frame does. */
    --accent-line:      #C08A1E;
    --accent-ring:      rgba(242, 169, 0, .55);  /* inset ring on a focus panel */
    --accent-hover-bg:  #FFF4DB;
    --wash-accent:      #FFF6E0; /* hover wash on a clickable cell */
    --row-accent:       #FFF8E6; /* "this row is open" table wash */
    --focus-ring:       #9A6600; /* 4.9:1 on white, 4.4:1 on the page ground */

    /* --- state: ok ----------------------------------------------------- */
    --ok:          #0E7A4E;
    --ok-tint:     #E4F6EC;
    --ok-edge:     #4E9E79;
    --ok-solid:    #0E7A4E;      /* a filled "go" button */
    --on-ok:       #FFFFFF;

    /* --- state: short / bad -------------------------------------------- */
    --bad:         #C4262F;
    --bad-tint:    #FDE9EA;
    --bad-edge:    #D4686E;
    --bad-soft:    #AE3238;      /* a list of row errors — quieter than --bad */
    --bad-hover-bg:#FDEDEE;
    --row-bad:     #FDF1F2;
    --silent-ink:  #9E4F55;      /* DEVICE_SILENT: a dead box, not a thief */

    /* --- state: info --------------------------------------------------- */
    --info:        #1668A8;
    --info-tint:   #E6F1FA;
    --info-edge:   #5B96C4;
    --row-info:    #F0F7FC;

    /* --- state: violet (Z variance, system notes) ---------------------- */
    --violet:      #6941C6;
    --violet-tint: #F0EAFC;
    --violet-edge: #9478D6;
    --wash-violet: #F5F1FD;

    /* --- state: hot (the gap ramp's middle rung) ----------------------- */
    --hot:         #AE5209;
    --hot-tint:    #FDEDDF;
    --hot-edge:    #C57B3C;

    /* --- state: dim (not judged / no data) ----------------------------- */
    --dim-tint:    #EDF0F4;

    /* A flat data swatch (legend chip, route dot, device colour) is a small
       block of pure hue with nothing to separate it from the page. On white
       it needs a hairline; on navy the hue already carries itself. */
    --swatch-ring: rgba(22, 33, 46, .22);

    /* --- chart series: one token per series, so the stroke can be
           re-picked per theme. A 2.25px #F2A900 line is 1.9:1 on white and
           simply vanishes; the light set below is all >=3.7:1. ---------- */
    --ser-tx:       #B07A00;
    --ser-pax:      #0E7A4E;
    --ser-cctv-in:  #1668A8;
    --ser-cctv-out: #6941C6;
    --ser-cctv-avg: #64727F;

    /* --- donut hues, cycled per route --------------------------------- */
    --rt-1: #B07A00;
    --rt-2: #0E7A4E;
    --rt-3: #1668A8;
    --rt-4: #6941C6;
    --rt-5: #AE5209;
    --rt-6: #9E4F55;

    /* --- Leaflet surfaces --------------------------------------------- */
    --map-ground:  #E6EAEF;      /* behind the tiles, before they load */
    --tile-filter: grayscale(.10) contrast(1.01);
    --pin-ring:    rgba(22, 33, 46, .30);   /* keeps a pale badge off pale tiles */
    --pin-shadow:  0 2px 8px rgba(22, 33, 46, .22);
    --overlay-bg:  rgba(255, 255, 255, .92);
    --float-bg:    rgba(255, 255, 255, .90); /* the pin's code label */
    --attrib-bg:   rgba(255, 255, 255, .84);
}

/* =========================== DARK ======================================= */
/* The values FareSentry shipped with, unchanged except where a chip was
   measurably unreadable: the state tints were semi-transparent washes of their
   own bright ink, which LIGHTENED the ground and dropped chip-bad to 3.6:1.
   They are now opaque dark grounds of the same hue — the pill still reads as
   "a dark chip with a coloured edge", and every ink clears 4.5:1 unchanged. */
:root[data-theme="dark"] {
    color-scheme: dark;

    --bg:             #16212E;
    --surface:        #1E2C3C;
    --surface-sunken: #16212E;
    --surface-hover:  #26374A;
    --field:          #16212E;
    --line:           #2C3C4F;
    --line-soft:      #263546;
    --line-strong:    #3C5168;
    --line-faint:     #26374A;
    --thead-bg:       transparent;
    --shadow-card:    none;
    --shadow-pop:     0 6px 20px rgba(0, 0, 0, .5);

    --ink:     #E8EDF2;
    --ink-dim: #9FB0C0;

    --accent:           #F2A900;
    --on-accent:        #16212E;
    --accent-ink:       #F2A900;
    --accent-tint:      #3A2B06;
    --accent-edge:      rgba(242, 169, 0, .5);
    --accent-line:      #F2A900;
    --accent-ring:      rgba(242, 169, 0, .25);
    --accent-hover-bg:  rgba(242, 169, 0, .12);
    --wash-accent:      rgba(242, 169, 0, .10);
    --row-accent:       rgba(242, 169, 0, .07);
    --focus-ring:       #F2A900;

    --ok:          #4CC38A;
    --ok-tint:     #123024;
    --ok-edge:     rgba(76, 195, 138, .45);
    --ok-solid:    #4CC38A;
    --on-ok:       #0C1A12;

    /* #F2555A, the red FareSentry shipped with, measures 4.20:1 as text on
       --surface — under the 4.5 floor for the cash-short figures, the Disable
       button and the calendar's SHORT line. Lifted by the smallest step that
       clears it (4.67:1 on the card, 5.21:1 on its own chip tint); the hue is
       unchanged and the two reds are indistinguishable side by side. */
    --bad:         #F4656A;
    --bad-tint:    #351B1E;
    --bad-edge:    rgba(242, 85, 90, .45);
    --bad-soft:    #F0A8AA;
    --bad-hover-bg:rgba(242, 85, 90, .12);
    --row-bad:     rgba(242, 85, 90, .07);
    --silent-ink:  #E0A3A5;

    --info:        #58A8E6;
    --info-tint:   #16303F;
    --info-edge:   rgba(88, 168, 230, .45);
    --row-info:    rgba(88, 168, 230, .06);

    --violet:      #A98BE8;
    --violet-tint: #2A2340;
    --violet-edge: rgba(169, 139, 232, .45);
    --wash-violet: rgba(169, 139, 232, .06);

    --hot:         #F0892D;
    --hot-tint:    #38240F;
    --hot-edge:    rgba(242, 131, 45, .5);

    --dim-tint:    #28333F;
    --swatch-ring: rgba(232, 237, 242, .30);

    --ser-tx:       #F2A900;
    --ser-pax:      #4CC38A;
    --ser-cctv-in:  #58A8E6;
    --ser-cctv-out: #A98BE8;
    --ser-cctv-avg: #9FB0C0;

    --rt-1: #F2A900;
    --rt-2: #4CC38A;
    --rt-3: #58A8E6;
    --rt-4: #A98BE8;
    --rt-5: #F0892D;
    --rt-6: #E0A3A5;

    --map-ground:  #16212E;
    --tile-filter: grayscale(.28) brightness(.9) contrast(1.03);
    --pin-ring:    rgba(232, 237, 242, .6);
    --pin-shadow:  0 2px 8px rgba(0, 0, 0, .5);
    --overlay-bg:  rgba(22, 33, 46, .86);
    --float-bg:    rgba(22, 33, 46, .82);
    --attrib-bg:   rgba(22, 33, 46, .78);
}

/* The OS preference, for a visitor who has never touched the toggle. The
   :not([data-theme="light"]) guard is what makes an explicit choice stick. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --bg:             #16212E;
        --surface:        #1E2C3C;
        --surface-sunken: #16212E;
        --surface-hover:  #26374A;
        --field:          #16212E;
        --line:           #2C3C4F;
        --line-soft:      #263546;
        --line-strong:    #3C5168;
        --line-faint:     #26374A;
        --thead-bg:       transparent;
        --shadow-card:    none;
        --shadow-pop:     0 6px 20px rgba(0, 0, 0, .5);

        --ink:     #E8EDF2;
        --ink-dim: #9FB0C0;

        --accent:           #F2A900;
        --on-accent:        #16212E;
        --accent-ink:       #F2A900;
        --accent-tint:      #3A2B06;
        --accent-edge:      rgba(242, 169, 0, .5);
        --accent-line:      #F2A900;
        --accent-ring:      rgba(242, 169, 0, .25);
        --accent-hover-bg:  rgba(242, 169, 0, .12);
        --wash-accent:      rgba(242, 169, 0, .10);
        --row-accent:       rgba(242, 169, 0, .07);
        --focus-ring:       #F2A900;

        --ok:          #4CC38A;
        --ok-tint:     #123024;
        --ok-edge:     rgba(76, 195, 138, .45);
        --ok-solid:    #4CC38A;
        --on-ok:       #0C1A12;

        /* #F2555A, the red FareSentry shipped with, measures 4.20:1 as text on
           --surface — under the 4.5 floor for the cash-short figures, the Disable
           button and the calendar's SHORT line. Lifted by the smallest step that
           clears it (4.67:1 on the card, 5.21:1 on its own chip tint); the hue is
           unchanged and the two reds are indistinguishable side by side. */
        --bad:         #F4656A;
        --bad-tint:    #351B1E;
        --bad-edge:    rgba(242, 85, 90, .45);
        --bad-soft:    #F0A8AA;
        --bad-hover-bg:rgba(242, 85, 90, .12);
        --row-bad:     rgba(242, 85, 90, .07);
        --silent-ink:  #E0A3A5;

        --info:        #58A8E6;
        --info-tint:   #16303F;
        --info-edge:   rgba(88, 168, 230, .45);
        --row-info:    rgba(88, 168, 230, .06);

        --violet:      #A98BE8;
        --violet-tint: #2A2340;
        --violet-edge: rgba(169, 139, 232, .45);
        --wash-violet: rgba(169, 139, 232, .06);

        --hot:         #F0892D;
        --hot-tint:    #38240F;
        --hot-edge:    rgba(242, 131, 45, .5);

        --dim-tint:    #28333F;
        --swatch-ring: rgba(232, 237, 242, .30);

        --ser-tx:       #F2A900;
        --ser-pax:      #4CC38A;
        --ser-cctv-in:  #58A8E6;
        --ser-cctv-out: #A98BE8;
        --ser-cctv-avg: #9FB0C0;

        --rt-1: #F2A900;
        --rt-2: #4CC38A;
        --rt-3: #58A8E6;
        --rt-4: #A98BE8;
        --rt-5: #F0892D;
        --rt-6: #E0A3A5;

        --map-ground:  #16212E;
        --tile-filter: grayscale(.28) brightness(.9) contrast(1.03);
        --pin-ring:    rgba(232, 237, 242, .6);
        --pin-shadow:  0 2px 8px rgba(0, 0, 0, .5);
        --overlay-bg:  rgba(22, 33, 46, .86);
        --float-bg:    rgba(22, 33, 46, .82);
        --attrib-bg:   rgba(22, 33, 46, .78);
    }
}

/* =================== base ============================================== */

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

/* One visible focus ring for the whole admin, in a colour measured against
   BOTH grounds (4.9:1 on white, 7.9:1 on the dark card). Keyboard only — a
   mouse click should not light up every control. */
a:focus-visible,
button:focus-visible,
summary:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .3px; }
.brand-mark { color: var(--accent); margin-right: 6px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.who { color: var(--ink-dim); font-size: 14px; }

.wrap { max-width: 860px; margin: 0 auto; padding: 32px 22px 56px; }

.hero { margin-bottom: 24px; }
.hero h1 { margin: 0 0 6px; font-size: 32px; }
.tagline { margin: 0; color: var(--ink-dim); }
.pill {
    font-size: 13px; font-weight: 600; color: var(--on-accent);
    background: var(--accent); padding: 2px 10px; border-radius: 999px;
    vertical-align: middle;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 20px 22px;
    margin-bottom: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 18px; }
.count {
    font-size: 13px; color: var(--on-accent); background: var(--accent);
    padding: 1px 9px; border-radius: 999px; margin-left: 6px;
}

.login-card { max-width: 400px; }
label { display: block; margin-bottom: 14px; font-size: 14px; color: var(--ink-dim); }
input[type=text], input[type=password] {
    display: block; width: 100%; margin-top: 6px;
    padding: 10px 12px; font-size: 15px;
    background: var(--field); color: var(--ink);
    border: 1px solid var(--line); border-radius: 8px;
}
input:focus { border-color: var(--accent); }

.btn {
    display: inline-block; cursor: pointer; font-size: 14px; font-weight: 600;
    padding: 10px 18px; border-radius: 8px; border: 1px solid transparent;
    text-decoration: none; transition: transform .12s ease-out, filter .12s ease-out;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; color: var(--ink-dim); border-color: var(--line); }
.btn-ghost:hover { color: var(--ink); }

.alert { padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.alert-error { background: var(--bad-tint); color: var(--bad); border: 1px solid var(--bad-edge); }

.status { font-weight: 600; margin: 0; }
.status-ok { color: var(--ok); }
.status-bad { color: var(--bad); }

.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--ink-dim); font-weight: 600; background: var(--thead-bg); }

.muted { color: var(--ink-dim); }
code { background: var(--surface-sunken); padding: 2px 6px; border-radius: 5px; color: var(--accent-ink); }

.foot {
    text-align: center; padding: 22px; color: var(--ink-dim);
    font-size: 13px; border-top: 1px solid var(--line);
}

@media (prefers-reduced-motion: reduce) {
    .btn { transition: none; }
}
/* Login: reveal toggle — a mistyped character is the commonest "it doesn't work". */
.pw-wrap{position:relative;display:block}
.pw-wrap input{width:100%;padding-right:86px}
.pw-eye{position:absolute;right:6px;top:50%;transform:translateY(-50%);background:transparent;
        border:1px solid var(--line);color:var(--ink-dim);font-size:12px;letter-spacing:.04em;
        padding:5px 10px;border-radius:6px;cursor:pointer}
.pw-eye:hover,.pw-eye:focus-visible{color:var(--accent-ink);border-color:var(--accent)}

/* =================== the theme toggle ================================== */
/* Rendered by includes/partials/theme_toggle.php. The LABEL is chosen in CSS,
   not JS, so it is already correct at first paint — a label that flips after
   hydration is the same bug as a flash of the wrong theme. */
/* The strip the toggle sits in on an ordinary admin screen: right-aligned,
   lined up with the nav's own 22px gutter. It collapses to NOTHING the moment
   includes/partials/admin_nav.php carries the toggle itself, because the
   partial renders at most once per request and :empty then hides the strip —
   so wiring the nav will never produce a second button or a stray gap. */
.fs-theme-bar {
    display: flex; justify-content: flex-end;
    padding: 10px 22px 0;
}
.fs-theme-bar:empty { display: none; }
/* map.php / timelapse.php: no page scroll, so the control lives in the
   sidebar head instead of a strip. */
.fs-theme-bar-inline { padding: 10px 0 0; }
@media (max-width: 720px) {
    .fs-theme-bar { padding: 8px 12px 0; }
}

/* index.php / login.php: the brand claims the slack so every control — the
   nav and the toggle — groups at the right edge. */
.topbar .brand { margin-right: auto; }

.fs-theme-toggle {
    display: inline-flex; align-items: center; gap: 7px;
    background: var(--surface); color: var(--ink-dim);
    border: 1px solid var(--line); border-radius: 999px;
    padding: 5px 13px; font: 600 12.5px/1.25 inherit; font-family: inherit;
    cursor: pointer; white-space: nowrap;
    transition: color .14s ease-out, border-color .14s ease-out;
}
.fs-theme-toggle:hover { color: var(--accent-ink); border-color: var(--accent); }

/* The label names the theme you are IN, so the button's accessible name and
   its aria-pressed state agree ("Itim na tema" + pressed = dark is on). The
   ACTION goes in the title, which theme.js keeps in step.
   Both labels occupy the SAME grid cell and are swapped with visibility: the
   cell is therefore always as wide as the wider label ("Itim na tema"), so the
   button does not change size when the theme does. A control that resizes on
   theme is a layout shift, and in index.php's flex topbar a 2px one drags
   every sibling with it. visibility:hidden is out of the accessibility tree,
   so the hidden label never reaches the accessible name either. */
.fs-theme-toggle .fs-theme-ico,
.fs-theme-toggle .fs-theme-lbl { display: inline-grid; justify-items: center; }
.fs-theme-toggle .fs-theme-ico > *,
.fs-theme-toggle .fs-theme-lbl > * { grid-area: 1 / 1; }
.fs-theme-toggle .fs-theme-ico { font-size: 13px; line-height: 1; }

.fs-theme-toggle .fs-lbl-dark,
.fs-theme-toggle .fs-ico-dark { visibility: hidden; }
:root[data-theme="dark"] .fs-theme-toggle .fs-lbl-light,
:root[data-theme="dark"] .fs-theme-toggle .fs-ico-light { visibility: hidden; }
:root[data-theme="dark"] .fs-theme-toggle .fs-lbl-dark,
:root[data-theme="dark"] .fs-theme-toggle .fs-ico-dark { visibility: visible; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .fs-theme-toggle .fs-lbl-light,
    :root:not([data-theme="light"]) .fs-theme-toggle .fs-ico-light { visibility: hidden; }
    :root:not([data-theme="light"]) .fs-theme-toggle .fs-lbl-dark,
    :root:not([data-theme="light"]) .fs-theme-toggle .fs-ico-dark { visibility: visible; }
}
@media (prefers-reduced-motion: reduce) {
    .fs-theme-toggle { transition: none; }
}

/* =================== the admin nav ===================================== */
/* includes/partials/admin_nav.php is owned by another workstream this round
   and still hardcodes the dark palette in its own <style> block, which the
   browser applies AFTER this file. These rules therefore carry one extra
   element (`body`) purely to win on specificity (0,2,1) vs (0,2,0) — the nav
   sits on every admin screen and would otherwise stay navy on a white page.
   When that file is released, move these declarations into it and delete this
   block; nothing else here depends on it. */
body .fsnav {
    background: var(--surface);
    border-bottom-color: var(--line);
    box-shadow: var(--shadow-card);
}
body .fsnav-brand { color: var(--ink); }
body .fsnav-brand span { color: var(--accent); }
body .fsnav-link { color: var(--ink-dim); }
body .fsnav-link:hover { color: var(--ink); background: var(--surface-hover); }
body .fsnav-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
body .fsnav-link.is-on { color: var(--on-accent); background: var(--accent); }
body .fsnav-who { color: var(--ink-dim); }
body .fsnav-out { color: var(--ink-dim); border-color: var(--line); }
body .fsnav-out:hover,
body .fsnav-out:focus-visible { color: var(--accent-ink); border-color: var(--accent); }
