/* ==========================================================================
   Zenith Geospatial Design System & Cyber-Luxury Stylesheet
   ========================================================================== */

:root {
  /* Zenith Color Tokens */
  --surface: #0b1326;
  --surface-dim: #0b1326;
  --surface-bright: #31394d;
  --surface-container-lowest: #060e20;
  --surface-container-low: #131b2e;
  --surface-container: #171f33;
  --surface-container-high: #222a3d;
  --surface-container-highest: #2d3449;
  --on-surface: #dae2fd;
  --on-surface-variant: #c7c4d7;
  --inverse-surface: #dae2fd;
  --inverse-on-surface: #283044;
  --outline: #908fa0;
  --outline-variant: #464554;
  --surface-tint: #c0c1ff;
  --primary: #c0c1ff;
  --on-primary: #1000a9;
  --primary-container: #8083ff;
  --on-primary-container: #0d0096;
  --inverse-primary: #494bd6;
  --secondary: #4edea3;
  --on-secondary: #003824;
  --secondary-container: #00a572;
  --on-secondary-container: #00311f;
  --tertiary: #ffb95f;
  --on-tertiary: #472a00;
  --tertiary-container: #ca8100;
  --on-tertiary-container: #3e2400;
  --error: #ffb4ab;
  --on-error: #690005;
  --error-container: #93000a;
  --on-error-container: #ffdad6;
  --primary-fixed: #e1e0ff;
  --primary-fixed-dim: #c0c1ff;
  --on-primary-fixed: #07006c;
  --on-primary-fixed-variant: #2f2ebe;
  --secondary-fixed: #6ffbbe;
  --secondary-fixed-dim: #4edea3;
  --on-secondary-fixed: #002113;
  --on-secondary-fixed-variant: #005236;
  --tertiary-fixed: #ffddb8;
  --tertiary-fixed-dim: #ffb95f;
  --on-tertiary-fixed: #2a1700;
  --on-tertiary-fixed-variant: #653e00;
  --background: #0b1326;
  --on-background: #dae2fd;
  --surface-variant: #2d3449;

  /* Legacy Mapped Tokens for Compatibility */
  --bg-app: var(--background);
  --bg-sidebar: #050810;
  --bg-surface: var(--surface-container);
  --bg-surface-hover: var(--surface-container-high);
  --bg-card: var(--surface-container-low);
  --bg-card-selected: var(--surface-container-highest);

  /* Status Tokens */
  --color-available: #4edea3;
  --color-available-glow: rgba(78, 222, 163, 0.15);
  --color-assigned: #ffb95f;
  --color-assigned-glow: rgba(255, 185, 95, 0.15);
  --color-completed: #c0c1ff;
  --color-completed-glow: rgba(192, 193, 255, 0.15);
  --color-boundary-needed: #908fa0;
  --color-boundary-needed-glow: rgba(144, 143, 160, 0.1);

  /* Accents */
  --color-primary: #8083ff;
  --color-primary-hover: #6366f1;
  --color-primary-glow: rgba(128, 131, 255, 0.25);
  --color-danger: #ffb4ab;

  /* Layout */
  --sidebar-width: 340px;

  /* Typography */
  --text-main: var(--on-surface);
  --text-muted: var(--on-surface-variant);
  --text-inverse: var(--inverse-on-surface);

  /* Borders & Lines */
  --border-subtle: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.2);

  /* Radii */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body,
html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Main App Container */
.tp-app-container {
  display: flex;
  width: 100vw;
  height: 100vh; /* fallback for older browsers */
  height: 100dvh; /* dynamic viewport height — excludes mobile browser chrome */
  position: relative;
  overflow: hidden;
}

/* ================= Login Gatekeeper ================= */
#tpLoginGatekeeper {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #03050e;
}

#tp-globe-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
}

.login-overlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(6, 9, 20, 0.45) 0%, rgba(4, 7, 15, 0.75) 100%);
  pointer-events: none;
  z-index: 1;
}

.login-card-container {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.login-card {
  background: rgba(13, 19, 33, 0.55);
  backdrop-filter: blur(25px) saturate(180%);
  -webkit-backdrop-filter: blur(25px) saturate(180%);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-2xl);
  padding: 36px 32px;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(128, 131, 255, 0.25) inset;
}

