/*
 * ╔══════════════════════════════════════════════════════════════════════╗
 * ║ File:    public/css/patrol.css                                       ║
 * ║ Purpose: Styles for the patrol screens (phone / iPad). Plain CSS,    ║
 * ║          no build step.                                              ║
 * ║ Design:  BIG writing, few choices, high contrast, dark by default    ║
 * ║          for evening use (light theme via the header toggle),        ║
 * ║          finger-sized buttons. "Easy for every patroller."           ║
 * ║ Main parts: theme colours, page layout + header, rows, buttons,      ║
 * ║          chips, full-screen sheets, number pad, fuel gauge, banners. ║
 * ║ Fit rule (2026-11-22): no screen should need scrolling on a small    ║
 * ║          phone. The base text size follows the screen height, labels ║
 * ║          are small, and everything you tap stays finger-sized.       ║
 * ║ Last updated: 2026-11-22                                             ║
 * ╚══════════════════════════════════════════════════════════════════════╝
 */

/* ── Theme colours: dark is the default; [data-theme=light] overrides ── */
:root {
    --bg: #0e141b;
    --panel: #19222d;
    --panel-2: #223040;
    --line: #34465a;
    --text: #f4f7fb;
    --muted: #a9b8c9;
    --accent: #ffd23f;        /* high-visibility yellow */
    --accent-text: #1a1400;
    --good: #46d17a;
    --bad: #ff6b6b;
    --warn: #ffb347;
    --radius: 18px;
    color-scheme: dark;
}
:root[data-theme="light"] {
    --bg: #f2f5f9;
    --panel: #ffffff;
    --panel-2: #e6edf5;
    --line: #b9c6d6;
    --text: #0d1722;
    --muted: #4a5b6f;
    --accent: #ffcc00;
    --accent-text: #1a1400;
    --good: #12823f;
    --bad: #c0262d;
    --warn: #a35d00;
    color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[x-cloak] { display: none !important; }
/* The base text size follows the screen height: 22px on a tall screen, down to 16px on a short one, so the same
   screens fit a small phone and a big one. (Everything sized in rem scales with it.) Labels are small; anything
   you tap (buttons, rows, fields, list items) stays a comfortable finger size. */
html { font-size: clamp(15px, min(2.7vh, 5vw), 20px); }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.3; min-height: 100vh;
}

/* ── Page layout ── */
/* Slim header: it scrolls away with the page (not stuck to the top) so it costs a phone screen almost nothing. */
.app-header {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: .3rem .8rem; background: var(--panel); border-bottom: 2px solid var(--line);
}
.app-header .who { min-width: 0; line-height: 1.15; }                       /* min-width 0 lets long names shorten instead of wrapping */
.app-header .who > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-header .hdr-main { font-size: 1rem; color: var(--text); }
.app-header .hdr-main strong { color: var(--text); }
.app-header .hdr-unit { font-size: .72rem; color: var(--muted); }
.app-header .tools { display: flex; gap: .4rem; align-items: center; flex-shrink: 0; }
.app-header .btn-small { min-height: 2.2rem; padding: .15rem .7rem; }
.page { max-width: 760px; margin: 0 auto; padding: .4rem .8rem 1rem; }
h1 { font-size: 1.3rem; margin: .1rem 0 .45rem; }
h2 { font-size: 1.05rem; margin: .7rem 0 .3rem; color: var(--muted); }
.muted { color: var(--muted); }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }   /* read by screen readers, not drawn */

/* ── Rows on the start page: a label, the current answer, a chevron ── */
.rows { display: flex; flex-direction: column; gap: .4rem; }
.row {
    display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .1rem .8rem;
    width: 100%; text-align: left; font: inherit; color: inherit;
    background: var(--panel); border: 2px solid var(--line); border-radius: 14px;
    padding: .35rem .9rem; min-height: 3.6rem; cursor: pointer;
}
.row .label { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); grid-column: 1; }   /* small: not something you tap */
.row .value { font-size: 1.2rem; font-weight: 700; grid-column: 1; overflow-wrap: anywhere; line-height: 1.2; }
.row .chev { grid-column: 2; grid-row: 1 / span 2; font-size: 1.6rem; color: var(--muted); }
.row.needs { border-color: var(--bad); border-width: 3px; }   /* something still to do: red, not orange */
.row.suggest { border-color: var(--accent); }

/* Two-column version of the rows (start page): short answers sit side by side so the page fits on one
   screen. Rows marked .wide (long answers like names and areas) take the full width. On a narrow phone
   it falls back to one column. */
