[hidden] { display: none !important; }
:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #1b2421;
  --muted: #6b7672;
  --line: #e2e5e0;
  --accent: #0f5c5c;
  --accent-soft: #dcecea;
  --done: #2f7d4f;
  --warn: #b86a12;
  --danger: #b3261e;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111715;
    --card: #1a2220;
    --text: #e8ece9;
    --muted: #93a09b;
    --line: #2a3431;
    --accent: #5fb3ad;
    --accent-soft: #1f3836;
    --done: #6cc28f;
    --warn: #e0a04f;
    --danger: #f2827a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(24px + var(--safe-bottom));
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: var(--accent); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: #0d2524; } }
.topbar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 10px; display: grid; place-items: center; color: inherit; }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg circle { fill: currentColor; stroke: none; }
.icon-btn:active { background: rgba(255,255,255,.15); }

main { max-width: 680px; margin: 0 auto; padding: 14px; }

/* Buttons */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600;
  background: var(--accent); color: #fff; width: 100%;
}
@media (prefers-color-scheme: dark) { .btn { color: #0d1a19; } }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: none; color: var(--accent); border: 1.5px dashed var(--line); }
.btn.danger { background: none; color: var(--danger); border: 1.5px solid var(--line); }
.btn:active { opacity: .85; }

/* Case list */
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty p { margin: 0 0 18px; }
.search { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); margin-bottom: 12px; }
.filters { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .chip.on { color: #0d1a19; } }

.case-card {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
}
.case-card:active { transform: scale(.99); }
.case-card .name { font-weight: 650; font-size: 17px; }
.case-card .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.case-card .next { font-size: 14px; margin-top: 10px; }
.case-card .next b { color: var(--accent); font-weight: 600; }
.bars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.bar label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .04em; }
.bar .track { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.bar.full .fill { background: var(--done); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); vertical-align: 2px; margin-left: 6px; }
.badge.done { background: color-mix(in srgb, var(--done) 18%, transparent); color: var(--done); }

/* Case view */
.case-head { margin-bottom: 12px; }
.case-head .meta { color: var(--muted); font-size: 14px; }
.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 14px;
  position: sticky; top: calc(56px + var(--safe-top)); z-index: 4;
}
.tab { border: 0; background: none; padding: 8px 4px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); }
.tab small { display: block; font-weight: 500; font-size: 11px; }
.tab.on { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .tab.on { color: #0d1a19; } }

.notice { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }

/* Steps */
.steps { list-style: none; margin: 0; padding: 0; }
.steps.dim { opacity: .55; }
.step { position: relative; display: flex; gap: 12px; padding: 0 0 14px; }
.step::before {
  content: ""; position: absolute; left: 15px; top: 34px; bottom: 0; width: 2px; background: var(--line);
}
.step:last-child::before { display: none; }
.step.is-done::before { background: var(--done); }
.check {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--card);
  display: grid; place-items: center; padding: 0;
}
.check svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.step.is-done .check { background: var(--done); border-color: var(--done); }
.step.is-done .check svg { opacity: 1; }
.step.is-current .check { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.step-body {
  flex: 1; min-width: 0; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px;
}
.step.is-current .step-body { border-color: var(--accent); }
.step-title { font-weight: 600; }
.step.is-done .step-title { color: var(--muted); }
.step-sub { color: var(--muted); font-size: 13px; }
.step-info { font-size: 12px; color: var(--done); margin-top: 4px; }
.step-note { font-size: 13px; margin-top: 6px; white-space: pre-wrap; border-left: 3px solid var(--accent-soft); padding-left: 8px; }
.step-open { background: none; border: 0; padding: 0; width: 100%; text-align: left; }

.group {
  display: flex; align-items: center; justify-content: space-between;
  margin: 6px 0 10px 44px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent);
}
.group button { background: none; border: 0; color: var(--muted); font-size: 12px; text-transform: none; letter-spacing: 0; padding: 4px 6px; }
.add-round { margin: 0 0 14px 44px; width: calc(100% - 44px); }

/* Checklist items inside a step (pending info / missing docs) */
.items { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 8px; }
.items-label { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.item { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.item input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--done); flex: none; }
.item span { flex: 1; font-size: 14px; word-break: break-word; }
.item.got span { text-decoration: line-through; color: var(--muted); }
.item .x { background: none; border: 0; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 6px; }
.item-add { display: flex; gap: 6px; margin-top: 6px; }
.item-add input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); font-size: 14px; }
.item-add button { border: 0; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-weight: 700; padding: 0 12px; }
.items-summary { font-size: 12px; color: var(--warn); margin-top: 4px; }

.case-notes { margin-top: 18px; }
.case-notes label { font-size: 13px; color: var(--muted); font-weight: 600; }
textarea, .field input, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--card);
}
textarea { min-height: 90px; resize: vertical; }

/* Bottom sheet */
dialog {
  border: 0; padding: 0; width: 100%; max-width: 680px; margin: auto auto 0;
  border-radius: 20px 20px 0 0; background: var(--bg); color: var(--text);
  max-height: 90vh;
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog[open] { animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
#sheetForm { padding: 18px 16px calc(18px + var(--safe-bottom)); display: grid; gap: 12px; }
#sheetForm h2 { margin: 0; font-size: 18px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.toggle { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--done); }
.menu-list { display: grid; gap: 8px; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
