/*
  app.css
  All the styling for Ferguson Turnout, following the approved wireframes and the
  look in SPEC 12. Colours are set once as variables at the top: the light (day)
  values first, then the dark (night) values. Phones get one column; screens 900 px
  and wider (tablet landscape) get two columns.
*/

/* ---------- Colours (day theme) ---------- */
:root {
  --brand-red: #A20E00;
  --go-green: #4C6B24;
  --caution-orange: #E28425;
  --caution-text: #111111;
  --ack-blue: #3C5DFF;
  --notice-purple: #4F2877;
  --page: #F0F0F0;
  --card: #FFFFFF;
  --row: #F5F5F5;
  --text: #111111;
  --sub: #595959;
  --line: #E4E4E4;
  --input-border: #8A8A8A;
  --input-bg: #FFFFFF;
  --chip-bg: #FFFFFF;
  --chip-on-bg: #E8EDFF;
  --tab-bg: #FFFFFF;
  --tab-on: #A20E00;
  --link: #2F49D6;
  --call-bg: #FFFFFF;
  --call-text: #2F49D6;
  --dy: #4C6B24;
  --dn: #A20E00;
  --dx: #7A4510;
  --dx-border: #B86A1C;
  --shadow: 0 1px 2px rgba(0, 0, 0, .15);
  --warn-bg: #FFF4E8;
  color-scheme: light;
}

/* ---------- Colours (night theme) ---------- */
:root[data-theme="dark"] {
  --page: #111111;
  --card: #252525;
  --row: #303030;
  --text: #FFFFFF;
  --sub: #B3B3B3;
  --line: #3A3A3A;
  --input-border: #8A8A8A;
  --input-bg: #303030;
  --chip-bg: #303030;
  --chip-on-bg: #1F2A66;
  --tab-bg: #1A1A1A;
  --tab-on: #FF6B5B;
  --link: #9DB0FF;
  --call-bg: transparent;
  --call-text: #9DB0FF;
  --dy: #9CC46A;
  --dn: #FF8A7D;
  --dx: #F0A050;
  --dx-border: #F0A050;
  --shadow: none;
  --warn-bg: #3A2A16;
  color-scheme: dark;
}

/* ---------- Page and shell ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 16px/1.4 Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--link); }
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
button:disabled { opacity: .45; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--ack-blue); outline-offset: 2px; }

/* Hidden but still readable by screen readers (used for file inputs). */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: 0; background: #fff; color: #111; padding: 8px; z-index: 100; }
.skip:focus { left: 8px; }

/* Strip and top bar stay at the top while the page scrolls. */
.top-fixed { position: sticky; top: 0; z-index: 60; }
/* Height of the strip and bar, set by app.js. Menus and sheets start below it so SOS is never covered. */
:root { --top-h: 56px; }
.live {
  display: flex; align-items: center; justify-content: center; min-height: 48px;
  background: #FFFFFF; color: #111111; font-size: 14px; font-weight: 600;
  padding: 4px 12px; text-decoration: none; border-bottom: 1px solid #CFCFCF;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar {
  background: var(--brand-red); color: #fff; height: 56px; display: flex; align-items: center;
  justify-content: space-between; gap: 8px; padding: 0 6px;
}
.bar h1 { font-size: 20px; font-weight: 600; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ib {
  width: 48px; height: 48px; border: 0; background: none; color: #fff; display: flex;
  align-items: center; justify-content: center; padding: 0; cursor: pointer; flex: none;
}
.sos {
  width: 48px; height: 48px; border-radius: 50%; border: 2px solid #fff; background: var(--brand-red);
  color: #fff; font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center;
  text-decoration: none; flex: none;
}
.update {
  display: block; width: 100%; min-height: 48px; border: 0; background: var(--ack-blue); color: #fff;
  font-weight: 700; font-size: 16px; cursor: pointer;
}
body.emergency .bar h1 { letter-spacing: 1px; }

/* Main area. Bottom padding leaves room for the tabs and the + button. */
.body { padding: 12px 12px 168px; display: flex; flex-direction: column; gap: 12px; }
.body.one { max-width: 760px; margin: 0 auto; }
.body.one .col-b:empty, .body .col:empty { display: none; }
.col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

/* Two columns on tablets in landscape: timer and radio card left, questions right. */
@media (min-width: 900px) {
  .body.cols {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px;
    padding: 16px 24px 168px; align-items: start; max-width: 1400px; margin: 0 auto;
  }
  .body.cols .col { gap: 16px; }
  .body.cols .col-a { position: sticky; top: 104px; }
  .card { padding: 16px; }
  .script { font-size: 22px; }
}

/* Bottom tabs. */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(64px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--tab-bg); border-top: 1px solid var(--line); display: flex;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 13px; color: var(--sub); text-decoration: none; min-height: 48px;
}
.tab.on { color: var(--tab-on); font-weight: 700; }
.ico { display: inline-flex; line-height: 0; }

