:root {
  --green: #3dcd58;
  --green-strong: #2fb24a;
  --green-ink: #0b3d1a;
  --green-soft: #e8f8ec;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1c2420;
  --muted: #5d6b63;
  --line: #dde3df;
  --danger: #c62828;
  --warn: #e0a100;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 14px rgb(0 0 0 / 5%);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  min-height: 100dvh;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; flex: none; }

/* ---------- header ---------- */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 10px;
  background: var(--green);
  color: var(--green-ink);
  box-shadow: 0 2px 8px rgb(0 0 0 / 12%);
}
.bar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand svg { width: 34px; height: 34px; display: block; border-radius: 9px; box-shadow: 0 0 0 2px rgb(255 255 255 / 60%); }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; }
.icon-btn:active { background: rgb(0 0 0 / 10%); }
.icon-btn.small { width: 32px; height: 32px; color: var(--muted); }
.icon-btn.small svg { width: 18px; height: 18px; }

.sync {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 5px 10px;
  background: rgb(255 255 255 / 85%); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green-strong); }
.sync.busy .dot { background: var(--green-strong); animation: blink 1s infinite; }
.sync.warn .dot { background: var(--warn); }
.sync.err .dot { background: var(--danger); }
@keyframes blink { 50% { opacity: .25; } }

/* ---------- layout ---------- */
.page { padding: 16px 16px calc(120px + var(--safe-b)); max-width: 640px; margin: 0 auto; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card h2, .section { margin: 0 0 12px; font-size: 17px; }
.section { margin: 24px 2px 10px; color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: .04em; }
.greeting { margin: 4px 2px 14px; font-size: 20px; }
.muted { color: var(--muted); }
.center { text-align: center; font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 14px; }
input, textarea {
  display: block; width: 100%; margin-top: 6px;
  border: 1.5px solid var(--line); border-radius: 10px; background: #fff;
  padding: 12px; font-size: 16px; font-weight: 400; color: var(--text);
}
input:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgb(61 205 88 / 25%); }
textarea { resize: vertical; min-height: 140px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 50px; margin-top: 10px; padding: 12px 16px;
  border: 0; border-radius: 12px; font-weight: 700; font-size: 16px; text-decoration: none;
}
.btn.primary { background: var(--green); color: var(--green-ink); }
.btn.primary:active { background: var(--green-strong); }
.btn.primary:disabled { background: #cfd8d2; color: #7d8a82; }
.btn.secondary { background: var(--green-soft); color: var(--green-ink); }
.btn.wide { margin-top: 20px; }
.link { border: 0; background: none; color: var(--green-strong); font-weight: 700; padding: 4px; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

/* ---------- setup ---------- */
.setup { max-width: 480px; margin: 0 auto; padding: calc(env(safe-area-inset-top, 0px) + 24px) 16px 40px; }
.hero { text-align: center; padding: 20px 0 24px; }
.hero svg { width: 72px; height: 72px; }
.hero h1 { margin: 10px 0 4px; font-size: 26px; }
.hero p { margin: 0; color: var(--muted); }
.checks { list-style: none; padding: 0; margin: 14px 0 4px; }
.checks li { display: flex; gap: 10px; align-items: center; padding: 7px 0; font-weight: 600; }
.checks li.ok svg { color: var(--green-strong); }
.checks li.bad { color: var(--danger); }

/* ---------- pickers ---------- */
.picker { margin-bottom: 6px; }
.picker label { margin-bottom: 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border: 1.5px solid var(--line); border-radius: 999px; background: #fff; padding: 7px 12px; font-size: 14px;
}
.chip.on { border-color: var(--green); background: var(--green-soft); font-weight: 600; }

/* ---------- lists ---------- */
.list { list-style: none; padding: 0; margin: 0; }
.list li { margin-bottom: 10px; }
.list button {
  display: grid; width: 100%; text-align: left; gap: 2px;
  border: 0; border-left: 5px solid var(--green); border-radius: 12px; background: var(--card); box-shadow: var(--shadow); padding: 12px 14px;
}
.list span { color: var(--text); }
.list small { color: var(--muted); }

/* ---------- report ---------- */
.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; position: relative; border-top: 5px solid var(--green); }
.meta div:first-child { grid-column: 1 / -1; padding-right: 48px; }
.meta small { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.meta strong { font-size: 15px; overflow-wrap: anywhere; }
.meta .link { position: absolute; top: 12px; right: 12px; }

.note { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 12px 12px; margin-bottom: 12px; }
.note-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.note-head .kind { font-weight: 700; color: var(--green-ink); }
.note-head time { color: var(--muted); font-size: 13px; flex: 1; }
.note-head .state svg { width: 18px; height: 18px; }
.note-head .state.ok { color: var(--green-strong); }
.note-head .state.wait { color: var(--warn); }
.note p { margin: 6px 0 0; white-space: normal; overflow-wrap: anywhere; }
.note img { display: block; width: 100%; max-height: 420px; object-fit: cover; border-radius: 10px; background: #e9eeeb; }
.voice-player { display: flex; align-items: center; gap: 8px; }
.voice-player audio { flex: 1; min-width: 0; height: 40px; }
.voice-player span { font-size: 13px; color: var(--muted); }
.voice-player svg { color: var(--green-strong); }
.empty { text-align: center; color: var(--muted); padding: 30px 20px; }
.empty svg { width: 44px; height: 44px; color: var(--green); }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  padding: 10px 12px calc(10px + var(--safe-b));
  background: rgb(255 255 255 / 96%); border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.dock button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; border-radius: 14px; padding: 10px 4px; background: var(--green); color: var(--green-ink); font-weight: 700; font-size: 14px;
}
.dock button:active { background: var(--green-strong); }
.dock svg { width: 26px; height: 26px; }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: rgb(0 0 0 / 0%); transition: background .2s;
}
.modal.open { background: rgb(0 0 0 / 45%); }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto;
  background: var(--card); border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + var(--safe-b));
  transform: translateY(100%); transition: transform .2s ease-out;
}
.modal.open .sheet { transform: none; }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 54px;
  border: 0; border-bottom: 1px solid var(--line); background: none; padding: 10px 6px; font-size: 16px; font-weight: 600; text-align: left;
}
.sheet-btn svg { width: 26px; height: 26px; color: var(--green-strong); }
.sheet-btn.danger, .sheet-btn.danger svg { color: var(--danger); }
.sheet-btn.cancel { justify-content: center; border: 0; color: var(--muted); margin-top: 6px; }
.filename { font-weight: 600; overflow-wrap: anywhere; background: var(--green-soft); padding: 10px 12px; border-radius: 10px; }

