:root {
  --bg: #0b1020;
  --bg-elev: rgba(20, 26, 48, 0.72);
  --bg-elev-solid: #141a30;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e7ecff;
  --text-dim: #9aa3c7;
  --text-faint: #6b739a;
  --accent: #4ECDC4;
  --danger: #ff6b6b;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --radius-sm: 10px;
  --blur: saturate(180%) blur(20px);
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-elev: rgba(255, 255, 255, 0.78);
  --bg-elev-solid: #ffffff;
  --border: rgba(15, 23, 42, 0.08);
  --text: #0f172a;
  --text-dim: #475569;
  --text-faint: #94a3b8;
  --shadow: 0 10px 40px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--bg);
}

.glass {
  background: var(--bg-elev);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ---------- Topbar ---------- */
.topbar {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius);
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo-dot {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4ECDC4 0%, #556ee6 100%);
  box-shadow: 0 0 24px rgba(78, 205, 196, 0.45);
  flex-shrink: 0;
  position: relative;
}
.logo-dot::after {
  content: "";
  position: absolute;
  inset: 8px;
  background: var(--bg-elev-solid);
  border-radius: 6px;
  opacity: 0.85;
  background-image: radial-gradient(circle at 50% 45%, var(--accent) 0 4px, transparent 5px);
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.subtitle {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #888;
  box-shadow: 0 0 0 0 rgba(78, 205, 196, 0.5);
}
.status-dot.live {
  background: var(--accent);
  animation: pulse-dot 2s infinite;
}
.status-dot.error { background: var(--danger); }
@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 rgba(78, 205, 196, 0.6); }
  70%  { box-shadow: 0 0 0 10px rgba(78, 205, 196, 0); }
  100% { box-shadow: 0 0 0 0 rgba(78, 205, 196, 0); }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.06); }
[data-theme="light"] .icon-btn:hover { background: rgba(15,23,42,0.05); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn.small { width: 32px; height: 32px; border-radius: 10px; }

#theme-toggle .icon-moon { display: none; }
[data-theme="light"] #theme-toggle .icon-sun { display: none; }
[data-theme="light"] #theme-toggle .icon-moon { display: inline-block; }

.select-wrap {
  position: relative;
}
.select-wrap::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-30%) rotate(45deg);
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  pointer-events: none;
}
select {
  appearance: none;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 28px 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
}
select:hover { background: rgba(255,255,255,0.04); }
[data-theme="light"] select:hover { background: rgba(15,23,42,0.03); }
select option { background: var(--bg-elev-solid); color: var(--text); }

/* ---------- Side panel ---------- */
.side-panel {
  position: fixed;
  top: 88px;
  left: 16px;
  width: 320px;
  max-height: calc(100vh - 104px);
  border-radius: var(--radius);
  z-index: 999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.panel-handle { display: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  gap: 10px;
}
.panel-header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}
.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--accent);
  color: #06241f;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}
.panel-sub {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--text-faint);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 10px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.chip:hover { color: var(--text); border-color: var(--text-dim); }
.chip-spacer { flex: 1; }
.follow-label {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.follow-label select {
  padding: 4px 22px 4px 8px;
  font-size: 11px;
}

.alias-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.alias-list:empty { padding: 0; }

.alias-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.alias-item:hover { background: rgba(255,255,255,0.04); }
[data-theme="light"] .alias-item:hover { background: rgba(15,23,42,0.04); }
.alias-item.hidden-alias { opacity: 0.45; }
.alias-item.followed { background: rgba(78, 205, 196, 0.1); }
.alias-item.flash { animation: row-flash 1s ease-out; }
@keyframes row-flash {
  0%   { background: rgba(78, 205, 196, 0.25); }
  100% { background: transparent; }
}

.alias-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.06);
}
.alias-info { min-width: 0; }
.alias-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.alias-meta {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alias-meta .dot { color: var(--text-faint); }
.alias-actions {
  display: flex;
  gap: 4px;
}
.alias-actions .icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 9px;
}
.alias-actions .icon-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
}
.empty-state h3 { margin: 12px 0 6px; font-size: 15px; color: var(--text); font-weight: 600; }
.empty-state p { margin: 0; font-size: 12px; line-height: 1.5; }
.empty-illu { color: var(--text-faint); }
.alias-list:not(:empty) ~ .empty-state { display: none; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  top: 88px;
  right: 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 320px;
}
.toast {
  background: var(--bg-elev);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 13px;
  color: var(--text);
  animation: toast-in 0.3s ease-out, toast-out 0.3s ease-in 3.7s forwards;
  pointer-events: auto;
}
.toast .toast-title { font-weight: 600; font-size: 12px; }
.toast .toast-body { color: var(--text-dim); font-size: 11px; margin-top: 2px; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-8px) scale(0.96); }
}

