/* ─────────────────────────────────────────────────────────────
   GGV v2 — base layout & structure
   Single-panel design: map fills the canvas, one floating panel
   on the right that switches between LIST and DETAIL views.
   Themes cascade on top. Container queries + @media for iframe
   and mobile responsiveness.
   ───────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }
body {
  font-family: var(--font-body, 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif);
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg, #1a1d23);
  background: var(--bg, #fff);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img { max-width: 100%; height: auto; display: block; }
button { font: inherit; cursor: pointer; }
a { color: var(--accent, #002B54); }

/* ───────── App shell ───────── */

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header"
    "map";
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  container-type: inline-size;
  container-name: app;
}

.app__header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border, #e6e6e6);
  background: var(--header-bg, var(--bg, #fff));
  gap: 16px;
  z-index: 10;
}

/* When embedded in an iframe, hide our own brand header — the parent
   page already has its title. Gives back vertical space to the map. */
html.is-embedded .app {
  grid-template-rows: 1fr;
  grid-template-areas: "map";
}
html.is-embedded .app__header { display: none; }

.app__map {
  grid-area: map;
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--map-bg, #C5E0EB);
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--map-bg, #C5E0EB);
}
.leaflet-container { background: transparent !important; }

/* ───────── Header bits ───────── */

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.brand__title {
  font-family: var(--font-display, var(--font-body));
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
.brand__sub {
  font-size: 12px;
  opacity: 0.65;
}

/* ───────── Floating panel (the single right-side dock) ───────── */

.panel {
  position: absolute;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: min(440px, calc(100% - 32px));
  background: var(--panel-bg, var(--bg, #fff));
  color: var(--fg, #14181F);
  border: 1px solid var(--border, #e6e6e6);
  border-radius: 14px;
  box-shadow: 0 10px 36px rgba(0, 30, 60, 0.14), 0 2px 8px rgba(0, 30, 60, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 5;
  transition: transform 0.32s cubic-bezier(.22, .61, .36, 1),
              opacity 0.22s ease;
  transform-origin: top right;
}

.app[data-panel-state="closed"] .panel {
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;
}

/* Floating "Browse" button shows only when panel is closed */
#open-panel { display: none; }
.app[data-panel-state="closed"] #open-panel { display: inline-flex; }

/* ───────── Panel toolbar ───────── */

.panel__toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border, #e6e6e6);
  background: var(--panel-toolbar-bg, var(--bg, #fff));
  flex-shrink: 0;
}

.panel__btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg-soft, #4A5160);
  border-radius: 8px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.panel__btn:hover {
  background: var(--row-hover-bg, rgba(0,0,0,0.05));
  color: var(--accent, #002B54);
}
.panel__btn:active { transform: translateY(0.5px); }
.panel__btn[disabled] { opacity: 0.35; pointer-events: none; }

.panel__menu { margin-right: 2px; }
.panel__close-btn { margin-left: auto; }

.panel__nav {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
  margin-right: auto;
  padding: 0 4px;
}
.panel__nav-count {
  display: inline-block;
  min-width: 60px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--fg-soft, #4A5160);
  font-weight: 500;
}

/* Show / hide nav strip based on panel state */
.app[data-panel-state="list"] #panel-nav { display: none; }
.app[data-panel-state="detail"] #panel-nav { display: inline-flex; }

/* Highlight active mode of menu button */
.app[data-panel-state="list"] .panel__menu {
  color: var(--accent, #002B54);
  background: var(--row-selected-bg, rgba(0,43,84,0.06));
}

/* ───────── Panel body / views ───────── */

.panel__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel__view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.app[data-panel-state="list"]   #view-detail { display: none; }
.app[data-panel-state="detail"] #view-list   { display: none; }

/* ───────── List view (filters + chips + scrollable list) ───────── */

.sidebar__filters {
  padding: 14px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.search-wrap { position: relative; }
.search-wrap input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1px solid var(--border, #e0e0e0);
  border-radius: 8px;
  font: inherit;
  background: var(--input-bg, #fff);
  color: inherit;
}
.search-wrap input:focus {
  outline: 2px solid var(--accent, #002B54);
  outline-offset: -1px;
  border-color: transparent;
}
.search-wrap::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  background: no-repeat center / contain url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><path d='M21 21l-4.3-4.3'/></svg>");
  opacity: 0.7;
}

/* ───────── Collapsible filter (in sidebar) ───────── */
.filter-collapsible {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-trigger {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: var(--input-bg, #fff);
  border: 1px solid var(--border-strong, var(--border, #ddd));
  color: var(--fg, #1a1d23);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.filter-trigger:hover { border-color: var(--accent, #002B54); }
.filter-trigger[aria-expanded="true"] {
  border-color: var(--accent, #002B54);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}
.filter-trigger-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.filter-trigger-caret {
  color: var(--fg-soft, #6b727f);
  font-size: 11px;
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px;
  background: var(--input-bg, #fff);
  border: 1px solid var(--accent, #002B54);
  border-top: none;
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
  margin-top: -4px;
}
.category-row {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--fg, #1a1d23);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
  cursor: pointer;
}
.category-row:hover { background: var(--row-hover-bg, rgba(0,0,0,0.04)); }
.category-row.is-active {
  background: var(--accent, #002B54);
  color: var(--accent-fg, #fff);
}
.category-row.is-active .category-row-count { color: rgba(255,255,255,0.85); }
.category-row.is-active .pin-dot { box-shadow: 0 0 0 1px rgba(255,255,255,0.5); }

.pin-dot--all {
  background: conic-gradient(#289747, #1f6feb, #D29A2F, #eab308, #289747);
}

.category-row-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.category-row-count {
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--fg-soft, #6b727f);
  opacity: 0.8;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(0,0,0,0.04);
}
.category-row.is-active .category-row-count {
  background: rgba(255,255,255,0.18);
}

.pin-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.08);
}

.sidebar__meta {
  padding: 8px 16px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-soft, #6b727f);
  opacity: 0.85;
  flex-shrink: 0;
}

.sidebar__list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 12px;
  scrollbar-width: thin;
  min-height: 0;
}

.marker-row {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 10px;
  border: none;
  background: transparent;
  text-align: left;
  border-radius: 8px;
  color: inherit;
  transition: background 0.12s ease;
}
.marker-row:hover { background: var(--row-hover-bg, rgba(0,0,0,0.04)); }
.marker-row.is-selected {
  background: var(--row-selected-bg, rgba(0,43,84,0.08));
  outline: 1px solid var(--accent, #002B54);
}
.marker-row .pin-dot { margin-top: 5px; }
.marker-row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.marker-row-title {
  font-weight: 500;
  font-size: 14px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.marker-row-meta {
  font-size: 12px;
  opacity: 0.6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.marker-row.is-inactive {
  opacity: 0.55;
}
.marker-row.is-inactive .marker-row-title {
  text-decoration: line-through;
  text-decoration-color: rgba(0,0,0,0.3);
}
.marker-row-badge {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
  align-self: center;
  white-space: nowrap;
}
.marker-row-badge--inactive {
  background: #ffe6e6;
  color: #b34141;
  border: 1px solid #f3c8c8;
}

.empty-state {
  padding: 24px 16px;
  text-align: center;
  opacity: 0.55;
  font-size: 13px;
}

.list-divider {
  padding: 14px 16px 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-soft, #888);
  opacity: 0.75;
  border-top: 1px solid var(--border, #e6e6e6);
  margin-top: 6px;
}

/* ───────── Detail view (lives inside panel) ───────── */

#detail {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 28px;
  min-height: 0;
}

.detail-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.75;
  margin-bottom: 8px;
}
.detail-title {
  font-family: var(--font-display, var(--font-body));
  font-size: 26px;
  line-height: 1.2;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
}
.detail-subtitle {
  font-size: 15px;
  opacity: 0.75;
  margin: 0 0 16px;
}
.detail-where {
  font-size: 13px;
  opacity: 0.7;
  margin: 0 0 14px;
}
.detail-image {
  margin: 16px 0;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0,0,0,0.05);
  padding: 0;
}
.detail-image img {
  width: 100%;
  aspect-ratio: 16/10;
  object-fit: cover;
  display: block;
}
.detail-empty {
  opacity: 0.55;
  font-size: 14px;
}
.detail-desc {
  font-size: 14.5px;
  line-height: 1.6;
  margin: 0 0 20px;
}
.detail-desc p { margin: 0 0 0.9em; }
.detail-desc img { border-radius: 6px; margin: 10px 0; }

.detail-links {
  border-top: 1px solid var(--border, #e6e6e6);
  padding-top: 16px;
  margin-top: 16px;
}
.detail-links h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.65;
  margin: 0 0 8px;
  font-weight: 600;
}
.detail-link {
  display: block;
  padding: 6px 0;
  font-size: 13px;
  color: var(--accent, #002B54);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.detail-link::before { content: '↗ '; opacity: 0.6; }
.detail-link:hover { text-decoration: underline; }

.detail-source {
  border-top: 1px solid var(--border, #e6e6e6);
  padding-top: 16px;
  margin-top: 16px;
}
.detail-source h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.65;
  margin: 0 0 6px;
  font-weight: 600;
}
.detail-source-text {
  font-size: 13.5px;
  line-height: 1.5;
  margin: 0;
  color: var(--fg-soft, #4A5160);
  font-style: italic;
}

.detail-citation {
  margin-top: 18px;
  padding: 12px 14px;
  background: var(--citation-bg, rgba(0,0,0,0.03));
  border-radius: 8px;
  font-size: 13px;
}
.detail-citation summary {
  cursor: pointer;
  font-weight: 500;
  opacity: 0.85;
}
.citation-text {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: 12px;
  line-height: 1.5;
  margin: 10px 0;
  padding: 8px;
  background: var(--citation-code-bg, rgba(0,0,0,0.04));
  border-radius: 4px;
  word-break: break-word;
}
.citation-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.btn-copy {
  appearance: none;
  border: 1px solid var(--border, #ddd);
  background: var(--bg, #fff);
  color: inherit;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn-copy:hover { border-color: var(--accent, #002B54); }
.btn-copy--ghost {
  background: transparent;
  color: var(--accent, #002B54);
}

/* Toast notifications */
.ggv-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 24, 32, 0.94);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 9999;
}
.ggv-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ───────── Pin styling ───────── */
.ggv-pin {
  background: transparent !important;
  border: none !important;
}
.ggv-pin svg {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25));
  transition: transform 0.15s ease, opacity 0.2s ease;
  transform-origin: center bottom;
}
.ggv-pin:hover svg { transform: scale(1.1); }
.ggv-pin--selected svg { transform: scale(1.18); }

.app__map.has-selection .ggv-pin:not(.ggv-pin--selected) svg {
  opacity: 0.35;
}
.app__map.has-selection .ggv-pin:not(.ggv-pin--selected):hover svg {
  opacity: 1;
}
/* In admin mode, keep all pins visible so the editor can see context */
body[data-mode="admin"] .app__map.has-selection .ggv-pin:not(.ggv-pin--selected) svg {
  opacity: 1;
}

/* ───────── Map floating buttons ───────── */
.map-btn {
  position: absolute;
  z-index: 400;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--bg, #fff);
  color: var(--accent, #002B54);
  border: 1px solid var(--border, #e6e6e6);
  border-radius: 8px;
  font: 500 12.5px var(--font-body, 'Inter', sans-serif);
  letter-spacing: 0.01em;
  box-shadow: 0 4px 14px rgba(0,30,60,0.10);
  cursor: pointer;
  transition: background 0.12s, transform 0.12s;
}
.map-btn:hover {
  background: var(--accent, #002B54);
  color: #fff;
  border-color: var(--accent, #002B54);
}
.map-btn:active { transform: translateY(1px); }
.map-btn svg { flex-shrink: 0; }

.map-btn--reset { top: 16px; left: 16px; }
.map-btn--open-panel { top: 16px; right: 16px; }

/* ───────── Compact legend overlay (bottom-left of map) ───────── */
.map-legend {
  position: absolute;
  bottom: 28px;
  left: 16px;
  z-index: 400;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border, #e6e6e6);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0, 30, 60, 0.10);
  padding: 10px 14px 11px;
  font-size: 12.5px;
  pointer-events: none;
  user-select: none;
  min-width: 148px;
}
.map-legend-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent, #002B54);
  margin-bottom: 5px;
}
.map-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  color: var(--fg, #14181F);
  font-weight: 500;
  line-height: 1.4;
}
.map-legend-row .pin-dot { width: 9px; height: 9px; }
.map-legend-label { white-space: nowrap; }

/* Scale up gradually on wider viewports / iframes */
@container app (min-width: 1200px) {
  .map-legend {
    font-size: 13px;
    padding: 11px 15px 12px;
    min-width: 160px;
  }
  .map-legend-row .pin-dot { width: 10px; height: 10px; }
}
@container app (min-width: 1600px) {
  .map-legend {
    font-size: 13.5px;
    padding: 12px 16px 13px;
    min-width: 175px;
  }
  .map-legend-title { font-size: 10.5px; }
  .map-legend-row .pin-dot { width: 11px; height: 11px; }
}

/* Mobile: hide entirely — info is in the right-side filter list anyway */
@media (max-width: 768px) {
  .map-legend { display: none !important; }
}

/* ───────── Hover tooltip on pins (richer than Rich's status bar) ───────── */
.leaflet-tooltip.ggv-tooltip {
  background: var(--detail-bg, #fff) !important;
  color: var(--fg, #14181F) !important;
  border: 1px solid var(--border, #e6e6e6) !important;
  border-radius: 10px !important;
  padding: 11px 14px !important;
  box-shadow: 0 8px 24px rgba(0,30,60,0.16) !important;
  font: 500 13px var(--font-body, 'Inter', sans-serif) !important;
  max-width: 360px;        /* wider so titles & hover text don't wrap tight */
  min-width: 200px;
  line-height: 1.45;
  white-space: normal;
}
.leaflet-tooltip-top.ggv-tooltip::before {
  border-top-color: var(--border, #e6e6e6) !important;
}
.ggv-tt-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-soft, #6b727f);
  margin-bottom: 4px;
}
.ggv-tt-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.08);
}
.ggv-tt-title {
  font-family: var(--font-display, var(--font-body));
  font-weight: 600;
  font-size: 14.5px;
  color: var(--accent, #002B54);
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.ggv-tt-place {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--fg-soft, #6b727f);
  font-weight: 500;
}
.ggv-tt-hover {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border, #e6e6e6);
  font-size: 12.5px;
  font-style: italic;
  color: var(--fg, #14181F);
  font-weight: 400;
}

/* ───────── Leaflet polish ───────── */
.leaflet-control-attribution {
  font-size: 10px !important;
  background: rgba(255,255,255,0.85) !important;
  padding: 2px 6px !important;
}
.leaflet-bar a {
  width: 30px !important;
  height: 30px !important;
  line-height: 30px !important;
  color: var(--accent, #002B54) !important;
}
.leaflet-control-zoom {
  margin-top: 60px !important;     /* sit below the reset button */
  margin-left: 16px !important;
}

/* ───────── Responsiveness ───────── */

@container app (max-width: 720px) {
  .panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 60vh;
    border-radius: 14px 14px 0 0;
  }
  .app[data-panel-state="closed"] .panel {
    transform: translateY(calc(100% + 24px));
  }
}

@media (max-width: 768px) {
  .app__header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
  }
  .brand__title { font-size: 16px; }
  .brand__sub { font-size: 11px; }
  .panel {
    top: auto !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    max-height: 65vh;
    border-radius: 14px 14px 0 0;
  }
  .app[data-panel-state="closed"] .panel {
    transform: translateY(calc(100% + 24px)) !important;
  }
  .map-btn--reset { top: 12px; left: 12px; }
  .map-btn--open-panel { top: auto; bottom: 16px; right: 16px; }
  #detail { padding: 16px 18px 24px; }
  .detail-title { font-size: 22px; }
}
