/* ===== CSS Custom Properties ===== */
:root {
  --bg-deep:       #030a1a;
  --bg-card:       #071526;
  --bg-card-hover: #0a1e36;
  --border:        #0d2a4a;
  --text-primary:  #c8dff0;
  --text-secondary:#7aa8cc;
  --text-glow:     #00d4ff;
  --moon-color:    #f0e68c;
  --moon-glow:     rgba(240, 230, 140, 0.5);
  --accent-green:  #00ff88;
  --accent-amber:  #ffaa00;
  --accent-red:    #ff4444;
  --font-mono:     'Courier New', Courier, monospace;
  --chart-line:    #00d4ff;
  --chart-fill:    rgba(0, 212, 255, 0.08);
  --chart-tick:    #7aa8cc;
  --chart-grid:    rgba(13, 42, 74, 0.8);
  --row-border:    rgba(13, 42, 74, 0.5);
  --radius:        8px;
  --header-bg:     var(--bg-deep);
  --header-title:  var(--text-glow);
  --header-sub:    var(--text-secondary);
  --header-rule:   1px solid var(--border);
  --title-shadow:  0 0 12px var(--text-glow);
}

/* ===== Light Theme Overrides ===== */
html[data-theme="light"],
body.light-theme {
  --bg-deep:       #f0f4f8;
  --bg-card:       #ffffff;
  --bg-card-hover: #e4edf8;
  --border:        #c0d4eb;
  --text-primary:  #1a2e45;
  --text-secondary:#3a6a9a;
  --text-glow:     #005fa3;
  --moon-color:    #000000;
  --moon-glow:     transparent;
  --accent-green:  #007744;
  --accent-amber:  #b87800;
  --accent-red:    #bb2222;
  --chart-line:    #005fa3;
  --chart-fill:    rgba(0, 95, 163, 0.1);
  --chart-tick:    #3a6a9a;
  --chart-grid:    rgba(192, 212, 235, 0.95);
  --row-border:    rgba(192, 212, 235, 0.9);
  --title-shadow:  none;
}

/* ===== Monochrome — black, white, sharp, industrial ===== */
html[data-theme="monochrome"] {
  --bg-deep:       #000000;
  --bg-card:       #0a0a0a;
  --bg-card-hover: #141414;
  --border:        #2a2a2a;
  --text-primary:  #ffffff;
  --text-secondary:#9a9a9a;
  --text-glow:     #ffffff;
  --moon-color:    #ffffff;
  --moon-glow:     transparent;
  --accent-green:  #ffffff;
  --accent-amber:  #cfcfcf;
  --accent-red:    #ff5a5a;
  --font-mono:     "Helvetica Neue", Helvetica, Arial, sans-serif;
  --chart-line:    #ffffff;
  --chart-fill:    rgba(255, 255, 255, 0.06);
  --chart-tick:    #9a9a9a;
  --chart-grid:    rgba(255, 255, 255, 0.08);
  --row-border:    rgba(255, 255, 255, 0.08);
  --radius:        0px;
  --header-bg:     #000000;
  --header-title:  #ffffff;
  --header-sub:    #9a9a9a;
  --header-rule:   1px solid #ffffff;
  --title-shadow:  none;
}

/* ===== Mission Blue — deep blue, signal red, clean sans ===== */
html[data-theme="mission"] {
  --bg-deep:       #eef2f7;
  --bg-card:       #ffffff;
  --bg-card-hover: #f7f9fc;
  --border:        #d3dce8;
  --text-primary:  #1b1b1b;
  --text-secondary:#3e4c63;
  --text-glow:     #0B3D91;
  --moon-color:    #0B3D91;
  --moon-glow:     transparent;
  --accent-green:  #0B3D91;
  --accent-amber:  #FC3D21;
  --accent-red:    #FC3D21;
  --font-mono:     "Helvetica Neue", Helvetica, Arial, sans-serif;
  --chart-line:    #0B3D91;
  --chart-fill:    rgba(11, 61, 145, 0.08);
  --chart-tick:    #3e4c63;
  --chart-grid:    rgba(11, 61, 145, 0.12);
  --row-border:    rgba(11, 61, 145, 0.12);
  --radius:        2px;
  --header-bg:     #0B3D91;
  --header-title:  #ffffff;
  --header-sub:    rgba(255, 255, 255, 0.82);
  --header-rule:   4px solid #FC3D21;
  --title-shadow:  none;
}

