:root {
  --accent: #007f55;
  --accent-dark: #00663f;
  --accent-soft: #e6f3ee;
  --text: #1c2421;
  --muted: #5f6b66;
  --line: #dde3e0;
  --bg: #f4f6f5;
  --card: #ffffff;
  --danger: #b3261e;
  --danger-soft: #fbeceb;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.06), 0 4px 16px rgba(16, 24, 20, 0.05);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---- top bar with progress ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner { max-width: 760px; margin: 0 auto; padding: 10px 16px 10px; }
.topbar-title { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 8px 0 4px; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width 0.3s ease; }
.progress-text { font-size: 13px; color: var(--muted); }

/* ---- layout ---- */
.main { max-width: 760px; margin: 0 auto; padding: 16px 16px 140px; }
.intro { margin: 4px 0 16px; }
.intro h1 { font-size: 24px; line-height: 1.25; margin: 0 0 6px; color: var(--accent); }
.intro p { margin: 0; color: var(--muted); }
.context {
  display: grid; gap: 2px 12px; grid-template-columns: auto 1fr;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 16px; font-size: 15px;
}
.context dt { color: var(--muted); }
.context dd { margin: 0; font-weight: 550; }

.section {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 4px 16px 8px; margin-bottom: 16px;
}
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 14px 0 4px; }
.section-head h2 { font-size: 19px; margin: 0; }
.section-count { font-size: 13px; color: var(--muted); white-space: nowrap; }
.section-count.done { color: var(--accent); font-weight: 600; }

.field { padding: 14px 0; border-top: 1px solid var(--line); scroll-margin-top: 96px; }
.section-head + .field { border-top: 0; }
.field-label { display: block; font-weight: 600; margin-bottom: 8px; }
.field-label .req { color: var(--danger); margin-left: 2px; }
.field-label .opt { color: var(--muted); font-weight: 400; font-size: 14px; margin-left: 4px; }
.field-hint { font-size: 14px; color: var(--muted); margin: -4px 0 8px; }
.field.missing .field-label { color: var(--danger); }
.field.missing { background: linear-gradient(90deg, var(--danger-soft), transparent 60%); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }

.input {
  width: 100%; min-height: 48px; padding: 11px 13px;
  border: 1.5px solid var(--line); border-radius: 10px; background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea.input { min-height: 96px; resize: vertical; line-height: 1.45; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }

/* option cards, yes/no, chips */
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  flex: 1 1 140px; min-height: 48px; padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: 10px; background: #fff;
  cursor: pointer; text-align: center; font-weight: 550;
  transition: border-color 0.15s, background 0.15s;
}
.choices.yesno .choice { flex: 1 1 0; }
.choice:hover { border-color: #b9c5bf; }
.choice[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.choice:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 1px; }

/* file tiles */
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.tile {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: #eef1ef; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile a.open { position: absolute; inset: 0; }
.tile .doc { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px; text-align: center; font-size: 12px; color: var(--muted); word-break: break-word; }
.tile .doc svg { width: 28px; height: 28px; color: var(--accent); }
.tile .badge {
  position: absolute; left: 6px; bottom: 6px; right: 6px;
  font-size: 11px; font-weight: 600; line-height: 1.2; padding: 3px 6px; border-radius: 6px;
  background: rgba(255, 255, 255, 0.92); color: var(--text); text-align: center;
}
.tile .badge.unsaved { background: var(--warn-soft); color: var(--warn); }
.tile .badge.error { background: var(--danger-soft); color: var(--danger); }
.tile .badge.busy { background: rgba(255, 255, 255, 0.92); color: var(--accent-dark); }
.tile .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); transition: width 0.2s; }
.tile .remove {
  position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 99px;
  border: 0; background: rgba(0, 0, 0, 0.55); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 18px; line-height: 1;
}
.tile .retry { position: absolute; inset: 0; border: 0; background: transparent; cursor: pointer; }
.add-tile {
  aspect-ratio: 1; border-radius: 10px; border: 1.5px dashed #a9b8b1; background: #fbfcfb;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--accent); font-weight: 600; font-size: 14px; cursor: pointer; text-align: center; padding: 6px;
}
.add-tile:hover { background: var(--accent-soft); }
.add-tile svg { width: 26px; height: 26px; }
.add-tile input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.add-tile:focus-within { outline: 3px solid var(--accent-soft); }

/* ---- bottom bar ---- */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: rgba(255, 255, 255, 0.97); border-top: 1px solid var(--line);
  backdrop-filter: saturate(1.4) blur(8px);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottombar-inner { max-width: 760px; margin: 0 auto; padding: 10px 16px; display: flex; flex-direction: column; gap: 8px; }
.save-status { font-size: 13px; color: var(--muted); min-height: 19px; }
.save-status.warn { color: var(--warn); }
.save-status.error { color: var(--danger); }
.save-status.ok { color: var(--accent-dark); }
.actions { display: flex; gap: 10px; }
.btn {
  flex: 1; min-height: 48px; border-radius: 12px; border: 1.5px solid transparent;
  font-weight: 650; cursor: pointer; padding: 0 16px;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--accent-dark); }
.btn-secondary { background: #fff; color: var(--accent-dark); border-color: var(--accent); }
.btn-secondary:not(:disabled):hover { background: var(--accent-soft); }

/* ---- states, dialog, toast ---- */
.state { text-align: center; padding: 64px 16px; color: var(--muted); }
.state h1 { color: var(--text); font-size: 22px; margin: 16px 0 8px; }
.state .icon { width: 56px; height: 56px; color: var(--accent); }
.state .icon.bad { color: var(--danger); }
.spinner { width: 32px; height: 32px; margin: 0 auto; border-radius: 99px; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.notice { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 14px; font-weight: 550; }

.dialog { border: 0; border-radius: 16px; padding: 0; max-width: min(460px, calc(100vw - 32px)); width: 100%; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
.dialog::backdrop { background: rgba(16, 24, 20, 0.45); }
.dialog form { padding: 20px; }
.dialog h2 { margin: 0 0 8px; font-size: 19px; }
.dialog ul { padding-left: 20px; margin: 8px 0; }
.dialog li a { color: var(--accent-dark); }
.dialog-actions { display: flex; gap: 10px; margin-top: 16px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(130px + env(safe-area-inset-bottom)); z-index: 30;
  background: #1c2421; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}

@media (min-width: 720px) {
  .bottombar-inner { flex-direction: row; align-items: center; justify-content: space-between; }
  .actions { flex: 0 0 auto; }
  .btn { flex: 0 0 auto; min-width: 150px; }
  .main { padding-top: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
