/* ── Design tokens ──────────────────────────────────────────────────────── */
:root {
  --bg:          #f2f5f2;
  --surface:     #ffffff;
  --border:      #dde5dd;
  --header-bg:   #1b3d2a;
  --header-text: #ffffff;
  --accent:      #2d6a4f;
  --accent-dim:  #e8f3ed;
  --text:        #1c2e1c;
  --text-muted:  #6b7f6b;
  --shadow-sm:   0 1px 4px rgba(0,0,0,.08);
  --shadow-md:   0 4px 16px rgba(0,0,0,.10);
  --radius:      10px;
  --radius-sm:   6px;
}

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

body {
  font-family: 'Inter', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header p {
  font-size: 0.8rem;
  opacity: 0.6;
  font-weight: 400;
}

/* ── Controls bar ────────────────────────────────────────────────────────── */
#controls {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: flex-end;
  box-shadow: var(--shadow-sm);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.control-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

/* Fuel chips */
.fuel-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.fuel-chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s;
  color: var(--text-muted);
}

.fuel-chip input { display: none; }

.fuel-chip .chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.fuel-chip.checked {
  color: var(--text);
  border-color: transparent;
  background: var(--accent-dim);
  box-shadow: var(--shadow-sm);
}

.fuel-chip:hover { border-color: var(--accent); }

/* Country select */
#country-select {
  font-family: inherit;
  font-size: 0.82rem;
  padding: 0.4rem 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  min-width: 180px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

#country-select:focus { border-color: var(--accent); }

/* Deforestation toggle */
.toggle-row {
  display: flex;
  flex-direction: row;
  gap: 0.4rem;
}

#deforest-toggle,
#population-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.42rem 1rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
}

#deforest-toggle .toggle-icon,
#population-toggle .toggle-icon {
  font-size: 1rem;
  line-height: 1;
}

#deforest-toggle .toggle-pill,
#population-toggle .toggle-pill {
  width: 32px;
  height: 17px;
  border-radius: 999px;
  background: #ccc;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

#deforest-toggle .toggle-pill::after,
#population-toggle .toggle-pill::after {
  content: '';
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: white;
  top: 2px;
  left: 2px;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

#deforest-toggle.active {
  border-color: #52b788;
  color: #1b4332;
  background: #d8f3dc;
}

#deforest-toggle.active .toggle-pill { background: #52b788; }
#deforest-toggle.active .toggle-pill::after { left: 17px; }

#population-toggle.active {
  border-color: #52b788;
  color: #1b4332;
  background: #d8f3dc;
}

#population-toggle.active .toggle-pill { background: #52b788; }
#population-toggle.active .toggle-pill::after { left: 17px; }

/* Loading indicator */
#loading {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(27, 61, 42, 0.55);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  color: white;
  font-weight: 600;
  font-size: 1rem;
}

#loading.visible { display: flex; }

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ── Main layout ─────────────────────────────────────────────────────────── */
main {
  flex: 1;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.top-row {
  display: flex;
  gap: 1rem;
  align-items: stretch;
}

/* ── Map ─────────────────────────────────────────────────────────────────── */
#map-wrapper {
  flex: 3;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

#map {
  height: 480px;
  width: 100%;
}

/* ── Side panel ──────────────────────────────────────────────────────────── */
#side-panel {
  flex: 1;
  min-width: 210px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}

.panel-card--grow { flex: 1; }

.panel-card h3 {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
}

/* Detail content */
#detail-content {
  font-size: 0.85rem;
}

.detail-placeholder {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  line-height: 1.5;
}

.detail-name {
  font-weight: 700;
  font-size: 0.92rem;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.detail-row:last-child { border-bottom: none; }

.detail-key {
  color: var(--text-muted);
  font-weight: 500;
}

.detail-val {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.detail-fuel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* Legend */
.legend-items {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Bottom charts ───────────────────────────────────────────────────────── */
.bottom-row {
  display: flex;
  gap: 1rem;
}

.chart-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem 0.5rem;
  box-shadow: var(--shadow-sm);
  min-height: 200px;
  display: flex;
  flex-direction: column;
}

.chart-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.chart-total {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.pie-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  text-align: center;
}

.chart-card svg {
  flex: 1;
  width: 100%;
  display: block;
}

.chart-card svg path.curve {
  stroke: var(--accent);
  stroke-width: 1.5px;
  fill: none;
}

.chart-card svg text {
  font-family: 'Inter', sans-serif;
  font-size: 7px;
  fill: var(--text-muted);
}

.chart-card svg text.tick {
  font-size: 5.5px;
  fill: var(--text-muted);
}

.chart-card svg text.axis-label {
  font-size: 6px;
  fill: var(--text-muted);
  font-weight: 600;
}

.placeholder-chart {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

.chart-card--placeholder {
  justify-content: center;
  align-items: center;
  border: 2px dashed var(--border);
  background: transparent;
}

.placeholder-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-style: italic;
  text-align: center;
}

.placeholder-icon {
  font-size: 2rem;
}

/* ── Toast notification ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1b3d2a;
  color: white;
  padding: 0.6rem 1.25rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 9998;
  animation: fadeInOut 4s ease forwards;
}

@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateX(-50%) translateY(8px); }
  10%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}
