:root {
  --bg: #0e1116;
  --panel: #151a22;
  --panel-2: #1b2230;
  --text: #e8edf2;
  --muted: #9aa6b2;
  --accent: #6ea8fe;
  --accent-2: #5dd39e;
  --danger: #ff6b6b;
  --border: #283040;
  --header-height: 56px;
  --footer-height: 48px;
  --safe-area-inset-top: env(safe-area-inset-top);
  --safe-area-inset-bottom: env(safe-area-inset-bottom);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  height: 100vh;
  height: calc(100vh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  padding-top: var(--safe-area-inset-top);
  padding-bottom: var(--safe-area-inset-bottom);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  touch-action: manipulation;
}

/* Header */
.app-header {
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: linear-gradient(180deg, #101521, #0e1116);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 1000;
  flex-wrap: wrap;
  gap: 8px;
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.3px;
  color: var(--text);
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-width: 0;
}

.header-btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  touch-action: manipulation;
  transition: all 0.2s;
}

.header-btn:hover {
  background: var(--panel);
}

.header-btn:active {
  transform: scale(0.95);
}


/* Desktop Controls */
.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  flex: 1;
  justify-content: flex-end;
}

.controls.collapsed {
  display: none;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.control-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.control select, .control input {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  min-height: 44px;
  min-width: 120px;
  touch-action: manipulation;
}

.control input {
  width: 100%;
  max-width: 240px;
}

button {
  background: var(--accent);
  color: #071018;
  border: 0;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
  white-space: nowrap;
  transition: all 0.2s;
  box-sizing: border-box;
}

/* Responsive button sizing for smaller windows */
@media (max-width: 1024px) {
  button {
    padding: 8px 14px;
    font-size: 13px;
    min-height: 40px;
    min-width: 40px;
    border-radius: 7px;
  }
}

@media (max-width: 768px) {
  button {
    padding: 7px 12px;
    font-size: 12px;
    min-height: 38px;
    min-width: 38px;
    border-radius: 6px;
  }
}

@media (max-width: 480px) {
  button {
    padding: 6px 10px;
    font-size: 11px;
    min-height: 36px;
    min-width: 36px;
    border-radius: 5px;
  }
}

button:hover {
  filter: brightness(1.05);
}

button:active {
  filter: brightness(0.95);
}

button:disabled {
  opacity: .6;
  cursor: not-allowed;
}

/* Main Layout */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 360px;
  overflow: hidden;
  min-height: 0;
  padding-bottom: 0;
}

.map-panel {
  position: relative;
  overflow: hidden;
  z-index: 1;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: pan-x pan-y pinch-zoom;
}

/* Desktop Side Panel */
.side-panel {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  border-left: 1px solid var(--border);
  background: var(--panel);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
  position: relative;
  z-index: 100;
}

.panel-section {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  flex-shrink: 0;
}

.panel-section.small {
  font-size: 12px;
  color: var(--muted);
}

.panel-section h3 {
  margin: 0 0 10px 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.summary {
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
}

.hint {
  color: var(--muted);
  font-size: 11px;
  margin-top: 6px;
  line-height: 1.4;
}

.stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #121826;
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  min-height: 44px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  flex: 1;
}

.stat-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent-2);
  text-align: right;
  min-width: 40px;
}

