/* ==========================================================
   SAPERI & SAPORI — Sagra di Gesualdo
   Design System — Mobile-First PWA
   ========================================================== */

/* --- Google Font Import --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* --- CSS Custom Properties --- */
:root {
  /* Brand palette (from grafica.pdf) */
  --color-navy: #1a2744;
  --color-navy-dark: #0f1a2e;
  --color-navy-light: #263a5e;
  --color-amber: #f5a623;
  --color-amber-light: #ffc857;
  --color-amber-dark: #d48e1a;
  --color-cream: #fdf6e3;
  --color-cream-dark: #f0e6c8;

  /* Accent rainbow (from branding confetti) */
  --color-red: #e74c3c;
  --color-green: #5cb85c;
  --color-blue: #3498db;
  --color-purple: #8e44ad;

  /* Category colors */
  --cat-cibo: #e67e22;
  --cat-dolci: #e84393;
  --cat-bevande: #6c5ce7;
  --cat-cassa: #00b894;
  --cat-musica: #fd79a8;
  --cat-mostra: #00cec9;
  --cat-servizi: #636e72;

  /* Neutrals */
  --color-text: #1a2744;
  --color-text-light: #5a6a82;
  --color-text-muted: #8899aa;
  --color-surface: #ffffff;
  --color-surface-glass: rgba(255, 255, 255, 0.88);
  --color-overlay: rgba(15, 26, 46, 0.45);
  --color-border: rgba(26, 39, 68, 0.1);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-xs: 0.75rem;
  --font-sm: 0.8125rem;
  --font-base: 0.9375rem;
  --font-lg: 1.125rem;
  --font-xl: 1.375rem;
  --font-2xl: 1.75rem;

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(26, 39, 68, 0.08);
  --shadow-md: 0 4px 12px rgba(26, 39, 68, 0.12);
  --shadow-lg: 0 8px 32px rgba(26, 39, 68, 0.18);
  --shadow-sheet: 0 -4px 32px rgba(26, 39, 68, 0.2);

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.22, 1, 0.36, 1);

  /* Z-index layers */
  --z-map: 1;
  --z-header: 100;
  --z-sheet-overlay: 200;
  --z-sheet: 300;
  --z-toast: 400;

  /* Safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-base);
  color: var(--color-text);
  background: var(--color-cream);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  position: relative;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  background: none;
  color: inherit;
}

input {
  font-family: inherit;
  border: none;
  outline: none;
  background: none;
}

/* --- Header --- */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-header);
  padding: calc(var(--safe-top) + var(--space-sm)) var(--space-md) var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

.header > * {
  pointer-events: auto;
}

/* --- Search Bar --- */
.search-container {
  position: relative;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: var(--color-surface-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-sm) var(--space-md);
  box-shadow: var(--shadow-md);
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.search-bar:focus-within {
  box-shadow: var(--shadow-lg);
  border-color: var(--color-amber);
}

.search-bar__icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--color-text-muted);
  transition: color var(--transition-fast);
}

.search-bar:focus-within .search-bar__icon {
  color: var(--color-amber-dark);
}

.search-bar__input {
  flex: 1;
  font-size: var(--font-base);
  color: var(--color-text);
  min-width: 0;
}

.search-bar__input::placeholder {
  color: var(--color-text-muted);
}

.search-bar__clear {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: background var(--transition-fast), color var(--transition-fast);
  opacity: 0;
  pointer-events: none;
}

.search-bar__clear.visible {
  opacity: 1;
  pointer-events: auto;
}

.search-bar__clear:hover {
  background: rgba(26, 39, 68, 0.08);
  color: var(--color-text);
}

/* --- Search Results Dropdown --- */
.search-results {
  position: absolute;
  top: calc(100% + var(--space-xs));
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: var(--color-surface-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: none;
  overscroll-behavior: contain;
}

.search-results.active {
  display: block;
  animation: fadeSlideDown var(--transition-base) forwards;
}

.search-results__item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  border-bottom: 1px solid var(--color-border);
}

.search-results__item:last-child {
  border-bottom: none;
}

.search-results__item:hover,
.search-results__item:active {
  background: rgba(245, 166, 35, 0.08);
}

.search-results__icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.search-results__info {
  flex: 1;
  min-width: 0;
}