.login-card h2 {
  font-family: 'Outfit', sans-serif;
  font-size: 2.25rem;
  color: #fff;
  margin-bottom: 8px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff, var(--primary));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-card p {
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.login-field-group {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.login-field-group label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.login-card input {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  color: #fff;
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s ease;
  font-family: 'Inter', sans-serif;
}

.login-card input:focus {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.login-card button {
  width: 100%;
  background: linear-gradient(135deg, var(--color-primary-hover), #8083ff);
  color: #fff;
  border: none;
  border-radius: var(--radius-lg);
  padding: 13px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: 10px;
  transition: transform 0.2s, box-shadow 0.2s;
  font-family: 'Inter', sans-serif;
}

.login-card button:hover {
  box-shadow: 0 0 24px rgba(128, 131, 255, 0.45);
}

.login-card button:active {
  transform: scale(0.98);
}

/* ================= Sidebar Layout =================
   The sidebar is an overlay on every viewport (it never pushes the map).
   Hidden = translated off-screen left; visible = body.tp-sidebar-open sets
   transform: translateX(0), giving a smooth slide-in/out animation. */
.tp-sidebar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  z-index: 1500; /* above the map + floating controls, below drawer/modals */
  background: #0a0f1e;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  transform: translateX(-100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
  will-change: transform;
}

body.tp-sidebar-open .tp-sidebar {
  transform: translateX(0);
}

/* Since the panel is now an overlay everywhere, the close (×) button is
   always available — on desktop too — so a closed panel can be reopened
   from the map and an open panel closed from inside itself. */
.tp-sidebar-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tp-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.tp-logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Close arrow button in the sidebar header to collapse/close panel */
.tp-sidebar-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tp-sidebar-close:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.25);
}

.tp-sidebar-close:active {
  transform: scale(0.95);
}

/* Keep Leaflet's bottom-right controls above the browser home indicator / tab bar */
.leaflet-bottom {
  bottom: env(safe-area-inset-bottom, 0px);
}

.tp-logo-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #8083ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  color: #fff;
  font-size: 13px;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.45);
}

.tp-logo-text h1 {
  font-family: 'Outfit', sans-serif;
  color: #fff;
  font-size: 15px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.tp-logo-text p {
  color: var(--text-muted);
  font-size: 10px;
  margin: 0;
  line-height: 1.2;
}

/* Mode Toggles */
.tp-mode-toggles {
  padding: 10px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.tp-pill-btn {
  padding: 7px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
}

.tp-pill-btn .material-symbols-outlined {
  font-size: 15px !important;
}

.tp-pill-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.35);
}

.tp-pill-btn.active,
.tp-pill-btn.tp-elder-active {
  background: #6366f1;
  border-color: #6366f1;
  color: #fff;
  box-shadow: 0 0 14px rgba(99, 102, 241, 0.4);
}

/* Stats Dashboard */
.tp-stats-dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  padding: 12px 0 10px;
}

.tp-stat-card {
  background: transparent;
  padding: 8px 4px;
  text-align: center;
  cursor: default;
}

.tp-stat-num {
  font-family: 'Outfit', sans-serif;
  font-size: 28px;
  font-weight: 800;
  color: #4edea3;
  line-height: 1;
  display: block;
}

.tp-stat-num.assigned {
  color: #ffb95f;
}

.tp-stat-num.completed {
  color: #c0c1ff;
}

.tp-stat-label {
  font-size: 9px;
  color: rgba(255, 255, 255, 0.45);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  margin-top: 5px;
  display: block;
}

.tp-stat-shimmer {
  height: 56px;
  width: 100%;
  background: linear-gradient(90deg, #131b2e 25%, #222a3d 50%, #131b2e 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  grid-column: span 3;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

/* Search & Filters */
.tp-search-filter-section,
.tp-controls-section {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tp-search-box,
.tp-search-container {
  position: relative;
}

.tp-search-box input,
#tpSearchInput {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 9px 12px 9px 34px;
  color: #fff;
  font-size: 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  font-family: 'Inter', sans-serif;
}

.tp-search-box input::placeholder,
#tpSearchInput::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.tp-search-box input:focus,
#tpSearchInput:focus {
  border-color: rgba(128, 131, 255, 0.6);
  box-shadow: 0 0 0 2px rgba(128, 131, 255, 0.15);
  background: rgba(255, 255, 255, 0.07);
}

.tp-search-icon,
.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.3);
  font-size: 16px;
  pointer-events: none;
}

