/*================================
  Reset & Base Styles
  ================================*/

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

html, body {
  height: 100%;
  overflow: hidden;
}

/*================================
  Custom Properties
  ================================*/

:root {
  /* Green Party Brand Colors */
  --green-primary: #098137;
  --green-dark: #076329;
  --green-light: #0ba848;
  --green-pale: #e8f5e9;
  
  /* UI Colors */
  --white: #ffffff;
  --black: #000000;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  
  /* Status Colors */
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #991b1b;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  
  /* Spacing */
  --spacing-xs: 0.5rem;
  --spacing-sm: 0.75rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;
  
  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  
  /* Borders */
  --border-radius-sm: 0.25rem;
  --border-radius-md: 0.375rem;
  --border-radius-lg: 0.5rem;
  --border-radius-xl: 0.75rem;
  
  /* Z-index layers */
  --z-map: 1;
  --z-sidebar: 10;
  --z-header: 20;
  --z-footer: 5;
}

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: 1.5;
  color: var(--gray-900);
  background-color: var(--gray-100);
}

/* Visually hidden but accessible to screen readers */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/*================================
  Header
  ================================ */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, var(--green-primary) 0%, var(--green-dark) 100%);
  color: var(--white);
  padding: var(--spacing-sm) var(--spacing-lg);
  box-shadow: var(--shadow-md);
  z-index: var(--z-header);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
}

.site-title {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  margin-bottom: var(--spacing-xs);
  line-height: 1.2;
}

.site-subtitle {
  font-size: var(--font-size-sm);
  font-weight: 400;
  opacity: 0.95;
  margin: 0;
}

/*================================
  Main Container & Map
  ================================ */

.main-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  padding-top: 82px; /* Header height */
}

#map {
  position: absolute;
  top: 82px;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: calc(100vh - (82px + 45px)); /* Header + Footer height */
  z-index: var(--z-map);
}

/*================================
  Sidebar
  ================================ */

.sidebar {
  position: fixed;
  top: 82px;
  left: 0;
  width: 400px;
  max-width: 100%;
  height: calc(100vh - (82px + 45px)); /* Header + Footer height */
  background: var(--white);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-sidebar);
  overflow-y: auto;
  padding: var(--spacing-lg);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xl);
}

/*================================
  Sidebar Sections
  ================================ */

.instructions-section,
.search-section,
.results-section {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.sidebar h2 {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--green-primary);
  margin: 0;
}

.sidebar h3 {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--gray-800);
  margin: 0;
}

.instructions-section p,
.empty-state p {
  color: var(--gray-600);
  line-height: 1.6;
  margin: 0;
}

/*================================
  Search Box
  ================================ */

.search-container {
  position: relative;
}

#address1 {
  width: 100%;
  padding: var(--spacing-md);
  font-size: var(--font-size-base);
  font-family: var(--font-sans);
  border: 2px solid var(--gray-300);
  border-radius: var(--border-radius-lg);
  outline: none;
  transition: all 0.2s ease;
  background-color: var(--white);
}

#address1:hover {
  border-color: var(--gray-400);
}

#address1:focus {
  border-color: var(--green-primary);
  box-shadow: 0 0 0 3px rgba(9, 129, 55, 0.1);
}

#address1::placeholder {
  color: var(--gray-400);
}

/* Ensure Addy autocomplete dropdown has proper styling */
.addy-autocomplete-menu {
  border: 1px solid var(--gray-300);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  margin-top: var(--spacing-xs);
  max-height: 300px;
  overflow-y: auto;
}

/*================================
  Results Display
  ================================ */

.results-section {
  flex: 1;
  min-height: 200px;
}

.loading-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-xl) 0;
  color: var(--gray-600);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--green-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  padding: var(--spacing-xl);
  background-color: var(--gray-50);
  border-radius: var(--border-radius-lg);
  border: 2px dashed var(--gray-300);
  text-align: center;
}

.results-content {
  background-color: var(--green-pale);
  border-radius: var(--border-radius-lg);
  padding: var(--spacing-lg);
  border: 2px solid var(--green-light);
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  margin: 0;
}