.rows.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; }
.rows.cols .row { min-height: 3.6rem; padding: .3rem .7rem; }
.rows.cols .row .value { font-size: 1.1rem; }
.rows.cols .row .chev { font-size: 1.4rem; }
.rows.cols .row.wide, .rows.cols .tick.wide { grid-column: 1 / -1; }
.tick.compact { min-height: 3.6rem; padding: .3rem .8rem; font-size: 1rem; gap: .6rem; border-radius: 14px; }
.tick.compact .box { width: 1.7rem; height: 1.7rem; font-size: 1.2rem; flex: none; }
/* (Two columns are kept on phones too: the answers are short, and one column made the page too tall.) */
@media (max-width: 320px) { .rows.cols { grid-template-columns: 1fr; } }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    min-height: 3.1rem; padding: .3rem 1rem; font: inherit; font-size: 1.05rem; font-weight: 700;
    color: var(--text); background: var(--panel-2); border: 2px solid var(--line);
    border-radius: 14px; cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-danger { border-color: var(--bad); color: var(--bad); }
.btn-good { background: var(--good); color: #04180c; border-color: var(--good); }
.btn-big { width: 100%; min-height: 3.5rem; font-size: 1.3rem; }
.btn-small { min-height: 2.6rem; padding: .3rem .8rem; font-size: .9rem; }
.btn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: .5rem; }
.btn.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn .tag { font-size: .75rem; font-weight: 600; opacity: .85; display: block; }
.btn-stack { display: flex; flex-direction: column; align-items: center; }

/* ── Chips (chosen patrollers) ── */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
    display: inline-flex; align-items: center; gap: .5rem; padding: .5rem .9rem;
    background: var(--accent); color: var(--accent-text); border-radius: 999px; font-weight: 800; font-size: 1.1rem;
}
.chip button { font: inherit; border: 0; background: rgba(0,0,0,.15); color: inherit; border-radius: 999px; padding: .1rem .6rem; cursor: pointer; }
.chip .role { font-size: .75rem; font-weight: 700; text-transform: uppercase; }

/* ── Inputs ── */
.field {
    width: 100%; font: inherit; font-size: 1.25rem; padding: .55rem .9rem; color: var(--text);
    background: var(--panel); border: 2px solid var(--line); border-radius: 14px;
}
.field:focus { outline: 3px solid var(--accent); }
textarea.field { min-height: 6rem; font-size: 1.2rem; }

/* ── Full-screen sheets (modal sheet, not the browser Fullscreen API) ── */
.sheet {
    position: fixed; inset: 0; z-index: 50; background: var(--bg);
    display: flex; flex-direction: column;
}
/* The sheet's top bar (Back + title) is half the height it was, to leave more room for the answer below it. */
.sheet-head { display: flex; align-items: center; gap: .7rem; padding: .2rem .7rem; border-bottom: 2px solid var(--line); background: var(--panel); }
.sheet-head .btn { min-height: 2.1rem; padding: 0 .7rem; font-size: 1rem; }
.sheet-head h2 { margin: 0; color: var(--text); font-size: 1.1rem; flex: 1; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: .7rem 1rem; max-width: 760px; width: 100%; margin: 0 auto; -webkit-overflow-scrolling: touch; }
/* Done bar: slim, so the answer and its keys get the room. */
.sheet-foot { padding: .4rem .8rem calc(.4rem + env(safe-area-inset-bottom)); border-top: 2px solid var(--line); background: var(--panel); }
.sheet-foot .btn { max-width: 760px; margin: 0 auto; display: flex; min-height: 3.2rem; font-size: 1.3rem; }

/* ── Name list ── */
.name-list { display: flex; flex-direction: column; gap: .5rem; margin-top: .8rem; }
.name-item { text-align: left; justify-content: space-between; min-height: 4rem; }
.name-item .sub { font-size: .8rem; color: var(--muted); font-weight: 600; }
.name-item.on .sub { color: var(--accent-text); }

/* "Add a new name" form: stacked, full-width, roomy (class-based so show/hide keeps the layout) */
.btn-block { width: 100%; }
.add-form { display: flex; flex-direction: column; gap: .9rem; margin: .4rem 0 1.5rem; padding: 1rem; background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); }
.add-form .field { flex: none; }
.name-list { padding-bottom: 2rem; }

