/* ===================================================================
   Google Fonts
   =================================================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=IBM+Plex+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap');

/* ===================================================================
   Reset & base
   =================================================================== */

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

:root {
  /* Status colors */
  --color-banned:         #C8102E;
  --color-banned-bg:      #FFF0F2;
  --color-special:        #A85C00;
  --color-special-bg:     #FFF8ED;
  --color-conditional:    #1A4ED8;
  --color-conditional-bg: #EEF4FF;
  --color-permitted:      #156F34;
  --color-permitted-bg:   #F0FDF5;

  /* Layout palette — warm newsprint */
  --color-text:           #181412;
  --color-text-muted:     #6B6460;
  --color-text-faint:     #A09890;
  --color-border:         #E0DBD3;
  --color-border-strong:  #C4BDB4;
  --color-bg:             #F4F1EB;
  --color-panel-bg:       #FFFFFF;
  --color-panel-alt:      #F8F6F2;
  --color-header-bg:      #0C1118;
  --color-header-text:    #EBE6DC;
  --color-accent:         #C8102E;
  --color-accent-dark:    #9E0C23;

  /* Typography */
  --font-display: 'DM Serif Display', Georgia, 'Times New Roman', serif;
  --font-body:    'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:    ui-monospace, 'SFMono-Regular', Menlo, monospace;

  /* Layout */
  --panel-width:  380px;
  --radius:       5px;
  --radius-lg:    10px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:    0 4px 14px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===================================================================
   Accessibility
   =================================================================== */

.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;
}

/* ===================================================================
   Noscript banner
   =================================================================== */

.noscript-banner {
  background: #FEF3C7;
  border-bottom: 2px solid #F59E0B;
  padding: 0.75rem 1.25rem;
  text-align: center;
  font-size: 0.9375rem;
}

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

.site-header {
  background: var(--color-header-bg);
  color: var(--color-header-text);
  padding: 1.125rem 1.5rem 1.25rem;
  flex-shrink: 0;
  z-index: 10;
  border-bottom: 3px solid var(--color-accent);
  position: relative;
}

/* Subtle Chicago-flag-inspired star accent */
.site-header::after {
  content: '\2736';
  position: absolute;
  right: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.375rem;
  color: var(--color-accent);
  opacity: 0.35;
  pointer-events: none;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
}

.site-title {
  font-family: var(--font-display);
  font-size: 1.875rem;
  font-weight: 400;
  letter-spacing: -0.015em;
  margin-bottom: 0.2rem;
  line-height: 1.15;
  color: #FFFFFF;
}

.site-subtitle {
  font-size: 0.875rem;
  color: #7A8EA0;
  margin-bottom: 0.9375rem;
  font-weight: 400;
  line-height: 1.45;
}

/* ===================================================================
   Address form
   =================================================================== */

.address-form {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  max-width: 580px;
}

.address-input {
  flex: 1;
  padding: 0.6875rem 1rem;
  font-size: 0.9375rem;
  font-family: var(--font-body);
  border: 1.5px solid #253040;
  border-radius: var(--radius);
  background: #131C27;
  color: #EBE6DC;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.address-input::placeholder {
  color: #465870;
}

.address-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.18);
}

.search-button {
  padding: 0.6875rem 1.375rem;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: var(--font-body);
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: 0.01em;
  transition: background 0.15s, transform 0.1s;
}

.search-button:hover,
.search-button:focus-visible {
  background: var(--color-accent-dark);
  outline: none;
}

.search-button:active {
  transform: translateY(1px);
}

.address-error {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: #FCA5A5;
  font-weight: 500;
}

/* ===================================================================
   Loading / error banners
   =================================================================== */

.loading-banner {
  background: #EFF6FF;
  color: #1E3A8A;
  padding: 0.5rem 1.25rem;
  font-size: 0.875rem;
  text-align: center;
  border-bottom: 1px solid #BFDBFE;
}

.data-error-banner {
  background: #FEF2F2;
  color: #991B1B;
  padding: 0.5rem 1.25rem;
  font-size: 0.875rem;
  text-align: center;
  border-bottom: 1px solid #FECACA;
}

/* ===================================================================
   App layout
   =================================================================== */

.app-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ===================================================================
   Side panel wrapper (collapsible)
   =================================================================== */

