/* スマートフォンでの利用を基本にした設計。
   地図を画面いっぱいに出し、検索・カテゴリは地図の上に浮かせ、一覧は下から引き出す（ボトムシート）。
   幅 900px 以上（PC）では、地図の右に一覧を並べる。 */
:root {
  --accent: #2e5e4e;      /* 二上山の緑 */
  --bg: #f6f5f1;
  --card: #ffffff;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2e0d8;
  --ok: #1b7f3b;
  --partial: #b26a00;
  --ng: #c62828;
  --unknown: #6b6b66;
  --warn-bg: #fff1d0;
  --warn-fg: #7a4b00;
  --notice-bg: #fff4d6;
  --shadow: 0 2px 8px rgba(0,0,0,.18);
  --sheet-h: 0px;         /* JS が一覧シートの高さを入れる */
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #7fb59e;
    --bg: #151614;
    --card: #1f201d;
    --fg: #ecebe6;
    --muted: #a3a29b;
    --line: #34352f;
    --ok: #5cc27e;
    --partial: #e0a040;
    --ng: #ff7070;
    --warn-bg: #3a3020;
    --warn-fg: #f0c060;
    --notice-bg: #3a3220;
    --shadow: 0 2px 8px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; height: 100%; overflow: hidden; }

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

button, select, input, textarea { font: inherit; }

/* ---------------------------------------------------------------- ヘッダー */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px 14px;
  background: #2e5e4e;
  color: #fff;
  flex: none;
}
.topbar h1 { margin: 0; font-size: 1.1rem; letter-spacing: .06em; }
.tagline { margin: 1px 0 0; font-size: .7rem; opacity: .85; }
.top-actions { display: flex; gap: 4px; }

.icon-btn {
  border: 0;
  background: rgba(255,255,255,.18);
  color: #fff;
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 1.1rem;
  font-weight: bold;
}

.banner {
  flex: none;
  background: var(--notice-bg);
  font-size: .75rem;
  padding: 4px 14px;
}

