/* ----------------------------------------------------------------
   style.css
   図書館利用可能区マップ スタイル
   フォント: Noto Sans JP（Google Fonts CDN）
   カラーパレット: 落ち着いた行政系ブルー × オフホワイト
---------------------------------------------------------------- */

/* リセット & ベース */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-primary:      #1E3A5F;
  --color-primary-mid:  #2563EB;
  --color-primary-lite: #DBEAFE;
  --color-green:        #16A34A;
  --color-green-lite:   #DCFCE7;
  --color-surface:      #F8F9FB;
  --color-border:       #D1D9E6;
  --color-text:         #1A202C;
  --color-text-muted:   #6B7280;
  --color-error:        #DC2626;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);

  --font-body: 'Noto Sans JP', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN',
               Meiryo, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;

  --sidebar-w: 340px;
  --header-h:  56px;
}

html, body {
  height: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-surface);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  /* Leaflet が地図を描画するにはhtml,bodyが高さを持っている必要がある */
  overflow: hidden;
}

/* ----------------------------------------------------------------
   レイアウト
---------------------------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;   /* ← 100%ではなくvhで確実に全画面 */
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 20px;
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
  z-index: 100;
  flex-shrink: 0;
}

header h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .03em;
}

header .header-sub {
  font-size: 12px;
  opacity: .75;
  margin-left: auto;
}

.layout {
  display: flex;
  flex: 1;
  min-height: 0;   /* ← flexアイテムがはみ出さないために必要 */
  overflow: hidden;
}

/* ----------------------------------------------------------------
   サイドバー
---------------------------------------------------------------- */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: #fff;
  border-right: 1px solid var(--color-border);
  z-index: 10;
}

.sidebar-section {
  padding: 20px;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-section:last-child {
  border-bottom: none;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 14px;
}

/* CSV出力ボタン付き見出し行 */
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.section-title-row .section-title { margin-bottom: 0; }

.btn-csv {
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-body);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  flex-shrink: 0;
}
.btn-csv:hover {
  border-color: var(--color-primary-mid);
  color: var(--color-primary-mid);
}

/* フォーム */
.form-group {
  margin-bottom: 16px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 6px;
}

.form-label span {
  font-weight: 400;
  color: var(--color-text-muted);
  font-size: 11px;
  margin-left: 4px;
}

.form-select {
  width: 100%;
  padding: 9px 32px 9px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236B7280' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 12px center;
  -webkit-appearance: none;
  appearance: none;
  font-size: 14px;
  font-family: var(--font-body);
  color: var(--color-text);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}

.form-select:focus {
  outline: none;
  border-color: var(--color-primary-mid);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

/* 都道府県切り替えボタン */
.pref-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pref-btn {
  padding: 6px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: 99px;
  background: var(--color-surface);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all .15s;
}

.pref-btn:hover {
  border-color: var(--color-primary-mid);
  color: var(--color-primary-mid);
}

.pref-btn--active {
  background: var(--color-primary-mid);
  border-color: var(--color-primary-mid);
  color: #fff;
}

/* ----------------------------------------------------------------
   検索条件表示行（サイドバー）
---------------------------------------------------------------- */
.cond-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 0.5px solid var(--color-border);
}
.cond-row:last-of-type { border-bottom: none; margin-bottom: 4px; }

