:root {
  --bg: #F4F6F8;
  --surface: #FFFFFF;
  --ink: #16323B;
  --ink-2: #5F7078;
  --ink-3: #93A1A7;
  --line: #E3E8EB;
  --accent: #0F7089;
  --accent-dark: #0B5768;
  --accent-soft: #E6F2F5;

  --ready: #1E8A5E;      --ready-soft: #E4F4EC;
  --occupied: #4F6572;   --occupied-soft: #EAEEF0;
  --needs: #D08700;      --needs-soft: #FFF3DC;
  --refreshing: #2F6FD0; --refreshing-soft: #E7EFFB;
  --maint: #C23B3B;      --maint-soft: #FBE8E8;

  --radius: 18px;
  --radius-sm: 12px;
  --tap: 52px;
  --shadow: 0 1px 2px rgba(22,50,59,.04), 0 8px 24px -12px rgba(22,50,59,.18);
  --shadow-lg: 0 12px 40px -12px rgba(22,50,59,.35);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-size: 16px; line-height: 1.5;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
h1 { font-size: clamp(26px, 4vw, 32px); font-weight: 700; letter-spacing: -0.02em; margin: 4px 0 6px; line-height: 1.15; }
h2 { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); margin: 32px 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.center { text-align: center; margin-top: 24px; }
code { font: 13px/1.3 ui-monospace, Menlo, monospace; }
strong { font-weight: 600; }

/* ---------- Top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--accent); color: #fff;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.who { font-size: 13px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.page { max-width: 1080px; margin: 0 auto; padding: 20px 16px 32px; }
@media (min-width: 720px) { .page { padding: 32px 28px 48px; } }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head h1 { margin-bottom: 4px; }
.lead { color: var(--ink-2); margin-bottom: 20px; }
.back { display: inline-flex; align-items: center; color: var(--ink-2); font-size: 14px; font-weight: 500; margin-bottom: 8px; }
.back:hover { color: var(--accent); }

/* ---------- Status board ---------- */
.board { display: grid; grid-template-columns: 1fr; gap: 14px; margin: 4px 0 8px; }
@media (min-width: 560px) { .board { grid-template-columns: repeat(2, 1fr); gap: 16px; } }
@media (min-width: 900px) { .board { grid-template-columns: repeat(3, 1fr); } }

.tile {
  position: relative; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; display: flex; flex-direction: column; gap: 14px;
  border: 1px solid rgba(22,50,59,.05);
  transition: box-shadow .2s ease;
}
.tile::before {
  content: ""; position: absolute; left: 20px; right: 20px; top: 0; height: 4px; border-radius: 0 0 4px 4px;
  background: var(--c);
}
.tile:hover { box-shadow: var(--shadow-lg); }
.st-ready         { --c: var(--ready);      --c-soft: var(--ready-soft); }
.st-occupied      { --c: var(--occupied);   --c-soft: var(--occupied-soft); }
.st-needs_refresh { --c: var(--needs);      --c-soft: var(--needs-soft); }
.st-refreshing    { --c: var(--refreshing); --c-soft: var(--refreshing-soft); }
.st-maintenance   { --c: var(--maint);      --c-soft: var(--maint-soft); }

.tile-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.tile-name { font-weight: 700; font-size: 21px; letter-spacing: -0.015em; line-height: 1.2; margin-top: 4px; }
.tile-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
.tile-status {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--c-soft); color: var(--c); font-weight: 600; font-size: 14px;
  padding: 6px 12px 6px 10px; border-radius: 999px;
}
.tile-status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: none; }
.st-needs_refresh .tile-status::before, .st-maintenance .tile-status::before { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--c) 25%, transparent); } }
.tile-since { color: var(--ink-3); font-size: 13px; }

.tile-actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.tile-actions form { display: contents; }
.tbtn {
  width: 100%; min-height: 48px; padding: 0 16px; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
  border: 1.5px solid transparent; transition: background .15s, border-color .15s, transform .1s;
}
.tbtn.primary { background: var(--accent); color: #fff; }
.tbtn.primary:hover { background: var(--accent-dark); }
.tbtn.quiet { background: transparent; color: var(--ink-2); border-color: var(--line); }
.tbtn.quiet:hover { border-color: var(--ink-3); color: var(--ink); }
.tbtn:active { transform: translateY(1px); }
.tile-note {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px;
  border-radius: var(--radius-sm); background: var(--bg); color: var(--ink-2); font-size: 14px; font-weight: 500;
}
.tile-note::before { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--c); border-right-color: transparent; animation: spin 1.1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .tile-note::before, .tile-status::before { animation: none; } .tile { transition: none; } }

