:root {
  --bg: #f2f4f7;
  --card-bg: #ffffff;
  --text: #1a1d23;
  --text-muted: #667085;
  --accent: #2f6feb;
  --border: #e4e7ec;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  --good: #12b76a;
  --warn: #f79009;
  --bad: #f04438;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card-bg: #1a1d24;
    --text: #e6e8ec;
    --text-muted: #9aa2b1;
    --accent: #5b8def;
    --border: #2a2e37;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s, color 0.2s;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
}
.topbar h1 {
  font-size: 1.3rem;
  font-weight: 600;
  margin: 0;
}
.clock {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.fire-banner {
  max-width: 1200px;
  margin: 0 auto 4px;
  padding: 10px 28px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #fff;
  background: linear-gradient(90deg, #d92d20, #f04438);
  border-radius: 10px;
}
.fire-banner[data-severity="watch"] {
  background: linear-gradient(90deg, #b54708, #f79009);
}
.fire-banner-icon {
  font-size: 1.1rem;
  line-height: 1;
}
.fire-banner[hidden] {
  display: none;
}

.dashboard {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 40px;
  display: grid;
  gap: 18px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.top-grid {
  display: grid;
  grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.brief-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.brief-table td {
  padding: 5px 0;
}
.brief-table .label {
  color: var(--text-muted);
}
.brief-table .value {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
}
.hero-temp {
  display: flex;
  align-items: flex-start;
}
.big-number {
  font-size: 5rem;
  font-weight: 700;
  line-height: 1;
}
.hero-temp .unit {
  font-size: 1.8rem;
  color: var(--text-muted);
  margin-top: 10px;
}
.hero-location {
  color: var(--text-muted);
  font-size: 0.95rem;
}
.hero-updated {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 8px;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 600;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
}
.panel-title {
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.panel-note {
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.embed-frame {
  width: 100%;
  height: 280px;
  border: 0;
  border-radius: 10px;
  display: block;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}
.period-toggle {
  display: flex;
  gap: 6px;
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
}
.period-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}
.period-btn.active {
  background: var(--accent);
  color: #fff;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 20px;
}
.chart-box {
  position: relative;
  height: 220px;
}

.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  text-align: center;
}

.celestial-grid {
  display: grid;
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
  gap: 18px;
}

.events-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.event-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
}
.event-item.not-visible {
  opacity: 0.6;
}
.event-days {
  min-width: 52px;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
}
.event-days .unit-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
}
.event-body {
  flex: 1;
}
.event-title {
  font-weight: 600;
}
.event-note {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.event-visibility {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.event-visibility.yes {
  background: rgba(18, 183, 106, 0.15);
  color: var(--good);
}
.event-visibility.no {
  background: rgba(240, 68, 56, 0.15);
  color: var(--bad);
}

.status-ok { color: var(--good); }
.status-low { color: var(--bad); }
.status-unknown { color: var(--text-muted); }

.footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 20px;
}
.footer a { color: var(--accent); }

/* Below this width, the panel/chart minmax() floors (320-360px) no longer
   fit within the viewport minus padding, so auto-fit can't wrap them -
   force a single column instead of letting them overflow horizontally. */
@media (max-width: 680px) {
  .top-grid,
  .panel-grid,
  .chart-grid,
  .celestial-grid {
    grid-template-columns: 1fr;
  }
  .dashboard {
    padding: 0 14px 30px;
  }
  .card {
    padding: 16px;
  }
  .big-number {
    font-size: 3.8rem;
  }
}