.tp-clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  display: none;
  padding: 2px;
  font-size: 14px;
}

.tp-filter-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.tp-filter-chips::-webkit-scrollbar {
  display: none;
}

.tp-chip {
  padding: 4px 10px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.55);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  border: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.tp-chip:hover {
  color: rgba(255, 255, 255, 0.85);
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.09);
}

.tp-chip.active {
  background: #6366f1;
  color: #fff;
  border-color: var(--color-primary-hover);
  box-shadow: 0 2px 8px var(--color-primary-glow);
}

/* Scrollable List Section */
.tp-list-section {
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.tp-list {
  display: flex;
  flex-direction: column;
}

.tp-card {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: background 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.tp-card:hover {
  background: rgba(255, 255, 255, 0.04);
}

.tp-card.selected {
  background: rgba(99, 102, 241, 0.12);
  border-left: 2px solid #6366f1;
  padding-left: 14px;
}

.tp-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin-bottom: 0;
}

.tp-badge {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.9);
  flex-shrink: 0;
  white-space: nowrap;
}

.tp-card-name {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: rgba(255, 255, 255, 0.85);
}

.status-badge,
.tp-pill {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.status-available,
.tp-pill-available {
  color: var(--secondary);
  background: rgba(78, 222, 163, 0.12);
  border: 1px solid rgba(78, 222, 163, 0.3);
}

.status-assigned,
.tp-pill-assigned {
  color: var(--tertiary);
  background: rgba(255, 185, 95, 0.12);
  border: 1px solid rgba(255, 185, 95, 0.3);
}

.status-completed,
.tp-pill-completed {
  color: var(--primary);
  background: rgba(192, 193, 255, 0.12);
  border: 1px solid rgba(192, 193, 255, 0.3);
}

.status-needs_boundary,
.tp-pill-needs_boundary {
  color: var(--outline);
  background: rgba(144, 143, 160, 0.1);
  border: 1px dashed rgba(144, 143, 160, 0.4);
}

.tp-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
}

/* Small info chips inside each territory card (assigned to, last worked,
   Idle countdown). Inline color styles (e.g. red countdown) still win. */
.tp-card-meta span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.65);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  padding: 2px 7px;
  white-space: nowrap;
  line-height: 1.4;
}

.tp-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Sidebar Footer */
.tp-sidebar-footer {
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 2px solid rgba(255, 255, 255, 0.07);
  display: flex;
  gap: 16px;
  background-color: #0a0f1e;
}

.tp-mode-btn,
.tp-add-btn {
  height: 80px;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  outline: none;
  transition: all 0.15s ease;
}

.tp-mode-btn {
  flex: 1;
  background-color: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
}

.tp-mode-btn:hover {
  background-color: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
}

.tp-add-btn {
  flex: 1;
  background: linear-gradient(135deg, #6366f1, #494bd6);
  border: none;
  color: #fff;
  box-shadow: 0 3px 10px rgba(99, 102, 241, 0.35);
}

.tp-add-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(99, 102, 241, 0.5);
}

/* ================= Map Section ================= */
.tp-map-wrap {
  flex: 1;
  position: relative;
  background: #000;
  transition: transform 0.5s ease-out;
}

#tp-map {
  width: 100%;
  height: 100%;
  z-index: 1;
}

body.tp-immersive-mode .tp-app-container {
  perspective: 1500px;
}

body.tp-immersive-mode .tp-map-wrap {
  transform-style: preserve-3d;
}