/* ===== Sky — navy and sky blue ===== */
html[data-theme="sky"] {
  --bg-deep:       #061525;
  --bg-card:       #0c243c;
  --bg-card-hover: #123050;
  --border:        #1d4e78;
  --text-primary:  #e7f4fb;
  --text-secondary:#8eb8d0;
  --text-glow:     #5ec8ef;
  --moon-color:    #d7f1fb;
  --moon-glow:     rgba(94, 200, 239, 0.35);
  --accent-green:  #3ddc97;
  --accent-amber:  #7ed0f2;
  --accent-red:    #ff6b6b;
  --font-mono:     "Helvetica Neue", Helvetica, Arial, sans-serif;
  --chart-line:    #5ec8ef;
  --chart-fill:    rgba(94, 200, 239, 0.1);
  --chart-tick:    #8eb8d0;
  --chart-grid:    rgba(94, 200, 239, 0.12);
  --row-border:    rgba(94, 200, 239, 0.14);
  --radius:        6px;
  --header-bg:     #00205B;
  --header-title:  #ffffff;
  --header-sub:    rgba(255, 255, 255, 0.8);
  --header-rule:   3px solid #7ed0f2;
  --title-shadow:  none;
  --header-active-fg: #00205B;
}

/* ===== Neon — black and hot pink ===== */
html[data-theme="neon"] {
  --bg-deep:       #050505;
  --bg-card:       #111111;
  --bg-card-hover: #1a1a1a;
  --border:        #2c2c2c;
  --text-primary:  #ffffff;
  --text-secondary:#b3b3b3;
  --text-glow:     #ff2e97;
  --moon-color:    #ffd0ea;
  --moon-glow:     rgba(255, 46, 151, 0.35);
  --accent-green:  #3ddc97;
  --accent-amber:  #ff2e97;
  --accent-red:    #ff4d6a;
  --font-mono:     "Helvetica Neue", Helvetica, Arial, sans-serif;
  --chart-line:    #ff2e97;
  --chart-fill:    rgba(255, 46, 151, 0.1);
  --chart-tick:    #b3b3b3;
  --chart-grid:    rgba(255, 46, 151, 0.12);
  --row-border:    rgba(255, 255, 255, 0.08);
  --radius:        0px;
  --header-bg:     #000000;
  --header-title:  #ffffff;
  --header-sub:    #ff8ac4;
  --header-rule:   3px solid #ff2e97;
  --title-shadow:  none;
  --header-active-fg: #000000;
}

/* ===== Daylight — steel blue and orange ===== */
html[data-theme="daylight"] {
  --bg-deep:       #f3f5f7;
  --bg-card:       #ffffff;
  --bg-card-hover: #f7f8fa;
  --border:        #d5dde6;
  --text-primary:  #1c2430;
  --text-secondary:#4d5d70;
  --text-glow:     #004B87;
  --moon-color:    #004B87;
  --moon-glow:     transparent;
  --accent-green:  #0d7a45;
  --accent-amber:  #E87722;
  --accent-red:    #c0392b;
  --font-mono:     "Helvetica Neue", Helvetica, Arial, sans-serif;
  --chart-line:    #004B87;
  --chart-fill:    rgba(0, 75, 135, 0.08);
  --chart-tick:    #4d5d70;
  --chart-grid:    rgba(0, 75, 135, 0.12);
  --row-border:    rgba(0, 75, 135, 0.12);
  --radius:        2px;
  --header-bg:     #004B87;
  --header-title:  #ffffff;
  --header-sub:    rgba(255, 255, 255, 0.82);
  --header-rule:   4px solid #E87722;
  --title-shadow:  none;
  --header-active-fg: #004B87;
}