/* Red round + button (diary entry). */
.fab {
  position: fixed; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 21; width: 56px; height: 56px;
  border-radius: 50%; background: var(--brand-red); color: #fff; font-size: 32px; line-height: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35); display: flex; align-items: center; justify-content: center; text-decoration: none;
}
@media (min-width: 900px) { .fab { right: 24px; bottom: 84px; } }

/* Side menu. */
.menu { position: fixed; inset: var(--top-h) 0 0 0; z-index: 40; background: rgba(0, 0, 0, .45); }
.menu-panel {
  position: absolute; left: 0; top: 0; bottom: 0; width: min(300px, 85vw); background: var(--card);
  padding: 16px 0; display: flex; flex-direction: column; box-shadow: 2px 0 8px rgba(0, 0, 0, .3);
}
.menu-panel a, .menu-panel button {
  display: flex; align-items: center; min-height: 56px; padding: 0 20px; border: 0; background: none;
  color: var(--text); font-size: 17px; text-decoration: none; text-align: left; cursor: pointer; border-bottom: 1px solid var(--line);
}

/* ---------- Cards and text ---------- */
.card {
  background: var(--card); border-radius: 12px; padding: 14px; display: flex; flex-direction: column;
  gap: 10px; box-shadow: var(--shadow); min-width: 0;
}
.card h2 { font-size: 17px; font-weight: 700; }
.card.warn { border: 2px solid var(--caution-orange); background: var(--warn-bg); }
.sub { font-size: 14px; color: var(--sub); }
.sub.label { margin-top: 2px; font-weight: 600; }
.sub.err { color: var(--dn); }
.section-title { font-size: 17px; margin: 4px 0 0; }
.notice { font-weight: 700; color: var(--dn); }
.ok-msg { font-weight: 700; color: var(--dy); }
.entry { white-space: pre-wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.inline { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.inline > .field { flex: 1 1 140px; }
/* Line the Photo button up with the text box beside it (the box has a label above). */
.inline > .photo-ctl { padding-top: 24px; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.big-result { font-size: 22px; font-weight: 700; min-height: 1.4em; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* ---------- Buttons ---------- */
.pill {
  min-height: 52px; border-radius: 26px; border: 0; font-weight: 600; font-size: 16px; display: flex;
  align-items: center; justify-content: center; gap: 8px; text-decoration: none; padding: 8px 18px;
  text-align: center; cursor: pointer; width: 100%;
}
.next { background: var(--caution-orange); color: var(--caution-text); }
.yes { background: var(--go-green); color: #fff; }
.no { background: var(--brand-red); color: #fff; }
.call { background: var(--call-bg); color: var(--call-text); border: 2px solid var(--ack-blue); }
.called { background: var(--ack-blue); color: #fff; border: 2px solid var(--ack-blue); }
.outline-red { background: transparent; color: var(--dn); border: 2px solid var(--dn); }
.pill.running { background: #000; color: #fff; border-color: #000; font-size: 18px; }
.link {
  font-size: 16px; font-weight: 600; text-align: center; padding: 12px 0; background: none; border: 0;
  color: var(--link); text-decoration: underline; cursor: pointer; min-height: 48px;
}
.link.left { text-align: left; }

/* Choice chips. */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 48px; padding: 6px 16px; border-radius: 24px; border: 1.5px solid var(--input-border);
  background: var(--chip-bg); color: var(--text); font-size: 15px; cursor: pointer; display: inline-flex;
  align-items: center; gap: 6px; text-align: left;
}
.chip.on { border: 2px solid var(--ack-blue); background: var(--chip-on-bg); font-weight: 700; }
.chips.big .chip { min-height: 52px; font-size: 16px; padding: 6px 20px; }
.hint { text-align: center; }
.chips.compass .chip { min-width: 56px; justify-content: center; }
.filter { margin-top: 2px; }

/* Rows: "Label ...... value >". Real buttons so they work with keyboards and readers. */
.row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 52px; width: 100%;
  border: 0; border-bottom: 1px solid var(--line); background: none; padding: 4px 0; color: var(--text);
  font-size: 16px; text-decoration: none; text-align: left; cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row.static { cursor: default; }
.row-label { flex: 1 1 auto; min-width: 0; }
.val { color: var(--sub); text-align: right; display: inline-flex; align-items: center; gap: 2px; flex: 0 1 auto; min-width: 0; overflow-wrap: anywhere; }
.val.empty { color: var(--link); font-weight: 600; }
details.more > summary { list-style: none; }
details.more > summary .row-label { flex: none; font-weight: 600; }
details.more > summary .val { font-size: 14px; }
details.more > summary::-webkit-details-marker { display: none; }
details.more[open] > summary { margin-bottom: 8px; }

/* Text boxes. */
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--sub); min-width: 0; }
.field input, .field textarea, .search input {
  min-height: 48px; border: 1.5px solid var(--input-border); border-radius: 8px; padding: 10px 12px; width: 100%;
  background: var(--input-bg); color: var(--text); font: 16px Roboto, system-ui, sans-serif;
}
.field textarea { resize: vertical; }
.field-label { font-weight: 600; }

/* ---------- Checklists ---------- */
.ck {
  display: grid; grid-template-columns: minmax(0, 1fr) 48px 48px 48px; align-items: center; gap: 6px;
  font-size: 16px; min-height: 56px; border-bottom: 1px solid var(--line);
}
.ck:last-child { border-bottom: 0; }
.d {
  width: 48px; height: 48px; border-radius: 24px; background: var(--card); display: flex; align-items: center;
  justify-content: center; cursor: pointer; padding: 0;
}
.dy { border: 1.5px solid var(--dy); color: var(--dy); }
.dy.on { background: var(--go-green); color: #fff; border-color: var(--go-green); }
.dn { border: 1.5px solid var(--dn); color: var(--dn); }
.dn.on { background: var(--brand-red); color: #fff; border-color: var(--brand-red); }
.dx { border: 1.5px solid var(--dx-border); color: var(--dx); }
.dx.on { background: var(--caution-orange); color: #111; border-color: var(--caution-orange); }
.tally { display: flex; height: 24px; border-radius: 4px; overflow: hidden; font-size: 13px; font-weight: 700; }
.tally span { display: flex; align-items: center; justify-content: center; }
.tally-y { background: var(--go-green); color: #fff; }
.tally-n { background: var(--brand-red); color: #fff; }
.tally-x { background: var(--caution-orange); color: #111; }
.tally-none { background: var(--row); color: var(--sub); }

/* ---------- Timer band and radio cards ---------- */
.timer { background: #000; color: #fff; text-align: center; padding: 6px 0 8px; margin: -12px -12px 0; }
.timer .t { font-size: 40px; font-weight: 700; letter-spacing: 2px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.timer .l { color: #FF6B5B; font-size: 13px; font-weight: 700; letter-spacing: 1px; }
.timer.overdue .t { color: #FFB199; }
@media (min-width: 900px) {
  .timer { margin: 0; border-radius: 12px; border: 1px solid #3A3A3A; padding: 8px 0; }
  .timer .t { font-size: 44px; }
}
.band {
  background: var(--notice-purple); color: #fff; font-size: 13px; font-weight: 700; letter-spacing: .5px;
  padding: 8px 14px; margin: -14px -14px 0; border-radius: 12px 12px 0 0;
}
@media (min-width: 900px) { .band { margin: -16px -16px 0; padding: 8px 16px; } }
.protocol { font-size: 13px; }
.script { font-size: 20px; line-height: 1.4; }
.script.strong { font-weight: 700; }
.callwrap { display: flex; flex-direction: column; gap: 8px; }
.tel { font-weight: 700; display: inline-flex; align-items: center; min-height: 48px; }

/* ---------- Photos and GPS ---------- */
.photo-ctl { display: flex; flex-direction: column; gap: 8px; }
.photo-btn { align-self: flex-start; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs:empty { display: none; }
.thumb { border: 1px solid var(--line); border-radius: 8px; padding: 0; background: var(--row); width: 76px; cursor: pointer; overflow: hidden; color: var(--text); }
.thumb img { display: block; width: 76px; height: 57px; object-fit: cover; }
.thumb span { display: block; font-size: 13px; padding: 2px 0; }
.gps { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.gps-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.gps-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.typed > summary { min-height: 48px; display: flex; align-items: center; color: var(--link); font-weight: 600; cursor: pointer; }

/* ---------- PAFTACS letters ---------- */
.letters { display: flex; justify-content: space-between; gap: 2px; }
.letter {
  width: 48px; height: 48px; border-radius: 24px; display: flex; align-items: center; justify-content: center;
  font-weight: 700; text-decoration: none; font-size: 17px; flex: none;
}
.letter.done { background: var(--go-green); color: #fff; }
.letter.now { background: var(--ack-blue); color: #fff; }
.letter.todo { border: 1.5px solid var(--input-border); color: var(--sub); }

/* ---------- Crew picker ---------- */
.search { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; background: var(--card); padding-bottom: 8px; z-index: 1; }
.mlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.mrow {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; border: 0;
  border-bottom: 1px solid var(--line); background: none; text-align: left; padding: 6px 4px; cursor: pointer; color: var(--text);
}
.mrow.on { background: var(--chip-on-bg); }
.circle {
  width: 48px; height: 48px; border-radius: 50%; color: #fff; font-weight: 700; display: flex;
  align-items: center; justify-content: center; flex: none; font-size: 17px;
}
.mname { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.mtag { font-size: 13px; font-weight: 700; background: var(--row); border-radius: 10px; padding: 3px 8px; }
.mtick { width: 24px; color: var(--ack-blue); }

/* ---------- Incident log ---------- */
.seg { display: flex; background: var(--line); border-radius: 10px; padding: 3px; }
.seg a, .seg span { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 4px 0; font-size: 15px; color: var(--text); text-decoration: none; border-radius: 8px; }
.seg a.on { background: var(--card); font-weight: 700; }
.seg .seg-off { color: var(--sub); }
.tag { font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 10px; white-space: nowrap; }
.tag-progress { background: #C9F0D2; color: #0B5A1C; }
.tag-queued { background: #FBE3CC; color: #6B3A08; }
.tag-sent { background: #E3EFD9; color: #2F4A12; }
.tag-closed { background: #E4E4E4; color: #333; }
.card-link { font-size: 16px; font-weight: 600; min-height: 48px; display: flex; align-items: center; }
.plain-list { list-style: none; margin: 0; padding: 0; }

/* ---------- Close screen ---------- */
.missing { margin: 0; padding: 0; list-style: none; }
.missing li { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 52px; border-bottom: 1px solid var(--line); }
.fix { font-weight: 700; min-width: 48px; min-height: 48px; display: flex; align-items: center; justify-content: flex-end; }
.outbox-item { border-left: 4px solid var(--ack-blue); padding: 6px 10px; background: var(--row); border-radius: 4px; }
.outbox-item.err { border-left-color: var(--brand-red); }
.confirm-q { font-size: 18px; }

/* ---------- Emergency ---------- */
.sos-card { border: 3px solid var(--brand-red); }
.sos-card h2 { color: var(--dn); }
.avl { background: var(--caution-orange); color: #111; }
.avl h2 { font-size: 20px; }
.steps { margin: 0; padding-left: 22px; font-size: 17px; line-height: 1.6; }
.coords { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Guides ---------- */
.guide-list { list-style: none; margin: 0; padding: 0; }
.viewer { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.viewer .full { display: inline-flex; align-items: center; min-height: 48px; font-weight: 600; }
.viewer img { width: 100%; height: auto; border-radius: 8px; background: #fff; touch-action: pinch-zoom; }

/* ---------- Sheets, toast, highlight ---------- */
.backdrop { position: fixed; inset: var(--top-h) 0 0 0; z-index: 50; background: rgba(0, 0, 0, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); color: var(--text); width: 100%; max-width: 640px; max-height: calc(100dvh - var(--top-h) - 12px); overflow: auto;
  border-radius: 16px 16px 0 0; padding: 0 16px 24px; display: flex; flex-direction: column;
}
.sheet.wide { max-width: 860px; }
.sheet .card { box-shadow: none; border: 1px solid var(--line); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--card); padding: 8px 0; z-index: 2; }
.sheet-head h2 { font-size: 19px; }
.sheet-x { color: var(--text); }
.sheet-body { display: flex; flex-direction: column; gap: 12px; }
.sheet-foot { position: sticky; bottom: -24px; background: var(--card); padding: 8px 0 0; }
@media (min-width: 900px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 16px; max-height: calc(100dvh - var(--top-h) - 40px); }
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom)); z-index: 60;
  background: #222; color: #fff; padding: 12px 18px; border-radius: 24px; font-size: 15px; max-width: 90vw; text-align: center;
}
.flash { animation: flash 2.4s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px var(--caution-orange); } 100% { box-shadow: 0 0 0 0 transparent; } }

/* Respect "reduce motion" settings. */
@media (prefers-reduced-motion: reduce) { .flash { animation: none; outline: 3px solid var(--caution-orange); } }