.search-results__name {
  font-weight: 600;
  font-size: var(--font-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-results__products {
  font-size: var(--font-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.search-results__empty {
  padding: var(--space-lg);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--font-sm);
}

/* --- Map Container --- */
#map {
  position: fixed;
  inset: 0;
  z-index: var(--z-map);
}

/* Leaflet overrides */
.leaflet-control-attribution {
  font-size: 10px !important;
  background: var(--color-surface-glass) !important;
  backdrop-filter: blur(8px) !important;
  -webkit-backdrop-filter: blur(8px) !important;
  padding: 2px 6px !important;
  border-radius: var(--radius-sm) !important;
  margin: var(--space-sm) !important;
}

.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow-md) !important;
  border-radius: var(--radius-sm) !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: var(--color-surface-glass) !important;
  backdrop-filter: blur(8px) !important;
  -webkit-backdrop-filter: blur(8px) !important;
  color: var(--color-navy) !important;
  border-bottom: 1px solid var(--color-border) !important;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 18px !important;
}

.leaflet-control-zoom a:last-child {
  border-bottom: none !important;
}

/* --- Floating GPS Location Button --- */
.btn-location {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 88px);
  right: 10px;
  z-index: 99;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--color-navy);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), transform var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.btn-location:hover {
  background: var(--color-surface);
  color: var(--color-amber-dark);
}

.btn-location:active {
  transform: scale(0.92);
}

.btn-location.active {
  background: var(--color-navy);
  color: var(--color-amber-light);
  border-color: var(--color-amber);
}

.btn-location.loading svg {
  animation: spin 1s linear infinite;
}

/* --- Custom Marker Icons --- */
.marker-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: var(--shadow-md);
  border: 2.5px solid var(--color-surface);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.marker-icon > * {
  transform: rotate(45deg);
}

.marker-icon--cibo {
  background: var(--cat-cibo);
}

.marker-icon--dolci {
  background: var(--cat-dolci);
}

.marker-icon--bevande {
  background: var(--cat-bevande);
}

.marker-icon--cassa {
  background: var(--cat-cassa);
}

.marker-icon--musica {
  background: var(--cat-musica);
}

.marker-icon--mostra {
  background: var(--cat-mostra);
}

.marker-icon--servizi {
  background: var(--cat-servizi);
}

.marker-icon--multi {
  background: linear-gradient(135deg, var(--cat-cibo), var(--cat-bevande));
}

.marker-icon.active {
  transform: rotate(-45deg) scale(1.25);
  box-shadow: var(--shadow-lg);
  z-index: 1000 !important;
}

/* --- Featured Marker (Da Sandro) --- */
.marker-icon--featured {
  background: linear-gradient(135deg, #f5a623, #e67e22) !important;
  border-color: #ffc857 !important;
  border-width: 3px;
  box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.3), var(--shadow-lg) !important;
  position: relative;
}

.marker-icon__star {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: var(--color-navy);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(45deg);
  box-shadow: var(--shadow-sm);
  border: 1.5px solid var(--color-amber-light);
}

.marker-icon__star svg {
  transform: none;
  fill: var(--color-amber-light);
}

.marker-featured-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 48px;
  height: 48px;
  margin-top: -48px;
  margin-left: -24px;
  border-radius: 50%;
  background: rgba(245, 166, 35, 0.2);
  animation: pulse 2.5s ease-out infinite;
  pointer-events: none;
}

/* --- "SEI QUI" Marker --- */
.marker-sei-qui {
  position: relative;
  width: 24px;
  height: 24px;
}

.marker-sei-qui__dot {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--color-amber);
  border: 3px solid var(--color-surface);
  box-shadow: var(--shadow-md);
  z-index: 2;
}

.marker-sei-qui__pulse {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  background: rgba(245, 166, 35, 0.25);
  animation: pulse 2s ease-out infinite;
  z-index: 1;
}

.marker-sei-qui__label {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-navy);
  color: var(--color-amber-light);
  font-size: var(--font-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  z-index: 3;
}

.marker-sei-qui__label::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--color-navy);
}

/* --- Bottom Sheet Overlay --- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet-overlay);
  background: var(--color-overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.sheet-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* --- Bottom Sheet --- */
.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-sheet);
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-sheet);
  transform: translateY(100%);
  transition: transform var(--transition-slow);
  max-height: 70vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: calc(var(--safe-bottom) + var(--space-md));
}

