:root {
  --bg: #0f1419;
  --panel: #1a222c;
  --panel2: #243040;
  --border: #2e3a4a;
  --text: #e8eef5;
  --muted: #8b9bb0;
  --accent: #3d9cf0;
  --good: #3ecf8e;
  --bad: #f07178;
  --warn: #f0b429;
  --radius: 14px;
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "IBM Plex Sans", system-ui, -apple-system, Segoe UI, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}
a { color: var(--accent); }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 2rem 1rem; }
.error { color: var(--bad); font-size: 0.9rem; }

button, input, select, textarea { font: inherit; color: var(--text); }
input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
}
button {
  background: var(--accent);
  border: none;
  border-radius: 10px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  color: #061018;
  font-weight: 700;
}
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.icon-btn { min-height: 40px; padding: 0.4rem 0.7rem; }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100dvh; padding: 1rem; }
.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
}
.login-card h1 { margin: 0 0 0.35rem; font-size: 1.35rem; }
.login-card label { display: block; margin: 0.85rem 0 0.35rem; font-size: 0.85rem; color: var(--muted); }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.55rem 0.75rem;
  background: rgba(26, 34, 44, 0.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.app-header h1 { margin: 0; font-size: 0.95rem; white-space: nowrap; }
.view-tabs { display: flex; gap: 0.25rem; flex: 1; justify-content: center; }
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  font-size: 0.85rem;
}
.tab.active { background: var(--panel2); color: var(--text); border-color: var(--border); }
.stats-wrap { width: 100%; order: 5; }
.stats-wrap summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}
.stats-wrap summary::-webkit-details-marker { display: none; }
.stats { display: flex; gap: 0.65rem; flex-wrap: wrap; font-size: 0.75rem; color: var(--muted); padding-top: 0.35rem; }
.stats strong { color: var(--text); }

.view { display: none; min-height: calc(100dvh - var(--header-h)); }
.view.active { display: flex; flex-direction: column; }

/* Swipe */
.swipe-filters {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 0.5rem 0.75rem;
}
.swipe-filters select { width: auto; min-width: 7rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.6rem;
}
.chip input { width: auto; margin: 0; }
#swipe-progress { margin-left: auto; font-size: 0.78rem; }

.deck {
  flex: 1;
  position: relative;
  padding: 0.25rem 0.75rem 0.5rem;
  min-height: 420px;
  display: flex;
  align-items: stretch;
  justify-content: center;
}
.card-stack {
  position: relative;
  width: min(520px, 100%);
  height: min(78dvh, 760px);
  max-height: 760px;
}
.swipe-card {
  position: absolute;
  inset: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  touch-action: none;
  user-select: none;
  transition: transform 0.15s ease, opacity 0.15s ease;
  will-change: transform;
}
.swipe-card.dragging { transition: none; }
.swipe-card .stamp {
  position: absolute;
  top: 18px;
  z-index: 5;
  font-weight: 900;
  font-size: 1.6rem;
  padding: 0.2rem 0.55rem;
  border: 3px solid;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  letter-spacing: 0.04em;
}
.swipe-card .stamp.like { left: 16px; color: var(--good); border-color: var(--good); transform: rotate(-12deg); }
.swipe-card .stamp.pass { right: 16px; color: var(--bad); border-color: var(--bad); transform: rotate(12deg); }

.card-map {
  height: 68%;
  min-height: 320px;
  background: #111;
  position: relative;
  touch-action: pan-x pan-y;
  z-index: 2;
}
.card-map .leaflet-container, .card-map .gm-style { width: 100%; height: 100%; }
.map-layer-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1000;
  display: flex;
  gap: 0.25rem;
}
.map-layer-toggle button {
  font-size: 0.7rem;
  padding: 0.35rem 0.5rem;
  border-radius: 999px;
  background: rgba(15,20,25,0.85);
  color: var(--text);
  border: 1px solid var(--border);
}
.map-layer-toggle button.active { background: var(--accent); color: #061018; }

.card-body {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.75rem 0.85rem 0.9rem;
  touch-action: pan-y;
}
.card-body h2 { margin: 0 0 0.35rem; font-size: 1.05rem; line-height: 1.25; }
.badge-row { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-bottom: 0.55rem; }
.badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--panel2);
  border: 1px solid var(--border);
}
.badge.A { background: #1a4d3a; border-color: #2a7a5a; }
.badge.B { background: #1a3d4d; border-color: #2a6a8a; }
.badge.C { background: #4d3a1a; border-color: #8a6a2a; }
.badge.D { background: #4d1a1a; border-color: #8a2a2a; }
.badge.delinq { background: #4d2a1a; color: #ffc9a8; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 0.65rem;
  font-size: 0.88rem;
  margin-bottom: 0.65rem;
}
.stat-grid span { display: block; color: var(--muted); font-size: 0.7rem; }

.card-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}
.card-links a, .card-links button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  text-decoration: none;
  font-size: 0.85rem;
  border-radius: 10px;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 650;
}
.card-links a.primary { background: var(--accent); color: #061018; border-color: transparent; }

.swipe-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1rem calc(0.85rem + var(--safe-bottom));
}
.swipe-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-size: 1.55rem;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.swipe-btn.up { background: var(--good); }
.swipe-btn.down { background: var(--bad); color: #fff; }
.swipe-btn.skip { width: 48px; height: 48px; font-size: 0.75rem; font-weight: 700; }

/* Matches */
.matches-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0.75rem;
}
.matches-toolbar input { flex: 1; }
.matches-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0 0.75rem 1.5rem;
}
.match-row {
  text-align: left;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  color: var(--text);
  font-weight: 500;
}
.match-row .line1 { display: flex; justify-content: space-between; gap: 0.5rem; font-weight: 700; }
.match-row .line2 { font-size: 0.78rem; color: var(--muted); margin-top: 0.25rem; }
.match-detail {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.75rem 0.75rem calc(1.5rem + var(--safe-bottom));
}
.match-detail .detail-top {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 0.35rem 0;
  z-index: 2;
}
.detail-map { height: 220px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); margin-bottom: 0.75rem; }
.field { margin-bottom: 0.55rem; }
.field label { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.2rem; }
.pricing-grid { display: grid; grid-template-columns: 1fr; gap: 0.45rem; }
@media (min-width: 520px) {
  .pricing-grid { grid-template-columns: 1fr 1fr 1fr; }
}
.field input, .field textarea, .field select { min-height: 44px; font-size: 1rem; }
.field textarea { min-height: 88px; }
.action-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }

/* Map overview */
.map-toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.5rem 0.75rem;
}
.map-toolbar select { width: auto; }
.overview-map {
  flex: 1;
  min-height: calc(100dvh - var(--header-h) - 52px);
  background: #111;
}

@media (min-width: 900px) {
  .card-stack { height: min(82vh, 820px); width: min(560px, 100%); }
  .pricing-grid { grid-template-columns: 1fr 1fr 1fr; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

.maps-status {
  width: 100%;
  order: 6;
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0.15rem 0 0;
}
.maps-status.bad { color: var(--warn); }

.pano-host { position: absolute; inset: 0; background: #111; z-index: 1; }
.card-map .map-host { position: absolute; inset: 0; }
.pano-empty {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}
