/* CSS custom properties — defined on both :root (for body-appended modals)
   and #map-view (for scoped inheritance within the map panel) */
:root,
#map-view {
  --purple:      #7c3aed;
  --purple-soft: #a78bfa;
  --purple-dim:  rgba(124, 58, 237, 0.12);
  --surface:     #ffffff;
  --border:      rgba(124, 58, 237, 0.15);
  --text-main:   #1a1a2e;
  --text-sub:    #6b7280;
  --bg:          #f5f3ff;
}

/* ── Map view container ───────────────────────────────────── */
#map-view {
  position: relative;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 180px);
  border: 1px solid var(--stroke-soft, var(--border));
  border-radius: 12px;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
}

/* ── Content row (map + right panel) ─────────────────────── */
#content-row {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Map container ───────────────────────────────────────── */
#map-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
}

/* ── Timeline overlay ────────────────────────────────────── */
#timeline {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 100px);
  max-width: 680px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  padding: 18px 20px 10px;
  user-select: none;
  z-index: 10;
}

#tl-scrubber {
  position: relative;
  height: 20px;
  cursor: pointer;
  touch-action: none;
}

#tl-track {
  position: absolute;
  top: 50%;
  left: 0; right: 0;
  height: 4px;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.10);
  border-radius: 2px;
  pointer-events: none;
}

#tl-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--purple);
  border-radius: 2px;
}

#tl-ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tl-tick {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(0,0,0,0.18);
  width: 4px;
  height: 4px;
}

.tl-tick.major {
  width: 7px;
  height: 7px;
  background: var(--purple);
  opacity: 0.45;
}

#tl-handle {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  background: var(--purple);
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,0.22);
  cursor: grab;
  z-index: 2;
  touch-action: none;
}

#tl-handle:active { cursor: grabbing; }

#tl-time {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--purple);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  letter-spacing: 0.04em;
}

#tl-labels {
  position: relative;
  height: 14px;
  margin-top: 6px;
}

.tl-hour-lbl {
  position: absolute;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-sub);
  white-space: nowrap;
  pointer-events: none;
}

/* ── Right data panel ────────────────────────────────────── */
#right-panel {
  width: 25%;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  font-family: 'Avenir Next', 'Avenir', system-ui, sans-serif;
}

.close-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.close-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-sub);
}

.close-table tbody tr {
  border-bottom: 1px solid var(--border);
}

.close-table tbody tr:last-child {
  border-bottom: none;
}

.close-table td {
  padding: 9px 12px;
  vertical-align: top;
  color: var(--text-main);
  line-height: 1.5;
}

.close-table td.col-time {
  font-weight: 700;
  white-space: nowrap;
  color: var(--purple);
  font-variant-numeric: tabular-nums;
  width: 1%;
}

.close-table td.col-areas {
  color: var(--text-sub);
  font-weight: 500;
}

.close-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

#enr-error-list {
  height: 60%;
  overflow-y: auto;
  flex-shrink: 0;
}

.panel-divider {
  height: 1px;
  background: var(--border);
  flex-shrink: 0;
}

.enr-error-item {
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.enr-error-item:last-child { border-bottom: none; }

.enr-error-header {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 9px 12px;
}

.enr-error-time {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--purple);
  flex-shrink: 0;
}

.enr-error-juris {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  flex-shrink: 0;
}

.enr-error-summary {
  color: var(--text-sub);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.enr-expand-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 16px;
  background: var(--purple-dim);
  border: 1px solid rgba(124, 58, 237, 0.3);
  border-radius: 3px;
  color: var(--purple);
  cursor: pointer;
  font-size: 9px;
  padding: 0;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.enr-expand-btn:hover { background: rgba(124, 58, 237, 0.2); }
.enr-expand-btn.expanded { transform: rotate(180deg); }

.enr-error-desc {
  display: none;
  padding: 0 12px 10px;
}

.enr-error-desc pre {
  margin: 0;
  font-size: 10px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  color: var(--text-main);
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  line-height: 1.5;
}

.enr-error-empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--text-sub);
  font-size: 12px;
}