.bottom-sheet.active {
  transform: translateY(0);
}

.sheet__handle {
  display: flex;
  justify-content: center;
  padding: var(--space-md) 0 var(--space-sm);
  cursor: grab;
}

.sheet__handle-bar {
  width: 40px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--color-border);
}

.sheet__content {
  padding: 0 var(--space-lg) var(--space-md);
}

.sheet__header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.sheet__icon-wrap {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.sheet__title-area {
  flex: 1;
  min-width: 0;
}

.sheet__title {
  font-size: var(--font-xl);
  font-weight: 800;
  color: var(--color-navy);
  line-height: 1.2;
  margin-bottom: var(--space-xs);
}

.sheet__categories {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.sheet__category-badge {
  font-size: var(--font-xs);
  font-weight: 600;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  color: white;
  letter-spacing: 0.02em;
}

.sheet__category-badge--cibo { background: var(--cat-cibo); }
.sheet__category-badge--dolci { background: var(--cat-dolci); }
.sheet__category-badge--bevande { background: var(--cat-bevande); }
.sheet__category-badge--cassa { background: var(--cat-cassa); }
.sheet__category-badge--musica { background: var(--cat-musica); }
.sheet__category-badge--mostra { background: var(--cat-mostra); }
.sheet__category-badge--servizi { background: var(--cat-servizi); }
.sheet__category-badge--featured {
  background: linear-gradient(135deg, #f5a623, #e67e22);
  color: white;
}

.sheet__close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 39, 68, 0.06);
  color: var(--color-text-muted);
  font-size: 1.1rem;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.sheet__close:hover {
  background: rgba(26, 39, 68, 0.12);
  color: var(--color-text);
}

.sheet__section {
  margin-bottom: var(--space-md);
}

.sheet__section-label {
  font-size: var(--font-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
}

.sheet__description {
  font-size: var(--font-sm);
  color: var(--color-text-light);
  line-height: 1.6;
}

.sheet__products {
  font-size: var(--font-sm);
  color: var(--color-text);
  line-height: 1.6;
}

/* --- Navigate Button --- */
.btn-navigate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-md) var(--space-lg);
  background: var(--color-navy);
  color: var(--color-amber-light);
  font-size: var(--font-base);
  font-weight: 700;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  transition: background var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
  margin-top: var(--space-md);
}

.btn-navigate:hover {
  background: var(--color-navy-light);
  box-shadow: var(--shadow-lg);
}

.btn-navigate:active {
  transform: scale(0.97);
}

.btn-navigate svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* --- Toast Notification (Top Floating Banner) --- */
.toast {
  position: fixed;
  top: calc(var(--safe-top) + 72px);
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: var(--z-toast);
  background: var(--color-navy);
  color: var(--color-cream);
  font-size: var(--font-sm);
  font-weight: 600;
  line-height: 1.4;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 28px rgba(15, 26, 46, 0.3);
  white-space: normal;
  word-break: break-word;
  width: min(92%, 440px);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transition: transform var(--transition-base), opacity var(--transition-base);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.toast--warning {
  background: var(--color-amber);
  color: var(--color-navy-dark);
  border-color: var(--color-amber-dark);
  box-shadow: 0 8px 24px rgba(245, 166, 35, 0.35);
}

.toast--error {
  background: var(--color-red);
  color: white;
  border-color: #c0392b;
}

/* --- Offline Route Line Label --- */
.route-label {
  background: var(--color-navy);
  color: var(--color-amber-light);
  font-family: var(--font-family);
  font-size: var(--font-xs);
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  border: none;
}

/* --- Animations --- */
@keyframes pulse {
  0% {
    transform: scale(0.8);
    opacity: 0.8;
  }
  70% {
    transform: scale(2);
    opacity: 0;
  }
  100% {
    transform: scale(2);
    opacity: 0;
  }
}

@keyframes fadeSlideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Loading Spinner (for GPS wait) --- */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--color-amber-light);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* --- Tablet/Desktop Adjustments --- */
@media (min-width: 768px) {
  .header {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
  }

  .bottom-sheet {
    max-width: 420px;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-md);
    max-height: 60vh;
  }

  .bottom-sheet.active {
    transform: translateX(-50%) translateY(0);
  }

  .search-results {
    max-height: 360px;
  }
}

/* --- Utility --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
