:root {
  --bg: #f4f5f7;
  --surface: #fff;
  --text: #1f2933;
  --muted: #667085;
  --line: #d9dee5;
  --accent: #1d4e89;
  --accent-text: #fff;
  --done: #15803d;
  --todo: #dc2626;
  --radius: 10px;
  --topbar-h: 52px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
}
h1, h2 { line-height: 1.35; margin: 0; }
a { color: var(--accent); }

/* ---- ボタン・フォーム ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 44px; padding: 0 18px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; touch-action: manipulation;
}
.btn:hover { background: #eef1f5; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: #163f70; }
.btn-danger { color: #b42318; border-color: #f0b7b1; }
.btn-danger:hover { background: #fdecea; }
.btn-ghost { background: transparent; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 14px; }
:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }

.field { display: block; margin: 0 0 14px; padding: 0; border: 0; min-width: 0; }
.field > span, .field > legend { display: flex; justify-content: space-between; font-weight: 700; font-size: 14px; margin-bottom: 4px; padding: 0; }
.hint { display: block; margin: -2px 0 6px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.count { font-style: normal; font-weight: 400; color: var(--muted); }
input[type=text], input[type=password], input:not([type]), textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid #b8c0cc; border-radius: 8px;
  background: #fff; color: inherit; font: inherit;
}
textarea { resize: vertical; min-height: 5.5em; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 auto; }
.muted { color: var(--muted); font-size: 14px; }

/* 設置 / 未設置 の切り替え */
.seg { display: flex; gap: 0; border: 1px solid #b8c0cc; border-radius: 10px; overflow: hidden; background: #fff; }
.seg > label, .seg > button { flex: 1; position: relative; margin: 0; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span, .seg > button {
  display: flex; align-items: center; justify-content: center; min-height: 46px;
  font: inherit; font-weight: 700; cursor: pointer; border: 0; background: #fff; color: var(--text); width: 100%;
}
.seg > * + * { border-left: 1px solid #b8c0cc; }
.seg input[value="0"]:checked + span, .seg > button[data-v="0"][aria-pressed="true"] { background: var(--todo); color: #fff; }
.seg input[value="1"]:checked + span, .seg > button[data-v="1"][aria-pressed="true"] { background: var(--done); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid #f59e0b; outline-offset: -3px; }
.seg-big span, .seg-big > button { min-height: 64px; font-size: 20px; }

.badge { display: inline-block; padding: 2px 14px; border-radius: 999px; color: #fff; font-weight: 700; margin: 0 0 8px; }
.badge.is-done { background: var(--done); }
.badge.is-todo { background: var(--todo); }

/* ---- 地図画面 ---- */
.page-map { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  flex: none; height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; background: #16324f; color: #fff; z-index: 1200;
}
.brand { color: #fff; text-decoration: none; font-weight: 800; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; margin-right: 8px; }
.topnav { display: flex; gap: 6px; flex: none; }
.navbtn {
  min-height: 38px; padding: 0 16px; border: 1px solid rgba(255,255,255,.45); border-radius: 8px;
  background: rgba(255,255,255,.12); color: #fff; font: inherit; font-weight: 700; text-decoration: none;
  display: inline-flex; align-items: center; cursor: pointer;
}
.navbtn:hover { background: rgba(255,255,255,.25); }
.navbtn.is-off { opacity: .6; }

.layout { flex: 1; min-height: 0; display: flex; }
.mapwrap { position: relative; flex: 1; min-width: 0; min-height: 0; }
.mapwrap .folium-map { position: absolute !important; inset: 0; width: auto !important; height: auto !important; }

.panel {
  flex: none; width: 400px; max-width: 45vw; overflow-y: auto; background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: -4px 0 14px rgba(0,0,0,.08); z-index: 1100;
}
.pane { padding: 18px 18px 28px; }
.pane h2 { font-size: 19px; margin-bottom: 12px; }
.pos { margin: 0 0 14px; color: var(--muted); font-size: 14px; word-break: break-all; }
.ask { margin-top: 6px; padding-top: 14px; border-top: 1px solid var(--line); }
.ask b { display: block; margin-bottom: 8px; }
.actions { margin: 6px 0 10px; }
.links { padding-top: 12px; border-top: 1px solid var(--line); }
.preview { display: block; width: 100%; max-height: 240px; object-fit: contain; background: #eef1f5; border-radius: 8px; margin-bottom: 8px; }
.file-btn { position: relative; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 2000; max-width: 92vw;
  padding: 10px 18px; border-radius: 10px; background: #1f2933; color: #fff; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.toast.is-error { background: #b42318; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .panel { width: auto; max-width: none; max-height: 58%; border-left: 0; border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(0,0,0,.12); }
  .pane { padding: 14px 14px 22px; }
  .brand { font-size: 14px; white-space: normal; line-height: 1.25; }
  .navbtn { padding: 0 11px; }
  .toast { bottom: auto; top: calc(var(--topbar-h) + 10px); }
}

/* ---- 地図上のアイコン ---- */
.kb-icon { background: none; border: 0; overflow: visible; }
.kb-marker { position: relative; width: 40px; height: 52px; --c: var(--todo); }
.kb-marker.is-done { --c: var(--done); }
.kb-pin { display: block; filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }
.kb-body { fill: var(--c); stroke: #fff; stroke-width: 2; }
.kb-num { fill: var(--c); font-weight: 800; font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif; }
.kb-badge { fill: var(--c); stroke: #fff; stroke-width: 2; }
.kb-check { fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.kb-marker.is-selected .kb-pin { transform: scale(1.25); transform-origin: 50% 100%; }
.kb-label {
  position: absolute; left: 42px; top: 6px; max-width: 15em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 1px 7px; border: 2px solid var(--c); border-radius: 6px; background: #fff; color: #111;
  font-size: 12px; line-height: 1.5; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.kb-label b { color: var(--c); margin-right: 2px; }
.kb-target { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #f59e0b; background: rgba(245,158,11,.25); }
.kb-target::after { content: ""; position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: #f59e0b; }

/* ---- ログイン画面 ---- */
.login { max-width: 420px; margin: 0 auto; padding: 8vh 16px 40px; }
.login h1 { font-size: 22px; text-align: center; margin-bottom: 18px; }
.login .btn { width: 100%; margin-top: 4px; }
.login input { font-size: 16px; } /* 16px 未満だと iPhone が入力時に拡大する */
.login .flash { margin-bottom: 14px; }

/* ---- 共有画面・保守画面（ふつうのページ） ---- */
.page { max-width: 760px; margin: 0 auto; padding: 0 12px 40px; }
.page-wide { max-width: 1100px; }
.simple-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 4px; font-weight: 800; }
.simple-head a { font-weight: 600; font-size: 14px; }
.simple-head .right { display: flex; gap: 12px; align-items: center; }
.linkbtn { border: 0; background: none; padding: 0; font: inherit; font-weight: 600; font-size: 14px; color: var(--accent); text-decoration: underline; cursor: pointer; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-bottom: 16px; }
.card h1 { font-size: 24px; margin-bottom: 8px; }
.card h2 { font-size: 15px; color: var(--muted); margin: 22px 0 8px; }
.note { white-space: pre-wrap; margin: 0; }
.photo { display: block; width: 100%; max-height: 360px; object-fit: contain; background: #eef1f5; border-radius: 10px; margin-top: 14px; }
.mapbox { position: relative; height: 320px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.mapbox .folium-map { position: absolute !important; inset: 0; width: auto !important; height: auto !important; }
.urlbox { display: flex; gap: 8px; }
.urlbox input { flex: 1; min-width: 0; }

.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { flex: 1 1 110px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.stat b { display: block; font-size: 26px; line-height: 1.2; }
.stat.is-done b { color: var(--done); }
.stat.is-todo b { color: var(--todo); }
.tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.tools h3 { margin: 0 0 6px; font-size: 16px; }
.tools p { margin: 0 0 10px; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 10px; font-weight: 600; }
.flash.ok { background: #dcfce7; color: #14532d; }
.flash.error { background: #fee2e2; color: #7f1d1d; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 12px; }
.filters .btn[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.list { display: grid; gap: 10px; }
.item {
  display: grid; grid-template-columns: 56px 110px 1fr auto; gap: 6px 14px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--todo); border-radius: 12px; padding: 12px 14px;
}
.item.is-done { border-left-color: var(--done); }
.item .no { font-weight: 800; color: var(--muted); }
.item .thumb { width: 110px; height: 76px; object-fit: cover; border-radius: 8px; background: #eef1f5; display: block; }
.item .thumb.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.item h3 { margin: 0; font-size: 17px; }
.item .meta { color: var(--muted); font-size: 13px; }
.item .note { font-size: 14px; color: #3b4652; }
.item .acts { display: flex; flex-direction: column; gap: 6px; align-items: stretch; min-width: 200px; }
.item form.up { display: flex; gap: 6px; }
.item form.up input[type=file] { flex: 1; min-width: 0; font-size: 13px; }
.links-inline { display: flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 760px) {
  .item { grid-template-columns: 96px 1fr; }
  .item .no { grid-column: 1 / -1; }
  .item .thumb { width: 96px; height: 68px; }
  .item .acts { grid-column: 1 / -1; min-width: 0; }
}

/* ---- 印刷画面（A4）：余白は 8mm、地図は用紙の残りいっぱいに広げる ---- */
.page-print { background: #d8dce2; }
.toolbar { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 12px; }
/* 画面上の用紙：296mm 高 - 余白 8mm x 2 = 印刷時の内容領域 280mm と同じ大きさ */
.paper {
  width: 210mm; height: 296mm; margin: 0 auto 24px; padding: 8mm; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.25);
  display: flex; flex-direction: column; gap: 4mm; overflow: hidden;
}
.sheet-head { display: flex; gap: 6mm; align-items: center; flex: none; }
.sheet-no {
  flex: none; min-width: 34mm; padding: 1mm 5mm; border-radius: 3mm; background: #111; color: #fff; text-align: center;
  display: flex; align-items: baseline; justify-content: center; gap: 1.5mm; line-height: 1.1;
}
.sheet-no small { font-size: 18pt; font-weight: 700; }
.sheet-no b { font-size: 54pt; font-weight: 800; letter-spacing: -.02em; }
.sheet-no.long b { font-size: 40pt; }
.sheet-title { flex: 1; min-width: 0; font-size: 26pt; line-height: 1.25; margin: 0; word-break: break-all; }
.sheet-note { flex: none; padding: 3mm 4mm; border: 0.4mm solid #333; border-radius: 2mm; font-size: 14pt; line-height: 1.5; white-space: pre-wrap; word-break: break-all; }
.sheet-map { flex: 1; min-height: 60mm; border: 0.4mm solid #333; border-radius: 0; height: auto; }
.sheet-map .kb-pin { transform: scale(1.4); transform-origin: 50% 100%; }
.sheet-foot { display: flex; gap: 6mm; align-items: center; flex: none; }
.sheet-photo { width: 40mm; height: 40mm; object-fit: contain; border: 0.3mm solid #999; flex: none; }
.qr { display: flex; gap: 5mm; align-items: center; flex: 1; min-width: 0; }
.qr img { width: 40mm; height: 40mm; flex: none; }
.qr p { margin: 0 0 1.5mm; font-size: 11pt; line-height: 1.4; }
.qr .url { font-size: 9pt; color: #333; word-break: break-all; }
.qr .pos { margin: 1.5mm 0 0; font-size: 9pt; color: #555; }
.page-print * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
@page { size: A4 portrait; margin: 8mm; }
@media print {
  .no-print { display: none !important; }
  .page-print { background: #fff; }
  .paper { width: auto; height: 280mm; margin: 0; padding: 0; box-shadow: none; }
}
