/* =============================================
   NORDIC WEATHER — app.css v30
   ============================================= */

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

/* ---- Design Tokens ---- */
:root {
  --bg:           #f0f2f7;
  --panel:        #ffffff;
  --sidebar-bg:   #ffffff;
  --sidebar-w:    210px;
  --text:         #1a2236;
  --text-soft:    #4a5568;
  --muted:        #8896aa;
  --border:       #e2e8f2;
  --shadow-sm:    0 1px 4px rgba(26,34,54,0.07);
  --shadow-md:    0 4px 20px rgba(26,34,54,0.10);
  --shadow-lg:    0 12px 48px rgba(26,34,54,0.14);
  --radius:       14px;
  --radius-sm:    8px;

  /* Metric colours */
  --c-temp-out:   #3b82f6;
  --c-temp-in:    #f59e0b;
  --c-hum-out:    #10b981;
  --c-hum-in:     #8b5cf6;
  --c-pressure:   #06b6d4;

  /* Health / status */
  --health:       #10b981;

  /* Dynamic comfort colour vars (set by JS) */
  --temp-out-feel: var(--c-temp-out);
  --temp-in-feel:  var(--c-temp-in);
  --hum-out-feel:  var(--c-hum-out);
  --hum-in-feel:   var(--c-hum-in);
}

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

html {
  min-width: 320px;
  scroll-behavior: smooth;
}

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

h1, h2, h3, h4, p { margin: 0; }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---- Screen-reader only ---- */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* =============================================
   LAYOUT: Sidebar + Main
   ============================================= */

/* ---- Mobile Topbar (hidden on desktop) ---- */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0 18px;
  align-items: center;
  justify-content: space-between;
  z-index: 200;
  box-shadow: var(--shadow-sm);
}

.mobile-topbar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.hamburger {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-soft);
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.2s ease;
}

.hamburger.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.is-open span:nth-child(2) { opacity: 0; }
.hamburger.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0 0 24px;
  z-index: 150;
  overflow-y: auto;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 20px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}

.brand-icon {
  width: 22px;
  height: 22px;
  color: var(--c-temp-out);
  flex-shrink: 0;
}

/* ---- Navigation ---- */
.nav-list {
  list-style: none;
  margin: 0;
  padding: 0 10px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
  margin-bottom: 2px;
}

.nav-item svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.nav-item:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-item.is-active {
  background: #eff6ff;
  color: var(--c-temp-out);
  font-weight: 600;
}

/* ---- Sidebar Forecast ---- */
.sidebar-forecast {
  margin: 16px 14px;
  padding: 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.sf-icon {
  font-size: 26px;
  animation: weather-pulse 4s ease-in-out infinite;
  flex-shrink: 0;
}

.sf-text strong {
  display: block;
  font-size: 13px;
  color: var(--c-temp-out);
  font-weight: 600;
}

.sf-text span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.4;
}

/* ---- Sidebar Status ---- */
.sidebar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  font-size: 12px;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--health);
  flex-shrink: 0;
  transition: background 0.3s ease;
}

.status-dot.red   { background: #ef4444; }
.status-dot.orange { background: #f59e0b; }
.status-dot.green  { background: #10b981; }

/* ---- Sidebar Backdrop (mobile) ---- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26, 34, 54, 0.4);
  z-index: 140;
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.is-visible {
  opacity: 1;
}

/* ---- Main Content ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  padding: 32px 28px 48px;
  max-width: 1200px;
}

/* =============================================
   PAGE STRUCTURE
   ============================================= */

.page {
  animation: fade-in 0.25s ease;
}

.page[hidden] { display: none; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1.1;
}

.page-subtitle {
  font-size: 14px;
  color: var(--muted);
  margin-top: 5px;
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

/* ---- Clock ---- */
.clock {
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 500;
  white-space: nowrap;
}

/* ---- Health Indicator ---- */
.health-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-soft);
  box-shadow: var(--shadow-sm);
}

.health-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--health);
}

/* =============================================
   OVERVIEW LAYOUT
   ============================================= */

.overview-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 22px;
  align-items: start;
}

/* ---- Barometer ---- */
.barometer-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.barometer-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#barometerCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---- Forecast Card ---- */
.forecast-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.forecast-card:hover {
  box-shadow: var(--shadow-md);
}

