/* styles.css — Earth Explorer Enzi */
/* FIX #3: Atmosphere overlay now reads --glow-strength and --atmo-opacity
   CSS custom properties set by map.js to produce a dynamic Earth glow. */

/* -------------------------------------------------------------------------
   Reset & base
   ---------------------------------------------------------------------- */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #060d1f;
  color: #fff;
}

/* -------------------------------------------------------------------------
   Map
   ---------------------------------------------------------------------- */

#map {
  position: absolute;
  inset: 0;
}

/* -------------------------------------------------------------------------
   FIX #3: Atmosphere overlay — dynamic glow driven by JS
   ---------------------------------------------------------------------- */
/* map.js sets two custom properties on this element every zoom frame:
     --atmo-opacity   (0–1)  master visibility
     --glow-strength  (0–1)  glow ring intensity
   The gradient and opacity below consume these so the glow scales smoothly
   from a bold "Earth from space" ring at orbital zoom down to nothing as
   the user zooms into street level.                                        */

#atmosphere {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;

  /* Defaults before JS has run — prevents flash of unstyled content */
  --atmo-opacity: 0.8;
  --glow-strength: 0.7;

  /* Master opacity driven by JS */
  opacity: var(--atmo-opacity, 0);

  /* Multi-layer gradient for a rich glow effect:
     1. Inner soft blue halo (simulates atmospheric scattering)
     2. Mid-range dark-blue vignette (space transition)
     3. Outer deep-space darkness                                           */
  background:
    /* Layer 1 — blue atmospheric halo */
    radial-gradient(
      ellipse 55% 55% at 50% 50%,
      rgba(60, 140, 255, calc(0.12 * var(--glow-strength))) 0%,
      rgba(30, 80, 200, calc(0.08 * var(--glow-strength))) 40%,
      transparent 65%
    ),
    /* Layer 2 — deep vignette */
    radial-gradient(
      ellipse at 50% 50%,
      transparent 25%,
      rgba(5, 20, 70, calc(0.35 * var(--glow-strength))) 55%,
      rgba(2, 8, 35, calc(0.75 * var(--glow-strength))) 100%
    );
}

/* -------------------------------------------------------------------------
   UI Panel
   ---------------------------------------------------------------------- */

#ui-panel {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 10;
  width: 240px;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

#ui-panel.expanded {
  width: clamp(280px, 33vw, 480px);
}

/* -------------------------------------------------------------------------
   Country Explorer — expanded state
   ---------------------------------------------------------------------- */

#ui-panel.country-explorer {
  width: 300px;
  height: calc(100vh - 40px);
}

#ui-panel.country-explorer .panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}

#ui-panel.country-explorer .panel-header {
  flex-shrink: 0;
}

#ui-panel.country-explorer .nav-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
}

#ui-panel.country-explorer .nav-bar {
  flex-shrink: 0;
}

#ui-panel.country-explorer .nav-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

#ui-panel.country-explorer .nav-body::-webkit-scrollbar {
  width: 4px;
}

#ui-panel.country-explorer .nav-body::-webkit-scrollbar-track {
  background: transparent;
}

#ui-panel.country-explorer .nav-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

#ui-panel.country-explorer .panel-section,
#ui-panel.country-explorer .panel-footer {
  display: none;
}

.panel {
  background: rgba(6, 13, 31, 0.82);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.55);
}

/* Header */

.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.panel-logo {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.panel-logo-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.logo-dot {
  width: 10px;
  height: 10px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.7);
}

.panel-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  line-height: 1.2;
}

.panel-subtitle {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.35);
  margin-top: 2px;
}

/* Sections */

.panel-section {
  margin-bottom: 20px;
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.3);
  margin-bottom: 10px;
}

/* -------------------------------------------------------------------------
   Navigation structure
   ---------------------------------------------------------------------- */

.nav-section {
  margin-bottom: 20px;
}

.nav-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  min-height: 22px;
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s ease, background 0.15s ease;
}

.back-btn:hover {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.07);
}

.back-btn svg {
  width: 15px;
  height: 15px;
}

.nav-breadcrumb {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.3);
}

.nav-body {
  position: relative;
  overflow: hidden;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  text-align: left;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.15s ease;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateX(3px);
}

.nav-btn-primary {
  font-size: 13px;
  font-weight: 500;
}

.nav-btn-secondary {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
}

/* CTA tile — "See All N Countries" */

.nav-btn-cta {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  gap: 10px;
}

.nav-btn-cta:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.15);
}

