* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', sans-serif;
  height: 100vh;
  overflow: hidden;
}

/* ---- 共通ナビゲーションバー ---- */

#global-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: #1a1a2e;
  display: flex;
  align-items: center;
  gap: 0;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  padding: 0 12px;
}

.nav-brand {
  color: #a8b4f8;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding-right: 20px;
  border-right: 1px solid rgba(255,255,255,0.15);
  margin-right: 8px;
  white-space: nowrap;
}

.nav-link {
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 0.82rem;
  padding: 0 14px;
  height: 40px;
  display: flex;
  align-items: center;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.nav-link.active {
  background: #4361ee;
  color: #fff;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---- 右側コントロールパネル ---- */

#panel {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 220px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#panel h2 {
  font-size: 0.9rem;
  color: #1a1a2e;
  border-bottom: 2px solid #4361ee;
  padding-bottom: 6px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group label {
  font-size: 0.72rem;
  color: #555;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.85rem;
  background: #fff;
  cursor: pointer;
}

button {
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: #4361ee;
  color: white;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.2s;
}

button:hover {
  background: #3451d1;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.city-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.city-btn {
  background: #f0f4ff;
  color: #4361ee;
  border: 1px solid #c5d0f8;
}

.city-btn:hover {
  background: #dce4ff;
}

.info-box {
  background: #f5f5f5;
  border-radius: 6px;
  padding: 8px;
  font-size: 0.78rem;
  color: #333;
  line-height: 1.6;
  font-family: monospace;
}

/* ---- 左側レイヤパネル ---- */

#layer-panel {
  position: absolute;
  top: 100px; /* NavigationControl の下に配置 */
  left: 10px;
  width: 196px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 10;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

#layer-panel h3 {
  font-size: 0.78rem;
  color: #1a1a2e;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid #4361ee;
  padding-bottom: 6px;
  margin-bottom: 8px;
}

.layer-group {
  margin-bottom: 10px;
}

.layer-group-label {
  font-size: 0.68rem;
  color: #777;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  cursor: pointer;
  font-size: 0.82rem;
  color: #333;
  user-select: none;
}

.layer-row input[type="checkbox"] {
  cursor: pointer;
  flex-shrink: 0;
}

.layer-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid #aaa;
  flex-shrink: 0;
}

/* ---- 上部検索バー ---- */

#search-bar {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  z-index: 10;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 24px;
  padding: 6px 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  min-width: 320px;
  max-width: 480px;
  width: calc(100vw - 520px); /* 両パネルと重ならないよう */
}

#search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 0.88rem;
  color: #333;
  background: transparent;
  padding: 2px 4px;
}

#search-btn {
  padding: 4px 12px;
  font-size: 0.82rem;
  border-radius: 16px;
  flex-shrink: 0;
}

#search-clear-btn {
  padding: 4px 8px;
  font-size: 0.78rem;
  border-radius: 50%;
  background: #ccc;
  color: #333;
  flex-shrink: 0;
}

#search-clear-btn:hover {
  background: #aaa;
}

/* 検索結果マーカー */
.search-marker {
  width: 24px;
  height: 24px;
  background: #e63946;
  border: 3px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* ---- 計測ボタン（左下）---- */

#measure-btn {
  position: absolute;
  bottom: 60px;
  left: 10px;
  z-index: 10;
  padding: 8px 14px;
  font-size: 0.85rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

#measure-btn.active {
  background: #e63946;
}

#measure-btn.active:hover {
  background: #c1121f;
}

/* ---- 計測結果表示（下部中央）---- */

#measure-result {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.88rem;
  color: #333;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
  white-space: nowrap;
  pointer-events: none;
}

/* ---- ポップアップ ---- */

.popup-content {
  font-size: 0.82rem;
  line-height: 1.5;
  min-width: 180px;
}

.popup-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: #1a1a2e;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid #e0e0e0;
}

.popup-table {
  width: 100%;
  border-collapse: collapse;
}

.popup-table th,
.popup-table td {
  text-align: left;
  padding: 2px 4px;
  font-size: 0.8rem;
}

.popup-table th {
  color: #888;
  font-weight: 600;
  white-space: nowrap;
  width: 40%;
}

.popup-table td {
  color: #333;
}

.status-ok {
  color: #2a9d2a;
  font-weight: 600;
}

.status-warn {
  color: #e07020;
  font-weight: 600;
}

/* ---- Phase 2: 車両動態バー（上部左）---- */

#vehicle-bar {
  position: absolute;
  top: 16px;
  left: 216px; /* レイヤパネル右端より少し右 */
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(26, 26, 46, 0.88);
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.78rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#vehicle-updated {
  font-family: monospace;
  opacity: 0.9;
}

#vehicle-polling-btn {
  padding: 3px 10px;
  font-size: 0.75rem;
  border-radius: 12px;
  background: #4361ee;
}

#vehicle-polling-btn:hover {
  background: #3451d1;
}

/* ---- Phase 2: 災害受信票モーダル ---- */

#incident-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

#incident-modal-inner {
  background: #fff;
  border-radius: 12px;
  width: 480px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  overflow: hidden;
}

#incident-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: #1a1a2e;
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
}

#incident-modal-close {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
}

