/* ===========================================================================
   FareSentry — conductor PWA.
   Designed for ONE reader: a conductor standing in a moving jeepney, in
   tropical noon sun, holding a cheap Android in one hand.

   That reader dictates every choice here:
   - The dense, must-hit-first-time controls (the two stop lists) sit on NEAR
     WHITE with near-black ink — the highest contrast a phone can produce at
     full brightness. The chrome around them stays FareSentry navy.
   - Nothing interactive is under 48px; the primary targets are 56-68px with
     12px of slack between them, because the bus is moving.
   - Money is rendered once, enormous, in tabular figures, never in a sentence.
   - Two end actions only: CASH (green) and QR (yellow). No destructive action
     lives anywhere near them.
   - System fonts only, zero external assets: the app must paint instantly on
     2G and work with the radio off.
   =========================================================================== */

:root {
    --navy:        #16212E;
    --navy-raised: #1E2C3C;
    --navy-line:   #2C3C4F;
    --yellow:      #F2A900;
    --yellow-ink:  #16212E;
    --green:       #1C9E5A;
    --green-dark:  #157A45;
    --white:       #FFFFFF;
    --paper:       #F7F9FB;
    --paper-line:  #D8E0E8;
    --ink:         #10161D;
    --ink-dim:     #5B6B7B;
    --ink-on-navy: #E8EDF2;
    --dim-on-navy: #9FB0C0;
    --bad:         #D93A3F;
    --radius:      12px;
    --tap:         48px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--navy);
    color: var(--ink-on-navy);
    line-height: 1.35;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
}

b, strong { font-weight: 700; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* --- Banners ------------------------------------------------------------- */
.banner {
    position: sticky;
    top: 0;
    z-index: 40;
    padding: 10px 14px;
    font-size: 15px;
    text-align: center;
    letter-spacing: .2px;
}
.banner-offline { background: var(--yellow); color: var(--yellow-ink); }
.banner-stale   { background: var(--bad);    color: var(--white); }

/* --- Screens ------------------------------------------------------------- */
.screen { display: flex; flex-direction: column; min-height: 100%; }
.screen[hidden] { display: none; }

/* ===========================================================================
   SETUP
   =========================================================================== */
.screen-setup { max-width: 560px; margin: 0 auto; padding: 24px 18px 40px; width: 100%; }
.setup-head { margin-bottom: 18px; }
.brand { font-weight: 800; letter-spacing: .4px; font-size: 15px; color: var(--dim-on-navy); }
.brand-mark { color: var(--yellow); margin-right: 6px; }
.setup-head h1 { margin: 10px 0 4px; font-size: 26px; color: var(--white); }
.sub { margin: 0; color: var(--dim-on-navy); font-size: 15px; }

.card {
    background: var(--navy-raised);
    border: 1px solid var(--navy-line);
    border-radius: var(--radius);
    padding: 18px 16px;
    margin-bottom: 16px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; color: var(--white); }

.field { display: block; margin-bottom: 16px; border: 0; padding: 0; }
.field-label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .6px;
    text-transform: uppercase;
    color: var(--dim-on-navy);
    margin-bottom: 6px;
}
.field input, .select-lg {
    width: 100%;
    min-height: 52px;
    padding: 12px 14px;
    font-size: 17px;
    font-family: inherit;
    color: var(--ink);
    background: var(--white);
    border: 2px solid var(--paper-line);
    border-radius: 10px;
}
.field input:focus-visible, .select-lg:focus-visible, .btn:focus-visible, .stop:focus-visible, .cat:focus-visible {
    outline: 3px solid var(--yellow);
    outline-offset: 2px;
}
.hint { display: block; margin-top: 6px; font-size: 13px; color: var(--dim-on-navy); }
.link-btn {
    background: none; border: 0; padding: 0;
    color: var(--yellow); font: inherit; font-size: 13px;
    text-decoration: underline; cursor: pointer;
}
/* Two credential cards on the setup screen (SPEC-DEVICE-AUTH §6): the
   enrollment card is the one a conductor is meant to use, so it gets the
   yellow edge and the full-weight primary button; the legacy K1 card stays
   present and fillable (the pilot handsets + the airplane harness drive it)
   but is visibly demoted — dimmer border, dimmer ink, ghost button. */
