/* ============================================
   Veðursjá — Weather & More for Iceland
   ============================================ */

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

:root {
  --bg: #f8fafc; --bg-panel: #ffffff; --bg-panel-hover: #f1f5f9;
  --text: #0f172a; --text-muted: #64748b; --border: #e2e8f0;
  --accent: #2563eb; --accent-hover: #1d4ed8;
  --shadow: 0 4px 24px rgba(0,0,0,0.08); --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --radius: 14px; --radius-sm: 10px;
  --topbar-h: 56px; --sidebar-w: 380px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --glass: rgba(255,255,255,0.85); --glass-border: rgba(255,255,255,0.5);
}

[data-theme="dark"] {
  --bg: #0c1222; --bg-panel: #1a2332; --bg-panel-hover: #253344;
  --text: #e8edf5; --text-muted: #7d8fa8; --border: #2a3a4e;
  --accent: #3b82f6; --accent-hover: #60a5fa;
  --shadow: 0 4px 24px rgba(0,0,0,0.35); --shadow-sm: 0 2px 8px rgba(0,0,0,0.25);
  --glass: rgba(26,35,50,0.88); --glass-border: rgba(42,58,78,0.6);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body { font-family: var(--font); background: var(--bg); color: var(--text); overflow: hidden; height: 100dvh; width: 100vw; }

#map { position: absolute; inset: 0; z-index: 0; }

/* ---- Glassmorphism panels ---- */
.glass-panel {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

/* ---- Top bar ---- */
#topbar {
  position: fixed; top: 12px; left: 12px; right: 12px; height: var(--topbar-h);
  background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: space-between; padding: 0 14px;
  z-index: 100; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  gap: 12px;
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-center { flex: 1; max-width: 400px; margin: 0 auto; }

.logo { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.02em; }

.icon-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); transition: all 0.15s; font-size: 1.1rem;
}
.icon-btn:hover { background: var(--bg-panel-hover); color: var(--text); }

/* ---- Search ---- */
.search-box { position: relative; width: 100%; }
.search-box .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
#search-input {
  width: 100%; padding: 8px 12px 8px 36px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 0.8125rem; outline: none; transition: border-color 0.15s;
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text-muted); }

.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); overflow: hidden; z-index: 200;
}
.search-results.hidden { display: none; }
.search-result {
  padding: 10px 14px; cursor: pointer; font-size: 0.8125rem;
  border-bottom: 1px solid var(--border); transition: background 0.1s;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--bg-panel-hover); }

