/* =======================================================================
   Paisley Park design tokens
   Palette:  --bg (ink) / --surface / --border / --text / --text-muted
             --accent (rust — pins, primary actions, alerts)
             --safe   (sage — moderation / trust / verified)
             --redact (near-black bar used as the recurring "redaction"
                       motif — the site's signature device)
   Type:     Lora (display, serif, restrained) / Inter (body) /
             IBM Plex Mono (case numbers, timestamps, meta — documentary feel)
   ======================================================================= */

:root{
  --bg: #10151c;
  --surface: #1a222c;
  --surface-2: #212b37;
  --border: #2c3846;
  --text: #edeae2;
  --text-muted: #8c97a6;
  --accent: #c4432b;
  --accent-dim: #8f3323;
  --accent-tint: rgba(196,67,43,0.14);
  --safe: #4e7c6b;
  --safe-tint: rgba(78,124,107,0.16);
  --redact: #05070a;

  --font-display: 'Lora', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;

  --radius: 3px;
  --shadow-panel: -12px 0 40px rgba(0,0,0,0.35);
  --shadow-modal: 0 24px 60px rgba(0,0,0,0.5);
}

*{ box-sizing: border-box; }
html, body{ height: 100%; margin: 0; }
/* The `hidden` attribute must always win over any class's `display`
   property. Without `!important` here, a same-specificity class rule
   like `.modal-backdrop{ display:flex }` can beat the browser's own
   `[hidden]{ display:none }`, leaving the element visible AND
   intercepting clicks even while "hidden". */
[hidden]{ display: none !important; }
body{
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
h1,h2,h3{ font-family: var(--font-display); font-weight: 600; margin: 0; }
p{ margin: 0; }
button{ font-family: inherit; cursor: pointer; }
input, select, textarea{ font-family: inherit; }
a{ color: var(--accent); }

::selection{ background: var(--accent); color: #fff; }

/* focus visibility — accessibility floor */
button:focus-visible, input:focus-visible, textarea:focus-visible,
select:focus-visible, a:focus-visible{
  outline: 2px solid var(--safe);
  outline-offset: 2px;
}

/* =======================================================================
   Intro — signature redaction-reveal
   ======================================================================= */
.intro{
  position: fixed; inset: 0; z-index: 999;
  background: var(--redact);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  animation: introFade .4s ease 1.6s forwards;
}
.intro-word{
  font-size: clamp(2.5rem, 8vw, 5rem);
  letter-spacing: 0.14em;
  color: var(--text);
}
.intro-bar{
  position: absolute; inset: 0;
  background: var(--redact);
  transform-origin: left;
  animation: introWipe 1.1s cubic-bezier(.65,0,.35,1) .3s forwards;
}
@keyframes introWipe{ to{ transform: scaleX(0); } }
@keyframes introFade{ to{ opacity: 0; visibility: hidden; } }

@media (prefers-reduced-motion: reduce){
  .intro{ animation: none; opacity: 0; visibility: hidden; }
  .intro-bar{ animation: none; }
}

/* =======================================================================
   App shell
   ======================================================================= */
.app{ position: relative; width: 100vw; height: 100vh; }

#map{
  position: absolute; inset: 0;
  background: var(--bg);
  filter: saturate(0.65) brightness(0.92) contrast(1.02);
}
.leaflet-tile-pane{ filter: grayscale(0.15); }

/* fallback shown if the Leaflet library fails to load (e.g. no network) */
.map-fallback{
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 8px; text-align: center; padding: 24px;
  color: var(--text-muted); font-size: 0.9rem;
}
.map-fallback strong{ color: var(--text); font-family: var(--font-display); font-size: 1.1rem; }

/* custom pin marker */
.pin{
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid rgba(237,234,226,0.85);
  box-shadow: 0 0 0 5px rgba(196,67,43,0.18);
  position: relative;
}
.pin::after{
  content: "";
  position: absolute; inset: -8px;
  border-radius: 50%;
  border: 1px solid rgba(196,67,43,0.5);
  animation: pinPulse 2.6s ease-out infinite;
}
@keyframes pinPulse{
  0%{ transform: scale(0.6); opacity: 0.9; }
  100%{ transform: scale(1.8); opacity: 0; }
}
@media (prefers-reduced-motion: reduce){ .pin::after{ animation: none; } }

/* preview pin — shown while a business is being added, before it's published */
.pin-preview{
  width: 14px; height: 14px; border-radius: 50%;
  background: transparent;
  border: 2px dashed var(--safe);
  box-shadow: 0 0 0 5px rgba(78,124,107,0.16);
}

.leaflet-popup-content-wrapper, .leaflet-popup-tip{
  background: var(--surface); color: var(--text);
  border-radius: var(--radius); border: 1px solid var(--border);
}
.leaflet-popup-content{ font-family: var(--font-body); font-size: 0.85rem; }
.leaflet-container a.leaflet-popup-close-button{ color: var(--text-muted); }

/* =======================================================================
   Top bar
   ======================================================================= */
.topbar{
  position: absolute; top: 0; left: 0; right: 0; z-index: 500;
  display: flex; align-items: center; gap: 24px;
  padding: 18px 28px;
  background: linear-gradient(to bottom, rgba(16,21,28,0.92), rgba(16,21,28,0));
  pointer-events: none;
}
.topbar > *{ pointer-events: auto; }

.brand{ display: flex; flex-direction: column; line-height: 1.1; margin-right: auto; }
.brand-mark{
  font-family: var(--font-display); font-weight: 600;
  font-size: 1.3rem; letter-spacing: 0.08em;
}
.brand-sub{
  font-family: var(--font-mono); font-size: 0.62rem;
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted);
}