.nav-btn-cta-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.nav-btn-cta-body .nav-btn-secondary {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.cta-arrow {
  width: 14px;
  height: 14px;
  color: rgba(255, 255, 255, 0.3);
  flex-shrink: 0;
  transition: color 0.18s ease, transform 0.18s ease;
}

.nav-btn-cta:hover .cta-arrow {
  color: rgba(255, 255, 255, 0.6);
  transform: translateX(2px);
}

/* Expanded country rows — 3-column grid: name | city count | flag */

.country-row {
  display: grid;
  grid-template-columns: 1fr max-content max-content;
  align-items: center;
  gap: 10px;
}

.country-row-name {
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.country-row-cities {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  white-space: nowrap;
}

.country-row-flag {
  font-size: 15px;
  line-height: 1;
}

/* Location detail card */

.location-detail {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
}

.location-detail-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  line-height: 1.3;
}

.location-detail-desc {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.55);
  line-height: 1.55;
}

.location-detail-image {
  display: block;
  width: 100%;
  margin-top: 12px;
  border-radius: 8px;
  object-fit: cover;
  opacity: 0;
  animation: image-fade-in 0.3s ease 0.25s forwards;
}

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

/* -------------------------------------------------------------------------
   Nav view transitions
   ---------------------------------------------------------------------- */

.nav-view.exit-forward,
.nav-view.exit-backward {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  pointer-events: none;
}

@keyframes enter-fwd {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes enter-bwd {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes exit-fwd {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(-12px); }
}

@keyframes exit-bwd {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(12px); }
}

.nav-view.enter-forward  { animation: enter-fwd 0.22s ease forwards; }
.nav-view.enter-backward { animation: enter-bwd 0.22s ease forwards; }
.nav-view.exit-forward   { animation: exit-fwd  0.22s ease forwards; }
.nav-view.exit-backward  { animation: exit-bwd  0.22s ease forwards; }

/* Layer toggles */

.panel-section .layer-toggle + .layer-toggle,
.panel-section .time-of-day-row + .layer-toggle,
.panel-section .layer-toggle + .time-of-day-row {
  margin-top: 10px;
}

.layer-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  min-height: 22px;
}

/* -------------------------------------------------------------------------
   Time of Day selector
   ---------------------------------------------------------------------- */

.time-of-day-row {
  cursor: default;
  position: relative;
}

.tod-selector {
  position: relative;
}

.tod-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  padding: 4px 8px;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
  white-space: nowrap;
}

.tod-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.16);
}

.tod-chevron {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  transition: transform 0.18s ease;
}

.tod-btn--open .tod-chevron {
  transform: rotate(180deg);
}

.tod-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  min-width: 90px;
  background: rgba(12, 22, 48, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  overflow: hidden;
  z-index: 20;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  animation: tod-drop 0.15s ease;
}

@keyframes tod-drop {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tod-option {
  display: block;
  width: 100%;
  padding: 9px 12px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tod-option + .tod-option {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.tod-option:hover {
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.9);
}

.tod-option--selected {
  color: rgba(255, 255, 255, 0.95);
  font-weight: 600;
}

.toggle-label-text {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
}

.toggle-switch {
  position: relative;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  transition: background 0.2s ease;
  cursor: pointer;
}

.toggle-track::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s ease, background 0.2s ease;
}

.toggle-switch input:checked + .toggle-track {
  background: rgba(58, 123, 213, 0.7);
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(16px);
  background: #fff;
}

/* Footer */

.panel-footer {
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.world-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.world-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.9);
}

.world-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* -------------------------------------------------------------------------
   AI Panel (right side)
   ---------------------------------------------------------------------- */

#ai-panel {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10;
  width: clamp(260px, 28vw, 360px);
  transform: translateX(calc(100% + 32px));
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

#ai-panel.visible {
  transform: translateX(0);
  pointer-events: auto;
}

.ai-panel-inner {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 18px 18px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

#ai-panel.visible .ai-panel-inner > * {
  animation: ai-content-fade 0.3s ease 0.25s both;
}

@keyframes ai-content-fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ai-dot {
  width: 8px;
  height: 8px;
  background: #00aaff;
  border-radius: 50%;
  flex-shrink: 0;
  animation: ai-pulse 2.2s ease-in-out infinite;
}

@keyframes ai-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 170, 255, 0.6); opacity: 1; }
  50%       { box-shadow: 0 0 0 6px rgba(0, 170, 255, 0);  opacity: 0.8; }
}

.ai-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: rgba(255, 255, 255, 0.75);
  line-height: 1.3;
}

.ai-context {
  margin-bottom: 12px;
  min-height: 32px;
}

.ai-context-hint {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.3);
  font-style: italic;
}

.ai-context-location {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 2px;
  line-height: 1.3;
}