/* ===== Indigo — indigo night and cyan ===== */
html[data-theme="indigo"] {
  --bg-deep:       #07101c;
  --bg-card:       #0e1c30;
  --bg-card-hover: #142844;
  --border:        #1e3d66;
  --text-primary:  #e8f2ff;
  --text-secondary:#9bb4d4;
  --text-glow:     #3ec6ff;
  --moon-color:    #d6ebff;
  --moon-glow:     rgba(62, 198, 255, 0.3);
  --accent-green:  #3ddc97;
  --accent-amber:  #3ec6ff;
  --accent-red:    #ef4135;
  --font-mono:     "Helvetica Neue", Helvetica, Arial, sans-serif;
  --chart-line:    #3ec6ff;
  --chart-fill:    rgba(62, 198, 255, 0.1);
  --chart-tick:    #9bb4d4;
  --chart-grid:    rgba(62, 198, 255, 0.12);
  --row-border:    rgba(62, 198, 255, 0.14);
  --radius:        4px;
  --header-bg:     #001E60;
  --header-title:  #ffffff;
  --header-sub:    rgba(255, 255, 255, 0.78);
  --header-rule:   3px solid #3ec6ff;
  --title-shadow:  none;
  --header-active-fg: #001E60;
}

/* ===== Copper — charcoal and copper ===== */
html[data-theme="copper"] {
  --bg-deep:       #161210;
  --bg-card:       #221c19;
  --bg-card-hover: #2c241f;
  --border:        #3d322b;
  --text-primary:  #f6eee8;
  --text-secondary:#c2aea0;
  --text-glow:     #e07a3d;
  --moon-color:    #f0c7a8;
  --moon-glow:     rgba(224, 122, 61, 0.35);
  --accent-green:  #7dcea0;
  --accent-amber:  #e07a3d;
  --accent-red:    #e05a4f;
  --font-mono:     "Helvetica Neue", Helvetica, Arial, sans-serif;
  --chart-line:    #e07a3d;
  --chart-fill:    rgba(224, 122, 61, 0.12);
  --chart-tick:    #c2aea0;
  --chart-grid:    rgba(224, 122, 61, 0.14);
  --row-border:    rgba(224, 122, 61, 0.16);
  --radius:        2px;
  --header-bg:     #100e0c;
  --header-title:  #f6eee8;
  --header-sub:    #e0b090;
  --header-rule:   3px solid #e07a3d;
  --title-shadow:  none;
  --header-active-fg: #100e0c;
}

/* ===== Gold — night sky and gold ===== */
html[data-theme="gold"] {
  --bg-deep:       #070b16;
  --bg-card:       #12182b;
  --bg-card-hover: #1a2340;
  --border:        #2a3658;
  --text-primary:  #f8f3e4;
  --text-secondary:#cbb98a;
  --text-glow:     #f5c518;
  --moon-color:    #ffe27a;
  --moon-glow:     rgba(245, 197, 24, 0.45);
  --accent-green:  #8ee08a;
  --accent-amber:  #f5c518;
  --accent-red:    #ff6b5a;
  --font-mono:     "Helvetica Neue", Helvetica, Arial, sans-serif;
  --chart-line:    #f5c518;
  --chart-fill:    rgba(245, 197, 24, 0.12);
  --chart-tick:    #cbb98a;
  --chart-grid:    rgba(245, 197, 24, 0.12);
  --row-border:    rgba(245, 197, 24, 0.14);
  --radius:        10px;
  --header-bg:     #070b16;
  --header-title:  #ffe27a;
  --header-sub:    #cbb98a;
  --header-rule:   3px solid #f5c518;
  --title-shadow:  0 0 14px rgba(245, 197, 24, 0.45);
  --header-active-fg: #070b16;
}

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

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
}

