:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --ink: #16191d;
  --ink-2: #4b5360;
  --ink-3: #7a8290;
  --line: #e1e4e9;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e0f2ef;
  --good: #15803d;   --good-soft: #e3f4e8;
  --warn: #a16207;   --warn-soft: #fbf1d9;
  --bad: #b91c1c;    --bad-soft: #fbe5e5;
  --bar: #0f766e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1113;
    --surface: #1a1d21;
    --surface-2: #23272c;
    --ink: #eef0f2;
    --ink-2: #b5bcc6;
    --ink-3: #858d99;
    --line: #2d3238;
    --accent: #2bb3a6;
    --accent-ink: #062a27;
    --accent-soft: #123a36;
    --good: #4ade80;   --good-soft: #13301d;
    --warn: #facc15;   --warn-soft: #332a0d;
    --bad: #f87171;    --bad-soft: #3a1717;
    --bar: #2bb3a6;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

#app { max-width: 760px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: 13px; color: var(--ink-3); font-weight: 400; }
.back { border: 0; background: none; padding: 6px 8px 6px 0; font-size: 26px; line-height: 1; color: var(--accent); cursor: pointer; }

main.page { padding: 16px; }

/* ---------- bottom nav ---------- */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-inner { display: flex; width: 100%; max-width: 760px; }
.nav a {
  flex: 1; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-3); font-size: 12px; font-weight: 500;
}
.nav a svg { width: 24px; height: 24px; }
.nav a.active { color: var(--accent); }