.note {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.geocode-remaining-container {
  margin-top: 8px;
  margin-bottom: 8px;
}

/* Responsive geocode container */
@media (max-width: 480px) {
  .geocode-remaining-container {
    margin-top: 6px;
    margin-bottom: 6px;
  }
}

@media (max-width: 360px) {
  .geocode-remaining-container {
    margin-top: 5px;
    margin-bottom: 5px;
  }
}

.manual-add-btn {
    width: 100%;
    padding: 8px 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-sizing: border-box;
    min-height: 36px;
}

/* Responsive manual add button */
@media (max-width: 480px) {
  .manual-add-btn {
    padding: 6px 10px;
    font-size: 0.85em;
    min-height: 32px;
    border-radius: 6px;
  }
}

@media (max-width: 360px) {
  .manual-add-btn {
    padding: 5px 8px;
    font-size: 0.8em;
    min-height: 28px;
    border-radius: 5px;
  }
}

.manual-add-btn:hover {
    background: #5a9dfe;
    transform: translateY(-1px);
}

.manual-add-btn.active {
    background: var(--accent-2);
    box-shadow: 0 0 0 3px rgba(93, 211, 158, 0.3);
}

.manual-add-status {
    font-size: 0.85em;
    color: var(--accent-2);
    text-align: center;
}

/* Responsive manual add container spacing */
@media (max-width: 480px) {
  .manual-add-container {
    margin-top: 8px !important;
  }
}

@media (max-width: 360px) {
  .manual-add-container {
    margin-top: 6px !important;
  }
}

.geocode-remaining-btn {
  width: 100%;
  font-size: 12px;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background-color 0.2s, opacity 0.2s;
  box-sizing: border-box;
  min-height: 40px;
}

/* Responsive geocode button */
@media (max-width: 480px) {
  .geocode-remaining-btn {
    font-size: 11px;
    padding: 8px 12px;
    min-height: 36px;
    border-radius: 6px;
  }
}

@media (max-width: 360px) {
  .geocode-remaining-btn {
    font-size: 10px;
    padding: 6px 10px;
    min-height: 32px;
    border-radius: 5px;
  }
}

.geocode-remaining-btn:hover:not(:disabled) {
  background: var(--accent-2);
}

.geocode-remaining-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.geocode-progress {
  margin-top: 8px;
  font-size: 11px;
  color: var(--accent-2);
  line-height: 1.4;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.geocode-warning {
  animation: pulse 2s ease-in-out infinite;
}

.geocode-disclaimer {
  position: fixed;
  bottom: var(--footer-height);
  left: 0;
  right: 0;
  z-index: 999;
  padding: 2px 8px;
  font-size: 9px;
  line-height: 1.3;
  color: var(--muted);
  text-align: center;
  background: rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.8;
  }
}

.utilities-overlay-details {
  margin: 0;
}

.utilities-overlay-summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
  padding: 4px 0;
  margin-bottom: 8px;
}

.utilities-overlay-summary::-webkit-details-marker {
  display: none;
}

.utilities-overlay-summary::before {
  content: '▶';
  display: inline-block;
  margin-right: 6px;
  transition: transform 0.2s;
  font-size: 10px;
  color: var(--muted);
}

.utilities-overlay-details[open] .utilities-overlay-summary::before {
  transform: rotate(90deg);
}

.utilities-disclaimer {
  margin-bottom: 8px;
  padding: 6px 8px;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  border-radius: 6px;
}

.utilities-disclaimer.mobile {
  margin-top: 8px;
  margin-bottom: 8px;
}

.utilities-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.utilities-controls.mobile {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  max-width: 100%;
  box-sizing: border-box;
}

/* Ensure utilities overlay doesn't break scrolling on mobile */
@media (max-width: 768px) {
  .utilities-overlay-details.mobile {
    max-width: 100%;
    box-sizing: border-box;
  }
  
  .utilities-controls.mobile {
    padding: 10px;
    gap: 6px;
  }
  
  .utility-checkbox.mobile {
    padding: 8px;
    min-height: 40px;
    flex-shrink: 0;
  }
}

.utility-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.utility-checkbox:hover {
  background: var(--panel);
  border-color: var(--accent);
}

.utility-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.utility-checkbox span {
  font-size: 13px;
  color: var(--text);
  flex: 1;
}

.utility-checkbox.mobile {
  padding: 10px;
  min-height: 44px;
}

.utility-checkbox.mobile span {
  font-size: 14px;
}

@media (max-width: 480px) {
  .utility-checkbox {
    padding: 6px;
    min-height: 40px;
  }
  
  .utility-checkbox span {
    font-size: 12px;
  }
  
  .utility-checkbox.mobile {
    padding: 8px;
    min-height: 40px;
  }
  
  .utility-checkbox.mobile span {
    font-size: 13px;
  }
}

.export-buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.export-buttons button {
  width: 100%;
  font-size: 13px;
}

/* Responsive export buttons */
@media (max-width: 768px) {
  .export-buttons {
    gap: 8px;
  }
  
  .export-buttons button {
    font-size: 12px;
    padding: 8px 12px;
  }
}

@media (max-width: 480px) {
  .export-buttons {
    gap: 6px;
  }
  
  .export-buttons button {
    font-size: 11px;
    padding: 7px 10px;
  }
}

/* Mobile Settings Panel */
.settings-panel {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: var(--footer-height);
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: none;
  animation: fadeIn 0.2s;
}

.settings-panel.show {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.settings-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.settings-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.close-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  touch-action: manipulation;
}

.close-btn:active {
  background: var(--panel-2);
}