/* ===== Header ===== */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  border-bottom: var(--header-rule);
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.header-title {
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--header-title);
  text-shadow: var(--title-shadow);
  letter-spacing: 0.05em;
}

.header-subtitle {
  font-size: 0.75rem;
  color: var(--header-sub);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-right {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
}

.last-updated {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ===== Refresh Button ===== */
.refresh-btn {
  background: transparent;
  border: 1px solid var(--accent-green);
  color: var(--accent-green);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.refresh-btn:hover:not(:disabled) {
  background: rgba(0, 255, 136, 0.1);
  box-shadow: 0 0 10px var(--accent-green);
}

.refresh-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#refresh-btn.spinning .refresh-icon {
  display: inline-block;
  animation: spin-refresh 1s linear infinite;
}

@keyframes spin-refresh {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ===== Menu: settings and actions =====
   The header keeps only the connection dot and this button; theme, units, language,
   notifications and the install/refresh/populate/reset actions live in its panel. */
.hamburger-menu {
  position: relative;
}

.menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.menu-btn:hover,
.menu-btn.open {
  background: rgba(128, 128, 128, 0.16);
  background: color-mix(in srgb, currentColor 14%, transparent);
  border-color: currentColor;
}

.menu-btn:focus-visible,
.settings-panel button:focus-visible,
.settings-select:focus-visible {
  outline: 2px solid var(--text-glow);
  outline-offset: 2px;
}

.menu-icon {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
}

.menu-icon span {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 0.2s, opacity 0.2s;
}

.menu-btn.open .menu-icon span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-btn.open .menu-icon span:nth-child(2) { opacity: 0; }
.menu-btn.open .menu-icon span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.settings-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 200;
  width: min(320px, calc(100vw - 24px));
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 0.9rem;
  letter-spacing: normal;
  text-transform: none;
  animation: settings-in 0.14s ease-out;
}

.settings-panel[hidden] { display: none; }

@keyframes settings-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-section[hidden] { display: none; }

.settings-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.settings-value {
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  color: var(--text-primary);
}

/* Theme chips: a swatch of the theme's own colours and its name */
.theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.theme-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text-primary);
  font: inherit;
  font-size: 0.82rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.theme-chip:hover { background: var(--bg-card-hover); }

.theme-chip[aria-checked="true"] {
  border-color: var(--text-glow);
  box-shadow: inset 0 0 0 1px var(--text-glow);
}

.theme-swatch {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--sw-bg) 50%, var(--sw-fg) 50%);
  box-shadow: 0 0 0 1px rgba(128, 128, 128, 0.45);
}

/* Units: a segmented control */
.segmented {
  display: flex;
  padding: 3px;
  gap: 3px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.seg-btn {
  flex: 1;
  padding: 6px 0;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--text-secondary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.seg-btn:hover { color: var(--text-primary); }

.seg-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), 0 0 0 1px var(--border);
}

/* Language */
.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 7px;
  height: 7px;
  margin-top: -6px;
  border-right: 2px solid var(--text-secondary);
  border-bottom: 2px solid var(--text-secondary);
  transform: rotate(45deg);
  pointer-events: none;
}

.settings-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding: 8px 34px 8px 12px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
}

.settings-select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* Notifications: a label and a switch */
.settings-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-row-title { font-weight: 600; }

.settings-row-hint {
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.settings-row-warn .settings-row-hint { color: var(--accent-amber); }
.switch:disabled { opacity: 0.45; cursor: not-allowed; }

.switch {
  flex: none;
  position: relative;
  width: 40px;
  height: 22px;
  padding: 0;
  background: var(--border);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}

.switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s;
}

