:root {
  --bg-primary: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-card: #334155;
  --bg-card-hover: #475569;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #38bdf8;
  --accent-hover: #0284c7;
  --accent-glow: rgba(56, 189, 248, 0.25);
  --parcel-border: #f59e0b;
  --parcel-fill: rgba(245, 158, 11, 0.15);
  --parcel-hover: rgba(56, 189, 248, 0.4);
  --parcel-active: #ec4899;
  --border-color: rgba(255, 255, 255, 0.08);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --font-main: 'Outfit', sans-serif;
}

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

body, html {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100%;
  width: 100%;
  overflow: hidden;
}

.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar Styling */
.sidebar {
  width: 380px;
  min-width: 340px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.brand-icon {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #fff;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.ku-select-dropdown {
  background-color: rgba(30, 41, 59, 0.7);
  border: 1px solid rgba(56, 189, 248, 0.2);
  color: var(--accent);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  outline: none;
  padding: 8px 12px;
  margin-top: 4px;
  border-radius: var(--radius-md);
  cursor: pointer;
  max-width: 240px;
  width: 100%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(8px);
}

.ku-select-dropdown:hover {
  border-color: var(--accent);
  background-color: rgba(30, 41, 59, 0.9);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.ku-select-dropdown:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.ku-select-dropdown option,
select option {
  background-color: #0f172a !important;
  color: #f8fafc !important;
  padding: 8px 12px;
}


.badge {
  font-size: 0.75rem;
  font-weight: 500;
  background-color: rgba(56, 189, 248, 0.12);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 20px;
  display: inline-block;
  margin-top: 2px;
}

.search-box {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-box input {
  width: 100%;
  padding: 10px 12px 10px 38px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  transition: all 0.2s ease;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Tab navigation */
.tab-nav {
  display: flex;
  padding: 8px 20px;
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
  background-color: rgba(0, 0, 0, 0.15);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  color: var(--accent);
  background-color: rgba(56, 189, 248, 0.12);
  font-weight: 600;
}

/* Sidebar Content */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

.info-card {
  display: flex;
  gap: 12px;
  background-color: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.2);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 16px;
}

.info-icon {
  font-size: 1.2rem;
}

.owners-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.owner-item {
  padding: 12px 14px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.owner-item:hover {
  background-color: var(--bg-card-hover);
  transform: translateY(-1px);
  border-color: var(--accent);
}

.owner-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.owner-parcels-count {
  font-size: 0.75rem;
  background-color: rgba(0, 0, 0, 0.3);
  padding: 3px 8px;
  border-radius: 12px;
  color: var(--accent);
}

/* Parcel detail card */
.parcel-detail-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
}

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

.detail-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.detail-field {
  background-color: rgba(0, 0, 0, 0.2);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.detail-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.detail-value {
  font-size: 0.95rem;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  margin-bottom: 12px;
  opacity: 0.5;
}

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  font-size: 0.8rem;
  color: var(--text-muted);
  background-color: rgba(0, 0, 0, 0.2);
}

.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status-online {
  color: #10b981;
  font-weight: 500;
}

/* Map Container */
.map-container {
  flex: 1;
  position: relative;
  height: 100vh;
  width: 100%;
}

#map {
  width: 100%;
  height: 100%;
  background-color: #0f172a;
}

/* Floating Controls */
.map-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  gap: 6px;
  background-color: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(12px);
  padding: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
}

.layer-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.layer-btn:hover {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.1);
}

.layer-btn.active {
  background-color: var(--accent);
  color: #0f172a;
  font-weight: 600;
}

/* Custom Leaflet Tooltip & Popup */
.leaflet-popup-content-wrapper {
  background: rgba(30, 41, 59, 0.95) !important;
  backdrop-filter: blur(12px);
  color: var(--text-primary) !important;
  border-radius: var(--radius-md) !important;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg) !important;
  padding: 4px !important;
}

.leaflet-popup-tip {
  background: rgba(30, 41, 59, 0.95) !important;
}

.custom-popup {
  padding: 8px 12px;
}