/* Map Controls & Floating Toolbar */
.tp-map-floating-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tp-map-btn {
  background: rgba(10, 15, 30, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  transition: all 0.2s ease;
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
}

.tp-map-btn:hover {
  background: rgba(20, 28, 50, 0.95);
  border-color: rgba(255, 255, 255, 0.22);
}

.tp-map-btn .material-symbols-outlined {
  font-size: 16px !important;
}

/* Collapsible hamburger menu for the map toolbar */
.tp-map-menu {
  position: relative;
}

.tp-map-menu-toggle {
  width: 42px;
  height: 42px;
  background: rgba(10, 15, 30, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  transition: all 0.2s ease;
}

.tp-map-menu-toggle:hover {
  background: rgba(20, 28, 50, 0.95);
  border-color: rgba(255, 255, 255, 0.22);
}

.tp-map-menu-toggle.active {
  background: rgba(99, 102, 241, 0.25);
  border-color: rgba(192, 193, 255, 0.5);
  color: #c0c1ff;
}

.tp-map-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: rgba(10, 15, 30, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px) scale(0.97);
  transform-origin: top right;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
  pointer-events: none;
}

.tp-map-menu-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.tp-map-menu-panel .tp-map-btn {
  width: 100%;
  justify-content: flex-start;
  padding: 9px 12px;
}

.tp-map-btn-danger {
  background-color: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #ef4444;
  font-weight: 600;
}

/* Map Legend */
.tp-legend-card {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 24px;
  z-index: 1000;
  background: rgba(13, 19, 33, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  color: #fff;
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* The sidebar is an overlay on top of the map, so the toggle arrow
   (top-left) and legend (bottom-left) would be hidden behind it while open.
   Slide them to just right of the panel so they stay visible + usable. */
body.tp-sidebar-open #tpSidebarToggleBtn {
  left: calc(var(--sidebar-width) + 16px) !important; /* overrides inline left:16px */
}

body.tp-sidebar-open .tp-legend-card {
  left: calc(var(--sidebar-width) + 24px);
}

#tpSidebarToggleBtn {
  /* Keep the slide animation for left, but preserve the base .tp-map-btn
     hover transitions (background/border/shadow) so they don't snap. */
  transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.3s ease,
    background 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.tp-legend-card h4 {
  font-family: 'Outfit', sans-serif;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.tp-legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.tp-legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

/* Color swatch rendered by renderLegend() — must stay visible! */
.tp-legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}


/* Map Label Overlay */
.tp-territory-label {
  background: rgba(11, 19, 38, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-strong);
  color: #fff;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

/* Draggable vertex handle used while tracing a boundary */
.tp-draw-point {
  width: 14px;
  height: 14px;
  background-color: #f59e0b;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.9);
  cursor: grab;
  box-sizing: border-box;
}

.tp-draw-point:active {
  cursor: grabbing;
}

/* Midpoint "+" handle shown while reshaping: click it to insert a new
   vertex exactly between two existing ones. Indigo so it's distinct from
   the red vertex handles. */
.tp-vertex-add {
  width: 16px;
  height: 16px;
  background-color: #8083ff;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(128, 131, 255, 0.95);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-sizing: border-box;
  user-select: none;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.tp-vertex-add:hover {
  background-color: #6366f1;
  transform: scale(1.2);
}

/* Boundary tracing banner (point count, Undo / Finish / Cancel) */
.tp-draw-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background-color: rgba(30, 41, 59, 0.92);
  border: 1px solid var(--color-assigned);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  backdrop-filter: blur(8px);
}

.tp-draw-banner span {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-assigned);
}

.tp-draw-banner button {
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  background-color: var(--color-assigned);
  color: var(--text-inverse);
  transition: all var(--transition-fast);
}

.tp-draw-banner button:hover {
  opacity: 0.9;
}

.tp-draw-banner button.ghost {
  background-color: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.tp-draw-banner button.ghost:hover {
  color: var(--text-main);
  background-color: var(--bg-surface);
}

/* ================= Drawer & Modals ================= */
.tp-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.tp-drawer-overlay.show {
  display: block;
  opacity: 1;
}

.tp-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  max-width: 90vw;
  height: 100%;
  background: #0f172a;
  border-left: 1px solid var(--border-subtle);
  z-index: 10001;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

.tp-drawer.open {
  transform: translateX(0);
}

/* ================= Drawer Internal Form & Detail Styling ================= */
div.tp-drawer {
  background-color: #0b1326 !important;
  color: #dae2fd !important;
}

div.tp-drawer-head {
  padding: 20px 24px !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  background: #0f172a !important;
}

div.tp-drawer-close {
  margin-left: auto !important;
  background: transparent !important;
  border: none !important;
  color: var(--text-muted) !important;
  cursor: pointer !important;
  padding: 6px !important;
  border-radius: var(--radius-sm) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: color 0.2s, background 0.2s !important;
}

div.tp-drawer-close:hover {
  color: #fff !important;
  background: rgba(255, 255, 255, 0.1) !important;
}

div.tp-drawer-body {
  flex: 1 !important;
  overflow-y: auto !important;
  padding: 20px 24px !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 16px !important;
}

div.tp-drawer .tp-row2 {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 12px !important;
}

div.tp-drawer .tp-field {
  display: flex !important;
  flex-direction: column !important;
  gap: 6px !important;
  width: 100% !important;
}

div.tp-drawer .tp-field label {
  font-size: 11px !important;
  font-weight: 700 !important;
  color: #94a3b8 !important;
  text-transform: uppercase !important;
  letter-spacing: 0.05em !important;
  display: block !important;
  margin-bottom: 2px !important;
}

/* Force dark styling on all form controls inside drawer and modal */
div.tp-drawer input,
div.tp-drawer select,
div.tp-drawer textarea,
div.tp-modal input,
div.tp-modal select,
div.tp-modal textarea {
  width: 100% !important;
  background-color: #171f33 !important;
  background: #171f33 !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  border-radius: 8px !important;
  padding: 10px 12px !important;
  color: #ffffff !important;
  font-size: 13px !important;
  font-family: 'Inter', sans-serif !important;
  outline: none !important;
  box-sizing: border-box !important;
  box-shadow: none !important;
  display: block !important;
  margin: 0 !important;
  appearance: auto !important;
  -webkit-appearance: auto !important;
  transition: border-color 0.2s, box-shadow 0.2s !important;
}

div.tp-drawer select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 10px center !important;
  background-size: 16px !important;
  padding-right: 32px !important;
  appearance: none !important;
  -webkit-appearance: none !important;
}

div.tp-drawer input:focus,
div.tp-drawer select:focus,
div.tp-drawer textarea:focus,
div.tp-modal input:focus,
div.tp-modal select:focus,
div.tp-modal textarea:focus {
  border-color: #8083ff !important;
  box-shadow: 0 0 0 2px rgba(128, 131, 255, 0.25) !important;
}

div.tp-drawer select option,
div.tp-modal select option {
  background-color: #171f33 !important;
  color: #ffffff !important;
}

div.tp-drawer textarea {
  min-height: 90px !important;
  resize: vertical !important;
  line-height: 1.4 !important;
}

div.tp-drawer .tp-field-value {
  padding: 10px 12px !important;
  background: #171f33 !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  border-radius: 8px !important;
  color: #ffffff !important;
  font-size: 13px !important;
  line-height: 1.4 !important;
}

div.tp-drawer .tp-photo-frame {
  width: 100% !important;
  height: 190px !important;
  border-radius: 8px !important;
  overflow: hidden !important;
  background: #171f33 !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  position: relative !important;
}

div.tp-drawer .tp-photo-error {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  color: #94a3b8 !important;
  font-size: 12px !important;
  text-align: center !important;
  padding: 20px !important;
}

div.tp-drawer-actions {
  padding: 16px 24px !important;
  border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  background: #0f172a !important;
}

div.tp-drawer .tp-btn {
  height: 40px !important;
  padding: 0 16px !important;
  border-radius: 8px !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
  outline: none !important;
  border: none !important;
  transition: all 0.2s ease !important;
  white-space: nowrap !important;
}

div.tp-drawer .tp-btn-primary {
  background: linear-gradient(135deg, #6366f1, #494bd6) !important;
  color: #ffffff !important;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3) !important;
}

div.tp-drawer .tp-btn-primary:hover {
  transform: translateY(-1px) !important;
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.45) !important;
}

div.tp-drawer .tp-btn-secondary {
  background: #171f33 !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  color: #ffffff !important;
}

div.tp-drawer .tp-btn-secondary:hover {
  background: #222a3d !important;
  border-color: rgba(255, 255, 255, 0.3) !important;
}

div.tp-drawer .tp-btn-danger {
  background: rgba(255, 180, 171, 0.12) !important;
  border: 1px solid rgba(255, 180, 171, 0.3) !important;
  color: #ffb4ab !important;
}

div.tp-drawer .tp-btn-danger:hover {
  background: rgba(255, 180, 171, 0.25) !important;
}

div.tp-drawer .tp-btn-wide {
  flex: 1 !important;
}

.tp-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(12px);
  z-index: 11000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.tp-modal-overlay.open {
  display: flex;
}

.tp-modal {
  background: rgba(17, 27, 49, 0.95);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px; /* wide enough for the boundary modal's 520px intent */
  padding: 28px;
  color: #fff;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7);
}

.tp-modal-head h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 6px;
}

.tp-modal-head p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 16px;
}

