@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
  --bg-black: #020617;
  --bg-surface: #0f172a;
  --bg-card: #1e293b;
  --accent-primary: #6366f1;
  --accent-secondary: #4f46e5;
  --accent-premium: #a855f7;
  --accent-warning: #f59e0b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: rgba(255, 255, 255, 0.1);
  --nav-height: 80px;
  --radius-lg: 16px;
  --radius-md: 10px;
  --glass-bg: rgba(15, 23, 42, 0.85);
  --glass-border: rgba(255, 255, 255, 0.08);
}

/* Light theme overrides */
[data-theme="light"] {
  --bg-black: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-card: #f8fafc;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: rgba(0, 0, 0, 0.1);
  --glass-bg: rgba(255, 255, 255, 0.88);
  --glass-border: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] body,
[data-theme="light"] .navbar,
[data-theme="light"] .map-loader {
  background-color: var(--bg-black) !important;
  color: var(--text-main);
}

/* Map background stays dark in light mode (same as dark mode) */
[data-theme="light"] #map {
  background-color: #020617 !important;
}

[data-theme="light"] .leaflet-popup-content-wrapper,
[data-theme="light"] .leaflet-popup-tip {
  background: #fff !important;
  color: #0f172a !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12) !important;
}

[data-theme="light"] .glass,
[data-theme="light"] .modal-content.glass {
  background: rgba(255,255,255,0.92) !important;
  border-color: rgba(0,0,0,0.08) !important;
  color: var(--text-main);
}

[data-theme="light"] .ctx-menu.glass {
  background: rgba(255,255,255,0.95) !important;
  border-color: rgba(0,0,0,0.1) !important;
}

[data-theme="light"] input,
[data-theme="light"] textarea,
[data-theme="light"] select {
  background: #f1f5f9 !important;
  color: #0f172a !important;
  border-color: rgba(0,0,0,0.15) !important;
}

[data-theme="light"] .nav-icon-btn {
  color: var(--text-main);
}

[data-theme="light"] .sentinel-stat {
  background: rgba(0,0,0,0.03) !important;
  border-color: rgba(0,0,0,0.08) !important;
}

[data-theme="light"] .atbl th {
  color: var(--text-muted) !important;
  border-color: rgba(0,0,0,0.1) !important;
}

[data-theme="light"] .atbl td {
  border-color: rgba(0,0,0,0.06) !important;
}

[data-theme="light"] .map-loader {
  background: rgba(241,245,249,0.95) !important;
}

[data-theme="light"] .loader-text {
  color: #64748b !important;
}

[data-theme="light"] .nav-links {
  background: rgba(0,0,0,0.03) !important;
  border-color: rgba(0,0,0,0.08) !important;
}

[data-theme="light"] .nav-link.active {
  color: #fff !important;
}

[data-theme="light"] .nav-link:hover {
  background: rgba(0,0,0,0.05) !important;
}

[data-theme="light"] .user-profile-area {
  background: rgba(0,0,0,0.03) !important;
  border-color: rgba(0,0,0,0.08) !important;
}

[data-theme="light"] .nav-icon-btn {
  background: rgba(0,0,0,0.04) !important;
  border-color: rgba(0,0,0,0.1) !important;
}

[data-theme="light"] .nav-icon-btn:hover {
  background: rgba(0,0,0,0.08) !important;
}

[data-theme="light"] .tk-counter {
  background: rgba(245,158,11,0.08) !important;
  border-color: rgba(245,158,11,0.2) !important;
}

[data-theme="light"] .logout-btn {
  background: rgba(239,68,68,0.06) !important;
  border-color: rgba(239,68,68,0.15) !important;
}

[data-theme="light"] .event-feed-panel {
  background: rgba(255,255,255,0.95) !important;
  border-color: rgba(0,0,0,0.08) !important;
}

[data-theme="light"] .feed-card {
  background: rgba(0,0,0,0.02) !important;
  border-color: rgba(0,0,0,0.06) !important;
}

[data-theme="light"] .popup-container {
  color: #0f172a;
}

[data-theme="light"] .footer {
  background: rgba(255,255,255,0.95) !important;
  border-color: rgba(0,0,0,0.06) !important;
}

[data-theme="light"] .footer h4,
[data-theme="light"] .footer .c-label {
  color: #0f172a !important;
}

