* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  position: fixed;
  overscroll-behavior: none;
}
#map { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }

/* Header */
#header {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: max(env(safe-area-inset-top), 8px) 12px 8px;
  background: linear-gradient(180deg, rgba(26, 58, 82, 0.95) 0%, rgba(26, 58, 82, 0.85) 70%, rgba(26, 58, 82, 0) 100%);
  color: #fff;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: auto;
}
.brand {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.05em;
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px 6px;
  margin: 0;
  font-family: inherit;
}
.brand:active { opacity: 0.7; }
.brand-en {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.12em;
  opacity: 0.75;
  margin-left: 4px;
}
.header-right {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-wrap: nowrap;
  min-width: 0;
}
#home-btn, #style-toggle-btn, #sidebar-btn, #heatmap-btn, #lasso-btn, #undo-btn, #reset-btn {
  background: rgba(255, 255, 255, 0.92);
  color: #1a3a52;
  border: none;
  padding: 6px 10px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  white-space: nowrap;
  flex-shrink: 0;
}
#home-btn:active, #style-toggle-btn:active, #sidebar-btn:active, #heatmap-btn:active, #lasso-btn:active, #undo-btn:active, #reset-btn:active { transform: scale(0.96); }

#undo-btn, #reset-btn {
  font-size: 16px;
  font-weight: 700;
  padding: 4px 9px;
}
#undo-btn:disabled, #reset-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
#reset-btn {
  background: #fff0e0;
  color: #c4500c;
}

#lasso-btn.active {
  background: #e85a3f;
  color: #fff;
}

#heatmap-btn.active {
  background: #e85a3f;
  color: #fff;
}

/* 市区町村ヒートマップ ポップアップ */
.muni-popup {
  padding: 6px 4px;
  text-align: center;
  font-family: inherit;
}
.muni-popup-name {
  font-size: 14px;
  font-weight: 700;
  color: #1a3a52;
  margin-bottom: 2px;
}
.muni-popup-pref {
  font-size: 11px;
  color: #888;
  margin-bottom: 6px;
}
.muni-popup-count {
  font-size: 12px;
  color: #2a3a48;
}
.muni-popup-count b {
  color: #e85a3f;
  font-size: 16px;
}

/* スタイルピッカー */
.style-picker { position: relative; }
#style-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: rgba(255, 255, 255, 0.98);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  min-width: 100px;
  display: none;
  overflow: hidden;
  z-index: 12;
}
#style-menu[aria-hidden="false"] { display: block; }
.style-option {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  padding: 9px 14px;
  font-size: 13px;
  color: #1a3a52;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.style-option:active { background: #f4f5f7; }
.style-option.active {
  background: #e8eef3;
  font-weight: 600;
}
.ym-row {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
  margin-bottom: 4px;
}
.ym-label {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 500;
  letter-spacing: 0.05em;
}
.header-right .ym-select {
  appearance: none;
  -webkit-appearance: none;
  background-color: rgba(255, 255, 255, 0.92);
  color: #1a3a52;
  border: none;
  padding: 6px 20px 6px 8px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%231a3a52'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  flex-shrink: 0;
}
.header-right .ym-select option {
  color: #1a3a52;
  background: #fff;
}
.ym-select {
  background: rgba(255, 255, 255, 0.18);
  color: white;
  border: none;
  padding: 5px 12px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='white'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}
.ym-select option {
  color: #1a3a52;
  background: #fff;
}

.period-picker {
  display: flex;
  gap: 6px;
  pointer-events: auto;
}
.period-picker button {
  flex: 1;
  padding: 8px 4px;
  border: none;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}
.period-picker button.active {
  background: #fff;
  color: #1a3a52;
}
.period-picker button:active {
  transform: scale(0.97);
}

/* 検索パネル(右下、候補は上方向に展開) */
#search-panel {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom), 20px);
  right: 12px;
  width: min(230px, calc(100% - 24px));
  z-index: 8;
  display: flex;
  flex-direction: column-reverse;
}
#search-input {
  width: 100%;
  padding: 9px 32px 9px 14px;
  border-radius: 20px;
  border: none;
  background: rgba(255, 255, 255, 0.95);
  font-size: 13px;
  color: #1a3a52;
  box-shadow: 0 1px 4px rgba(0,0,0,0.14);
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
}
#search-input:focus {
  background: #fff;
  box-shadow: 0 2px 8px rgba(26, 58, 82, 0.25);
}
#search-input::placeholder {
  color: #98a3ad;
}
#search-clear {
  position: absolute;
  right: 8px;
  top: 7px;
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(0,0,0,0.08);
  border-radius: 12px;
  color: #555;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#search-results {
  margin-bottom: 4px;
  background: rgba(255, 255, 255, 0.98);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  max-height: 50vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: none;
}
#search-results.open {
  display: block;
}
.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f1f3f5;
  font-size: 12px;
  color: #2a3a48;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:active { background: #f6f7f9; }
