/* ═══════════════════════════════════════════════════
   Ayushi & Rohit's Map — "Personal Tasting Journal"
   Fraunces (editorial display) + DM Sans (clean body)
   OKLCH rose palette with warm-tinted neutrals
   ═══════════════════════════════════════════════════ */

:root {
  /* Rose palette — OKLCH for perceptual uniformity */
  --rose-50:  oklch(96% 0.02 10);
  --rose-100: oklch(92% 0.04 10);
  --rose-200: oklch(84% 0.08 10);
  --rose-300: oklch(74% 0.12 8);
  --rose-400: oklch(64% 0.14 6);
  --rose-500: oklch(54% 0.15 4);
  --rose-600: oklch(44% 0.13 2);

  /* Warm-tinted neutrals — hint of rose (hue 10) */
  --neutral-50:  oklch(97% 0.006 10);
  --neutral-100: oklch(94% 0.008 10);
  --neutral-200: oklch(88% 0.010 10);
  --neutral-300: oklch(78% 0.010 10);
  --neutral-400: oklch(62% 0.012 10);
  --neutral-500: oklch(48% 0.012 10);
  --neutral-800: oklch(25% 0.015 10);
  --neutral-900: oklch(18% 0.015 10);

  /* Semantic */
  --surface: var(--neutral-50);
  --text: var(--neutral-900);
  --text-secondary: var(--neutral-400);
  --text-muted: var(--neutral-300);
  --border: var(--neutral-200);
  --accent: var(--rose-400);
  --accent-soft: var(--rose-100);
  --accent-deep: var(--rose-600);
  --danger: oklch(55% 0.18 25);
  --danger-soft: oklch(92% 0.04 25);

  /* Shadows — rose-tinted */
  --shadow-sm: 0 1px 3px oklch(60% 0.04 10 / 0.08);
  --shadow-md: 0 4px 16px oklch(55% 0.06 10 / 0.10);
  --shadow-lg: 0 8px 32px oklch(50% 0.06 10 / 0.14);
  --shadow-xl: 0 16px 48px oklch(45% 0.08 10 / 0.18);

  /* Typography */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;

  /* Spacing — 4pt base */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Easing */
  --ease-out: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-in: cubic-bezier(0.7, 0, 0.84, 0);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-full: 9999px;
}

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

body {
  font-family: var(--font-body);
  color: var(--text);
  overflow: hidden;
  height: 100dvh;
  width: 100vw;
  -webkit-font-smoothing: antialiased;
}

/* ─── Map ─────────────────────────────────────────── */

#map {
  width: 100%;
  height: 100dvh;
}

.leaflet-tile-pane {
  filter: hue-rotate(332deg) saturate(1.35) brightness(1.06);
}

.leaflet-control-attribution {
  font-family: var(--font-body) !important;
  font-size: 10px !important;
  background: oklch(97% 0.006 10 / 0.75) !important;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.leaflet-control-zoom a {
  font-family: var(--font-body) !important;
  color: var(--neutral-500) !important;
  border-color: var(--border) !important;
}

/* ─── Search ──────────────────────────────────────── */

.search-container {
  position: absolute;
  top: var(--sp-4);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: 90%;
  max-width: 420px;
}

.search-bar {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius-full);
  padding: 0 var(--sp-5);
  height: 52px;
  box-shadow: var(--shadow-lg);
  border: 1.5px solid transparent;
  transition: border-color 200ms var(--ease-out),
              box-shadow 200ms var(--ease-out);
}

.search-bar:focus-within {
  border-color: var(--rose-200);
  box-shadow: var(--shadow-xl), 0 0 0 4px var(--rose-100);
}

.search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
  margin-right: var(--sp-3);
}

#search-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 500;
  background: transparent;
  color: var(--text);
  letter-spacing: -0.01em;
}

#search-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.search-clear {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--sp-1);
  line-height: 1;
  transition: color 150ms;
}

.search-clear:hover { color: var(--text-secondary); }

.search-results {
  list-style: none;
  background: var(--surface);
  border-radius: var(--radius-lg);
  margin-top: var(--sp-2);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  max-height: 300px;
  overflow-y: auto;
}

.search-results:empty { display: none; }

.search-results li {
  padding: var(--sp-3) var(--sp-5);
  cursor: pointer;
  transition: background 120ms;
}

.search-results li + li {
  border-top: 1px solid var(--border);
}

.search-results li:hover { background: var(--rose-50); }
.search-results li:active { background: var(--rose-100); }

.search-results li .result-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.01em;
}