.cond-label {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}
.cond-label--res  { background: #DCFCE7; color: #15803D; }
.cond-label--work { background: #FEF3C7; color: #B45309; }

.cond-value {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cond-edit-btn {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-body);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all .15s;
}
.cond-edit-btn:hover {
  border-color: var(--color-primary-mid);
  color: var(--color-primary-mid);
}

/* ----------------------------------------------------------------
   モーダル
---------------------------------------------------------------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay--open { display: flex; }

.modal-panel {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  width: min(860px, 100%);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text-primary);
  margin: 0;
}
.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  font-size: 16px;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 50%;
  transition: background .15s;
}
.modal-close:hover { background: var(--color-border); }

#modal-map {
  flex: 1;
  min-height: 380px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.modal-footer-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.modal-footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.modal-select-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.modal-select {
  flex: 1;
  min-width: 120px;
  max-width: 240px;
}
.modal-selected-name {
  font-size: 13px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
}
.modal-selected-name--res  { background: #DCFCE7; color: #15803D; }
.modal-selected-name--work { background: #FEF3C7; color: #B45309; }

/* モーダル内 都道府県選択バー */
.modal-pref-bar {
  display: flex;
  gap: 6px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.modal-pref-btn {
  padding: 5px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: 99px;
  background: var(--color-surface);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all .15s;
}
.modal-pref-btn:hover {
  border-color: var(--color-primary-mid);
  color: var(--color-primary-mid);
}
.modal-pref-btn--active {
  background: var(--color-primary-mid);
  border-color: var(--color-primary-mid);
  color: #fff;
}

/* モーダルローディング */
.modal-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 380px;
  font-size: 14px;
  color: var(--color-text-muted);
}


/* モーダル出典表記 */
.modal-attribution {
  padding: 5px 20px;
  font-size: 10px;
  color: var(--color-text-muted);
  border-top: 0.5px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}
.modal-attribution a {
  color: inherit;
  text-decoration: underline;
}

/* マーカー常時表示ラベル（図書館名） */
.marker-label {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
  pointer-events: none;
}
.marker-label::before { display: none; }

.geo-tooltip {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border: none;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}


/* トグルスイッチ */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text);
  user-select: none;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  background: var(--color-border);
  border-radius: 10px;
  transition: background .2s;
  flex-shrink: 0;
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.toggle-input:checked + .toggle-track {
  background: var(--color-primary-mid);
}

.toggle-input:checked + .toggle-track .toggle-thumb {
  transform: translateX(16px);
}

/* 分館バッジ */
.popup-branch {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
  background: #F3F4F6;
  color: #6B7280;
  margin-right: 2px;
}

/* ボタン */
.btn-group {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.btn {
  flex: 1;
  padding: 10px 0;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.btn:active { transform: scale(.98); }

.btn--primary {
  background: var(--color-primary-mid);
  color: #fff;
}
.btn--primary:hover { background: #1D4ED8; }
.btn--primary:disabled {
  background: #93C5FD;
  cursor: not-allowed;
  transform: none;
}

.btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1.5px solid var(--color-border);
}
.btn--ghost:hover {
  background: var(--color-surface);
  color: var(--color-text);
}

/* 結果パネル */
.result-count {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 12px;
}

.result-count strong {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-primary);
  margin-right: 4px;
}

.library-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.library-item {
  padding: 12px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color .15s, box-shadow .15s;
}

.library-item:hover {
  border-color: var(--color-primary-mid);
  box-shadow: var(--shadow-sm);
}

.library-item-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
}

.library-item-note {
  font-size: 11px;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.library-item-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--color-primary-mid);
  text-decoration: none;
}
.library-item-link:hover { text-decoration: underline; }

/* バッジ */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .03em;
  margin-left: 6px;
  vertical-align: middle;
}

.badge--green {
  background: var(--color-green-lite);
  color: var(--color-green);
}

.badge--blue {
  background: var(--color-primary-lite);
  color: var(--color-primary-mid);
}

/* エラー / ローディング */
.state-message {
  padding: 20px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 13px;
}

.state-message--error {
  color: var(--color-error);
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary-mid);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 凡例 */
.legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-row-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-text-muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-top: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--color-text-secondary);
}

.legend-item svg { flex-shrink: 0; }

.legend-colors {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.legend-color-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.15);
}

/* Leaflet divIcon のデフォルト白背景・枠線を無効化 */
.leaflet-div-icon {
  background: none !important;
  border: none !important;
}

/* 地図内凡例コントロール（右下） */
.map-legend {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 12px;
  box-shadow: var(--shadow-sm);
  min-width: 120px;
}

.map-legend-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.map-legend-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
  color: var(--color-text);
}

.map-legend-row svg { flex-shrink: 0; }

.map-legend-divider {
  border-top: 1px solid var(--color-border);
  margin: 7px 0;
}

.map-legend-dots {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.map-legend-dots span {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.12);
}

/* ----------------------------------------------------------------
   地図エリア
---------------------------------------------------------------- */
#map {
  flex: 1;
  min-height: 0;
  min-width: 0;    /* flex子要素の横方向の縮小も許可 */
  width: 100%;     /* Leafletが幅を認識するために明示 */
  height: 100%;
  z-index: 0;
}

/* Leaflet ポップアップのカスタマイズ */
.popup-content {
  min-width: 220px;
  max-width: 280px;
  font-family: var(--font-body);
  font-size: 13px;
}

.popup-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.popup-header strong {
  font-size: 14px;
  color: var(--color-primary);
}

.popup-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
}

.popup-badge--green {
  background: var(--color-green-lite);
  color: var(--color-green);
}

.popup-badge--blue {
  background: var(--color-primary-lite);
  color: var(--color-primary-mid);
}

.popup-note {
  font-size: 11px;
  color: var(--color-text-muted);
  line-height: 1.5;
  margin-bottom: 8px;
}

.popup-links a {
  font-size: 12px;
  color: var(--color-primary-mid);
  text-decoration: none;
}
.popup-links a:hover { text-decoration: underline; }

/* ----------------------------------------------------------------
   ユーティリティ
---------------------------------------------------------------- */
[x-cloak] { display: none !important; }

/* ----------------------------------------------------------------
   レスポンシブ（参考）
---------------------------------------------------------------- */
@media (max-width: 680px) {
  :root { --sidebar-w: 100%; }

  .layout {
    flex-direction: column;
  }

  #sidebar {
    width: 100%;
    max-height: 50vh;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
}
