/* Lead Extractor — design tokens (Exaggerated Minimalism / Plus Jakarta Sans) */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  --color-primary: #0F172A;
  --color-on-primary: #FFFFFF;
  --color-secondary: #334155;
  --color-accent: #0369A1;
  --color-accent-hover: #0284C7;
  --color-background: #F8FAFC;
  --color-foreground: #020617;
  --color-muted: #E8ECF1;
  --color-muted-fg: #64748B;
  --color-border: #E2E8F0;
  --color-card: #FFFFFF;
  --color-destructive: #DC2626;
  --color-success: #059669;
  --color-warning: #D97706;
  --color-ring: #0F172A;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --font: "Plus Jakarta Sans", system-ui, sans-serif;
  --nav-h: 52px;
  --bottom-nav-h: 64px;
  --sidebar-w: 240px;
  /* iOS / Android system insets (ui-ux-pro-max: never put UI under status/home bars) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

html {
  max-width: 100%;
  /* Do NOT set overflow on html/body — it breaks position:fixed bottom-nav on iOS. */
}

body.app-body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-foreground);
  background: var(--color-background);
  min-height: 100dvh;
  max-width: 100%;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { color: var(--color-accent-hover); }

.app-shell {
  display: flex;
  min-height: 100dvh;
  max-width: 100%;
}

.app-sidebar {
  width: var(--sidebar-w);
  background: var(--color-primary);
  color: var(--color-on-primary);
  padding: var(--space-6) var(--space-4);
  flex-shrink: 0;
  display: none;
  flex-direction: column;
}

@media (min-width: 768px) {
  .app-sidebar { display: flex; }
}

.brand {
  margin-bottom: var(--space-8);
  padding: 0 var(--space-2);
}
.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0;
}
.brand-sub {
  font-size: 0.75rem;
  opacity: 0.65;
  margin-top: var(--space-1);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.75);
  font-weight: 500;
  font-size: 0.9375rem;
  transition: background 180ms ease, color 180ms ease;
  cursor: pointer;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active { background: rgba(255,255,255,0.12); color: #fff; font-weight: 600; }
.nav-divider { border: 0; border-top: 1px solid rgba(255,255,255,0.1); margin: var(--space-4) 0; }

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

@media (min-width: 768px) {
  .app-main { padding-bottom: 0; padding-left: 0; padding-right: 0; }
}

/* Mobile top bar — sits fully below iOS status bar (clock / battery) */
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  box-sizing: border-box;
  min-height: calc(var(--nav-h) + var(--safe-top));
  height: auto;
  padding-top: var(--safe-top);
  padding-left: max(var(--space-3), var(--safe-left));
  padding-right: max(var(--space-3), var(--safe-right));
  padding-bottom: 0;
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 40;
}
@media (min-width: 768px) {
  .app-topbar { display: none; }
}

.topbar-start {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
}
.topbar-end {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  flex-shrink: 0;
}
.topbar-brand {
  font-weight: 800;
  letter-spacing: -0.03em;
  font-size: 1rem;
  color: var(--color-foreground);
}
.topbar-brand-truncate {
  display: block;
  max-width: 48vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-foreground);
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}
.icon-btn:hover,
.icon-btn:focus-visible {
  background: var(--color-muted);
  color: var(--color-foreground);
}

.app-content {
  flex: 1;
  padding: var(--space-4);
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  min-width: 0;
  overflow-x: clip;
}
@media (min-width: 768px) {
  .app-content { padding: var(--space-6) var(--space-8); }
}
.page-header-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
@media (max-width: 767px) {
  .results-title-desktop { display: none !important; }
  .results-header-actions-desktop,
  .desktop-only-actions { display: none !important; }
  .page-header-row {
    margin-bottom: var(--space-3);
  }
  .page-header-row .page-subtitle {
    margin: 0;
  }
  .app-topbar .icon-btn {
    width: 36px;
    height: 36px;
  }
}

@media (min-width: 768px) {
  .desktop-only-actions { display: flex; }
  #results-topbar-actions,
  .mobile-topbar-action { display: none !important; }
}

