:root {
  --ink: #1f2328;
  --muted: #5b636d;
  --line: #d5dae0;
  --bg: #f4f6f8;
  --primary: #1a56db;
  --ok: #16803c;
  --danger: #b42318;
  --warn-bg: #fff6db;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .4em; }
p { margin: 0 0 .8em; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 18px; border-radius: var(--radius);
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-size: 16px; font-weight: 700; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.line { background: #06c755; border-color: #06c755; color: #fff; }
.btn.danger { color: var(--danger); border-color: #f0b8b3; }
.btn.big { min-height: 62px; font-size: 21px; border-radius: 14px; flex: 1; }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: 15px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.link { background: none; border: 0; padding: 8px 2px; color: var(--primary); font: inherit; font-size: 15px; text-decoration: underline; cursor: pointer; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .btn { flex: 1; }

input[type=text], input[type=password], textarea, select {
  width: 100%; font: inherit; font-size: 17px; padding: 12px; border: 1px solid #b9c0c8; border-radius: 10px; background: #fff; color: var(--ink);
}
textarea { min-height: 150px; font-size: 14px; font-family: ui-monospace, Menlo, monospace; }
label.field { display: block; font-weight: 700; margin: 12px 0 6px; }

/* 選択ボタン（ラジオ） */
.choices { display: flex; gap: 8px; flex-wrap: wrap; }
.choices label { flex: 1; min-width: 64px; }
.choices input { position: absolute; opacity: 0; pointer-events: none; }
.choices span {
  display: flex; align-items: center; justify-content: center; min-height: 46px; padding: 0 4px;
  border: 2px solid var(--line); border-radius: 10px; font-weight: 700; background: #fff; cursor: pointer; text-align: center;
  white-space: nowrap; font-size: 16px;
}
.choices input:checked + span { border-color: var(--primary); background: #eaf0ff; color: var(--primary); }
.choices input:focus-visible + span { outline: 3px solid #93b4ff; }

.note { background: var(--warn-bg); border-radius: 10px; padding: 12px 14px; font-size: 15px; }
.note b { display: block; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 12px; right: 12px; bottom: 24px; margin: 0 auto; width: fit-content; max-width: 560px;
  transform: translateY(30px); opacity: 0; pointer-events: none;
  z-index: 3000; background: #222; color: #fff; border-radius: 14px; padding: 12px 16px; font-size: 16px;
  display: flex; gap: 14px; align-items: center; box-shadow: 0 6px 24px rgba(0,0,0,.25);
  transition: opacity .2s, transform .2s;
}
.toast span { flex: 1 1 auto; }
.toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.toast.error { background: var(--danger); }
.toast button { background: #fff; color: #222; border: 0; border-radius: 10px; padding: 8px 14px; font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
body.team .toast { bottom: calc(var(--sheet-h, 200px) + 12px); }

/* ---------- map pins ---------- */
.pin-wrap { background: none; border: 0; }
.pin {
  position: absolute; transform: translate(-50%, -50%);
  min-width: 30px; height: 30px; padding: 0 7px; border-radius: 15px;
  background: var(--c); color: #fff; border: 2px solid #fff;
  font: 700 14px/26px -apple-system, "Hiragino Sans", sans-serif; text-align: center; white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,.45); cursor: pointer;
}
.pin.done { background: #fff; color: var(--c); border: 3px solid var(--c); line-height: 24px; opacity: .8; }
.pin.gray { background: #a3a9b0; color: #fff; border-color: #fff; opacity: .9; }
.pin.none { background: #fff; color: #333; border: 2px dashed #444; line-height: 26px; }
.pin.next { transform: translate(-50%, -50%) scale(1.45); }
.pin.next::after {
  content: ""; position: absolute; inset: -9px; border-radius: 99px; border: 4px solid var(--c); opacity: .6;
  animation: pulse 1.6s ease-out infinite;
}
.pin.next::before {
  content: "次"; position: absolute; left: 50%; top: -26px; transform: translateX(-50%);
  background: #111; color: #fff; font-size: 11px; line-height: 18px; padding: 0 6px; border-radius: 6px;
}
.pin.sel { box-shadow: 0 0 0 4px #111, 0 2px 8px rgba(0,0,0,.4); }
.pin.paint { cursor: crosshair; }
.pin.nophoto::after {
  content: "!"; position: absolute; right: -7px; top: -7px; width: 16px; height: 16px; border-radius: 50%;
  background: #d97706; color: #fff; font-size: 11px; line-height: 16px; text-align: center; border: 1.5px solid #fff;
}
.card-photo { display: block; width: 100%; max-height: 220px; object-fit: cover; border-radius: 10px; margin-top: 8px; border: 1px solid var(--line); }
.far .pin { min-width: 18px; height: 18px; padding: 0; font-size: 0; line-height: 0; }
.far .pin:not(.next)::before { content: ""; position: absolute; inset: -9px; }
.far .pin.next, .far .pin.sel { min-width: 30px; height: 30px; padding: 0 7px; font-size: 14px; line-height: 26px; }
@keyframes pulse { from { transform: scale(.8); opacity: .7; } to { transform: scale(1.6); opacity: 0; } }
.start-pin {
  position: absolute; transform: translate(-50%, -100%); white-space: nowrap;
  background: #fff; color: var(--c); border: 2px solid var(--c); border-radius: 8px; padding: 1px 7px;
  font: 700 13px/20px -apple-system, "Hiragino Sans", sans-serif; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.leaflet-container { font: inherit; background: #e9edf0; }
.leaflet-control-attribution { font-size: 11px; }

/* ---------- home ---------- */
body.simple { background: var(--bg); }
main.narrow { max-width: 560px; margin: 0 auto; padding: 28px 18px 60px; }
.brand { font-size: 28px; font-weight: 800; margin: 0 0 4px; }
.lead { font-size: 18px; color: var(--muted); }
.card { background: #fff; border-radius: 16px; padding: 18px; margin: 16px 0; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.how { list-style: none; padding: 0; margin: 0; counter-reset: how; }
.how li { counter-increment: how; display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; }
.how li::before {
  content: counter(how); flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff;
  font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.recent { list-style: none; margin: 0; padding: 0; }
.recent a { display: flex; justify-content: space-between; gap: 8px; padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); font-weight: 700; }
.recent a span { color: var(--muted); font-weight: 400; font-size: 14px; white-space: nowrap; }

/* ---------- admin ---------- */
body.admin { height: 100vh; height: 100dvh; display: grid; grid-template-columns: 430px 1fr; overflow: hidden; }
#panel { overflow-y: auto; background: #fff; border-right: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
#mapbox { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
.panel-head { padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.title-btn { all: unset; cursor: pointer; font-size: 21px; font-weight: 800; display: inline-flex; gap: 8px; align-items: center; }
.title-btn::after { content: "✎"; font-size: 15px; color: var(--muted); font-weight: 400; }
.progress { height: 10px; background: #e6e9ed; border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; transition: width .3s; }
.overall { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-weight: 700; }
.overall .progress { flex: 1; }
.step { padding: 18px; border-bottom: 1px solid var(--line); }
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.step-head h2 { font-size: 19px; margin: 0; flex: 1; }
.step-num {
  flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff;
  font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.step.done .step-num { background: var(--ok); font-size: 0; }
.step.done .step-num::after { content: "✓"; font-size: 18px; }
.step.locked { opacity: .55; }
.step-status { font-weight: 700; color: var(--ok); font-size: 15px; }
.team-list { list-style: none; margin: 0 0 10px; padding: 0; }
.team-row { display: grid; grid-template-columns: 18px 1fr auto; gap: 4px 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid #eef0f2; }
.team-row:last-child { border-bottom: 0; }
.dot { width: 18px; height: 18px; border-radius: 50%; background: var(--c); }
.team-row .name { font-weight: 800; }
.team-row .meta { grid-column: 2; font-size: 14px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.team-row .meta .progress { flex: 1; max-width: 140px; height: 8px; }
.team-row .btn { grid-row: 1 / span 2; grid-column: 3; }
.warn-text { color: #a15c00; font-weight: 700; }
.send-row { display: grid; grid-template-columns: 18px 1fr; gap: 6px 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid #eef0f2; }
.send-row .row { grid-column: 1 / -1; }
.panel-foot { padding: 18px; font-size: 14px; color: var(--muted); }

.map-banner {
  position: absolute; top: 10px; left: 10px; right: 60px; z-index: 1000; background: #111; color: #fff;
  border-radius: 14px; padding: 12px 14px; box-shadow: 0 4px 18px rgba(0,0,0,.3); font-size: 16px;
}
.map-banner .row { margin-top: 8px; }
.map-banner .btn { min-height: 42px; }
.paint-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.paint-chips button {
  border: 3px solid transparent; background: var(--c); color: #fff; font: inherit; font-weight: 800; font-size: 15px;
  border-radius: 99px; padding: 6px 14px; cursor: pointer;
}
.paint-chips button.none { background: #fff; color: #333; border-color: #888; }
.paint-chips button[aria-pressed=true] { border-color: #fff; box-shadow: 0 0 0 3px #ffd43b; }

.board-card {
  position: absolute; left: 10px; bottom: 10px; z-index: 1000; width: min(440px, calc(100% - 20px));
  background: #fff; border-radius: 16px; padding: 14px 16px; box-shadow: 0 6px 24px rgba(0,0,0,.25);
  max-height: calc(100% - 20px); overflow-y: auto;
}
.board-card .close { position: absolute; right: 6px; top: 4px; background: none; border: 0; font-size: 26px; width: 44px; height: 44px; cursor: pointer; color: var(--muted); }
.board-card h3 { font-size: 19px; margin-right: 36px; }
.board-card .label { font-size: 14px; font-weight: 700; color: var(--muted); margin: 10px 0 6px; }
.team-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.team-pick button {
  border: 2px solid var(--c); background: #fff; color: var(--ink); border-radius: 99px; padding: 6px 12px;
  font: inherit; font-size: 15px; font-weight: 700; cursor: pointer; min-height: 40px;
}
.team-pick button[aria-pressed=true] { background: var(--c); color: #fff; }
.team-pick button.none { --c: #666; }
.done-line { color: var(--ok); font-weight: 800; }

dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 20px)); max-height: calc(100dvh - 30px);
  box-shadow: 0 10px 40px rgba(0,0,0,.3); color: var(--ink);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dlg { padding: 20px; }
dialog h2 { font-size: 21px; outline: none; }
dialog .dlg-actions { display: flex; gap: 8px; margin-top: 18px; }
dialog .dlg-actions .btn { flex: 1; }
.preview-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.preview-table th, .preview-table td { border-bottom: 1px solid #eee; padding: 4px 6px; text-align: left; vertical-align: top; }
.preview-table th { background: #f6f7f9; white-space: nowrap; }
.board-list { list-style: none; padding: 0; margin: 0; max-height: 42dvh; overflow-y: auto; }
.board-list li { display: flex; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.board-list li > div { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.board-list li b, .board-list li span { display: block; }
.board-list .btn { flex: none; }
.board-list .board-list-actions { flex: none; display: flex; flex-direction: column; gap: 6px; }
.coord-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 14px; margin-top: 6px; }
.coord-fields input { min-width: 0; }
.danger-text { color: var(--danger); }
#board-form .dlg-actions { position: sticky; bottom: -20px; background: #fff; padding: 10px 0; }
.qr-box { display: flex; justify-content: center; padding: 10px; }
.qr-box img { width: min(320px, 80vw); height: auto; image-rendering: pixelated; }

@media (max-width: 820px) {
  body.admin { grid-template-columns: 1fr; grid-template-rows: 46dvh 1fr; }
  #mapbox { grid-row: 1; }
  #panel { grid-row: 2; border-right: 0; border-top: 1px solid var(--line); }
  /* スマホでは地図を隠さないよう、カードと案内は地図の下（パネルの場所）に出す */
  .board-card, .map-banner {
    position: fixed; top: 46dvh; left: 0; right: 0; bottom: 0; width: auto; max-height: none;
    border-radius: 0; z-index: 1500; overflow-y: auto; box-shadow: 0 -2px 10px rgba(0,0,0,.15);
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  }
  .map-banner { font-size: 16px; background: #fff; color: var(--ink); border-top: 5px solid #ffd43b; }
  .map-banner > b:first-child { display: block; font-size: 18px; }
  .map-banner > b:first-child::before { content: "↑ "; }
  .paint-chips button[aria-pressed=true] { border-color: #111; }
}

/* 位置の修正中は地図を広く使い、保存・取消を地図の上に出す（スマホも同じ操作）。 */
body.admin.position-editing { grid-template-columns: 1fr; grid-template-rows: 1fr; }
body.admin.position-editing #panel { display: none; }
body.admin.position-editing #mapbox { grid-column: 1; grid-row: 1; }
body.admin.position-editing .map-banner {
  position: absolute; top: auto; bottom: calc(24px + env(safe-area-inset-bottom)); left: 10px; right: 10px;
  width: auto; max-width: 560px; max-height: 48dvh; overflow-y: auto; margin: 0 auto;
  background: #fff; color: var(--ink); border: 2px solid var(--primary); border-radius: 16px;
  padding: 12px 14px; box-shadow: 0 4px 18px rgba(0,0,0,.25);
}
body.admin.position-editing .map-banner > b:first-child::before { content: none; }
body.admin.position-editing .toast { top: calc(12px + env(safe-area-inset-top)); bottom: auto; }
.pin.position-candidate, .far .pin.position-candidate {
  min-width: 68px; height: 38px; padding: 0 10px; font-size: 16px; line-height: 34px;
  box-shadow: 0 0 0 6px #1a56db33, 0 2px 8px #0005; cursor: grab;
}

/* ---------- team (現場の画面) ---------- */
body.team { height: 100vh; height: 100dvh; overflow: hidden; background: #e9edf0; }
body.team #map { position: fixed; top: 0; left: 0; right: 0; bottom: var(--sheet-h, 200px); }
.topbar {
  position: fixed; z-index: 1000; top: calc(8px + env(safe-area-inset-top)); left: 8px; right: 8px;
  background: #fff; border-radius: 14px; padding: 8px 12px; box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
.topbar .team-name { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.topbar .count { margin-left: auto; font-size: 16px; }
.topbar .progress { margin-top: 6px; height: 8px; }
.tools { position: fixed; z-index: 1000; top: calc(86px + env(safe-area-inset-top)); left: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.tools button {
  background: #fff; border: 0; border-radius: 99px; padding: 8px 14px; font: inherit; font-size: 15px; font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,.2); cursor: pointer; color: var(--ink);
}
.sheet {
  position: fixed; z-index: 1001; left: 0; right: 0; bottom: 0; background: #fff;
  border-radius: 20px 20px 0 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 24px rgba(0,0,0,.18); max-height: 70dvh; overflow-y: auto;
}
.sheet-label { font-size: 15px; font-weight: 800; color: var(--muted); display: flex; gap: 8px; align-items: baseline; }
.sheet-label.is-next { color: var(--primary); }
.sheet-label.is-done { color: var(--ok); }
.sheet-label .rest { margin-left: auto; font-weight: 700; }
.sheet-title { font-size: 20px; font-weight: 800; margin: 4px 0 2px; display: flex; gap: 10px; align-items: flex-start; }
.code-badge { flex: none; background: var(--c); color: #fff; border-radius: 99px; padding: 0 10px; min-width: 38px; text-align: center; font-size: 17px; line-height: 30px; margin-top: 1px; }
.sheet-sub { font-size: 15px; color: var(--muted); margin-bottom: 10px; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn.big.nav { flex: .8; }
.sheet-actions .btn.big.ok { flex: 1.2; }
.sheet .center { text-align: center; }
.pending { background: var(--warn-bg); border-radius: 10px; padding: 8px 12px; font-size: 14px; margin-bottom: 10px; font-weight: 700; }
.list-view { position: fixed; inset: 0; z-index: 2000; background: #fff; display: flex; flex-direction: column; }
.list-view header { display: flex; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; border-bottom: 1px solid var(--line); }
.list-view header h2 { flex: 1; margin: 0; font-size: 19px; }
.list-info { padding: 10px 14px; border-bottom: 1px solid var(--line); background: #f8f9fb; }
.list-info p { margin: 0 0 8px; }
.list-view .st.num { flex: none; width: 30px; height: 30px; margin: 0 12px; border-radius: 50%; background: #e9ecf0; color: var(--muted); font-size: 13px; line-height: 30px; }
.route-arrow { position: absolute; width: 18px; height: 18px; transform: translate(-50%, -50%) rotate(var(--r)); pointer-events: none; }
.route-arrow svg { display: block; }
.replan-hint { display: block; margin-top: 6px; }
.nav-banner {
  position: fixed; z-index: 1002; top: calc(8px + env(safe-area-inset-top)); left: 8px; right: 8px;
  background: #0b5d3b; color: #fff; border-radius: 16px; padding: 10px 14px; box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.nav-banner.arrived { background: #b45309; }
.nav-main { display: flex; align-items: center; gap: 14px; }
.nav-icon { font-size: 46px; line-height: 1; width: 52px; text-align: center; font-weight: 800; }
.nav-dist { font-size: 26px; font-weight: 800; line-height: 1.2; }
.nav-text { font-size: 16px; opacity: .95; }
.nav-sub { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 14px; flex-wrap: wrap; }
.nav-sub > span:first-child { flex: 1; min-width: 120px; }
.nav-btns { display: flex; gap: 6px; }
.nav-btns button { background: rgba(255,255,255,.18); color: #fff; border: 1px solid rgba(255,255,255,.5); border-radius: 99px; padding: 6px 12px; font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; }
.nav-btns button[aria-pressed=false] { opacity: .6; text-decoration: line-through; }
body.navigating .topbar, body.navigating .tools { display: none; }
.confirm { position: fixed; inset: 0; z-index: 3100; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.confirm-box {
  background: #fff; width: min(520px, 100%); border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px; text-align: center;
}
.confirm-icon { font-size: 40px; margin: 0; line-height: 1; }
.confirm-title { font-size: 21px; font-weight: 800; margin: 0; }
.confirm-text { margin: 0 0 6px; color: var(--muted); }
.no-cam { text-align: right; margin-top: 2px; }
.no-cam .link { color: var(--muted); padding: 4px 2px; font-size: 13px; }
.sheet-actions .btn.big.ok { line-height: 1.15; }
.photo-row { display: flex; gap: 12px; align-items: center; margin: 2px 0 12px; }
.photo-thumb { width: 96px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: #eef0f2; flex: none; }
.photo-row .muted { font-size: 14px; }
.photo-missing { color: #a15c00; font-weight: 700; font-size: 15px; }
.list-view .np { color: #a15c00; font-size: 12px; font-weight: 700; white-space: nowrap; }
.busy-photo { position: fixed; inset: 0; z-index: 2600; background: rgba(255,255,255,.7); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 18px; }
.list-view ol { list-style: none; margin: 0; padding: 0 0 calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; flex: 1; }
.list-view li button {
  all: unset; box-sizing: border-box; width: 100%; display: flex; gap: 12px; align-items: center; padding: 14px 16px;
  border-bottom: 1px solid #eef0f2; cursor: pointer;
}
.list-view .st { flex: none; width: 54px; font-size: 14px; font-weight: 800; text-align: center; }
.list-view .st.done { color: var(--ok); }
.list-view .st.next { color: #fff; background: var(--primary); border-radius: 8px; }
.list-view .st.todo { color: var(--muted); }
.list-view .nm { flex: 1; }
.list-view li.is-done .nm { color: var(--muted); }
