/* RetailScout — Vintage roadtrip aesthetic
   cream paper, brick red ink, hand-drawn accents */

:root {
  --cream: #faf3e0;
  --cream-deep: #f3e8c8;
  --paper-shadow: rgba(60, 40, 20, 0.12);
  --ink: #3a2f23;
  --ink-soft: #6b5742;
  --brick: #b54e3c;
  --brick-dark: #8d3727;
  --khaki: #c4b896;
  --olive: #6b6b3e;
  --gold: #c89b3c;
  --rust: #a0522d;
  --hot: #c0392b;     /* no website — best lead */
  --warm: #d68a3c;    /* has site, weak */
  --cold: #6b8e5a;    /* solid site, low priority */
  --section-fill: rgba(181, 78, 60, 0.16);
  --section-stroke: #b54e3c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  background: var(--cream);
  color: var(--ink);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overscroll-behavior: none;
}

body { position: relative; }

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
  filter: sepia(0.45) saturate(1.15) contrast(0.92) brightness(1.05);
  background: var(--cream);
}

/* paper grain overlay above the map */
#paper-grain {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.55;
  mix-blend-mode: multiply;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.55  0 0 0 0 0.42  0 0 0 0 0.25  0 0 0 0.25 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 240px 240px;
}

/* topbar */
.topbar {
  position: absolute;
  top: env(safe-area-inset-top, 0);
  left: 0; right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
  background: linear-gradient(180deg, var(--cream) 60%, transparent);
}

.brand { display: flex; align-items: baseline; gap: 8px; }

.brand-mark {
  font-size: 24px;
  color: var(--brick);
  text-shadow: 1px 1px 0 var(--cream-deep);
}

.brand-name {
  font-family: "DM Serif Display", Georgia, serif;
  font-size: 30px;
  letter-spacing: 0.5px;
  color: var(--ink);
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.live-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: "Caveat", cursive;
  font-size: 22px;
  color: var(--ink-soft);
  cursor: pointer;
}

.live-toggle input {
  appearance: none;
  width: 36px;
  height: 20px;
  border: 1.5px solid var(--ink-soft);
  border-radius: 10px;
  background: var(--cream);
  position: relative;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.live-toggle input::after {
  content: "";
  position: absolute;
  top: 1px; left: 1px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--ink-soft);
  transition: transform 0.18s, background 0.15s;
}
.live-toggle input:checked {
  background: var(--brick);
  border-color: var(--brick);
}
.live-toggle input:checked::after {
  transform: translateX(16px);
  background: var(--cream);
}

.icon-btn {
  appearance: none;
  border: 1.5px solid var(--ink);
  background: var(--cream);
  width: 38px; height: 38px;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  color: var(--ink);
  font-family: "DM Serif Display", Georgia, serif;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 2px 2px 0 var(--khaki);
  transition: transform 0.05s;
}
.icon-btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--khaki); }

/* scan button */
.scan-btn {
  position: absolute;
  bottom: calc(28px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  appearance: none;
  border: 2.5px solid var(--ink);
  background: var(--brick);
  color: var(--cream);
  padding: 14px 30px 12px;
  border-radius: 6px;
  font-family: "DM Serif Display", Georgia, serif;
  font-size: 22px;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 200px;
  transition: transform 0.05s, box-shadow 0.05s;
}
.scan-btn:active {
  transform: translate(calc(-50% + 2px), 2px);
  box-shadow: 2px 2px 0 var(--ink);
}
.scan-btn[disabled] {
  opacity: 0.65;
  cursor: wait;
}
.scan-label { line-height: 1; }
.scan-sub {
  font-family: "Caveat", cursive;
  font-size: 15px;
  letter-spacing: 0;
  opacity: 0.95;
  line-height: 1;
}

/* bottom sheet */
.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  background: var(--cream);
  border-top: 2.5px solid var(--ink);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -10px 30px rgba(60, 40, 20, 0.25);
  max-height: 70dvh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 44px; height: 4px;
  background: var(--khaki);
  border-radius: 2px;
  margin: 8px auto 4px;
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 6px 18px 8px;
  gap: 10px;
}

.sheet-title {
  font-family: "DM Serif Display", Georgia, serif;
  font-size: 26px;
  line-height: 1.1;
  color: var(--ink);
}

.sheet-sub {
  font-family: "Caveat", cursive;
  font-size: 18px;
  color: var(--ink-soft);
  margin-top: 2px;
}

.sheet-filter {
  display: flex;
  gap: 8px;
  padding: 4px 18px 10px;
  border-bottom: 1.5px dashed var(--khaki);
}

.filter-chip {
  appearance: none;
  border: 1.5px solid var(--ink);
  background: var(--cream);
  color: var(--ink);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 15px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.filter-chip.active {
  background: var(--ink);
  color: var(--cream);
}

.sheet-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 12px 14px;
}