.custom-popup h3 {
  font-size: 1.05rem;
  color: var(--accent);
  margin-bottom: 4px;
}

.custom-popup p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

/* Floating overlay buttons on Map */
.map-overlay-btn {
  position: absolute;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  backdrop-filter: blur(8px);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  cursor: pointer;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.map-overlay-btn:hover {
  background: var(--bg-card-hover);
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px var(--accent-glow);
}

#sidebar-toggle {
  top: 20px;
  left: 20px;
  width: 44px;
  height: 44px;
}

#locate-btn {
  top: 76px;
  left: 20px;
  width: 44px;
  height: 44px;
}

#measure-btn {
  top: 132px;
  left: 20px;
  width: 44px;
  height: 44px;
}

/* Geolocation pulsing marker on map */
.user-location-marker {
  background-color: var(--accent);
  border: 3px solid #ffffff;
  border-radius: 50%;
  width: 14px !important;
  height: 14px !important;
  box-shadow: 0 0 0 8px var(--accent-glow);
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(56, 189, 248, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(56, 189, 248, 0);
  }
}

/* Favorites star button */
.favorite-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--text-muted);
  padding: 0 8px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.favorite-btn:hover {
  color: #fbbf24;
  transform: scale(1.15);
}

.favorite-btn.active {
  color: #fbbf24;
  text-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

/* Smooth transition for collapsible sidebar */
.sidebar {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  transform: translateX(-100%);
  border-right: none;
}

.sidebar.collapsed *,
.sidebar.collapsed .sidebar-content,
.sidebar.collapsed .owners-list {
  overflow: hidden !important;
}

/* Stats Footer Button */
.stats-footer-btn {
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.stats-footer-btn:hover {
  background: rgba(56, 189, 248, 0.25);
  border-color: var(--accent);
  color: #ffffff;
}

/* Address Clean Link in Right Panels */
.address-clean-link {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s ease;
}

.address-clean-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Shift map toggle button when sidebar is collapsed */
.sidebar.collapsed ~ .map-container #sidebar-toggle {
  left: 20px;
}

/* Mobile Responsiveness Styles */
@media (max-width: 768px) {
  .app-container {
    position: relative;
    overflow: hidden;
  }
  
  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 85% !important;
    max-width: 380px;
    z-index: 1010;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.5);
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
    width: 85% !important;
  }

  /* Shift overlay buttons when sidebar is open on mobile */
  .sidebar:not(.collapsed) ~ .map-container #sidebar-toggle,
  .sidebar:not(.collapsed) ~ .map-container #locate-btn,
  .sidebar:not(.collapsed) ~ .map-container #measure-btn {
    left: calc(85% + 15px);
  }

  @media (max-width: 440px) {
    .sidebar:not(.collapsed) ~ .map-container #sidebar-toggle,
    .sidebar:not(.collapsed) ~ .map-container #locate-btn,
    .sidebar:not(.collapsed) ~ .map-container #measure-btn {
      left: calc(380px + 15px);
    }
  }

  /* Optimize layout for smaller screens */
  .tab-btn {
    padding: 8px 6px;
    font-size: 0.8rem;
    gap: 4px;
  }
  
  .tab-nav {
    padding: 8px 10px;
  }

  .map-overlay-btn {
    width: 40px;
    height: 40px;
  }
  
  #locate-btn {
    top: 72px;
  }

  #measure-btn {
    top: 124px;
  }

  .owner-detail-panel {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 85% !important;
    max-width: 380px;
    z-index: 1020;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.5);
  }
}

/* Right-side Owner Detail Panel */
.owner-detail-panel {
  width: 380px;
  min-width: 340px;
  background-color: var(--bg-sidebar);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 1005;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease;
  overflow-y: auto;
  padding: 20px;
}

.owner-detail-panel.collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  transform: translateX(100%);
  border-left: none;
}

.panel-close-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.panel-close-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
}

.pin-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: var(--accent);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.pin-btn:hover {
  background: rgba(56, 189, 248, 0.2);
  border-color: var(--accent);
}