[data-theme="light"] .footer a {
  color: #6366f1 !important;
}

[data-theme="light"] .footer .footer-bottom {
  color: #64748b !important;
}

/* Smooth theme transition */
body, .navbar, .glass, .modal-content, .ctx-menu, input, textarea, select,
.leaflet-popup-content-wrapper, .atbl th, .atbl td, .sentinel-stat, .nav-icon-btn {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Basic Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  background-color: var(--bg-black);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── Navbar (Enhanced & Animated) ── */
.navbar {
  position: sticky !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: var(--nav-height) !important;
  z-index: 9999 !important;
  background: var(--glass-bg) !important;
  backdrop-filter: blur(20px) !important;
  -webkit-backdrop-filter: blur(20px) !important;
  border-bottom: 1px solid var(--glass-border) !important;
  box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.6) !important;
  display: grid !important;
  grid-template-columns: 240px 1fr auto !important;
  align-items: center !important;
  padding: 0 2.5rem !important;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.nav-left, .nav-center, .nav-right {
  display: flex;
  align-items: center;
}

.nav-left {
  overflow: visible;
  z-index: 10;
}

.nav-center {
  justify-content: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  text-decoration: none;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.brand:hover {
  transform: scale(1.03);
}

.brand img {
  height: 88px;
  width: auto;
  filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.3));
}

.nav-links {
  display: flex;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.45rem;
  border-radius: 100px;
  border: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.6rem 1.25rem;
  border-radius: 100px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  white-space: nowrap;
}

.nav-link i {
  font-size: 1.1rem;
  transition: transform 0.3s ease;
}

.nav-link:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.06);
}

.nav-link:hover i {
  transform: translateY(-1px);
}

.nav-link.active {
  color: #fff;
  background: var(--accent-primary);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.nav-link.active i {
  color: #fff;
}

/* User Controls */
.nav-right {
  gap: 1rem;
}

.nav-icon-wrapper {
  position: relative;
}

.nav-icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.nav-icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.notif-badge {
  display: none !important;
}

.tk-counter {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(245, 158, 11, 0.05));
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 0.6rem 1.1rem;
  border-radius: 14px;
  color: #f59e0b;
  font-weight: 800;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.1);
  transition: all 0.3s ease;
  cursor: pointer;
}

.tk-counter:hover {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.2);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(245, 158, 11, 0.15);
}

.user-profile-area {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.45rem 0.45rem 0.45rem 1.15rem;
  border-radius: 16px;
  border: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
}

.user-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.logout-btn {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #ef4444;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 1.1rem;
}

.logout-btn:hover {
  background: #ef4444;
  color: #fff;
  transform: translateX(3px);
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.3);
}

/* Dropdowns */
.nav-dropdown {
  position: absolute;
  top: calc(100% + 15px);
  right: 0;
  width: 350px;
  background: #0f172a;
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.8);
  display: none;
  flex-direction: column;
  z-index: 10000;
  overflow: hidden;
  animation: navDropdownIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  backdrop-filter: blur(25px);
}

