/* Layout: search bar on top; map fills the left, the swipe deck sits in a 400px panel on the right.
   Below 820px the map goes on top and the panel follows underneath. */
:root {
  --bg: #F3F4F1;
  --surface: #FFFFFF;
  --ink: #1C2024;
  --muted: #5B636A;
  --line: #DADDD6;
  --job: #2B5A9B;
  --keep: #13724F;
  --nope: #B1452D;
  --current: #E3A008;
  --on-pin: #FFFFFF;
  --shadow: 0 1px 2px rgb(20 24 28 / .06), 0 10px 28px rgb(20 24 28 / .10);
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --surface: #1B1F23;
    --ink: #E8EBED;
    --muted: #9BA4AC;
    --line: #2D3339;
    --job: #7EA5E0;
    --keep: #4FC28F;
    --nope: #EA7C62;
    --current: #F2C14E;
    --on-pin: #111417;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 10px 28px rgb(0 0 0 / .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--job); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 24px;
  padding-block: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-top: max(12px, env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.brand small {
  display: block;
  font-size: .78rem;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--muted);
}
.search {
  flex: 1 1 560px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 10px;
  min-width: 0;
}
.field {
  display: grid;
  gap: 4px;
  min-width: 0;
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
}
.field em { font-style: normal; font-weight: 400; }
.field.where { flex: 1 1 180px; }
.field.what { flex: 1 1 150px; }
.field.radius { flex: 0 1 170px; }
.field output { color: var(--ink); font-variant-numeric: tabular-nums; }
input[type="search"] {
  height: 38px;
  width: 100%;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: .95rem;
  font-weight: 400;
}
input[type="range"] { width: 100%; height: 38px; margin: 0; accent-color: var(--job); }

button {
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--ink); border-color: var(--ink); color: var(--surface); }
button.ghost { background: transparent; }
button.small { height: 32px; padding: 0 10px; font-size: .85rem; }

.banner {
  padding-block: 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: color-mix(in srgb, var(--current) 22%, var(--surface));
  border-bottom: 1px solid var(--line);
  font-size: .88rem;
}

/* ---------- Map + panel ---------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
}
.map { min-height: 320px; background: var(--bg); }
.panel {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px 20px;
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-left: 1px solid var(--line);
}

.tabs { display: flex; gap: 6px; }
.tabs button { flex: 1; height: 36px; border-radius: 999px; font-size: .9rem; }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.count {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 .4em;
  border-radius: 999px;
  background: var(--keep);
  color: var(--on-pin);
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
}

#deck-view { display: flex; flex-direction: column; gap: 12px; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 12px; }
.status { margin: 0; flex: 1 1 200px; font-size: .85rem; color: var(--muted); }
.status.error { color: var(--nope); font-weight: 600; }
.order { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.order select {
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .85rem;
}

/* ---------- Cards ---------- */
.deck { display: grid; min-height: 360px; }
.deck > * { grid-area: 1 / 1; }
.card {
  position: relative;
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 18px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  touch-action: pan-y;
  user-select: none;
  cursor: grab;
  transition: transform .28s ease, opacity .28s ease;
}
.card.under { transform: translateY(10px) scale(.96); opacity: .55; pointer-events: none; }
.card.dragging { transition: none; cursor: grabbing; }
.card.leaving { opacity: 0; }
.card.info { cursor: default; touch-action: auto; user-select: text; }
.card h2 { margin: 0; font-size: 1.3rem; line-height: 1.2; letter-spacing: -0.01em; text-wrap: balance; }
.card p { margin: 0; }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chip {
  padding: 2px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--job) 14%, var(--surface));
  color: var(--job);
  font-size: .78rem;
  font-weight: 650;
}
.dist { font-size: .85rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.company { color: var(--muted); }
.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin: 2px 0 0;
  font-size: .88rem;
}
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.snippet { font-size: .92rem; color: var(--ink); }
.open { justify-self: start; color: var(--job); font-weight: 650; }
.sample-note { font-size: .8rem; color: var(--muted); }
.stamp {
  position: absolute;
  top: 14px;
  padding: 3px 10px;
  border: 2px solid currentColor;
  border-radius: 6px;
  background: var(--surface);
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  pointer-events: none;
}
.stamp.keep { right: 14px; color: var(--keep); opacity: var(--keep-o, 0); }
.stamp.nope { left: 14px; color: var(--nope); opacity: var(--nope-o, 0); }
.card.info h2 { font-size: 1.15rem; }
.card.info ol { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; }
.card.loading { color: var(--muted); }

.actions { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.actions .nope { color: var(--nope); border-color: color-mix(in srgb, var(--nope) 45%, var(--line)); }
.actions .keep { color: var(--keep); border-color: color-mix(in srgb, var(--keep) 45%, var(--line)); }
.hint { margin: 0; text-align: center; font-size: .78rem; color: var(--muted); }

/* ---------- Saved list ---------- */
.saved-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.saved-list li {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.saved-list .title { font-weight: 650; }
.saved-list .meta { font-size: .85rem; color: var(--muted); }
.saved-list .row { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-top: 4px; }
.saved-list a { color: var(--job); font-weight: 600; font-size: .9rem; }
.saved-list .empty { background: transparent; border-style: dashed; color: var(--muted); }

/* ---------- Map pins ---------- */
.pin-wrap { background: none; border: 0; }
.pin {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--job);
  color: var(--on-pin);
  box-shadow: 0 1px 4px rgb(0 0 0 / .35);
  font: 700 11px/1 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: transform .15s ease;
}
.pin.saved { background: var(--keep); }
.pin.current { background: var(--current); color: #1C2024; transform: scale(1.3); }
.center-pin {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--ink);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 2px var(--ink);
}
.leaflet-container { font: inherit; }

/* ---------- Phone ---------- */
@media (max-width: 820px) {
  body { height: auto; min-height: 100%; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .map { height: 44vh; }
  .panel {
    overflow: visible;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
  }
  .field.radius { flex: 1 1 140px; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .pin { transition: none; }
}
