:root {
  --navy: #1f2a44;
  --navy-2: #2c3a5c;
  --accent: #e8772e;
  --accent-dark: #c0601f;
  --ink: #1e2430;
  --ink-2: #4a5468;
  --muted: #7a8496;
  --line: #dfe3ea;
  --bg: #f3f5f8;
  --card: #ffffff;
  --ok: #2f8f5b;
  --warn: #c9861a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 14px rgba(20, 30, 50, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; flex: none;
  display: grid; place-items: center; font-weight: 800;
  background: var(--accent); color: #fff;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 15px; }
.brand-text small { font-size: 11px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topnav { display: flex; gap: 4px; }
.topnav a {
  text-decoration: none; font-size: 13px; padding: 6px 10px; border-radius: 8px; opacity: .85;
  white-space: nowrap;
}
.topnav a.active, .topnav a:hover { background: rgba(255, 255, 255, .14); opacity: 1; }

main { max-width: 1280px; margin: 0 auto; padding: 16px; padding-bottom: 96px; }
.mock-note {
  max-width: 1280px; margin: 0 auto; padding: 12px 16px 28px;
  font-size: 11px; color: var(--muted);
}

/* ---------- generic ---------- */
h1 { font-size: 20px; margin: 4px 0 2px; }
h2 { font-size: 16px; margin: 0 0 8px; }
.sub { color: var(--ink-2); font-size: 13px; margin: 0; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #eef1f6; color: var(--ink-2);
  white-space: nowrap;
}
.pill.accent { background: #fdeee3; color: var(--accent-dark); }
.pill.ok { background: #e6f4ec; color: var(--ok); }
.pill.warn { background: #fbf1df; color: var(--warn); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; cursor: pointer;
  font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #c5ccd8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.navy { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 14px; }
.page-head .titles { flex: 1 1 260px; min-width: 0; }
.back { font-size: 13px; color: var(--ink-2); text-decoration: none; }

/* ---------- patrol list ---------- */
.hero {
  padding: 18px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  background: linear-gradient(120deg, var(--navy), var(--navy-2)); color: #fff;
}
.hero .titles { flex: 1 1 240px; }
.hero .sub { color: rgba(255, 255, 255, .8); }
.hero .stat-row { display: flex; gap: 16px; margin-top: 8px; }
.hero .stat b { font-size: 22px; display: block; line-height: 1.1; }
.hero .stat span { font-size: 11px; opacity: .8; }
.patrol-list { display: grid; gap: 10px; margin-top: 14px; }
.patrol-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; text-decoration: none;
}
.patrol-item:hover { outline: 2px solid #d6dce6; }
.date-box {
  width: 56px; flex: none; text-align: center; border-radius: 10px; background: #eef1f6; padding: 6px 0;
}
.date-box b { display: block; font-size: 20px; line-height: 1.1; }
.date-box span { font-size: 11px; color: var(--ink-2); }
.patrol-item .meta { flex: 1; min-width: 0; }
.patrol-item .meta p { margin: 2px 0 0; font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumbs-mini { display: flex; gap: 4px; }
.thumbs-mini img { width: 44px; height: 33px; object-fit: cover; border-radius: 4px; }

/* ---------- patrol detail ---------- */
.detail-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
.detail-grid > * { min-width: 0; }
.tabs { display: flex; gap: 4px; padding: 4px; background: #e6eaf0; border-radius: 10px; margin-bottom: 12px; }
.tabs button {
  flex: 1; min-height: 38px; border: 0; border-radius: 8px; background: transparent; cursor: pointer;
  font-weight: 600; font-size: 14px; color: var(--ink-2);
}
.tabs button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.finding-list { display: grid; gap: 10px; }
.finding {
  padding: 14px; border: 2px solid transparent; cursor: pointer;
}
.finding.selected { border-color: var(--accent); }
.finding-head { display: flex; gap: 10px; align-items: flex-start; }
.no-badge {
  width: 28px; height: 28px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 13px;
  background: var(--accent); color: #fff;
}
.finding-text { margin: 0; font-weight: 600; font-size: 15px; }
.finding-meta { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.photo-strip { display: flex; gap: 6px; overflow-x: auto; margin-top: 10px; padding-bottom: 2px; }
.photo-thumb {
  position: relative; flex: none; width: 92px; height: 69px; border-radius: 8px; overflow: hidden;
  border: 0; padding: 0; cursor: zoom-in; background: #dfe3ea;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.dir-badge {
  position: absolute; right: 4px; bottom: 4px;
  display: inline-flex; align-items: center; gap: 2px;
  padding: 1px 5px 1px 3px; border-radius: 999px; font-size: 10px; font-weight: 700;
  background: rgba(20, 28, 44, .78); color: #fff;
}
.arrow { display: inline-block; width: 12px; height: 12px; }
.empty {
  padding: 28px 16px; text-align: center; color: var(--muted); font-size: 14px;
}

.map-panel { padding: 10px; }
.map-switch { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; }
.map-switch button {
  min-height: 34px; padding: 4px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2);
}
.map-switch button.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.map-box { height: 62vh; min-height: 340px; border-radius: 10px; overflow: hidden; background: #e8ecf1; }
.map-hint { font-size: 12px; color: var(--muted); margin: 6px 2px 0; }

.pin {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: var(--accent); border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  display: grid; place-items: center;
}
.pin span { transform: rotate(45deg); color: #fff; font-weight: 800; font-size: 13px; }
.pin.selected { background: var(--navy); }
.cam-dot {
  width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--navy);
}
.leaflet-popup-content { margin: 10px 12px; font-family: inherit; }
.popup-title { font-weight: 700; margin-bottom: 6px; font-size: 13px; }
.popup-photos { display: grid; grid-template-columns: repeat(4, 56px); gap: 4px; }
.popup-photos .photo-thumb { width: 56px; height: 42px; }

.fab {
  position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 900;
  box-shadow: 0 6px 18px rgba(232, 119, 46, .45); border-radius: 999px; padding: 10px 20px;
}

@media (min-width: 900px) {
  .detail-grid { grid-template-columns: minmax(360px, 5fr) 7fr; align-items: start; }
  .detail-grid .map-col { position: sticky; top: 72px; }
  .tabs.mobile-only { display: none; }
  .detail-grid > .hidden-mobile { display: block !important; }
  .fab { display: none; }
}
@media (max-width: 899px) {
  .desktop-only { display: none !important; }
  .hidden-mobile { display: none; }
}

/* ---------- form ---------- */
.form { padding: 16px; }
.field { margin-bottom: 16px; }
.field > label, .field > .label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; }
.input, textarea.input, select.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px; border: 1px solid #cdd3dd; background: #fff;
  font-size: 16px; /* iOS のズームを防ぐ */
}
textarea.input { min-height: 96px; resize: vertical; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid #cdd3dd; border-radius: 10px; overflow: hidden; }
.seg button { min-height: 42px; padding: 0 16px; border: 0; background: #fff; cursor: pointer; font-weight: 600; }
.seg button.active { background: var(--navy); color: #fff; }
.who-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 600px) { .who-grid { grid-template-columns: 1fr 1fr auto; } }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photo-card { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.photo-card .img { position: relative; aspect-ratio: 4 / 3; background: #dfe3ea; }
.photo-card .img img { width: 100%; height: 100%; object-fit: cover; }
.photo-card .info { padding: 6px 8px; font-size: 12px; display: grid; gap: 4px; }
.photo-card .info button { justify-self: start; }
.remove-photo {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer; font-size: 16px; line-height: 1;
}
.add-tiles { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.status-line { font-size: 12px; color: var(--ink-2); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 6px; }

.plan-picker { max-width: 720px; position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: crosshair; background: #fff; }
.plan-picker img { width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.plan-mark {
  position: absolute; width: 26px; height: 26px; margin: -26px 0 0 -13px; pointer-events: none;
}
.plan-mark .pin { width: 26px; height: 26px; }

.submit-bar {
  position: sticky; bottom: 0; z-index: 800; margin: 0 -16px -16px; padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96); border-top: 1px solid var(--line);
  display: flex; gap: 8px; border-radius: 0 0 var(--radius) var(--radius);
}
.submit-bar .btn.primary { flex: 1; }

/* ---------- modal / lightbox / toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 2000; background: rgba(10, 15, 25, .55);
  display: grid; place-items: center; padding: 16px;
}
.modal {
  width: min(520px, 100%); max-height: 90vh; overflow: auto; background: #fff; border-radius: 16px; padding: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.modal h2 { margin-bottom: 4px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.dir-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.dir-pick button { min-height: 52px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 700; }
.dir-pick button:hover { border-color: var(--accent); }
.dir-pick .center { background: #f3f5f8; color: var(--muted); font-weight: 400; font-size: 11px; cursor: default; }

.lw-preview { margin-top: 12px; border-radius: 12px; background: #eef7ee; padding: 12px; }
.lw-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #2a6b3e; font-weight: 700; margin-bottom: 8px; }
.lw-logo { width: 22px; height: 22px; border-radius: 6px; background: #19b45a; color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 800; }
.lw-bubble { background: #fff; border-radius: 12px; padding: 10px 12px; font-size: 13px; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); white-space: pre-wrap; }
.lw-bubble .lw-link { display: inline-block; margin-top: 6px; color: #1a73e8; font-weight: 600; }

.lightbox {
  position: fixed; inset: 0; z-index: 2100; background: rgba(8, 10, 16, .92); color: #fff;
  display: flex; flex-direction: column;
}
.lightbox .lb-top { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
.lightbox .lb-img { flex: 1; display: grid; place-items: center; padding: 8px; min-height: 0; }
.lightbox .lb-img img { max-height: 100%; max-width: 100%; object-fit: contain; border-radius: 6px; }
.lightbox .lb-info { padding: 12px 16px 20px; font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.lightbox .lb-nav { display: flex; gap: 8px; }
.lightbox button { background: rgba(255, 255, 255, .14); color: #fff; border: 0; border-radius: 8px; min-height: 40px; padding: 0 14px; cursor: pointer; font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 2200;
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: calc(100% - 32px);
}

/* ---------- settings ---------- */
.settings-grid { display: grid; gap: 14px; }
.settings-grid .card { padding: 16px; }
.plan-preview { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }

/* ---------- print / PDF ---------- */
.print-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.print-toolbar .sub { flex: 1 1 220px; }
.sheet {
  background: #fff; color: #111; width: 100%; max-width: 210mm; margin: 0 auto; padding: 12mm;
  box-shadow: var(--shadow); font-size: 11px; line-height: 1.5;
}
.sheet h1 { font-size: 18px; margin: 0; }
.sheet .doc-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid #111; padding-bottom: 6px; margin-bottom: 10px; gap: 12px; }
.sheet .stamp { display: grid; grid-template-columns: repeat(3, 18mm); border: 1px solid #333; text-align: center; font-size: 9px; }
.sheet .stamp div { border-left: 1px solid #333; }
.sheet .stamp div:first-child { border-left: 0; }
.sheet .stamp .lbl { border-bottom: 1px solid #333; padding: 1px 0; }
.sheet .stamp .box { height: 14mm; }
.sheet table { width: 100%; border-collapse: collapse; margin: 6px 0 10px; }
.sheet th, .sheet td { border: 1px solid #555; padding: 3px 5px; vertical-align: top; text-align: left; }
.sheet th { background: #eef0f3; font-weight: 700; white-space: nowrap; }
.sheet .plan-fig { position: relative; border: 1px solid #555; }
.sheet .plan-fig img { width: 100%; }
.sheet .plan-fig .pp {
  position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%;
  background: #e8772e; color: #fff; font-size: 10px; font-weight: 800; display: grid; place-items: center;
  border: 1.5px solid #fff; box-shadow: 0 0 0 1px #e8772e;
}
.sheet .sec-title { font-size: 13px; font-weight: 800; margin: 12px 0 4px; border-left: 4px solid #e8772e; padding-left: 6px; }
.sheet .fblock { break-inside: avoid; page-break-inside: avoid; border: 1px solid #999; padding: 6px; margin-bottom: 8px; }
.sheet .fblock .fhead { display: flex; gap: 6px; align-items: baseline; margin-bottom: 4px; }
.sheet .fblock .fno { font-weight: 800; color: #c0601f; }
.sheet .fblock .ftext { font-weight: 700; font-size: 12px; }
.sheet .fblock .fmeta { color: #444; font-size: 10px; margin-bottom: 4px; }
.sheet .pgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.sheet .pgrid figure { margin: 0; }
.sheet .pgrid img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border: 1px solid #ccc; }
.sheet .pgrid figcaption { font-size: 8.5px; color: #333; }
.sheet .page-break { break-before: page; page-break-before: always; }
.sheet .foot { margin-top: 8px; font-size: 9px; color: #666; }

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; }
  .no-print, .topbar, .mock-note, .print-toolbar, .fab, #toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .sheet { box-shadow: none; padding: 0; max-width: none; }
}

.status-line .pill, .finding-meta { white-space: normal; overflow-wrap: anywhere; }
.add-tiles .btn { flex: 1 1 auto; }
.patrol-list > *, .finding-list > * { min-width: 0; }
.submit-bar .btn { white-space: normal; min-width: 0; line-height: 1.3; }
.hero .btn:not(.primary) { color: var(--ink); }