@keyframes navDropdownIn {
  from { opacity: 0; transform: translateY(15px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.nav-dropdown.open { display: flex; }

.dropdown-header {
  padding: 1.25rem;
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dropdown-header span {
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.dropdown-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
}

.dropdown-close:hover { color: #fff; }

.dropdown-body {
  max-height: 450px;
  overflow-y: auto;
  padding: 1rem;
}

/* Modal Close Button (Stylish) */
.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  line-height: 1;
  padding: 0;
}
.modal-close:hover {
  background: rgba(239,68,68,0.15);
  border-color: rgba(239,68,68,0.4);
  color: #ef4444;
  transform: rotate(90deg) scale(1.1);
  box-shadow: 0 0 20px rgba(239,68,68,0.3);
}
[data-theme="light"] .modal-close {
  background: rgba(0,0,0,0.04);
  border-color: rgba(0,0,0,0.1);
}
[data-theme="light"] .modal-close:hover {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.3);
  color: #ef4444;
  box-shadow: 0 0 15px rgba(239,68,68,0.15);
}

/* Scrollable Layouts */
body.map-page {
  height: 100vh !important;
  overflow: hidden !important;
}

body:not(.map-page) {
  height: auto !important;
  min-height: 100vh !important;
  overflow-y: auto !important;
}

/* Responsive */
@media (max-width: 1200px) {
  .navbar { padding: 0 1.5rem !important; grid-template-columns: 180px 1fr auto !important; }
  .nav-links { gap: 0.4rem; padding: 0.35rem; }
  .nav-link { padding: 0.5rem 0.9rem; font-size: 0.8rem; }
}

/* Common UI Components */
.tier-badge {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(148, 163, 184, 0.1);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.2);
}
.tier-plus { background: rgba(79, 110, 247, 0.1); color: #4f6ef7; border: 1px solid rgba(79, 110, 247, 0.2); }
.tier-pro { background: rgba(245, 158, 11, 0.1); color: #f59e0b; border: 1px solid rgba(245, 158, 11, 0.2); }
.tier-premium { background: rgba(168, 85, 247, 0.1); color: #a855f7; border: 1px solid rgba(168, 85, 247, 0.2); }

.quota-item, .notif-item {
  padding: 1rem 1.25rem;
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
  margin-bottom: 0.75rem;
  border: 1px solid rgba(255,255,255,0.05);
  transition: all 0.3s ease;
}

.quota-item:hover, .notif-item:hover {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
  transform: translateX(4px);
}

.quota-item { display: flex; justify-content: space-between; align-items: center; }
.quota-label { font-size: 0.9rem; font-weight: 600; color: var(--text-main); }
.quota-val { font-family: 'JetBrains Mono', monospace; font-weight: 800; color: #f59e0b; font-size: 1rem; }

.notif-time { display: block; font-size: 0.75rem; color: var(--text-muted); margin-top: 0.5rem; font-weight: 500; }

/* ── Pulsing Animation for Markers ── */
@keyframes iconPulse {
  0% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(99, 102, 241, 0)); }
  50% { transform: scale(1.1); filter: drop-shadow(0 0 12px rgba(99, 102, 241, 0.6)); }
  100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(99, 102, 241, 0)); }
}
@keyframes iconPulsePremium {
  0% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(168, 85, 247, 0)); }
  50% { transform: scale(1.15); filter: drop-shadow(0 0 15px rgba(168, 85, 247, 0.8)); }
  100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(168, 85, 247, 0)); }
}
@keyframes iconPulseFeatured {
  0% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(245, 158, 11, 0)); }
  50% { transform: scale(1.12); filter: drop-shadow(0 0 12px rgba(245, 158, 11, 0.7)); }
  100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(245, 158, 11, 0)); }
}

.marker-pulse { animation: iconPulse 2s infinite ease-in-out; }
.marker-pulse-premium { animation: iconPulsePremium 1.8s infinite ease-in-out; }
.marker-pulse-featured { animation: iconPulseFeatured 2.2s infinite ease-in-out; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); border: 2px solid transparent; background-clip: padding-box; }

/* ── Page Transition ── */
html {
  scroll-behavior: smooth;
}

body {
  animation: pageFadeIn 0.25s ease-out;
}

@keyframes pageFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Smooth nav link active state transition */
.nav-link {
  position: relative;
}
.nav-link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) scaleX(0);
  width: 60%;
  height: 2px;
  background: var(--accent-primary);
  border-radius: 2px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.nav-link.active::after {
  transform: translateX(-50%) scaleX(1);
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE DESIGN – Phone / Tablet / Desktop
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Tablet (≤1024px) ─────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .navbar {
    grid-template-columns: 1fr auto !important;
    padding: 0 1rem !important;
    height: 64px !important;
  }
  .nav-left { display: none !important; }
  .nav-center { display: none !important; }
  .nav-right { gap: 0.5rem !important; }

  /* Hamburger menu for mobile nav */
  .mobile-menu-btn {
    display: flex !important;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    width: 40px; height: 40px;
    border-radius: 10px;
    align-items: center; justify-content: center;
    cursor: pointer; font-size: 1.2rem;
  }

  .nav-links {
    display: none !important;
  }

  .nav-links.mobile-open {
    display: flex !important;
    flex-direction: column;
    position: absolute;
    top: 64px; left: 0; right: 0;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    padding: 0.75rem;
    gap: 0.25rem;
    z-index: 9998;
    border-radius: 0 0 16px 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
  }

  .nav-links.mobile-open .nav-link {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-size: 0.9rem;
    width: 100%;
    justify-content: flex-start;
  }

  .nav-icon-btn { width: 38px; height: 38px; border-radius: 10px; }
  .user-name { display: none; }
  .tier-badge { font-size: 0.55rem; padding: 0.15rem 0.4rem; }
  .tk-counter { font-size: 0.75rem; padding: 0.4rem 0.7rem; }

  /* Map takes full height */
  #map { height: calc(100vh - 64px) !important; }

  /* Modals */
  .modal-content { max-width: 95vw !important; margin: 0.5rem; }
  .modal-overlay { padding: 0.5rem; }

  /* Sentinel/Package tabs */
  .sentinel-tab { font-size: 0.7rem; padding: 0.4rem 0.6rem; }

  /* Event feed panel */
  .event-feed-panel { width: 280px !important; font-size: 0.8rem; }

  /* Tables */
  .atbl { font-size: 0.72rem; }
  .atbl th, .atbl td { padding: 0.4rem 0.5rem; }
}