.search-result-name {
  font-size: 13px;
  font-weight: 600;
  color: #1a3a52;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.search-result-cat {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  color: #fff;
  font-weight: 500;
}
.search-result-cat-hospital { background: #d9534f; }
.search-result-cat-clinic { background: #f0ad4e; }
.search-result-cat-care { background: #5bc0de; }
.search-result-cat-visit { background: #5cb85c; }
.search-result-addr {
  color: #777;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-empty {
  padding: 14px;
  text-align: center;
  font-size: 12px;
  color: #888;
}

/* 紹介あり トグル */
#referral-filter {
  position: absolute;
  /* ヘッダー(safe-area + brand行 + period-picker行) の高さに合わせて動的に */
  top: calc(env(safe-area-inset-top, 0px) + 100px);
  left: 12px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 14px;
  padding: 6px 8px;
  z-index: 6;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  backdrop-filter: blur(8px);
}

/* 紹介フィルタ 3状態セグメント */
.segment-group {
  display: flex;
  gap: 2px;
  background: #eef0f3;
  border-radius: 10px;
  padding: 2px;
}
.segment {
  flex: 1;
  border: none;
  background: transparent;
  color: #6a7480;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.segment.active {
  background: #1a3a52;
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.segment:active {
  transform: scale(0.97);
}
.toggle-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  color: #1a3a52;
  font-weight: 500;
}
.toggle-switch input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 32px;
  height: 18px;
  background: #d4d8de;
  border-radius: 9px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  margin: 0;
}
.toggle-switch input[type="checkbox"]::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.toggle-switch input[type="checkbox"]:checked {
  background: #1a3a52;
}
.toggle-switch input[type="checkbox"]:checked::after {
  transform: translateX(14px);
}

/* 施設追加フォーム */
.field-label {
  display: block;
  font-size: 12px;
  color: #555;
  font-weight: 600;
  margin: 10px 0 4px;
}
.field-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d4d8de;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  box-sizing: border-box;
}
.field-input:focus {
  outline: none;
  border-color: #1a3a52;
}
.field-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.field-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.field-btn-cancel {
  background: #f0f1f3;
  color: #555;
}
.field-btn-submit {
  background: #1a3a52;
  color: #fff;
}
.field-btn-delete {
  width: 100%;
  margin-top: 10px;
  background: transparent;
  color: #d9534f;
  border: 1px solid #d9534f;
}
.field-btn-delete:active {
  background: rgba(217, 83, 79, 0.08);
}

/* 紹介数履歴 編集 */
.referrals-section {
  margin: 14px 0 4px;
  padding-top: 14px;
  border-top: 1px solid #eee;
}
.referrals-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
  font-size: 13px;
}
.referrals-row .ref-ym {
  min-width: 80px;
  color: #555;
  font-variant-numeric: tabular-nums;
}
.referrals-row .ref-count {
  width: 70px;
  padding: 5px 8px;
  border: 1px solid #d4d8de;
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
  text-align: right;
}
.referrals-row .ref-del {
  background: transparent;
  color: #d9534f;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
}
.referrals-row .ref-del:active { background: rgba(217, 83, 79, 0.1); border-radius: 4px; }
.referrals-empty {
  color: #999;
  font-size: 12px;
  padding: 4px 0;
}
.field-status {
  margin-top: 10px;
  font-size: 12px;
  text-align: center;
}
.field-status.success { color: #2c7a2c; }
.field-status.error { color: #e53935; }

/* About / 施設追加 / 編集 / 紹介数追加 / トレンド モーダル共通 */
#about-modal,
#add-facility-modal,
#edit-facility-modal,
#add-referral-modal,
#trend-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
}
#about-modal[aria-hidden="false"],
#add-facility-modal[aria-hidden="false"],
#edit-facility-modal[aria-hidden="false"],
#add-referral-modal[aria-hidden="false"],
#trend-modal[aria-hidden="false"] {
  display: flex;
}

