* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  background-color: #f4f6f9;
  color: #333;
  line-height: 1.5;
}

/* ヘッダー（上部固定） */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #ffffff;
  border-bottom: 1px solid #d9e0e7;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: #1e3a5f;
  color: #fff;
}

.header-top h1 {
  font-size: 1.15rem;
  font-weight: 600;
}

.controls-group {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}

.controls-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.controls-group select,
.controls-group input {
  padding: 5px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.9rem;
}

/* ツールバー */
.header-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: #f8fafc;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

#search-input {
  width: 240px;
  padding: 6px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.9rem;
}

.summary-box {
  background: #eef4ff;
  border: 1px solid #c7d9ff;
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 0.9rem;
}

.summary-box strong {
  color: #1d4ed8;
  font-size: 1.05rem;
}

.summary-box .divider {
  margin: 0 8px;
  color: #94a3b8;
}

/* ボタン */
.btn {
  padding: 7px 14px;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s;
}

.btn-primary {
  background: #2563eb;
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: #1d4ed8;
}
.btn-primary:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.btn-secondary {
  background: #fff;
  color: #334155;
  border-color: #cbd5e1;
}
.btn-secondary:hover {
  background: #f1f5f9;
}

.btn-danger-outline {
  background: #fff;
  color: #dc2626;
  border-color: #fca5a5;
}
.btn-danger-outline:hover {
  background: #fef2f2;
}

/* メインエリア */
/* メインエリア（左インデックス＋右一覧の2カラム） */
.app-main {
  max-width: 1360px;
  margin: 20px auto;
  padding: 0 16px 60px;
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

.main-content {
  flex: 1;
  min-width: 0;
}

/* 左サイドバー（市町村インデックス） */
.city-index {
  width: 260px;
  flex-shrink: 0;
  position: sticky;
  top: 120px; /* 上部固定ヘッダーの下に配置 */
  max-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  overflow: hidden;
}

.city-index-header {
  padding: 10px 12px;
  background: #1e3a5f;
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
}

.city-index-total {
  font-size: 0.8rem;
  font-weight: 500;
  color: #dbeafe;
  white-space: nowrap;
}

.city-index-list {
  list-style: none;
  overflow-y: auto;
  padding: 4px 0;
}

.city-index-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px;
  font-size: 0.84rem;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.12s;
}

.city-index-item:last-child {
  border-bottom: none;
}

.city-index-item:hover {
  background: #f1f5f9;
}

.city-index-item.has-selected {
  background: #eff6ff;
}

.city-index-name {
  font-weight: 600;
  color: #1e293b;
  white-space: nowrap;
}

.city-index-copies {
  font-size: 0.78rem;
  color: #64748b;
  white-space: nowrap;
}

.city-index-item.has-selected .city-index-copies {
  color: #1d4ed8;
  font-weight: 600;
}

/* ジャンプ時に上部ヘッダーで隠れないように余白を確保 */
.level-area1 {
  scroll-margin-top: 125px;
}

.status-message {
  text-align: center;
  padding: 40px;
  color: #64748b;
  font-size: 1rem;
}

/* アコーディオン階層 */
details {
  margin-bottom: 6px;
  border-radius: 6px;
  overflow: hidden;
}

summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
}

summary::-webkit-details-marker {
  display: none;
}

.summary-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.summary-title-group::before {
  content: "▶";
  font-size: 0.7rem;
  color: #64748b;
  transition: transform 0.15s;
}

details[open] > summary .summary-title-group::before {
  transform: rotate(90deg);
}

.summary-meta {
  font-size: 0.85rem;
  color: #475569;
}

/* 階層ごとの色分け */
.level-area1 {
  background: #fff;
  border: 1px solid #cbd5e1;
  margin-bottom: 10px;
}
.level-area1 > summary {
  background: #e2e8f0;
  font-size: 0.98rem;
}

.level-area2 {
  margin: 6px 10px;
  border: 1px solid #e2e8f0;
}
.level-area2 > summary {
  background: #f1f5f9;
  font-size: 0.92rem;
}

/* エリア行 */
.area-list {
  padding: 4px 12px 10px;
  background: #fff;
}

.area-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-bottom: 1px solid #f1f5f9;
  gap: 12px;
}

.area-row:last-child {
  border-bottom: none;
}

.area-row.is-selected {
  background-color: #eff6ff;
}

.area-row:has(.copies-input:focus) {
  background-color: #fef9c3;
}

.area-row.is-zero {
  opacity: 0.55;
}

.area-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  cursor: pointer;
}

.area-id {
  font-family: monospace;
  font-size: 0.8rem;
  color: #64748b;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 3px;
}

.area-name {
  font-size: 0.92rem;
}

.area-copies-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.max-copies-label {
  color: #64748b;
  min-width: 85px;
  text-align: right;
}

.copies-input {
  width: 85px;
  padding: 4px 6px;
  text-align: right;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.9rem;
}

.copies-input:disabled {
  background: #f8fafc;
  color: #94a3b8;
}

.hidden {
  display: none !important;
}
/* モード切替ボタン */
.mode-switch {
  display: inline-flex;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  overflow: hidden;
  margin-right: 6px;
}

.btn-mode {
  border: none;
  border-radius: 0;
  background: #fff;
  color: #475569;
  padding: 7px 12px;
}

.btn-mode.active {
  background: #1e3a5f;
  color: #fff;
}

/* マップ表示エリア */
.map-view-wrapper {
  width: 100%;
  height: calc(100vh - 115px);
  position: relative;
}

#map-container {
  width: 100%;
  height: 100%;
  z-index: 1;
}