#incident-modal-close:hover {
  background: rgba(255,255,255,0.15);
}

#incident-modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #555;
}

.modal-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.82rem;
  color: #555;
}

.incident-id {
  font-size: 0.72rem;
  color: #999;
  font-family: monospace;
  margin-left: auto;
}

.incident-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
}

.incident-badge.incident-火災   { background: #c1121f; }
.incident-badge.incident-救急   { background: #e07020; }
.incident-badge.incident-風水害 { background: #0077cc; }

.modal-select {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.88rem;
  background: #fff;
}

/* 活動記録リスト */
.records-list {
  border: 1px solid #e8e8e8;
  border-radius: 6px;
  max-height: 160px;
  overflow-y: auto;
  font-size: 0.82rem;
}

.record-row {
  display: grid;
  grid-template-columns: 48px 72px 1fr;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid #f0f0f0;
  line-height: 1.4;
}

.record-row:last-child {
  border-bottom: none;
}

.record-time {
  font-family: monospace;
  color: #888;
  font-size: 0.78rem;
}

.record-author {
  color: #4361ee;
  font-weight: 600;
  font-size: 0.78rem;
}

.record-content {
  color: #333;
}

.record-empty {
  padding: 10px;
  color: #bbb;
  font-size: 0.82rem;
  text-align: center;
}

/* 活動記録フォーム */
.record-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.record-form-row {
  display: flex;
  gap: 6px;
}

.modal-input {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.85rem;
  flex: 1;
}

.modal-textarea {
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.85rem;
  resize: vertical;
  font-family: inherit;
}

.modal-btn-primary {
  padding: 8px 16px;
  background: #4361ee;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  align-self: flex-end;
}

.modal-btn-primary:hover {
  background: #3451d1;
}

/* ---- Phase 2: 障害サマリ（右パネル内）---- */

.badge {
  display: inline-block;
  background: #c1121f;
  color: #fff;
  border-radius: 10px;
  font-size: 0.7rem;
  padding: 1px 6px;
  margin-left: 4px;
  vertical-align: middle;
}

.obstacle-info {
  font-size: 0.78rem;
  line-height: 1.6;
}

.obstacle-info div {
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid #e8e8e8;
}

.obstacle-info div:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.obstacle-info small {
  color: #e07020;
}

/* ---- Phase 3: 分析ボタン群（左下）---- */

#analysis-btns {
  position: absolute;
  bottom: 110px;
  left: 10px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#analysis-btns button {
  padding: 7px 14px;
  font-size: 0.82rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  text-align: left;
}

#analysis-btns button.active {
  background: #e63946;
}

#analysis-btns button.active:hover {
  background: #c1121f;
}

/* ---- Phase 3: 出張所ピックアップ結果 ---- */

#pickup-result {
  position: absolute;
  bottom: 110px;
  left: 220px;
  z-index: 10;
  background: rgba(255,255,255,0.97);
  border-radius: 10px;
  padding: 10px 14px;
  min-width: 200px;
  max-width: 260px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  font-size: 0.82rem;
}

.pickup-header {
  font-weight: 700;
  font-size: 0.78rem;
  color: #4361ee;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #e8e8e8;
  padding-bottom: 6px;
  margin-bottom: 6px;
}

.pickup-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
  border-bottom: 1px solid #f0f0f0;
}

.pickup-row:last-child { border-bottom: none; }

.pickup-name {
  color: #1a1a2e;
  font-size: 0.82rem;
}

.pickup-dist {
  color: #ff6600;
  font-weight: 700;
  font-size: 0.78rem;
  font-family: monospace;
  margin-left: 8px;
  flex-shrink: 0;
}

.pickup-empty {
  color: #aaa;
  font-size: 0.82rem;
  text-align: center;
  padding: 8px 0;
}

#pickup-clear-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 4px;
  font-size: 0.78rem;
  background: #f0f0f0;
  color: #555;
  border-radius: 4px;
}

#pickup-clear-btn:hover { background: #e0e0e0; }

/* ---- Phase 3: 火災分析パネル（右側スライドイン）---- */

#stats-panel {
  position: absolute;
  top: 0;
  right: -320px; /* 初期は隠れている */
  width: 300px;
  height: 100vh;
  background: rgba(255,255,255,0.98);
  box-shadow: -4px 0 16px rgba(0,0,0,0.15);
  z-index: 20;
  display: flex;
  flex-direction: column;
  transition: right 0.3s ease;
  overflow-y: auto;
}

#stats-panel.open {
  right: 0;
}

.stats-panel-header {
  background: #1a1a2e;
  color: #fff;
  padding: 14px 16px;
  font-weight: 700;
  font-size: 0.92rem;
  flex-shrink: 0;
}

.stats-filter-row {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid #e8e8e8;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.stats-filter-row select {
  flex: 1;
  min-width: 80px;
  padding: 5px 8px;
  font-size: 0.82rem;
}

.stats-count {
  font-weight: 700;
  color: #e63946;
  font-size: 0.88rem;
  margin-left: auto;
  white-space: nowrap;
}

.chart-wrap {
  padding: 12px 14px;
  height: 200px;
  flex-shrink: 0;
}

.chart-wrap-sm {
  height: 180px;
}