.switch[aria-checked="true"] { background: var(--accent-green); }
.switch[aria-checked="true"] .switch-knob { transform: translateX(18px); }

.settings-divider {
  height: 1px;
  margin: 0 -16px;
  background: var(--border);
}

/* Actions */
.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: -6px -8px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.menu-item[hidden] { display: none; }
a.menu-item { text-decoration: none; }
.menu-item:hover:not(:disabled) { background: var(--bg-card-hover); }

.menu-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.menu-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  color: var(--text-secondary);
  font-size: 1rem;
}

.reset-item,
.reset-item .menu-item-icon { color: var(--accent-red); }

/* Advanced: refresh / populate / reset behind the admin key */
.advanced {
  margin: -6px -8px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.advanced-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.advanced-toggle:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.lock-icon {
  width: 15px;
  height: 15px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.6;
}

.lock-icon rect { stroke: none; }
.advanced-toggle.unlocked .lock-icon path { transform: translateX(2.5px) translateY(-1px); }

.advanced-chevron {
  margin-left: auto;
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.2s;
}

.advanced-toggle[aria-expanded="true"] .advanced-chevron { transform: rotate(45deg); }

.advanced-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 8px 4px;
}

.advanced-body[hidden],
.advanced-unlock[hidden],
.settings-actions[hidden] { display: none; }

.advanced-unlock {
  display: flex;
  gap: 6px;
}

.advanced-key {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font: inherit;
  font-size: 0.85rem;
}

.advanced-key:focus-visible {
  outline: 2px solid var(--text-glow);
  outline-offset: 1px;
}

.unlock-btn {
  padding: 7px 12px;
  background: var(--text-glow);
  border: 1px solid var(--text-glow);
  border-radius: 8px;
  color: var(--bg-card);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.unlock-btn:hover { filter: brightness(1.1); }

.advanced-msg {
  margin: 0;
  font-size: 0.76rem;
  color: var(--accent-red);
}

.advanced-msg:empty { display: none; }

.advanced-body .settings-actions { margin: 0 -8px; }

.lock-btn {
  align-self: flex-start;
  margin: 2px 0 0 30px;
  padding: 2px 0;
  background: none;
  border: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.78rem;
  text-decoration: underline;
  cursor: pointer;
}

.lock-btn:hover { color: var(--text-primary); }

/* ===== Install Button ===== */

/* ===== Theme Toggle Button ===== */

/* ===== Notification Bell ===== */

/* ===== Unit Selector ===== */

/* ===== Toast Notification ===== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--accent-green);
  color: var(--accent-green);
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  box-shadow: 0 0 16px rgba(0, 255, 136, 0.25);
  opacity: 0;
  transform: translateY(0.5rem);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  z-index: 400;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== Reset Data Button ===== */
.reset-btn {
  background: transparent;
  border: 1px solid #ff4444;
  color: #ff4444;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.reset-btn:hover:not(:disabled) {
  background: rgba(255, 68, 68, 0.1);
  box-shadow: 0 0 10px #ff4444;
}

.reset-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Populate Past Button ===== */
.populate-btn {
  background: transparent;
  border: 1px solid #ffaa00;
  color: #ffaa00;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.populate-btn:hover:not(:disabled) {
  background: rgba(255, 170, 0, 0.1);
  box-shadow: 0 0 10px #ffaa00;
}

.populate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Card Grid ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  grid-auto-flow: dense;
  gap: 1rem;
  padding: 1rem 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color 0.3s;
}

.card:hover {
  background: var(--bg-card-hover);
}

.card.updated {
  animation: flash-border 2s ease-out forwards;
}

@keyframes flash-border {
  0%   { border-color: var(--text-glow); box-shadow: 0 0 16px var(--text-glow); }
  100% { border-color: var(--border);    box-shadow: none; }
}

/* Moon (hero) and Near Earth cards take up two rows */
.moon-card,
.near-card {
  grid-row: span 2;
}