.settings-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-group label {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

.mobile-select,
.mobile-input {
  width: 100%;
  min-height: 52px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 16px;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}

.mobile-select:focus,
.mobile-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(110, 168, 254, 0.1);
}

.mobile-btn {
  min-height: 52px;
  background: var(--accent);
  color: #071018;
  border: 0;
  border-radius: 12px;
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s;
  width: 100%;
  box-sizing: border-box;
}

/* Responsive button sizing - scale down on smaller screens */
@media (max-width: 480px) {
  .mobile-btn {
    min-height: 44px;
    padding: 10px 18px;
    font-size: 14px;
    border-radius: 10px;
  }
}

@media (max-width: 360px) {
  .mobile-btn {
    min-height: 40px;
    padding: 8px 16px;
    font-size: 13px;
    border-radius: 8px;
  }
}

.mobile-btn:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.mobile-btn.danger {
  background: var(--danger);
  color: white;
}

.mobile-btn.full-width {
  width: 100%;
  box-sizing: border-box;
  margin-top: 8px;
}

/* Responsive full-width buttons */
@media (max-width: 480px) {
  .mobile-btn.full-width {
    margin-top: 6px;
  }
}

@media (max-width: 360px) {
  .mobile-btn.full-width {
    margin-top: 5px;
  }
}

/* Ensure export button is always accessible */
#exportCsvBtnMobile {
  margin-top: 12px;
  margin-bottom: 0;
  position: relative;
  z-index: 1;
}

/* Responsive export button */
@media (max-width: 480px) {
  #exportCsvBtnMobile {
    margin-top: 10px;
  }
}

@media (max-width: 360px) {
  #exportCsvBtnMobile {
    margin-top: 8px;
  }
}

/* Mobile Results Card */
.results-card {
  position: fixed;
  bottom: var(--footer-height);
  left: 0;
  right: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  z-index: 1100;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
  max-height: calc(85vh - var(--footer-height) - var(--safe-area-inset-bottom));
  height: calc(85vh - var(--footer-height) - var(--safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  transform: translateY(calc(100% - 60px));
  transition: transform 0.3s ease-out;
  box-sizing: border-box;
  overflow: hidden;
}

.results-card.expanded {
  transform: translateY(0);
  z-index: 1100;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  min-height: 60px;
  touch-action: manipulation;
  cursor: pointer;
  flex-shrink: 0;
  box-sizing: border-box;
}

/* Responsive card header */
@media (max-width: 480px) {
  .card-header {
    padding: 12px 16px;
    min-height: 52px;
  }
}

@media (max-width: 360px) {
  .card-header {
    padding: 10px 14px;
    min-height: 48px;
  }
}

.card-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

/* Responsive card header title */
@media (max-width: 480px) {
  .card-header h3 {
    font-size: 16px;
  }
}

@media (max-width: 360px) {
  .card-header h3 {
    font-size: 15px;
  }
}

.toggle-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  touch-action: manipulation;
  transition: transform 0.3s;
  box-sizing: border-box;
}

/* Responsive toggle button */
@media (max-width: 480px) {
  .toggle-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    font-size: 18px;
    border-radius: 8px;
  }
}

@media (max-width: 360px) {
  .toggle-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    font-size: 16px;
    border-radius: 7px;
  }
}

.toggle-btn.rotated {
  transform: rotate(180deg);
}

.card-body {
  padding: 20px;
  padding-bottom: calc(24px + var(--safe-area-inset-bottom, 0px)); /* Extra padding at bottom for export button + safe area */
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: none;
  flex-direction: column;
  gap: 16px;
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  box-sizing: border-box;
  overscroll-behavior: contain;
  position: relative;
}

/* Responsive card body - reduce gaps on smaller screens */
@media (max-width: 480px) {
  .card-body {
    padding: 16px;
    padding-bottom: calc(20px + var(--safe-area-inset-bottom, 0px));
    gap: 12px;
  }
}

@media (max-width: 360px) {
  .card-body {
    padding: 12px;
    padding-bottom: calc(16px + var(--safe-area-inset-bottom, 0px));
    gap: 10px;
  }
}

.results-card.expanded .card-body {
  display: flex;
}

.result-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-height: 56px;
  box-sizing: border-box;
}

/* Responsive result stat */
@media (max-width: 480px) {
  .result-stat {
    padding: 12px;
    min-height: 48px;
    border-radius: 10px;
  }
}

