:root {
  --bg: #f6f6f4; --fg: #1c1c1a; --muted: #6a6a64; --card: #ffffff; --line: #deddd6;
  --accent: #1f5f4a; --accent-fg: #ffffff; --warn: #8a5a00; --warn-bg: #fff4d6; --err: #8f1d1d; --err-bg: #fde8e8;
  --test: #5b2b8c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413; --fg: #ecece8; --muted: #a2a29a; --card: #1e1e1c; --line: #34342f;
    --accent: #5fb394; --accent-fg: #0d1a14; --warn: #f0c36a; --warn-bg: #3a2e12; --err: #f2a3a3; --err-bg: #3a1a1a;
    --test: #c9a3f2;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.topbar .muted { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
h1 { font-size: 20px; margin: 0 0 8px; }
h2 { font-size: 17px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 12px 0 6px; }
.muted { color: var(--muted); font-size: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 12px; }
.card[hidden], [hidden] { display: none !important; }
label { display: block; font-size: 14px; margin: 12px 0 4px; font-weight: 600; }
input, select, textarea {
  width: 100%; font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 88px; resize: vertical; }
button {
  font: inherit; min-height: 44px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--fg); cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); margin-top: 16px; font-weight: 600; }
button.danger { color: var(--err); border-color: var(--err); }
button.link { border: 0; background: none; color: var(--accent); text-decoration: underline; min-height: 36px; padding: 4px 8px; }
button:disabled { opacity: .55; cursor: not-allowed; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 4px; -webkit-overflow-scrolling: touch; }
.tabs button { white-space: nowrap; flex: 0 0 auto; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; font-size: 12px;
  line-height: 20px; text-align: center; background: var(--warn-bg); color: var(--warn);
}
.tabs button[aria-selected="true"] .badge { background: rgba(255,255,255,.25); color: inherit; }
.row { display: flex; align-items: center; gap: 12px; margin: 4px 0 12px; }
.row .muted { flex: 1; text-align: right; }
.item-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item-title { font-weight: 700; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; font-size: 14px; margin: 6px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tag-test {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .06em; padding: 1px 8px; border-radius: 6px;
  border: 1px solid var(--test); color: var(--test);
}
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 10px 12px; margin: 0 0 12px; }
.notice.error { background: var(--err-bg); color: var(--err); }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.qr { display: block; margin: 8px auto; background: #fff; border-radius: 8px; }
code { overflow-wrap: anywhere; }
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 20;
}
.modal-box {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; padding: 16px;
  border-radius: 16px 16px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.modal-actions .primary { margin-top: 0; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom));
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: 90vw;
}
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.photos figure { margin: 0; }
.photos img { width: 100%; height: 120px; object-fit: cover; border-radius: 8px; background: var(--line); }
.photos figcaption { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
ol.answers { padding-left: 20px; margin: 6px 0; }
ol.answers li { margin-bottom: 8px; }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--line); }
@media (min-width: 640px) { .modal { align-items: center; } .modal-box { border-radius: 16px; } }
.emergency { font-size: 20px; font-weight: 800; margin: 8px 0; padding: 8px 12px; border-radius: 8px; border: 2px solid var(--err); color: var(--err); }
.ref-photo { max-width: 100%; max-height: 240px; border-radius: 8px; display: block; margin: 8px 0; }
.photo-box { margin: 8px 0; }