/* ポップアップ内 紹介数追加 / 編集ボタン */
.popup-edit-row {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}
.popup-add-ref-btn,
.popup-edit-btn {
  flex: 1;
  padding: 8px 4px;
  background: #f4f5f7;
  color: #1a3a52;
  border: 1px solid #d4d8de;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.popup-add-ref-btn:active,
.popup-edit-btn:active { background: #e4e7ec; }

.popup-trend-btn {
  flex: 1;
  padding: 8px 4px;
  background: #fff4d6;
  color: #1a3a52;
  border: none;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.popup-trend-btn:active { background: #ffe4a8; transform: scale(0.97); }

/* トレンドモーダル */
.trend-modal-content {
  width: min(700px, calc(100% - 24px));
  max-width: 100%;
}
.trend-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0;
}
.trend-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #1a3a52;
  font-weight: 600;
}
.trend-legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}
.trend-chart {
  width: 100%;
  margin-bottom: 8px;
}
.trend-chart svg.trend-svg {
  width: 100%;
  height: auto;
  display: block;
}
.trend-empty {
  display: none;
  padding: 36px 20px;
  text-align: center;
  color: #888;
  font-size: 13px;
}
.trend-empty.show { display: block; }
.trend-note {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
  line-height: 1.5;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}
.modal-content {
  position: relative;
  background: #fff;
  border-radius: 16px;
  max-width: 480px;
  width: calc(100% - 32px);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  -webkit-overflow-scrolling: touch;
}
#about-close {
  position: sticky;
  top: 10px;
  float: right;
  margin: 10px 12px 0 0;
  background: rgba(0, 0, 0, 0.05);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 16px;
  font-size: 15px;
  color: #555;
  cursor: pointer;
  z-index: 2;
}
.modal-body {
  padding: 14px 22px 28px;
  color: #2a3a48;
  font-size: 14px;
  line-height: 1.7;
}
.modal-body h2 {
  font-size: 22px;
  margin: 0 0 12px;
  color: #1a3a52;
  font-weight: 700;
}
.modal-en {
  font-size: 14px;
  font-weight: 400;
  opacity: 0.7;
  letter-spacing: 0.12em;
  margin-left: 8px;
}
.modal-lead {
  font-size: 15px;
  color: #1a3a52;
  font-weight: 500;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid #eee;
}
.modal-body p { margin: 0 0 14px; }
.modal-body ul {
  padding-left: 20px;
  margin: 14px 0 18px;
}
.modal-body li {
  margin-bottom: 10px;
}
.modal-body b { color: #1a3a52; }

/* Legend */
#legend {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom), 20px);
  left: 12px;
  background: rgba(255, 255, 255, 0.95);
  padding: 10px 14px;
  border-radius: 11px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  font-size: 13px;
  z-index: 5;
  backdrop-filter: blur(8px);
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 3px 0;
  color: #333;
  font-weight: 500;
}
.legend-toggle {
  cursor: pointer;
  user-select: none;
  padding: 5px 7px;
  margin: 1px -7px;
  border-radius: 7px;
  transition: background 0.12s ease;
}
.legend-toggle:active {
  background: rgba(0, 0, 0, 0.06);
}
.legend-toggle.off {
  color: #bbb;
}
.legend-toggle.off .dot {
  opacity: 0.25;
}
.dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1.5px solid #fff;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}
.dot-hospital { background: #d9534f; }
.dot-clinic { background: #f0ad4e; }
.dot-care { background: #5bc0de; }
.dot-visit { background: #5cb85c; }

.legend-sep {
  border-top: 1px solid #e0e0e0;
  margin: 6px 0 4px;
}
.diff-label {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 26px;
  text-align: left;
  letter-spacing: -0.02em;
}
.diff-up { color: #e53935; }
.diff-down { color: #1976d2; }

/* UI 非表示トグルボタン(現在地ボタンの下あたり) */
#hide-ui-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 250px);
  right: 10px;
  width: 29px;
  height: 29px;
  background: #fff;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  color: #333;
  cursor: pointer;
  z-index: 6;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.1);
  font-family: inherit;
}
@media (max-width: 500px) {
  #hide-ui-btn {
    top: calc(env(safe-area-inset-top, 0px) + 230px);
  }
}
#hide-ui-btn:active { background: #f0f1f3; }
body.ui-hidden #hide-ui-btn {
  background: #1a3a52;
  color: #fff;
}

/* UI 非表示時の対象要素 */
#header, #search-panel, #referral-filter, #legend {
  transition: opacity 0.3s ease, transform 0.3s ease;
}
body.ui-hidden #header,
body.ui-hidden #search-panel,
body.ui-hidden #referral-filter,
body.ui-hidden #legend {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95);
}

/* Popup (ゆる〜と 風: ヘッダー帯 + アクションボタン列 + ボディ) */
.maplibregl-popup-content {
  padding: 0 !important;
  border-radius: 12px;
  overflow: hidden;
  min-width: 260px;
  max-width: 320px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}
