@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&display=swap');

/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #f5f6f7;
  --surface:    #ffffff;
  --surface2:   #f0f2f4;
  --border:     #e2e5e9;
  --text:       #1a2030;
  --text-muted: #6b7585;
  --accent:     #0e7a5f;
  --accent-dim: rgba(14,122,95,0.10);
  --hover:      rgba(0,0,0,0.04);
  --danger:     #c0392b;
  --sidebar-w:  300px;
  --radius:     6px;
  --font:       'IBM Plex Sans', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  overflow: hidden;
}

/* ── App layout ───────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: 2px 0 12px rgba(0,0,0,0.07);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
}

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

#admin-link {
  font-size: 16px;
  color: var(--text-muted);
  text-decoration: none;
  opacity: 0.6;
  transition: opacity .15s;
}
#admin-link:hover { opacity: 1; }

#logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--text);
}

#logo-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

#tagline-link {
  font-size: 10.5px;
  font-weight: 400;
  color: var(--accent);
  text-decoration: none;
  opacity: 0.8;
  letter-spacing: 0;
}
#tagline-link:hover { opacity: 1; text-decoration: underline; }

#sidebar-content {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

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

/* ── Section header (label + reload button) ───────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.reload-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--radius);
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.reload-btn:hover {
  color: var(--accent);
  background: var(--accent-dim);
}

/* ── Product tree ─────────────────────────────────────────── */
.product-group { margin-bottom: 6px; }

.product-group-header {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  padding: 5px 6px;
  border-radius: var(--radius);
  user-select: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  transition: background 0.15s;
}
.product-group-header:hover { background: var(--hover); }

.chevron {
  font-size: 9px;
  color: var(--text-muted);
  transition: transform 0.18s;
  flex-shrink: 0;
}
.product-group-header.open .chevron { transform: rotate(90deg); }

.product-group-body {
  display: none;
  padding-left: 12px;
  margin-top: 3px;
}
.product-group-body.open { display: block; }

.source-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-muted);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  margin-bottom: 2px;
}
.source-item:hover { background: var(--hover); color: var(--text); }
.source-item.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.source-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  opacity: 0.6;
}
.source-item.active .source-dot { opacity: 1; }

.info-icon {
  margin-left: 0;
  flex-shrink: 0;
  font-size: 11px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border: 1px solid var(--border, rgba(255,255,255,0.15));
  cursor: pointer;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s;
}
.info-icon:hover { color: var(--text); border-color: var(--text-muted); }

.info-popover {
  position: absolute;
  z-index: 9999;
  max-width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 12.5px;
  color: var(--text);
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  pointer-events: none;
}

/* ── Pill groups (version / resolution / years) ───────────── */
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 6px;
}

.placeholder {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.selection-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin: 8px 0 0;
  line-height: 1.6;
}

.pill {
  padding: 3px 11px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  user-select: none;
  white-space: nowrap;
}
.pill:hover {
  border-color: var(--text-muted);
  background: var(--hover);
}
.pill.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.pill.select-all {
  border-style: dashed;
  color: var(--text-muted);
}
.pill.select-all.active {
  border-style: solid;
}

/* ── Year slider ─────────────────────────────────────────── */
.year-slider-wrap {
  padding: 4px 0 0;
}

.year-single {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  padding: 5px 0 2px;
  text-align: center;
}

.year-slider-inner {
  position: relative;
  padding: 2px 0;
}

/* (0,2,1) beats global input[type="range"] (0,1,1) regardless of order */
input[type="range"].year-range {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  min-width: unset;
  max-width: unset;
  height: 20px;
  flex: none;
  background: transparent;
  outline: none;
  cursor: pointer;
  position: relative;
  z-index: 2;
}
input[type="range"].year-range::-webkit-slider-container { overflow: visible; }
input[type="range"].year-range::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--fill-pct, 0%),
    var(--border) var(--fill-pct, 0%),
    var(--border) 100%
  );
}
input[type="range"].year-range::-moz-range-track {
  height: 5px;
  border-radius: 3px;
  background: var(--border);
}
input[type="range"].year-range::-moz-range-progress {
  height: 5px;
  border-radius: 3px;
  background: var(--accent);
}
input[type="range"].year-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1.5px var(--accent);
  cursor: pointer;
  margin-top: -4.5px;
  transition: box-shadow 0.15s;
}
input[type="range"].year-range:hover::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px rgba(14,122,95,0.15);
}
input[type="range"].year-range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  /* outline instead of box-shadow: outline is never clipped by overflow,
     box-shadow is — which caused 1-2px top clipping in Firefox */
  outline: 1.5px solid var(--accent);
  outline-offset: 0;
  cursor: pointer;
}

.year-ticks {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 1;
}
.year-tick {
  position: absolute;
  top: 70%;
  width: 2px;
  height: 8px;
  border-radius: 1px;
  background: var(--border);
  transform: translateX(-50%) translateY(-50%);
}
.year-tick.filled  { background: var(--accent); opacity: 0.45; }
.year-tick.current { background: var(--accent); opacity: 1; height: 10px; }

.year-labels {
  position: relative;
  height: 16px;
  margin-top: 8px;
}
.year-label {
  position: absolute;
  font-size: 10px;
  color: var(--text-muted);
  top: 50%;
  transform: translateX(-50%) translateY(-50%);
  white-space: nowrap;
  line-height: 1;
}
.year-label.current { color: var(--accent); font-weight: 600; font-size: 12px; }

.year-all-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.year-all-toggle input[type="checkbox"] {
  -webkit-appearance: auto;
  appearance: auto;
  accent-color: var(--accent);
  cursor: pointer;
  width: 13px;
  height: 13px;
  min-width: unset;
  max-width: unset;
  flex-shrink: 0;
}