.pin-btn.active {
  background: #0284c7;
  color: #ffffff;
  border-color: #0284c7;
}

/* ==========================================
   MOBILE-FIRST BOTTOM SHEET & NAVIGATION (< 768px)
   (Desktop layout remains 100% unchanged)
   ========================================== */
.mobile-nav {
  display: none;
}

@media (max-width: 767px) {
  /* Mobile Navigation Bar */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    z-index: 2000;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(16px);
    padding: 0 8px;
  }

  .mobile-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: #cbd5e1 !important; /* High contrast light slate grey */
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 72px;
  }

  .mobile-nav-btn.active {
    color: #38bdf8 !important;
    background: rgba(56, 189, 248, 0.18) !important;
    font-weight: 700;
  }

  .mnav-icon {
    font-size: 1.3rem;
    line-height: 1.1;
    margin-bottom: 2px;
  }

  /* Shift map overlay buttons and Leaflet zoom controls on mobile */
  .leaflet-bottom.leaflet-right {
    bottom: 74px !important;
  }

  .map-overlay-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  }

  #sidebar-toggle {
    display: none !important; /* Managed via mobile nav bar */
  }

  #locate-btn {
    position: fixed !important;
    top: 16px !important;
    right: 16px !important;
    left: auto !important;
    z-index: 1200 !important;
  }

  #measure-btn {
    position: fixed !important;
    top: 68px !important;
    right: 16px !important;
    left: auto !important;
    z-index: 1200 !important;
  }

  /* Sidebar Drawer on Mobile */
  .sidebar {
    position: fixed;
    bottom: 64px;
    left: 0;
    right: 0;
    top: auto;
    width: 100% !important;
    min-width: 100% !important;
    height: 72vh;
    max-height: 80vh;
    z-index: 1500;
    border-radius: 20px 20px 0 0;
    border-right: none;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
    transform: translateY(120%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    background-color: var(--bg-sidebar);
  }

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

  .sidebar::before {
    content: "";
    width: 40px;
    height: 4px;
    background: var(--text-muted);
    border-radius: 2px;
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0.4;
  }

  .sidebar-header {
    padding-top: 18px;
  }

  /* Right-side Owner Detail Panel as Bottom Sheet on Mobile */
  .owner-detail-panel {
    position: fixed;
    bottom: 64px;
    left: 0;
    right: 0;
    top: auto;
    width: 100% !important;
    min-width: 100% !important;
    height: 65vh;
    max-height: 75vh;
    z-index: 1600;
    border-radius: 20px 20px 0 0;
    border-left: none;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.6);
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), height 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    background-color: var(--bg-sidebar);
    padding: 16px;
  }

  .owner-detail-panel.collapsed {
    transform: translateY(120%);
    width: 100% !important;
    padding: 16px;
  }

  .owner-detail-panel.minimized {
    height: 72px !important;
    min-height: 72px !important;
    max-height: 72px !important;
    overflow: hidden !important;
    transform: translateY(0) !important;
    cursor: pointer;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
  }

  .owner-detail-panel::before {
    content: "";
    width: 40px;
    height: 4px;
    background: var(--accent);
    border-radius: 2px;
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0.7;
  }

  .panel-close-btn,
  .panel-minimize-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 1.1rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
    height: 40px;
    border-radius: 10px;
    font-size: 1.1rem;
  }
}

.color-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

/* Distance Measurement Tool Styles */
#measure-btn {
  top: 124px;
}

#measure-btn.active {
  background: var(--accent);
  color: #0f172a;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.6);
  border-color: #38bdf8;
}

.measure-box {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  min-width: 260px;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
}

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

.measure-btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.measure-btn-icon:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

.measure-result {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 10px;
}

.measure-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.measure-action-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.measure-action-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
}

.measure-tooltip {
  background: var(--bg-card) !important;
  border: 1px solid var(--accent) !important;
  color: var(--accent) !important;
  font-weight: 600 !important;
  font-size: 0.75rem !important;
  border-radius: 6px !important;
  padding: 2px 6px !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}


