/* NTHMAP — base theme + layout (PLAN.md §1) */

:root[data-theme="dark"] {
  --bg-primary:     #080B0F;
  --bg-secondary:   #0D1117;
  --bg-card:        #111820;
  --border:         #1E2A35;
  --accent-primary: #00D4FF;
  --accent-energy:  #FF6B35;
  --accent-danger:  #FF3B5C;
  --accent-green:   #00FF8C;
  --accent-gold:    #FFD700;
  --text-primary:   #E8F0F7;
  --text-secondary: #7A9BB5;
  --text-muted:     #3D5A70;
  --map-overlay:    rgba(8,11,15,0.85);
}

:root[data-theme="light"] {
  --bg-primary:     #F4F7FB;
  --bg-secondary:   #FFFFFF;
  --bg-card:        #FFFFFF;
  --border:         #D1DCE8;
  --accent-primary: #0066CC;
  --accent-energy:  #D4500A;
  --accent-danger:  #CC1F3A;
  --accent-green:   #007A45;
  --accent-gold:    #B8860B;
  --text-primary:   #0A1628;
  --text-secondary: #3D5A70;
  --text-muted:     #8FA8BE;
  --map-overlay:    rgba(244,247,251,0.92);
}

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

html, body {
  height: 100%;
  font-family: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  font-size: 13px;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

h1, h2, h3, .display {
  font-family: "Inter", system-ui, sans-serif;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.15;
  color: var(--text-primary);
}

button {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 2px;
  cursor: pointer;
  transition: all 150ms ease-out;
}
button:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
button.primary {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: var(--bg-primary);
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.15); }
button.ghost { background: var(--bg-card); }
button.danger { color: var(--accent-danger); border-color: var(--accent-danger); }
button.block { display: block; width: 100%; margin-top: 8px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"] {
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 2px;
  outline: none;
  transition: border-color 150ms;
}
input:focus { border-color: var(--accent-primary); }

a { color: var(--accent-primary); text-decoration: none; }

/* ─────────────────────────────────────────── LAYOUT */
body {
  display: grid;
  grid-template-columns: 260px 1fr 0;
  grid-template-rows: 56px 1fr 40px;
  grid-template-areas:
    "topbar topbar topbar"
    "left   map    right"
    "bottom bottom bottom";
  transition: grid-template-columns 220ms ease-out;
}
body.right-open                     { grid-template-columns: 260px 1fr 360px; }
body.sidebar-collapsed              { grid-template-columns: 0    1fr 0; }
body.sidebar-collapsed.right-open   { grid-template-columns: 0    1fr 360px; }
body.sidebar-collapsed #left-panel  { transform: translateX(-100%); pointer-events: none; }
#left-panel { transition: transform 220ms ease-out; will-change: transform; }

/* ─────────────────────────────────────────────────────────────────
   Z-INDEX HIERARCHY (Leaflet's controls live at z-index 800,
   so all chrome must be > 800 to render above the map)
     1000  #topbar  (and its children like the user dropdown)
      900  #left-panel, #right-panel, #ticker
     2000  modals
     2100  toasts
   ───────────────────────────────────────────────────────────────── */

#topbar {
  grid-area: topbar;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px 0 14px;
  gap: 16px;
  z-index: 1000;
  position: relative;
}

/* Sidebar toggle button */
.icon-btn {
  width: 34px; height: 34px;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 3px;
  cursor: pointer;
  transition: all 150ms ease-out;
  flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--accent-primary); }
.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 16px; height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
  transition: all 200ms ease-out;
}
.hamburger { position: relative; }
.hamburger::before, .hamburger::after { content: ""; position: absolute; left: 0; }
.hamburger::before { top: -5px; }
.hamburger::after  { top:  5px; }
.icon-btn:hover .hamburger,
.icon-btn:hover .hamburger::before,
.icon-btn:hover .hamburger::after { background: var(--accent-primary); }

/* Animate to a "›" arrow when sidebar is collapsed */
body.sidebar-collapsed .hamburger        { background: transparent; }
body.sidebar-collapsed .hamburger::before { top: 0; transform: rotate(45deg);  width: 10px; left: 4px; }
body.sidebar-collapsed .hamburger::after  { top: 0; transform: rotate(-45deg); width: 10px; left: 4px; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.logo-mark { font-size: 22px; color: var(--accent-primary); }
.logo-text { font-family: "Inter"; font-weight: 800; font-size: 18px; letter-spacing: 0.15em; }
.logo-tag {
  font-family: "Inter"; font-weight: 500; font-size: 9px;
  letter-spacing: 0.25em; color: var(--text-muted);
  border-left: 1px solid var(--border); padding-left: 10px;
}
.search-wrap {
  flex: 1;
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 2px;
  max-width: 560px;
}
.search-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 9px 14px;
  font-size: 12.5px;
  color: var(--text-primary);
}
.search-wrap input::placeholder { color: var(--text-muted); font-style: italic; }
.search-wrap button { border: none; border-left: 1px solid var(--border); padding: 0 14px; }
.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
  height: 100%;
}