.search-results li .result-type {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ─── Modal ───────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: oklch(25% 0.02 10 / 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: overlayIn 250ms var(--ease-out);
}

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

.save-modal {
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 88dvh;
  overflow-y: auto;
  animation: modalSlideUp 350ms var(--ease-out-expo);
  overscroll-behavior: contain;
}

@keyframes modalSlideUp {
  from { transform: translateY(100%); opacity: 0.5; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-5) var(--sp-6) var(--sp-4);
  position: sticky;
  top: 0;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  z-index: 1;
}

.modal-header h3 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--accent-deep);
  letter-spacing: -0.02em;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
  transition: color 150ms, background 150ms;
}

.modal-close:hover {
  color: var(--text-secondary);
  background: var(--neutral-100);
}

.modal-body {
  padding: 0 var(--sp-6) var(--sp-8);
}

.modal-place-info {
  margin-bottom: var(--sp-6);
  padding-bottom: var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.modal-place-name {
  width: 100%;
  border: none;
  background: transparent;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  padding: 0;
  outline: none;
}

.modal-place-addr {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: var(--sp-1);
  line-height: 1.45;
}

/* Items section */
.items-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-4);
}

.items-section-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--neutral-500);
  letter-spacing: -0.01em;
}

.add-item-btn {
  background: transparent;
  border: 1.5px dashed var(--rose-200);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  padding: var(--sp-1) var(--sp-3);
  cursor: pointer;
  transition: all 150ms var(--ease-out);
}

.add-item-btn:hover {
  background: var(--rose-50);
  border-color: var(--rose-300);
}

.items-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  font-style: italic;
  padding: var(--sp-8) 0 var(--sp-6);
}

/* Item card */
.item-card {
  padding: var(--sp-4) 0;
  animation: itemReveal 300ms var(--ease-out-expo) both;
}

.item-card + .item-card {
  border-top: 1px solid var(--border);
}

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

.item-card-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.item-name-input {
  flex: 1;
  border: none;
  border-bottom: 1.5px solid var(--border);
  background: transparent;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  padding: var(--sp-1) 0;
  outline: none;
  letter-spacing: -0.01em;
  transition: border-color 200ms;
}

.item-name-input:focus {
  border-color: var(--accent);
}

.item-name-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
  font-style: italic;
}

.item-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: var(--sp-1);
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: all 150ms;
}

.item-delete-btn:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

/* Rating sliders */
.item-ratings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}

.item-rating-col {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  transition: opacity 200ms var(--ease-out);
}

.item-rating-col.rating-disabled {
  opacity: 0.35;
}

.item-rating-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  cursor: pointer;
}

.item-rating-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}

.item-rating-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.item-rating-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.item-rating-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--neutral-200);
  border-radius: 2px;
  outline: none;
  min-width: 0;
}

.item-rating-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 150ms var(--ease-out);
}

.item-rating-row input[type="range"]::-webkit-slider-thumb:active {
  transform: scale(1.2);
}

.item-rating-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.item-rating-val {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-deep);
  min-width: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.save-btn {
  width: 100%;
  padding: var(--sp-4);
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent-deep);
  color: var(--neutral-50);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: var(--sp-6);
  letter-spacing: -0.01em;
  transition: opacity 120ms, transform 120ms var(--ease-out);
}

.save-btn:hover { opacity: 0.92; }
.save-btn:active { transform: scale(0.98); opacity: 0.85; }

/* ─── Map markers ─────────────────────────────────── */

.marker-saved { cursor: pointer; }

.marker-pin {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-deep);
  border: 3px solid var(--neutral-50);
  box-shadow: var(--shadow-md);
  transition: transform 150ms var(--ease-out);
}

.marker-saved:hover .marker-pin {
  transform: scale(1.25);
}

.marker-temp {
  background: var(--rose-200);
  border: 2.5px solid var(--accent);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: 0 0 0 5px oklch(64% 0.14 6 / 0.15);
  animation: tempPulse 2s ease-in-out infinite;
}

@keyframes tempPulse {
  0%, 100% { box-shadow: 0 0 0 5px oklch(64% 0.14 6 / 0.15); }
  50% { box-shadow: 0 0 0 10px oklch(64% 0.14 6 / 0.05); }
}

/* ─── Leaflet popup overrides ─────────────────────── */

.leaflet-popup-content-wrapper {
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-xl) !important;
  padding: 0 !important;
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0 !important;
  font-family: var(--font-body);
  max-height: 340px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.leaflet-popup-tip {
  box-shadow: none !important;
}

.popup-content {
  padding: var(--sp-5);
  min-width: 230px;
  max-width: 290px;
}