/* hide MapLibre logo/attribution for cleaner look */
.maplibregl-ctrl-bottom-left,
.maplibregl-ctrl-bottom-right {
  opacity: 0.5;
  transform: scale(0.85);
  transform-origin: bottom left;
}

/* ── County popup ────────────────────────────────────────── */
.maplibregl-popup-content {
  padding: 0;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.13);
  border: 1px solid var(--border);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
}

.maplibregl-popup-close-button {
  font-size: 16px;
  color: var(--text-sub);
  padding: 4px 8px;
}

.popup-inner {
  padding: 12px 14px 13px;
  min-width: 210px;
}

.popup-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.popup-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 5px;
  font-size: 15px;
}

.popup-row-sep { margin-top: 10px; padding-top: 8px; border-top: 1px solid rgba(128,128,128,0.25); }
.popup-label { color: var(--text-sub); font-weight: 500; white-space: nowrap; }
.popup-value { color: var(--text-main); font-weight: 600; text-align: right; }

.popup-ts {
  font-size: 15px;
  color: var(--text-sub);
  font-weight: 500;
  text-align: right;
  margin-top: 15px;
}

.popup-ext-btn {
  background: none;
  border: none;
  padding: 0 0 0 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  vertical-align: baseline;
}

.popup-ext-icon {
  display: inline-block;
  width: 11px;
  height: 11px;
  background-color: #dc2626;
  -webkit-mask-image: url('assets/open-new-window.svg');
  mask-image: url('assets/open-new-window.svg');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  vertical-align: -1px;
}

/* ── Error description modal ─────────────────────────── */
#enr-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

#enr-modal {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.22);
  border: 1px solid var(--border);
  width: min(620px, 90vw);
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#enr-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

#enr-modal-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

#enr-modal-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-sub);
  padding: 0 2px;
  flex-shrink: 0;
}

#enr-modal-close:hover { color: var(--text-main); }

#enr-modal-body {
  overflow-y: auto;
  padding: 14px 16px;
  flex: 1;
}

#enr-modal-body pre {
  margin: 0;
  font-size: 11px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  color: var(--text-main);
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.6;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 14px;
}

/* ── Map loading overlay (absolute within #map-view) ─── */
#map-loading-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

/* Ensure the spinner icon div centres its child img */
#map-loading-overlay .spinner-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-wrapper {
  margin-top: 28px;
  width: 300px;
  text-align: center;
}

.progress-bar-track {
  width: 100%;
  height: 6px;
  background-color: rgba(124, 58, 237, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7c3aed, #a78bfa);
  border-radius: 3px;
  transition: width 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-text {
  margin-top: 10px;
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
}

.progress-detail {
  margin-top: 4px;
  font-size: 12px;
  color: #737373;
}

/* ── Map search overlay ──────────────────────────────── */
#map-search {
  position: absolute;
  top: 10px;
  right: 52px;
  z-index: 10;
  width: 220px;
}

#map-search-input {
  width: 100%;
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
  outline: none;
}

#map-search-input:focus {
  border-color: var(--purple);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10), 0 0 0 2px var(--purple-dim);
}

#map-search-results {
  display: none;
  list-style: none;
  padding: 0;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  margin-top: 4px;
  max-height: 220px;
  overflow-y: auto;
}

.map-search-item {
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text-main);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.map-search-item:last-child { border-bottom: none; }

.map-search-item:hover,
.map-search-item.active {
  background: var(--purple-dim);
  color: var(--purple);
}

/* ── Zoom-to-populated button ────────────────────────── */
.zoom-populated-btn {
  width: 29px;
  height: 29px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: #333;
}

.zoom-populated-btn:hover { background: rgba(0,0,0,0.05); }