.tile-menu { position: relative; flex: none; }
.tile-menu summary {
  list-style: none; cursor: pointer; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; color: var(--ink-3); font-size: 20px; font-weight: 700; line-height: 1; letter-spacing: 1px;
}
.tile-menu summary:hover, .tile-menu[open] summary { background: var(--bg); color: var(--ink); }
.tile-menu summary::-webkit-details-marker { display: none; }
.tile-menu form {
  position: absolute; right: 0; top: 42px; z-index: 20; min-width: 190px;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); border: 1px solid var(--line); padding: 6px;
}
.tile-menu form::before { content: "Set status"; display: block; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); padding: 8px 12px 4px; }
.tile-menu form button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 10px 12px; font: inherit; font-size: 15px; border-radius: 9px; cursor: pointer; color: var(--ink); }
.tile-menu form button:hover { background: var(--bg); }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid rgba(22,50,59,.05); }
.list li { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); min-height: var(--tap); }
.list li:last-child { border-bottom: 0; }
.list li:hover { background: #FAFBFC; }
.list li.urgent { box-shadow: inset 4px 0 0 var(--maint); }
.list li.unread { background: var(--accent-soft); }
.list li.faded { opacity: .55; }
.grow { flex: 1; min-width: 0; }
.chev { color: var(--ink-3); font-size: 22px; }
.col { display: flex; flex-direction: column; gap: 6px; }

.linklist { background: var(--surface); border-radius: var(--radius); overflow: hidden; margin-bottom: 20px; box-shadow: var(--shadow); border: 1px solid rgba(22,50,59,.05); }
.linklist a { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); font-weight: 600; min-height: 56px; }
.linklist a:hover { background: #FAFBFC; }
.linklist a:last-child { border-bottom: 0; }
.linklist span { color: var(--ink-3); font-size: 20px; }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.pill.red { background: var(--maint-soft); color: var(--maint); }
.pill.blue { background: var(--refreshing-soft); color: var(--refreshing); }
.pill.green { background: var(--ready-soft); color: var(--ready); }
.pill.grey { background: var(--occupied-soft); color: var(--occupied); }

.card { background: var(--surface); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); border: 1px solid rgba(22,50,59,.05); }
.card h2 { margin-top: 0; }
.note { white-space: pre-line; }
.empty { text-align: center; color: var(--ink-2); padding: 36px 16px; }
.empty h1 { color: var(--ink); }

/* ---------- Forms ---------- */
.stack { display: flex; flex-direction: column; gap: 16px; margin-top: 12px; max-width: 560px; }
label { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=date], input[type=datetime-local], select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius-sm); min-height: var(--tap);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(15,112,137,.15); }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid rgba(15,112,137,.45); outline-offset: 2px; }
textarea { min-height: 96px; resize: vertical; }
fieldset { border: 1.5px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px 6px; margin: 0; background: var(--surface); }
legend { font-weight: 600; color: var(--ink-2); padding: 0 6px; font-size: 14px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters select, .filters input { flex: 1 1 150px; margin: 0; min-height: 44px; padding: 8px 12px; font-size: 15px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 22px; border-radius: var(--radius-sm); font: inherit; font-weight: 600; font-size: 15px;
  background: var(--surface); color: var(--ink); border: 1.5px solid var(--line); cursor: pointer; text-align: center;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: 0 6px 16px -8px rgba(15,112,137,.7); }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.big { width: 100%; font-size: 17px; min-height: 58px; }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); box-shadow: none; }
.btn.ghost:hover { background: var(--surface); }
.btn.danger { color: var(--maint); }
.btn:active { transform: translateY(1px); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row.actions { margin: 16px 0 4px; }
.row.actions .btn { flex: 1 1 200px; max-width: 320px; }

/* ---------- Checklist ---------- */
.checklist { list-style: none; padding: 0; margin: 0 0 20px; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid rgba(22,50,59,.05); }
.checklist li { border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: 0; }
.check { display: flex; align-items: center; gap: 14px; padding: 14px 18px; min-height: 62px; font-size: 17px; font-weight: 500; color: var(--ink); cursor: pointer; transition: background .15s; }
.check:hover { background: #FAFBFC; }
.check input { width: 26px; height: 26px; flex: none; accent-color: var(--ready); margin: 0; }
.check.done span { color: var(--ink-3); text-decoration: line-through; }
.check.toggle { background: var(--surface); border-radius: var(--radius-sm); border: 1.5px solid var(--line); min-height: var(--tap); padding: 12px 16px; font-weight: 500; font-size: 15px; }
.check.toggle input { accent-color: var(--accent); }

/* ---------- Messages ---------- */
.flash { padding: 14px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-weight: 500; }
.flash-ok { background: var(--ready-soft); color: #145C3F; }
.flash-error { background: var(--maint-soft); color: #7E1F1F; }
.toast { position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 14px 18px; border-radius: 14px; max-width: 92vw; z-index: 30; box-shadow: var(--shadow-lg); font-weight: 500; }
#offline-bar { display: none; background: var(--needs); color: #fff; text-align: center; padding: 6px; font-size: 14px; }
.offline #offline-bar { display: block; }

/* ---------- Table ---------- */
.tablewrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid rgba(22,50,59,.05); }
.table { border-collapse: collapse; width: 100%; font-size: 14px; }
.table th, .table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--ink-2); font-weight: 600; white-space: nowrap; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
.table tr:last-child td { border-bottom: 0; }

/* ---------- Login ---------- */
.login { max-width: 400px; margin: 10vh auto 0; background: var(--surface); padding: 32px 28px; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid rgba(22,50,59,.05); }
.login h1 { font-size: 28px; }
.login .stack { max-width: none; }

/* ---------- Bottom tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; background: rgba(255,255,255,.92); backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 10px 4px 8px; font-size: 11.5px; font-weight: 600; color: var(--ink-3); position: relative; min-height: 60px; transition: color .15s; }
.tabs a.active { color: var(--accent); }
.tabs a.active::after { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.tabs .ico { font-size: 21px; line-height: 1; }
.badge { position: absolute; top: 6px; left: calc(50% + 8px); background: var(--maint); color: #fff; font-size: 11px; border-radius: 999px; padding: 1px 6px; font-weight: 700; }
@media (min-width: 720px) { .tabs a { font-size: 13px; } }

/* ---------- Install banner ---------- */
.install { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; background: var(--surface); border: 1.5px solid var(--accent); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.install-text { display: flex; flex-direction: column; gap: 2px; flex: 1 1 220px; }
.install-text span { color: var(--ink-2); font-size: 14px; }
.install-actions { display: flex; gap: 6px; }
