/* ============================================================
   MeteoScope — professional weather dashboard styles
   Design system: 8px spacing unit, system fonts, dark theme
   ============================================================ */

:root {
  --bg: #0f1115;
  --bg-elev: #161a21;
  --bg-card: #1a1e26;
  --bg-input: #12151b;
  --border: #262c37;
  --border-strong: #333b49;
  --text: #e5e7eb;
  --text-dim: #9aa3b2;
  --text-mute: #6b7280;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --success: #34d399;
  --warn: #fbbf24;
  --error: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.3);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  z-index: 1300;
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  font-size: 26px;
  color: var(--accent);
  text-shadow: 0 0 18px rgba(56, 189, 248, 0.6);
  line-height: 1;
}
.brand-text h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: 0.2px; }
.brand-sub { font-size: 11px; color: var(--text-mute); letter-spacing: 0.4px; text-transform: uppercase; }

.search-wrap { position: relative; flex: 1 1 auto; max-width: 420px; margin: 0 auto; }
#search-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 150ms ease-out, box-shadow 150ms ease-out;
}
#search-input::placeholder { color: var(--text-mute); }
#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
  z-index: 1200;
}
.search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background 150ms ease-out;
}
.search-item:hover, .search-item:focus-visible { background: var(--accent-soft); outline: none; }
.search-item .si-name { font-weight: 600; }
.search-item .si-meta { color: var(--text-mute); font-size: 12px; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease-out, border-color 150ms ease-out, transform 100ms ease-out;
}
.btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn .ic { font-size: 16px; line-height: 1; }

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.view-btn {
  padding: 9px 16px;
  background: var(--bg-card);
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease-out, color 150ms ease-out;
}
.view-btn + .view-btn { border-left: 1px solid var(--border-strong); }
.view-btn:hover { color: var(--text); }
.view-btn.is-active { background: var(--accent); color: #06202e; }
.view-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- Layout ---------- */
.layout {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.map-pane { position: relative; flex: 1 1 auto; min-width: 0; }
#map { position: absolute; inset: 0; background: #0b0e13; }

/* ---------- Map overlays ---------- */
.map-controls {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.layer-switch {
  display: inline-flex;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  pointer-events: auto;
}
.layer-btn {
  padding: 9px 14px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease-out, color 150ms ease-out;
}
.layer-btn + .layer-btn { border-left: 1px solid var(--border); }
.layer-btn:hover { color: var(--text); }
.layer-btn.is-active { background: var(--accent-soft); color: var(--accent); }
.layer-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.map-status {
  align-self: flex-start;
  padding: 6px 12px;
  background: rgba(15, 17, 21, 0.82);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

.legend {
  position: absolute;
  bottom: 24px;
  left: 16px;
  z-index: 1000;
  background: rgba(15, 17, 21, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  backdrop-filter: blur(6px);
}
.legend-title { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 6px; }
.legend-bar {
  width: 180px; height: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, #2b6cb0, #38bdf8, #fbbf24, #ef4444);
}
.legend-labels { display: flex; justify-content: space-between; font-size: 10px; color: var(--text-mute); margin-top: 4px; }

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(11, 14, 19, 0.72);
  backdrop-filter: blur(3px);
  color: var(--text-dim);
  font-size: 14px;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Side panel ---------- */
.side-panel {
  flex: 0 0 400px;
  max-width: 100%;
  background: var(--bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  z-index: 1000;
}
.panel-scroll { padding: 16px; display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.card-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.muted { color: var(--text-mute); font-size: 12px; }
.badge {
  background: var(--error);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 9px;
  min-width: 22px;
  text-align: center;
}
.badge.zero { background: var(--success); }

/* current conditions */
.current-grid { display: flex; gap: 20px; align-items: center; }
.cur-temp { display: flex; align-items: baseline; gap: 2px; }
.temp-big { font-size: 56px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.temp-unit { font-size: 22px; color: var(--text-dim); font-weight: 600; }
.cur-metrics { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.metric { display: flex; flex-direction: column; gap: 2px; }
.m-label { font-size: 11px; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.5px; }
.m-value { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* alerts */
.alerts-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alerts-list .empty-state { color: var(--text-mute); font-size: 13px; padding: 6px 0; }
.alert-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 13px;
}
.alert-item .a-icon { font-size: 16px; line-height: 1.2; }
.alert-item .a-title { font-weight: 700; }
.alert-item .a-desc { color: var(--text-dim); margin-top: 2px; }
.alert-item.severity-high { border-color: rgba(248, 113, 113, 0.5); background: rgba(248, 113, 113, 0.08); }
.alert-item.severity-mid { border-color: rgba(251, 191, 36, 0.5); background: rgba(251, 191, 36, 0.08); }

/* grid stats */
.grid-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { display: flex; flex-direction: column; gap: 3px; }
.s-label { font-size: 11px; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.5px; }
.s-value { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* forecast */
.chart-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.chart-tab {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease-out, color 150ms ease-out, border-color 150ms ease-out;
}
.chart-tab:hover { color: var(--text); border-color: var(--accent); }
.chart-tab.is-active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.chart-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.chart-wrap { position: relative; height: 240px; }

/* ---------- Footer ---------- */
.foot {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 20px;
  font-size: 11px;
  color: var(--text-mute);
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
}
.foot a { color: var(--text-dim); text-decoration: none; }
.foot a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- Leaflet dark tweaks ---------- */
.leaflet-container { background: #0b0e13; font-family: var(--font); }
.meteo-canvas { position: absolute; top: 0; left: 0; pointer-events: none; }
.dark-tiles { filter: brightness(0.82) contrast(1.05) saturate(0.9); }
.leaflet-control-attribution { background: rgba(15,17,21,0.7) !important; color: var(--text-mute) !important; font-size: 10px !important; }
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-control-zoom a { background: var(--bg-elev) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-control-zoom a:hover { background: var(--bg-card) !important; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .side-panel { flex-basis: 340px; }
  .brand-sub { display: none; }
}
@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .map-pane { flex: 1 1 55%; }
  .side-panel { flex: 1 1 45%; border-left: none; border-top: 1px solid var(--border); }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }
  .btn-label { display: none; }
  .temp-big { font-size: 44px; }
  .foot-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
