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

/* ── Theme variables ──────────────────────────────────────── */
:root {
  --bg:            #050b14;
  --glass-bg:      rgba(5, 15, 30, 0.85);
  --header-bg:     rgba(5, 11, 20, 0.96);
  --border:        rgba(0, 212, 255, 0.12);
  --text:          #c8d8e8;
  --text-dim:      #4e6880;
  --text-bright:   #e8f4ff;
  --cell-bg:       rgba(0, 212, 255, 0.04);
  --tooltip-bg:    rgba(5, 11, 20, 0.94);
  --grid-color:    rgba(0, 212, 255, 0.025);
  --scanline-dark: rgba(0, 0, 0, 0.05);
  --map-bg:        #050b14;

  --cyan:          #00d4ff;
  --cyan-dim:      rgba(0, 212, 255, 0.15);
  --cyan-glow:     rgba(0, 212, 255, 0.4);
  --green:         #22d45e;
  --green-glow:    rgba(34, 212, 94, 0.5);
  --amber:         #f5a623;
  --amber-glow:    rgba(245, 166, 35, 0.5);
  --blue:          #4f8ef7;
  --blue-glow:     rgba(79, 142, 247, 0.5);

  --header-h:      64px;
  --footer-h:      44px;
  --panel-w:       340px;
}

[data-theme="light"] {
  --bg:            #edf1f7;
  --glass-bg:      rgba(235, 242, 255, 0.90);
  --header-bg:     rgba(230, 238, 252, 0.97);
  --border:        rgba(0, 100, 180, 0.14);
  --text:          #2a3a50;
  --text-dim:      #7a8fa8;
  --text-bright:   #0a1a30;
  --cell-bg:       rgba(0, 100, 180, 0.05);
  --tooltip-bg:    rgba(235, 242, 255, 0.97);
  --grid-color:    rgba(0, 80, 160, 0.04);
  --scanline-dark: rgba(0, 0, 0, 0.015);
  --map-bg:        #edf1f7;

  --cyan:          #0099cc;
  --cyan-dim:      rgba(0, 153, 204, 0.12);
  --cyan-glow:     rgba(0, 153, 204, 0.35);
}

/* ── Base ─────────────────────────────────────────────────── */
html, body {
  height: 100%;
  font-family: 'Space Grotesk', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  transition: background 0.3s, color 0.3s;
}

/* ── Ambient layers ───────────────────────────────────────── */
.scanline {
  position: fixed; inset: 0; z-index: 9999;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    var(--scanline-dark) 2px,
    var(--scanline-dark) 4px
  );
}

.grid-overlay {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
  background-size: 48px 48px;
  transition: background-image 0.3s;
}

/* ── Glass ────────────────────────────────────────────────── */
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  transition: background 0.3s, border-color 0.3s;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  z-index: 1000;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
  transition: background 0.3s, border-color 0.3s;
}

.header-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 12px;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.hex-icon {
  width: 34px;
  flex-shrink: 0;
  color: var(--cyan);
  filter: drop-shadow(0 0 6px var(--cyan-glow));
}

.title-block h1 {
  font-family: 'Orbitron', monospace;
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--text-bright);
  line-height: 1;
  white-space: nowrap;
}

.accent { color: var(--cyan); }

.subtitle {
  font-size: 0.62rem;
  color: var(--text-dim);
  letter-spacing: 0.07em;
  margin-top: 4px;
  text-transform: uppercase;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.ai-note {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.ai-pill {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  color: #fff;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border-radius: 4px;
  font-family: 'Orbitron', monospace;
  flex-shrink: 0;
}

.ai-pill.small { font-size: 0.55rem; padding: 2px 5px; }

.refresh-indicator {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.67rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.pulse-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green-glow);
  flex-shrink: 0;
  animation: pulse 2.2s ease-in-out infinite;
}

/* ── Theme toggle button ──────────────────────────────────── */
.theme-toggle {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--cell-bg);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--cyan);
  color: var(--cyan);
  background: var(--cyan-dim);
}

/* ── Main layout ──────────────────────────────────────────── */
main {
  position: fixed;
  top: var(--header-h);
  bottom: var(--footer-h);
  left: 0; right: 0;
  display: flex;
  z-index: 1;
}

.map-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%; height: 100%;
  background: var(--map-bg);
}

/* ── Legend ───────────────────────────────────────────────── */
.legend {
  position: absolute;
  bottom: 24px; left: 16px;
  z-index: 800;
  padding: 14px 18px;
  border-radius: 10px;
  min-width: 196px;
}

.legend-title {
  font-family: 'Orbitron', monospace;
  font-size: 0.58rem;
  letter-spacing: 0.15em;
  color: var(--cyan);
  margin-bottom: 12px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.77rem;
  color: var(--text);
  margin-bottom: 8px;
}

