/* ── Base Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 16px; }
#map { width: 100%; height: 100%; }

/* ── Auth Gate ─────────────────────────────────────────── */
#auth-gate {
  display: none;
  position: fixed; inset: 0;
  z-index: 9999;
  background: #f5f3ef;
  justify-content: center; align-items: center;
  flex-direction: column;
  text-align: center;
  padding: 24px;
}
#auth-gate.visible { display: flex; }
#auth-gate h1 { font-family: 'EB Garamond', Georgia, serif; font-size: 28px; margin: 0 0 12px; color: #1a1a1a; }
#auth-gate p { font-size: 16px; color: #555; margin: 0 0 24px; max-width: 400px; line-height: 1.5; }
#auth-gate a {
  display: inline-block;
  padding: 12px 28px;
  background: #2c5282;
  color: #fff;
  text-decoration: none;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 600;
}
#auth-gate a:hover { background: #1a365d; }

/* ── Top Bar (Hamburger + Search) ──────────────────────── */
#top-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1200;
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  height: 48px;
  max-width: 408px;
  width: calc(100% - 24px);
}
#hamburger-btn {
  background: none;
  border: none;
  border-right: 1px solid #e0e0e0;
  width: 48px;
  height: 48px;
  font-size: 20px;
  cursor: pointer;
  color: #5f6368;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 8px 0 0 8px;
}
#hamburger-btn:hover { background: #f1f3f4; }
#search-container {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}
#place-search {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  padding: 8px 12px;
  background: transparent;
  min-width: 0;
}
#search-button {
  background: none;
  border: none;
  width: 44px;
  height: 44px;
  cursor: pointer;
  color: #4285f4;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 0 8px 8px 0;
}
#search-button:hover { background: #f1f3f4; }

/* ── Search Results ────────────────────────────────────── */
#search-results {
  position: absolute;
  top: 64px;
  left: 12px;
  background: #fff;
  width: 408px;
  max-width: calc(100% - 24px);
  max-height: 300px;
  overflow-y: auto;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  display: none;
  z-index: 1300;
}
.search-result-item {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
  font-size: 14px;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.search-result-item:hover { background: #f8f9fa; }
.search-result-item:last-child { border-bottom: none; }
.no-results { padding: 12px 16px; color: #666; font-style: italic; line-height: 1.5; }
.no-results a { color: #1a73e8; text-decoration: none; font-style: normal; font-weight: 500; }
.no-results a:hover { text-decoration: underline; }

/* ── Explore Chips ──────────────────────────────────────── */
#explore-chips {
  position: absolute;
  top: 12px;
  left: 432px;
  z-index: 1200;
  display: flex;
  gap: 8px;
  height: 48px;
  align-items: center;
}
.explore-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: none;
  border-radius: 24px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #3c4043;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  white-space: nowrap;
  transition: background 0.15s, box-shadow 0.15s;
}
.explore-chip:hover {
  background: #f8f9fa;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.explore-chip svg { color: #5f6368; flex-shrink: 0; }

/* ── Bible Map Title Overlay ───────────────────────────── */
#bible-map-title-overlay {
  display: none;
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  z-index: 1100;
  pointer-events: none;
  font-family: 'EB Garamond', Georgia, serif;
}
#bible-map-title-overlay .bm-title {
  font-size: 26px;
  font-weight: bold;
  color: #1a1a1a;
  text-shadow: 0 1px 3px rgba(255,255,255,0.8);
  margin: 0;
  line-height: 1.2;
}
#bible-map-title-overlay .bm-subtitle {
  font-size: 17px;
  font-weight: normal;
  color: #444;
  text-shadow: 0 1px 3px rgba(255,255,255,0.8);
  margin: 2px 0 0;
  line-height: 1.2;
}

/* ── Side Panel ────────────────────────────────────────── */
#side-panel {
  position: absolute;
  top: 0;
  left: -380px;
  width: 380px;
  height: 100%;
  background: #fff;
  box-shadow: 2px 0 8px rgba(0,0,0,0.2);
  z-index: 1400;
  transition: left 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#side-panel.open { left: 0; }