.fc-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #eff6ff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.fc-icon {
  font-size: 24px;
  animation: weather-pulse 4s ease-in-out infinite;
  display: block;
}

.fc-body {
  flex: 1;
  min-width: 0;
}

.fc-body strong {
  display: block;
  font-size: 15px;
  color: var(--c-temp-out);
  font-weight: 600;
}

.fc-body p {
  font-size: 13px;
  color: var(--text-soft);
  margin-top: 3px;
  line-height: 1.4;
}

.fc-arrow {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.fc-arrow:hover {
  background: var(--bg);
  color: var(--text);
}

.fc-arrow svg {
  width: 16px;
  height: 16px;
}

/* ---- Metric Card Grid ---- */
.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ---- Metric Card ---- */
.mcard {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 14px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  outline: none;
  transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
}

.mcard:hover,
.mcard:focus-visible {
  box-shadow: var(--shadow-md);
  border-color: #c7d7f0;
  transform: translateY(-1px);
}

.mcard.full-width {
  grid-column: 1 / -1;
}

.mcard-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.mcard-icon {
  width: 16px;
  height: 16px;
  color: var(--muted);
  flex-shrink: 0;
}

.mcard-label {
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 500;
  flex: 1;
}

.forecast-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(6, 182, 212, 0.12);
  color: var(--c-pressure);
}

.mcard-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-bottom: 8px;
}

.mcard-num {
  font-size: 42px;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  transition: color 0.3s ease;
}

.temp-out .mcard-num  { color: var(--temp-out-feel); }
.temp-in  .mcard-num  { color: var(--temp-in-feel); }
.hum-out  .mcard-num  { color: var(--hum-out-feel); }
.hum-in   .mcard-num  { color: var(--hum-in-feel); }
.pressure .mcard-num  { color: var(--c-pressure); }

.mcard-unit {
  font-size: 16px;
  font-weight: 500;
  color: var(--muted);
}

/* ---- Sparklines ---- */
.sparkline {
  display: block;
  width: 100%;
  height: 36px;
  margin-bottom: 6px;
}

/* ---- Pressure Trend ---- */
.pressure-trend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: -4px 0 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--c-pressure);
}

/* ---- Card Extremes (expand on click) ---- */
.mcard-extremes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transform: translateY(6px);
  transition: max-height 0.28s ease, opacity 0.22s ease, transform 0.28s ease, margin-top 0.28s ease;
}

.mcard.is-expanded .mcard-extremes {
  max-height: 80px;
  opacity: 1;
  transform: translateY(0);
  margin-top: 10px;
}

.mcard-extremes div {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.mcard-extremes span,
.mcard-extremes time {
  display: block;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}

.mcard-extremes strong {
  display: block;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 2px 0 1px;
}

/* ---- Status Strip ---- */
.status-strip {
  display: flex;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 24px;
  margin-top: 20px;
  box-shadow: var(--shadow-sm);
  gap: 0;
  flex-wrap: wrap;
  row-gap: 14px;
}

.ss-item {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 150px;
}

.ss-item svg {
  width: 20px;
  height: 20px;
  color: var(--muted);
  flex-shrink: 0;
}

.ss-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.ss-value {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-top: 2px;
}

.ss-divider {
  width: 1px;
  height: 36px;
  background: var(--border);
  margin: 0 20px;
  flex-shrink: 0;
}

/* =============================================
   HISTORY PAGE
   ============================================= */

.range-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.range-controls button {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 16px;
  transition: border-color 0.15s, color 0.15s, background 0.15s, box-shadow 0.15s;
}

.range-controls button:hover {
  border-color: var(--c-temp-out);
  color: var(--text);
}

.range-controls button.is-active {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
  box-shadow: 0 4px 12px rgba(26,34,54,0.15);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 14px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-soft);
}

.legend-item::before {
  content: '';
  display: inline-block;
  width: 20px;
  height: 3px;
  border-radius: 10px;
}

.temp-out-key::before  { background: var(--c-temp-out); }
.temp-in-key::before   { background: var(--c-temp-in); }
.hum-out-key::before   { background: var(--c-hum-out); }
.hum-in-key::before    { background: var(--c-hum-in); }
.pressure-key::before  { background: var(--c-pressure); }

.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

#historyChart {
  display: block;
  width: 100%;
  height: 720px;
  touch-action: none;
}

/* =============================================
   TRENDS PAGE
   ============================================= */