.side-panel {
  width: var(--panel-width);
  min-width: var(--panel-width);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              min-width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.side-panel.is-collapsed {
  width: 0;
  min-width: 0;
}

/* ===================================================================
   Panel collapse toggle button
   =================================================================== */

.panel-toggle {
  /* In flex row: sits naturally between side-panel and map */
  align-self: center;
  flex-shrink: 0;
  width: 14px;
  height: 52px;
  padding: 0;
  background: var(--color-panel-bg);
  border: 1px solid var(--color-border);
  border-left: none;
  border-radius: 0 5px 5px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  box-shadow: 2px 1px 6px rgba(0, 0, 0, 0.08);
  z-index: 20;
  transition: background 0.15s, color 0.15s;
}

.panel-toggle:hover,
.panel-toggle:focus-visible {
  background: var(--color-panel-alt);
  color: var(--color-text);
  outline: none;
}

.panel-toggle__icon {
  flex-shrink: 0;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.panel-toggle.is-collapsed .panel-toggle__icon {
  transform: rotate(180deg);
}

/* Mobile: full-width horizontal bar between panel and map */
@media (max-width: 768px) {
  .panel-toggle {
    align-self: auto;
    width: 100%;
    height: 32px;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    box-shadow: none;
    background: var(--color-panel-alt);
  }

  .panel-toggle__icon {
    transform: rotate(-90deg); /* chevron points down = "collapse up" */
  }

  .panel-toggle.is-collapsed .panel-toggle__icon {
    transform: rotate(90deg); /* chevron points up = "expand down" */
  }
}

/* ===================================================================
   Intro panel (shown before any lookup)
   =================================================================== */

.intro-panel {
  width: var(--panel-width);
  min-width: var(--panel-width);
  background: var(--color-panel-bg);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.intro-body {
  padding: 1.625rem 1.5rem 1.75rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.intro-heading {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-text-faint);
  margin-bottom: 0.875rem;
}

.intro-text {
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--color-text);
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

/* Stats */
.intro-stats {
  list-style: none;
  display: flex;
  flex-direction: column;
  margin-top: 0.125rem;
}

.intro-stat {
  display: flex;
  align-items: flex-start;
  gap: 1.125rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--color-border);
}

.intro-stat:last-child {
  border-bottom: none;
  padding-bottom: 0.5rem;
}

.intro-stat__number {
  font-family: var(--font-display);
  font-size: 2.375rem;
  font-weight: 400;
  color: var(--color-accent);
  line-height: 1;
  min-width: 4.25rem;
  flex-shrink: 0;
  letter-spacing: -0.025em;
}

.intro-stat__text {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding-top: 0.2rem;
}

.intro-stat__label {
  font-size: 0.875rem;
  color: var(--color-text);
  line-height: 1.45;
}

.intro-stat__source {
  font-size: 0.6875rem;
  color: var(--color-text-faint);
  text-decoration: none;
  font-style: italic;
  transition: color 0.1s;
}

.intro-stat__source:hover {
  color: var(--color-accent);
  text-decoration: underline;
}

.intro-about-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 500;
  margin-top: 1.25rem;
}

.intro-about-link:hover {
  text-decoration: underline;
}

/* ===================================================================
   Results panel
   =================================================================== */

[hidden] {
  display: none !important;
}

.results-panel {
  width: var(--panel-width);
  min-width: var(--panel-width);
  background: var(--color-panel-bg);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 5;
}

.results-loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem;
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}

.spinner {
  display: inline-block;
  width: 1.125rem;
  height: 1.125rem;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

/* ===================================================================
   District header
   =================================================================== */

.district-header {
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-panel-alt);
}

.district-label {
  display: block;
  font-family: var(--font-display);
  font-size: 2.125rem;
  font-weight: 400;
  letter-spacing: -0.025em;
  color: var(--color-text);
  line-height: 1.1;
  margin-bottom: 0.25rem;
}

.neighborhood-label {
  display: block;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  font-weight: 400;
}

/* ===================================================================
   Messages (PD / all-permitted / no-data)
   =================================================================== */

.pd-message,
.all-permitted-message,
.no-data-message {
  padding: 1.25rem 1.5rem;
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  line-height: 1.65;
}

.pd-message p,
.all-permitted-message p,
.no-data-message p {
  margin-bottom: 0.75rem;
}

.pd-link {
  display: inline-block;
  color: var(--color-accent);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
}

.pd-link:hover {
  text-decoration: underline;
}

/* ===================================================================
   Use sections
   =================================================================== */

.use-section {
  padding: 1.0625rem 1.5rem;
}

.use-section + .use-section {
  border-top: 1px solid var(--color-border);
}

.use-section--banned {
  background: var(--color-banned-bg);
  border-left: 3px solid var(--color-banned);
}

.use-section--special {
  background: var(--color-special-bg);
  border-left: 3px solid var(--color-special);
}

.use-section--conditional {
  background: var(--color-conditional-bg);
  border-left: 3px solid var(--color-conditional);
}

.use-section--permitted {
  background: var(--color-permitted-bg);
  border-left: 3px solid var(--color-permitted);
}

.use-section__title {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 0.625rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.use-section--banned .use-section__title      { color: var(--color-banned); }
.use-section--special .use-section__title     { color: var(--color-special); }
.use-section--conditional .use-section__title { color: var(--color-conditional); }
.use-section--permitted .use-section__title-text { color: var(--color-permitted); }

.use-section__summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-permitted);
  user-select: none;
}

.use-section__summary::-webkit-details-marker {
  display: none;
}

.use-section__count {
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: none;
  letter-spacing: 0;
}

.use-section__chevron {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  transition: transform 0.15s;
}

details.use-section[open] .use-section__chevron {
  transform: rotate(90deg);
}

details.use-section[open] .use-section__subtitle,
details.use-section[open] .use-list {
  display: block;
}

details.use-section .use-section__subtitle,
details.use-section .use-list {
  display: none;
}