#panel-header {
  display: flex;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
  min-height: 56px;
}
#panel-header h3 {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 500;
  color: #202124;
  padding: 0 4px;
}
#panel-back-btn, #panel-close-btn {
  background: none;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #5f6368;
  flex-shrink: 0;
}
#panel-back-btn:hover, #panel-close-btn:hover { background: #f1f3f4; }
#panel-body {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.panel-view {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
}
.panel-view.active { display: block; }
#panel-scripture.active {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Menu Items ────────────────────────────────────────── */
.menu-item {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  gap: 16px;
  transition: background 0.15s;
}
.menu-item:hover { background: #f8f9fa; }
.menu-icon { color: #5f6368; flex-shrink: 0; display: flex; align-items: center; }
.menu-text { flex: 1; min-width: 0; }
.menu-label { display: block; font-size: 15px; font-weight: 500; color: #202124; }
.menu-desc { display: block; font-size: 13px; color: #5f6368; margin-top: 2px; }
.menu-chevron { color: #dadce0; flex-shrink: 0; }

/* ── Bible Map List ────────────────────────────────────── */
.bible-map-item {
  padding: 14px 20px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.15s;
}
.bible-map-item:hover { background: #f8f9fa; }
.bible-map-item.selected {
  background: #e8f0fe;
  border-left: 3px solid #1a73e8;
  padding-left: 17px;
}
.bm-item-name { display: block; font-size: 14px; font-weight: 500; color: #202124; }
.bm-item-subtitle { display: block; font-size: 12px; color: #5f6368; margin-top: 2px; }
.bible-map-none { border-bottom: 2px solid #e0e0e0; }

/* ── Scripture Panel ───────────────────────────────────── */
#time-period-list-container {
  padding: 10px 12px;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}
.time-period-item {
  padding: 6px 10px;
  margin-bottom: 3px;
  cursor: pointer;
  border-radius: 20px;
  border: 1px solid #dadce0;
  background: #f8f9fa;
  font-size: 13px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}
.time-period-item:hover { background: #e8eaed; border-color: #bdc1c6; }
.time-period-item.selected-period {
  background: #d2e3fc;
  color: #1a73e8;
  border-color: #1a73e8;
  font-weight: 600;
}
.time-period-item.selected-period .tp-check::after { content: '\2713'; }
.tp-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1.5px solid #9aa0a6;
  font-size: 11px;
  color: transparent;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.selected-period .tp-check {
  border-color: #1a73e8;
  background: #1a73e8;
  color: #fff;
}
.tp-hint {
  font-size: 14px;
  font-weight: 600;
  color: #202124;
  margin-bottom: 10px;
  line-height: 1.4;
}
.ch-hint {
  font-size: 14px;
  font-weight: 600;
  color: #202124;
  line-height: 1.4;
  margin: 0 0 8px;
  font-style: normal;
}
.tp-deselect {
  font-size: 12px;
  color: #5f6368;
  border-color: transparent;
  background: transparent;
}
.tp-deselect:hover { background: #f1f3f4; }
#chapter-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px;
}
.chapter-item {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
  min-height: 44px;
  gap: 8px;
}
.chapter-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  accent-color: #1a73e8;
}
.chapter-item label {
  cursor: pointer;
  font-size: 14px;
}
#deselect-all-chapters-btn {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid #dadce0;
  border-radius: 6px;
  background: #f8f9fa;
  min-height: 44px;
  width: 100%;
  margin-bottom: 8px;
  transition: background 0.15s;
}
#deselect-all-chapters-btn:hover { background: #e8eaed; }

/* ── Panel Backdrop ────────────────────────────────────── */
#panel-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1350;
}
#panel-backdrop.visible { display: block; }

/* ── Map Text Boxes (read-only) ────────────────────────── */
.map-text-box {
  background: rgba(255,255,255,0.9);
  padding: 5px 8px;
  border: 1px solid rgba(170,170,170,0.8);
  border-radius: 8px;
  font-family: sans-serif;
  font-size: 14px;
  max-width: 200px;
  word-wrap: break-word;
  pointer-events: none;
  user-select: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  white-space: pre-wrap;
}

/* ── Label Markers (read-only) ─────────────────────────── */
.label-marker-circle {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: bold;
  color: #fff;
  user-select: none;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  border: 2px solid rgba(255,255,255,0.8);
  pointer-events: none;
}

/* ── Scale Control Styles ──────────────────────────────── */
.maplibregl-ctrl-scale {
  background-color: rgba(255,255,255,0.8);
  border-color: rgba(0,0,0,0.2);
  margin-bottom: 10px !important;
  font-family: sans-serif;
  border-radius: 2px;
}

/* ── North Arrow ───────────────────────────────────────── */
.maplibregl-ctrl-north-arrow {
  display: block;
  width: 30px;
  height: 30px;
  background-color: rgba(255,255,255,0.8);
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.1);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.1);
  cursor: pointer;
  position: relative;
}
.north-arrow-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

/* ── Map Text Annotations ───────────────────────────────── */
.map-text-annotation {
  pointer-events: none;
  user-select: none;
  white-space: pre-wrap;
  text-shadow: 0 0 4px white, 0 0 4px white, 0 0 2px white;
  line-height: 1.3;
}

/* ── Mobile Responsive ─────────────────────────────────── */
@media (max-width: 640px) {
  #top-bar {
    top: 8px;
    left: 8px;
    right: 8px;
    max-width: none;
    width: auto;
  }
  #search-results {
    top: 60px;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
  }
  #side-panel { width: 100vw; left: -100vw; }
  #explore-chips { display: none; }
  #bible-map-title-overlay { top: 68px; }
  #bible-map-title-overlay .bm-title { font-size: 20px; }
  #bible-map-title-overlay .bm-subtitle { font-size: 14px; }
}
@media (min-width: 641px) {
  #panel-backdrop { display: none !important; }
}

/* ── Clear Map Dialog ──────────────────────────────────── */
#clear-map-dialog {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.5);
  justify-content: center;
  align-items: center;
}
#clear-map-dialog.visible { display: flex; }
.dialog-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 340px;
  width: calc(100% - 48px);
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
}
.dialog-box p {
  margin: 0 0 20px;
  font-size: 15px;
  line-height: 1.5;
  color: #202124;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.dialog-actions button {
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  min-height: 40px;
}
#dialog-hide-map {
  background: #f1f3f4;
  color: #202124;
}
#dialog-hide-map:hover { background: #e8eaed; }
#dialog-keep-map {
  background: #1a73e8;
  color: #fff;
}
#dialog-keep-map:hover { background: #1557b0; }
