:root {
  --bg: #f6f4f2; --surface: #ffffff; --surface2: #f0edea; --text: #1d1b1a; --muted: #6b6560; --line: #e2ddd8;
  --brand: #b81e1e; --brand-ink: #ffffff; --ok: #1f7a3a; --ok-bg: #e5f4e9; --warn: #9a5b00; --warn-bg: #fff1d6;
  --bad: #b3261e; --bad-bg: #fde8e7; --info-bg: #e8eef8; --info: #2b4a7a;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151312; --surface: #1f1c1b; --surface2: #2a2625; --text: #f2eeea; --muted: #a39b94; --line: #3a3533;
    --brand: #e0453f; --ok: #6fd08c; --ok-bg: #173323; --warn: #f3b44f; --warn-bg: #3a2a10; --bad: #ff8a80; --bad-bg: #3d1a18; --info-bg: #1c2638; --info: #9db8e6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151312; --surface: #1f1c1b; --surface2: #2a2625; --text: #f2eeea; --muted: #a39b94; --line: #3a3533;
  --brand: #e0453f; --ok: #6fd08c; --ok-bg: #173323; --warn: #f3b44f; --warn-bg: #3a2a10; --bad: #ff8a80; --bad-bg: #3d1a18; --info-bg: #1c2638; --info: #9db8e6;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
h1 { font-size: 1.5rem; margin: 0 0 12px; } h2 { font-size: 1.15rem; margin: 20px 0 10px; } h3 { font-size: 1rem; margin: 16px 0 8px; }
p { margin: 6px 0; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1.5px solid var(--line); border-radius: 10px; padding: 12px; width: 100%; min-height: 48px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; }
.muted { color: var(--muted); } .err { color: var(--bad); min-height: 1em; } small { display: block; margin-top: 4px; }

.btn { border: 1.5px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 16px; min-height: 44px; font-weight: 600; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.big { min-height: 56px; padding: 12px 28px; font-size: 1.05rem; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--surface2); font-size: .85rem; font-weight: 600; }
.pill.warn { background: var(--warn-bg); color: var(--warn); }

/* Start screens */
.center-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; text-align: center; }
.brand { font-weight: 800; font-size: 2rem; letter-spacing: .08em; color: var(--brand); }
.brand.small { font-size: 1.15rem; white-space: nowrap; }
.star { display: inline-block; }
.sub { color: var(--muted); margin-bottom: 24px; }
.lead { font-size: 1.2rem; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; text-align: left; }
.card.narrow { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 10px; }
.demo-note { margin-top: 24px; color: var(--warn); font-size: .9rem; }
.staff-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; width: 100%; max-width: 820px; }
.staff-btn { background: var(--surface); border: 0; border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 10px; display: flex; flex-direction: column; align-items: center; gap: 8px; font-weight: 600; font-size: 1.05rem; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 1.5rem; font-weight: 800; }

/* PIN pad */
.pin { text-align: center; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 14px 0; }
.pin-dots span { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots span.on { background: var(--text); border-color: var(--text); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 300px; margin: 0 auto; }
.key { min-height: 64px; border-radius: 14px; border: 0; background: var(--surface2); font-size: 1.5rem; font-weight: 600; }
.key:active { background: var(--line); }

/* Main */
header.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--surface); box-shadow: var(--shadow); flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; border-radius: 10px; font-weight: 600; color: var(--muted); white-space: nowrap; min-height: 44px; }
.tabs button.on { background: var(--brand); color: var(--brand-ink); }
.who { display: flex; align-items: center; gap: 8px; font-weight: 600; }
main { padding: 16px; max-width: 1280px; margin: 0 auto; }