/* ── Preview controls ─────────────────────────────────────── */
.control-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
  padding: 2px 0;
  position: relative;
}
.control-row:last-child { margin-bottom: 0; }

/* Give slider rows enough bottom padding to physically contain the thumb,
   so the next row's background can't cover it. Offset with less margin-bottom
   to keep the visual gap between rows unchanged. */
#preview-controls .control-row:nth-child(2),
#preview-controls .control-row:nth-child(4) {
  padding-bottom: 8px;
  margin-bottom: 2px;
}
#preview-controls .control-row:nth-child(5) { margin-bottom: 0; }

.control-label {
  font-size: 13px;
  color: var(--text-muted);
  width: 72px;
  flex-shrink: 0;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

input[type="range"] {
  flex: 1;
  min-width: 150px;
  max-width: 150px;
  accent-color: var(--accent);
  cursor: pointer;
  height: 12px;
}

#opacity-value, #threshold-value {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 34px;
  text-align: center;
}

#colormap-select {
  flex: 1;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
}
#colormap-select:focus { outline: none; border-color: var(--accent); }

/* ── Legend ───────────────────────────────────────────────── */
#legend-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

#legend-canvas {
  width: 100%;
  height: 14px;
  border-radius: 3px;
}

#legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

#legend-unit {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}

/* ── Selection info pane ──────────────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 14px;
}

.info-key {
  color: var(--text-muted);
  white-space: nowrap;
}

.info-val {
  color: var(--text);
  font-weight: 600;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Download method selector ─────────────────────────────── */
.pill--disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@keyframes terms-pulse {
  0%   { background: transparent; }
  30%  { background: var(--accent-dim); outline: 2px solid var(--accent); }
  100% { background: transparent; outline: 2px solid transparent; }
}
.terms-check-row--pulse {
  border-radius: 4px;
  animation: terms-pulse 0.8s ease-out forwards;
}

#download-method-pills .pill {
  padding: 6px 16px;
  font-size: 14px;
}

.download-method-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.download-method-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}
.download-method-item:not(.download-method-item--disabled):hover {
  background: var(--hover);
  border-color: var(--text-muted);
}
.download-method-item:has(input:checked) {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.download-method-item--disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.download-method-item input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  cursor: pointer;
}
.download-method-item--disabled input[type="checkbox"] { cursor: not-allowed; }

.download-method-label {
  font-size: 14px;
  color: var(--text);
  flex: 1;
}

.download-method-soon {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ── Terms checkbox ───────────────────────────────────────── */
.terms-check-row {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  margin-top: 6px;
  margin-bottom: 8px;
  line-height: 1.4;
}
.terms-check-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  margin-top: 1px;
  flex-shrink: 0;
  cursor: pointer;
}
.terms-check-row a {
  color: var(--accent);
  text-decoration: underline;
}

.modal-box--terms {
  max-width: 440px;
  text-align: left;
}
.terms-body {
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
}
.terms-body p { margin: 0 0 10px; }
.terms-body ul { margin: 0 0 10px; padding-left: 20px; }
.terms-body li { margin-bottom: 4px; }

/* ── Download button ──────────────────────────────────────── */
.download-btn {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, background 0.2s;
}
.download-btn:hover:not(:disabled) { background: #0a6550; }
.download-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.error-msg {
  margin-top: 8px;
  font-size: 12px;
  color: var(--danger);
  text-align: center;
}

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

#map {
  position: absolute;
  inset: 0;
  user-select: none;
}

/* ── Cursor value (sidebar) ───────────────────────────────── */
.cursor-value { display: flex; align-items: baseline; flex: 1; min-width: 0; }
.cursor-value #pixel-panel-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.cursor-value #pixel-panel-unit  { font-size: 11px; color: var(--text-muted); margin-left: 2px; }
.pixel-panel-coords { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; margin-left: auto; white-space: nowrap; padding-left: 6px; }

/* ── Tile tooltip ─────────────────────────────────────────── */
.tile-tooltip {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 11px;
  font-size: 12px;
  color: var(--text);
  pointer-events: none;
  z-index: 100;
  max-width: 200px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
  white-space: nowrap;
}

/* ── Shift-drag selection box ─────────────────────────────── */
.selection-box {
  position: absolute;
  border: 1.5px solid var(--accent);
  background: rgba(14, 122, 95, 0.08);
  pointer-events: none;
  z-index: 50;
}

/* ── Download progress modal ──────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  min-width: 300px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  text-align: center;
}

.modal-status {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}

.modal-bar-track {
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.modal-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.25s ease-out;
}

.modal-pct {
  font-size: 12px;
  color: var(--text-muted);
}

.modal-box--urls {
  width: min(860px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 16px 20px 20px;
}

.urls-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  flex-shrink: 0;
}

.urls-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.urls-tab {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 16px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.urls-tab:hover { background: var(--hover); color: var(--text); }
.urls-tab.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.urls-textarea {
  flex: 1;
  min-height: 0;
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: monospace;
  font-size: 12px;
  line-height: 1.6;
  padding: 10px 12px;
  resize: none;
  box-sizing: border-box;
  white-space: pre;
  overflow-y: auto;
}

.modal-urls-footer {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-shrink: 0;
}

.download-btn--secondary {
  background: var(--surface2);
  color: var(--text);
}
.download-btn--secondary:hover:not(:disabled) {
  background: #e4e7eb;
}

/* ── Utility ──────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── MapLibre GL attribution styling ──────────────────────── */
.maplibregl-ctrl-attrib {
  background: rgba(255,255,255,0.85) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}
.maplibregl-ctrl-attrib a { color: var(--text-muted) !important; }

.maplibregl-ctrl-bottom-right { bottom: 30px !important; }
