/* ============================================================
   Design tokens — light (white + gold) is the base; dark (navy +
   gold) overrides via [data-theme="dark"]. Both share the same type
   system and card layout, differing only in surface/ink colors, so
   they read as one design's light/dark modes, not two different apps.
   ============================================================ */
:root {
  --bg: #FBF8F1;
  --surface: #FFFFFF;
  --ink: #2B2620;
  --ink-muted: #59503F;
  --mist: #A8988A;
  --border: #E9E2D2;
  --border-strong: #D8CDB4;

  --gold-300: #E6C877;
  --gold-500: #C9A227;
  --gold-muted: #A8842E;
  --gold-glow: 0 0 14px rgba(201, 162, 39, 0.45);

  --pine: #5C7A5E;
  --evergreen: #3E7A46;
  --rose: #C2445A;

  --gold-rgb: 201, 162, 39;

  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-ui: "Jost", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --radius-sm: 3px;
  --radius: 16px;
  --radius-pill: 10px;
  --shadow-card: 0 2px 10px rgba(43, 38, 32, 0.06);
  --shadow-sheet: 0 -8px 32px rgba(0, 0, 0, 0.18);
}

:root[data-theme="dark"] {
  --bg: #10182D;
  --surface: #141E38;
  --ink: #F2EFE6;
  --ink-muted: #AEB6D2;
  --mist: #7C87AE;
  --border: #263153;
  --border-strong: #35406A;

  --gold-300: #E6C877;
  --gold-500: #D4B04E;
  --gold-muted: #D4B04E;
  --gold-glow: 0 0 14px rgba(212, 176, 78, 0.55);

  --pine: #7FAF82;
  --evergreen: #6FBF7B;
  --rose: #E2708C;

  --gold-rgb: 212, 176, 78;

  --shadow-card: none;
  --shadow-sheet: 0 -8px 32px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html {
  font-size: 18.5px;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ============================================================
   Header
   ============================================================ */
.app-header {
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.app-header::before {
  /* Softness comes from the gradient's own multi-stop falloff, not a
     blur() filter — filters are expensive to repaint, and this layer
     repaints on every theme toggle since it reads --gold-rgb. */
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(var(--gold-rgb), 0.16) 0%, rgba(var(--gold-rgb), 0.05) 18%, transparent 38%),
    radial-gradient(circle at 80% 10%, rgba(var(--gold-rgb), 0.14) 0%, rgba(var(--gold-rgb), 0.04) 18%, transparent 40%),
    radial-gradient(circle at 94% 60%, rgba(var(--gold-rgb), 0.15) 0%, rgba(var(--gold-rgb), 0.05) 18%, transparent 38%);
}

.app-header__inner {
  position: relative;
  z-index: 1;
  padding: 18px 16px 14px;
}

.app-header__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.6rem;
  margin: 0;
  letter-spacing: 0.01em;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.app-header__wordmark {
  display: flex;
  align-items: center;
  gap: 6px;
}

.app-header__star {
  color: var(--gold-500);
  flex-shrink: 0;
}

.app-header__title .accent {
  color: var(--gold-muted);
  font-style: italic;
}

.app-header__tagline {
  font-size: 0.78rem;
  color: var(--mist);
  margin: 3px 0 12px;
  letter-spacing: 0.01em;
}

.app-header__icon-btns {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.theme-toggle,
.lang-toggle {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold-muted);
  flex-shrink: 0;
}

.lang-toggle {
  font-family: var(--font-ui);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.theme-toggle svg { width: 15px; height: 15px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.app-header__controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.view-switch {
  display: flex;
  gap: 6px;
  flex: 1;
}

.view-switch__btn {
  flex: 1;
  border: 1px solid var(--border-strong);
  border-radius: 9999px;
  background: transparent;
  color: var(--mist);
  padding: 8px 0;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.view-switch__btn[aria-pressed="true"] {
  background: var(--gold-500);
  border-color: var(--gold-500);
  color: var(--bg);
  font-weight: 600;
}

.saved-toggle {
  border: 1px solid var(--border-strong);
  border-radius: 9999px;
  background: transparent;
  color: var(--mist);
  padding: 8px 12px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.saved-toggle[aria-pressed="true"] {
  background: var(--gold-500);
  border-color: var(--gold-500);
  color: var(--bg);
  font-weight: 600;
}

.saved-toggle .heart { font-size: 0.9rem; }

.app-header__filterbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px -16px 0;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
}

.app-header__filterbar::-webkit-scrollbar { display: none; }

.filter-pills {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.filter-pill {
  flex-shrink: 0;
  border: 1px solid var(--border-strong);
  border-radius: 9999px;
  background: transparent;
  color: var(--mist);
  padding: 6px 12px;
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
  font-family: var(--font-ui);
}

.filter-pill[aria-pressed="true"] {
  background: var(--gold-500);
  border-color: var(--gold-500);
  color: var(--bg);
  font-weight: 600;
}

.filter-select {
  flex-shrink: 0;
  border: 1px solid var(--border-strong);
  border-radius: 9999px;
  background: transparent;
  color: var(--mist);
  padding: 6px 10px;
  font-size: 0.72rem;
  font-weight: 500;
  font-family: var(--font-ui);
  max-width: 140px;
}

.filter-select.is-hidden { display: none; }

@media (max-width: 719px) {
  .filter-pill,
  .filter-select {
    padding: 4px 10px;
    font-size: 0.68rem;
  }
}

/* ============================================================
   Main views
   ============================================================ */
main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.view {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.view[hidden] { display: none; }

#map { width: 100%; height: 100%; background: var(--bg); }

/* Light theme: plain default OSM tiles, no filter. Dark theme: the
   grayscale+invert treatment so the map matches the dark surface. */
:root[data-theme="dark"] .map-tiles-theme {
  filter: grayscale(1) invert(1) brightness(0.92) contrast(0.95);
}

/* ---- List view ---- */
#list-view {
  overflow-y: auto;
  padding: 4px 20px 24px;
}

@media (min-width: 720px) {
  /* Desktop: map pinned left, list scrolls right — both always
     visible, no more Map/List tab-switching. The view-switch tabs
     become redundant, so hide them; Saved still filters both panes.
     ".view[hidden]" is overridden here (rather than relying on
     :not([hidden])) specifically so both stay shown regardless of
     which tab the (hidden) JS state thinks is "active". */
  main { flex-direction: row; }
  .view[hidden] { display: block; }
  #map-view { flex: 0 0 42%; border-right: 1px solid var(--border); }

  #list-view {
    flex: 1;
    padding: 16px 20px 24px;
  }
  .app-header__controls .view-switch { display: none; }
  .saved-toggle { margin-left: auto; }
  /* The list pane is always visible in the split layout, so sort always
     applies — override the mobile tab-switching hide. */
  .filter-select.is-hidden { display: block; }
}

@media (min-width: 1400px) {
  #list-view {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    align-content: start;
  }
  .market-card { margin-bottom: 0; }
  .empty-state { grid-column: 1 / -1; }
}

.empty-state {
  text-align: center;
  color: var(--mist);
  padding: 48px 20px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.market-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 16px 16px 18px;
  margin-bottom: 12px;
  position: relative;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.market-card__row {
  display: flex;
  gap: 12px;
}

.market-card__content {
  flex: 1;
  min-width: 0;
}

.market-card__thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
}

.market-card__thumb__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.market-card__thumb__placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--surface) 0%, var(--bg) 100%);
}

.market-card__thumb__placeholder img {
  width: 28px;
  height: 28px;
  opacity: 0.6;
}

.market-card:hover,
.market-card:focus-visible {
  box-shadow: 0 4px 16px rgba(43, 38, 32, 0.1);
  transform: translateY(-1px);
}

:root[data-theme="dark"] .market-card:hover,
:root[data-theme="dark"] .market-card:focus-visible {
  border-color: var(--border-strong);
  box-shadow: none;
}

.market-card__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.market-card__name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  line-height: 1.3;
  margin: 0;
  color: var(--ink);
}