.tp-modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tp-pin-input {
  text-align: center;
  font-size: 24px !important;
  letter-spacing: 12px;
  padding-left: 20px !important;
}

.tp-error-text {
  color: var(--color-danger);
  font-size: 12px;
  font-weight: 600;
  margin-top: 6px;
  display: none;
}

.tp-help {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 12px;
  line-height: 1.4;
  border-top: 1px dashed var(--border-subtle);
  padding-top: 10px;
}

/* Modal action row — Cancel / Enter side by side, each a full-size button */
.tp-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

/* Modal buttons — styled directly (the drawer .tp-btn rules don't reach
   modals), tall and clearly visible. Cancel = outlined, Enter/Save =
   primary gradient. */
div.tp-modal .tp-btn {
  height: 44px !important;
  padding: 0 20px !important;
  border-radius: 10px !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 14px !important;
  font-weight: 700 !important;
  cursor: pointer !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
  outline: none !important;
  border: none !important;
  transition: all 0.2s ease !important;
  white-space: nowrap !important;
}

div.tp-modal .tp-btn-primary {
  background: linear-gradient(135deg, #6366f1, #494bd6) !important;
  color: #ffffff !important;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.45) !important;
}

div.tp-modal .tp-btn-primary:hover {
  transform: translateY(-1px) !important;
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6) !important;
}

