/* ============================================================
   Community Projects Dashboard — Stylesheet
   Clean light theme: white · grey · black
   ============================================================ */

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

/* ── Design tokens ── */
:root {
  --bg:           #f4f5f7;
  --surface:      #ffffff;
  --surface-2:    #f8f9fa;
  --surface-3:    #f0f1f3;
  --border:       #e4e5e9;
  --border-dark:  #cfd0d6;

  --text:         #111216;
  --text-muted:   #6b7280;
  --text-dim:     #9ca3af;

  --ok:    #16a34a;
  --warn:  #ca8a04;
  --err:   #dc2626;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow:    0 1px 4px rgba(0,0,0,0.07), 0 0 0 1px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);

  --radius:    10px;
  --radius-sm:  6px;
  --font:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, 'Cascadia Code', 'SF Mono', monospace;
}

/* ── Dark mode ── */
[data-theme="dark"] {
  --bg:          #0e1118;
  --surface:     #161b27;
  --surface-2:   #111520;
  --surface-3:   #1c2235;
  --border:      #252c3f;
  --border-dark: #343d52;
  --text:        #dde2ee;
  --text-muted:  #8b92a8;
  --text-dim:    #5c6478;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow:    0 1px 4px rgba(0,0,0,0.5), 0 0 0 1px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5), 0 0 0 1px rgba(0,0,0,0.2);
}

[data-theme="dark"] #site-header {
  background: rgba(22,27,39,0.92);
}

[data-theme="dark"] .leaflet-control-attribution {
  background: rgba(17,21,32,0.85) !important;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 3px; }

h1, h2, h3 { font-family: var(--font); }
a { color: var(--text); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════════════════════
   HEADER
═══════════════════════════════════════════════════════════ */
#site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-brand h1 {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.header-brand .subtitle {
  font-size: 0.68rem;
  color: var(--text-muted);
  display: none;
}

@media (min-width: 640px) { .header-brand .subtitle { display: block; } }

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
}

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

.status-pill.ok   .dot { background: var(--ok);   animation: pulse 2s infinite; }
.status-pill.warn .dot { background: var(--warn); }
.status-pill.err  .dot { background: var(--err);  }

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(22,163,74,0.4); }
  50%       { opacity: 0.7; box-shadow: 0 0 0 4px rgba(22,163,74,0); }
}

#live-clock {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-dim);
  padding-left: 4px;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 28px;
  height: 22px;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--surface-3); }

/* ═══════════════════════════════════════════════════════════
   MAIN LAYOUT
═══════════════════════════════════════════════════════════ */
main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Section card ── */
.dash-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface-2);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title .icon { font-size: 1rem; line-height: 1; }

.section-title h2 {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.section-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.68rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  flex-wrap: wrap;
}

.badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.62rem;
  font-family: var(--font-mono);
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge:hover { background: var(--surface-3); text-decoration: none; }

/* ═══════════════════════════════════════════════════════════
   MAPS — shared Leaflet styles
═══════════════════════════════════════════════════════════ */
.map-wrap { position: relative; background: var(--surface-2); }

.leaflet-map { width: 100%; height: 420px; }

/* Leaflet light-theme overrides */
.leaflet-container { background: var(--surface-2); }

.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content {
  margin: 10px 14px;
  font-size: 0.75rem;
  line-height: 1.7;
  font-family: var(--font);
}
.leaflet-popup-content b { color: var(--text); font-weight: 600; }
.leaflet-bar a {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.leaflet-bar a:hover { background: var(--surface-3); }
.leaflet-attribution-flag { display: none !important; }
.leaflet-control-attribution {
  background: rgba(255,255,255,0.85) !important;
  color: var(--text-dim) !important;
  font-size: 0.58rem !important;
}
.leaflet-control-attribution a { color: var(--text-muted) !important; }

.plane-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25));
}

/* ═══════════════════════════════════════════════════════════
   SECTION 1 — WEATHER (top, full width)
═══════════════════════════════════════════════════════════ */
.weather-body {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: 120px;
}

.weather-primary {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 24px;
  padding: 20px 28px;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.temp-display {
  display: flex;
  align-items: baseline;
  gap: 2px;
  line-height: 1;
}

.temp-value {
  font-size: 3.2rem;
  font-weight: 300;
  color: var(--text);
  letter-spacing: -0.03em;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}

.temp-unit { font-size: 1.4rem; color: var(--text-muted); font-weight: 300; }

.humidity-display { text-align: center; }

.humidity-value {
  font-size: 1.6rem;
  font-weight: 300;
  color: var(--text);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.weather-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Secondary cards in a horizontal strip */
.weather-grid {
  flex: 1;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0;
}

.weather-card {
  flex: 1;
  min-width: 90px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px 18px;
  border-right: 1px solid var(--border);
  gap: 3px;
  background: var(--surface);
  transition: background 0.1s;
}

.weather-card:last-child { border-right: none; }
.weather-card:hover { background: var(--surface-2); }

.weather-card .w-icon { font-size: 1rem; margin-bottom: 2px; line-height: 1; }
.weather-card .w-label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-dim); }
.weather-card .w-value { font-size: 1rem; font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }
.weather-card .w-unit  { font-size: 0.65rem; color: var(--text-muted); margin-left: 1px; }