.legend-row:last-child { margin-bottom: 0; }

.dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.producing    { background: var(--green); box-shadow: 0 0 8px var(--green-glow); }
.dot.construction { background: var(--amber); box-shadow: 0 0 8px var(--amber-glow); }
.dot.planned      { background: var(--blue);  box-shadow: 0 0 8px var(--blue-glow);  }

.count {
  margin-left: auto;
  font-family: 'Orbitron', monospace;
  font-size: 0.68rem;
  color: var(--cyan);
}

/* ── Stats bar ────────────────────────────────────────────── */
.stats-bar {
  position: absolute;
  top: 16px; left: 50%;
  transform: translateX(-50%);
  z-index: 800;
  border-radius: 10px;
  display: flex;
  align-items: center;
  padding: 10px 24px;
  gap: 20px;
  white-space: nowrap;
}

.stat-item { text-align: center; }

.stat-num {
  font-family: 'Orbitron', monospace;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-bright);
  line-height: 1;
}

.stat-num.accent { color: var(--cyan); }

.stat-lbl {
  font-size: 0.58rem;
  color: var(--text-dim);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  margin-top: 4px;
}

.stat-sep {
  width: 1px; height: 32px;
  background: var(--border);
}

/* ── Detail panel ─────────────────────────────────────────── */
.detail-panel {
  width: var(--panel-w);
  flex-shrink: 0;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  border-top: none; border-right: none; border-bottom: none;
  border-radius: 0;
  display: flex;
  flex-direction: column;
}

.detail-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-dim);
  font-size: 0.82rem;
  text-align: center;
  line-height: 1.6;
  padding: 40px 24px;
}

.placeholder-icon { width: 58px; color: var(--text-dim); opacity: 0.35; }

.placeholder-sub {
  font-size: 0.72rem;
  color: var(--text-dim);
  opacity: 0.7;
  margin-top: 4px;
}

.placeholder-sub strong { color: var(--cyan); }

.detail-content { padding: 20px; }

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.status-badge {
  font-family: 'Orbitron', monospace;
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  font-weight: 700;
}

.status-badge.producing {
  background: rgba(34, 212, 94, 0.1);
  color: var(--green);
  border: 1px solid rgba(34, 212, 94, 0.3);
}

.status-badge.construction {
  background: rgba(245, 166, 35, 0.1);
  color: var(--amber);
  border: 1px solid rgba(245, 166, 35, 0.3);
}

.status-badge.planned {
  background: rgba(79, 142, 247, 0.1);
  color: var(--blue);
  border: 1px solid rgba(79, 142, 247, 0.3);
}

.close-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 26px; height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.72rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}

.close-btn:hover { border-color: var(--cyan); color: var(--cyan); }

.detail-content h2 {
  font-family: 'Orbitron', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-bright);
  line-height: 1.45;
  margin-bottom: 5px;
}

.d-location {
  font-size: 0.73rem;
  color: var(--cyan);
  letter-spacing: 0.05em;
  margin-bottom: 16px;
  opacity: 0.8;
}

.d-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.d-cell {
  background: var(--cell-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
}

.d-cell.full { grid-column: 1 / -1; }

.d-label {
  font-family: 'Orbitron', monospace;
  font-size: 0.53rem;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.d-value {
  font-size: 0.76rem;
  color: var(--text);
  line-height: 1.4;
}

.d-value.mono      { font-family: 'Space Grotesk', monospace; color: var(--cyan); }
.d-value.accent-val { color: var(--cyan); font-weight: 600; }

.d-brief {
  font-size: 0.78rem;
  line-height: 1.75;
  color: var(--text);
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-bottom: 14px;
  opacity: 0.88;
}

.d-ai-note {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.68rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* ── Leaflet overrides ────────────────────────────────────── */
.leaflet-container { background: var(--map-bg) !important; }

.leaflet-control-attribution {
  background: var(--glass-bg) !important;
  color: var(--text-dim) !important;
  font-size: 0.58rem !important;
  border-top: 1px solid var(--border) !important;
}

.leaflet-control-attribution a { color: var(--text-dim) !important; }

.leaflet-control-zoom a {
  background: var(--glass-bg) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--cyan-dim) !important;
  color: var(--cyan) !important;
}

/* ── Custom Leaflet tooltip ───────────────────────────────── */
.fab-tooltip {
  background: var(--tooltip-bg) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  color: var(--text) !important;
  font-family: 'Space Grotesk', sans-serif !important;
  font-size: 0.77rem !important;
  padding: 8px 12px !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3), 0 0 10px var(--cyan-dim) !important;
  backdrop-filter: blur(12px);
  white-space: nowrap;
}

.fab-tooltip::before { display: none !important; }

.tooltip-name {
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 3px;
}

.tooltip-loc {
  font-size: 0.68rem;
  color: var(--cyan);
  opacity: 0.75;
  margin-bottom: 2px;
}

.tooltip-node {
  font-size: 0.68rem;
  color: var(--text-dim);
}

/* ── Footer ───────────────────────────────────────────────── */
footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--footer-h);
  z-index: 1000;
  background: var(--header-bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-size: 0.67rem;
  color: var(--text-dim);
  transition: background 0.3s, border-color 0.3s;
}