.today { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 24px; }
@media (max-width: 860px) { .today { grid-template-columns: 1fr; } }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 560px) { .quick { grid-template-columns: repeat(2, 1fr); } }
.quick-btn, .tile { background: var(--surface); border: 0; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 600; text-align: center; min-height: 96px; justify-content: center; font-size: .95rem; }
.quick-btn.alert { color: var(--bad); }
.ico { font-size: 1.7rem; line-height: 1; }
.due { display: flex; flex-direction: column; gap: 8px; }
.due-item { display: grid; grid-template-columns: 84px 1fr; gap: 2px 12px; text-align: left; border: 0; border-left: 6px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--surface); box-shadow: var(--shadow); }
.due-item .lvl { grid-row: span 2; font-weight: 800; font-size: .8rem; text-transform: uppercase; align-self: center; }
.due-item .t { font-weight: 700; } .due-item .d { color: var(--muted); font-size: .92rem; }
.due-item.overdue { border-left-color: var(--bad); background: var(--bad-bg); } .due-item.overdue .lvl { color: var(--bad); }
.due-item.due { border-left-color: var(--warn); } .due-item.due .lvl { color: var(--warn); }
.due-item.soon { border-left-color: var(--info); } .due-item.soon .lvl { color: var(--info); }
.due-item.info { border-left-color: var(--muted); } .due-item.info .lvl { color: var(--muted); }
.allgood { padding: 20px; text-align: center; background: var(--ok-bg); color: var(--ok); border-radius: var(--radius); font-weight: 700; }
.log { list-style: none; padding: 0; margin: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.log li { display: grid; grid-template-columns: 50px 1fr auto; gap: 0 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.log li:last-child { border-bottom: 0; }
.log .time { color: var(--muted); font-variant-numeric: tabular-nums; } .log .k { font-weight: 600; } .log .s { grid-column: 2 / 4; color: var(--muted); font-size: .9rem; }
.log .by { grid-column: 3; grid-row: 1; color: var(--muted); font-size: .85rem; }
.flag { position: absolute; right: 8px; bottom: 8px; background: var(--bad); color: #fff; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .8rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.tile .no { color: var(--muted); font-size: .8rem; font-weight: 500; }
.list { display: flex; flex-direction: column; gap: 8px; }
.card.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Modal & forms */
.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px; overflow-y: auto; }
.modal { background: var(--bg); border-radius: 18px; padding: 20px; width: 100%; max-width: 440px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal.wide { max-width: 820px; }
.modal > div > input { margin-bottom: 10px; }
.form-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.form-head h2 { margin: 0; }
.form-foot { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.form-foot .muted { margin-right: auto; }
.intro { background: var(--info-bg); color: var(--info); padding: 10px 14px; border-radius: 10px; margin: 12px 0; }
.field { margin: 14px 0; }
.field > label { display: block; font-weight: 600; margin-bottom: 6px; }
.field.inline { display: flex; align-items: center; gap: 10px; } .field.inline label { margin: 0; } .field.inline input { width: auto; }
.req { color: var(--bad); }
.num { display: flex; align-items: center; gap: 8px; } .num input { max-width: 140px; font-size: 1.3rem; font-weight: 700; text-align: center; } .unit { color: var(--muted); font-weight: 600; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1.5px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 16px; min-height: 48px; font-weight: 600; }
.seg button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.seg.small button { min-height: 40px; padding: 6px 12px; font-size: .9rem; }
.seg button.on.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.seg button.on.problem { background: var(--bad); border-color: var(--bad); color: #fff; }
.seg button.on.na { background: var(--muted); border-color: var(--muted); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; min-height: 42px; font-size: .95rem; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.check-head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.checklist { display: flex; flex-direction: column; gap: 6px; }
.check-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; background: var(--surface); padding: 10px 12px; border-radius: 10px; border-left: 5px solid var(--line); }
.check-row.done { border-left-color: var(--ok); } .check-row.problem { border-left-color: var(--bad); background: var(--bad-bg); } .check-row.na { border-left-color: var(--muted); }
.check-row .note { grid-column: 1 / -1; }
@media (max-width: 600px) { .check-row { grid-template-columns: 1fr; } }
.readings { display: flex; flex-direction: column; gap: 8px; }
.reading { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; background: var(--surface); padding: 10px 12px; border-radius: 10px; border-left: 5px solid var(--line); }
.reading.bad { border-left-color: var(--bad); background: var(--bad-bg); }
.rn { font-weight: 600; }
@media (max-width: 600px) { .reading { grid-template-columns: 1fr; } }
.evidence table { width: 100%; border-collapse: collapse; margin-top: 8px; } .evidence td { padding: 4px 0; border-bottom: 1px solid var(--line); } .evidence td:last-child { text-align: right; font-weight: 600; }

/* History */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters select, .filters input { width: auto; }
.hist { display: grid; grid-template-columns: 70px 200px 1fr; gap: 2px 12px; background: var(--surface); padding: 10px 14px; border-radius: 10px; cursor: pointer; position: relative; }
.hist .d { font-weight: 700; } .hist .k { font-weight: 600; } .hist .by { grid-column: 3; color: var(--muted); font-size: .85rem; }
.hist.old { opacity: .55; text-decoration: line-through; }
@media (max-width: 700px) { .hist { grid-template-columns: 60px 1fr; } .hist .s, .hist .by { grid-column: 1 / -1; } }
.detail table.kv { width: 100%; border-collapse: collapse; } .kv th { text-align: left; vertical-align: top; padding: 6px 12px 6px 0; color: var(--muted); font-weight: 600; text-transform: capitalize; width: 30%; }
.kv td { padding: 6px 0; white-space: pre-line; border-bottom: 1px solid var(--line); }
.problems { background: var(--bad-bg); color: var(--bad); padding: 8px 12px; border-radius: 10px; margin: 8px 0; } .problems ul { margin: 4px 0; padding-left: 20px; }
ol li { cursor: pointer; } ol li.this { font-weight: 700; }

/* Manage */
.list-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; } .list-table th, .list-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.list-table tr.inactive td { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 12px; }
.row-edit { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; } .row-edit select { width: auto; } .row-edit input.short { width: 80px; }
.reports details { margin: 12px 0; } .reports summary { cursor: pointer; font-weight: 600; padding: 8px 0; }
.reports .actions { margin: 16px 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px); opacity: 0; transition: all .25s; background: var(--ok); color: #fff; padding: 14px 22px; border-radius: 12px; font-weight: 600; z-index: 50; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
.toast.show { transform: translate(-50%, 0); opacity: 1; } .toast.err { background: var(--bad); } .toast.warn { background: var(--warn); }
@media (max-width: 700px) {
  header.top { gap: 6px; padding: 8px 12px; }
  .tabs { order: 3; flex: 1 1 100%; flex-wrap: wrap; overflow: visible; }
  .tabs button { padding: 8px 10px; min-height: 40px; flex: 1 1 auto; }
  .who { margin-left: auto; }
}

/* Tap-to-pick temperatures */
.picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.pk { min-height: 52px; border: 1.5px solid var(--line); background: var(--surface); border-radius: 10px; font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; padding: 0 4px; }
.pk.hi { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.pk.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.pk.on.hi { background: var(--bad); border-color: var(--bad); color: #fff; }
.num.other { margin-top: 8px; } .num.other input { max-width: 110px; font-size: 1.05rem; min-height: 44px; padding: 8px; }
.reading { grid-template-columns: 1fr auto; }
.reading .pick-row { grid-column: 1 / -1; }
@media (max-width: 600px) { .reading { grid-template-columns: 1fr auto; } .picks { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); } .pk { min-height: 48px; font-size: 1rem; } }

/* Tile status colours */
.quick { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 900px) { .quick { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .quick { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.quick-btn, .tile { border: 2px solid transparent; position: relative; }
.st { font-size: .78rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: var(--surface2); color: var(--muted); }
.st-ok { background: var(--ok-bg); border-color: var(--ok); }
.st-ok .st { background: var(--ok); color: #fff; }
.st-overdue { background: var(--bad-bg); border-color: var(--bad); }
.st-overdue .st { background: var(--bad); color: #fff; }
.st-due { background: var(--warn-bg); border-color: var(--warn); }
.st-due .st { background: var(--warn); color: #fff; }
.st-soon { border-color: var(--info); }
.st-soon .st { background: var(--info-bg); color: var(--info); }

/* Quick log row */
.quicklog { display: flex; flex-wrap: wrap; gap: 8px; }
.ql { display: inline-flex; align-items: center; gap: 8px; border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px 8px 10px; min-height: 48px; font-weight: 600; font-size: .95rem; }
.ql .ico { font-size: 1.3rem; }
.ql.alert { color: var(--bad); }
.due h2 { margin: 12px 0 2px; }
.jobs { margin: 6px 0 0; padding-left: 20px; } .jobs li { margin: 3px 0; }
.chip.done { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); display: inline-flex; flex-direction: column; align-items: flex-start; gap: 0; font-weight: 600; }
.chip.done .when { margin: 0; font-size: .75rem; font-weight: 500; color: var(--muted); }

/* Alarms */
.alarm-wrap { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(0,0,0,.55); }
.alarm { width: 100%; max-width: 560px; background: var(--surface); border-radius: 20px; padding: 28px 24px; text-align: center; border-top: 14px solid var(--warn); box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.alarm-wrap.lv-alarm .alarm { border-top-color: var(--bad); animation: alarm-pulse 1s ease-in-out infinite alternate; }
.alarm h2 { font-size: 1.5rem; margin: 8px 0; } .alarm p { font-size: 1.1rem; }
.alarm-bell { font-size: 3.5rem; line-height: 1; }
.alarm-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
@keyframes alarm-pulse { from { box-shadow: 0 0 0 0 rgba(179,38,30,.5); } to { box-shadow: 0 0 0 18px rgba(179,38,30,0); } }
@media (prefers-reduced-motion: reduce) { .alarm-wrap.lv-alarm .alarm { animation: none; } }
.alarm-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.alarm-row small { display: block; }