/* ── Number pad ── */
/* FITS THE SCREEN: the pad is a column that fills the sheet. The number box and the "last" line keep their size,
   and the keys share whatever height is left (each key between 2.6rem and a cap of 4.6rem / 9.5% of the screen
   height), so the number box and every key are on screen together on any phone, big or small. If a screen is
   truly too short even for the smallest keys, the sheet scrolls instead of cutting keys off. */
.numpad-wrap { display: flex; flex-direction: column; gap: .5rem; height: 100%; max-width: 460px; margin: 0 auto; }
/* The number box is ONE line ("41,355 km"). */
.numpad-display {
    display: flex; justify-content: flex-end; align-items: baseline; gap: .4rem; white-space: nowrap; line-height: 1.1;
    font-size: 2.85rem; font-weight: 800; padding: .3rem 1rem; min-height: 0; flex: none;
    background: var(--panel); border: 2px solid var(--accent); border-radius: var(--radius); font-variant-numeric: tabular-nums;
}
.numpad-display small { font-size: .45em; font-weight: 700; color: var(--muted); }
.numpad-last { text-align: center; color: var(--muted); font-size: 1.1rem; flex: none; }
.numpad {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem;   /* equal columns even with word labels */
    grid-template-rows: repeat(4, minmax(2.6rem, min(4.6rem, 11vh)));
    flex: 1 1 0; min-height: min-content; align-content: start;
}
/* Digits are 5% smaller than before. Each key fills its row (the rows are sized above). */
.numpad .btn { min-height: 0; height: 100%; font-size: 1.71rem; padding: 0 .2rem; }
/* The word keys (Delete, Clear) get a smaller size so the whole word sits well inside its key. */
.numpad .btn-danger, .numpad .btn-good { font-size: 1.3rem; }

