/* ==========================================================================
   Achaia Wine Region Dashboard — Design Tokens
   Palette derived from the Achaia landscape: sun-bleached limestone hills,
   the Gulf of Patras / Gulf of Corinth aegean blue, terracotta soil, and
   deep Mavrodaphne wine red.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Type */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, sans-serif;

  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2.5rem;
  --text-hero: clamp(2.25rem, 5vw, 3.75rem);

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;
  --space-10: 4rem;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  /* Light mode palette */
  --bg: 38 40% 96%;
  --surface: 40 45% 99%;
  --surface-elevated: 0 0% 100%;
  --surface-sunken: 36 30% 92%;
  --border: 32 20% 84%;
  --text-primary: 218 30% 15%;
  --text-secondary: 216 14% 40%;
  --text-tertiary: 216 10% 55%;

  --accent: 200 58% 33%;
  --accent-hover: 200 58% 27%;
  --accent-soft: 200 45% 92%;
  --terracotta: 24 62% 47%;

  --shadow-color: 30 30% 20%;

  /* Zone colors (kept in sync with js/data.js) */
  --zone-pgi: #8a8375;
  --zone-patras: #c17a2c;
  --zone-muscat-patras: #d4a72c;
  --zone-muscat-rio: #e8c14a;
  --zone-mavrodaphne: #7a1f2b;

  --map-tile-filter: none;
}

.dark {
  --bg: 216 32% 9%;
  --surface: 216 28% 13%;
  --surface-elevated: 216 26% 16%;
  --surface-sunken: 216 32% 7%;
  --border: 216 20% 24%;
  --text-primary: 36 30% 93%;
  --text-secondary: 32 14% 68%;
  --text-tertiary: 32 10% 50%;

  --accent: 199 62% 58%;
  --accent-hover: 199 62% 66%;
  --accent-soft: 200 40% 20%;
  --terracotta: 24 70% 60%;

  --shadow-color: 0 0% 0%;

  --map-tile-filter: brightness(0.92) contrast(1.05);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-body);
  background: hsl(var(--bg));
  color: hsl(var(--text-primary));
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

@media (max-width: 860px) {
  body { overflow: visible; }
}

*:focus-visible {
  outline: 2px solid hsl(var(--accent));
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

a { color: hsl(var(--accent)); text-decoration: none; }
a:hover { text-decoration: underline; }

.tabular { font-variant-numeric: tabular-nums lining-nums; }

/* Skip link */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: hsl(var(--accent));
  color: white;
  padding: var(--space-2) var(--space-4);
  z-index: 999;
}
.skip-link:focus { left: 0; }

/* ==========================================================================
   Layout — dashboard grid
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: auto 1fr;
  height: 100dvh;
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    height: auto;
  }
}

/* ---- Sidebar ---- */
.sidebar {
  grid-row: 1 / -1;
  background: hsl(var(--surface));
  border-right: 1px solid hsl(var(--border) / 0.7);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-5) var(--space-5) var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