.results-select-bar {
  margin-bottom: 0.75rem;
  align-items: center;
  gap: 0.75rem;
}
@media (min-width: 768px) {
  .results-select-bar {
    display: none !important;
  }
}
.selection-count {
  font-size: 0.8125rem;
  font-weight: 600;
}
.mobile-selection-delete {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}
@media (min-width: 768px) {
  .mobile-selection-delete {
    display: none !important;
  }
}

.actions-dropdown {
  position: relative;
  display: none;
  align-items: center;
}
@media (min-width: 768px) {
  .actions-dropdown.desktop-only-actions {
    display: inline-flex;
  }
}
.actions-dropdown .btn[data-actions-toggle] {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.2;
  min-height: 0;
  height: auto;
}
.actions-dropdown .btn[data-actions-toggle] svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.actions-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  min-width: 11rem;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 0.35rem;
  z-index: 60;
  display: none;
  flex-direction: column;
  gap: 0.15rem;
}
.actions-menu:not([hidden]) {
  display: flex;
}
.actions-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.7rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--color-foreground);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.25;
}
.actions-menu-item[hidden],
.selection-only[hidden] {
  display: none !important;
}
.actions-menu-item:hover,
.actions-menu-item:focus-visible {
  background: var(--color-muted);
  color: var(--color-foreground);
}
.actions-menu-item-danger {
  color: var(--color-danger, #b42318);
  border-top: 1px solid var(--color-border);
  margin-top: 0.15rem;
  border-radius: 0 0 6px 6px;
}
.actions-menu-item-danger:hover,
.actions-menu-item-danger:focus-visible {
  background: color-mix(in srgb, var(--color-danger, #b42318) 12%, transparent);
  color: var(--color-danger, #b42318);
}

/* Bottom nav (mobile) — icons sit in the top bar; safe-area is padding only (no gap under bar) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: stretch;
  box-sizing: border-box;
  /* Height = bar + home-indicator padding; background paints through the padding */
  min-height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  padding: 0;
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.06);
}
@media (min-width: 768px) {
  .bottom-nav { display: none; }
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  /* Keep labels/icons in the 64px band — not vertically centered into the safe area */
  height: var(--bottom-nav-h);
  max-height: var(--bottom-nav-h);
  align-self: flex-start;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-muted-fg);
  cursor: pointer;
  text-decoration: none;
}
.bottom-nav a.active { color: var(--color-accent); }
.bottom-nav svg { width: 22px; height: 22px; }

/* Cards */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}
.card-desc {
  font-size: 0.875rem;
  color: var(--color-muted-fg);
  margin: var(--space-1) 0 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}
@media (min-width: 768px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }
}
.stat-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted-fg);
}
.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  margin-top: var(--space-1);
  color: var(--color-primary);
}

.page-header {
  margin-bottom: var(--space-6);
}
.page-title {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  margin: 0;
}
.page-subtitle {
  color: var(--color-muted-fg);
  margin: var(--space-2) 0 0;
  font-size: 0.9375rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.625rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
  text-decoration: none;
  line-height: 1.25;
}
.btn:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
}
.btn-primary {
  background: var(--color-accent);
  color: #fff;
}
.btn-primary:hover { background: var(--color-accent-hover); color: #fff; }
.btn-secondary {
  background: var(--color-card);
  border-color: var(--color-border);
  color: var(--color-foreground);
}
.btn-secondary:hover { background: var(--color-muted); }
.icon-btn-danger {
  color: var(--color-destructive, #b42318);
}
.icon-btn-danger:hover,
.icon-btn-danger:focus-visible {
  color: var(--color-destructive, #b42318);
  background: #FEF2F2;
}
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Forms */
.label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: var(--space-2);
  color: var(--color-secondary);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.input, .glass-input, select.input, textarea.input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9375rem;
  background: var(--color-card);
  color: var(--color-foreground);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
.input:focus, .glass-input:focus, select.input:focus, textarea.input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(3, 105, 161, 0.15);
}
.field {
  margin-bottom: var(--space-4);
  min-width: 0;
  max-width: 100%;
}
.field-hint {
  font-size: 0.75rem;
  color: var(--color-muted-fg);
  margin-top: var(--space-1);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.field-masked {
  font-size: 0.75rem;
  color: var(--color-muted-fg);
  margin: 0 0 var(--space-2);
  max-width: 100%;
}
.field-masked code {
  display: inline-block;
  max-width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  word-break: break-all;
  overflow-wrap: anywhere;
  white-space: normal;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-card);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted-fg);
  background: var(--color-muted);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #F1F5F9; }

/* Frappe-like filter bar */
.table-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: #F1F5F9;
  border-bottom: 1px solid var(--color-border);
  align-items: center;
}
.table-filter-bar .input,
.table-filter-bar select {
  width: auto;
  min-width: 120px;
  padding: 0.375rem 0.5rem;
  font-size: 0.8125rem;
}
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
}
.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.25rem 0.5rem;
  background: #E0F2FE;
  color: #075985;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.filter-tag a {
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  line-height: 1;
}
.filter-tag a:hover { opacity: 1; }