.search{ position: relative; display: flex; align-items: center; width: min(420px, 38vw); }
.search input{
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 10px 40px 10px 14px; border-radius: var(--radius);
  font-size: 0.88rem;
}
.search input::placeholder{ color: var(--text-muted); }
.search button{
  position: absolute; right: 6px; background: none; border: none; color: var(--text-muted);
  padding: 6px; display: flex;
}
.search-results{
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  max-height: 260px; overflow-y: auto; box-shadow: var(--shadow-modal);
}
.search-results button{
  width: 100%; text-align: left; background: none; border: none; color: var(--text);
  padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 0.85rem;
}
.search-results button:last-child{ border-bottom: none; }
.search-results button:hover{ background: var(--surface-2); }
.search-results .empty{ padding: 14px; color: var(--text-muted); font-size: 0.82rem; }
.search-results .result-tag{ font-family: var(--font-mono); font-size: 0.65rem; color: var(--accent); display: block; margin-top: 2px; }

/* =======================================================================
   Buttons
   ======================================================================= */
.btn{
  border-radius: var(--radius); border: 1px solid transparent;
  padding: 10px 16px; font-size: 0.85rem; font-weight: 600;
  transition: transform .12s ease, background .15s ease;
}
.btn:active{ transform: translateY(1px); }
.btn-accent{ background: var(--accent); color: #fff; }
.btn-accent:hover{ background: var(--accent-dim); }
.btn-outline{ background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover{ border-color: var(--text-muted); }
.btn-block{ width: 100%; }

/* =======================================================================
   Toast (add-pin instruction)
   ======================================================================= */
.toast{
  position: absolute; bottom: 64px; left: 50%; transform: translateX(-50%);
  z-index: 500; background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 12px 16px; display: flex; align-items: center;
  gap: 14px; font-size: 0.85rem; box-shadow: var(--shadow-modal);
}
.toast button{
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  border-radius: var(--radius); padding: 6px 10px; font-size: 0.78rem;
}

/* =======================================================================
   Side panel
   ======================================================================= */
.panel{
  position: absolute; top: 0; right: 0; bottom: 0; width: min(420px, 92vw);
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-panel); z-index: 600;
  transform: translateX(100%); transition: transform .32s cubic-bezier(.65,0,.35,1);
  display: flex; flex-direction: column;
}
.panel.open{ transform: translateX(0); }
.panel-scroll{ overflow-y: auto; padding: 56px 24px 32px; flex: 1; }
.panel-close{
  position: absolute; top: 14px; right: 16px; background: none; border: none;
  color: var(--text-muted); font-size: 1.6rem; line-height: 1; z-index: 2;
}
.panel-close:hover{ color: var(--text); }

.tag{
  display: inline-block; font-family: var(--font-mono); font-size: 0.65rem;
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--accent);
  background: var(--accent-tint); border-radius: var(--radius); padding: 4px 8px;
  margin-bottom: 10px;
}
.panel-header h2{ font-size: 1.5rem; margin-bottom: 6px; }
.panel-meta{
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted);
  letter-spacing: 0.03em;
}