.card h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-glow);
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.moon-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.moon-card-head h2 {
  margin-bottom: 0;
  border-bottom: none;
  padding-bottom: 0;
}

.moon-graphic-switch {
  display: flex;
  flex-shrink: 0;
  border: 1px solid var(--text-secondary);
  border-radius: 4px;
  overflow: hidden;
}

.graphic-btn {
  background: transparent;
  border: none;
  border-right: 1px solid var(--text-secondary);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  padding: 0.28rem 0.45rem;
  cursor: pointer;
  line-height: 1;
}

.graphic-btn:last-child {
  border-right: none;
}

.graphic-btn:hover {
  background: rgba(122, 168, 204, 0.15);
  color: var(--text-primary);
}

.graphic-btn[aria-pressed="true"] {
  background: var(--text-secondary);
  color: var(--bg-deep);
  font-weight: bold;
}

/* ===== Moon Card (hero) ===== */
.moon-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.moon-illumination {
  font-size: 3rem;
  font-weight: bold;
  line-height: 1;
  color: var(--moon-color);
  text-shadow: 0 0 10px var(--moon-glow);
  font-variant-numeric: tabular-nums;
}

.moon-illumination-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 0.35rem;
}

.moon-phase-name {
  font-size: 1.3rem;
  color: var(--moon-color);
  text-shadow: 0 0 10px var(--moon-glow);
  margin-top: 0.4rem;
}

.moon-stage {
  position: relative;
  width: 100%;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.moon-cycle {
  margin: 1.25rem 0 1rem;
}

.moon-cycle-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.moon-cycle-day {
  font-size: 0.8rem;
  color: var(--text-primary);
}

.moon-cycle-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.moon-cycle-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--moon-color);
  transition: width 0.6s ease;
}

.phase-strip {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  justify-items: center;
  margin-top: 0.75rem;
}

.phase-icon {
  display: block;
  width: 26px;
  height: 26px;
}

.phase-icon .phase-dark { fill: var(--border); }
.phase-icon .phase-lit  { fill: var(--moon-color); }
.phase-icon .phase-ring { fill: none; stroke: var(--text-glow); stroke-width: 1.5; }

.moon-ascii {
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--moon-color);
  opacity: 0.85;
  margin: 0;
  white-space: pre;
}

.moon-canvas {
  display: block;
  width: 100%;
  height: 200px;
}

/* The rocket's outings, spacecraft passes and meteors fly over the page on this layer,
   under the header and menus; it never takes clicks. */
.flight-layer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

html[data-moon-graphic="ascii"] .moon-canvas {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  pointer-events: none;
}

