/* ============================================================
   Small Black Coffee Index — Stylesheet
   Matches erickrueger.com design system
   ============================================================ */


/* ── Variables (light mode) ───────────────────────────────── */

:root {
  --width:   800px;
  --font:    Verdana, sans-serif;
  --bg:      #fff;
  --heading: #222;
  --text:    #444;
  --link:    #3273dc;
  --visited: #8b6fcb;
  --subtle:  #888;
  --border:  #ddd;
  --code-bg: #f2f2f2;

  /* Spacing scale */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --space-xl:  2.5rem;
  --space-2xl: 4rem;

  /* Surface — subtle background for cards and callout boxes */
  --surface: #f7f5f2;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #01242e;
    --heading: #eee;
    --text:    #ddd;
    --link:    #8cc2dd;
    --visited: #c9b8e8;
    --subtle:  #7aabb8;
    --border:  #1e4a57;
    --code-bg: #000;
    --surface: #012030;
  }
}


/* ── Reset ────────────────────────────────────────────────── */

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


/* ── Base ─────────────────────────────────────────────────── */

body {
  font-family: var(--font);
  font-size: 1em;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  padding: 20px;
  animation: page-in 0.2s ease-out;
}

@keyframes page-in {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

a {
  color: var(--link);
}

a:visited {
  color: var(--visited);
}

h1, h2, h3 {
  color: var(--heading);
  line-height: 1.3;
}


/* ── Layout ───────────────────────────────────────────────── */

.container {
  max-width: var(--width);
  margin: 0 auto;
}


/* ── Header ───────────────────────────────────────────────── */

header {
  max-width: var(--width);
  margin: 0 auto 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1rem;
}

.site-name {
  font-size: 1.5rem;
  font-weight: bold;
  text-decoration: none;
  color: var(--heading);
  line-height: 1;
  display: block;
}

.site-name:visited {
  color: var(--heading);
}

.header-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1rem;
  align-items: center;
}

.header-nav a {
  text-decoration: none;
  color: var(--link);
  white-space: nowrap;   /* Prevent individual link text from breaking mid-phrase */
}

.header-nav a:hover {
  color: var(--link);
  text-decoration: underline;
}

.btn-nav {
  background: var(--link);
  color: #fff !important;
  padding: 0.3rem 0.85rem;
  border-radius: 3px;
  text-decoration: none !important;
  font-weight: bold;
  transition: opacity 0.15s;
}

.btn-nav:hover {
  opacity: 0.85;
  text-decoration: none !important;
}

@media (prefers-color-scheme: dark) {
  .btn-nav { color: #01242e !important; }
}


/* ── Stats bar ────────────────────────────────────────────── */

.stats-bar {
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
  font-size: 0.85rem;
  color: var(--subtle);
  flex-wrap: wrap;
}

.stat strong {
  display: block;
  font-size: 1.4rem;
  color: var(--heading);
  line-height: 1.2;
}

/* Skeleton shimmer — applied by JS while stats are loading */
@keyframes shimmer {
  0%   { background-position:  200% 0; }
  100% { background-position: -200% 0; }
}

.stat-skeleton {
  background: linear-gradient(
    90deg,
    var(--border) 25%,
    color-mix(in srgb, var(--border) 40%, var(--bg)) 50%,
    var(--border) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 3px;
  color: transparent !important;
  min-width: 2.5rem;
  user-select: none;
}


/* ── Sections ─────────────────────────────────────────────── */

section {
  margin-bottom: 2.5rem;
}

h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--subtle);
  font-weight: normal;
  margin-bottom: 0.6rem;
}

.section-desc {
  font-size: 0.85rem;
  color: var(--subtle);
  margin-bottom: 0.8rem;
}


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

#map {
  height: 480px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* Custom map marker — dot style */
.map-dot-marker {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Do NOT set position: relative here — Leaflet's CSS sets
     position: absolute on .leaflet-marker-icon. Overriding it with
     position: relative breaks marker placement on the map. */
  background: none;
  border: none;
}

.dot-core {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--link);
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
  position: relative; /* establishes z-index stacking without breaking flex */
  z-index: 1;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.map-dot-marker.marker-active .dot-core {
  transform: scale(1.25);
}

.dot-ripple {
  /* Absolutely positioned relative to the marker element (position:absolute
     from Leaflet). Centered explicitly since abs-positioned elements are
     removed from flex layout. */
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  border: 2px solid var(--link);
  opacity: 0;
  pointer-events: none;
}

.map-dot-marker.marker-active .dot-ripple {
  animation: dot-ripple-expand 1.5s ease-out infinite;
}