.popup-content h4 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.popup-content .popup-address {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  margin-bottom: var(--sp-4);
  line-height: 1.35;
}

/* Avg bar in popup */
.popup-avg-bar {
  display: flex;
  gap: var(--sp-6);
  padding: var(--sp-3) var(--sp-4);
  background: var(--rose-50);
  border-radius: var(--radius-sm);
  margin-bottom: var(--sp-3);
}

.popup-avg-col { text-align: center; flex: 1; }

.popup-avg-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.popup-avg-val {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-deep);
  letter-spacing: -0.03em;
}

/* Items list in popup */
.popup-items {
  list-style: none;
  margin-bottom: var(--sp-4);
}

.popup-item {
  padding: var(--sp-2) 0;
}

.popup-item + .popup-item {
  border-top: 1px solid var(--border);
}

.popup-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.popup-item-scores {
  display: flex;
  gap: var(--sp-4);
  margin-top: 2px;
}

.popup-item-score {
  font-size: 12px;
  color: var(--text-secondary);
}

.popup-item-score span {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--accent-deep);
}

.popup-no-items {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: var(--sp-4);
}

.popup-actions {
  display: flex;
  gap: var(--sp-2);
}

.popup-actions button {
  flex: 1;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  border: none;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: -0.01em;
  transition: opacity 120ms, transform 120ms var(--ease-out);
}

.popup-actions button:active { transform: scale(0.96); }

.popup-btn-edit {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.popup-btn-edit:hover { background: var(--rose-200); }

.popup-btn-delete {
  background: var(--danger-soft);
  color: var(--danger);
}

.popup-btn-save {
  background: var(--accent-deep);
  color: var(--neutral-50);
  width: 100%;
  padding: var(--sp-3);
}

/* ─── Drawer ──────────────────────────────────────── */

.drawer-toggle {
  position: absolute;
  bottom: var(--sp-6);
  right: var(--sp-4);
  z-index: 1000;
  background: var(--surface);
  border: none;
  border-radius: var(--radius-full);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  color: var(--accent-deep);
  transition: transform 150ms var(--ease-out), box-shadow 150ms;
}

.drawer-toggle:hover { box-shadow: var(--shadow-xl); }
.drawer-toggle:active { transform: scale(0.92); }

.drawer-count {
  position: absolute;
  top: -3px;
  right: -3px;
  background: var(--accent);
  color: var(--neutral-50);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.drawer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1500;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: 0 -8px 40px oklch(50% 0.04 10 / 0.12);
  max-height: 55dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: drawerSlideUp 300ms var(--ease-out-expo);
}

@keyframes drawerSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-5) var(--sp-6) var(--sp-3);
  position: sticky;
  top: 0;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  z-index: 1;
}

.drawer-header::after {
  content: '';
  position: absolute;
  top: var(--sp-2);
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--neutral-200);
}

.drawer-header h3 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--accent-deep);
  letter-spacing: -0.02em;
}

.drawer-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
  transition: color 150ms, background 150ms;
}

.drawer-close:hover {
  color: var(--text-secondary);
  background: var(--neutral-100);
}

.saved-list {
  list-style: none;
  padding: 0 var(--sp-4) var(--sp-4);
}

.saved-list li {
  padding: var(--sp-4);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background 120ms;
}

.saved-list li:hover { background: var(--rose-50); }
.saved-list li:active { background: var(--rose-100); }

.saved-list li + li {
  border-top: 1px solid var(--border);
}

.saved-list-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-3);
}

.saved-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.saved-avg {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--accent-deep);
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: -0.02em;
}

.saved-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.saved-items-preview {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: var(--sp-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
}

.saved-empty {
  padding: var(--sp-12) var(--sp-6);
  text-align: center;
}

.saved-empty p {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--text-secondary);
  font-weight: 600;
}

.saved-empty span {
  font-size: 13px;
  color: var(--text-muted);
  display: block;
  margin-top: var(--sp-1);
}

/* ─── Desktop ─────────────────────────────────────── */

@media (min-width: 600px) {
  .save-modal {
    border-radius: var(--radius-xl);
    margin-bottom: 40px;
    max-width: 460px;
  }

  .modal-overlay {
    align-items: center;
  }

  .drawer {
    width: 380px;
    left: auto;
    right: var(--sp-4);
    bottom: 88px;
    border-radius: var(--radius-xl);
    max-height: 60dvh;
  }

  .drawer-header {
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }

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

/* ─── Reduced motion ──────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .save-modal, .drawer, .item-card { animation: none !important; }
  .marker-temp { animation: none !important; }
  .modal-overlay { animation: none !important; }
}
