/* ===== Snuffel — design tokens ===== */
:root {
  --brand: #f97316;          /* warm orange */
  --brand-dark: #ea580c;
  --brand-soft: #fff4ec;
  --ink: #1f2430;
  --ink-soft: #5b6473;
  --line: #e7e9ee;
  --bg: #f7f8fb;
  --card: #ffffff;
  --green: #16a34a;
  --green-soft: #e7f6ed;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(20, 25, 40, .06), 0 1px 3px rgba(20, 25, 40, .08);
  --shadow-md: 0 6px 24px rgba(20, 25, 40, .10);
  --maxw: 1180px;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
/* The [hidden] attribute must win over author display rules (.btn, overlay, etc.) */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }

/* ===== Header ===== */
.app-header {
  position: sticky; top: 0; z-index: 1000;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: var(--maxw); margin: 0 auto;
  padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.brand-mark {
  font-size: 26px; width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--brand-soft); border-radius: 12px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.brand-tag { font-size: 12px; color: var(--ink-soft); }

.lang-switch {
  display: inline-flex; align-items: center; gap: 6px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px 4px 12px;
}
.lang-icon { font-size: 14px; line-height: 1; }
.lang-switch select {
  border: 0; background: transparent; cursor: pointer; outline: none;
  font-family: inherit; font-weight: 600; font-size: 13px; color: var(--ink);
  padding: 4px 2px; max-width: 120px;
}
.lang-switch select:focus-visible { outline: 2px solid var(--brand); border-radius: 6px; }

/* ===== Hero ===== */
.hero {
  background:
    radial-gradient(1200px 400px at 80% -50%, #ffe7d3 0%, transparent 60%),
    linear-gradient(180deg, #fff 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--line);
}
.hero-inner { max-width: var(--maxw); margin: 0 auto; padding: 48px 20px 40px; }
.hero h1 {
  font-size: clamp(28px, 4vw, 44px); line-height: 1.08; letter-spacing: -.02em;
  margin: 0 0 12px; max-width: 18ch;
}
.hero-sub { font-size: clamp(15px, 1.6vw, 18px); color: var(--ink-soft); max-width: 60ch; margin: 0 0 28px; }

.search-bar {
  display: flex; gap: 10px; flex-wrap: wrap;
  background: var(--card); padding: 10px; border-radius: var(--radius);
  box-shadow: var(--shadow-md); border: 1px solid var(--line); max-width: 760px;
}
.search-field {
  flex: 1 1 280px; display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0 14px;
}
.search-icon { font-size: 18px; }
.search-field input {
  flex: 1; border: 0; background: transparent; outline: none;
  font-size: 16px; padding: 14px 0; color: var(--ink);
}
.btn {
  border: 0; cursor: pointer; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 15px; padding: 0 18px;
  display: inline-flex; align-items: center; gap: 8px; min-height: 48px;
  transition: transform .04s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { background: #eef0f5; }

.country-note { margin-top: 16px; font-size: 13px; color: var(--ink-soft); }

/* ===== Controls ===== */
.controls { border-bottom: 1px solid var(--line); background: var(--card); }
.controls-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg);
  border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 600;
  color: var(--ink-soft); user-select: none;
}
.chip .chip-dot { width: 10px; height: 10px; border-radius: 50%; }
.chip.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }

.controls-right { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.radius-control { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-soft); font-weight: 600; }
.radius-control select {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  background: var(--card); font-size: 14px; font-weight: 600; color: var(--ink);
}
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; font-weight: 600; }
.toggle input { position: absolute; opacity: 0; }
.toggle-track {
  width: 42px; height: 24px; background: #cfd4de; border-radius: 999px; position: relative; transition: background .15s ease;
}
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform .15s ease; box-shadow: var(--shadow-sm); }
.toggle input:checked + .toggle-track { background: var(--green); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(18px); }

/* ===== Results layout ===== */
.results-section { max-width: var(--maxw); margin: 0 auto; padding: 20px; }
.results-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 20px; }
.results-head { display: flex; align-items: baseline; gap: 10px; margin: 4px 2px 14px; }
.results-head h2 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
.results-count { font-size: 13px; color: var(--ink-soft); }
.results-list { display: flex; flex-direction: column; gap: 12px; max-height: 70vh; overflow-y: auto; padding-right: 4px; }