.ai-context-path {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.38);
}

.ai-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 8px 10px;
  transition: border-color 0.18s ease;
}

.ai-input-row:focus-within {
  border-color: rgba(0, 170, 255, 0.35);
}

#ai-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  caret-color: #00aaff;
}

#ai-input::placeholder {
  color: rgba(255, 255, 255, 0.28);
}

.ai-input-hint {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.2);
  white-space: nowrap;
  flex-shrink: 0;
}

/* -------------------------------------------------------------------------
   Enzi Homepage AI — bottom-left presence
   ---------------------------------------------------------------------- */

#enzi-home {
  position: fixed;
  top: 24px;
  right: 24px;
  left: auto;
  bottom: auto;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 360px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
  transform: scale(0.9) translateY(-6px);
}

#enzi-home.visible {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1) translateY(0);
}

#enzi-home.dimmed {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95) translateY(-4px);
}

.enzi-home-sphere {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 170, 255, 0.08);
  border: 1px solid rgba(0, 170, 255, 0.18);
  border-radius: 50%;
  margin-top: 2px;
}

.enzi-home-sphere .ai-dot {
  width: 9px;
  height: 9px;
  animation: ai-pulse 2s ease-in-out infinite;
}

.enzi-home-body {
  font-size: 13px;
  font-family: inherit;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.65;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-height: 7em;
}

.enzi-home-body div {
  min-height: 1em;
}

.enzi-home-body div:first-child {
  font-weight: 600;
  color: rgba(255, 255, 255, 0.95);
}

.enzi-home-body div:last-child {
  color: rgba(0, 200, 255, 0.8);
  margin-top: 4px;
  font-style: italic;
}

/* -------------------------------------------------------------------------
   MapLibre control overrides — match dark theme
   ---------------------------------------------------------------------- */

.maplibregl-ctrl-group {
  background: rgba(6, 13, 31, 0.82) !important;
  backdrop-filter: blur(16px) !important;
  border: 1px solid rgba(255, 255, 255, 0.07) !important;
  border-radius: 12px !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45) !important;
  overflow: hidden;
}

.maplibregl-ctrl-group button {
  width: 36px !important;
  height: 36px !important;
}

.maplibregl-ctrl-group button + button {
  border-top: none !important;
  border-left: 1px solid rgba(255, 255, 255, 0.06) !important;
}

/* ===== FINAL CLEAN ISLAND BAR (REPLACE EVERYTHING) ===== */

#bottom-bar {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 20;

  display: flex;
  align-items: center;
  gap: 10px;
}

/* each item = island */
#bottom-bar > * {
  display: flex;
  align-items: center;

  background: rgba(6, 13, 31, 0.72);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 8px;

  padding: 4px 10px;
}

/* built by */
.built-by {
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  white-space: nowrap;
}

/* attribution = SAME AS ISLAND + SAME TEXT COLOR */
#bottom-bar .maplibregl-ctrl-attrib {
  display: flex;
  align-items: center;

  background: rgba(6, 13, 31, 0.72) !important;
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.07) !important;
  border-radius: 8px;

  padding: 4px 10px !important;

  white-space: nowrap !important;
  font-size: 11px !important;

  color: rgba(255,255,255,0.6) !important;
  opacity: 1 !important;
}

/* FIX LINK COLOR INSIDE ATTRIBUTION */
#bottom-bar .maplibregl-ctrl-attrib a {
  color: rgba(255,255,255,0.6) !important;
  text-decoration: none !important;
}

#bottom-bar .maplibregl-ctrl-attrib a:hover {
  color: rgba(255,255,255,0.85) !important;
}

/* scale = SAME AS ISLAND + SAME TEXT COLOR */
#bottom-bar .maplibregl-ctrl-scale {
  display: flex;
  align-items: center;

  background: rgba(6, 13, 31, 0.72) !important;
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.07) !important;
  border-radius: 8px;

  padding: 4px 10px !important;

  font-size: 10px !important;

  color: rgba(255,255,255,0.6) !important;
  opacity: 1 !important;
}

/* nav buttons */
#bottom-bar .maplibregl-ctrl-group {
  display: flex !important;
  flex-direction: row !important;

  background: rgba(6, 13, 31, 0.72) !important;
  border: 1px solid rgba(255,255,255,0.07) !important;
  border-radius: 8px !important;

  padding: 2px !important;
}

/* button separators */
#bottom-bar .maplibregl-ctrl-group button + button {
  border-left: 1px solid rgba(255,255,255,0.06) !important;
  border-top: none !important;
}

/* icon polish */
.maplibregl-ctrl-icon {
  filter: invert(1) opacity(0.6) !important;
}