/* Quality Lead Finder — light theme redesign */
:root {
  --bg: #f7f8fb;
  --bg-elevated: #ffffff;
  --bg-muted: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-ring: rgba(79, 70, 229, 0.25);

  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --danger-fg: #b91c1c;
  --warning: #f59e0b;
  --warning-soft: #fef3c7;
  --warning-fg: #92400e;
  --success: #10b981;
  --success-soft: #dcfce7;
  --success-fg: #166534;

  --text: #0f172a;
  --text-2: #334155;
  --text-3: #64748b;
  --text-inv: #ffffff;

  --radius: 10px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 16px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.12);

  /* Balanced density scale */
  --header-h: 52px;
  --tab-h: 56px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --text-xs: 11px;
  --text-sm: 12.5px;
  --text-md: 13.5px;
  --text-lg: 15px;
  --text-xl: 17px;
  --control-h: 40px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  height: -webkit-fill-available;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  font-size: 14px;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  /* iOS: kill rubber-band overscroll fighting the app shell */
  position: fixed;
  inset: 0;
  touch-action: manipulation;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 0; /* reset iOS; components set their own */
}
button { cursor: pointer; }
input, select, textarea { border-radius: var(--radius-sm); }

.hidden { display: none !important; }

.kicker {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 2px;
}

/* App shell */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  height: -webkit-fill-available;
  min-height: 0;
  min-height: 100%;
  background: var(--bg);
  /* Safe areas for notched iPhones (home-screen PWA) */
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  /* bottom safe area handled by tab bar */
}

.topbar {
  min-height: var(--header-h);
  height: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 40;
}

/* Standalone (added-to-home-screen) polish */
.is-standalone .topbar {
  padding-top: 8px;
  padding-bottom: 8px;
}
.is-standalone .brand-sub {
  display: none;
}
.is-standalone .usage-label {
  display: none;
}
.is-standalone .usage-meter {
  padding: 4px 8px;
  gap: 6px;
}
.is-standalone .usage-bar {
  width: 36px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.logo-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(145deg, #6366f1, var(--primary));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.28);
  flex-shrink: 0;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-copy strong {
  font-size: 13.5px;
  font-weight: 650;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 10.5px;
  color: var(--text-3);
}

.topbar-nav {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--bg-muted);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
}

.nav-pill {
  border: none;
  background: transparent;
  color: var(--text-3);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
}

.nav-pill:hover { color: var(--text); }
.nav-pill.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
}

.usage-meter {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  color: var(--text-3);
  white-space: nowrap;
  flex-shrink: 0;
}

.usage-label { font-weight: 600; color: var(--text-2); }
.usage-bar {
  width: 48px;
  height: 4px;
  background: #e2e8f0;
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.usage-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-pill);
  transition: width 0.25s ease, background 0.25s ease;
}
.usage-fill.usage-warn { background: var(--warning); }
.usage-fill.usage-over { background: var(--danger); }
.usage-count {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
  min-width: 2.8rem;
  text-align: right;
  font-size: 11.5px;
}

/* Main views */
.main {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  /* Critical for nested flex scroll on iOS */
  display: flex;
  flex-direction: column;
}

.view {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  /* iOS momentum scroll for children */
  -webkit-overflow-scrolling: touch;
}
.view.active-view { display: flex; z-index: 10; }
.view.hidden { display: none !important; }

/* Search bar */
.search-bar {
  display: grid;
  grid-template-columns: minmax(110px, 0.85fr) minmax(160px, 1.35fr) minmax(120px, 0.8fr) auto;
  gap: 10px;
  align-items: end;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  position: relative;
}

.field label {
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
}

.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: var(--control-h);
  line-height: 1.3;
}

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  background: #fff;
}

.input-with-icon { position: relative; }
.field-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-3);
  pointer-events: none;
}
.input-with-icon .input { padding-left: 34px; }

.autocomplete {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 50;
  max-height: 220px;
  overflow-y: auto;
}

.autocomplete div {
  padding: 10px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
}
.autocomplete div:last-child { border-bottom: none; }
.autocomplete div:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.radius-val {
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-2);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.slider {
  width: 100%;
  height: 32px;
  accent-color: var(--primary);
  cursor: pointer;
}

.search-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: 0.15s ease;
  min-height: var(--control-h);
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(180deg, #6366f1 0%, #4f46e5 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.28);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #4f46e5 0%, #4338ca 100%);
  border-color: transparent;
}
.btn-lg {
  min-height: 46px;
  font-size: 14.5px;
  border-radius: 10px;
}