@keyframes dot-ripple-expand {
  0%   { transform: scale(1);   opacity: 0.35; }
  100% { transform: scale(5.5); opacity: 0;    }
}

/* Multi-report business marker — coffee-amber dot */
.marker-multi .dot-core {
  background: #c07a3a;
  width: 11px;
  height: 11px;
}

.marker-multi .dot-ripple {
  border-color: #c07a3a;
}

/* ── Map popup — premium card ──────────────────────────────── */

/* Wrapper: rounded card, layered shadow, no border */
.leaflet-popup-content-wrapper {
  border-radius: 14px !important;
  border: none !important;
  box-shadow:
    0 2px 4px  rgba(0,0,0,0.06),
    0 8px 24px rgba(0,0,0,0.14),
    0 1px 2px  rgba(0,0,0,0.08) !important;
  padding: 0 !important;
  overflow: hidden;
  transform-origin: 50% 100%; /* scale up from bottom toward the marker */
  animation: popup-card-in 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popup-card-in {
  from { opacity: 0; transform: scale(0.92) translateY(5px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);   }
}

@media (prefers-reduced-motion: reduce) {
  .leaflet-popup-content-wrapper { animation: none; }
}

/* Inner content: zero margin so .popup-card controls all spacing */
.leaflet-popup-content {
  margin: 0 !important;
  line-height: 1.5;
}

/* Close button — small circular × */
.leaflet-popup-close-button {
  top:    9px !important;
  right:  9px !important;
  width:  20px !important;
  height: 20px !important;
  border-radius: 50% !important;
  background: rgba(0,0,0,0.07) !important;
  color: #777 !important;
  font-size: 12px !important;
  line-height: 20px !important;
  text-align: center !important;
  padding: 0 !important;
  transition: background 0.12s, color 0.12s !important;
  text-decoration: none !important;
}

.leaflet-popup-close-button:hover {
  background: rgba(0,0,0,0.15) !important;
  color: #222 !important;
}

/* ── Popup card layout ─────────────────────────────────────── */
/* Popup is always light — it's overlaid on the dark map tile,
   so we use hardcoded light-mode colors rather than CSS vars.   */

.popup-card {
  padding: 14px 16px 13px;
  min-width: 210px;
  max-width: 272px;
  font-family: Verdana, sans-serif;
  font-size: 0.84rem;
  color: #444;
  background: #fff;
}

.popup-name {
  font-size: 0.91rem;
  font-weight: bold;
  color: #111;
  line-height: 1.3;
  padding-right: 22px; /* clear of close button */
}

.popup-city {
  font-size: 0.77rem;
  color: #999;
  margin-top: 1px;
}

.popup-price-row {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-top: 9px;
}

.popup-price {
  font-size: 1.65rem;
  font-weight: bold;
  line-height: 1;
  color: #3273dc;
  font-variant-numeric: tabular-nums;
}

.popup-price-sub {
  font-size: 0.77rem;
  color: #bbb;
  line-height: 1;
}

.popup-meta {
  font-size: 0.75rem;
  color: #aaa;
  margin-top: 4px;
}

.popup-divider {
  height: 1px;
  background: #f0f0f0;
  margin: 10px -16px;
}

/* Report rows inside group popup */
.popup-reports {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.79rem;
}

.popup-report-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
  color: #666;
}

.popup-report-row strong {
  color: #222;
  font-variant-numeric: tabular-nums;
}

.popup-report-link {
  margin-left: auto;
  color: #3273dc;
  text-decoration: none;
  font-size: 0.72rem;
  opacity: 0.7;
  white-space: nowrap;
  transition: opacity 0.1s;
}

.popup-report-link:hover {
  opacity: 1;
  text-decoration: underline;
}

.popup-more {
  font-size: 0.74rem;
  color: #ccc;
  margin-top: 2px;
}

/* Link pill buttons */
.popup-links {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}