/* Progress */
.progress-banner {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-accent);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  max-width: 100%;
  min-width: 0;
}
.progress-banner-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.progress-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.progress-track {
  height: 8px;
  background: var(--color-muted);
  border-radius: 999px;
  overflow: hidden;
  margin: var(--space-3) 0;
}
.progress-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 999px;
  transition: width 300ms ease;
}
.progress-meta {
  font-size: 0.8125rem;
  color: var(--color-muted-fg);
}
.progress-nested {
  margin-top: 0.65rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-border);
}
.progress-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.35rem;
}
.progress-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--color-muted-fg);
}
.progress-track-nested {
  height: 6px;
  margin: var(--space-2) 0 var(--space-1);
}
.progress-fill-nested,
.progress-track-nested .progress-fill {
  background: color-mix(in srgb, var(--color-accent) 70%, #0f172a);
}
.progress-banner-parent {
  position: sticky;
  top: 0;
  z-index: 5;
}

/* Statewide city subtasks */
.subtask-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: var(--space-3);
  align-items: stretch;
}
.subtask-filters .input {
  flex: 1 1 140px;
  min-width: 0;
}
.subtask-summary {
  font-size: 0.8125rem;
  margin-bottom: var(--space-3);
}
.subtask-list {
  display: grid;
  gap: 0.65rem;
}
.subtask-card {
  text-decoration: none;
  color: inherit;
  transition: border-color 160ms ease, transform 160ms ease;
  cursor: pointer;
  min-height: 44px;
}
.subtask-card:hover {
  border-color: var(--color-accent);
}
.subtask-card.is-active {
  border-left: 4px solid var(--color-accent);
}
.subtask-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}
.subtask-msg {
  margin-top: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Instant feedback while navigating / submitting on mobile */
.nav-loading {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: color-mix(in srgb, #0f172a 35%, transparent);
  backdrop-filter: blur(2px);
}
.nav-loading[hidden] {
  display: none !important;
}
.nav-loading-card {
  min-width: min(240px, 90vw);
  padding: 1.1rem 1.25rem;
  border-radius: var(--radius);
  background: var(--color-card);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.18);
}
.nav-loading-spinner {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  animation: nav-spin 0.7s linear infinite;
  flex-shrink: 0;
}
.nav-loading-text {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-fg);
}
@keyframes nav-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .subtask-card,
  .progress-fill {
    transition: none !important;
  }
  .nav-loading-spinner {
    animation: none;
    border-top-color: var(--color-accent);
    opacity: 0.85;
  }
}

/* Lead cards (mobile) vs table (desktop) — keep display modes correct.
   Never set display:block on <table> (it stacks header+rows like mobile cards). */
.lead-cards {
  display: grid;
  gap: var(--space-3);
}
.lead-cards-mobile-only {
  display: grid;
  gap: var(--space-3);
}
.table-desktop-only {
  display: none;
}