/* Result card */
.place {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; gap: 14px; box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.place:hover { border-color: #d4d8e2; box-shadow: var(--shadow-md); }
.place.is-chain { opacity: .92; }
.place-icon {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; font-size: 22px; color: #fff;
}
.place-body { flex: 1; min-width: 0; }
.place-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.place-name { font-weight: 700; font-size: 15px; margin: 0; }
.place-cat { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.place-dist { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.place-addr { font-size: 13px; color: var(--ink-soft); margin: 6px 0 0; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.badge {
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 4px;
}
.badge-independent { background: var(--green-soft); color: var(--green); }
.badge-chain { background: var(--warn-soft); color: var(--warn); }
.badge-via { font-weight: 600; opacity: .75; margin-left: 2px; }
.place-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.place-actions a {
  font-size: 13px; font-weight: 600; text-decoration: none;
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  color: var(--ink); background: var(--bg); display: inline-flex; align-items: center; gap: 6px;
}
.place-actions a.primary { background: var(--brand-soft); border-color: #ffd9bf; color: var(--brand-dark); }
.place-actions a:hover { border-color: #d4d8e2; }

.section-note {
  font-size: 13px; color: var(--warn); background: var(--warn-soft);
  border: 1px solid #f5e3c7; border-radius: var(--radius-sm); padding: 10px 12px; margin: 4px 0 4px;
}
.chains-divider {
  font-size: 12px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase;
  letter-spacing: .04em; margin: 12px 2px 2px; display: flex; align-items: center; gap: 8px;
}
.chains-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.empty-state { text-align: center; color: var(--ink-soft); padding: 40px 20px; }
.empty-state .emoji { font-size: 36px; }

/* Map */
.map-panel { position: sticky; top: 80px; height: 70vh; min-height: 420px; }
#map { width: 100%; height: 100%; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow-sm); z-index: 1; }
.map-legend {
  position: absolute; bottom: 12px; left: 12px; z-index: 500;
  background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 11px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 4px; max-width: 180px;
}
.legend-row { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); font-weight: 600; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.leaflet-popup-content { font-family: 'Inter', sans-serif; margin: 12px 14px; }
.popup-name { font-weight: 700; font-size: 14px; }
.popup-meta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.popup-link { display: inline-block; margin-top: 8px; font-size: 12px; font-weight: 700; color: var(--brand-dark); text-decoration: none; }

/* ===== Status overlay ===== */
.status-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(247, 248, 251, .8); backdrop-filter: blur(2px);
  display: grid; place-items: center;
}
.status-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 28px 32px; text-align: center; max-width: 360px;
}
.status-card p { margin: 14px 0 0; color: var(--ink-soft); }
.spinner {
  width: 36px; height: 36px; border-radius: 50%; margin: 0 auto;
  border: 3px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#statusRetry { margin-top: 16px; }

/* ===== Footer ===== */
.app-footer { border-top: 1px solid var(--line); background: var(--card); margin-top: 24px; }
.footer-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 22px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  font-size: 13px; color: var(--ink-soft);
}
.footer-inner p { margin: 0; }
.footer-roadmap { color: var(--brand-dark); font-weight: 600; }

/* ===== Emergency ===== */
.btn-emergency {
  border: 0; cursor: pointer; border-radius: 999px;
  background: #fee2e2; color: #b91c1c; border: 1px solid #fbcaca;
  font-weight: 700; font-size: 13px; padding: 9px 15px;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn-emergency:hover { background: #fecaca; }
.btn-emergency.is-active { background: #dc2626; color: #fff; border-color: #dc2626; box-shadow: 0 0 0 4px rgba(220,38,38,.18); }
.emergency-banner {
  background: #dc2626; color: #fff; border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 13px; font-weight: 600; margin-bottom: 12px;
  display: flex; gap: 8px; align-items: flex-start; line-height: 1.35;
}
.emergency-note {
  background: #fff4ec; color: var(--warn); border: 1px solid #f5d8bf;
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; margin-bottom: 12px;
}

/* Hours + rating badges */
.badge-open { background: var(--green-soft); color: var(--green); }
.badge-closed { background: #fde8e8; color: #c0392b; }
.badge-247 { background: #eef2ff; color: #4338ca; }
.badge-rating { background: #fff7e6; color: #b7791f; }
.place-hours { font-size: 12px; color: var(--ink-soft); margin: 6px 0 0; display: flex; align-items: center; gap: 5px; }

/* ===== AI symptom checker widget ===== */
.ai-widget { position: fixed; left: 20px; bottom: 20px; z-index: 1500; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.ai-launcher {
  border: 0; cursor: pointer; border-radius: 999px;
  background: var(--ink); color: #fff; font-weight: 700; font-size: 14px;
  padding: 12px 18px; display: inline-flex; align-items: center; gap: 9px;
  box-shadow: var(--shadow-md);
}
.ai-launcher:hover { background: #000; }
.ai-launcher-icon { font-size: 18px; }
.ai-panel {
  width: 340px; max-width: calc(100vw - 40px); height: 440px; max-height: calc(100vh - 120px);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-md); display: flex; flex-direction: column; overflow: hidden;
}
.ai-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--brand-soft), #fff);
}
.ai-head-title { font-weight: 700; font-size: 15px; }
.ai-close { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink-soft); padding: 0 4px; }
.ai-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.ai-msg { max-width: 85%; padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4; }
.ai-msg.bot { background: var(--bg); color: var(--ink); border-bottom-left-radius: 4px; align-self: flex-start; }
.ai-msg.user { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; align-self: flex-end; }
.ai-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.ai-input input { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 14px; outline: none; }
.ai-input input:focus { border-color: var(--brand); }
.ai-input .btn { min-height: 0; padding: 0 14px; font-size: 14px; }
.ai-disclaimer { font-size: 11px; color: var(--ink-soft); padding: 0 14px 10px; text-align: center; }
.ai-msg.typing { display: inline-flex; gap: 4px; align-items: center; }
.ai-msg.typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-soft);
  animation: blink 1.2s infinite both;
}
.ai-msg.typing span:nth-child(2) { animation-delay: .2s; }
.ai-msg.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* List/Map view switch — hidden on desktop, shown on mobile */
.view-switch {
  display: none; margin-left: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px;
}
.view-btn {
  border: 0; background: transparent; cursor: pointer;
  padding: 6px 14px; border-radius: 999px; font-weight: 600; font-size: 13px; color: var(--ink-soft);
}
.view-btn.is-active { background: var(--ink); color: #fff; }

/* Inline search feedback (bad address, location blocked) */
.search-error {
  max-width: 760px; margin: 10px 0 0; padding: 10px 14px;
  background: #fde8e8; color: #b91c1c; border: 1px solid #f8c9c9;
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
}

/* Overlay error state: always offers a way out */
.status-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.status-actions .btn { min-height: 42px; }

/* Off-screen result cards skip layout/paint: long lists stay smooth on phones */
.place { content-visibility: auto; contain-intrinsic-size: auto 170px; }

/* AI messages: keep the model's line breaks, show triage + actions */
.ai-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-urgency {
  display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .02em;
  padding: 3px 8px; border-radius: 999px; margin-bottom: 6px;
}
.ai-urgency-emergency { background: #dc2626; color: #fff; }
.ai-urgency-vet_soon { background: #fff4ec; color: var(--brand-dark); border: 1px solid #ffd9bf; }
.ai-urgency-monitor { background: var(--green-soft); color: var(--green); }
.ai-cta {
  display: block; width: 100%; margin-top: 10px; cursor: pointer;
  border: 0; border-radius: 10px; padding: 10px 12px;
  font-family: inherit; font-size: 13px; font-weight: 700; text-align: center;
}
.ai-cta-emergency { background: #dc2626; color: #fff; }
.ai-cta-emergency:hover { background: #b91c1c; }
.ai-cta-vets { background: var(--ink); color: #fff; }
.ai-cta-trainers { background: #0f766e; color: #fff; }
.ai-input input:disabled, .ai-input .btn:disabled { opacity: .55; cursor: default; }

/* ===== Responsive ===== */
@media (max-width: 880px) {
  .results-layout { grid-template-columns: 1fr; }
  .map-panel { position: relative; top: 0; height: 65vh; min-height: 320px; }
  .results-list { max-height: none; }
  .controls-inner { flex-direction: column; align-items: stretch; }
  .controls-right { justify-content: space-between; }

  /* Compact, swipeable category chips */
  .filters { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .filters::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; }

  /* One view at a time, switched via the List/Map toggle */
  .view-switch { display: inline-flex; }
  .results-layout.view-list .map-panel { display: none; }
  .results-layout.view-map .results-panel { display: none; }
}
@media (max-width: 560px) {
  .hero-inner { padding: 28px 16px 24px; }
  .header-inner { padding: 10px 14px; }
  .brand-tag { display: none; }
  .lang-switch { padding: 3px 8px 3px 10px; }
  .lang-switch select { max-width: 96px; font-size: 12px; }
  .search-bar { padding: 8px; }
  .btn { flex: 1; justify-content: center; }
  .search-field { flex-basis: 100%; }
  .ai-widget { left: 12px; bottom: 12px; right: 12px; }
  /* dvh tracks the on-screen keyboard; vh is the fallback for older browsers */
  .ai-panel { width: 100%; height: 60vh; height: 60dvh; }
  /* Keep the last card and the footer clear of the floating AI launcher */
  .results-section { padding-bottom: 76px; }
  .app-footer { padding-bottom: 64px; }
  .ai-launcher { font-size: 13px; padding: 11px 15px; }
  .controls-inner .btn-emergency { width: 100%; justify-content: center; }
}

/* Cloudflare Turnstile bot check in the AI chat: invisible unless Cloudflare asks for a click */
.ai-botcheck:empty { display: none; }
.ai-botcheck { display: flex; justify-content: center; padding: 4px 8px 0; }