/* ── Phone (≤640px) ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root { --nav-height: 56px; }

  .navbar {
    height: 56px !important;
    padding: 0 0.75rem !important;
    grid-template-columns: 1fr auto !important;
  }

  .brand img { height: 32px; }
  .brand .version-tag { display: none; }

  .nav-right { gap: 0.35rem !important; }
  .nav-icon-btn { width: 34px; height: 34px; border-radius: 8px; font-size: 0.9rem; }
  .tk-counter { font-size: 0.7rem; padding: 0.3rem 0.5rem; border-radius: 8px; }
  .user-profile-area { padding: 0.3rem; border-radius: 10px; gap: 0.4rem; }
  .tier-badge { font-size: 0.5rem; }
  .logout-btn { width: 30px; height: 30px; border-radius: 8px; font-size: 0.9rem; }

  #map { height: calc(100vh - 56px) !important; }

  /* Modals full screen on phone */
  .modal-content {
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    margin: 0;
  }
  .modal-overlay { padding: 0; }
  .modal-header { padding: 0.75rem 1rem; }
  .modal-body { padding: 0.75rem; max-height: calc(100vh - 50px); }

  /* Sentinel/Package panel tabs scroll */
  .sentinel-tab { font-size: 0.65rem; padding: 0.35rem 0.5rem; white-space: nowrap; }

  /* Event feed hidden on phone (toggle button instead) */
  .event-feed-panel {
    width: 100% !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    max-height: 50vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
  }
  .event-feed-panel.open { transform: translateY(0); }

  /* Context menu */
  .ctx-menu { min-width: 180px !important; }

  /* Report form */
  .af-row, .form-group { flex-direction: column; gap: 0.5rem; }

  /* Stats grid */
  .sentinel-stat { padding: 0.5rem; }
  .sentinel-stat-val { font-size: 1.2rem; }
  .sentinel-stat-label { font-size: 0.6rem; }

  /* Tables scroll */
  .atbl { font-size: 0.65rem; display: block; overflow-x: auto; }
  .atbl th, .atbl td { padding: 0.3rem 0.4rem; }

  /* Popup */
  .leaflet-popup-content-wrapper { max-width: 240px; }
  .leaflet-popup-content { font-size: 0.8rem; margin: 8px 10px; }

  /* Footer */
  .footer { padding: 1.5rem 1rem; }
  .footer-grid { grid-template-columns: 1fr !important; gap: 1rem; }
}

/* ── Mobile menu button (hidden on desktop) ──────────────────────────────── */
.mobile-menu-btn { display: none !important; }

/* ── Landscape phone adjustments ─────────────────────────────────────────── */
@media (max-width: 640px) and (orientation: landscape) {
  .navbar { height: 48px !important; }
  #map { height: calc(100vh - 48px) !important; }
  .modal-body { max-height: calc(100vh - 40px); }
}

/* ── Large desktop (≥1400px) ─────────────────────────────────────────────── */
@media (min-width: 1400px) {
  .navbar { padding: 0 3rem !important; grid-template-columns: 260px 1fr auto !important; }
  .nav-links { gap: 1rem; }
  .event-feed-panel { width: 380px; }
}