.trends-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.trend-card.wide {
  grid-column: 1 / -1;
}

.trend-card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 12px;
}

.trend-card canvas {
  display: block;
  width: 100%;
  height: 180px;
}

/* =============================================
   COMPARE PAGE
   ============================================= */

.compare-table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.compare-table th,
.compare-table td {
  padding: 13px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.compare-table th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--bg);
}

.compare-table td:first-child {
  font-weight: 500;
  color: var(--text-soft);
}

.compare-table td.diff-pos { color: #10b981; font-weight: 600; }
.compare-table td.diff-neg { color: #ef4444; font-weight: 600; }
.compare-table td.diff-zero { color: var(--muted); }

.compare-empty {
  text-align: center;
  color: var(--muted);
  padding: 32px !important;
}

.compare-chart-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.compare-chart-wrap h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 14px;
}

#compareChart {
  display: block;
  width: 100%;
  height: 240px;
}

/* =============================================
   SETTINGS PAGE
   ============================================= */

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

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

.settings-card h2 {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 14px;
}

.settings-dl {
  margin: 0 0 16px;
}

.settings-dl div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.settings-dl dt {
  color: var(--text-soft);
  font-size: 13px;
}

.settings-dl dd {
  margin: 0;
  font-weight: 600;
  font-size: 13px;
}

.settings-hint {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 500;
  margin-bottom: 14px;
}

.field-input {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
  margin-top: 6px;
  color: var(--text);
  transition: border-color 0.15s;
  outline: none;
}

.field-input:focus {
  border-color: var(--c-temp-out);
}

.btn-primary {
  display: block;
  width: 100%;
  background: var(--text);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 11px;
  transition: background 0.15s, box-shadow 0.15s;
}

.btn-primary:hover {
  background: #2c3a55;
  box-shadow: 0 4px 14px rgba(26,34,54,0.18);
}

.btn-secondary {
  display: inline-block;
  background: none;
  color: var(--c-temp-out);
  border: 1px solid var(--c-temp-out);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  padding: 8px 16px;
  transition: background 0.15s;
}

.btn-secondary:hover {
  background: #eff6ff;
}

/* =============================================
   WEATHER ICON ANIMATION
   ============================================= */

@keyframes weather-pulse {
  0%, 100% {
    transform: scale(1);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.12));
  }
  50% {
    transform: scale(1.14);
    filter: drop-shadow(0 4px 12px rgba(6,182,212,0.4));
  }
}

/* =============================================
   RESPONSIVE BREAKPOINTS
   ============================================= */

/* Tablet: sidebar collapses */
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }

  .mobile-topbar {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    width: 240px;
    top: 0;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
  }

  .main-content {
    margin-left: 0;
    padding: 20px 16px 40px;
    margin-top: 56px;
  }

  .overview-layout {
    grid-template-columns: 1fr;
  }

  .barometer-wrap {
    max-width: 360px;
    margin: 0 auto;
    width: 100%;
    aspect-ratio: 1;
  }

  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
    gap: 12px;
  }

  .page-header h1 {
    font-size: 24px;
  }

  .page-header-right {
    width: 100%;
    justify-content: space-between;
  }

  #historyChart {
    height: 640px;
  }

  .trends-grid {
    grid-template-columns: 1fr;
  }

  .trend-card.wide {
    grid-column: 1;
  }
}

/* Small mobile */
@media (max-width: 540px) {
  .main-content {
    padding: 16px 12px 32px;
  }

  .overview-layout {
    gap: 14px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .mcard-num {
    font-size: 36px;
  }

  .status-strip {
    padding: 14px 16px;
    gap: 0;
  }

  .ss-divider {
    display: none;
  }

  .ss-item {
    min-width: 50%;
    flex: 0 0 50%;
  }

  #historyChart {
    height: 560px;
  }

  .page-header h1 {
    font-size: 22px;
  }

  .range-controls button {
    padding: 6px 10px;
    font-size: 12px;
  }

  #compareChart {
    height: 180px;
  }
}

/* Very small */
@media (max-width: 380px) {
  .main-content {
    padding: 12px 10px 24px;
  }

  .mcard-num {
    font-size: 30px;
  }
}

/* Wide desktop: more room */
@media (min-width: 1200px) {
  .main-content {
    padding: 36px 40px 56px;
  }

  .overview-layout {
    grid-template-columns: 420px 1fr;
  }
}
