/* ===== CSS VARIABLES ===== */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #10b981;
  --accent: #f59e0b;
  --dark: #111827;
  --light: #f3f4f6;
  --gray: #6b7280;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --card-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --soft-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --header-height: 60px;
}

/* ===== RESET & BASE STYLES ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--dark);
  margin: 0;
  padding: 0;
  background: #f0f0f0;
  height: 100vh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

/* ===== HEADER STYLES ===== */
header {
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  height: var(--header-height);
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1000;
  box-shadow: var(--card-shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  flex-shrink: 0;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 600;
  display: flex;
  align-items: center;
}

header h1 svg {
  margin-right: 0.5rem;
}

.admin-link {
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  text-decoration: none;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  transition: all 0.2s ease;
}

.admin-link:hover {
  background-color: rgba(255, 255, 255, 0.3);
}

.admin-link svg {
  margin-right: 0.4rem;
}

/* ===== MAIN LAYOUT ===== */
main {
  flex: 1;
  width: 100%;
  height: calc(100vh - var(--header-height));
  margin: var(--header-height) 0 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.map-container-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

/* ===== FLOATING UI ELEMENTS ===== */
#search-container {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  z-index: 200;
  max-width: none;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: nowrap;
}

.search-bar-wrapper {
  position: relative;
  flex: 1;
  min-width: 300px;
  max-width: 400px;
}

.search-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

#controls {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: none;
  padding: 0;
  box-shadow: none;
  pointer-events: auto;
}

#search-bar {
  width: 100%;
  padding: 0.75rem 2.5rem 0.75rem 2.5rem;
  font-size: 0.9rem;
  border: none;
  border-radius: 8px;
  background-color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  transition: all 0.2s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.75rem center;
  background-size: 18px 18px;
  box-sizing: border-box;
}

#search-bar:focus {
  outline: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

#search-bar::placeholder {
  color: var(--gray);
}

.clear-search {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--gray);
  cursor: pointer;
  display: none;
  width: 18px;
  height: 18px;
  padding: 0;
}

#search-bar:not(:placeholder-shown) + .clear-search {
  display: block;
}

#search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 100%;
  max-width: 400px;
  max-height: 60vh;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  display: none;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}

/* ===== RECENT SEARCHES DROPDOWN ===== */
.recent-searches-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 100%;
  max-width: 400px;
  max-height: 50vh;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  z-index: 100;
  display: none;
  animation: slideDown 0.2s ease-out;
  box-sizing: border-box;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.recent-searches-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.1), rgba(16, 185, 129, 0.1));
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--primary-dark);
  min-height: 0;
  flex-shrink: 0;
}

.close-recent-searches {
  background: none;
  border: none;
  color: var(--gray);
  font-size: 1.2rem;
  cursor: pointer;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  padding: 0;
  transition: all 0.2s;
  flex-shrink: 0;
}

.close-recent-searches:hover {
  background-color: rgba(0, 0, 0, 0.1);
  color: var(--dark);
}

.recent-searches-content {
  max-height: 40vh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.recent-search-item {
  padding: 1rem 1.25rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 0, 0, 0.03);
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.recent-search-item:last-child {
  border-bottom: none;
}

.recent-search-item:hover {
  background-color: rgba(37, 99, 235, 0.05);
  transform: translateX(2px);
}

.recent-search-main {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex-wrap: wrap;
}

.recent-search-lot {
  font-weight: 600;
  color: var(--primary);
  font-size: 0.95rem;
  flex-shrink: 0;
}

.recent-search-map {
  font-size: 0.8rem;
  color: var(--gray);
  background: rgba(37, 99, 235, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.recent-search-details {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-width: 0;
  gap: 0.5rem;
}

.recent-search-name {
  color: var(--dark);
  font-size: 0.9rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-search-date {
  font-size: 0.8rem;
  color: var(--gray);
  flex-shrink: 0;
}

.result-category {
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.result-category:last-child {
  border-bottom: none;
}

.category-header {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.1), rgba(16, 185, 129, 0.1));
  padding: 0.75rem 1.25rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--primary-dark);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  position: sticky;
  top: 0;
  z-index: 10;
}

.result-item {
  padding: 1rem 1.25rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 0, 0, 0.03);
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.result-item:last-child {
  border-bottom: none;
}

.result-item:hover,
.result-item:focus {
  background-color: rgba(37, 99, 235, 0.05);
  transform: translateX(2px);
}

.result-main {
  font-weight: 500;
  color: var(--dark);
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-district {
  font-size: 0.8rem;
  color: var(--gray);
}

.mode-toggle,
#reset-view {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background-color: white;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  color: #3c4043;
  white-space: nowrap;
  height: 36px;
}

.mode-toggle:hover,
#reset-view:hover {
  background-color: #f8f9fa;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.mode-toggle svg,
#reset-view svg {
  width: 16px;
  height: 16px;
  margin-right: 4px;
}

.mode-toggle.click-mode {
  background-color: #1a73e8;
  color: white;
}

.mode-toggle.click-mode:hover {
  background-color: #1557b0;
}

.mode-toggle.pan-mode {
  background-color: white;
  color: #3c4043;
}

/* ===== FLOATING ZOOM CONTROLS ===== */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: white;
  border-radius: 2px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  margin-bottom: 0.75rem;
}

