/* ============================================================
   ATOMKRAFT RADAR — Main Stylesheet
   Dark / Light mode via [data-theme] attribute on <html>
   ============================================================ */

/* ---------- CSS Custom Properties ---------- */
:root {
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,.12);
  --shadow-md: 0 4px 20px rgba(0,0,0,.18);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.28);
  --transition: .2s ease;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;

  /* Status colours (constant) */
  --c-operational: #22c55e;
  --c-shutdown:    #94a3b8;
  --c-construction:#f59e0b;
  --c-accident:    #ef4444;
  --c-accent:      #3b82f6;
}

[data-theme="dark"] {
  --bg:          #0f1117;
  --bg-2:        #1a1d27;
  --bg-3:        #252836;
  --border:      rgba(255,255,255,.08);
  --text:        #e8eaf6;
  --text-muted:  #6b7280;
  --text-inv:    #0f1117;
  --card-shadow: 0 4px 32px rgba(0,0,0,.5);
  --input-bg:    #1e2130;
  --btn-text:    #fff;
  --map-filter:  brightness(.92) saturate(.85);
}

[data-theme="light"] {
  --bg:          #f0f2f8;
  --bg-2:        #ffffff;
  --bg-3:        #eef0f8;
  --border:      rgba(0,0,0,.08);
  --text:        #1a1d2e;
  --text-muted:  #6b7280;
  --text-inv:    #ffffff;
  --card-shadow: 0 4px 32px rgba(0,0,0,.1);
  --input-bg:    #f5f6fa;
  --btn-text:    #fff;
  --map-filter:  none;
}

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

html { scroll-behavior: smooth; }

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

/* ---------- Header ---------- */
.header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  text-decoration: none;
  color: var(--text);
}

.logo-icon {
  width: 32px;
  height: 32px;
  color: var(--c-accent);
  flex-shrink: 0;
}

.logo-text {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -.5px;
}

.logo-accent {
  color: var(--c-accent);
}

/* Theme toggle */
.theme-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background var(--transition), transform var(--transition);
}

.theme-toggle:hover { background: var(--border); transform: scale(1.08); }

.theme-toggle svg { width: 18px; height: 18px; }

[data-theme="dark"] .theme-icon-moon { display: none; }
[data-theme="light"] .theme-icon-sun { display: none; }

/* ---------- Main ---------- */
.main {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ---------- Search Card ---------- */
.search-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem 2.5rem;
  box-shadow: var(--card-shadow);
}

.search-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: .3rem;
  letter-spacing: -.5px;
}

.search-subtitle {
  color: var(--text-muted);
  margin-bottom: 1.8rem;
  font-size: .95rem;
}

.search-form {
  display: grid;
  gap: 1.4rem;
}

/* Input group */
.input-group { display: flex; flex-direction: column; gap: .5rem; }

.input-label {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: .9rem;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.input-field {
  width: 100%;
  padding: .75rem .9rem .75rem 2.7rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.input-field:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.2);
}

.input-field::placeholder { color: var(--text-muted); }

/* Slider group */
.slider-group { display: flex; flex-direction: column; gap: .5rem; }

.radius-value {
  font-weight: 700;
  color: var(--c-accent);
  min-width: 60px;
  text-align: right;
}

.slider-wrapper {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.slider-min, .slider-max {
  font-size: .75rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 36px;
}

.slider-max { text-align: right; }

.radius-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-3);
  outline: none;
  cursor: pointer;
  border: 1px solid var(--border);
}

.radius-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--c-accent);
  cursor: pointer;
  border: 3px solid var(--bg-2);
  box-shadow: 0 0 0 1px var(--c-accent);
  transition: transform .15s;
}

.radius-slider::-webkit-slider-thumb:hover { transform: scale(1.15); }

.radius-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--c-accent);
  cursor: pointer;
  border: 3px solid var(--bg-2);
}

/* Search button */
.btn-search {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding: .85rem 2rem;
  background: var(--c-accent);
  color: var(--btn-text);
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter var(--transition), transform var(--transition);
  font-family: var(--font);
  width: 100%;
  max-width: 320px;
}

.btn-search svg { width: 18px; height: 18px; }

.btn-search:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }
.btn-search:active:not(:disabled) { transform: translateY(0); }
.btn-search:disabled { opacity: .6; cursor: not-allowed; }

/* Spinner */
.spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.spinner.active { display: block; }

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

