/* ------------------------------------------------
   THEME VARIABLES
--------------------------------------------------*/
:root {
  --bg: #0f1115;
  --fg: #e6e6e6;
  --muted: #a0a6b3;
  --card: #161925;
  --accent: #7aa2f7;
  --table-border: #24283b;
  --header-h: 0px; /* updated by JS */
}

.theme-light {
  --bg: #fafafa;
  --fg: #1d2330;
  --muted: #5c667a;
  --card: #ffffff;
  --accent: #2b6cb0;
  --table-border: #e9e9ef;
}
.theme-dark {
  /* default theme uses :root */
}
.theme-black {
  --bg: #000;
  --fg: #d8d8d8;
  --muted: #9a9a9a;
  --card: #0a0a0a;
  --accent: #5aa8ff;
  --table-border: #1a1a1a;
}
.theme-red {
  --bg: #000;
  --fg: #ff4d4d;
  --muted: #ff8080;
  --card: #090909;
  --accent: #ff4d4d;
  --table-border: #1a1a1a;
}

/* ------------------------------------------------
   GLOBAL / BASE
--------------------------------------------------*/
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  padding-top: var(--header-h); /* space for fixed header */
  background: var(--bg);
  color: var(--fg);
  font:
    14px/1.5 system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Ubuntu,
    Cantarell,
    Noto Sans,
    Arial;
}

/* ------------------------------------------------
   HEADER
--------------------------------------------------*/
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--table-border);
}
.app-header h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.2px;
}
.header-actions button {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--table-border);
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
}

/* ------------------------------------------------
   TABS
--------------------------------------------------*/
.tabs {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--table-border);
  background: var(--bg);
}
.tab {
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--table-border);
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0.85;
}
.tab.active {
  outline: 2px solid var(--accent);
  opacity: 1;
}

/* ------------------------------------------------
   CONTENT LAYOUT
--------------------------------------------------*/
.content {
  padding: 1rem;
  max-width: 1300px;
  margin: 0 auto;
}
.scroll-layout .card {
  margin-bottom: 1rem;
}
.card {
  background: var(--card);
  border: 1px solid var(--table-border);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}
.card-sub h3 {
  margin: 0.25rem 0 0.5rem;
  font-size: 0.95rem;
  color: var(--muted);
}

/* split for generic two-column cards */
.split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 900px) {
  .split {
    grid-template-columns: 1fr 1fr;
  }
}

/* ------------------------------------------------
   REGION DISK + TABLE LAYOUT
--------------------------------------------------*/
.region-wrap {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
}

/* disk fixed-ish size, table takes the rest */
.disk {
  flex: 0 0 320px;
  max-width: 320px;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: 1px dashed var(--table-border);
}
.region-list {
  flex: 1 1 auto;
  min-width: 0; /* allow table to fill remaining width */
}

/* ------------------------------------------------
   TOOLBAR
--------------------------------------------------*/
.toolbar {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.5rem;
  color: var(--muted);
}
.toolbar button {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--table-border);
  padding: 0.3rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
}

/* ------------------------------------------------
   CHART CONTAINERS
--------------------------------------------------*/
.chart {
  position: relative;
  width: 100%;
  height: 300px;
}
.chart.tall {
  height: 100%;
}
@media (min-width: 900px) {
  .chart {
    height: 340px;
  }
  .chart.tall {
    height: 100%;
  }
}
.chart > canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

#tab-flares .split {
  display: block; /* or grid with 1 column – both ok */
  grid-template-columns: 1fr;
}

/* ------------------------------------------------
   TABLES
--------------------------------------------------*/
table {
  width: 100%;
  border-collapse: collapse;
}
th,
td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--table-border);
  text-align: left;
}
thead th {
  font-weight: 600;
  color: var(--muted);
}
tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* trend arrows in flare table */
td.trend {
  text-align: center;
  font-size: 0.85rem;
}
.trend-up {
  color: #00ff00;
  font-weight: 900;
}
.trend-down {
  color: #ff4444;
  font-weight: 900;
}
.trend-same {
  color: #aaaaaa;
  font-weight: 900;
}

/* ------------------------------------------------
   DIALOG
--------------------------------------------------*/
#prefs-dialog {
  border: 1px solid var(--table-border);
  border-radius: 12px;
  background: var(--card);
  color: var(--fg);
  padding: 1rem;
  width: min(520px, 96vw);
}
.prefs-form fieldset {
  border: 1px solid var(--table-border);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}
.prefs-form legend {
  padding: 0 0.4rem;
  color: var(--muted);
}
.prefs-form menu {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin: 0;
  padding-top: 0.5rem;
}

/* ------------------------------------------------
   FOOTER
--------------------------------------------------*/
.app-footer {
  padding: 0.8rem 1rem;
  color: var(--muted);
}