@media (max-width: 860px) {
  .sidebar {
    grid-row: auto;
    border-right: none;
    border-bottom: 1px solid hsl(var(--border) / 0.7);
    max-height: none;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-logo { width: 38px; height: 38px; color: hsl(var(--accent)); flex-shrink: 0; }

.brand-text h1 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
  color: hsl(var(--text-primary));
}

.brand-text span {
  display: block;
  font-size: var(--text-xs);
  color: hsl(var(--text-tertiary));
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 2px;
}

.sidebar-section h2 {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: hsl(var(--text-tertiary));
  font-weight: 600;
  margin: 0 0 var(--space-3);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.sidebar-nav a {
  color: hsl(var(--text-secondary));
  font-size: var(--text-sm);
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-nav a:hover { background: hsl(var(--surface-sunken)); color: hsl(var(--text-primary)); text-decoration: none; }

/* Legend / zone toggles */
.legend-list { display: flex; flex-direction: column; gap: var(--space-2); }

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  background: none;
  border: 1px solid hsl(var(--border) / 0.7);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font-family: var(--font-body);
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.legend-item:hover { background: hsl(var(--surface-sunken)); }

.legend-item[aria-pressed="false"] { opacity: 0.42; }

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px hsl(0 0% 0% / 0.15);
}

.legend-swatch.outline {
  background: transparent;
  border: 2px dashed var(--zone-pgi);
  border-radius: 3px;
}

.legend-copy { flex: 1; min-width: 0; }
.legend-name { font-size: var(--text-sm); font-weight: 600; color: hsl(var(--text-primary)); line-height: 1.25; }
.legend-sub { font-size: var(--text-xs); color: hsl(var(--text-tertiary)); }

.sidebar-note {
  font-size: var(--text-xs);
  color: hsl(var(--text-tertiary));
  line-height: 1.6;
  padding-top: var(--space-4);
  border-top: 1px solid hsl(var(--border) / 0.6);
}
.sidebar-note a { color: hsl(var(--text-secondary)); text-decoration: underline; text-decoration-color: hsl(var(--border)); }

/* ---- Header ---- */
.header {
  grid-column: 2;
  position: sticky;
  top: 0;
  z-index: 20;
  background: hsl(var(--surface) / 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid hsl(var(--border) / 0.7);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
}

@media (max-width: 860px) { .header { grid-column: 1; } }

.header-title h1 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  margin: 0;
  color: hsl(var(--text-primary));
}
.header-title p {
  margin: 2px 0 0;
  font-size: var(--text-sm);
  color: hsl(var(--text-secondary));
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: hsl(var(--surface-elevated));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  color: hsl(var(--text-primary));
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  flex-shrink: 0;
}
.theme-toggle:hover { background: hsl(var(--surface-sunken)); }
.theme-toggle svg { width: 16px; height: 16px; }

/* ---- Main ---- */
.main {
  grid-column: 2;
  overflow-y: auto;
  overscroll-behavior: contain;
}

@media (max-width: 860px) { .main { grid-column: 1; overflow-y: visible; } }

/* Map section */
.map-section {
  position: relative;
  height: 64vh;
  min-height: 420px;
  border-bottom: 1px solid hsl(var(--border) / 0.7);
}
@media (max-width: 860px) { .map-section { height: 62vh; min-height: 380px; } }

#map {
  width: 100%;
  height: 100%;
  background: hsl(var(--surface-sunken));
  filter: var(--map-tile-filter);
}

.map-caption {
  position: absolute;
  bottom: var(--space-3);
  left: var(--space-3);
  z-index: 1000;
  background: hsl(var(--surface-elevated));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  color: hsl(var(--text-tertiary));
  max-width: 320px;
  filter: none;
}

.map-caption strong { color: hsl(var(--text-secondary)); font-weight: 600; }

.leaflet-popup-content-wrapper {
  background: hsl(var(--surface-elevated));
  color: hsl(var(--text-primary));
  border-radius: var(--radius-md);
  box-shadow: 0 8px 28px hsl(var(--shadow-color) / 0.28);
}
.leaflet-popup-tip { background: hsl(var(--surface-elevated)); }
.leaflet-popup-content { font-family: var(--font-body); font-size: var(--text-sm); margin: var(--space-3) var(--space-4); line-height: 1.5; }
.popup-title { font-family: var(--font-display); font-weight: 600; font-size: var(--text-lg); margin: 0 0 4px; }
.popup-kind { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; color: hsl(var(--text-tertiary)); margin-bottom: var(--space-2); }
.popup-row { margin: 2px 0; }
.popup-row b { color: hsl(var(--text-secondary)); font-weight: 600; }

/* Content sections */
.content {
  padding: var(--space-8) var(--space-6) var(--space-10);
  max-width: 1180px;
  margin: 0 auto;
}

.section { margin-bottom: var(--space-10); }
.section-head { margin-bottom: var(--space-5); max-width: 640px; }
.section-head h2 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  margin: 0 0 var(--space-2);
  color: hsl(var(--text-primary));
}
.section-head p { margin: 0; color: hsl(var(--text-secondary)); font-size: var(--text-base); }

/* Zone cards */
.zone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-5);
}

.zone-card {
  background: hsl(var(--surface-elevated));
  border: 1px solid hsl(var(--border) / 0.7);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.zone-card[data-dimmed="true"] { opacity: 0.38; }

.zone-card-head { display: flex; align-items: flex-start; gap: var(--space-3); margin-bottom: var(--space-3); }
.zone-dot { width: 12px; height: 12px; border-radius: 3px; margin-top: 6px; flex-shrink: 0; }
.zone-card-head h3 { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 600; margin: 0; color: hsl(var(--text-primary)); }
.zone-card-head .zone-kind { font-size: var(--text-xs); color: hsl(var(--text-tertiary)); text-transform: uppercase; letter-spacing: 0.04em; }

.zone-card p.zone-desc { font-size: var(--text-sm); color: hsl(var(--text-secondary)); margin: 0 0 var(--space-4); }

.zone-fact { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) 0; border-top: 1px solid hsl(var(--border) / 0.5); font-size: var(--text-sm); }
.zone-fact:first-of-type { border-top: none; }
.zone-fact dt { color: hsl(var(--text-tertiary)); flex-shrink: 0; }
.zone-fact dd { margin: 0; color: hsl(var(--text-primary)); text-align: right; font-weight: 500; }