@media (max-width: 800px) {
  .weather-body { flex-direction: column; }
  .weather-primary { border-right: none; border-bottom: 1px solid var(--border); }
  .weather-grid { flex-wrap: wrap; }
  .weather-card { min-width: 80px; flex: 0 0 calc(50% - 0px); border-bottom: 1px solid var(--border); }
  .weather-card:nth-child(even) { border-right: none; }
}

.live-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6rem;
  color: var(--ok);
  padding: 1px 7px;
  border-radius: 3px;
  border: 1px solid rgba(22,163,74,0.25);
  background: rgba(22,163,74,0.06);
  font-family: var(--font-mono);
}
.live-tag::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--ok);
  display: block;
  animation: pulse 1.5s infinite;
}

/* ═══════════════════════════════════════════════════════════
   SECTION 2 — ADS-B / FLIGHT TRACKER
═══════════════════════════════════════════════════════════ */
.adsb-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  height: 420px;
}

@media (max-width: 860px) {
  .adsb-layout { grid-template-columns: 1fr; height: auto; }
  .adsb-layout .leaflet-map { height: 320px; }
  #aircraft-sidebar { height: 220px; border-left: none; border-top: 1px solid var(--border); }
}

#aircraft-sidebar {
  background: var(--surface-2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.65rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  display: flex;
  justify-content: space-between;
  background: var(--surface);
}

#aircraft-list { overflow-y: auto; flex: 1; }

.aircraft-item {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 8px;
  align-items: center;
}
.aircraft-item:hover { background: var(--surface-3); }

.aircraft-callsign { font-family: var(--font-mono); font-size: 0.7rem; font-weight: 500; color: var(--text); }
.aircraft-type     { font-size: 0.62rem; color: var(--text-dim); }
.aircraft-alt      { font-family: var(--font-mono); font-size: 0.62rem; color: var(--text-muted); text-align: right; }
.aircraft-details  { grid-column: 1 / -1; font-size: 0.6rem; color: var(--text-dim); font-family: var(--font-mono); }

.no-data-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 80px;
  gap: 6px;
  color: var(--text-dim);
  font-size: 0.72rem;
  text-align: center;
  padding: 20px;
}
.no-data-msg .emoji { font-size: 1.8rem; }

#adsb-iframe-wrap iframe { width: 100%; height: 480px; border: none; display: block; }

/* ═══════════════════════════════════════════════════════════
   BOTTOM ROW — TinyGS + All-Sky (side by side)
═══════════════════════════════════════════════════════════ */
.bottom-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 900px) { .bottom-row { grid-template-columns: 1fr; } }

/* ── TinyGS ── */
.tinygs-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  height: 380px;
  overflow: hidden;
}

@media (max-width: 700px) {
  .tinygs-layout { grid-template-columns: 1fr; height: auto; overflow: visible; }
  #tinygs-stats-panel { border-left: none; border-top: 1px solid var(--border); height: 280px; }
}

.tinygs-layout .leaflet-map { height: 100%; }

#tinygs-stats-panel {
  background: var(--surface-2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0; /* allows flex children to shrink within the grid cell */
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.stat-cell {
  padding: 14px 16px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
}
.stat-cell:nth-child(even) { border-right: none; }
.stat-cell:nth-last-child(-n+2) { border-bottom: none; }

.stat-label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-dim); }
.stat-value { font-family: var(--font-mono); font-size: 1.2rem; font-weight: 500; color: var(--text); line-height: 1.2; }

.packets-head {
  padding: 8px 14px;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

#packet-list { overflow-y: auto; flex: 1; }

.packet-item {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 8px;
  font-size: 0.68rem;
}

.packet-sat  { font-weight: 500; color: var(--text); font-size: 0.7rem; }
.packet-time { font-family: var(--font-mono); font-size: 0.6rem; color: var(--text-dim); text-align: right; }
.packet-meta { font-family: var(--font-mono); font-size: 0.6rem; color: var(--text-muted); }
.packet-rssi { font-family: var(--font-mono); font-size: 0.6rem; color: var(--text-dim); text-align: right; }

/* ── Meshtastic ── */
.meshtastic-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  height: 380px;
  overflow: hidden;
}