html[data-moon-graphic="animated"] .moon-ascii {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* ===== Data Table ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table td {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--row-border);
  font-size: 0.85rem;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table th {
  color: var(--text-glow);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: normal;
  padding: 0 0 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.data-table th.val {
  text-align: right;
}

.data-table td:first-child {
  color: var(--text-secondary);
  padding-right: 1rem;
  white-space: nowrap;
}

.data-table td.val {
  color: var(--text-primary);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Stacked section tables (Near Earth card) */
.section-table + .section-table {
  margin-top: 1.1rem;
}

.section-table th:first-child {
  text-align: left;
}

.card-note {
  margin-top: 0.75rem;
  font-size: 0.7rem;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

/* ===== Meteor showers and eclipses ===== */
.sky-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sky-item {
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--row-border);
}

.sky-item:last-child {
  border-bottom: none;
}

.sky-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.85rem;
}

.sky-name {
  color: var(--text-primary);
}

.sky-row .val {
  color: var(--text-primary);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.sky-detail {
  margin-top: 0.15rem;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

/* ===== History Card ===== */
.history-card {
  grid-column: 1 / -1;  /* full width */
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.history-header h2 {
  margin-bottom: 0;
  border-bottom: none;
  padding-bottom: 0;
}

.history-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.metric-select {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  outline: none;
}

.metric-select:focus {
  border-color: var(--text-glow);
  box-shadow: 0 0 6px var(--text-glow);
}

.export-btn {
  background: transparent;
  border: 1px solid var(--text-secondary);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.export-btn:hover {
  background: rgba(122, 168, 204, 0.12);
  color: var(--text-primary);
  box-shadow: 0 0 8px var(--text-secondary);
}

.history-chart-wrap {
  position: relative;
  height: 260px;
}

.history-monthly-wrap {
  height: 340px;
}

.history-chart-wrap[hidden] {
  display: none;
}

.history-controls {
  flex-wrap: wrap;
}

.history-msg {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  min-height: 1.2em;
}

/* ===== Footer ===== */
footer {
  font-size: 0.75rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Snap Store badge: the dark one on dark themes, the light one on light themes */
.footer-snap {
  display: inline-flex;
  border-radius: 8px;
  transition: box-shadow 0.3s;
}

.footer-snap:hover { box-shadow: 0 0 12px var(--text-glow); }
.footer-snap:focus-visible { outline: 2px solid var(--text-glow); outline-offset: 3px; }

.snap-badge {
  display: block;
  height: 44px;
  width: auto;
}

.snap-badge-light { display: none; }
html[data-theme="light"] .snap-badge-dark,
html[data-theme="mission"] .snap-badge-dark,
html[data-theme="daylight"] .snap-badge-dark { display: none; }
html[data-theme="light"] .snap-badge-light,
html[data-theme="mission"] .snap-badge-light,
html[data-theme="daylight"] .snap-badge-light { display: block; }

/* ===== Responsive ===== */
@media (max-width: 480px) {
  header { gap: 0.5rem; }
  .header-subtitle { font-size: 0.6rem; }
  .card-grid { padding: 0.75rem; gap: 0.75rem; }
  .moon-card,
  .near-card { grid-row: span 1; }
  .footer-inner { flex-direction: column; text-align: center; }
}

html[data-theme="monochrome"] .card,
html[data-theme="monochrome"] button,
html[data-theme="monochrome"] .moon-graphic-switch,
html[data-theme="monochrome"] .menu-dropdown,
html[data-theme="monochrome"] .metric-select,
html[data-theme="monochrome"] .toast,
html[data-theme="monochrome"] .footer-snap,
html[data-theme="monochrome"] .moon-cycle-track,
html[data-theme="monochrome"] .moon-cycle-fill {
  border-radius: 0;
}

html[data-theme="monochrome"] .header-title,
html[data-theme="monochrome"] .card h2,
html[data-theme="monochrome"] .header-subtitle {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 500;
  text-shadow: none;
}

html[data-theme="monochrome"] .menu-btn,
html[data-theme="monochrome"] .menu-dropdown {
  border-color: #ffffff;
  color: #ffffff;
  box-shadow: none;
}

html[data-theme="monochrome"] .menu-btn:hover,
html[data-theme="monochrome"] .refresh-item:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
  box-shadow: none;
  color: #ffffff;
}

html[data-theme="monochrome"] .refresh-item {
  color: #ffffff;
}

html[data-theme="mission"] .card h2,
html[data-theme="mission"] .history-header {
  border-bottom: 2px solid #FC3D21;
}

html[data-theme="mission"] .header-title {
  letter-spacing: 0.14em;
  font-weight: 700;
}

html[data-theme="mission"] header .menu-btn {
  border-color: rgba(255, 255, 255, 0.75);
  color: #ffffff;
}

html[data-theme="mission"] header .menu-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: none;
  color: #ffffff;
}

html[data-theme="sky"] header {
  background: linear-gradient(100deg, #001833 0%, #004e86 58%, #1a94c9 100%);
}

html[data-theme="indigo"] header {
  box-shadow: inset 0 -2px 0 #0055A4, inset 0 -4px 0 #ffffff, inset 0 -6px 0 #EF4135;
  border-bottom: none;
}

html[data-theme="neon"] .header-title,
html[data-theme="neon"] .card h2 {
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 600;
}

html[data-theme="daylight"] .card h2,
html[data-theme="daylight"] .history-header {
  border-bottom: 2px solid #E87722;
}

html[data-theme="gold"] .card h2 {
  text-shadow: 0 0 10px rgba(245, 197, 24, 0.35);
}

html[data-theme="sky"] header .menu-btn,
html[data-theme="neon"] header .menu-btn,
html[data-theme="daylight"] header .menu-btn,
html[data-theme="indigo"] header .menu-btn,
html[data-theme="copper"] header .menu-btn,
html[data-theme="gold"] header .menu-btn {
  border-color: rgba(255, 255, 255, 0.75);
  color: #ffffff;
}

html[data-theme="sky"] header .menu-btn:hover,
html[data-theme="neon"] header .menu-btn:hover,
html[data-theme="daylight"] header .menu-btn:hover,
html[data-theme="indigo"] header .menu-btn:hover,
html[data-theme="copper"] header .menu-btn:hover,
html[data-theme="gold"] header .menu-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: none;
  color: #ffffff;
}

html[data-theme="neon"] .card,
html[data-theme="neon"] button,
html[data-theme="neon"] .moon-graphic-switch,
html[data-theme="neon"] .menu-dropdown,
html[data-theme="neon"] .metric-select,
html[data-theme="neon"] .toast,
html[data-theme="neon"] .footer-snap,
html[data-theme="neon"] .moon-cycle-track,
html[data-theme="neon"] .moon-cycle-fill {
  border-radius: 0;
}

/* ===== Night mode =====
   Red on black for stargazing, like the Orbitly apps: no blue or green light, so dark-adapted
   eyes keep their sensitivity. It replaces the chosen theme, which comes back when it is off.
   The palette is in greys; the two filter layers then turn every pixel into red of the same
   brightness, which also covers what the palette cannot reach (the animated moon and flybys,
   emoji, the chart and the Snap Store badge). */
html[data-night="on"],
html[data-night="on"] body {
  --bg-deep:        #000000;
  --bg-card:        #161616;
  --bg-card-hover:  #242424;
  --border:         #3c3c3c;
  --text-primary:   #d8d8d8;
  --text-secondary: #9a9a9a;
  --text-glow:      #ffffff;
  --moon-color:     #ffffff;
  --moon-glow:      rgba(255, 255, 255, 0.22);
  --accent-green:   #d0d0d0;
  --accent-amber:   #bcbcbc;
  --accent-red:     #ffffff;
  --chart-line:     #e0e0e0;
  --chart-fill:     rgba(255, 255, 255, 0.07);
  --chart-tick:     #9a9a9a;
  --chart-grid:     rgba(255, 255, 255, 0.1);
  --row-border:     rgba(255, 255, 255, 0.07);
  --header-bg:      #000000;
  --header-title:   #ffffff;
  --header-sub:     #9a9a9a;
  --header-rule:    1px solid #3c3c3c;
  --header-active-fg: #000000;
  --title-shadow:   none;
}

html[data-night="on"] body { background: #000000; }

.night-filter { display: none; }

html[data-night="on"] .night-filter {
  display: block;
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2147483000;
}

html[data-night="on"] .night-filter-grey {
  -webkit-backdrop-filter: grayscale(1) brightness(0.85);
  backdrop-filter: grayscale(1) brightness(0.85);
}

html[data-night="on"] .night-filter-red {
  background: #ff0000;
  mix-blend-mode: multiply;
}

/* The theme is kept but can't be changed while night mode replaces it. */
html[data-night="on"] .theme-grid { opacity: 0.45; pointer-events: none; }

.night-row { padding-top: 2px; }