.recorder { display: grid; justify-items: center; gap: 10px; padding: 16px 0 8px; }
.pulse { display: grid; place-items: center; width: 92px; height: 92px; border-radius: 50%; background: var(--green); color: var(--green-ink); animation: pulse 1.4s infinite; }
.pulse svg { width: 40px; height: 40px; }
.timer { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(61 205 88 / 55%); } 100% { box-shadow: 0 0 0 26px rgb(61 205 88 / 0%); } }

.busy { display: grid; justify-items: center; gap: 12px; padding: 24px 0; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--green-soft); border-top-color: var(--green); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s;
  background: #1c2420; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.splash { min-height: 100dvh; background: var(--bg); }

/* ---------- BMS visit ---------- */
.hint.error { color: var(--danger); font-weight: 600; }
fieldset.segmented { border: 0; padding: 0; margin: 0 0 14px; }
fieldset.segmented legend { font-size: 14px; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 6px; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented button {
  flex: 1 1 0; min-height: 44px; padding: 8px 6px; border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff; font-weight: 600; font-size: 14px;
}
.segmented button.on { border-color: var(--green); background: var(--green); color: var(--green-ink); }
.segmented.stack { flex-direction: column; }
.segmented.stack button { flex: none; text-align: left; padding-left: 14px; }
.segmented.cats { margin-bottom: 4px; }
.segmented.cats button { flex: 1 1 40%; }

.meta .wide { grid-column: 1 / -1; padding-right: 48px; }
.meta div:first-child { padding-right: 48px; }

.checklist summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; list-style: none; font-weight: 700; font-size: 17px; }
.checklist summary::-webkit-details-marker { display: none; }
.checklist summary::after { content: '▾'; color: var(--muted); }
.checklist[open] summary::after { content: '▴'; }
.checklist summary small { margin-left: auto; color: var(--muted); font-weight: 600; font-size: 13px; }
.checklist .bad { color: var(--danger); }
.checklist h3 { margin: 18px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--green-strong); }
.check { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check span { font-size: 15px; }
.tri { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tri button { min-height: 38px; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; font-weight: 700; font-size: 14px; color: var(--muted); }
.tri button.on.pass { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.tri button.on.fail { background: var(--danger); border-color: var(--danger); color: #fff; }
.tri button.on.na { background: #6b7a72; border-color: #6b7a72; color: #fff; }
.add-check { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; }
.add-check svg { width: 18px; height: 18px; }

.note-head .cat { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--green-soft); color: var(--green-ink); }
.note-head .cat-fault { background: #fde7e7; color: #8f1d1d; }
.note-head .cat-recommendation { background: #fff3d6; color: #6b4b00; }
.note-head .cat-general { background: #eceff1; color: #37474f; }
.note-head .kind { font-weight: 600; color: var(--muted); font-size: 14px; }

.toggle { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 15px; }
.toggle input { width: 22px; height: 22px; margin: 0; accent-color: var(--green-strong); }
.sig-label { display: flex; justify-content: space-between; align-items: center; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.sig { display: block; width: 100%; height: 160px; border: 1.5px dashed #b9c4bd; border-radius: 12px; background: #fff; touch-action: none; }
.sig.blank { background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='160'%3E%3Ctext x='100' y='88' font-family='sans-serif' font-size='15' fill='%23a6b2ab' text-anchor='middle'%3ESign here%3C/text%3E%3C/svg%3E") center / 200px 160px no-repeat; }
.note .ts { font-size: 13px; font-style: italic; }
.note .ts.bad { color: var(--danger); }

/* Team visit (read only) */
.note-view p { margin: 6px 0 0; white-space: normal; }
.team-photo { display: block; max-width: 100%; border-radius: 10px; margin-top: 8px; }

.section .dash-link { float: right; font-size: 13px; font-weight: 700; color: var(--green-ink); text-decoration: none; }