.zone-varieties { margin-top: var(--space-3); }
.variety-group { margin-bottom: var(--space-2); }
.variety-label { font-size: var(--text-xs); font-weight: 600; color: hsl(var(--text-tertiary)); text-transform: uppercase; letter-spacing: 0.03em; display: block; margin-bottom: 4px; }
.variety-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.variety-tag {
  font-size: var(--text-xs);
  padding: 3px 9px;
  border-radius: 999px;
  background: hsl(var(--surface-sunken));
  color: hsl(var(--text-secondary));
  border: 1px solid hsl(var(--border) / 0.6);
}

.zone-sources { margin-top: var(--space-4); font-size: var(--text-xs); color: hsl(var(--text-tertiary)); }
.zone-sources a { margin-right: var(--space-2); }

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin-bottom: var(--space-5);
  padding: var(--space-4);
  background: hsl(var(--surface-elevated));
  border: 1px solid hsl(var(--border) / 0.7);
  border-radius: var(--radius-lg);
}

.search-input-wrap { position: relative; flex: 1 1 220px; }
.search-input-wrap svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: hsl(var(--text-tertiary)); }

#producer-search {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background: hsl(var(--surface));
  color: hsl(var(--text-primary));
  font-family: var(--font-body);
  font-size: var(--text-sm);
}
#producer-search:focus { outline: 2px solid hsl(var(--accent)); outline-offset: 1px; }

.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }

.filter-chip {
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--surface));
  color: hsl(var(--text-secondary));
  cursor: pointer;
  transition: all 0.15s ease;
}
.filter-chip:hover { background: hsl(var(--surface-sunken)); }
.filter-chip[aria-pressed="true"] {
  background: hsl(var(--accent));
  border-color: hsl(var(--accent));
  color: white;
}

.filter-count { font-size: var(--text-xs); color: hsl(var(--text-tertiary)); margin-left: auto; white-space: nowrap; }

/* Producer directory */
.producer-list { display: flex; flex-direction: column; gap: var(--space-4); }

.producer-card {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1.3fr;
  gap: var(--space-5);
  background: hsl(var(--surface-elevated));
  border: 1px solid hsl(var(--border) / 0.7);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
@media (max-width: 760px) {
  .producer-card { grid-template-columns: 1fr; }
}

.producer-card.hidden { display: none; }

.producer-main h3 { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 600; margin: 0 0 4px; color: hsl(var(--text-primary)); }
.producer-founded { font-size: var(--text-xs); color: hsl(var(--text-tertiary)); margin: 0 0 var(--space-3); }
.producer-note { font-size: var(--text-sm); color: hsl(var(--text-secondary)); margin: 0 0 var(--space-3); }
.producer-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--space-3); }
.producer-tag { font-size: var(--text-xs); padding: 3px 9px; border-radius: 999px; background: hsl(var(--accent-soft)); color: hsl(var(--accent)); font-weight: 500; }
.dark .producer-tag { color: hsl(var(--accent-hover)); }

.locate-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: hsl(var(--accent));
  background: none;
  border: 1px solid hsl(var(--accent) / 0.4);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  cursor: pointer;
}
.locate-btn:hover { background: hsl(var(--accent-soft)); }
.locate-btn svg { width: 12px; height: 12px; }

.producer-contact { font-size: var(--text-sm); color: hsl(var(--text-secondary)); display: flex; flex-direction: column; gap: 6px; }
.producer-contact div { display: flex; gap: 8px; align-items: flex-start; }
.producer-contact svg { width: 14px; height: 14px; margin-top: 3px; flex-shrink: 0; color: hsl(var(--text-tertiary)); }

.producer-portfolio h4 { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; color: hsl(var(--text-tertiary)); margin: 0 0 var(--space-2); font-weight: 600; }
.portfolio-item { display: flex; justify-content: space-between; gap: var(--space-3); padding: 5px 0; border-top: 1px solid hsl(var(--border) / 0.4); font-size: var(--text-sm); }
.portfolio-item:first-of-type { border-top: none; }
.portfolio-wine { color: hsl(var(--text-primary)); font-weight: 500; }
.portfolio-style { color: hsl(var(--text-tertiary)); font-size: var(--text-xs); text-align: right; flex-shrink: 0; }

.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: hsl(var(--text-tertiary));
  font-size: var(--text-sm);
}

/* Footer */
.footer {
  border-top: 1px solid hsl(var(--border) / 0.6);
  padding: var(--space-6);
  font-size: var(--text-xs);
  color: hsl(var(--text-tertiary));
  line-height: 1.7;
  max-width: 1180px;
  margin: 0 auto;
}
.footer a { color: hsl(var(--text-secondary)); }

@media (max-width: 480px) {
  .header { padding: var(--space-3) var(--space-4); flex-wrap: wrap; }
  .content { padding: var(--space-6) var(--space-4) var(--space-8); }
}