details.use-section[open] .use-section__subtitle {
  margin-top: 0.5rem;
}

details.use-section[open] .use-list {
  margin-top: 0.625rem;
}

.use-section__subtitle {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-bottom: 0.625rem;
  line-height: 1.5;
}

.use-section__icon {
  font-style: normal;
  font-size: 0.875rem;
}

/* ===================================================================
   Use list items
   =================================================================== */

.use-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3125rem;
}

.use-list__item {
  font-size: 0.9375rem;
  color: var(--color-text);
  line-height: 1.4;
}

.use-list__category {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-top: 0.875rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--color-border);
}

.use-list__category:first-child {
  margin-top: 0;
}

/* ===================================================================
   Ward CTA
   =================================================================== */

.ward-cta {
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-panel-alt);
}

.ward-cta__text {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: 0.875rem;
  line-height: 1.55;
}

.ward-button {
  display: block;
  width: 100%;
  padding: 0.8125rem 1rem;
  background: var(--color-accent);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9375rem;
  border-radius: var(--radius);
  text-align: center;
  font-family: var(--font-body);
  transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.01em;
}

.ward-button:hover,
.ward-button:focus-visible {
  background: var(--color-accent-dark);
  outline: none;
}

.ward-button:active {
  transform: translateY(1px);
}

/* ===================================================================
   Results context link
   =================================================================== */

.results-context {
  padding: 0.875rem 1.5rem;
  border-top: 1px solid var(--color-border);
}

.results-context__link {
  font-size: 0.875rem;
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 500;
}

.results-context__link:hover {
  text-decoration: underline;
}

/* ===================================================================
   Attribution
   =================================================================== */

.results-attribution {
  padding: 0.875rem 1.5rem 1.25rem;
  font-size: 0.75rem;
  color: var(--color-text-faint);
  border-top: 1px solid var(--color-border);
  line-height: 1.55;
  margin-top: auto;
}

.results-attribution a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.results-attribution a:hover {
  color: var(--color-accent);
  text-decoration: underline;
}

/* ===================================================================
   Map container
   =================================================================== */

.map-container {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ===================================================================
   Mobile layout (≤ 768px)
   =================================================================== */

@media (max-width: 768px) {
  .app-layout {
    flex-direction: column;
  }

  .side-panel {
    width: 100%;
    min-width: 0;
    /* Collapse by height on mobile */
    max-height: 1200px;
    transition: max-height 0.3s ease;
    overflow: hidden;
  }

  .side-panel.is-collapsed {
    width: 100%;
    min-width: 0;
    max-height: 0;
  }

  .intro-panel,
  .results-panel {
    width: 100%;
    min-width: 0;
    overflow-y: visible;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  .intro-body {
    padding: 1.25rem 1rem 1.5rem;
  }

  .intro-stat__number {
    font-size: 1.875rem;
    min-width: 3.75rem;
  }

  .map-container {
    height: 50vh;
    min-height: 280px;
    flex: none;
  }

  .site-header {
    padding: 1rem 1rem 1.125rem;
  }

  .site-header::after {
    display: none;
  }

  .site-title {
    font-size: 1.375rem;
  }

  .site-subtitle {
    display: none;
  }

  .address-form {
    flex-direction: column;
    gap: 0.5rem;
  }

  .search-button {
    width: 100%;
    padding: 0.8125rem 1rem;
  }

  .district-label {
    font-size: 1.75rem;
  }
}

/* ===================================================================
   Map legend
   =================================================================== */

.map-legend {
  position: absolute;
  bottom: 2rem;
  left: 0.75rem;
  z-index: 10;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  min-width: 10.5rem;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  overflow: hidden;
}

.map-legend__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.625rem 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-panel-alt);
}

.map-legend__title {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
}

.map-legend__toggle {
  font-size: 0.6875rem;
  font-family: var(--font-body);
  color: var(--color-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.125rem 0.25rem;
  border-radius: 3px;
  line-height: 1;
  transition: background 0.1s;
}

.map-legend__toggle:hover,
.map-legend__toggle:focus-visible {
  background: var(--color-border);
  color: var(--color-text);
  outline: none;
}

.map-legend__body {
  list-style: none;
  padding: 0.5625rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.map-legend__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-text);
  line-height: 1.3;
}

.map-legend__swatch {
  width: 0.875rem;
  height: 0.875rem;
  border-radius: 3px;
  flex-shrink: 0;
  opacity: 0.9;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
  .map-legend {
    bottom: 2.25rem;
    left: 0.5rem;
    font-size: 0.75rem;
    min-width: 0;
  }

  .map-legend__body {
    gap: 0.3rem;
    padding: 0.4rem 0.625rem;
  }

  .map-legend__swatch {
    width: 0.75rem;
    height: 0.75rem;
  }
}

/* ===================================================================
   MapLibre popup override
   =================================================================== */

.maplibregl-popup-content {
  font-family: var(--font-body);
  font-size: 0.875rem;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border);
}

.zone-popup-label {
  font-weight: 600;
  color: var(--color-text);
}

.zone-popup-type {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 0.125rem;
}