#controls button {
  background-color: white;
  border: none;
  color: #5f6368;
  width: 40px;
  height: 40px;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s;
  font-size: 18px;
  font-weight: 400;
  box-shadow: none;
  border-bottom: 1px solid #e8eaed;
}

#controls button:last-child {
  border-bottom: none;
}

#controls button:hover {
  background-color: #f8f9fa;
}

#controls button:active {
  background-color: #e8eaed;
  transform: none;
}

#zoom-in {
  color: #5f6368;
}

#zoom-out {
  color: #5f6368;
}


/* ===== MAP CONTAINER ===== */
#map-container {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: calc(100vh - var(--header-height));
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
  background-color: white;
  z-index: 1;
}

#zoom-pan-map {
  width: 100%;
  height: 100%;
  cursor: grab;
}

#zoom-pan-map:active {
  cursor: grabbing;
}

#zoom-pan-map svg.pan-cursor {
  cursor: grab;
}

#zoom-pan-map svg.pan-cursor:active {
  cursor: grabbing;
}

#zoom-pan-map svg.click-cursor {
  cursor: pointer;
}

.map-svg {
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ===== FLOATING INFO PANEL ===== */
#lot-info {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  max-width: 400px;
  background-color: white;
  border-radius: 12px;
  padding: 0;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  display: none;
  overflow: hidden;
  animation: slideUp 0.3s ease-out;
  z-index: 200;
  max-height: 50vh;
  overflow-y: auto;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
}

.info-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: white;
}

.info-header h3::before {
  display: none;
}

.close-info {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  padding: 0;
  transition: all 0.2s;
}

.close-info:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.district-info {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.1), rgba(16, 185, 129, 0.1));
  border-radius: 6px;
  padding: 8px 12px;
  margin: 8px 0;
  border-left: 4px solid var(--primary);
}

.multiple-results {
  padding: 1rem;
}

.result-option {
  margin: 8px 0;
  padding: 10px;
  background: rgba(0, 0, 0, 0.02);
  border-radius: 6px;
  cursor: pointer;
  border-left: 4px solid #ccc;
  transition: all 0.2s ease;
}

.result-option:hover {
  background: rgba(37, 99, 235, 0.05);
  transform: translateX(2px);
}

#lot-info table {
  width: 100%;
  border-collapse: collapse;
  padding: 1rem;
}

#lot-info td {
  padding: 0.75rem;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  font-size: 0.9rem;
}

#lot-info td:first-child {
  width: 30%;
  font-weight: 500;
  color: var(--gray);
}

#lot-info td a {
  color: var(--primary);
  text-decoration: none;
}

#lot-info td a:hover {
  text-decoration: underline;
}

/* ===== LOT STYLES ===== */
g.lot {
  transition: all 0.3s ease;
  fill: rgba(200, 230, 255, 0.5);
  stroke: rgba(37, 99, 235, 0.6);
  stroke-width: 1.5px;
  cursor: pointer;
}

g.lot:hover {
  fill: rgba(59, 130, 246, 0.5);
  stroke: var(--primary);
  stroke-width: 2.5px;
  filter: drop-shadow(0 0 5px rgba(37, 99, 235, 0.4));
}