footer a {
  color: var(--cyan);
  text-decoration: none;
}

footer a:hover { text-decoration: underline; }

.footer-note {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Animations ───────────────────────────────────────────── */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.45; transform: scale(0.75); }
}

@keyframes ring-pulse {
  0%   { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(2.6); opacity: 0; }
}

.marker-ring { animation: ring-pulse 2.2s ease-out infinite; }

/* ── Cluster overrides ────────────────────────────────────── */
.leaflet-cluster-anim .leaflet-marker-icon,
.leaflet-cluster-anim .leaflet-marker-shadow {
  transition: transform 0.3s ease-out, opacity 0.3s ease-out;
}

/* Spider legs */
.leaflet-marker-icon.leaflet-div-icon { background: none; border: none; }
.leaflet-cluster-anim .leaflet-div-icon { transition: transform 0.3s ease-out; }

/* ── News section ─────────────────────────────────────────── */
.news-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 4px;
}

.news-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.news-title {
  font-family: 'Orbitron', monospace;
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  color: var(--cyan);
}

.news-fetched {
  font-size: 0.62rem;
  color: var(--text-dim);
}

.news-item {
  display: block;
  text-decoration: none;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 7px;
  background: var(--cell-bg);
  transition: border-color 0.2s, background 0.2s;
}

.news-item:last-child { margin-bottom: 0; }

.news-item:hover {
  border-color: var(--cyan);
  background: var(--cyan-dim);
}

.news-item-title {
  font-size: 0.76rem;
  color: var(--text-bright);
  line-height: 1.4;
  margin-bottom: 5px;
}

.news-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.news-source {
  font-size: 0.64rem;
  color: var(--cyan);
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.news-date {
  font-size: 0.62rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Sheet handle (mobile) ────────────────────────────────── */
.sheet-handle {
  display: none;
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 2px;
  flex-shrink: 0;
}

/* ── Mobile responsive ────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --footer-h: 38px;
  }

  /* Header — keep logo + toggle, hide everything else */
  .header-inner { padding: 0 14px; gap: 8px; }
  .title-block h1 { font-size: 0.78rem; letter-spacing: 0.07em; }
  .subtitle { display: none; }
  .refresh-indicator { display: none; }
  .hex-icon { width: 26px; }

  /* Map fills all available space */
  .map-wrap { width: 100%; }

  /* Stats bar — hidden on mobile, too cramped */
  .stats-bar { display: none; }

  /* Legend — smaller and tighter */
  .legend {
    bottom: 10px; left: 10px;
    padding: 10px 13px;
    min-width: 0;
  }
  .legend-title { font-size: 0.54rem; margin-bottom: 8px; }
  .legend-row { font-size: 0.72rem; gap: 7px; margin-bottom: 6px; }
  .dot { width: 9px; height: 9px; }
  .count { font-size: 0.62rem; }

  /* Detail panel becomes a bottom sheet */
  .detail-panel {
    position: fixed;
    bottom: var(--footer-h);
    left: 0; right: 0;
    width: 100%;
    max-height: 72vh;
    border-radius: 16px 16px 0 0;
    border-left: none;
    border-top: 1px solid var(--border);
    transform: translateY(110%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 900;
    overflow-y: auto;
  }

  .detail-panel.mobile-open { transform: translateY(0); }

  .sheet-handle { display: block; }

  /* Hide placeholder on mobile — panel is invisible until tapped */
  .detail-placeholder { display: none; }

  .detail-content { padding: 14px 16px 20px; }
  .detail-content h2 { font-size: 0.82rem; }

  .d-grid { gap: 8px; }
  .d-cell { padding: 8px 10px; }
  .d-value { font-size: 0.73rem; }

  .d-brief { font-size: 0.75rem; line-height: 1.65; }

  .news-item-title { font-size: 0.73rem; }

  /* Footer — single line */
  footer { padding: 0 14px; font-size: 0.62rem; }
  footer span:first-child { display: none; }
  .footer-note { width: 100%; justify-content: center; }
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--cyan-dim); }