.popup-link {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 9999px;
  border: 1px solid #e2e2e2;
  font-size: 0.73rem;
  color: #555;
  text-decoration: none !important;
  white-space: nowrap;
  line-height: 1.5;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.popup-link:hover {
  border-color: #3273dc;
  color: #3273dc;
  background: rgba(50, 115, 220, 0.06);
}

/* Conf badges: always light-mode values inside the white popup */
.popup-card .conf-verified   { color: #2a7a2a; background: rgba(42,122,42,0.10);  }
.popup-card .conf-unverified { color: #b06000; background: rgba(176,96,0,0.10);   }

/* ── Popup embedded hyperlinks ─────────────────────────────── */
/* Leaflet sets .leaflet-container a { color: #0078a8 } with specificity
   (0,1,1). We prefix every rule with .popup-card to reach (0,2,x) and
   win. We also override :visited on each to prevent the browser's
   default purple on a white card.                                    */

/* Shop name → shop page
   Dotted underline is always visible (heading-links need a permanent
   affordance since hover isn't discoverable on first glance).
   Solid underline on hover confirms interactivity. */
/* Including the `a` element type in each selector gives specificity
   (0,2,1), which beats Leaflet's color rule regardless of load order. */
.popup-card a.popup-name-link,
.popup-card a.popup-name-link:visited {
  color: #111;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: rgba(0,0,0,0.22);
  text-underline-offset: 2px;
}
.popup-card a.popup-name-link:hover {
  text-decoration-style: solid;
  text-decoration-color: rgba(0,0,0,0.45);
}

/* City → Apple Maps (external)
   A permanent ↗ glyph via ::after signals "opens elsewhere" without
   needing underlines — the arrow is the affordance. */
.popup-card a.popup-city-link,
.popup-card a.popup-city-link:visited {
  color: #999;
  text-decoration: none;
}
.popup-card a.popup-city-link::after {
  content: ' ↗';
  font-size: 0.72em;
  opacity: 0.55;
}
.popup-card a.popup-city-link:hover {
  color: #666;
}

/* Price → entry page
   Blue is already a strong affordance. Keep it blue after visiting
   (override purple). Underline on hover only — permanent underline
   under a large number looks heavy. */
.popup-card a.popup-price,
.popup-card a.popup-price:visited {
  color: #3273dc;
  text-decoration: none;
  text-underline-offset: 2px;
}
.popup-card a.popup-price:hover {
  text-decoration: underline;
  text-decoration-color: rgba(50,115,220,0.5);
}

/* Report row prices → individual entry pages
   Hover turns them the brand blue; stays dark after visiting. */
.popup-card .popup-report-price,
.popup-card .popup-report-price:visited {
  font-weight: bold;
  font-variant-numeric: tabular-nums;
  color: #222;
  text-decoration: none;
  text-underline-offset: 2px;
}
.popup-card .popup-report-price:hover {
  color: #3273dc;
  text-decoration: underline;
  text-decoration-color: rgba(50,115,220,0.4);
}


/* ── Chart ────────────────────────────────────────────────── */

.chart-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.2rem;
}

#trend-chart {
  max-height: 300px;
}


/* ── Submit form ──────────────────────────────────────────── */

.submit-intro {
  margin-bottom: 1.8rem;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text);
}

.field {
  margin-bottom: 1.4rem;
}

.field-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.field-grow  { flex: 1; }
.field-shrink { flex: 0 0 130px; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: bold;
  color: var(--heading);
  margin-bottom: 0.35rem;
}

.optional {
  font-weight: normal;
  color: var(--subtle);
}

input[type="text"],
input[type="number"],
input[type="password"],
select {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 0.95rem;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
select:focus {
  outline: none;
  border-color: var(--link);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--link) 20%, transparent);
}

input[type="file"] {
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--subtle);
  width: 100%;
}

.hint {
  font-size: 0.78rem;
  color: var(--subtle);
  margin-top: 0.3rem;
}

.hint-warn {
  font-size: 0.78rem;
  color: #b06000;
  margin-top: 0.3rem;
}

@media (prefers-color-scheme: dark) {
  .hint-warn { color: #e0a050; }
}

/* Location autocomplete */
.location-wrap {
  position: relative;
}

.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 3px 3px;
  list-style: none;
  margin: 0;
  padding: 0;
  z-index: 100;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.suggestions li {
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  line-height: 1.4;
}

.suggestions li:last-child {
  border-bottom: none;
}

.suggestions li:hover,
.suggestions li.active {
  background: color-mix(in srgb, var(--link) 10%, transparent);
  color: var(--heading);
}

.suggestions li .suggestion-name {
  font-weight: bold;
  display: block;
}

.suggestions li .suggestion-addr {
  color: var(--subtle);
  font-size: 0.78rem;
}

/* Confirmed location display */
.location-confirmed {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  background: color-mix(in srgb, var(--link) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--link) 30%, transparent);
  border-radius: 3px;
  font-size: 0.85rem;
}

.location-confirmed-text {
  flex: 1;
  line-height: 1.4;
  color: var(--text);
}

.location-confirmed-coords {
  font-size: 0.75rem;
  color: var(--subtle);
  margin-top: 0.15rem;
  font-family: monospace;
}