@media (min-width: 768px) {
  .lead-cards-mobile-only {
    display: none !important;
  }
  /* wrappers */
  div.table-desktop-only,
  .table-wrap.table-desktop-only {
    display: block !important;
  }
  /* actual tables must remain tables */
  table.table-desktop-only {
    display: table !important;
    width: 100%;
  }
}

@media (max-width: 767px) {
  .lead-cards-mobile-only {
    display: grid !important;
  }
  .table-desktop-only {
    display: none !important;
  }
}
.lead-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.lead-card-name {
  font-weight: 700;
  font-size: 1rem;
  margin: 0 0 var(--space-1);
}
.lead-card-meta {
  font-size: 0.8125rem;
  color: var(--color-muted-fg);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-success { background: #D1FAE5; color: #065F46; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-muted { background: var(--color-muted); color: var(--color-secondary); }
.badge-info { background: #E0F2FE; color: #075985; }
.badge-danger { background: #FEE2E2; color: #991B1B; }

/* Flash */
.flash {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-4);
  font-size: 0.875rem;
  font-weight: 500;
}
.flash-success { background: #D1FAE5; color: #065F46; }
.flash-error, .flash-danger { background: #FEE2E2; color: #991B1B; }
.flash-info { background: #E0F2FE; color: #075985; }
.flash-warning { background: #FEF3C7; color: #92400E; }

/* Charts */
.chart-grid {
  display: grid;
  gap: var(--space-4);
  margin-top: var(--space-4);
}
@media (min-width: 768px) {
  .chart-grid { grid-template-columns: repeat(2, 1fr); }
}
.chart-card canvas { max-height: 260px; }

/* Map */
.map-panel {
  height: 320px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  overflow: hidden;
  margin-bottom: var(--space-4);
  z-index: 1;
}
.map-panel .leaflet-container {
  width: 100% !important;
  max-width: 100% !important;
  height: 100% !important;
}
@media (min-width: 768px) {
  .map-panel { height: 420px; }
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  max-width: 100%;
  min-width: 0;
}
.mono-text { font-family: ui-monospace, monospace; font-size: 0.8125rem; word-break: break-all; }
.grid-2 {
  display: grid;
  gap: var(--space-4);
  min-width: 0;
  max-width: 100%;
}
.grid-2 > * { min-width: 0; }
@media (min-width: 768px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
}

/* New Search — prevent horizontal pinch/scroll on mobile */
#search-form.card {
  max-width: 100%;
  min-width: 0;
  overflow-x: clip;
}
@media (max-width: 767px) {
  #search-form.card {
    width: 100%;
  }
  #search-form .input,
  #search-form select,
  #search-form .btn {
    max-width: 100%;
  }
  #search-form .toolbar-row .btn {
    flex: 1 1 calc(50% - var(--space-1));
    min-width: 0;
  }
}
.settings-grid {
  display: grid;
  gap: var(--space-4);
}
@media (min-width: 900px) {
  .settings-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-card-wide { grid-column: 1 / -1; }
}
.backup-info-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  margin: 0;
}
.backup-info-grid dt { font-size: 0.75rem; color: var(--color-muted-fg); font-weight: 600; }
.backup-info-grid dd { margin: 0; font-weight: 600; }
.backup-warning { color: var(--color-warning); font-size: 0.875rem; margin-top: var(--space-3); }
.backup-actions-cell { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.backup-inline-form { display: inline; }
.checkbox-wrap { display: flex; gap: var(--space-2); align-items: flex-start; font-size: 0.875rem; }

.empty-state {
  text-align: center;
  padding: var(--space-8);
  color: var(--color-muted-fg);
}

/* Legacy aliases used in older templates */
.glass-btn { composes: btn; }
.glass-body { background: var(--color-background); }
.glass-card { background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius); padding: var(--space-5); }
.glass-table { width: 100%; border-collapse: collapse; }
.glass-input { /* see .input */ }

.btn.glass-btn,
a.glass-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.625rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--color-accent);
  color: #fff;
  border: none;
  cursor: pointer;
}
.glass-btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.625rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  color: var(--color-foreground);
  cursor: pointer;
}
.dashboard-title { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.04em; margin: 0; }
.dashboard-subtitle { color: var(--color-muted-fg); margin: var(--space-2) 0 0; }