.panel-notice{
  margin-top: 20px; padding: 12px 14px; background: var(--safe-tint);
  border: 1px solid var(--safe); border-radius: var(--radius);
  font-size: 0.8rem; line-height: 1.5; color: var(--text);
}
.panel-notice strong{ color: var(--safe); }

/* testimony accordion */
.testimony-list{ margin-top: 22px; display: flex; flex-direction: column; gap: 10px; }
.testimony{
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.testimony-head{
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  background: var(--surface-2); border: none; color: var(--text);
  padding: 12px 14px; font-size: 0.8rem; font-family: var(--font-mono);
}
.testimony-head .case{ color: var(--text-muted); }
.testimony-head .chevron{ transition: transform .2s ease; color: var(--text-muted); }
.testimony.open .chevron{ transform: rotate(180deg); }
.testimony-body{
  max-height: 0; overflow: hidden; transition: max-height .25s ease;
  font-size: 0.88rem; line-height: 1.6; color: var(--text);
  overflow-wrap: break-word; word-break: break-word;
}
.testimony.open .testimony-body{ max-height: 400px; }
.testimony-body-inner{ padding: 14px; }
.testimony-body mark{
  background: var(--redact); color: var(--redact);
  border-radius: 2px; padding: 0 2px;
}

/* composer */
.composer{ margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.composer label{ font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.composer textarea{
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); padding: 10px 12px; font-size: 0.86rem; resize: vertical;
}
.composer-hint{ font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-muted); margin-top: 4px; }
.redaction-preview{
  background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 10px 12px; font-size: 0.85rem; line-height: 1.6; min-height: 44px; color: var(--text-muted);
  overflow-wrap: break-word; word-break: break-word; max-width: 100%;
}
.redaction-preview mark{ background: var(--redact); color: var(--redact); border-radius: 2px; padding: 0 2px; }
.composer-actions{ display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* =======================================================================
   Modals
   ======================================================================= */
.modal-backdrop{
  position: fixed; inset: 0; z-index: 800; background: rgba(5,7,10,0.72);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal{
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(480px, 100%); max-height: 88vh; overflow-y: auto; overflow-x: hidden;
  min-width: 0; padding: 32px;
  box-shadow: var(--shadow-modal); position: relative; display: flex; flex-direction: column; gap: 12px;
}
.modal-doc{ width: min(620px, 100%); }
.modal-close{
  position: absolute; top: 14px; right: 16px; background: none; border: none;
  color: var(--text-muted); font-size: 1.6rem; line-height: 1;
}
.modal-close:hover{ color: var(--text); }
.modal-sub{ color: var(--text-muted); font-size: 0.85rem; margin-bottom: 6px; }
.modal label{ font-size: 0.78rem; color: var(--text-muted); font-weight: 600; margin-top: 4px; }
.modal input, .modal select, .modal textarea{
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); padding: 10px 12px; font-size: 0.86rem;
  width: 100%; max-width: 100%; box-sizing: border-box;
  overflow-wrap: break-word; word-break: break-word;
}
/* Some browsers (notably Safari) ignore inherited color on <option> and
   render the native popup with default (often white-on-white) styling
   unless option itself is styled explicitly. */
.modal select option{
  background: var(--surface-2); color: var(--text);
}
.modal-doc-body{ font-size: 0.88rem; line-height: 1.7; color: var(--text); }
.modal-doc-body h3{ font-size: 1rem; margin-top: 18px; margin-bottom: 6px; color: var(--text); }
.modal-doc-body p{ margin-bottom: 10px; color: var(--text); }
.modal-doc-body ul{ margin: 0 0 10px; padding-left: 20px; }
.modal-doc-body li{ margin-bottom: 6px; }

/* =======================================================================
   Map link verification (paste a Google/Apple Maps link)
   ======================================================================= */
.link-status{
  font-size: 0.8rem; padding: 10px 12px; border-radius: var(--radius);
  border: 1px dashed var(--border); color: var(--text-muted);
}
.link-status.is-checking{ color: var(--text-muted); }
.link-status.is-error{ color: var(--accent); border-color: var(--accent); background: var(--accent-tint); }

.place-confirmed{
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--safe-tint); border: 1px solid var(--safe); border-radius: var(--radius);
  padding: 12px 14px;
}
.place-confirmed-icon{
  color: var(--safe); font-weight: 700; flex-shrink: 0; line-height: 1.4;
}
.place-confirmed-text{ display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.place-confirmed-text strong{ font-size: 0.9rem; color: var(--text); }
.place-confirmed-text span{ font-size: 0.76rem; color: var(--text-muted); }
.place-change{
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  border-radius: var(--radius); padding: 5px 10px; font-size: 0.72rem; flex-shrink: 0;
}
.place-change:hover{ color: var(--text); border-color: var(--text-muted); }

.label-optional{ font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-muted); }

.place-attribution{ font-size: 0.7rem; color: var(--text-muted); }
.place-attribution a{ color: var(--text-muted); text-decoration: underline; }

.modal input:disabled, .modal textarea:disabled, .modal select:disabled{
  opacity: 0.5; cursor: not-allowed;
}
.btn:disabled{ opacity: 0.45; cursor: not-allowed; }
.btn:disabled:hover{ background: var(--accent); }
.btn:disabled:active{ transform: none; }

/* =======================================================================
   Footer
   ======================================================================= */
.footer{
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 500;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: linear-gradient(to top, rgba(16,21,28,0.92), rgba(16,21,28,0));
  font-size: 0.75rem; color: var(--text-muted); pointer-events: none;
}
.footer > *{ pointer-events: auto; }
.footer-credit a{ color: var(--text-muted); text-decoration: underline; }
.footer-links{ display: flex; gap: 18px; }
.footer-links button, .footer-links a{
  background: none; border: none; color: var(--text-muted); font-size: 0.75rem;
  text-decoration: none;
}
.footer-links button:hover, .footer-links a:hover{ color: var(--text); }

/* =======================================================================
   Responsive
   ======================================================================= */
@media (max-width: 720px){
  .topbar{ flex-wrap: wrap; gap: 12px; padding: 14px; }
  .brand{ margin-right: 0; width: 100%; }
  .search{ width: 100%; order: 3; }
  .search-results{ max-height: 45vh; overflow-y: auto; }
  .search-results button{ padding: 12px; }
  .footer{ flex-direction: column; gap: 6px; align-items: flex-start; padding: 10px 14px; }
  .footer-links{ flex-wrap: wrap; gap: 10px; }

  /* Business panel becomes a bottom sheet instead of a right-hand drawer.
     openPanel()/closePanel() only toggle the .open class (script.js), so
     this reuses the existing transform transition, plus a height
     transition for the drag-to-dismiss "expanded" snap point. */
  .panel{
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%; height: 62vh;
    border-left: none; border-top: 1px solid var(--border);
    border-radius: 10px 10px 0 0;
    transform: translateY(100%);
    transition: transform .32s cubic-bezier(.65,0,.35,1), height .32s cubic-bezier(.65,0,.35,1);
    box-shadow: 0 -12px 40px rgba(0,0,0,0.35);
  }
  .panel.open{ transform: translateY(0); }
  .panel.panel--full{ height: 90vh; } /* drag-to-dismiss "expanded" snap point */
  .panel.panel--dragging{ transition: none; } /* live-follow the finger, no easing lag */
  .panel::before{                 /* grab handle */
    content: ""; position: absolute; top: 8px; left: 50%;
    transform: translateX(-50%);
    width: 36px; height: 4px; border-radius: 2px; background: var(--border);
  }

  /* Touch targets */
  .btn{ min-height: 44px; }
  .panel-close{ width: 44px; height: 44px; }
  .testimony-head{ padding: 14px 12px; }

  /* Pinch-zoom is enough on a touch screen, and the control collides
     with the sheet. */
  .leaflet-control-zoom{ display: none; }

  /* Any input under 16px triggers an automatic zoom on focus in iOS
     Safari. The generic type selector alone won't win here: .search
     input, .modal input/select/textarea, and .composer textarea all
     set their own smaller font-size at equal or higher specificity, so
     each is matched explicitly to actually override it on mobile. */
  input, select, textarea,
  .search input,
  .modal input, .modal select, .modal textarea,
  .composer textarea{ font-size: 16px; }

  /* Full-bleed modal so the long new-business form scrolls comfortably. */
  .modal{ max-height: 100dvh; width: 100%; border-radius: 0; }
}

/* =======================================================================
   Safe areas (installed PWA / notched devices, needs viewport-fit=cover)
   ======================================================================= */
.topbar{ padding-top: calc(14px + env(safe-area-inset-top)); }
.footer{ padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
@media (max-width: 720px){
  .panel-scroll{ padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
}