/* ---- Source toggle ---- */
.source-toggle { display: flex; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.source-btn {
  padding: 5px 12px; border: none; background: transparent; color: var(--text-muted);
  font-family: var(--font); font-size: 0.75rem; font-weight: 500; cursor: pointer;
  border-radius: 7px; transition: all 0.15s; white-space: nowrap;
}
.source-btn:hover { color: var(--text); }
.source-btn.active { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }

/* ---- Layer controls ---- */
#layer-controls {
  position: fixed; top: calc(12px + var(--topbar-h) + 12px); right: 12px;
  display: flex; flex-direction: column; gap: 4px; z-index: 90;
}
.layer-toggle {
  display: flex; align-items: center; gap: 6px; padding: 7px 12px;
  background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
  cursor: pointer; transition: all 0.15s; user-select: none;
  font-size: 0.75rem; font-weight: 500;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.layer-toggle:hover { border-color: var(--accent); }
.layer-toggle input { accent-color: var(--accent); width: 14px; height: 14px; }
.layer-icon { font-size: 0.875rem; line-height: 1; }
.layer-label { color: var(--text); }

/* ---- Info cards (Aurora, Avalanche) ---- */
#info-cards {
  position: fixed; bottom: 16px; left: 12px; display: flex; gap: 8px; z-index: 90;
}
.info-card {
  background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
  padding: 10px 14px; min-width: 160px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.info-card-header { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.info-card-icon { font-size: 1rem; }
.info-card-title { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.info-na { font-size: 0.75rem; color: var(--text-muted); }

/* Aurora mini chart */
.aurora-forecast { display: flex; gap: 6px; align-items: flex-end; height: 56px; }
.aurora-day { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1; }
.aurora-day-name { font-size: 0.5625rem; color: var(--text-muted); }
.aurora-bar { width: 16px; border-radius: 4px 4px 0 0; min-height: 4px; transition: height 0.3s; }
.aurora-bar.aurora-low { background: #22c55e; }
.aurora-bar.aurora-mid { background: #eab308; }
.aurora-bar.aurora-high { background: #a855f7; }
.aurora-kp { font-size: 0.625rem; font-weight: 600; color: var(--text); }

/* Avalanche zones */
.aval-zone { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 0.75rem; }
.aval-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.aval-region { color: var(--text); font-weight: 500; flex: 1; }
.aval-level { color: var(--text-muted); font-size: 0.6875rem; }

/* ---- Road legend ---- */
.legend-panel {
  position: fixed; bottom: 16px; right: 12px;
  background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-sm); padding: 10px 14px;
  z-index: 90; font-size: 0.75rem;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.legend-panel h3 { font-size: 0.625rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 6px; }
.legend-item { display: flex; align-items: center; gap: 6px; padding: 2px 0; color: var(--text); }
.legend-color { width: 20px; height: 3px; border-radius: 2px; flex-shrink: 0; }

/* ---- Sidebar ---- */
.sidebar {
  position: fixed; top: 12px; left: 12px; bottom: 12px; width: var(--sidebar-w);
  background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: var(--radius); box-shadow: var(--shadow); z-index: 110;
  display: flex; flex-direction: column; overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1), opacity 0.3s;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}
.sidebar.hidden { transform: translateX(calc(-1 * var(--sidebar-w) - 24px)); opacity: 0; pointer-events: none; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 1.05rem; font-weight: 600; }
.sidebar-content { flex: 1; overflow-y: auto; padding: 18px; }
.sidebar-footer { padding: 10px 18px; border-top: 1px solid var(--border); font-size: 0.6875rem; color: var(--text-muted); }
.sidebar-footer a { color: var(--accent); text-decoration: none; }
.forecast-section { margin-bottom: 20px; }
.forecast-section h3 { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 10px; }
.forecast-text-block { margin-bottom: 14px; }
.forecast-text-block h4 { font-size: 0.8125rem; font-weight: 600; margin-bottom: 4px; }
.forecast-text-block p { font-size: 0.8125rem; line-height: 1.6; color: var(--text-muted); }

/* ---- Popup ---- */
.popup-overlay {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: flex-end; justify-content: center;
  padding: 20px; background: rgba(0,0,0,0.12); transition: opacity 0.2s;
}
[data-theme="dark"] .popup-overlay { background: rgba(0,0,0,0.35); }
.popup-overlay.hidden { opacity: 0; pointer-events: none; }
.popup-overlay.hidden .popup-card { transform: translateY(20px); }
.popup-card {
  position: relative; background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px;
  min-width: 300px; max-width: 400px; width: 100%; max-height: 70vh; overflow-y: auto;
  transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
}
.popup-close-btn { position: absolute; top: 12px; right: 14px; background: none; border: none; font-size: 1.4rem; color: var(--text-muted); cursor: pointer; line-height: 1; }
.popup-close-btn:hover { color: var(--text); }
.popup-name { font-size: 1rem; font-weight: 600; margin-bottom: 2px; }
.popup-source { font-size: 0.625rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 12px; }
.popup-current { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.popup-temp { font-size: 2.25rem; font-weight: 700; line-height: 1; letter-spacing: -0.03em; }
.popup-details { font-size: 0.8125rem; color: var(--text-muted); line-height: 1.6; }
.popup-snow { margin-top: 4px; color: var(--accent); }

.popup-forecast-mini { display: flex; gap: 2px; border-top: 1px solid var(--border); padding-top: 12px; margin-bottom: 12px; }
.mini-hour { flex: 1; text-align: center; font-size: 0.6875rem; }
.mini-hour .mini-time { color: var(--text-muted); margin-bottom: 3px; }
.mini-hour .mini-icon { font-size: 1.2rem; margin-bottom: 2px; }
.mini-hour .mini-temp { font-weight: 600; color: var(--text); }

/* ---- 7-day forecast ---- */
.week-forecast { display: flex; gap: 2px; border-top: 1px solid var(--border); padding-top: 12px; }
.week-day { flex: 1; text-align: center; font-size: 0.6875rem; }
.week-day-name { color: var(--text-muted); margin-bottom: 3px; text-transform: capitalize; }
.week-day-icon { font-size: 1.1rem; margin-bottom: 2px; }
.week-day-temps { display: flex; gap: 4px; justify-content: center; }
.week-hi { font-weight: 600; color: var(--text); }
.week-lo { color: var(--text-muted); }
.week-day-wind { font-size: 0.5625rem; color: var(--text-muted); margin-top: 2px; }

/* ---- Road status ---- */
.road-status { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; color: #fff; margin: 4px 0 6px; }
.road-extra { font-size: 0.8125rem; color: var(--text-muted); margin-top: 4px; }

/* ---- Weather markers ---- */
.weather-marker { display: flex; flex-direction: column; align-items: center; cursor: pointer; gap: 3px; }
.weather-marker-dot {
  position: relative; width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); border: 2.5px solid rgba(255,255,255,0.9);
  box-shadow: 0 2px 10px rgba(0,0,0,0.25); display: flex; align-items: center;
  justify-content: center; font-size: 0.8125rem; font-weight: 700; color: #fff;
  transition: transform 0.15s; z-index: 2;
}
.weather-marker:hover .weather-marker-dot { transform: scale(1.1); }

/* Info panel below dot */
.weather-marker-info {
  background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: 6px; padding: 3px 7px; text-align: center;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 1px 6px rgba(0,0,0,0.12); max-width: 120px;
  pointer-events: none;
}
.wm-name { font-size: 0.625rem; font-weight: 600; color: var(--text); white-space: nowrap; line-height: 1.3; }
.wm-detail { font-size: 0.5625rem; color: var(--text-muted); white-space: nowrap; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; }

/* Wind arrow — shows direction wind is coming FROM */
.wind-arrow-wrap {
  position: absolute; inset: -8px; pointer-events: none;
  display: flex; align-items: flex-start; justify-content: center;
}
.wind-arrow-line {
  width: 2px; height: 12px; background: rgba(255,255,255,0.85);
  border-radius: 1px; position: relative;
}
.wind-arrow-line::after {
  content: ''; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 6px solid rgba(255,255,255,0.85);
}
[data-theme="dark"] .wind-arrow-line { background: rgba(200,220,255,0.7); }
[data-theme="dark"] .wind-arrow-line::after { border-top-color: rgba(200,220,255,0.7); }

/* Temp colors */
.weather-marker-dot.temp-freezing { background: #3b82f6; }
.weather-marker-dot.temp-cold { background: #06b6d4; }
.weather-marker-dot.temp-cool { background: #10b981; }
.weather-marker-dot.temp-mild { background: #eab308; }
.weather-marker-dot.temp-warm { background: #f97316; }
.weather-marker-dot.temp-hot { background: #ef4444; }

/* ---- Earthquake markers ---- */
.quake-marker {
  border-radius: 50%; background: rgba(239,68,68,0.35); border: 2px solid #ef4444;
  animation: quake-pulse 2s ease-in-out infinite; cursor: pointer;
}
.quake-marker.quake-medium { background: rgba(239,68,68,0.5); border-color: #dc2626; }
.quake-marker.quake-large { background: rgba(239,68,68,0.7); border-color: #b91c1c; animation-duration: 1.2s; }
@keyframes quake-pulse { 0%,100% { opacity: 0.7; transform: scale(1); } 50% { opacity: 1; transform: scale(1.15); } }

.quake-details { display: flex; gap: 14px; align-items: center; margin-top: 10px; }
.quake-mag { font-size: 2rem; font-weight: 700; color: #ef4444; }
.quake-info { font-size: 0.8125rem; color: var(--text-muted); line-height: 1.6; }

/* ---- Webcam marker ---- */
.webcam-marker {
  width: 26px; height: 26px; border-radius: 50%; background: var(--bg-panel);
  border: 2px solid var(--accent); box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; cursor: pointer; transition: transform 0.15s;
}
.webcam-marker:hover { transform: scale(1.2); }

/* ---- Loading ---- */
.loading-spinner { width: 22px; height: 22px; border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; margin: 16px auto; }
.loading-spinner.small { width: 16px; height: 16px; border-width: 2px; margin: 8px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Warning banner ---- */
.warning-banner { background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.3); border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 10px; }
[data-theme="dark"] .warning-banner { background: rgba(245,158,11,0.12); }
.warning-banner h4 { font-size: 0.8125rem; font-weight: 600; color: #b45309; margin-bottom: 3px; }
[data-theme="dark"] .warning-banner h4 { color: #fbbf24; }
.warning-banner p { font-size: 0.8125rem; color: #92400e; line-height: 1.5; }
[data-theme="dark"] .warning-banner p { color: #fde68a; }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  :root { --sidebar-w: 100vw; --topbar-h: 48px; }
  #topbar { top: 0; left: 0; right: 0; border-radius: 0; padding: 0 8px; }
  .logo { font-size: 1rem; }
  .topbar-center { max-width: 200px; }
  .source-toggle { display: none; }
  #layer-controls { top: calc(var(--topbar-h) + 6px); right: 6px; }
  .layer-toggle { padding: 5px 8px; }
  .layer-label { display: none; }
  .sidebar { top: 0; left: 0; bottom: 0; border-radius: 0; }
  #info-cards { bottom: 8px; left: 8px; flex-direction: column; gap: 4px; }
  .info-card { min-width: 140px; }
  .legend-panel { bottom: 8px; right: 8px; }
  .popup-card { min-width: unset; max-width: 95vw; }
}