@media (max-width: 360px) {
  .result-stat {
    padding: 10px;
    min-height: 44px;
    border-radius: 8px;
  }
}

.result-stat .stat-label {
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
}

.result-stat .stat-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--accent-2);
}

.result-stat .stat-value.small {
  font-size: 16px;
  color: var(--text);
}

/* Responsive stat labels and values */
@media (max-width: 480px) {
  .result-stat .stat-label {
    font-size: 13px;
  }
  
  .result-stat .stat-value {
    font-size: 20px;
  }
  
  .result-stat .stat-value.small {
    font-size: 14px;
  }
}

@media (max-width: 360px) {
  .result-stat .stat-label {
    font-size: 12px;
  }
  
  .result-stat .stat-value {
    font-size: 18px;
  }
  
  .result-stat .stat-value.small {
    font-size: 13px;
  }
}

.selection-info {
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
  box-sizing: border-box;
}

/* Responsive selection info */
@media (max-width: 480px) {
  .selection-info {
    padding: 10px;
    font-size: 13px;
    border-radius: 10px;
  }
}

@media (max-width: 360px) {
  .selection-info {
    padding: 8px;
    font-size: 12px;
    border-radius: 8px;
  }
}

/* Footer */
.app-footer {
  height: var(--footer-height);
  min-height: var(--footer-height);
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  padding-bottom: calc(8px + var(--safe-area-inset-bottom, 0px));
  flex-shrink: 0;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  overflow: visible;
  width: 100%;
  box-sizing: border-box;
}

.footer-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  position: relative;
  min-width: 0;
  overflow: visible;
}

.copyright {
  font-size: 12px;
  color: var(--muted);
}

.copyright-link {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s;
}

.copyright-link:hover {
  color: var(--accent-2);
  text-decoration: underline;
}

.donation-container {
  position: relative;
  z-index: 10;
  pointer-events: auto;
  flex-shrink: 0;
  min-width: 0;
  overflow: visible;
}

.donation-btn {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  min-height: 32px;
  touch-action: manipulation;
  position: relative;
  z-index: 10;
  pointer-events: auto;
  -webkit-tap-highlight-color: rgba(110, 168, 254, 0.2);
  box-sizing: border-box;
  white-space: nowrap;
  overflow: visible;
  text-overflow: ellipsis;
  max-width: 100%;
}

.donation-emoji {
  display: inline;
}

.donation-label {
  display: inline;
}

/* Hide donation text on mobile - show only emoji */
@media (max-width: 768px) {
  .donation-label {
    display: none;
  }
  
  .donation-emoji {
    font-size: 18px;
    display: inline-block;
  }
}

.donation-btn:hover {
  background: var(--panel-2);
}

.donation-options {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  flex-direction: column;
  gap: 8px;
  min-width: 200px;
  z-index: 10000;
  box-sizing: border-box;
  pointer-events: auto;
}

.donation-options.show {
  display: flex;
}