.btn-share {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(79, 70, 229, 0.28);
  font-weight: 650;
  gap: 6px;
  box-shadow: none;
  min-height: 38px;
  font-size: 13px;
}
.btn-share:hover {
  background: #e0e7ff;
  border-color: rgba(79, 70, 229, 0.4);
  color: var(--primary-hover);
}
.btn-share svg {
  flex-shrink: 0;
}

/* Share sheet (AI proposal brief) */
.share-sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.share-sheet.hidden { display: none !important; }
.share-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(3px);
}
.share-sheet-panel {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: min(88dvh, 720px);
  background: #fff;
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  border-bottom: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: share-up 0.22s ease;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@keyframes share-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}
.share-sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.share-sheet-head h2 {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.share-sheet-sub {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.45;
  max-width: 36ch;
}
.share-sheet-body {
  padding: 14px 18px 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.share-label {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
}
.share-textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px;
  outline: none;
}
.share-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  background: #fff;
}
.share-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.share-actions .btn {
  gap: 8px;
}
.share-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.45;
  padding: 10px 12px;
  background: var(--bg-muted);
  border-radius: 8px;
  border: 1px solid var(--border);
}

@media (min-width: 640px) {
  .share-sheet {
    align-items: center;
    padding: 24px;
  }
  .share-sheet-panel {
    border-radius: 16px;
    border-bottom: 1px solid var(--border);
    max-height: min(80vh, 680px);
  }
}

.btn-ghost {
  background: #fff;
  color: var(--text-2);
  border-color: var(--border-strong);
}
.btn-ghost:hover {
  background: var(--bg-muted);
  color: var(--text);
}

.btn-block { width: 100%; }

.recent-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 14px 8px;
  flex-shrink: 0;
}

.chip-btn, .recent-chips .chip {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.15s ease;
}
.chip-btn:hover, .recent-chips .chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

/* Workspace 3-col — balanced side rails */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 320px) minmax(240px, 1fr) minmax(280px, 340px);
  overflow: hidden;
}

.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  overflow: hidden;
}

.list-panel {
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.map-panel {
  border-right: 1px solid var(--border);
  background: var(--bg-muted);
}

.detail-panel {
  background: var(--bg-elevated);
  overflow-y: auto;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 8px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.panel-head h2 {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.select-sm {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-2);
  outline: none;
  cursor: pointer;
  min-height: 30px;
}

.filter-row {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-wrap: wrap;
}

.chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-3);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
}
.chip:hover { color: var(--text-2); border-color: var(--border-strong); }
.chip.active {
  background: var(--primary-soft);
  border-color: rgba(79, 70, 229, 0.35);
  color: var(--primary);
}

.card-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
}

/* Opportunity cards — compact, even density */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 11px;
  cursor: pointer;
  transition: 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: transparent;
}

.card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.card.active {
  border-color: rgba(79, 70, 229, 0.45);
  background: linear-gradient(90deg, rgba(79, 70, 229, 0.06), #fff 45%);
  box-shadow: 0 0 0 1px rgba(79, 70, 229, 0.15), var(--shadow-sm);
}
.card.active::before { background: var(--primary); }

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.card-title {
  font-weight: 650;
  font-size: 13.5px;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
  line-height: 1.3;
}

.card-rating-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-3);
}
.card-stars { color: var(--warning); letter-spacing: -1px; font-size: 11px; }
.card-rating-num { font-weight: 600; color: var(--text-2); }
.card-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.badge {
  font-size: 10.5px;
  font-weight: 650;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.badge.success { background: var(--success-soft); color: #059669; }
.badge.danger { background: var(--danger-soft); color: #dc2626; }

.card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 7px;
  border-top: 1px solid var(--border);
}

.opp-block { display: flex; align-items: center; gap: 6px; }
.opp-label {
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
}

.opp-pill {
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  min-width: 28px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
/* Soft score chips matching DC prototype */
.opp-pill.high { background: var(--danger-soft); color: var(--danger-fg); }
.opp-pill.med { background: var(--warning-soft); color: var(--warning-fg); }
.opp-pill.low { background: var(--success-soft); color: var(--success-fg); }

.card-chevron { color: var(--text-3); opacity: 0.5; font-size: 16px; }

.list-empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-3);
}
.list-empty-title { font-weight: 600; color: var(--text); margin-bottom: 6px; font-size: 14px; }
.list-empty-sub { font-size: 13px; line-height: 1.5; max-width: 240px; margin: 0 auto; }

/* Map */
.map-head { background: var(--bg-elevated); }
.map-town {
  font-size: 14px !important;
  font-weight: 600 !important;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.map-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-3);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: var(--radius-pill);
}