/* ------------------------------------------------
   SEGMENTED CONTROL
--------------------------------------------------*/
.segmented {
  --seg-bg: var(--panel-bg, #111);
  --seg-fg: var(--text, #ddd);
  --seg-ac: var(--accent, #4ade80);
  --seg-count: 2;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--seg-count), 1fr);
  border: 1px solid color-mix(in oklab, var(--seg-fg) 20%, transparent);
  background: var(--seg-bg);
  border-radius: 999px;
  padding: 2px;
  width: 260px;
  height: 36px;
  align-items: center;
}
.segmented input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented label {
  position: relative;
  z-index: 2;
  text-align: center;
  line-height: 32px;
  font-size: 14px;
  color: var(--seg-fg);
  cursor: pointer;
  border-radius: 999px;
}
.segmented .thumb {
  position: absolute;
  z-index: 1;
  top: 2px;
  left: 2px;
  width: calc((100% - 4px) / var(--seg-count));
  height: calc(100% - 4px);
  background: color-mix(in oklab, var(--seg-ac) 25%, #000 0%);
  border-radius: 999px;
  transform: translateX(0%);
  transition:
    transform 160ms ease,
    background 160ms ease;
}
.theme-red .segmented .thumb {
  background: #771;
}
.theme-light .segmented {
  --seg-bg: #fff;
  --seg-fg: #222;
}
.theme-black .segmented {
  --seg-bg: #000;
  --seg-fg: #ddd;
}

/* ------------------------------------------------
   GOES STICKY BLOCK
--------------------------------------------------*/
#tab-goes .goes-sticky {
  position: sticky;
  top: var(--header-h);
  z-index: 5;
  background: var(--app-bg, #000);
  padding-top: 0.25rem;
  padding-bottom: 0.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

/* chart inside sticky group should be non-sticky */
#tab-goes .chart.tall {
  position: static;
  box-shadow: none;
  background: transparent;
}

/* ------------------------------------------------
   AURORA MAP
--------------------------------------------------*/
#aurora-map-container {
  position: relative;
  height: 800px;
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid var(--table-border);
  background: #000;
  margin-bottom: 0.75rem;
}
#aurora-map {
  width: 100%;
  height: 100%;
}
.aurora-legend {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.75);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
}
.aurora-legend .swatch {
  width: 18px;
  height: 10px;
  border-radius: 999px;
}
.aurora-legend .sw-0 {
  background: #00ff00;
}
.aurora-legend .sw-25 {
  background: #ffff00;
}
.aurora-legend .sw-50 {
  background: #ff9900;
}
.aurora-legend .sw-75 {
  background: #8b0000;
}
.aurora-legend .sw-100 {
  background: #ab008b;
}
#aurora-meta {
  font-size: 0.8rem;
  opacity: 0.8;
}

/* ------------------------------------------------
   MAPLIBRE POPUP (TOOLTIP ONLY)
--------------------------------------------------*/
.maplibregl-popup {
  z-index: 5;
}
.maplibregl-popup-content {
  background: rgba(20, 20, 20, 0.95) !important;
  color: #eee !important;
  border-radius: 6px !important;
  padding: 6px 10px !important;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5) !important;
  font-size: 0.9rem !important;
  line-height: 1.25 !important;
}
.maplibregl-popup-tip {
  border-top-color: rgba(20, 20, 20, 0.95) !important;
}
/* ------- small base tweaks (desktop + mobile) ------- */

/* allow horizontal scroll if the table gets wider than the viewport */
.region-list {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
}

/* keep the flare table readable when it scrolls horizontally */
.region-list table {
  min-width: 600px;
}

/* let long toolbars wrap instead of overflowing */
.toolbar {
  flex-wrap: wrap;
}

/* ------- mobile layout ------- */
@media (max-width: 768px) {
  /* slightly tighter overall spacing */
  .content {
    padding: 0.5rem;
  }
  .card {
    padding: 0.75rem;
  }

  .app-header {
    padding-inline: 0.75rem;
  }
  .app-header h1 {
    font-size: 0.95rem;
  }

  /* tabs scroll horizontally instead of squeezing */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-inline: 0.5rem;
  }
  .tab {
    flex: 0 0 auto;
    white-space: nowrap;
    padding-inline: 0.6rem;
  }

  /* charts a bit shorter on phones */
  .chart {
    height: 230px;
  }

  /* flare disk + table: stack vertically */
  .region-wrap {
    flex-direction: column;
    align-items: stretch;
  }
  .disk {
    flex: 0 0 auto;
    max-width: min(260px, 80vw);
    margin: 0 auto 0.75rem;
  }
  .region-list {
    width: 100%;
  }

  /* flare table: slightly smaller text, tighter rows */
  #tbl-regions th,
  #tbl-regions td {
    padding: 0.3rem 0.4rem;
    font-size: 0.85rem;
  }

  /* segmented controls: full width on mobile */
  .segmented {
    width: 100%;
    max-width: 100%;
  }

  /* GOES sticky block: keep a bit shorter on small screens */
  #tab-goes .goes-sticky {
    padding-bottom: 0.25rem;
  }
}
