/* ── Design tokens ── */
:root {
  --ink: #1a1a2e;
  --ink-muted: #4a4a6a;
  --ink-faint: #9090b0;
  --paper: #f7f4ef;
  --paper-warm: #f0ece4;
  --sidebar-bg: #dff1fb;
  --sidebar-border: rgba(80,160,220,0.18);
  --accent: #1a7fc4;
  --accent-cool: #4a90d9;
  --surface: #ffffff;
  --border: rgba(26,26,46,0.1);
  --radius-sm: 8px;
  --radius-md: 14px;
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-sans: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'DM Mono', monospace;
  --sidebar-width: 300px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

  /* ── Font scale: change only this to resize all text ── */
  --font-scale: 1.4;                        /* 0.85 = smaller, 1.2 = larger */

  /* ── Named size tokens (base × scale) ── */
  --fs-2xs: calc(0.65rem * var(--font-scale));   /* .label-number, .copyright */
  --fs-xs:  calc(0.68rem * var(--font-scale));   /* .logo-sub, .scenario-tag, .download-hint */
  --fs-sm:  calc(0.70rem * var(--font-scale));   /* .field-label, .footer-note */
  --fs-md:  calc(0.72rem * var(--font-scale));   /* .active-badge.secondary */
  --fs-base: calc(0.78rem * var(--font-scale));  /* .active-badge, .map-subtitle, #loading-indicator */
  --fs-ui:  calc(0.82rem * var(--font-scale));   /* selects, buttons */
  --fs-lg:  calc(0.85rem * var(--font-scale));   /* #map-placeholder p */
  --fs-xl:  calc(1.05rem * var(--font-scale));   /* .logo-title */
  --fs-2xl: calc(1.25rem * var(--font-scale));   /* #mapTitle */
}

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

body {
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* ══════════════════════════════════════
   SIDEBAR
══════════════════════════════════════ */
#sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: #1a3a52;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow-y: auto;
  position: relative;
  z-index: 10;
  box-shadow: 4px 0 24px rgba(26,127,196,0.10);
}

/* Subtle grid texture on sidebar */
#sidebar::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(26,127,196,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(26,127,196,0.05) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
}

/* ── Sidebar header ── */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 28px 24px 24px;
  border-bottom: 1px solid var(--sidebar-border);
  color: #0d2f47;
  background: #c2e4f8;
}

.logo-mark {
  flex-shrink: 0;
  color: var(--accent);
}

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

.logo-title {
  font-family: var(--font-serif);
  font-size: var(--fs-xl);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #0d2f47;
}

.logo-sub {
  font-size: var(--fs-xs);
  font-weight: 400;
  color: rgba(13,47,71,0.55);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ── Sidebar sections ── */
.sidebar-section {
  padding: 22px 24px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: fadeSlideIn 0.4s both;
}

.sidebar-section:nth-child(2) { animation-delay: 0.05s; }
.sidebar-section:nth-child(3) { animation-delay: 0.10s; }
.sidebar-section:nth-child(4) { animation-delay: 0.15s; }
.sidebar-section:nth-child(5) { animation-delay: 0.20s; }
.sidebar-section:nth-child(6) { animation-delay: 0.25s; }
.sidebar-section:nth-child(7) { animation-delay: 0.30s; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Field labels ── */
.field-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(13,47,71,0.55);
  display: flex;
  align-items: center;
  gap: 8px;
}

.label-number {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--accent);
  opacity: 0.9;
}

/* ── Select wrapper ── */
.select-wrapper {
  position: relative;
}

.select-wrapper select {
  width: 100%;
  appearance: none;
  background: rgba(255,255,255,0.65);
  border: 1px solid rgba(26,127,196,0.22);
  border-radius: var(--radius-sm);
  color: #1a3a52;
  font-family: var(--font-sans);
  font-size: var(--fs-ui);
  font-weight: 400;
  padding: 10px 36px 10px 12px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  line-height: 1.4;
}

.select-wrapper select:hover {
  background: rgba(255,255,255,0.88);
  border-color: rgba(26,127,196,0.45);
}

.select-wrapper select:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(194,228,248,0.5);
}

.select-wrapper select option {
  background: #dff1fb;
  color: #1a3a52;
}

.select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: rgba(26,127,196,0.55);
}

/* ── Scenario legend ── */
.scenario-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}

.scenario-tag {
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  padding: 4px 8px;
  border-radius: 4px;
  color: rgba(13,47,71,0.6);
  border-left: 2px solid transparent;
}

.scenario-tag.ssp245 { border-color: #4a90d9; background: rgba(74,144,217,0.12); }
.scenario-tag.ssp585 { border-color: #1a7fc4; background: rgba(26,127,196,0.12); }

/* ── Active selection display ── */
.active-selection { gap: 8px; }

.active-badge {
  background: rgba(255,255,255,0.55);
  border: 1px solid rgba(26,127,196,0.18);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: var(--fs-base);
  color: #0d2f47;
  line-height: 1.4;
  min-height: 36px;
  display: flex;
  align-items: center;
}

.active-badge.secondary {
  font-family: var(--font-mono);
  font-size: var(--fs-md);
  color: var(--accent);
  background: rgba(26,127,196,0.08);
  border-color: rgba(26,127,196,0.22);
}

/* ── Download section ── */
.download-section { gap: 8px; }

.download-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--fs-ui);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  letter-spacing: 0.02em;
}

.download-btn:hover:not(:disabled) {
  background: #155f96;
  transform: translateY(-1px);
}

.download-btn:active:not(:disabled) {
  transform: translateY(0);
}

.download-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.download-hint {
  font-size: var(--fs-xs);
  color: rgba(13,47,71,0.45);
  line-height: 1.5;
}

/* ── Sidebar footer ── */
.sidebar-footer {
  margin-top: auto;
  padding: 20px 24px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #c2e4f8;
}

.footer-note {
  font-size: var(--fs-sm);
  color: rgba(13,47,71,0.45);
  line-height: 1.6;
}

.copyright {
  font-size: var(--fs-2xs);
  font-family: var(--font-mono);
  color: rgba(13,47,71,0.3);
  letter-spacing: 0.04em;
}

/* ══════════════════════════════════════
   MAIN CONTENT
══════════════════════════════════════ */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
  position: relative;
}

/* ── Map header bar ── */
#map-header {
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
  box-shadow: 0 1px 0 var(--border);
}

#mapTitle {
  font-family: var(--font-serif);
  font-size: var(--fs-2xl);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
  transition: opacity 0.3s;
}

.map-subtitle {
  font-size: var(--fs-base);
  color: var(--ink-faint);
  margin-top: 3px;
  line-height: 1.5;
}

/* ── Loading indicator ── */
#loading-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-base);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

#loading-indicator.hidden { display: none; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Map container ── */
#map-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--paper-warm);
}




#map {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Make bokeh plots fill the container */
#map .bk-root,
#map .bk-root .bk,
#map > div,
#map-bokeh-target,
#map-bokeh-target .bk-root {
  width: 100% !important;
  height: 100% !important;
}

/* ── Empty state placeholder ── */
#map-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--ink-muted);
  z-index: 2;
  pointer-events: none;
}

#map-placeholder p {
  font-size: var(--fs-lg);
  color: var(--ink-faint);
  font-family: var(--font-sans);
}

#map-placeholder.hidden { display: none; }

/* ── Scrollbar styling ── */
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(26,127,196,0.25); border-radius: 2px; }

/* ── Responsive ── */
@media (max-width: 680px) {
  body { flex-direction: column; }
  #sidebar { width: 100%; height: auto; flex-shrink: 0; }
  #main { flex: 1; }
}