/* Results / history polish */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.results-header-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}
.page-header-compact { margin-bottom: var(--space-3); }
.history-cards { gap: var(--space-3); margin-top: 0; }

.results-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.results-toolbar-actions,
.results-toolbar-btns {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.select-all-row {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0;
  align-items: center;
}

.filters-compact {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  padding: 0;
  background: transparent;
  border: 0;
}
@media (min-width: 768px) {
  .filters-compact {
    display: flex;
    flex-wrap: wrap;
  }
  .filters-compact .input { min-width: 7.5rem; max-width: 11rem; }
  .filters-compact input[type="search"] { min-width: 12rem; max-width: none; flex: 1; }
}
.filters-compact .input,
.filters-compact select {
  width: 100%;
  min-height: 2.5rem;
  font-size: 0.875rem;
}

/* Mobile filter bar: denser, no grey slab */
@media (max-width: 767px) {
  .table-filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
    padding: 0 0 var(--space-3);
    background: transparent;
    border: 0;
  }
  .table-filter-bar .input,
  .table-filter-bar select {
    width: 100%;
    min-width: 0;
    min-height: 2.5rem;
  }
  .table-filter-bar input[type="search"] {
    grid-column: 1 / -1;
  }
  .history-header {
    margin-bottom: var(--space-3);
  }
  .history-header .page-subtitle {
    margin-bottom: 0;
  }
  .history-cards {
    margin-top: 0;
    margin-bottom: 0;
    padding-bottom: 0;
  }
  /* Hidden desktop table must not inflate page width/height on mobile */
  .table-desktop-only {
    display: none !important;
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    border: 0 !important;
    pointer-events: none !important;
  }
  .history-stats {
    gap: var(--space-1) var(--space-2);
  }
  .history-stats > span {
    max-width: 100%;
    overflow-wrap: anywhere;
  }
}

.lead-card-line {
  font-size: 0.8125rem;
  color: var(--color-muted-fg);
  word-break: break-word;
  margin-top: 0.15rem;
}

