:root {
  --bg: #101317;
  --panel: #2a3038;
  --panel-raised: #363d47;
  --border: #4a515c;
  --border-strong: #5a6371;
  --accent: #ffb020;
  --accent-ink: #171308;
  --text: #f4f6f8;
  --text-dim: #9fb0d8;
  --text-faint: #8ea0ad;
  --radius-sm: 4px;
  --radius-md: 8px;
  --font-display: "Archivo", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::-webkit-scrollbar {
  width: 10px;
}
::-webkit-scrollbar-track {
  background: var(--panel);
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 6px;
  border: 2px solid var(--panel);
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */

.topbar {
  flex-shrink: 0;
  height: 64px;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 12px;
  z-index: 20;
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.brand-name {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.2px;
}

.status-pill {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
  cursor: pointer;
}

.status-pill:hover {
  border-color: var(--border-strong);
}

.status-pill.is-live {
  color: var(--accent);
  border-color: var(--accent);
}

.icon-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.icon-btn:hover {
  background: var(--panel-raised);
  border-color: var(--border-strong);
}
.icon-btn:active {
  background: var(--panel-raised);
}

/* ---------- Stage: map + sheet ---------- */

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.map {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--panel);
}

/* Standard OpenStreetMap raster tiles, re-toned to the dark board palette.
   No dark-tile provider needed - works anywhere, no API key. */
.map-tiles-dark {
  filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.92) saturate(0.6);
}

/* user position marker: a steady dot plus a pulsing radar ring */
.user-location-dot {
  position: relative;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
}
.leaflet-div-icon.user-location-dot {
  background: var(--accent);
  border: 3px solid var(--bg);
}
.user-location-dot::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: rgba(255, 176, 32, 0.35);
  animation: locationPulse 2.2s cubic-bezier(0.2, 0.7, 0.3, 1) infinite;
}
@keyframes locationPulse {
  from {
    transform: scale(0.6);
    opacity: 0.8;
  }
  to {
    transform: scale(2.6);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .user-location-dot::after {
    animation: none;
    opacity: 0;
  }
}

.listing-pin {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--text-faint);
}
.listing-pin.is-new {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 176, 32, 0.3);
}
.leaflet-div-icon.listing-pin {
  border: 2px solid var(--bg);
}

.leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
}
.leaflet-popup-tip {
  background: var(--panel);
}
.leaflet-popup-content {
  font-family: var(--font-display);
  margin: 12px 14px;
}
.popup-title {
  font-weight: 700;
  margin: 0 0 4px;
  font-size: 14px;
}
.popup-price {
  color: var(--accent);
  font-weight: 700;
  margin: 0 0 4px;
  font-family: var(--font-mono);
}
.popup-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 8px;
}
.leaflet-popup-content a {
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
}

/* ---------- Bottom sheet (mobile) ---------- */

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 56px;
  z-index: 15;
  background: var(--panel);
  border: 2px solid var(--border);
  border-bottom: none;
  box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  touch-action: none;
  will-change: transform;
}

.sheet-handle {
  flex-shrink: 0;
  height: 28px;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
.sheet-handle span {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
}

.radius-row {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 18px 14px;
  border-bottom: 2px solid var(--border);
}
.radius-row label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.radius-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}
.radius-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
  min-width: 52px;
  text-align: right;
}

.board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.board-head {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px 92px;
  gap: 10px;
  padding: 10px 18px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-faint);
  border-bottom: 2px solid var(--border);
}

.board-rows {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 24px;
}

.board-empty {
  padding: 32px 18px;
  text-align: center;
  color: var(--text-faint);
  font-size: 14px;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px 92px;
  gap: 10px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 2px solid var(--border);
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
}
.row:hover {
  background: var(--panel-raised);
}
.row:active {
  background: var(--panel-raised);
}

.row-find {
  min-width: 0;
}
.row-find h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-find .meta {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-find .price {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
}
.row-matches {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.match-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 3px;
  padding: 2px 6px;
}

.row-dist {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.row-status {
  justify-self: start;
}
.status-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-strong);
  color: var(--text-dim);
}
.status-badge.is-new {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

@keyframes rowEnter {
  from {
    transform: translateY(10px);
    opacity: 0;
    background-color: rgba(255, 176, 32, 0.22);
  }
  60% {
    background-color: rgba(255, 176, 32, 0.22);
  }
  to {
    transform: translateY(0);
    opacity: 1;
    background-color: transparent;
  }
}
.row.row-enter {
  animation: rowEnter 0.9s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ---------- Ambient saved-searches strip (idle glance, read-only) ---------- */

.ambient-searches {
  flex-shrink: 0;
  max-height: 150px;
  overflow-y: auto;
  border-top: 2px solid var(--border);
  padding: 12px 18px;
}
.ambient-searches h4 {
  margin: 0 0 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1.5px;
  font-weight: 700;
  color: var(--text-faint);
}
.ambient-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
}
.ambient-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.ambient-dot.is-active {
  background: var(--accent);
}
.ambient-dot.is-error {
  background: #ff6b5e;
}
.ambient-row .name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ambient-row .status-text {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

.error-state {
  padding: 24px 18px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

/* ---------- Search management overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
  display: flex;
  align-items: flex-end;
}
.overlay.hidden {
  display: none;
}

.manage-sheet {
  width: 100%;
  max-height: 86vh;
  background: var(--panel);
  border: 2px solid var(--border);
  border-bottom: none;
  display: flex;
  flex-direction: column;
  animation: sheetUp 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes sheetUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.manage-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 14px;
  border-bottom: 2px solid var(--border);
}
.manage-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.create-form {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 2px solid var(--border);
}
.create-form input {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 12px;
  font-size: 14px;
  font-family: var(--font-display);
}
.create-form input::placeholder {
  color: var(--text-faint);
}
.field-row {
  display: flex;
  gap: 10px;
}
.field-row input {
  flex: 1;
  min-width: 0;
}

.primary-btn {
  flex-shrink: 0;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 800;
  font-size: 14px;
  padding: 0 18px;
  white-space: nowrap;
}
.primary-btn:hover {
  background: #ffc34d;
}
.primary-btn:active {
  opacity: 0.85;
}

.searches-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 18px 24px;
}

.search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 2px solid var(--border);
}
.search-item .si-main {
  flex: 1;
  min-width: 0;
}
.search-item h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}
.search-item .si-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 3px;
}
.search-item .si-meta.is-error {
  color: #ff6b5e;
}
.si-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.si-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-strong);
  background: var(--panel-raised);
  color: var(--text-dim);
}
.si-btn:hover {
  background: var(--border);
  color: var(--text);
}
.si-btn.is-active {
  color: var(--accent);
  border-color: var(--accent);
}
.si-btn.is-active:hover {
  background: var(--panel-raised);
  color: var(--accent);
}
.si-btn.danger {
  color: #ff6b5e;
  border-color: #5a2a26;
}
.si-btn.danger:hover {
  background: #3a1e1c;
  color: #ff6b5e;
}

/* ---------- Desktop layout ---------- */

@media (min-width: 900px) {
  .sheet {
    left: auto;
    top: 0;
    width: 420px;
    border: none;
    border-left: 2px solid var(--border);
    box-shadow: none;
    transform: none !important;
  }
  .sheet-handle {
    display: none;
  }
  .overlay {
    align-items: center;
    justify-content: center;
  }
  .manage-sheet {
    width: 560px;
    max-height: 80vh;
    border: 2px solid var(--border);
    animation: none;
  }
}