.card-enroll { border-color: var(--yellow); }
/* Demoted by colour and weight, never by opacity: the inputs must stay crisp
   white and obviously usable — a pilot conductor still has to type into them. */
.card-legacy { background: transparent; border-style: dashed; }
.card-legacy h2 { color: var(--dim-on-navy); font-size: 15px; }
.card-legacy .field-label { color: var(--dim-on-navy); font-size: 12px; }
.card-legacy .field input { border-color: #B9C6D2; }
.card-note { margin: -6px 0 14px; color: var(--dim-on-navy); font-size: 13.5px; }
.tag-legacy {
    display: inline-block; margin-left: 6px; padding: 1px 8px;
    border: 1px solid var(--navy-line); border-radius: 999px;
    font-size: 11.5px; font-weight: 700; letter-spacing: .5px; color: var(--dim-on-navy);
}

.dir-choices { display: grid; gap: 10px; }
.dir-choice {
    display: flex; align-items: center; gap: 12px;
    min-height: var(--tap);
    padding: 12px 14px;
    background: var(--navy);
    border: 2px solid var(--navy-line);
    border-radius: 10px;
    font-size: 16px;
    cursor: pointer;
}
.dir-choice input { width: 22px; height: 22px; accent-color: var(--yellow); }
.dir-choice.is-on { border-color: var(--yellow); }

.msg { margin: 12px 0 0; font-size: 15px; min-height: 20px; }
.msg-bad { color: #FF9A9D; }
.msg-ok  { color: #7FE3AE; }
.foot-note { color: var(--dim-on-navy); font-size: 12.5px; margin: 4px 2px 0; }

/* ===========================================================================
   BUTTONS
   =========================================================================== */
.btn {
    min-height: var(--tap);
    padding: 12px 16px;
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: .3px;
    border: 2px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 140ms ease-out, opacity 140ms ease-out;
}
.btn:active { transform: scale(.985); }
.btn[disabled] { opacity: .42; cursor: not-allowed; }
.btn-lg { width: 100%; min-height: 60px; font-size: 18px; }
.btn-primary { background: var(--yellow); color: var(--yellow-ink); }
.btn-go      { background: var(--green);  color: var(--white); }
.btn-ghost   { background: transparent; color: var(--ink-on-navy); border-color: var(--navy-line); }

/* ===========================================================================
   TICKETING — header
   =========================================================================== */
.screen-ticket { height: 100%; }
.tbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    background: var(--navy-raised);
    border-bottom: 1px solid var(--navy-line);
}
.tbar-main { min-width: 0; flex: 1; }
.route-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.route-name {
    font-size: 16px; font-weight: 800; color: var(--white);
    margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.tbar-stats { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 9px;
    font-size: 12.5px;
    color: var(--dim-on-navy);
    background: var(--navy);
    border: 1px solid var(--navy-line);
    border-radius: 999px;
}
.chip b { color: var(--white); font-size: 13.5px; }
/* `display` on .chip beats the UA's [hidden] rule, so restate it — otherwise
   `el.hidden = true` silently does nothing (the house idiom, same as
   .screen[hidden] above). This is what hides "Magbukas ng Duty" once a duty
   is open, and the duty chip when there is none. */
.chip[hidden] { display: none; }
.chip-action {
    min-height: 34px; padding: 4px 12px; font: inherit; font-size: 13px; font-weight: 700;
    color: var(--yellow-ink); background: var(--yellow); border-color: var(--yellow); cursor: pointer;
}
.chip-net.is-off { color: var(--yellow-ink); background: var(--yellow); border-color: var(--yellow); }
.chip-pending.is-hot { color: var(--yellow); border-color: var(--yellow); }
.tbar-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.tbar-actions .btn { min-height: 44px; padding: 10px 12px; font-size: 14px; }

/* ===========================================================================
   TICKETING — the two stop columns (the part that must be perfect in sun)
   =========================================================================== */
.stops {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px;
    flex: 1 1 auto;
    min-height: 0;
}
.stopcol {
    display: flex; flex-direction: column; min-height: 0;
    background: var(--paper);
    border-radius: var(--radius);
    overflow: hidden;
}
.stopcol-head {
    padding: 8px 10px 6px;
    background: var(--white);
    border-bottom: 2px solid var(--paper-line);
}
.stopcol-title {
    display: block; font-size: 11.5px; font-weight: 800; letter-spacing: .8px;
    color: var(--ink-dim);
}
.stopcol-pick {
    display: block; font-size: 14px; font-weight: 800; color: var(--ink);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stoplist { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px; }
.stop {
    display: block;
    width: 100%;
    min-height: 56px;
    margin-bottom: 6px;
    padding: 8px 10px;
    text-align: left;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--ink);
    background: var(--white);
    border: 2px solid var(--paper-line);
    border-radius: 10px;
    cursor: pointer;
    transition: transform 120ms ease-out;
    /* Stop names are slash-joined compounds ("REYNA/PLAZA/H.SCHOOL") with no
       spaces to break at — let them wrap anywhere rather than clip. */
    overflow-wrap: anywhere;
}
.stop:active { transform: scale(.98); }
.stop .stop-km { display: block; margin-top: 3px; font-size: 11.5px; font-weight: 600; color: var(--ink-dim); }
.stop.is-on {
    background: var(--yellow);
    border-color: #C98C00;
    color: var(--yellow-ink);
}
.stop.is-on .stop-km { color: #5A4200; }
.stop[disabled] { opacity: .34; cursor: not-allowed; }

/* ===========================================================================
   TICKETING — dock: categories, qty, fare, actions
   =========================================================================== */
.dock {
    position: sticky; bottom: 0;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: var(--navy-raised);
    border-top: 1px solid var(--navy-line);
}
.cats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.cat {
    min-height: 56px;
    padding: 6px 2px;
    font-family: inherit;
    color: var(--ink-on-navy);
    background: var(--navy);
    border: 2px solid var(--navy-line);
    border-radius: 10px;
    cursor: pointer;
    transition: transform 120ms ease-out;
}
.cat:active { transform: scale(.97); }
.cat-code { display: block; font-size: 15px; font-weight: 800; letter-spacing: .4px; }
.cat-tl   { display: block; font-size: 10.5px; font-weight: 600; color: var(--dim-on-navy); margin-top: 2px; }
.cat.is-on { background: var(--yellow); border-color: var(--yellow); color: var(--yellow-ink); }
.cat.is-on .cat-tl { color: #5A4200; }

.dock-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.qty { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.qty-btn {
    width: 54px; height: 54px;
    font-family: inherit; font-size: 26px; font-weight: 700; line-height: 1;
    color: var(--ink-on-navy); background: var(--navy);
    border: 2px solid var(--navy-line); border-radius: 10px; cursor: pointer;
}
.qty-btn:active { transform: scale(.96); }
.qty-val { width: 54px; text-align: center; }
.qty-val span { display: block; font-size: 24px; font-weight: 800; color: var(--white); font-variant-numeric: tabular-nums; }
.qty-val small { display: block; font-size: 10.5px; color: var(--dim-on-navy); letter-spacing: .6px; }

.fare { flex: 1 1 auto; min-width: 0; text-align: right; }
.fare-amount {
    font-size: clamp(38px, 13vw, 58px);
    font-weight: 800;
    line-height: 1;
    letter-spacing: -1px;
    color: var(--yellow);
    font-variant-numeric: tabular-nums;
}
.fare-note { margin-top: 3px; font-size: 12.5px; color: var(--dim-on-navy); min-height: 16px; }
.fare-note.is-bad { color: #FF9A9D; }

.dock-actions { gap: 8px; }
.dock-actions .btn { flex: 1 1 50%; min-height: 68px; font-size: 22px; letter-spacing: 1px; }
.btn-cash { background: var(--green); color: var(--white); box-shadow: inset 0 -3px 0 var(--green-dark); }
.btn-qr   { background: var(--yellow); color: var(--yellow-ink); box-shadow: inset 0 -3px 0 #C98C00; }

/* ===========================================================================
   SUMMARY
   =========================================================================== */
.screen-summary { padding-bottom: 24px; }
.sum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; }
.sum-tile {
    background: var(--navy-raised); border: 1px solid var(--navy-line);
    border-radius: var(--radius); padding: 12px 14px;
}
.sum-tile-wide { grid-column: 1 / -1; }
.sum-k { display: block; font-size: 12px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--dim-on-navy); }
.sum-v { display: block; margin-top: 4px; font-size: 28px; font-weight: 800; color: var(--white); font-variant-numeric: tabular-nums; }
.sum-v-money { color: var(--yellow); font-size: 40px; letter-spacing: -1px; }
.screen-summary .card { margin: 0 10px 14px; }
.screen-summary .msg, .screen-summary .foot-note { margin-left: 12px; margin-right: 12px; }

.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th, .tbl td { padding: 9px 6px; border-bottom: 1px solid var(--navy-line); text-align: left; }
.tbl th { font-size: 12px; letter-spacing: .5px; text-transform: uppercase; color: var(--dim-on-navy); }
.tbl td { color: var(--white); }
.tbl .num, .tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ===========================================================================
   DUTY (docs/SPEC-DUTY.md §CLIENT-WIRING)

   Same reader, same rules: the three pickers are dense lists on NEAR WHITE
   (they must be hit first time, in sun, from a list of 22 buses and 67 crew),
   the PIN pad keys are 56px so a thumb cannot miss, and the one action that
   needs signal is the only one that can be disabled.
   =========================================================================== */
.chip-duty { max-width: 62vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-duty.is-on { color: var(--yellow); border-color: var(--yellow); }
/* FSGps status chip (js/fs-gps.js) — hidden with no duty; red text only when
   tracking is actually broken (permission denied or device unauthorized),
   so a conductor's eye is drawn to it exactly when it needs fixing. */
.chip-gps { max-width: 62vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-gps.is-bad { color: var(--white); background: var(--bad); border-color: var(--bad); }

.screen-duty { padding-bottom: 24px; }
.duty-body { padding: 10px; }
.screen-duty .card { margin-bottom: 12px; }
.screen-duty .card h2 { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.pick-val {
    font-size: 14px; font-weight: 800; color: var(--yellow);
    text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%;
}

.pick-search {
    width: 100%; min-height: 50px; margin-bottom: 8px;
    padding: 10px 12px; font-size: 16px; font-family: inherit;
    color: var(--ink); background: var(--white);
    border: 2px solid var(--paper-line); border-radius: 10px;
}
.pick-search:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* A bounded, scrollable list: the roster is long, the screen is not. */
.picklist {
    max-height: 208px; overflow-y: auto; -webkit-overflow-scrolling: touch;
    background: var(--paper); border-radius: 10px; padding: 6px;
}
.pick {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    width: 100%; min-height: 50px; margin-bottom: 6px; padding: 8px 10px;
    text-align: left; font-family: inherit; font-size: 15px; font-weight: 700; line-height: 1.2;
    color: var(--ink); background: var(--white);
    border: 2px solid var(--paper-line); border-radius: 10px; cursor: pointer;
    transition: transform 120ms ease-out;
    overflow-wrap: anywhere;
}
.pick:active { transform: scale(.985); }
.pick.is-on { background: var(--yellow); border-color: #C98C00; color: var(--yellow-ink); }
.pick-main { min-width: 0; }
.pick-note { flex: 0 0 auto; font-size: 11.5px; font-weight: 600; color: var(--ink-dim); }
.pick.is-on .pick-note { color: #5A4200; }
.picklist .card-note { margin: 6px 8px; color: var(--ink-dim); }

.pin-dots {
    margin-bottom: 10px; padding: 10px;
    text-align: center; font-size: 26px; letter-spacing: 4px; line-height: 1;
    color: var(--yellow); background: var(--navy);
    border: 1px solid var(--navy-line); border-radius: 10px;
}
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pinkey {
    min-height: 56px; font-family: inherit; font-size: 24px; font-weight: 800;
    color: var(--ink-on-navy); background: var(--navy);
    border: 2px solid var(--navy-line); border-radius: 10px; cursor: pointer;
    transition: transform 120ms ease-out;
}
.pinkey:active { transform: scale(.96); }
.pinkey:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.pinkey-alt { font-size: 18px; color: var(--dim-on-navy); }

.duty-actions { display: grid; gap: 8px; }

/* Duty panel on the summary screen. */
.card-duty { border-color: var(--yellow); }
.sum-grid-tight { padding: 0; margin-bottom: 12px; }
.tbl td.is-diff { color: var(--yellow); font-weight: 800; }
#dutyZPanel h2 { margin: 14px 0 8px; font-size: 15px; color: var(--white); }

/* ===========================================================================
   ISSUE FLASH + QR SHEET
   =========================================================================== */

/* The flash is anchored at the TOP on purpose: the conductor's thumb and the
   two end actions (CASH / QR) own the bottom of the screen, and a confirmation
   that covers the next sale's button for 2.6s costs more than one that briefly
   covers the route header. */
.toast {
    position: fixed; left: 10px; right: 10px; top: 10px;
    z-index: 60;
    padding: 14px 16px;
    background: var(--green);
    color: var(--white);
    border-radius: var(--radius);
    box-shadow: 0 14px 34px rgba(0, 0, 0, .45);
    animation: toast-in 180ms ease-out;
}
.toast[hidden] { display: none; }
.toast-head { display: flex; justify-content: space-between; align-items: baseline; }
.toast-title { font-size: 13px; font-weight: 800; letter-spacing: 1.2px; }
.toast-seq { font-size: 12px; opacity: .85; font-variant-numeric: tabular-nums; }
.toast-fare { font-size: 40px; font-weight: 800; line-height: 1.05; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
.toast-line { font-size: 13.5px; opacity: .95; }
.toast-day { margin-top: 4px; font-size: 12.5px; opacity: .9; }
.toast.is-bad { background: var(--bad); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.sheet {
    position: fixed; inset: 0; z-index: 70;
    display: flex; align-items: flex-end; justify-content: center;
    background: rgba(8, 12, 17, .72);
}
.sheet[hidden] { display: none; }
.sheet-inner {
    width: 100%; max-width: 520px;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    background: var(--navy-raised);
    border-radius: 16px 16px 0 0;
    border-top: 3px solid var(--yellow);
    animation: sheet-in 200ms ease-out;
    max-height: 92vh; overflow-y: auto;
}
.sheet-inner h2 { margin: 0 0 12px; font-size: 16px; color: var(--white); letter-spacing: .4px; }
/* Real scannable QR (vendored encoder, js/vendor/qrcode.js). Width is a
   viewport fraction, not a fixed px box, so it always reads >=60% of the
   screen width on a phone (SPEC-TICKET-SYNC §4 "QR render"); the SVG itself
   is `scalable:true` (no fixed width/height attrs) so it fills this box
   exactly via CSS. Square via aspect-ratio regardless of viewport width. */
.qr-box {
    width: 66vw; max-width: 66vw; aspect-ratio: 1 / 1;
    margin: 0 auto 12px;
    display: flex; align-items: center; justify-content: center;
    background: var(--white); border-radius: 10px; padding: 10px;
}
.qr-box svg { width: 100%; height: 100%; display: block; }
.qr-box.qr-box-error {
    color: var(--bad); font-size: 13px; font-weight: 700; text-align: center;
    letter-spacing: .3px; padding: 16px;
}
.qr-ph { color: var(--ink-dim); font-size: 13px; font-weight: 700; text-align: center; letter-spacing: .5px; }
.qr-fare { text-align: center; font-size: 34px; font-weight: 800; color: var(--yellow); font-variant-numeric: tabular-nums; }
.qr-line { text-align: center; font-size: 13.5px; color: var(--dim-on-navy); margin-bottom: 10px; }
.qr-payload {
    margin: 0 0 14px;
    padding: 10px;
    font-size: 10.5px;
    line-height: 1.45;
    word-break: break-all;
    white-space: pre-wrap;
    color: var(--ink-on-navy);
    background: var(--navy);
    border: 1px solid var(--navy-line);
    border-radius: 8px;
}

@keyframes sheet-in {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fatal {
    margin: 18px; padding: 16px;
    background: var(--bad); color: var(--white);
    border-radius: var(--radius); font-size: 16px; font-weight: 600;
}
.fatal[hidden] { display: none; }

/* --- Respect the user's motion preference (house rule). ------------------ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* --- Landscape / tablet: let the lists breathe, keep the dock reachable. - */
@media (min-width: 680px) {
    .stops { gap: 12px; padding: 12px; }
    .stop { min-height: 60px; font-size: 16px; }
    .dock { padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
    .sum-grid { grid-template-columns: repeat(4, 1fr); }
    .sum-tile-wide { grid-column: span 2; }
    /* Tablet: the duty pickers can show twice the roster at a glance. */
    .picklist { max-height: 300px; }
    .duty-body { max-width: 760px; margin: 0 auto; }
    /* Past the phone breakpoint the >=60vw rule no longer applies — cap the
       QR so it does not dominate a tablet-width sheet. */
    .qr-box { width: min(66vw, 320px); max-width: min(66vw, 320px); }
}