/* Universal 34 px baseline for every interactive thing in the right-side rail
   so the icon-button, the upgrade pill, the login button, and the avatar all
   sit on the exact same horizontal line. */
.topbar-actions > button,
.topbar-actions > #user-state > button,
.topbar-actions .user-menu-wrap > button {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  margin: 0;
  vertical-align: middle;
  box-sizing: border-box;
}
#user-state {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  height: 34px;
}

/* Theme toggle glyph centering */
#theme-toggle { font-size: 16px; line-height: 1; }

/* Upgrade pill in topbar (visible only for free users) */
.topbar-actions .upgrade-btn {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-energy));
  border: none;
  color: var(--bg-primary);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.1em;
  padding: 0 14px;
  box-shadow: 0 0 18px rgba(0, 212, 255, 0.25);
  transition: all 200ms ease-out;
  border-radius: 3px;
}
.topbar-actions .upgrade-btn:hover {
  filter: brightness(1.15);
  box-shadow: 0 0 28px rgba(0, 212, 255, 0.5);
}

/* Login button (logged-out state) */
.topbar-actions #login-btn {
  padding: 0 16px;
  font-size: 11px;
  letter-spacing: 0.1em;
}

/* User avatar button — same 34 px footprint as the icon buttons */
.user-menu-wrap {
  position: relative;
  display: flex;
  align-items: center;
  height: 34px;
}
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
  font-family: "Inter", sans-serif;
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: all 150ms ease-out;
  text-transform: uppercase;
}
.user-avatar:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
}
.user-avatar.pro,
.user-avatar.enterprise {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: radial-gradient(circle at 30% 30%, rgba(0, 212, 255, 0.15), var(--bg-card));
}
.user-avatar[aria-expanded="true"] {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.18);
}

/* Dropdown — display:none by default, .open swaps to display:block. */
.user-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 270px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(0, 212, 255, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  padding: 0;
  z-index: 9999;
  overflow: hidden;
  display: none;
  opacity: 1;
}
/* Animation is declared on .open so it's freshly applied each time the
   class is added — declaring it on the base element doesn't reliably
   restart the animation when display flips none → block. */
.user-dropdown.open {
  display: block;
  animation: dropdownIn 160ms ease-out both;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}
.user-dropdown::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
  opacity: 0.45;
}