/* ---------- Stats Bar ---------- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.stat-item {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.stat-label {
  font-size: .75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.stat-green .stat-value { color: var(--c-operational); }
.stat-blue .stat-value  { color: var(--c-accent); }
.stat-orange .stat-value { color: var(--c-construction); }

/* ---------- Map ---------- */
.map-container {
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
}

#map {
  height: 520px;
  width: 100%;
  background: var(--bg-3);
  filter: var(--map-filter);
}

/* Leaflet popups — theme-aware */
.leaflet-popup-content-wrapper {
  background: var(--bg-2) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-md) !important;
}

.leaflet-popup-tip { background: var(--bg-2) !important; }

.popup-name  { font-weight: 700; font-size: .95rem; margin-bottom: .2rem; }
.popup-country { color: var(--text-muted); font-size: .8rem; margin-bottom: .5rem; }
.popup-row   { font-size: .82rem; display: flex; justify-content: space-between; gap: 1rem; padding: .1rem 0; }
.popup-badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .5rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
  margin-top: .4rem;
}

.badge-operational { background: rgba(34,197,94,.15); color: var(--c-operational); }
.badge-shutdown    { background: rgba(148,163,184,.15); color: var(--c-shutdown); }
.badge-construction { background: rgba(245,158,11,.15); color: var(--c-construction); }
.badge-accident    { background: rgba(239,68,68,.15); color: var(--c-accident); }

/* ---------- Legend ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: .8rem 1.5rem;
  padding: .75rem 1rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: .82rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: .45rem;
  color: var(--text-muted);
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.25);
}

.legend-operational  { background: var(--c-operational); }
.legend-shutdown     { background: var(--c-shutdown); }
.legend-construction { background: var(--c-construction); }
.legend-accident     { background: var(--c-accident); }

.legend-line {
  width: 24px;
  height: 2px;
  background: var(--c-accent);
  opacity: .7;
  flex-shrink: 0;
  border-radius: 1px;
  border: none;
}

/* ---------- Plants Section ---------- */
.plants-section {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.plants-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .8rem;
  margin-bottom: 1.2rem;
}

.plants-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.filter-group {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
}

.filter-btn {
  padding: .3rem .8rem;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: .8rem;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
}

.filter-btn:hover  { border-color: var(--c-accent); color: var(--c-accent); }
.filter-btn.active { background: var(--c-accent); border-color: var(--c-accent); color: #fff; font-weight: 600; }

/* Plants grid */
.plants-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: .8rem;
}

/* Plant card */
.plant-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}

.plant-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 2px 0 0 2px;
}

.plant-card.status-operational::before { background: var(--c-operational); }
.plant-card.status-shutdown::before    { background: var(--c-shutdown); }
.plant-card.status-construction::before { background: var(--c-construction); }
.plant-card.status-accident::before    { background: var(--c-accident); }

.plant-card:hover {
  border-color: var(--c-accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.plant-card.highlighted {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 2px var(--c-accent);
}

.plant-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .5rem;
  margin-bottom: .5rem;
}

.plant-name {
  font-weight: 700;
  font-size: .9rem;
  line-height: 1.3;
}

.plant-distance {
  font-size: .85rem;
  font-weight: 700;
  color: var(--c-accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.plant-country {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: .5rem;
}

.plant-meta {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
}

.plant-badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .5rem;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
}

.plant-capacity {
  font-size: .75rem;
  color: var(--text-muted);
}

.no-results {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  font-size: .95rem;
}

/* ---------- Results section ---------- */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #ef4444;
  color: #fff;
  padding: .75rem 1.5rem;
  border-radius: 99px;
  font-size: .9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  transition: transform .3s cubic-bezier(.22,1,.36,1);
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
}

.toast.visible { transform: translateX(-50%) translateY(0); }

/* ---------- Footer ---------- */
.footer {
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  padding: 1.2rem 1.5rem;
  text-align: center;
  font-size: .78rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.footer-note { margin-top: .2rem; opacity: .6; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .main { padding: 1rem; gap: 1rem; }
  .search-card { padding: 1.2rem; }
  .search-title { font-size: 1.2rem; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .stat-value { font-size: 1.3rem; }
  #map { height: 360px; }
  .plants-header { flex-direction: column; align-items: flex-start; }
  .plants-grid { grid-template-columns: 1fr; }
  .btn-search { max-width: 100%; }
  .search-form { gap: 1rem; }
}

@media (max-width: 400px) {
  .header-inner { padding: 0 1rem; }
  .logo-text { font-size: 1rem; }
}

/* Transition for results appear */
.results-section {
  animation: fadeSlideIn .35s ease;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