div.tp-modal .tp-btn-secondary {
  background: rgba(255, 255, 255, 0.06) !important;
  border: 1px solid rgba(255, 255, 255, 0.22) !important;
  color: #ffffff !important;
}

div.tp-modal .tp-btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12) !important;
  border-color: rgba(255, 255, 255, 0.38) !important;
}

div.tp-modal .tp-btn-wide {
  flex: 1 !important;
}

/* Management page (publisher list manager) */
.tp-mgmt-overlay {
  position: fixed;
  inset: 0;
  z-index: 11500;
  background: rgba(2, 6, 18, 0.78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}

.tp-mgmt-overlay.open {
  display: flex;
  animation: tpMgmtFadeIn 0.22s ease;
}

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

.tp-mgmt-card {
  width: 100%;
  max-width: 640px;
  max-height: min(86vh, 720px);
  display: flex;
  flex-direction: column;
  background: rgba(17, 27, 49, 0.97);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7);
  animation: tpMgmtRise 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes tpMgmtRise {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.tp-mgmt-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 22px 24px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.tp-mgmt-head h3 {
  margin: 0;
  font-family: 'Outfit', sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
}

.tp-mgmt-head p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.tp-mgmt-close {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #94a3b8;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.tp-mgmt-close:hover {
  background: rgba(239, 68, 68, 0.16);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.4);
}

.tp-mgmt-add {
  display: flex;
  gap: 10px;
  padding: 16px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.tp-mgmt-namegroup {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.tp-mgmt-namegroup input {
  flex: 1;
  min-width: 0;
  height: 42px;
  background: #0f172a;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 13px;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.tp-mgmt-namegroup input:focus {
  border-color: rgba(99, 102, 241, 0.65);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.tp-mgmt-add select {
  height: 42px;
  background: #0f172a;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 0 10px;
  font-size: 13px;
  outline: none;
}

.tp-mgmt-add select option {
  background: #0f172a;
  color: #fff;
}

.tp-mgmt-add .tp-btn {
  height: 42px;
  padding: 0 20px;
  border-radius: 10px;
  flex-shrink: 0;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  outline: none;
  transition: all 0.2s ease;
}

.tp-mgmt-add .tp-btn-primary {
  background: linear-gradient(135deg, #6366f1, #494bd6);
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.45);
}

.tp-mgmt-add .tp-btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

.tp-mgmt-body {
  overflow-y: auto;
  padding: 18px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
  min-height: 0;
}

.tp-mgmt-cat {
  display: flex;
  flex-direction: column;
}

.tp-mgmt-cat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #cbd5e1;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  margin: -4px -6px;
  border-radius: 8px;
  text-align: left;
  font-family: inherit;
  width: 100%;
  transition: background 0.2s ease;
}

.tp-mgmt-cat-head:hover {
  background: rgba(255, 255, 255, 0.05);
}

.tp-mgmt-chevron {
  color: #64748b;
  flex-shrink: 0;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.tp-mgmt-cat.open .tp-mgmt-chevron {
  transform: rotate(180deg);
}

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

.tp-mgmt-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 1px 9px;
}

.tp-mgmt-names {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  margin-top: 0;
  transition: grid-template-rows 0.3s ease, opacity 0.25s ease, margin-top 0.3s ease;
}

.tp-mgmt-cat.open .tp-mgmt-names {
  grid-template-rows: 1fr;
  opacity: 1;
  margin-top: 10px;
}

/* Inner wrapper lets the row grow to fit every member chip — no clipping. */
.tp-mgmt-names-inner {
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tp-mgmt-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 5px 6px 5px 12px;
  font-size: 12.5px;
  color: #e2e8f0;
  max-width: 100%;
}

.tp-mgmt-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.tp-mgmt-del {
  background: rgba(255, 255, 255, 0.07);
  border: none;
  color: #94a3b8;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.tp-mgmt-del:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.tp-mgmt-empty {
  font-size: 12px;
  color: #64748b;
  font-style: italic;
}

/* Total individuals summary pinned to the bottom of the modal */
.tp-mgmt-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 23, 42, 0.55);
  flex-shrink: 0;
}

.tp-mgmt-foot-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.tp-mgmt-foot-num {
  font-family: 'Outfit', sans-serif;
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, #c0c1ff, #4edea3);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: #c0c1ff;
}

@media (max-width: 767px) {
  .tp-mgmt-overlay {
    padding: 0;
  }
  .tp-mgmt-card {
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  .tp-mgmt-add {
    flex-wrap: wrap;
  }
  .tp-mgmt-namegroup {
    flex: 1 1 100%;
  }
  .tp-mgmt-add select {
    flex: 1 1 100%;
  }
  .tp-mgmt-add .tp-btn {
    flex: 1 1 100%;
  }
}

/* Toast Center */
.toast-popup,
.tp-toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(49, 57, 77, 0.95);
  color: #fff;
  padding: 12px 24px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 500;
  z-index: 12000;
  max-width: min(90vw, 480px);
  text-align: center;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-subtle);
  pointer-events: none;
}