.market-card__district {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--mist);
  margin: 5px 0 0;
  letter-spacing: 0.03em;
}

.market-card__district svg { flex-shrink: 0; }

.market-card__status {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 600;
  margin: 12px 0 8px;
}

.market-card__status--open { color: var(--evergreen); }
.market-card__status--closed { color: var(--gold-muted); }

.market-card__summary {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--ink-muted);
  margin: 0;
}

.fav-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  padding: 2px 4px;
  color: var(--border-strong);
  flex-shrink: 0;
}

.fav-btn[aria-pressed="true"] {
  color: var(--gold-500);
  text-shadow: var(--gold-glow);
}

/* ============================================================
   Bottom sheet (market detail)
   ============================================================ */
.sheet-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 2000;
}

:root[data-theme="dark"] .sheet-overlay { background: rgba(0, 0, 0, 0.65); }

.sheet-overlay[hidden] { display: none; }

.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 78%;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow-sheet);
  display: flex;
  flex-direction: column;
  transform: translateY(0);
  animation: sheet-up 0.22s ease-out;
}

@media (min-width: 720px) {
  /* Full-bleed edge-to-edge sheets are a mobile pattern — at desktop
     width they swallow the whole screen and hide the overlay's
     click-to-dismiss area. Constrain it to a centered modal card. */
  .sheet-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
  }
  .sheet {
    position: relative;
    left: auto; right: auto; bottom: auto;
    width: 100%;
    max-width: 480px;
    max-height: 82vh;
    border: 1px solid var(--border);
    border-radius: 16px;
    animation: sheet-in 0.18s ease-out;
  }
  @keyframes sheet-in {
    from { transform: translateY(12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }
}

@keyframes sheet-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
}