/* ── Fuel gauge: a row of big buttons Empty ... Full in eighths ── */
.gauge { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.gauge .btn { min-height: 3.4rem; flex-direction: column; font-size: 1.2rem; }
.gauge .btn small { font-size: .65rem; font-weight: 600; }

/* ── Banners / notices ── */
.banner { padding: .5rem .8rem; border-radius: 14px; border: 2px solid var(--warn); background: var(--panel); margin-bottom: .5rem; font-weight: 700; font-size: .95rem; }
.banner.bad { border-color: var(--bad); }
.banner.good { border-color: var(--good); }
.banner.info { border-color: var(--line); font-weight: 600; }

/* The red "please fix these" box: big, centred, and it flashes three times to catch the eye. */
.problems { margin-top: .6rem; text-align: center; font-size: 1.15rem; line-height: 1.3; border-width: 4px; padding: .6rem; }
.problems div + div { margin-top: .3rem; }
.problems.flash { animation: problems-flash .5s ease-in-out 3; }
@keyframes problems-flash {
    0%, 100% { background: var(--panel); transform: none; }
    50% { background: var(--bad); color: #fff; transform: scale(1.03); }
}
@media (prefers-reduced-motion: reduce) { .problems.flash { animation: none; } }   /* people who ask for no motion get a plain bold box */
#offline-banner { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 99; background: var(--bad); color: #fff; text-align: center; padding: .7rem; font-weight: 800; }
body.is-offline #offline-banner { display: block; }

/* "Not saved yet": a tap (Start, Finish, Cancel, Save fuel) is waiting for the signal and is being sent again. Big, red, centred, always on screen. */
#unsaved-banner { display: none; position: fixed; left: 0; right: 0; top: 0; z-index: 100; background: #b3201f; color: #fff; border-bottom: 4px solid #fff; text-align: center; padding: 1rem; font-size: 1.4rem; font-weight: 800; line-height: 1.3; }
body.has-unsaved #unsaved-banner { display: block; }

/* ── Active-patrol summary: large print for typing into the Police Comms page ── */
/* The details are a two-column grid: a small label above a big answer. Long answers (.wide) take the full width. */
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 .8rem; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: .2rem .9rem; }
.fact { display: flex; flex-direction: column; padding: .2rem 0; border-bottom: 1px solid var(--line); }
.fact.wide { grid-column: 1 / -1; }
.fact span:first-child { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; }   /* small label */
.fact span:last-child { font-weight: 800; font-size: 1.05rem; line-height: 1.15; overflow-wrap: anywhere; }
.return-time { font-size: 2.1rem; font-weight: 900; color: var(--accent); text-align: center; padding: 0; line-height: 1.05; }
.tick { display: flex; align-items: center; gap: .8rem; padding: .5rem .9rem; min-height: 3.4rem; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; font-size: 1.1rem; font-weight: 700; cursor: pointer; width: 100%; font-family: inherit; color: inherit; text-align: left; }
.tick .box { width: 1.8rem; height: 1.8rem; flex: none; border: 3px solid var(--muted); border-radius: .4rem; display: grid; place-items: center; font-size: 1.3rem; }
.tick.on { border-color: var(--good); }
.tick.alert { border-color: var(--bad); background: rgba(255, 107, 107, .12); }
.tick.alert .box { border-color: var(--bad); }
.tick.on .box { background: var(--good); border-color: var(--good); color: #04180c; }
/* Finish (wide) beside Extend and Cancel: one row. */
.actions { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: .5rem; margin-top: .5rem; }
.actions .btn-big { font-size: 1.1rem; padding-inline: .4rem; line-height: 1.15; text-align: center; }

/* ── Area coverage list: seven compact rows so the whole list is on one screen ── */
.area-row { display: flex; justify-content: space-between; align-items: center; gap: .8rem; padding: .3rem .8rem; min-height: 3.2rem; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; }
.area-row.suggest { border-color: var(--accent); }
.area-row .days { font-size: 1.15rem; font-weight: 800; text-align: right; line-height: 1.1; }
.area-row .days small { display: block; font-size: .65rem; color: var(--muted); font-weight: 600; }
.badge { display: inline-block; background: var(--accent); color: var(--accent-text); font-size: .7rem; font-weight: 800; padding: .1rem .5rem; border-radius: 999px; vertical-align: middle; margin-left: .4rem; }

/* ── Bottom nav on start/active pages ── */
.navbar { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.navbar .btn { flex: 1 1 6rem; min-height: 2.8rem; padding-inline: .5rem; font-size: 1rem; }
/* The main button and its shortcuts under it (Start/Finish/Save + Back etc.). Stacked in portrait. */
.bottombar { margin-top: .6rem; }
.errors { color: var(--bad); font-weight: 700; margin: .6rem 0; }
.pin-dots { display: flex; gap: 1rem; justify-content: center; margin: 1rem 0; }
.pin-dots i { width: 1.6rem; height: 1.6rem; border-radius: 50%; border: 3px solid var(--muted); }
.pin-dots i.on { background: var(--accent); border-color: var(--accent); }
.logo { font-size: 1.1rem; font-weight: 800; }

/* ── LANDSCAPE (phone on its side): wide but short. Portrait is the main layout; in landscape the page uses its
      width instead of its height: more columns, and on a number pad the number box sits beside the keys. ── */
@media (orientation: landscape) {
    html { font-size: clamp(13px, 4.2vh, 20px); }
    .page { max-width: 980px; padding-bottom: .4rem; }
    .rows.cols { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .35rem; }
    .rows.cols .row { min-height: 3.1rem; padding: .2rem .6rem; }
    .rows.cols .row.wide, .rows.cols .tick.wide { grid-column: span 2; }
    .tick.compact { min-height: 3.1rem; }
    .btn { min-height: 2.8rem; }
    .btn-big { min-height: 3rem; }
    .facts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .fact.wide { grid-column: span 2; }
    .actions { grid-template-columns: 2fr 1fr 1fr; }
    /* Main button on the left, shortcuts on the right, in one row. */
    .bottombar { display: grid; grid-template-columns: 2fr 1fr; gap: .5rem; align-items: start; margin-top: .4rem; }
    .bottombar .navbar { margin-top: 0; flex-wrap: nowrap; }
    .bottombar .navbar .btn { flex: 1 1 0; min-height: 3rem; }
    .gauge { grid-template-columns: repeat(5, 1fr); }
    .areas-note { display: none; }   /* explanatory note: dropped in landscape to keep the list on one screen */
    .rows.areas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .35rem; }   /* the seven areas in two columns */
    /* Number pad: the number box and "last" line on the left, the keys on the right. */
    .numpad-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); grid-template-rows: auto 1fr; align-items: start; column-gap: 1rem; max-width: 760px; }
    .numpad-display { grid-column: 1; grid-row: 1; }
    .numpad-last { grid-column: 1; grid-row: 2; align-self: start; }
    .numpad { grid-column: 2; grid-row: 1 / span 2; grid-template-rows: repeat(4, minmax(2.2rem, min(4rem, 13.5vh))); }
    .sheet-foot .btn { min-height: 2.8rem; }
}