.popup-card { padding: 0; }
.popup-header {
  padding: 10px 14px;
}
.popup-header h3 {
  margin: 0;
  font-size: 15px;
  color: white;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.popup-header-hospital { background: #d9534f; }
.popup-header-clinic { background: #f0ad4e; }
.popup-header-care { background: #5bc0de; }
.popup-header-visit { background: #5cb85c; }

.popup-actions {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid #eee;
}
.popup-btn {
  flex: 1;
  min-width: 0;
  padding: 7px 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  background: #f4f5f7;
  border: none;
  border-radius: 6px;
  color: #1a3a52;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  font-family: inherit;
}
.popup-btn:active { background: #e4e7ec; }
.popup-btn.disabled {
  color: #c0c4cc;
  pointer-events: none;
  background: #fafafa;
}
.popup-btn.fav-active {
  background: #fff3cd;
  color: #d97706;
}

.popup-body { padding: 10px 14px 14px; }
.popup-cat {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  color: #fff;
  margin-bottom: 6px;
  font-weight: 500;
}
.popup-cat-hospital { background: #d9534f; }
.popup-cat-clinic { background: #f0ad4e; }
.popup-cat-care { background: #5bc0de; }
.popup-cat-visit { background: #5cb85c; }
.popup-addr {
  font-size: 12px;
  color: #555;
  margin-bottom: 4px;
  line-height: 1.4;
}
.popup-phone {
  font-size: 12px;
  color: #333;
}
.popup-body hr {
  border: none;
  border-top: 1px solid #eee;
  margin: 12px 0 10px;
}
.popup-section {
  font-size: 11px;
  color: #888;
  margin-bottom: 6px;
  letter-spacing: 0.05em;
}
.popup-table {
  width: 100%;
  font-size: 13px;
  border-collapse: collapse;
}
.popup-table td {
  padding: 4px 0;
  color: #333;
}
.popup-table td.num {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}
.popup-masked {
  font-size: 11px;
  color: #999;
  margin-top: 8px;
  font-style: italic;
}

/* --- サイドバー (一覧 / お気に入り) ---------------- */
#sidebar {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}
#sidebar[aria-hidden="false"] { pointer-events: auto; }

.sidebar-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.2s;
}
#sidebar[aria-hidden="false"] .sidebar-backdrop { opacity: 1; }

.sidebar-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 100%);
  background: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
  transform: translateX(100%);
  transition: transform 0.25s ease-out;
}
#sidebar[aria-hidden="false"] .sidebar-panel { transform: translateX(0); }

.sidebar-header {
  display: flex;
  align-items: stretch;
  background: #1a3a52;
  color: #fff;
  padding-top: env(safe-area-inset-top);
}
.sidebar-tabs {
  display: flex;
  flex: 1;
  padding-left: 8px;
}
.sidebar-tab {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-family: inherit;
  letter-spacing: 0.03em;
}
.sidebar-tab.active {
  color: #fff;
  border-bottom-color: #fff;
}
.sidebar-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  padding: 0 16px;
}

.sidebar-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid #eef0f3;
  background: #f7f8fa;
  font-size: 12px;
  color: #555;
}
.sidebar-sort {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid #d6dade;
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
  background: #fff;
  color: #1a3a52;
}
.sidebar-count {
  color: #888;
  font-size: 11px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid #f1f3f5;
  cursor: pointer;
}
.sidebar-row:active { background: #f6f7f9; }
.sidebar-row-main {
  flex: 1;
  min-width: 0;
}
.sidebar-row-name {
  font-size: 13px;
  font-weight: 600;
  color: #1a3a52;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sidebar-row-addr {
  color: #777;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-row-count {
  font-size: 15px;
  font-weight: 700;
  color: #1a3a52;
  text-align: right;
  flex-shrink: 0;
  min-width: 36px;
  font-variant-numeric: tabular-nums;
}
.sidebar-row-count.muted {
  color: #c0c5cc;
  font-weight: 500;
}
.sidebar-empty {
  padding: 36px 24px;
  text-align: center;
  color: #888;
  font-size: 13px;
  line-height: 1.7;
}

/* MapLibre 上部コントロール(ズーム / 現在地) の位置 ― PWA でも確実に重ならない値で固定 */
.maplibregl-ctrl-top-right,
.maplibregl-ctrl-top-left {
  top: calc(env(safe-area-inset-top, 0px) + 102px) !important;
}
@media (max-width: 500px) {
  .maplibregl-ctrl-top-right,
  .maplibregl-ctrl-top-left {
    top: calc(env(safe-area-inset-top, 0px) + 82px) !important;
  }
}

/* ===== モバイル用 (iPhone Pro Max 等 ≤ 500px) ヘッダーをさらにコンパクト化 ===== */
@media (max-width: 500px) {
  .brand { font-size: 16px; padding: 4px 4px; }
  .brand-en { display: none; }
  .header-right { gap: 4px; }
  #home-btn, #style-toggle-btn, #sidebar-btn, #heatmap-btn, #lasso-btn, #undo-btn, #reset-btn {
    padding: 5px 7px;
    font-size: 11px;
    border-radius: 14px;
  }
  .header-right .ym-select {
    padding: 5px 18px 5px 6px;
    font-size: 11px;
    border-radius: 14px;
  }
  .period-picker { gap: 4px; }
  .period-picker button {
    font-size: 12px;
    padding: 7px 2px;
  }
}