@media (max-width: 700px) {
  .meshtastic-layout { grid-template-columns: 1fr; height: auto; overflow: visible; }
  #mesh-stats-panel { border-left: none; border-top: 1px solid var(--border); height: 280px; }
}

.meshtastic-layout .leaflet-map { height: 100%; }

#mesh-stats-panel {
  background: var(--surface-2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

#mesh-node-list { overflow-y: auto; flex: 1; }

.mesh-node-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
  color: #ffffff;
  background: #10b981;
  border: 1.5px solid #047857;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  text-align: center;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.mesh-node-marker.stale {
  background: #94a3b8;
  border-color: #64748b;
}

/* ── All-sky camera ── */
#allsky-section {
  display: flex;
  flex-direction: column;
}

#allsky-image-wrap {
  flex: 1;
  position: relative;
  background: #0a0a0f;
  overflow: hidden;
  min-height: 200px;
}

#allsky-img, #allsky-stream {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.allsky-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 6px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  display: flex;
  justify-content: space-between;
  font-size: 0.62rem;
  font-family: var(--font-mono);
  color: rgba(255,255,255,0.6);
}

.allsky-meta {
  padding: 8px 14px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.allsky-meta span { display: flex; align-items: center; gap: 4px; }

/* ═══════════════════════════════════════════════════════════
   FOOTER
═══════════════════════════════════════════════════════════ */
footer {
  border-top: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-dim);
  flex-wrap: wrap;
  gap: 8px;
  max-width: 1600px;
  margin: 0 auto;
}

footer .links { display: flex; gap: 12px; }
footer a { color: var(--text-muted); }
footer a:hover { color: var(--text); text-decoration: none; }

/* ═══════════════════════════════════════════════════════════
   LOADING / ERROR STATES
═══════════════════════════════════════════════════════════ */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 80px;
  gap: 8px;
  color: var(--text-dim);
  font-size: 0.72rem;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

.error-box {
  padding: 14px 18px;
  background: rgba(220,38,38,0.04);
  border-left: 3px solid var(--err);
  margin: 12px;
  font-size: 0.72rem;
  color: var(--err);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.config-warning {
  padding: 12px 18px;
  background: rgba(202,138,4,0.05);
  border-left: 3px solid var(--warn);
  font-size: 0.72rem;
  color: var(--text-muted);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 12px;
}

/* ── Range ring tooltip ── */
.range-tooltip {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-muted) !important;
  font-size: 0.6rem !important;
  font-family: var(--font-mono) !important;
  padding: 2px 6px !important;
  border-radius: 3px !important;
  box-shadow: none !important;
}
.range-tooltip::before { display: none !important; }

/* ═══════════════════════════════════════════════════════════
   OFFLINE BANNER
═══════════════════════════════════════════════════════════ */
#offline-banner {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--err);
  color: #fff;
  padding: 8px 16px;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 500;
  display: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
#offline-banner.visible { display: block; }

/* ═══════════════════════════════════════════════════════════
   STALE TIMESTAMP INDICATOR
═══════════════════════════════════════════════════════════ */
/* The Updated-at <span>s in each section-meta go orange when the tile
   hasn't refreshed successfully within its expected window. The text
   itself changes to "Stale · last updated Xm ago" (see TileState in app.js). */
.section-meta > span.stale,
#allsky-timestamp.stale {
  color: var(--warn);
  font-weight: 500;
}
.section-meta > span.stale::before,
#allsky-timestamp.stale::before {
  content: "⚠ ";
  margin-right: 2px;
}

/* ═══════════════════════════════════════════════════════════
   UTILITY
═══════════════════════════════════════════════════════════ */
.hidden { display: none !important; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ═══════════════════════════════════════════════════════════
   MOBILE RESPONSIVE TWEAKS
═══════════════════════════════════════════════════════════ */
@media (max-width: 560px) {
  /* Tighter header on phones */
  #site-header { padding: 10px 12px; }
  .header-brand h1 { font-size: 1.05rem; }

  /* Section padding trimmed so maps have breathing room */
  .dash-section { padding: 12px; }
  .section-header { gap: 6px; }
  .section-title h2 { font-size: 1rem; }
}

@media (max-width: 480px) {
  .status-pill span:not(.dot) { display: none; }
  .status-pill { padding: 3px 6px; }
  .header-status { gap: 4px; flex-wrap: wrap; }
  #live-clock { font-size: 0.62rem; }
  /* Hide the section-meta updated text on very narrow screens — the pill
     already conveys state and saves a whole line of real estate. */
  .section-meta { font-size: 0.7rem; }
}
