:root {
  --green:  #2e9e5b;
  --yellow: #e0a800;
  --orange: #e8730c;
  --red:    #d63b30;
  --purple: #8d4bd6;
  --blue:   #2f7fd6;
  --gray:   #8a8f98;
  --faint:  #c9ced6;
  --bg:     #f4f6f8;
  --card:   #ffffff;
  --text:   #1d2329;
  --muted:  #6b737c;
  --line:   #dfe3e8;
}

* { box-sizing: border-box; }

/* display を持つ要素にも hidden を効かせる */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

/* ---------- ログイン ---------- */
.login-view {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font-size: 20px; margin: 0 0 16px; }

/* ---------- レイアウト ---------- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: #1f6f45; color: #fff;
}
.brand { flex: 1; font-size: 15px; }
.icon-btn {
  background: rgba(255,255,255,.15); color: #fff; border: 0;
  border-radius: 6px; padding: 6px 10px; font-size: 13px;
}
.badge {
  background: var(--red); color: #fff; border-radius: 10px;
  padding: 2px 8px; font-size: 12px; font-weight: 700;
}

.tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; padding: 11px 4px; border: 0; background: none;
  font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent;
}
.tab.active { color: #1f6f45; font-weight: 700; border-bottom-color: #1f6f45; }

main { flex: 1; position: relative; overflow: hidden; }

.view { display: none; height: 100%; overflow-y: auto; }
.view.active { display: block; }
#view-map.active { display: flex; flex-direction: column; overflow: hidden; }

/* ---------- 地図 ---------- */
.map-wrap { flex: 1; position: relative; min-height: 200px; display: flex; }
#map { flex: 1; min-height: 200px; }