.tp-toast.show {
  transform: translateX(-50%) translateY(0);
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Lightbox */
.tp-lightbox {
  position: fixed;
  inset: 0;
  z-index: 12000;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
}

.tp-lightbox.open {
  display: flex;
}

.tp-lightbox-content img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

.tp-lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 32px;
  cursor: pointer;
}

/* ==========================================================================
   Mobile (<768px) overrides — MUST come after all base rules so the cascade
   lets these win over equal-specificity base styles. Hiding every floating
   map element while the sidebar panel is open, plus compact toast + legend.
   ========================================================================== */
@media (max-width: 767px) {
  /* On phones the panel covers the full screen (base overlay + slide stay
     in effect; only the width changes). */
  body.tp-sidebar-open .tp-sidebar {
    width: 100%;
    z-index: 2000;
  }

  body.tp-sidebar-open .tp-map-floating-controls,
  body.tp-sidebar-open #tpSidebarToggleBtn,
  body.tp-sidebar-open .tp-legend-card,
  body.tp-sidebar-open .leaflet-control-container,
  body.tp-sidebar-open #tp-three-canvas {
    display: none !important;
  }

  /* Compact toast on mobile: slim pill, smaller text, never a wide panel */
  .toast-popup,
  .tp-toast {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    padding: 9px 16px;
    font-size: 12px;
    max-width: min(88vw, 320px);
    line-height: 1.35;
  }

  /* Compact color-only legend on mobile: hide the title + labels, keep dots */
  .tp-legend-card {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 14px;
    padding: 6px 8px;
    border-radius: 999px;
  }

  .tp-legend-card h4 {
    display: none;
  }

  .tp-legend-items {
    gap: 10px;
  }

  .tp-legend-item span {
    display: none;
  }

  .tp-legend-dot {
    width: 12px;
    height: 12px;
  }
}