.map-body {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #e2e8f0;
}

.map-el {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.map-hint {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--text-2);
  font-weight: 500;
  font-size: 13px;
  background: rgba(248, 250, 252, 0.72);
  pointer-events: none;
}
.map-hint.hidden { display: none; }

.lf-marker-wrap { background: transparent !important; border: none !important; }
.lf-marker {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.35);
  background: var(--primary);
}
/* Map markers stay high-contrast on tiles */
.lf-marker.high { background: #ef4444; }
.lf-marker.med { background: #f59e0b; }
.lf-marker.low { background: #10b981; }
.lf-marker.no-web {
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.35), 0 2px 8px rgba(15, 23, 42, 0.3);
}
.lf-marker.selected {
  width: 18px;
  height: 18px;
  border-width: 3px;
  border-color: #fbbf24;
  box-shadow: 0 0 0 4px var(--primary-ring), 0 4px 12px rgba(15, 23, 42, 0.3);
}

.leaflet-container { font-family: var(--font); background: #e2e8f0; }
.leaflet-control-zoom a {
  background: #fff !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-control-attribution {
  font-size: 10px !important;
  background: rgba(255, 255, 255, 0.9) !important;
  color: var(--text-3) !important;
}
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; }
.leaflet-popup-content strong { display: block; margin-bottom: 3px; }
.leaflet-popup-content span { color: var(--text-3); font-size: 12px; }

/* Detail */
.detail-empty {
  height: 100%;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 36px 24px;
  color: var(--text-3);
}
.detail-empty h3 {
  font-size: 16px;
  font-weight: 650;
  color: var(--text);
  margin: 8px 0 6px;
}
.detail-empty p {
  font-size: 13px;
  max-width: 240px;
  line-height: 1.5;
}
.empty-glyph {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid rgba(79, 70, 229, 0.15);
  margin-bottom: 12px;
}

.detail-card { padding: 12px 14px 20px; }

.detail-top {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.detail-top-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 6px;
}

.detail-name {
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-3);
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
}
.icon-btn:hover { color: var(--text); background: var(--bg-muted); }

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.meta-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-muted);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.meta-pill.status-ok { background: var(--success-soft); color: #059669; border-color: transparent; }
.meta-pill.status-bad { background: var(--danger-soft); color: #dc2626; border-color: transparent; }
.meta-pill.open { background: var(--success-soft); color: #059669; border-color: transparent; }
.meta-pill.closed { background: var(--bg-muted); color: var(--text-3); }

.detail-rating {
  font-size: 13px;
  color: var(--warning);
  margin-bottom: 6px;
}
.detail-rating .rating-text { color: var(--text-2); margin-left: 4px; }

.detail-address {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.4;
}
.detail-address svg { flex-shrink: 0; margin-top: 1px; }

.detail-editorial {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
  padding: 10px 12px;
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.detail-photo-wrap {
  position: relative;
  margin-bottom: 12px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  aspect-ratio: 16 / 9;
  max-height: 160px;
}
.detail-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-count {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
}

.detail-section { margin-bottom: 14px; }
.detail-section h3 {
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.breakdown {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.breakdown-item {
  padding: 16px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  border: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  text-align: center;
}
.breakdown-value {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.breakdown-label {
  font-size: 12px;
  color: var(--text-3);
  font-weight: 500;
}

.pitch-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pitch-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  background: var(--bg);
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.45;
}

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  position: sticky;
  bottom: 0;
  padding-top: 12px;
  background: linear-gradient(180deg, transparent, #fff 20%);
}
.action-row { display: flex; gap: 8px; }
.action-row .btn { flex: 1; }

/* Help guide */
.help-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
}
.help-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}
.help-head h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 6px;
  color: var(--text);
}
.help-lead {
  margin: 0;
  font-size: 14px;
  color: var(--text-3);
  max-width: 52ch;
  line-height: 1.5;
}
.help-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 40px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  align-content: start;
}
.help-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
}
.help-card-muted {
  background: var(--bg-muted);
}
.help-card h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0 0 12px;
}
.help-step {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.help-card p {
  margin: 0 0 10px;
  font-size: 13.5px;
  color: var(--text-2);
  line-height: 1.5;
}
.help-card p:last-child { margin-bottom: 0; }
.help-list {
  margin: 0 0 10px;
  padding-left: 18px;
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.55;
}
.help-list li { margin-bottom: 6px; }
.help-bullets {
  margin: 0 0 10px;
  padding-left: 18px;
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.55;
}
.help-bullets li { margin-bottom: 6px; }
.help-note {
  font-size: 12.5px !important;
  color: var(--text-3) !important;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 4px !important;
}
.help-note code {
  font-size: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}
.help-chips {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.help-chips li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: var(--text-2);
}

.help-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  color: var(--primary);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}
.help-icon-btn:hover {
  background: var(--primary-soft);
  border-color: rgba(79, 70, 229, 0.3);
}

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