/* ---------- Leaflet overrides ---------- */
.leaflet-container { background: var(--bg); font-family: inherit; }
.leaflet-control-attribution {
  background: var(--bg-elev) !important;
  color: var(--text-dim) !important;
  backdrop-filter: var(--blur);
  border-radius: 6px 0 0 0;
  padding: 2px 6px !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow) !important;
  border-radius: 12px !important;
  overflow: hidden;
}
.leaflet-control-zoom a {
  background: var(--bg-elev) !important;
  backdrop-filter: var(--blur);
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 18px !important;
}
.leaflet-control-zoom a:hover { background: rgba(255,255,255,0.08) !important; }
[data-theme="light"] .leaflet-control-zoom a:hover { background: rgba(15,23,42,0.05) !important; }

/* Custom marker */
.loc-marker {
  position: relative;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.loc-marker .pin {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--c, #4ECDC4);
  border: 3px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0;
  box-shadow: 0 4px 14px rgba(0,0,0,0.45), 0 0 0 1px rgba(0,0,0,0.2);
  z-index: 2;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.loc-marker .pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--c, #4ECDC4);
  opacity: 0.5;
  animation: pulse-marker 2.4s ease-out infinite;
  z-index: 1;
}
@keyframes pulse-marker {
  0%   { transform: scale(0.8); opacity: 0.55; }
  80%  { transform: scale(2.2); opacity: 0; }
  100% { transform: scale(2.2); opacity: 0; }
}
.loc-marker.flash .pin {
  animation: marker-flash 0.6s ease-out;
}
@keyframes marker-flash {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.35); box-shadow: 0 0 0 8px rgba(255,255,255,0.4), 0 4px 14px rgba(0,0,0,0.45); }
  100% { transform: scale(1); }
}

.marker-tooltip {
  background: var(--bg-elev) !important;
  backdrop-filter: var(--blur);
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  font-size: 12px !important;
  font-weight: 600;
  padding: 4px 8px !important;
  border-radius: 8px !important;
  box-shadow: var(--shadow) !important;
}
.marker-tooltip::before { display: none !important; }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .topbar {
    top: 8px;
    left: 8px;
    right: 8px;
    padding: 8px 10px;
  }
  .brand h1 { font-size: 13px; }
  .subtitle { font-size: 10px; }
  .logo-dot { width: 30px; height: 30px; border-radius: 10px; }
  .icon-btn { width: 34px; height: 34px; }
  select { padding: 7px 24px 7px 10px; font-size: 12px; }

  .side-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: 55vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(calc(100% - 80px));
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .side-panel.expanded { transform: translateY(0); }
  .panel-handle {
    display: block;
    width: 40px;
    height: 4px;
    background: var(--text-faint);
    border-radius: 2px;
    margin: 8px auto 0;
    opacity: 0.5;
    cursor: grab;
  }
  .panel-header { padding-top: 8px; }
  #panel-toggle svg { transition: transform 0.2s; }
  .side-panel.expanded #panel-toggle svg { transform: rotate(180deg); }

  .toasts { top: 70px; right: 8px; left: 8px; max-width: none; }
}

/* ---------- No-Access Screen ---------- */
.no-access-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at top, rgba(78, 205, 196, 0.08), transparent 60%),
    radial-gradient(ellipse at bottom, rgba(85, 110, 230, 0.08), transparent 60%),
    var(--bg);
}
.no-access-card {
  max-width: 420px;
  width: 100%;
  text-align: center;
  padding: 36px 32px;
  border-radius: 20px;
}
.no-access-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(78, 205, 196, 0.18), rgba(85, 110, 230, 0.18));
  color: var(--accent);
  margin-bottom: 18px;
}
.no-access-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.no-access-card p {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.5;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