.donation-link {
  color: var(--accent);
  text-decoration: none;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  text-align: center;
  font-size: 14px;
  touch-action: manipulation;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.donation-link:hover {
  background: var(--accent);
  color: #071018;
}

.donation-close {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 44px;
}

.donation-close:hover {
  background: var(--border);
}

/* Leaflet Overrides */
.leaflet-container {
  background: #0b0f18;
  font-family: inherit;
}

.leaflet-bar a, .leaflet-bar a:hover {
  background-color: rgba(22, 28, 41, 0.95) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-bottom: 1px solid var(--border) !important;
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  min-height: 44px !important;
  line-height: 44px !important;
  font-size: 18px !important;
  touch-action: manipulation;
  transition: all 0.2s ease !important;
  box-sizing: border-box !important;
  text-align: center !important;
}

.leaflet-bar a:hover {
  background-color: var(--panel) !important;
  border-color: var(--accent) !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

.leaflet-bar a:active {
  transform: translateY(0) !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2) !important;
}

.leaflet-control-zoom {
  margin: 16px 16px 0 16px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
}

.leaflet-control-zoom a:first-child {
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

.leaflet-control-zoom a:last-child {
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  border-bottom: 1px solid var(--border);
}

.leaflet-control-attribution {
  background: rgba(0, 0, 0, 0.6);
  color: var(--muted);
  font-size: 10px;
  padding: 4px 8px;
}

/* Draw toolbar (polygon, rectangle, etc.) – same container as zoom */
.leaflet-draw-section,
.leaflet-draw-toolbar {
  padding: 0 !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.leaflet-draw-toolbar {
  margin: 8px 0 0 16px !important;
  border-radius: 10px !important;
  overflow: hidden !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
  border: 1px solid var(--border) !important;
  background: transparent !important;
}

.leaflet-draw-toolbar a {
  background-color: rgba(22, 28, 41, 0.95) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-bottom: 1px solid var(--border) !important;
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  min-height: 44px !important;
  line-height: 44px !important;
  font-size: 18px !important;
  touch-action: manipulation !important;
  transition: all 0.2s ease !important;
  box-sizing: border-box !important;
  text-align: center !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
  text-decoration: none !important;
  float: none !important;
  background-repeat: no-repeat !important;
  background-size: 300px 30px !important;
}

/* Center sprite icons in 44px buttons (icon ~29px; offset +7px) */
.leaflet-draw-toolbar .leaflet-draw-draw-polygon { background-position: -24px -2px !important; }
.leaflet-touch .leaflet-draw-toolbar .leaflet-draw-draw-polygon { background-position: -22px -1px !important; }
.leaflet-draw-toolbar .leaflet-draw-draw-rectangle { background-position: -55px -2px !important; }
.leaflet-touch .leaflet-draw-toolbar .leaflet-draw-draw-rectangle { background-position: -53px -1px !important; }
.leaflet-draw-toolbar .leaflet-draw-edit-edit { background-position: -145px -2px !important; }
.leaflet-touch .leaflet-draw-toolbar .leaflet-draw-edit-edit { background-position: -143px -1px !important; }
.leaflet-draw-toolbar .leaflet-draw-edit-remove { background-position: -175px -2px !important; }
.leaflet-touch .leaflet-draw-toolbar .leaflet-draw-edit-remove { background-position: -173px -1px !important; }
.leaflet-draw-toolbar .leaflet-draw-edit-edit.leaflet-disabled { background-position: -205px -2px !important; }
.leaflet-touch .leaflet-draw-toolbar .leaflet-draw-edit-edit.leaflet-disabled { background-position: -203px -1px !important; }
.leaflet-draw-toolbar .leaflet-draw-edit-remove.leaflet-disabled { background-position: -235px -2px !important; }
.leaflet-touch .leaflet-draw-toolbar .leaflet-draw-edit-remove.leaflet-disabled { background-position: -233px -1px !important; }

/* Hide text/sr-only so layout is icon-only */
.leaflet-draw-toolbar a .sr-only,
.leaflet-draw-actions a .sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  border: 0 !important;
}

.leaflet-draw-toolbar a:hover {
  background-color: var(--panel) !important;
  border-color: var(--accent) !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

.leaflet-draw-toolbar a:active {
  transform: translateY(0) !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2) !important;
}

.leaflet-draw-toolbar a:first-child {
  border-top-left-radius: 10px !important;
  border-top-right-radius: 10px !important;
}

.leaflet-draw-toolbar a:last-child {
  border-bottom-left-radius: 10px !important;
  border-bottom-right-radius: 10px !important;
  border-bottom: 1px solid var(--border) !important;
}

/* Draw actions (Cancel when drawing) – absolute beside toolbar; edit actions (Edit/Delete) reuse same styles */
.leaflet-draw-actions {
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 10px !important;
  overflow: hidden !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
  border: 1px solid var(--border) !important;
  background: transparent !important;
  position: absolute !important;
  left: 52px !important;
  top: 0 !important;
  right: auto !important;
  white-space: nowrap !important;
}

.leaflet-touch .leaflet-draw-actions {
  left: 64px !important;
}

.leaflet-draw-actions li {
  display: block !important;
}

.leaflet-draw-actions a {
  background-color: rgba(22, 28, 41, 0.95) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-bottom: 1px solid var(--border) !important;
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  min-height: 44px !important;
  line-height: 44px !important;
  font-size: 18px !important;
  touch-action: manipulation !important;
  transition: all 0.2s ease !important;
  box-sizing: border-box !important;
  text-align: center !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
  text-decoration: none !important;
  white-space: nowrap !important;
  overflow: hidden !important;
}

.leaflet-draw-actions a:hover {
  background-color: var(--panel) !important;
  border-color: var(--accent) !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

.leaflet-draw-actions a:active {
  transform: translateY(0) !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2) !important;
}

.leaflet-draw-actions li:first-child a {
  border-top-left-radius: 10px !important;
  border-top-right-radius: 10px !important;
}

.leaflet-draw-actions li:last-child a {
  border-bottom-left-radius: 10px !important;
  border-bottom-right-radius: 10px !important;
  border-bottom: 1px solid var(--border) !important;
}

.leaflet-control-geocoder {
  font-size: 14px;
  margin: 16px 0 0 16px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.leaflet-control-geocoder a {
  min-width: 48px;
  min-height: 48px;
  line-height: 48px;
  background: rgba(22, 28, 41, 0.95);
  color: var(--text);
}

.leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.leaflet-popup-content {
  font-size: 14px;
  margin: 12px;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Utility Classes */
.mobile-hidden {
  display: none !important;
}

.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}


/* Responsive Breakpoints */
@media (max-width: 768px) {
  .main {
    grid-template-columns: 1fr;
    flex: 1;
    min-height: 0;
    padding-bottom: calc(var(--footer-height) + var(--safe-area-inset-bottom, 0px));
    overflow: hidden;
  }
  
  .side-panel {
    display: none;
  }
  
  .mobile-only {
    display: block;
  }
  
  .desktop-only {
    display: none;
  }
  
  .controls.desktop-only {
    display: none;
  }
  
  .app-header {
    padding: 0 16px;
    flex-wrap: wrap;
    min-height: var(--header-height);
  }
  
  .brand {
    font-size: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 0 1 auto;
    min-width: 0;
  }
  
  .results-card {
    border-radius: 20px 20px 0 0;
    max-height: calc(85vh - var(--footer-height) - var(--safe-area-inset-bottom, 0px));
    height: calc(85vh - var(--footer-height) - var(--safe-area-inset-bottom, 0px));
    overflow: hidden;
  }
  
  .card-body {
    padding-bottom: calc(28px + var(--safe-area-inset-bottom, 0px));
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .footer-content {
    flex-direction: row;
    min-width: 0;
    overflow: visible;
  }
  
  .donation-container {
    flex-shrink: 0;
    min-width: 40px;
  }
  
  .donation-btn {
    font-size: 18px;
    padding: 0;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    max-width: 40px !important;
    max-height: 40px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    box-sizing: border-box;
    overflow: visible;
    text-overflow: clip;
    pointer-events: auto !important;
    cursor: pointer !important;
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  .brand {
    flex: 1;
  }
  
  .controls.desktop-only {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    padding: 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,.3);
  }
  
  .controls.desktop-only.mobile-open {
    display: flex;
  }
  
  .control {
    width: 100%;
  }
  
  .control input {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 0 12px;
  }
  
  .brand {
    font-size: 16px;
  }
  
  .results-card {
    border-radius: 16px 16px 0 0;
    max-height: calc(90vh - var(--footer-height) - var(--safe-area-inset-bottom, 0px));
    height: calc(90vh - var(--footer-height) - var(--safe-area-inset-bottom, 0px));
  }
  
  .card-header {
    padding: 12px 16px;
    min-height: 52px;
    flex-shrink: 0;
  }
  
  .card-header h3 {
    font-size: 16px;
  }
  
  .card-body {
    padding: 16px;
    padding-bottom: calc(24px + var(--safe-area-inset-bottom, 0px));
    flex: 1 1 auto;
    min-height: 0;
  }
  
  .result-stat {
    padding: 12px;
    min-height: 52px;
  }
  
  .result-stat .stat-value {
    font-size: 20px;
  }
  
  .settings-content {
    border-radius: 16px;
  }
  
  .settings-header,
  .settings-body {
    padding: 16px;
  }
  
  .donation-btn {
    font-size: 18px;
  }
}

@media (min-width: 769px) {
  .header-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    font-size: 16px;
    border-radius: 6px;
  }
  
  .brand {
    font-size: 16px;
    letter-spacing: 0.4px;
  }
  
  .app-header {
    padding: 8px 12px;
  }
}

/* Very small screens - ensure scrolling works */
@media (max-width: 360px) {
  .results-card {
    max-height: calc(92vh - var(--footer-height) - var(--safe-area-inset-bottom, 0px));
    height: calc(92vh - var(--footer-height) - var(--safe-area-inset-bottom, 0px));
  }
  
  .card-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Tablet Optimizations */
@media (min-width: 768px) and (max-width: 1024px) {
  .main {
    grid-template-columns: 1fr 320px;
  }
  
  .results-card {
    max-height: 60vh;
  }
  
  .settings-content {
    max-width: 600px;
  }
}