@media (max-width: 860px) {
  .help-head {
    flex-direction: column;
    align-items: stretch;
    padding: 16px;
  }
  .help-body {
    padding: 14px 14px 28px;
    grid-template-columns: 1fr;
  }
  .help-head h2 { font-size: 18px; }
}

/* Saved CRM */
.saved-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.saved-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.saved-head h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.table-wrap {
  flex: 1;
  overflow: auto;
  padding: 16px 20px 28px;
}
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.table th {
  text-align: left;
  padding: 12px 14px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 12px 14px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--bg-muted); }

.status-dropdown {
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12.5px;
}

/* Loading / toasts */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.loading-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 36px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.spinner {
  width: 34px;
  height: 34px;
  border: 2.5px solid rgba(79, 70, 229, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-card p { font-weight: 600; color: var(--text-2); font-size: 13.5px; }

.toasts {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(480px, calc(100vw - 24px));
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: toast-in 0.25s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Mobile tabs — compact but tappable */
.mobile-tabs {
  display: none;
  min-height: var(--tab-h);
  height: auto;
  padding: 4px 4px max(6px, env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 50;
  box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.05);
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 650;
  cursor: pointer;
  border-radius: 10px;
  padding: 6px 2px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}
.tab-btn svg {
  width: 20px;
  height: 20px;
}
.tab-btn.active {
  color: var(--primary);
  background: var(--primary-soft);
}
.tab-btn:active {
  opacity: 0.85;
  transform: scale(0.98);
}

.desktop-only { display: block; }
.topbar-nav.desktop-only { display: flex; }
.mobile-only { display: none !important; }

/* Mobile scan opener + search sheet */
.mobile-scan-bar {
  padding: 8px 12px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.mobile-scan-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-2);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  margin: 0;
  min-height: 42px;
  line-height: 1.3;
}
.mobile-scan-btn span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mobile-scan-btn strong { color: var(--text); }
.mobile-scan-btn svg { color: #94a3b8; flex-shrink: 0; width: 16px; height: 16px; }

.search-sheet {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  background: #fff;
  /* Cover entire viewport including tab bar when open */
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}
.search-sheet.hidden { display: none !important; }
.search-sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.search-sheet-head h2 {
  font-size: 16px;
  font-weight: 650;
  color: var(--text);
  margin: 0;
}
.search-sheet-form {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.search-sheet-spacer { flex: 1; min-height: 12px; }

/* Phone: 16px inputs prevent iOS focus-zoom; desktop stays compact */
@media (max-width: 900px), ((max-width: 1200px) and (pointer: coarse)) {
  .input {
    font-size: 16px;
    min-height: 42px;
    padding: 9px 12px;
  }
}

.biz-rows {
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 13px;
  margin-bottom: 8px;
}
.biz-row {
  display: flex;
  gap: 8px;
}
.biz-row .lbl {
  color: #94a3b8;
  min-width: 76px;
  flex-shrink: 0;
}
.biz-row .val { color: var(--text); word-break: break-word; }
.biz-row a.val { color: #4338ca; text-decoration: none; }
.biz-row a.val:hover { color: #3730a3; }

.hours-box {
  padding: 10px 12px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--border);
  margin-top: 4px;
}

.command-bar {
  flex-shrink: 0;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

/* Responsive */
/* Tablet: list + map; detail only when selected (NOT phones — see max-width 900) */
@media (min-width: 901px) and (max-width: 1100px) {
  .workspace {
    grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  }
  .detail-panel { display: none; }
  .workspace.detail-open {
    grid-template-columns: minmax(250px, 290px) minmax(0, 1fr) minmax(280px, 320px);
  }
  .workspace.detail-open .detail-panel { display: flex; }
  .brand-sub { display: none; }
}

/*
 * Phone + mobile browser shell.
 * Use max-width 900 AND coarse pointer so iOS Safari (and desktop-site mode on phone)
 * still gets full-width single column + tab bar.
 */
@media (max-width: 900px), ((max-width: 1200px) and (pointer: coarse)) {
  .desktop-only { display: none !important; }
  .mobile-only { display: flex !important; }
  .mobile-scan-bar.mobile-only { display: block !important; }
  a.mobile-only { display: flex !important; }
  .mobile-tabs { display: flex !important; }

  /* Kill multi-column + detail-open from tablet rules — was half-width list bug */
  .workspace,
  .workspace.detail-open {
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr !important;
    flex: 1;
    min-height: 0;
  }

  .workspace .list-panel,
  .workspace .map-panel,
  .workspace .detail-panel {
    display: none !important;
    border: none !important;
    min-height: 0;
    height: 100%;
    width: 100%;
    max-width: none !important;
    grid-column: auto !important;
  }

  /* One panel at a time via JS classes */
  .workspace.mobile-leads .list-panel,
  .workspace:not(.mobile-map):not(.mobile-detail) .list-panel {
    display: flex !important;
  }
  .workspace.mobile-map .map-panel { display: flex !important; }
  .workspace.mobile-detail .detail-panel { display: flex !important; }

  .list-panel .card-list {
    padding-bottom: 16px;
  }

  .detail-panel {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    position: relative;
    z-index: 5;
  }

  .detail-top-row {
    position: sticky;
    top: 0;
    z-index: 6;
    background: #fff;
    padding: 2px 0 8px;
    margin-bottom: 2px;
    align-items: center;
  }

  .detail-name {
    font-size: 16px;
  }

  /* Comfortable X — not oversized */
  .detail-top-row .icon-btn,
  #btnCloseDetail {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px;
    min-height: 36px;
    font-size: 15px;
    display: grid !important;
    place-items: center;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    pointer-events: auto !important;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(79, 70, 229, 0.15);
  }

  .detail-card {
    padding: 10px 12px 16px;
  }

  .detail-photo-wrap {
    max-height: 140px;
  }

  .detail-actions {
    gap: 8px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .detail-actions .btn-block {
    min-height: 40px;
  }

  .panel-head {
    padding: 10px 12px 8px;
  }

  .filter-row {
    padding: 8px 12px 10px;
  }

  .list-panel .card-list {
    padding: 8px;
    gap: 6px;
  }

  .usage-label {
    display: none;
  }

  .help-icon-btn {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  .topbar-brand strong {
    font-size: 13px;
  }
  .logo-mark {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .map-body,
  .map-el {
    min-height: 0;
    height: 100%;
  }

  .toasts {
    bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 10px);
    left: 12px;
    right: 12px;
    transform: none;
    width: auto;
    max-width: none;
  }
  .toast {
    border-radius: 10px;
    font-size: 12.5px;
    padding: 10px 14px;
  }
}

/* Home-screen PWA: same single-panel shell */
@media (display-mode: standalone) {
  .desktop-only { display: none !important; }
  .mobile-only { display: flex !important; }
  .mobile-scan-bar.mobile-only { display: block !important; }
  a.mobile-only { display: flex !important; }
  .mobile-tabs { display: flex !important; }

  .workspace,
  .workspace.detail-open {
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr !important;
  }
  .workspace .list-panel,
  .workspace .map-panel,
  .workspace .detail-panel {
    display: none !important;
    border: none !important;
    width: 100%;
  }
  .workspace.mobile-leads .list-panel,
  .workspace:not(.mobile-map):not(.mobile-detail) .list-panel {
    display: flex !important;
  }
  .workspace.mobile-map .map-panel { display: flex !important; }
  .workspace.mobile-detail .detail-panel { display: flex !important; }
}

@media (max-width: 860px) {
  .table-wrap { padding: 12px; }
  .table th:nth-child(2),
  .table td:nth-child(2),
  .table th:nth-child(4),
  .table td:nth-child(4) {
    display: none;
  }
}