.locate-btn {
  /* Leafletの出典表示(右下)と重ならない高さに置く */
  position: absolute; right: 10px; bottom: 28px; z-index: 500;
  padding: 9px 13px; border: 1px solid var(--line); border-radius: 20px;
  background: rgba(255,255,255,.95); color: var(--text);
  font-size: 13px; font-weight: 700; box-shadow: 0 1px 5px rgba(0,0,0,.25);
}
.locate-btn:disabled { opacity: .5; }
.alerts { max-height: 30%; overflow-y: auto; background: var(--card); border-top: 1px solid var(--line); }
.alert-row {
  display: flex; gap: 8px; align-items: center;
  padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.alert-row .sev { font-weight: 700; }
.alert-row.critical .sev { color: var(--red); }
.alert-row.warn .sev { color: var(--orange); }

.legend {
  display: flex; flex-wrap: wrap; gap: 6px 12px;
  padding: 8px 12px; background: var(--card);
  border-top: 1px solid var(--line); font-size: 11px; color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* 地図マーカー */
.pin {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 11px; font-weight: 700;
}
.pin.square { border-radius: 4px; }
.pin-label {
  background: rgba(255,255,255,.9); border-radius: 3px;
  padding: 0 3px; font-size: 10px; white-space: nowrap;
  margin-top: 2px; text-align: center; color: var(--text);
}

/* ---------- リスト ---------- */
.list { padding: 10px; }
.row {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 11px 12px; margin-bottom: 8px; cursor: pointer;
}
.row-head { display: flex; align-items: center; gap: 8px; }
.row-title { font-weight: 700; font-size: 14px; flex: 1; }
.row-sub { color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.6; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 11px; padding: 2px 9px; font-size: 11px;
  font-weight: 700; color: #fff; white-space: nowrap;
}
.chip.green  { background: var(--green); }
.chip.yellow { background: var(--yellow); }
.chip.orange { background: var(--orange); }
.chip.red    { background: var(--red); }
.chip.purple { background: var(--purple); }
.chip.blue   { background: var(--blue); }
.chip.gray   { background: var(--gray); }
.chip.faint  { background: var(--faint); color: #55606b; }

.filters { display: flex; gap: 8px; align-items: center; padding: 10px 10px 0; flex-wrap: wrap; }
.filters select { padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.chk { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

/* ---------- カード・フォーム ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px; margin: 10px;
}
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
label input, label select, label textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--text);
}
button.primary {
  width: 100%; padding: 12px; border: 0; border-radius: 8px;
  background: #1f6f45; color: #fff; font-weight: 700;
}
button.secondary {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--text);
}
button.danger { background: var(--red); color: #fff; border: 0; }
/* Google Mapsナビ(v1.0)。外部アプリへ出るので他の操作と見た目を分ける。 */
button.nav {
  padding: 10px 14px; border: 0; border-radius: 8px;
  background: var(--blue); color: #fff; font-weight: 700;
}

.seg { display: flex; gap: 6px; margin-bottom: 12px; }
.seg-btn {
  flex: 1; padding: 8px; border: 1px solid var(--line);
  background: #fff; border-radius: 6px; font-size: 13px;
}
.seg-btn.active { background: #1f6f45; color: #fff; border-color: #1f6f45; }

.qr-area { margin-bottom: 12px; }
.qr-area button { width: 100%; padding: 10px; border: 1px solid var(--line); background: #fff; border-radius: 8px; }
#qr-video { width: 100%; border-radius: 8px; margin-top: 8px; background: #000; }

.gps-box { display: flex; gap: 8px; align-items: center; margin: 6px 0 10px; }
.gps-box button { padding: 9px 12px; border: 1px solid var(--line); background: #fff; border-radius: 8px; }

.hint  { font-size: 11px; color: var(--muted); margin: 4px 0; line-height: 1.6; }
.error { color: var(--red); font-size: 13px; }
.msg   { font-size: 13px; }
.msg.ok { color: var(--green); }

/* ---------- 詳細シート ---------- */
/* シート外をタップして閉じられるようにする背面 */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 1100;
  background: rgba(0,0,0,.35);
}
.sheet {
  position: fixed; inset: auto 0 0 0; max-height: 82vh;
  background: var(--card); border-radius: 14px 14px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,.2); z-index: 1200;
  display: flex; flex-direction: column;
}
/* 下方向にドラッグして閉じるためのつまみ */
.sheet-grip {
  flex: none; height: 20px; display: flex;
  align-items: center; justify-content: center;
  cursor: grab; touch-action: none;
}
.sheet-grip::before {
  content: ''; width: 40px; height: 4px; border-radius: 2px; background: var(--line);
}
.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 14px 12px; border-bottom: 1px solid var(--line);
}
.sheet-head strong { flex: 1; font-size: 15px; }
/* トップバーの .icon-btn は白文字なので、白いシート上では別スタイルを使う */
.sheet-close {
  flex: none; padding: 7px 12px; font-size: 13px; font-weight: 700;
  border: 1px solid var(--line); border-radius: 16px;
  background: var(--bg); color: var(--text);
}
.sheet-close:hover { background: #e8ebef; }
.sheet-body { overflow-y: auto; padding: 12px 14px calc(20px + env(safe-area-inset-bottom)); }

.kv { display: grid; grid-template-columns: 8.5em 1fr; gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.sheet-body h4 { margin: 16px 0 8px; font-size: 13px; }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.mini-list { font-size: 12px; }
.mini-list div { padding: 6px 0; border-bottom: 1px solid var(--line); }

/* ---------- 注意喚起ダイアログ ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1500; }
.modal {
  position: fixed; z-index: 1600;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(92vw, 460px); max-height: 86vh;
  background: var(--card); border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
  display: flex; flex-direction: column;
}
.modal h2 {
  margin: 0; padding: 14px 16px; font-size: 16px;
  border-bottom: 1px solid var(--line);
}
.modal-body { padding: 14px 16px; overflow-y: auto; font-size: 13px; line-height: 1.8; }
.modal-body p { margin: 0 0 10px; }
.modal-body ul { margin: 0 0 10px; padding-left: 1.2em; }
.modal-body li { margin-bottom: 6px; }
.notice-lead   { font-weight: 700; color: var(--orange); }
.notice-strong {
  background: #fdeceb; color: #a5271e; font-weight: 700;
  padding: 10px 12px; border-radius: 6px;
}
.modal-actions {
  display: flex; gap: 8px; padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.modal-actions button { flex: 1; width: auto; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: rgba(0,0,0,.85); color: #fff; padding: 10px 16px;
  border-radius: 20px; font-size: 13px; z-index: 2000; max-width: 90vw;
}

@media (min-width: 720px) {
  .list, .card { max-width: 760px; margin-left: auto; margin-right: auto; }
  .sheet { left: 50%; transform: translateX(-50%); width: 640px; border-radius: 14px 14px 0 0; }
}