.user-dropdown-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 14px;
}
.user-dropdown-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
  font-family: "Inter";
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  flex-shrink: 0;
}
.user-dropdown-avatar.pro,
.user-dropdown-avatar.enterprise {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: radial-gradient(circle at 30% 30%, rgba(0,212,255,0.15), var(--bg-secondary));
}
.user-dropdown-info { min-width: 0; flex: 1; }
.user-dropdown-info .email {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.user-dropdown-info .tier-line {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-dropdown-info .muted {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.tier-pill {
  display: inline-block;
  font-family: "Inter", sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  padding: 2px 7px;
  border-radius: 2px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  text-transform: uppercase;
  background: var(--bg-primary);
}
.tier-pill.pro,
.tier-pill.enterprise {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: rgba(0, 212, 255, 0.06);
}
.tier-pill.admin {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
  background: rgba(255, 215, 0, 0.06);
}
.tier-pill.internal {
  border-color: #B44FFF;
  color: #B44FFF;
  background: rgba(180, 79, 255, 0.06);
}
.tier-pill.trial {
  border-color: var(--accent-green);
  color: var(--accent-green);
  background: rgba(0, 255, 140, 0.06);
}

.user-dropdown-info .tier-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}
.user-dropdown-info .status-line {
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.user-dropdown-lang {
  padding: 12px 16px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-dropdown-lang label {
  font-family: "Inter";
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.user-dropdown-lang select {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 2px;
  cursor: pointer;
  outline: none;
}
.user-dropdown-lang select:focus { border-color: var(--accent-primary); }

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

.user-dropdown-items {
  display: flex;
  flex-direction: column;
  padding: 6px 0;
}
.user-dropdown-item {
  background: transparent;
  border: none;
  text-align: left;
  padding: 11px 18px;
  font-family: "Inter", sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 120ms ease-out;
  text-transform: none;
  border-radius: 0;
}
.user-dropdown-item:hover {
  background: var(--bg-secondary);
  color: var(--accent-primary);
}
.user-dropdown-item.highlight {
  color: var(--accent-primary);
  background: linear-gradient(90deg, rgba(0, 212, 255, 0.10), transparent);
  font-weight: 700;
  letter-spacing: 0.08em;
}
.user-dropdown-item.highlight:hover {
  background: linear-gradient(90deg, rgba(0, 212, 255, 0.18), rgba(255, 107, 53, 0.08));
}
.user-dropdown-item.danger { color: var(--accent-danger); }
.user-dropdown-item.danger:hover { background: rgba(255, 59, 92, 0.08); color: var(--accent-danger); }

#left-panel {
  grid-area: left;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 900;
  position: relative;
}
#left-panel::-webkit-scrollbar { width: 6px; }
#left-panel::-webkit-scrollbar-thumb { background: var(--border); }

#map {
  grid-area: map;
  position: relative;
  z-index: 1;
  background: var(--bg-primary);
}

#right-panel {
  grid-area: right;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  z-index: 900;
  position: relative;
}
#right-panel.hidden { display: none; }
#right-panel.hidden + #ticker { display: flex; }
#right-panel .close,
.modal .close {
  position: absolute;
  top: 12px; right: 14px;
  background: transparent; border: none;
  color: var(--text-secondary);
  font-size: 16px;
  padding: 4px 8px;
  z-index: 10;
}
#right-panel .close:hover { color: var(--accent-primary); }

#ticker {
  grid-area: bottom;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  z-index: 900;
  position: relative;
}

/* ─────────────────────────────────────────── MODAL */
.modal {
  position: fixed; inset: 0;
  background: rgba(8,11,15,0.78);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(8px);
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 32px;
  width: 380px;
  position: relative;
  border-radius: 4px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-card h2 {
  font-size: 20px;
  margin-bottom: 20px;
  letter-spacing: 0.05em;
}
.modal-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-toggle { margin-top: 14px; text-align: center; font-size: 11px; }
.upgrade-cta {
  margin-top: 20px;
  padding: 12px;
  background: linear-gradient(135deg, rgba(0,212,255,0.08), rgba(255,107,53,0.05));
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 11px;
  color: var(--text-secondary);
}
.upgrade-cta strong { color: var(--accent-primary); }

.error {
  background: rgba(255,59,92,0.12);
  border: 1px solid var(--accent-danger);
  color: var(--accent-danger);
  padding: 8px 12px;
  margin-top: 12px;
  font-size: 11px;
}
.error.hidden, .hidden { display: none !important; }

/* ─────────────────────────────────────────── LOADER */
.loader {
  position: fixed; inset: 0;
  background: var(--bg-primary);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity 600ms ease-out;
}
.loader.gone { opacity: 0; pointer-events: none; }
.loader-mark {
  font-family: "Inter"; font-weight: 800;
  font-size: 28px; letter-spacing: 0.2em;
  color: var(--accent-primary);
}
.loader-bar {
  margin-top: 24px;
  width: 200px; height: 2px;
  background: var(--border);
  position: relative;
  overflow: hidden;
}
.loader-bar span {
  position: absolute;
  width: 40%; height: 100%;
  background: var(--accent-primary);
  animation: loaderSlide 1.2s infinite ease-in-out;
}
@keyframes loaderSlide {
  0%   { left: -40%; }
  100% { left: 100%; }
}

/* ─────────────────────────────────────────── ANIMATIONS */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes eventPulse {
  0%   { transform: scale(1);   opacity: 0.8; }
  50%  { transform: scale(1.8); opacity: 0.3; }
  100% { transform: scale(2.4); opacity: 0;   }
}

/* ─────────────────────────────────────────────────────────────────
   MOBILE / RESPONSIVE
   - Below 900px: sidebar overlays the map (slides in/out)
   - Below 600px: topbar goes compact (logo tag hides, search shrinks)
   - Below 480px: right panel goes full-width
   ───────────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  body {
    grid-template-columns: 0 1fr 0 !important;
  }
  body.right-open { grid-template-columns: 0 1fr 100vw !important; }

  /* Sidebar floats over the map. .sidebar-collapsed = hidden (default).
     No class = visible (overlay). */
  #left-panel {
    position: fixed;
    top: 56px;
    bottom: 40px;
    left: 0;
    width: 280px;
    max-width: 80vw;
    transform: none;
    transition: transform 240ms ease-out;
    box-shadow: 6px 0 30px rgba(0, 0, 0, 0.5);
    z-index: 1500;
  }
  body.sidebar-collapsed #left-panel { transform: translateX(-100%); }

  /* Backdrop when sidebar is open on mobile */
  body:not(.sidebar-collapsed) #map::after {
    content: "";
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 500;
    pointer-events: auto;
  }

  #right-panel {
    position: fixed;
    top: 56px;
    bottom: 40px;
    right: 0;
    width: 360px;
    max-width: 92vw;
    box-shadow: -6px 0 30px rgba(0, 0, 0, 0.5);
    z-index: 1500;
  }
}

@media (max-width: 600px) {
  .logo-tag { display: none; }
  .search-wrap { max-width: none; }
  .search-wrap input { font-size: 11px; padding: 8px 10px; }
  #topbar { gap: 10px; padding: 0 10px; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .upgrade-btn { padding: 0 10px; font-size: 10px; }
  #topbar .brand .logo-text { font-size: 15px; }
}

@media (max-width: 480px) {
  #right-panel { width: 100vw; max-width: 100vw; }
  .ntm-modal-card { max-width: 92vw !important; }
}

/* badges */
.pro-badge {
  display: inline-block;
  font-family: "Inter";
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-energy));
  color: var(--bg-primary);
  padding: 1px 5px;
  border-radius: 2px;
  margin-left: 6px;
  vertical-align: middle;
}