/* ---------------------------------------------------------------- いまの状況（1行ずつ） */
.live { flex: none; }
.live:empty { display: none; }
.live-row {
  display: block;
  padding: 7px 14px;
  font-size: .82rem;
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.live-row small { display: none; }
.live-row.warn { background: var(--warn-bg); color: var(--warn-fg); font-weight: 700; }
.live-row.notice { background: var(--notice-bg); white-space: normal; }
.live-row.muted { color: var(--muted); }

/* ---------------------------------------------------------------- 地図 */
.workspace { flex: 1; min-height: 0; position: relative; }
.map-wrap { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; background: #ddd; }

/* 地図の上に浮かぶ検索・カテゴリ */
.map-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 1050;
  padding: 8px 8px 0;
  pointer-events: none;
}
.map-top > * { pointer-events: auto; }

.toolbar {
  display: flex;
  gap: 6px;
  padding: 6px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.toolbar select, .toolbar input {
  min-width: 0;
  height: 40px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 16px;          /* 16px 未満だと iPhone で入力時に拡大されてしまう */
}
.toolbar select { max-width: 7.5em; }
.toolbar input { flex: 1; }
.refresh {
  flex: none;
  height: 40px;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: .78rem;
  padding: 0 8px;
}
.refresh.loading { opacity: .5; }

.cats {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 0 6px;
  scrollbar-width: none;
}
.cats::-webkit-scrollbar { display: none; }
.cat {
  flex: none;
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  border-radius: 18px;
  padding: 0 12px;
  font-size: .85rem;
  box-shadow: var(--shadow);
}
.cat .n { color: var(--muted); font-size: .72rem; margin-left: 3px; }
.cat.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.cat.active .n { color: rgba(255,255,255,.8); }

/* Leaflet の部品を、浮かせた検索と一覧シートに重ならない位置へ */
.map-wrap .leaflet-top { top: 106px; }
.map-wrap .leaflet-bottom { bottom: var(--sheet-h); transition: bottom .25s; }
.leaflet-control-layers-toggle { width: 44px !important; height: 44px !important; }
.leaflet-control-layers-expanded { font-size: .95rem; line-height: 2; }

.map-btn {
  position: absolute;
  right: 10px;
  bottom: calc(var(--sheet-h) + 26px);
  z-index: 900;
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 0;
  background: var(--card);
  color: var(--accent);
  font-size: 1.4rem;
  box-shadow: var(--shadow);
  transition: bottom .25s;
}
.map-btn.small { width: 40px; height: 40px; font-size: 1.1rem; bottom: 10px; }

.pin {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--unknown);
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
  transition: transform .15s;
}
.pin.ok { border-color: #1b7f3b; }
.pin.partial { border-color: #b26a00; }
.pin.ng { border-color: #c62828; }
.pin.stale { opacity: .55; }
.pin.sel { transform: scale(1.35); box-shadow: 0 0 0 4px rgba(46,94,78,.45); }

.shelter-pin {
  width: 24px; height: 24px;
  border-radius: 4px;
  background: #1565c0;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
}

.leaflet-popup-content { font-size: .9rem; line-height: 1.5; }
.popup-actions { display: flex; gap: 6px; margin-top: 8px; }
.leaflet-popup-content a.btn.primary, .leaflet-popup-content a.btn.primary:visited { color: #fff; }

/* ---------------------------------------------------------------- 一覧（ボトムシート） */
.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: var(--sheet-h);
  z-index: 1100;            /* Leaflet の部品（1000）より上 */
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -2px 12px rgba(0,0,0,.2);
  transition: height .25s;
}
.sheet.dragging, .sheet.dragging ~ * { transition: none; }

.sheet-grip { flex: none; touch-action: none; padding: 6px 12px 8px; cursor: grab; }
.grip-bar { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 6px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.count-btn {
  border: 0;
  background: none;
  color: var(--fg);
  font-weight: 700;
  font-size: 1rem;
  min-height: 44px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chev { font-size: .9rem; color: var(--muted); transition: transform .25s; }
.sheet[data-state="full"] .chev { transform: rotate(180deg); }
.post-btn {
  border: 0;
  border-radius: 24px;
  min-height: 46px;
  padding: 0 20px;
  background: #2e5e4e;
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: var(--shadow);
}

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px calc(24px + env(safe-area-inset-bottom));
}
.list-opts {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .85rem;
  color: var(--muted);
  padding: 0 0 8px;
}
.list-opts select { border: 0; background: transparent; color: var(--muted); font-size: .85rem; min-height: 36px; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  scroll-margin-top: 8px;
}
.card.stale { opacity: .7; }
.card.selected { border: 2px solid var(--accent); padding: 11px; }
.card-top { display: flex; gap: 10px; cursor: pointer; }
.card-icon { font-size: 1.7rem; line-height: 1; }
.card-main { flex: 1; min-width: 0; }
.card-name { font-weight: 700; font-size: 1.02rem; word-break: break-word; }
.card-meta { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.card-note { margin: 8px 0 0; font-size: .95rem; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }

.time { display: inline-block; margin-top: 8px; font-size: .85rem; font-weight: 700; }
.time.fresh { color: var(--ok); }
.time.old { color: var(--muted); }

.badge {
  flex: none;
  align-self: flex-start;
  font-size: .78rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  color: #fff;
}
.badge.ok { background: var(--ok); }
.badge.partial { background: var(--partial); }
.badge.ng { background: var(--ng); }
.badge.unknown { background: var(--unknown); }

.card-actions { display: flex; gap: 6px; margin-top: 10px; }
.card-actions .btn { flex: 1; white-space: nowrap; padding: 0 8px; }
.card-actions .btn.subtle { flex: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  border-radius: 10px;
  padding: 0 12px;
  text-decoration: none;
  font-size: .9rem;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.subtle { color: var(--muted); font-size: .8rem; }

.detail { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 10px; }
.history { list-style: none; margin: 0 0 10px; padding: 0; font-size: .9rem; }
.history li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.history .h-time { color: var(--muted); font-size: .78rem; margin-right: 6px; }
.history .h-status { font-weight: 700; margin-right: 6px; }

.append-form textarea, dialog input, dialog select, dialog textarea {
  width: 100%;
  margin-top: 4px;
  padding: 10px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font-size: 16px;
}

.status-pick { border: 0; padding: 0; margin: 12px 0 0; }
.status-pick legend { font-size: .9rem; padding: 0; }
.status-opts { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 8px; }
.status-opts label { display: inline-flex; margin: 0; }
.status-opts input { position: absolute; opacity: 0; width: 1px; }
.status-opts span {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 21px;
  padding: 0 16px;
  font-size: .92rem;
  cursor: pointer;
}
.status-opts input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.status-opts input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.empty { text-align: center; color: var(--muted); padding: 28px 0; font-size: .95rem; line-height: 1.7; }

/* ---------------------------------------------------------------- ダイアログ（スマホでは全画面） */
dialog {
  border: 0;
  border-radius: 14px;
  width: min(520px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  background: var(--card);
  color: var(--fg);
  padding: 16px 16px 0;
}
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h2 { margin: 0 0 4px; font-size: 1.15rem; }
dialog h3 { font-size: 1rem; margin: 16px 0 4px; }
dialog p { font-size: .95rem; line-height: 1.65; }
dialog ul { padding-left: 1.2em; margin: 0; font-size: .95rem; line-height: 1.9; }
dialog label { display: block; margin-top: 12px; font-size: .92rem; }
.links a { color: var(--accent); font-weight: 700; }
.hint { font-size: .8rem; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }
.hint.warn { color: var(--ng); }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.sticky-actions {
  position: sticky;
  bottom: 0;
  background: var(--card);
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.sticky-actions .btn { min-height: 48px; padding: 0 20px; font-size: 1rem; }
.sticky-actions .btn.primary { flex: 1; }

@media (max-width: 600px) {
  dialog:not(.ask) {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    padding: calc(14px + env(safe-area-inset-top)) 16px 0;
  }
}

/* 場所えらび（十字を合わせる） */
.pick-label { font-size: .92rem; margin-top: 10px; }
.pick-map-wrap { position: relative; height: 36vh; min-height: 200px; margin-top: 4px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
#pick-map { position: absolute; inset: 0; }
.crosshair {
  position: absolute;
  left: 50%; top: 50%;
  width: 40px; height: 40px;
  transform: translate(-50%, -50%);
  z-index: 500;
  pointer-events: none;
  background:
    linear-gradient(#c62828, #c62828) center / 3px 100% no-repeat,
    linear-gradient(#c62828, #c62828) center / 100% 3px no-repeat;
}
.pick-where { font-size: .95rem; font-weight: 700; margin-top: 6px; color: var(--ok); }
.pick-where.out { color: var(--ng); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sheet-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1200;
  background: #1d1d1b;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: .9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  width: max-content;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; }

/* ---------------------------------------------------------------- 災害時のための部品 */


.list-opts { flex-wrap: wrap; gap: 4px 12px; }
.opt { display: flex; align-items: center; gap: 6px; min-height: 36px; }
.opt input { width: 20px; height: 20px; }

.source-tag { font-size: .75rem; color: var(--muted); margin-left: 6px; }
.source-tag.heard { color: var(--partial); }

.same-btn { width: 100%; min-height: 48px; margin-bottom: 10px; font-weight: 700; }
.detail-actions { display: flex; gap: 6px; margin-bottom: 10px; }
.detail-actions .btn { flex: 1; }

/* 確認ダイアログ（スマホでも全画面にしない） */
dialog.ask {
  width: min(440px, calc(100% - 24px));
  height: fit-content;
  max-height: calc(100dvh - 24px);
  margin: auto;
  border-radius: 16px;
  padding: 18px 16px 14px;
}
.ask h2 { font-size: 1.1rem; }
.ask-buttons { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.ask-buttons .btn { min-height: 48px; font-size: 1rem; width: 100%; }
.btn.danger { background: #c62828; border-color: #c62828; color: #fff; font-weight: 700; }
.ask-cands { list-style: none; padding: 0; margin: 10px 0 0; }
.ask-cands li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.guide { line-height: 1.9; }

/* 上部の帯の「ほかに N件」 */
.live-more {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font-size: .78rem;
  padding: 4px 14px;
  text-align: right;
}

/* 一覧の見出しの「送信待ち」「送れなかった」 */
.pill {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  border-radius: 16px;
  min-height: 36px;
  padding: 0 10px;
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
}
.pill.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: transparent; }
.pill[hidden] { display: none; }
.sheet-head .post-btn { margin-left: auto; }

/* ピンの状態の記号（色だけに頼らない） */
.pin { position: relative; }
.pin-mark {
  position: absolute;
  right: -6px; bottom: -6px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid currentColor;
  font-size: 11px;
  font-weight: 800;
  line-height: 14px;
  text-align: center;
}
.pin.ok .pin-mark { color: #1b7f3b; }
.pin.partial .pin-mark { color: #b26a00; }
.pin.ng .pin-mark { color: #c62828; }
.pin.unknown .pin-mark { color: #6b6b66; }

/* 近くのピンのまとまり */
.cluster {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #2e5e4e;
  color: #fff;
  border: 3px solid #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  box-shadow: 0 1px 6px rgba(0,0,0,.35);
}

/* 信頼の目安 */
.trust-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.trust { font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.trust.many { background: var(--bg); color: var(--fg); border: 1px solid var(--line); }

.more-btn { width: 100%; min-height: 48px; }

/* ロボット対策の確認（必要なときだけ表示される） */
.turnstile-box {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1300;
}

/* ---------------------------------------------------------------- PC：地図の右に一覧 */
@media (min-width: 900px) {
  :root { --sheet-h: 0px !important; }
  .workspace { display: flex; }
  .map-wrap { position: relative; flex: 1; }
  .sheet {
    position: static;
    width: 440px;
    height: auto;
    border-radius: 0;
    box-shadow: none;
    border-left: 1px solid var(--line);
  }
  .grip-bar, .chev { display: none; }
  .sheet-grip { cursor: default; padding-top: 10px; }
  .live-row small { display: block; color: var(--muted); font-weight: normal; }
  .live-row { white-space: normal; }
}
