/* ── CSS Custom Properties ───────────────────────────────────────────────── */
:root {
  --bg:              #f0f4f8;
  --panel-bg:        #ffffff;
  --panel-border:    #dde3ea;
  --text:            #1a202c;
  --text-secondary:  #4a5568;
  --accent:          #3b82f6;
  --accent-hover:    #2563eb;
  --detail-bg:       #f7fafc;
  --forecast-bg:     #f0f4f8;
  --shadow:          0 4px 24px rgba(0,0,0,0.12);
  --toast-bg:        #e53e3e;
  --spinner-color:   #3b82f6;
  --toggle-bg:       #e2e8f0;
  --toggle-text:     #1a202c;
}

[data-theme="dark"] {
  --bg:              #0f172a;
  --panel-bg:        #1e293b;
  --panel-border:    #334155;
  --text:            #f1f5f9;
  --text-secondary:  #94a3b8;
  --accent:          #60a5fa;
  --accent-hover:    #93c5fd;
  --detail-bg:       #263044;
  --forecast-bg:     #1a2744;
  --shadow:          0 4px 24px rgba(0,0,0,0.5);
  --toast-bg:        #c53030;
  --spinner-color:   #60a5fa;
  --toggle-bg:       #334155;
  --toggle-text:     #f1f5f9;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
}

/* ── Map ─────────────────────────────────────────────────────────────────── */
#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  cursor: crosshair;
}

/* ── Map Controls (top-right cluster) ───────────────────────────────────── */
#map-controls {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  gap: 8px;
  align-items: center;
}

#map-controls button {
  height: 44px;
  border-radius: 22px;
  border: none;
  background: var(--toggle-bg);
  color: var(--toggle-text);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.3s, transform 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#map-controls button:hover { transform: scale(1.05); }

#theme-toggle {
  width: 44px;
  font-size: 20px;
}

#unit-toggle {
  padding: 0 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* ── Measure hint (bottom-left) ──────────────────────────────────────────── */
#measure-hint {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--toggle-bg);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 16px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

#measure-hint.active { opacity: 1; }

/* ── Measure label (distance tooltip on map) ─────────────────────────────── */
.measure-label {
  background: none;
  border: none;
}

.measure-label span {
  display: inline-block;
  background: #f97316;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  white-space: nowrap;
}

/* ── Loading Spinner ─────────────────────────────────────────────────────── */
#loading-spinner {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(2px);
}

#loading-spinner[hidden] { display: none; }

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

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

/* ── Error Toast ─────────────────────────────────────────────────────────── */
#error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  background: var(--toast-bg);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  max-width: 360px;
  text-align: center;
  animation: toast-in 0.3s ease;
}

#error-toast[hidden] { display: none; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Weather Panel ───────────────────────────────────────────────────────── */
#weather-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  z-index: 900;
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4,0,0.2,1), background 0.3s, border-color 0.3s;
}

#weather-panel.open {
  transform: translateX(0);
}

#weather-panel[hidden] {
  /* keep hidden attribute working alongside animation */
  display: none;
}

/* ── Panel Header ────────────────────────────────────────────────────────── */
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--panel-border);
  gap: 12px;
}

#location-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

#location-coords {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

#close-panel {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

#close-panel:hover {
  color: var(--text);
  background: var(--detail-bg);
}

/* ── Current Conditions ──────────────────────────────────────────────────── */
.current-conditions {
  padding: 20px;
  border-bottom: 1px solid var(--panel-border);
}

.current-main {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

#weather-icon { flex-shrink: 0; }

.temp-large {
  display: block;
  font-size: 42px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.weather-desc {
  display: block;
  font-size: 14px;
  color: var(--text-secondary);
  text-transform: capitalize;
  margin-top: 4px;
}

.current-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.detail-item {
  background: var(--detail-bg);
  border-radius: 8px;
  padding: 10px 12px;
}

.detail-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.detail-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

/* ── Location Info ───────────────────────────────────────────────────────── */
.location-info-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--panel-border);
}

.loc-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.loc-flag {
  font-size: 32px;
  line-height: 1;
  flex-shrink: 0;
}

.loc-place {
  display: block;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.loc-region {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.loc-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ── Forecast ────────────────────────────────────────────────────────────── */
.forecast-section {
  padding: 20px;
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.forecast-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.forecast-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--forecast-bg);
  border-radius: 10px;
  padding: 10px 14px;
  gap: 8px;
}

.fc-day {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  width: 48px;
}

.fc-icon {
  width: 36px;
  height: 36px;
}

.fc-desc {
  flex: 1;
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: capitalize;
  text-align: center;
}

.fc-temps {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  white-space: nowrap;
}

.forecast-unavailable {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  padding: 12px 0;
}

.fc-temps .fc-low {
  color: var(--text-secondary);
  font-weight: 400;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 599px) {
  #weather-panel {
    width: 100%;
    top: auto;
    height: 60vh;
    transform: translateY(100%);
    border-left: none;
    border-top: 1px solid var(--panel-border);
    border-radius: 16px 16px 0 0;
  }

  #weather-panel.open {
    transform: translateY(0);
  }

  #theme-toggle {
    top: 12px;
    right: 12px;
  }

  .current-details {
    grid-template-columns: 1fr 1fr;
  }
}