.btn-text {
  background: none;
  border: none;
  color: var(--link);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.82rem;
  padding: 0;
  text-decoration: underline;
  white-space: nowrap;
}

/* Submit button */
.btn-submit {
  display: block;
  width: 100%;
  padding: 0.75rem 1.4rem;
  background: var(--link);
  color: #fff;
  border: none;
  border-radius: 3px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: opacity 0.15s;
}

/* In dark mode the link color is a light blue — use dark text for contrast */
@media (prefers-color-scheme: dark) {
  .btn-submit { color: #01242e; }
}

.btn-submit:hover    { opacity: 0.85; }
.btn-submit:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-submit:focus-visible,
#scan-btn:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

.btn-nav:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.btn-text:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Status messages */
#status {
  display: none;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 3px;
  font-size: 0.88rem;
  line-height: 1.5;
}

#status.success {
  display: block;
  background: color-mix(in srgb, #2a7a2a 10%, transparent);
  border: 1px solid color-mix(in srgb, #2a7a2a 30%, transparent);
  color: var(--text);
}

#status.error {
  display: block;
  background: color-mix(in srgb, #c0392b 10%, transparent);
  border: 1px solid color-mix(in srgb, #c0392b 30%, transparent);
  color: var(--text);
}


/* ── How it works ─────────────────────────────────────────── */

.steps {
  list-style: none;
  counter-reset: step-counter;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.steps li {
  counter-increment: step-counter;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.steps li::before {
  content: counter(step-counter);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: var(--link);
  color: #fff;
  font-size: 0.72rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

@media (prefers-color-scheme: dark) {
  .steps li::before { color: #01242e; }
}

.steps li strong {
  display: block;
  color: var(--heading);
  font-size: 0.88rem;
  margin-bottom: 0.25rem;
}

.steps li span {
  display: block;
  font-size: 0.8rem;
  color: var(--subtle);
  line-height: 1.5;
}


/* ── Share buttons ────────────────────────────────────────── */

.btn-share {
  display: inline-block;
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.3rem 0.75rem;
  font-family: var(--font);
  font-size: 0.8rem;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-share:hover { border-color: var(--link); color: var(--link); }

.btn-share:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}


/* ── Footer ───────────────────────────────────────────────── */

footer {
  max-width: var(--width);
  margin: 3rem auto 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--subtle);
}

footer a { color: var(--subtle); }


/* ── Scan tabs ────────────────────────────────────────────── */

.scan-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.tab-btn {
  flex: 1;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  font-family: var(--font);
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  text-align: center;
  white-space: nowrap;
}

.tab-btn:hover {
  border-color: var(--link);
  color: var(--link);
}

.tab-btn.active {
  background: var(--link);
  border-color: var(--link);
  color: #fff;
  font-weight: bold;
}

@media (prefers-color-scheme: dark) {
  .tab-btn.active { color: #01242e; }
}


/* ── Best Value badge (shop page) ─────────────────────────── */
/* Designed to be screenshot-able and shareable by businesses.  */

.best-value-badge {
  display: inline-flex;
  flex-direction: column;
  gap: 0.15rem;
  background: color-mix(in srgb, #c07a3a 10%, transparent);
  border: 1.5px solid #c07a3a;
  border-radius: 6px;
  padding: 0.65rem 1.1rem;
  margin: 0.8rem 0 0.4rem;
  color: #c07a3a;
  font-weight: bold;
  font-size: 0.95rem;
  line-height: 1.3;
}

.best-value-badge .badge-sub {
  font-weight: normal;
  font-size: 0.72rem;
  color: var(--subtle);
}


/* ── Confidence badges ─────────────────────────────────────── */

.conf-badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 2px;
  font-weight: bold;
  vertical-align: middle;
  margin-left: 0.3rem;
}

.conf-verified {
  background: color-mix(in srgb, #2a7a2a 15%, transparent);
  color: #2a7a2a;
}

.conf-unverified {
  background: color-mix(in srgb, #b06000 15%, transparent);
  color: #b06000;
}

@media (prefers-color-scheme: dark) {
  .conf-verified   { color: #5fcf5f; background: color-mix(in srgb, #5fcf5f 15%, transparent); }
  .conf-unverified { color: #f0a040; background: color-mix(in srgb, #f0a040 15%, transparent); }
}


/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 600px) {
  body { padding: 12px; }

  .header-nav {
    gap: 0.3rem 0.5rem;
  }

  .stats-bar { gap: 1.2rem; }

  .field-row {
    flex-direction: column;
  }
  .field-shrink { flex: 1; }

  #map { height: 320px; }
}