/* ---------- blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.stack > * + * { margin-top: 12px; }
.section-title { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); margin: 24px 4px 8px; }
.section-title:first-child { margin-top: 4px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.empty { text-align: center; color: var(--ink-3); padding: 32px 16px; }
.hello { font-size: 22px; font-weight: 700; margin: 4px 4px 2px; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; color: var(--ink); border-top: 1px solid var(--line); cursor: pointer; }
.list-item:first-child { border-top: 0; }
.list-item:active { background: var(--surface-2); }
.list-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.list-item .meta { font-size: 13px; color: var(--ink-3); }
.chev { color: var(--ink-3); font-size: 20px; }

.tpl-card { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.tpl-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.tpl-icon svg { width: 24px; height: 24px; }
.tpl-icon.audit { background: var(--warn-soft); color: var(--warn); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 13px; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad  { background: var(--bad-soft);  color: var(--bad); }
.badge.neutral { background: var(--surface-2); color: var(--ink-2); }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }

/* ---------- forms ---------- */
label.field { display: block; }
.field > span { display: block; font-size: 13px; color: var(--ink-2); margin: 0 2px 6px; font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); outline: none; font-size: 16px;
}
textarea.input { resize: vertical; min-height: 44px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 20px; height: 20px; }
.icon-btn { border: 0; background: var(--surface-2); color: var(--ink-2); width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn svg { width: 18px; height: 18px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); padding: 7px 14px; border-radius: 999px; font-size: 14px; font-weight: 550; cursor: pointer; color: var(--ink-2); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters select.input { width: auto; flex: 1 1 150px; padding: 9px 12px; font-size: 15px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.logo { width: 64px; height: 64px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; margin-bottom: 18px; }
.logo svg { width: 36px; height: 36px; }
.login h1 { font-size: 28px; margin: 0 0 4px; }

/* ---------- fill checklist ---------- */
.q { padding: 14px 14px 12px; }
.q.missing { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.q-text { font-weight: 550; margin-bottom: 4px; }
.q-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ans {
  min-height: 46px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface);
  font-weight: 650; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--ink-2);
}
.ans svg { width: 18px; height: 18px; }
.ans.yes.on { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.ans.no.on  { background: var(--bad-soft);  border-color: var(--bad);  color: var(--bad); }
.ans.na.on  { background: var(--surface-2); border-color: var(--ink-3); color: var(--ink); }
.q-extra { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.thumb { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; background: var(--surface-2); flex: none; cursor: zoom-in; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 22px; cursor: pointer; padding: 0; }
.thumb.loading::after { content: ""; position: absolute; inset: 0; background: rgba(255,255,255,.5); }
.add-photo { width: 72px; height: 72px; border-radius: 10px; border: 1.5px dashed var(--ink-3); background: none; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; gap: 2px; cursor: pointer; }
.add-photo svg { width: 22px; height: 22px; }
.add-photo.req { border-color: var(--warn); color: var(--warn); }

.sticky-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 25;
  display: flex; justify-content: center; padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); border-top: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.sticky-inner { width: 100%; max-width: 728px; display: flex; gap: 12px; align-items: center; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .2s; }

.result { text-align: center; padding: 28px 16px; }
.result .big { font-size: 56px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* ---------- inspection detail ---------- */
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.stat .k { font-size: 12px; color: var(--ink-3); font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .v { font-size: 24px; font-weight: 750; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }
.stat .v small { font-size: 14px; font-weight: 550; color: var(--ink-3); }
.ans-row { display: flex; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.ans-row:first-child { border-top: 0; }
.ans-ico { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none; margin-top: 1px; }
.ans-ico svg { width: 16px; height: 16px; }
.ans-ico.yes { background: var(--good-soft); color: var(--good); }
.ans-ico.no { background: var(--bad-soft); color: var(--bad); }
.ans-ico.na { background: var(--surface-2); color: var(--ink-3); }
.ans-row .comment { font-size: 14px; color: var(--ink-2); margin-top: 4px; background: var(--surface-2); padding: 6px 10px; border-radius: 8px; }
.ans-row .photos { margin-top: 8px; }

/* ---------- reports ---------- */
.bars { display: flex; flex-direction: column; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 11px 16px; border-top: 1px solid var(--line); align-items: center; }
.bar-row:first-child { border-top: 0; }
.bar-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--bar); border-radius: 999px; }
.bar-row .meta { grid-column: 1 / -1; font-size: 13px; color: var(--ink-3); }
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-wrap .grid line { stroke: var(--line); stroke-width: 1; }
.chart-wrap .axis text { fill: var(--ink-3); font-size: 11px; }
.chart-wrap .line { fill: none; stroke: var(--bar); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-wrap .area { fill: var(--bar); opacity: .08; }
.chart-wrap .dot { fill: var(--bar); stroke: var(--surface); stroke-width: 2; }
.chart-wrap .cross { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 13px;
  padding: 6px 10px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -100%); margin-top: -10px; z-index: 5;
}
.tooltip b { font-variant-numeric: tabular-nums; }

/* ---------- editor ---------- */
.item-edit { padding: 12px; }
.item-edit .top { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.item-edit .num { font-weight: 700; color: var(--ink-3); width: 26px; font-variant-numeric: tabular-nums; }
.item-edit .opts { display: flex; gap: 12px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.item-edit .opts .input { width: 76px; padding: 8px 10px; }

/* ---------- sheet / modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet h2 { margin: 0 0 14px; font-size: 20px; }
@media (min-width: 640px) { .overlay { align-items: center; } .sheet { border-radius: 20px; } }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 60; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 80px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 70; font-size: 15px;
  max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.err { background: var(--bad); color: #fff; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- anti-cheat ---------- */
.flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pill.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.pill.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.pill.audit { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.alert { display: flex; align-items: center; gap: 12px; border-left: 4px solid var(--accent); }
.alert.warn { border-left-color: var(--warn); background: var(--warn-soft); cursor: pointer; }
.alert.good { border-left-color: var(--good); background: var(--good-soft); }
.alert .small { color: var(--ink-2); margin-top: 2px; }
.comment.reject { background: var(--bad-soft); color: var(--bad); }
.ans-row.rejected .grow > div:first-child { text-decoration: line-through; text-decoration-color: var(--bad); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; flex-basis: 100%; margin-top: 4px; }

/* ---------- periodicity ---------- */
.not-due { margin-top: 18px; }
.not-due summary { cursor: pointer; font-weight: 600; color: var(--ink-2); }
.sched { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.sched select.input { width: auto; padding: 8px 10px; font-size: 15px; }
.sched .input.num { width: 64px; padding: 8px 10px; }
.wd { display: flex; gap: 4px; flex-wrap: wrap; }
.wd button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 8px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink-2); min-width: 36px; }
.wd button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.danger-zone { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }

.comment.accept { background: var(--good-soft); color: var(--good); }
.btn.accept { color: var(--good); }

.loc-checks { display: flex; flex-direction: column; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.loc-btn { min-height: 58px; font-size: 18px; justify-content: flex-start; padding-left: 18px; }