.sheet__handle {
  width: 100%;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: grab;
}

.sheet__handle::after {
  content: "";
  width: 36px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
}

.sheet__header {
  padding: 4px 18px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  touch-action: none;
}

.sheet__actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.sheet__actions button,
.sheet__actions a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  flex-shrink: 0;
  color: var(--mist);
  text-decoration: none;
}

.sheet__icon-btn {
  background: none;
  border: none;
  color: var(--mist);
}

.sheet__icon-btn svg { width: 18px; height: 18px; }

.sheet__icon-btn.copied { color: var(--evergreen); }

.sheet__close {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--mist);
}

.sheet__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.35rem;
  margin: 0 0 4px;
  color: var(--ink);
}

.sheet__meta {
  font-size: 0.85rem;
  color: var(--mist);
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sheet__meta svg { flex-shrink: 0; }

.sheet__status { font-family: var(--font-ui); font-weight: 600; }
.sheet__status--open { color: var(--evergreen); }
.sheet__status--closed { color: var(--gold-muted); }

.sheet__banner {
  width: 100%;
  height: 150px;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}

.sheet__banner__track {
  display: flex;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.sheet__banner__track::-webkit-scrollbar { display: none; }

.sheet__banner__slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
  height: 100%;
}

.sheet__banner__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.sheet__banner__dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  display: flex;
  justify-content: center;
  gap: 6px;
}

.sheet__banner__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transition: background 0.15s ease;
}

.sheet__banner__dot.active { background: #fff; }

.sheet__banner__placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--surface) 0%, var(--bg) 100%);
}

.sheet__banner__placeholder img {
  width: 84px;
  height: 84px;
  opacity: 0.6;
}

.sheet__body {
  overflow-y: auto;
  padding: 14px 18px 22px;
}

.sheet__summary {
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0 0 16px;
  color: var(--ink-muted);
}

.sheet__address {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--gold-muted);
  text-decoration: none;
  margin: 5px 0 0;
}

.sheet__address[hidden] { display: none; }

.sheet__address:hover { text-decoration: underline; }
.sheet__address svg { flex-shrink: 0; }

.vendor-group__title {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--gold-muted);
  margin: 16px 0 6px;
  font-weight: 600;
}

.vendor-group__title:first-child { margin-top: 0; }

.vendor-item {
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.vendor-item:first-of-type { border-top: none; }

.vendor-item__name {
  font-weight: 600;
  font-size: 0.92rem;
  margin: 0 0 2px;
  color: var(--ink);
}

.vendor-item__desc {
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin: 0 0 2px;
  line-height: 1.4;
}

.vendor-item__hours {
  font-size: 0.78rem;
  color: var(--mist);
  margin: 0;
}

.sheet__last-checked {
  font-size: 0.75rem;
  color: var(--mist);
  margin: 18px 0 0;
  text-align: center;
}

.sheet__loading, .sheet__error {
  padding: 20px 0;
  text-align: center;
  color: var(--mist);
  font-size: 0.9rem;
}

/* ============================================================
   Leaflet marker tweaks
   ============================================================ */
.market-marker {
  background: var(--gold-500);
  border: 2px solid var(--surface);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  box-shadow: var(--gold-glow);
}

.market-marker--fav {
  background: var(--gold-300);
  box-shadow: 0 0 16px rgba(230, 200, 119, 0.7);
}

.map-locate-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--ink-muted);
  cursor: pointer;
}

.map-locate-btn svg { width: 16px; height: 16px; }

.map-locate-btn--error { color: var(--rose); }

.user-location-marker {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-location-marker__dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #4A90E2;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 4px rgba(74, 144, 226, 0.3);
}

/* ============================================================
   Accessibility
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--gold-500);
  outline-offset: 2px;
}