.shop {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  border-bottom: 1px dashed var(--khaki);
  cursor: pointer;
}
.shop:last-child { border-bottom: 0; }
.shop.dismissed { opacity: 0.4; }
.shop.contacted .shop-name::after {
  content: "✓ contacted";
  font-family: "Caveat", cursive;
  color: var(--olive);
  font-size: 16px;
  margin-left: 8px;
}

.shop-pin {
  width: 26px; height: 26px;
  flex-shrink: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "DM Serif Display", Georgia, serif;
  color: var(--cream);
  font-size: 13px;
  border: 2px solid var(--ink);
  box-shadow: 1px 1px 0 var(--ink);
}
.shop-pin.hot  { background: var(--hot); }
.shop-pin.warm { background: var(--warm); }
.shop-pin.cold { background: var(--cold); }
.shop-pin.unknown { background: var(--khaki); color: var(--ink); }

.shop-body { flex: 1; min-width: 0; }
.shop-name {
  font-family: "DM Serif Display", Georgia, serif;
  font-size: 19px;
  color: var(--ink);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shop-meta {
  font-family: "Caveat", cursive;
  font-size: 17px;
  color: var(--ink-soft);
  margin-top: 1px;
  line-height: 1.1;
}
.shop-meta a {
  color: var(--brick-dark);
  text-decoration: underline;
  text-decoration-style: dotted;
}

.shop-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.shop-action {
  appearance: none;
  background: transparent;
  border: 1.5px solid var(--ink-soft);
  color: var(--ink-soft);
  border-radius: 999px;
  font-family: "Caveat", cursive;
  font-size: 16px;
  padding: 3px 10px 4px;
  cursor: pointer;
}
.shop-action.active { background: var(--ink); color: var(--cream); border-color: var(--ink); }
.shop-action.dismiss.active { background: var(--ink-soft); }
.shop-action.contact.active { background: var(--olive); border-color: var(--olive); color: var(--cream); }

/* leaflet map polygons */
.leaflet-tile-pane { /* let watercolor through */ }

.shop-marker {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  box-shadow: 1px 1px 0 var(--ink);
  background: var(--khaki);
}
.shop-marker.hot { background: var(--hot); }
.shop-marker.warm { background: var(--warm); }
.shop-marker.cold { background: var(--cold); }

.you-marker {
  width: 16px; height: 16px;
  background: var(--brick);
  border: 3px solid var(--cream);
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--brick), 1px 1px 0 var(--ink);
}

/* toast */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%) translateY(20px);
  z-index: 60;
  background: var(--ink);
  color: var(--cream);
  padding: 10px 16px;
  border-radius: 4px;
  font-family: "EB Garamond", Georgia, serif;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: 3px 3px 0 var(--khaki);
  max-width: 80vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* leaflet attribution tweak — fits paper aesthetic */
.leaflet-control-attribution {
  background: rgba(250, 243, 224, 0.85) !important;
  font-family: "EB Garamond", serif !important;
  font-size: 10px !important;
  color: var(--ink-soft) !important;
}
.leaflet-control-attribution a { color: var(--brick-dark) !important; }
.leaflet-control-zoom { display: none; }

/* clickable shop row hover state */
.shop:hover .shop-name { color: var(--brick-dark); }
.shop.focused {
  background: var(--cream-deep);
  border-radius: 6px;
  box-shadow: inset 3px 0 0 var(--brick);
}

/* tablet/desktop — pin sheet to RIGHT side, always visible */
@media (min-width: 720px) {
  .sheet {
    position: absolute;
    top: 12px;
    right: 12px;
    bottom: 12px;
    left: auto;
    width: 380px;
    max-height: none;
    border-radius: 14px;
    border: 2.5px solid var(--ink);
    box-shadow: 4px 4px 0 var(--khaki), 0 8px 30px rgba(60, 40, 20, 0.18);
    transform: translateY(0);
    /* always open on desktop, transform-on-mobile is overridden here */
  }
  .sheet:not(.open) { transform: translateY(0); }
  .sheet-handle { display: none; }
  #sheet-close { display: none; }  /* desktop panel stays open */
  .topbar { right: 410px; }  /* leave room for the panel */
  .scan-btn { left: calc(50% - 200px); transform: none; }
  .scan-btn:active { transform: translate(2px, 2px); }
  .toast { left: calc(50% - 200px); transform: translateX(-50%) translateY(20px); }
  .toast.show { transform: translateX(-50%) translateY(0); }
}

/* big desktop — wider panel for big monitors */
@media (min-width: 1280px) {
  .sheet { width: 440px; }
  .topbar { right: 470px; }
  .scan-btn { left: calc(50% - 230px); }
  .toast { left: calc(50% - 230px); }
}
