:root {
  --ink: #1b2a33;
  --ink-soft: #52636e;
  --paper: #eef3f4;
  --surface: #ffffff;
  --line: #d6e0e3;
  --aegean: #1f6f8b;
  --aegean-deep: #16384a;
  --dirty: #b4232c;
  --progress: #c98a0c;
  --clean: #2f6fb0;
  --inspected: #2e7d4f;
  --ooo: #6b7280;
  --critical: #b4232c;
  --warning: #c98a0c;
  --info: #2f6fb0;
  --radius-s: 6px;
  --radius-l: 14px;
  --font: "Avenir Next", "Avenir", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e4ecef; --ink-soft: #9db0ba; --paper: #0f1d24; --surface: #172a33; --line: #2a404b;
    --aegean: #5fb3d0; --aegean-deep: #0b1a21; --dirty: #f0646b; --progress: #e8b23c; --clean: #6aa7e6;
    --inspected: #5cc08a; --ooo: #9aa3ad; --critical: #f0646b; --warning: #e8b23c; --info: #6aa7e6;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font); font-size: 16px; line-height: 1.45; color: var(--ink); background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--aegean); outline-offset: 2px; }
a { color: var(--aegean); }

/* ---- shell ---- */
.top {
  position: sticky; top: 0; z-index: 10; background: var(--aegean-deep); color: #fff;
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
}
.brand { font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.brand small { font-weight: 400; opacity: .7; margin-left: 4px; }
.top select {
  background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.25);
  border-radius: var(--radius-s); padding: 6px 8px; max-width: 46vw;
}
.top select option { color: #1b2a33; }
.top .spacer { flex: 1; }
.top .who { font-size: 14px; opacity: .85; white-space: nowrap; }
.top button.link { white-space: nowrap; background: none; border: 0; color: #fff; text-decoration: underline; cursor: pointer; padding: 4px; }

nav.tabs { display: flex; gap: 4px; padding: 8px 16px 0; overflow-x: auto; background: var(--paper); border-bottom: 1px solid var(--line); }
nav.tabs a {
  text-decoration: none; color: var(--ink-soft); padding: 8px 12px 10px; border-bottom: 3px solid transparent; white-space: nowrap;
}
nav.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--aegean); font-weight: 600; }
nav.tabs .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 10px; background: var(--critical); color: #fff; font-size: 12px; text-align: center; }

main { padding: 16px; max-width: 1280px; margin: 0 auto; padding-bottom: 80px; }
h1 { font-size: 24px; margin: 4px 0 12px; font-weight: 700; }
h2 { font-size: 18px; margin: 24px 0 8px; font-weight: 600; }
.muted { color: var(--ink-soft); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

/* ---- buttons ---- */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-s);
  padding: 8px 14px; cursor: pointer; min-height: 40px;
}
.btn:hover { border-color: var(--aegean); }
.btn.primary { background: var(--aegean); border-color: var(--aegean); color: #fff; }
.btn.go { background: var(--inspected); border-color: var(--inspected); color: #fff; }
.btn.stop { background: var(--dirty); border-color: var(--dirty); color: #fff; }
.btn.big { min-height: 52px; padding: 12px 22px; font-size: 17px; font-weight: 600; }
.btn[disabled] { opacity: .5; cursor: default; }

/* ---- login ---- */
.login { max-width: 360px; margin: 12vh auto; padding: 0 16px; }
.login h1 { font-size: 30px; }
.field { display: grid; gap: 4px; margin-bottom: 14px; }
.field label { font-size: 14px; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); padding: 10px 12px; width: 100%;
}
.error { color: var(--dirty); margin: 8px 0; }

/* ---- status legend & filters ---- */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; color: var(--ink-soft); margin: 4px 0 14px; }
.legend button { border: 0; background: none; padding: 4px 0; cursor: pointer; color: inherit; display: inline-flex; align-items: center; gap: 6px; }
.legend button[aria-pressed="true"] { color: var(--ink); font-weight: 600; text-decoration: underline; text-underline-offset: 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--c, var(--ooo)); }

/* ---- the key-fob room board ---- */
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.fob {
  --c: var(--ooo);
  position: relative; text-align: left; cursor: pointer; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 22px 22px var(--radius-l) var(--radius-l);
  padding: 30px 14px 12px; min-height: 150px; display: flex; flex-direction: column; gap: 4px;
  box-shadow: inset 0 6px 0 var(--c);
}
.fob::before { /* the key-ring hole */
  content: ""; position: absolute; top: 12px; left: 50%; width: 14px; height: 14px; margin-left: -7px;
  border-radius: 50%; border: 2px solid var(--line); background: var(--paper);
}
.fob:hover { border-color: var(--c); }
.fob .num, .stat, td, .item .room { font-variant-numeric: tabular-nums; }
.fob .num { font-size: 34px; font-weight: 700; line-height: 1; letter-spacing: -.01em; }
.fob .type { font-size: 13px; color: var(--ink-soft); }
.fob .state { font-weight: 600; color: var(--c); font-size: 14px; margin-top: 4px; }
.fob .occ { font-size: 13px; }
.fob .who { font-size: 12px; color: var(--ink-soft); margin-top: auto; }
.fob .flag { color: var(--critical); font-weight: 700; }
.s-dirty { --c: var(--dirty); }
.s-in_progress { --c: var(--progress); }
.s-clean { --c: var(--clean); }
.s-inspected { --c: var(--inspected); }
.dot.s-ooo { background: var(--ooo); }
.fob.s-ooo { --c: var(--ooo); background: repeating-linear-gradient(135deg, var(--surface) 0 10px, var(--paper) 10px 20px); }

/* ---- lists ---- */
.list { display: grid; gap: 10px; }
.item {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 14px;
  display: grid; gap: 8px;
}
.item .head { display: flex; gap: 12px; align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.item .room { font-size: 22px; font-weight: 700; }
.item .kind { font-weight: 600; }
.item.done { opacity: .6; }
.item.p1 { border-left: 6px solid var(--dirty); }
.item.p2 { border-left: 6px solid var(--progress); }
.pill { display: inline-block; font-size: 13px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--c, var(--line)); color: var(--c, var(--ink-soft)); }
.sev-critical { --c: var(--critical); }
.sev-warning { --c: var(--warning); }
.sev-info { --c: var(--info); }
.alert { border-left: 6px solid var(--c); }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; font-size: 14px; color: var(--ink-soft); }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

.cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.brief { white-space: pre-wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 18px 20px; max-width: 72ch; line-height: 1.6; }
.stat { font-size: 32px; font-weight: 700; line-height: 1.1; }

/* ---- sheet (room / dialog) ---- */
.scrim { position: fixed; inset: 0; background: rgba(10, 20, 26, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--paper); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 20px 16px max(20px, env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@media (min-width: 700px) { .scrim { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 40;
  background: var(--aegean-deep); color: #fff; padding: 10px 16px; border-radius: var(--radius-s);
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw;
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--dirty); }

@media (max-width: 560px) {
  .top { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .top .who, .brand small { display: none; }
  .top select { max-width: 50vw; min-width: 0; flex: 1 1 auto; }
  .top .spacer { display: none; }
  .board { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  .fob { min-height: 132px; }
  .fob .num { font-size: 28px; }
  h1 { font-size: 21px; }
}