/* Compact icon tags */
.itag {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--color-muted);
  color: var(--color-secondary);
  text-decoration: none;
  line-height: 1.2;
  max-width: 100%;
}
.itag svg { width: 0.75rem; height: 0.75rem; flex-shrink: 0; }
.itag-ai { background: #DBEAFE; color: #1E40AF; }
.itag-ok { background: #D1FAE5; color: #065F46; }
.itag-danger { background: #FEE2E2; color: #991B1B; }
.itag-warn { background: #FEF3C7; color: #92400E; }
.itag-muted { background: var(--color-muted); color: var(--color-muted-fg); }
.itag-fit { background: #E0E7FF; color: #3730A3; }
.itag-mail { background: #F1F5F9; color: #334155; }
.itag-web { background: #E0F2FE; color: #075985; }
.itag-maps { background: #ECFDF5; color: #065F46; }
a.itag:hover { filter: brightness(0.96); color: inherit; }

/* Fetch more dialog */
.le-modal {
  border: 0;
  padding: 0;
  border-radius: var(--radius);
  max-width: 420px;
  width: calc(100% - 2rem);
  box-shadow: var(--shadow);
}
.le-modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
}
.le-modal-card {
  padding: var(--space-5);
  display: grid;
  gap: var(--space-2);
}
.le-modal-card h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 800;
}
.le-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.table-leads .col-phone {
  white-space: nowrap;
  max-width: 9.5rem;
}
.table-leads .col-email {
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table-leads .col-check { width: 2.5rem; }

.lead-cards { display: grid; gap: var(--space-3); }
.lead-card-row { cursor: pointer; }
.lead-card-top { display: flex; gap: var(--space-3); align-items: flex-start; }
.lead-check { padding-top: 0.2rem; }
.lead-card-body { flex: 1; min-width: 0; }

.tag-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.5rem;
}
.tag-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 999px;
  background: var(--color-muted);
  color: var(--color-secondary);
  flex-shrink: 0;
}
.tag-icon svg { width: 0.85rem; height: 0.85rem; }
.tag-icon:hover { background: #E0F2FE; color: #0369A1; }
.tag-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}
.tag-ai { background: #DBEAFE; color: #1E40AF; }
.tag-ai-pending { background: var(--color-muted); color: var(--color-muted-fg); }
.tag-ai-fail { background: #FEE2E2; color: #991B1B; }
.tag-sync-ok { background: #D1FAE5; color: #065F46; }
.tag-sync-pending { background: var(--color-muted); color: var(--color-muted-fg); }
.tag-sync-fail { background: #FEE2E2; color: #991B1B; }
.tag-sync-skip { background: #FEF3C7; color: #92400E; }

.table-leads td.nowrap,
.table td.nowrap { white-space: nowrap; }
.table-leads .email-cell {
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lead-row-click,
[data-href] {
  cursor: pointer;
}
.lead-row-click:hover { background: #F1F5F9; }
a.lead-card.history-card {
  display: block;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
a.lead-card.history-card:active {
  background: #F1F5F9;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.875rem;
  margin: 0.5rem 0 1rem;
}
.field-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-muted-fg);
  margin-bottom: 0.25rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 80;
  padding: var(--space-4);
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
}
.modal-card {
  background: var(--color-card);
  border-radius: var(--radius);
  padding: var(--space-5);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.modal-title { margin: 0 0 0.25rem; font-size: 1.125rem; font-weight: 800; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.detail-page { max-width: 920px; }
.detail-grid {
  display: grid;
  gap: var(--space-4);
}
@media (min-width: 768px) {
  .detail-grid { grid-template-columns: 1fr 1fr; }
}
.card-section-title {
  margin: 0 0 var(--space-3);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted-fg);
}
.detail-dl { margin: 0; display: grid; gap: 0.65rem; }
.detail-dl > div { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.875rem; }
.detail-dl dt { color: var(--color-muted-fg); flex-shrink: 0; }
.detail-dl dd { margin: 0; text-align: right; font-weight: 500; }
.detail-dl dd.wrap { word-break: break-word; overflow-wrap: anywhere; }
.detail-sync-form,
.detail-edit-form {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}
.notes-preview-wrap {
  overflow-x: auto;
  max-width: 100%;
  font-size: 0.875rem;
  line-height: 1.55;
}
.notes-preview p { margin: 0 0 0.5rem; word-break: break-word; }
.notes-preview ul { margin: 0 0 0.75rem; padding-left: 1.1rem; }
.notes-preview li { margin-bottom: 0.25rem; }
.notes-pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
  font-size: 0.875rem;
  margin: 0.75rem 0 0;
  background: var(--color-muted);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.review-item {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--color-border);
}
.review-item:last-child { border-bottom: 0; }
.review-item p { margin: 0.35rem 0 0; font-size: 0.875rem; }
.muted { color: var(--color-muted-fg); }
[x-cloak] { display: none !important; }

/* History context menu (right-click / long-press) */
.ctx-menu {
  position: fixed;
  z-index: 200;
  min-width: 10.5rem;
  padding: 0.3rem;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  display: none;
  flex-direction: column;
  gap: 0.1rem;
}
.ctx-menu:not([hidden]) {
  display: flex;
}
.ctx-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.7rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--color-foreground);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.25;
}
.ctx-menu-item:hover,
.ctx-menu-item:focus-visible {
  background: var(--color-muted);
}
.ctx-menu-item-danger {
  color: var(--color-destructive, #b42318);
  border-top: 1px solid var(--color-border);
  margin-top: 0.1rem;
  border-radius: 0 0 6px 6px;
}
.ctx-menu-item-danger:hover,
.ctx-menu-item-danger:focus-visible {
  background: #FEF2F2;
  color: var(--color-destructive, #b42318);
}
[data-search-item] {
  -webkit-touch-callout: none;
  user-select: none;
}