.result-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  border-bottom: 1px solid rgba(9, 129, 55, 0.2);
}

.result-item:last-child {
  border-bottom: none;
}

.result-item dt {
  font-weight: 600;
  color: var(--green-dark);
  font-size: var(--font-size-sm);
}

.result-item dd {
  /* font-weight: 700; */
  color: var(--gray-900);
  font-size: var(--font-size-sm);
  margin: 0;
}

.debug-info {
  opacity: 0.6;
  font-size: var(--font-size-sm);
}

/* Error State */
.error-state {
  padding: var(--spacing-lg);
  background-color: var(--error-bg);
  border: 2px solid var(--error-border);
  border-radius: var(--border-radius-lg);
}

.error-message {
  color: var(--error-text);
  font-weight: 500;
  margin: 0;
}

/*================================
  Footer
  ================================ */

.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: var(--gray-900);
  color: var(--white);
  padding: var(--spacing-sm) var(--spacing-lg);
  z-index: var(--z-footer);
  font-size: var(--font-size-sm);
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
}

.footer-content p {
  margin: 0;
}

.footer-links a {
  color: var(--green-light);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-links a:hover {
  color: var(--white);
  text-decoration: underline;
}

/*================================
  Responsive Design
  ================================ */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
  .sidebar {
    width: 360px;
  }
}

/* Mobile (<768px) */
@media (max-width: 767px) {
  :root {
    --spacing-lg: 1rem;
    --spacing-xl: 1.5rem;
  }
  
  .site-header {
    padding: var(--spacing-sm) var(--spacing-md);
  }
  
  .site-title {
    font-size: var(--font-size-xl);
  }
  
  .site-subtitle {
    font-size: var(--font-size-sm);
  }
  
  .main-container {
    padding-top: 72px;
  }
  
  #map {
    top: 72px;
    height: calc(100vh - 72px);
  }
  
  .sidebar {
    top: auto;
    bottom: 40px; /* Footer height */
    right: 0;
    left: 0;
    width: 100%;
    height: auto;
    max-height: 50vh;
    border-radius: var(--border-radius-xl) var(--border-radius-xl) 0 0;
    padding: var(--spacing-md);
  }
  
  .sidebar h2 {
    font-size: var(--font-size-lg);
  }
  
  .sidebar h3 {
    font-size: var(--font-size-base);
  }
  
  .result-item {
    grid-template-columns: 120px 1fr;
    gap: var(--spacing-xs);
  }
  
  .result-item dt {
    font-size: 0.8rem;
  }
  
  .result-item dd {
    font-size: var(--font-size-sm);
  }
  
  .footer-content {
    flex-direction: column;
    text-align: center;
    gap: var(--spacing-xs);
  }
}

/* Small Mobile (<480px) */
@media (max-width: 479px) {
  .sidebar {
    max-height: 60vh;
  }
  
  #address1 {
    padding: var(--spacing-sm);
    font-size: var(--font-size-sm);
  }
  
  .result-item {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
  
  .instructions-section {
    display: none; /* Hide on very small screens to save space */
  }
}

/*================================
  Accessibility & Interactions
  ================================ */

/* Ensure all interactive elements have proper touch targets on mobile */
@media (max-width: 767px) {
  button,
  a,
  input {
    min-height: 44px;
  }
}

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 3px solid var(--green-primary);
  outline-offset: 2px;
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

[hidden] {
  display: none !important;
}

/*================================
  Addy Autocomplete Overrides
  ================================ */
.ui-autocomplete {
  border: 1px solid var(--gray-300);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  margin-top: var(--spacing-xs);
  max-height: 300px;
  overflow-y: auto;
  z-index: 1000;
  width: 350px;
  background: var(--white);
  font-size: 12px; /* Might as well match the super-hardcoded size lol */
}

.ui-menu-item {
  padding: 4px var(--spacing-sm);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.ui-state-focus {
  background-color: var(--green-light) !important;
  color: var(--white) !important;
}