g.lot.selected {
  fill: rgba(245, 158, 11, 0.5);
  stroke: var(--accent);
  stroke-width: 3px;
  filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.5));
}

/* Generated lot styles */
g.generated-lot {
  cursor: pointer;
}

g.generated-lot:hover path.st8 {
  fill: rgba(59, 130, 246, 0.3);
  stroke: #2563eb;
  stroke-width: 2px;
}

g.generated-lot.selected path.st8 {
  fill: rgba(245, 158, 11, 0.5);
  stroke: #f59e0b;
  stroke-width: 3px;
}

path.st8 {
  pointer-events: all;
}

/* Lot Labels */
.lot-label {
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 12px;
  font-weight: 600;
  fill: var(--dark);
  pointer-events: none;
  transition: all 0.2s ease;
}

.lot-label.highlight {
  font-size: 14px;
  font-weight: 700;
  fill: var(--primary-dark);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

/* ===== LOADING STATES ===== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: all 0.5s ease;
}

.loading-overlay.fade-out {
  opacity: 0;
}

.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.loader svg {
  width: 60px;
  height: 60px;
  color: var(--primary);
  animation: rotate 2s linear infinite;
}

.loader div {
  font-size: 1.2rem;
  color: var(--primary-dark);
  font-weight: 500;
}

@keyframes rotate {
  100% {
    transform: rotate(360deg);
  }
}

/* ===== UTILITY CLASSES ===== */
.map-pin {
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.lot-tooltip {
  font-size: 10px;
  padding: 2px 4px;
}

.hint-category {
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

.search-hints {
  padding: 1rem;
}

.hint-examples {
  font-size: 0.9rem;
}

/* ===== MOBILE RESPONSIVE STYLES ===== */
@media (max-width: 768px) {
  :root {
    --header-height: 45px;
  }

  html {
    overflow: hidden;
  }

  body {
    font-size: 14px;
    height: 100vh;
    min-height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    position: fixed;
    width: 100%;
  }

  main {
    padding: 0;
    margin: 0;
    height: calc(100vh - var(--header-height));
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
  }

  header {
    height: 45px;
    padding: 0 0.75rem;
  }

  header h1 {
    font-size: 0.9rem;
  }

  .admin-link {
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
  }

  .map-container-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
    flex: 1;
    overflow: hidden;
  }

  #map-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border-radius: 0;
  }

  #search-container {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    right: 0.5rem;
    max-width: calc(100vw - 1rem);
    flex-direction: column;
    gap: 0.5rem;
  }

  .search-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .search-bar-wrapper {
    min-width: auto;
    max-width: none;
  }

  .search-controls {
    justify-content: center;
    gap: 0.5rem;
  }

  .mode-toggle,
  #reset-view {
    padding: 6px 12px;
    font-size: 12px;
    height: 32px;
  }

  .mode-toggle svg,
  #reset-view svg {
    width: 14px;
    height: 14px;
  }

  #search-bar {
    padding: 0.5rem 1.75rem 0.5rem 1.75rem;
    font-size: 0.8rem;
    border-radius: 6px;
    background-position: 0.5rem center;
    background-size: 16px 16px;
  }

  .clear-search {
    right: 0.5rem;
    width: 16px;
    height: 16px;
  }

  #controls {
    position: absolute;
    bottom: 1rem;
    right: 0.5rem;
    flex-direction: column;
    gap: 0;
    padding: 0;
    background: none;
    box-shadow: none;
  }

  .control-group {
    flex-direction: column;
    gap: 0;
    margin-right: 0;
    padding-right: 0;
    border-right: none;
    width: auto;
    background: white;
    border-radius: 2px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    margin-bottom: 0.5rem;
  }

  #controls button {
    width: 36px;
    height: 36px;
    font-size: 16px;
    border-radius: 0;
    box-shadow: none;
    border-bottom: 1px solid #e8eaed;
  }

  #controls button:last-child {
    border-bottom: none;
  }
}

@media (max-width: 480px) {
  .mode-toggle,
  #reset-view {
    padding: 4px 8px;
    font-size: 11px;
    height: 28px;
  }

  .mode-toggle svg,
  #reset-view svg {
    width: 12px;
    height: 12px;
  }
}
