/* AdBot Dashboard - Smartland */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --text-secondary: #5f6775;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --yellow: #ca8a04;
  --yellow-bg: #fef9c3;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --radius: 8px;
}

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* --- Login overlay --- */
#login-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
#login-overlay.hidden { display: none; }

#login-box {
  background: var(--card-bg);
  padding: 2.5rem 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 340px;
  text-align: center;
}
#login-box h2 { margin-bottom: 0.25rem; font-size: 1.25rem; }
#login-box p { color: var(--text-secondary); margin-bottom: 1.5rem; font-size: 0.9rem; }
#login-box input {
  display: block; width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}
#login-box button {
  width: 100%; padding: 0.6rem;
  background: var(--blue); color: #fff;
  border: none; border-radius: 6px;
  font-size: 0.95rem; cursor: pointer;
  font-weight: 600;
}
#login-box button:hover { opacity: 0.9; }
#login-error { color: var(--red); font-size: 0.85rem; margin-top: 0.5rem; display: none; }

/* --- Header (sticky) --- */
header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
header h1 { font-size: 1.15rem; font-weight: 700; }
header h1 span { color: var(--blue); }
.header-right { display: flex; align-items: center; gap: 1rem; font-size: 0.8rem; color: var(--text-secondary); }
.refresh-btn {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 0.35rem 0.75rem; cursor: pointer; font-size: 0.8rem; color: var(--text-secondary);
}
.refresh-btn:hover { background: var(--bg); }

/* --- Layout --- */
main { max-width: 1360px; margin: 0 auto; padding: 1.25rem 1.5rem 2rem; }

.section-title {
  font-size: 0.95rem; font-weight: 700;
  margin: 1.75rem 0 0.75rem;
  color: var(--text);
}
.section-title:first-child { margin-top: 0; }

/* Collapsible section headers */
.section-title.collapsible {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.section-title.collapsible:hover { color: #58a6ff; }
.section-title.collapsible .collapse-chevron {
  display: inline-block;
  width: 1em;
  color: var(--text-secondary);
  transition: transform 0.15s ease;
}
.section-title.collapsible .collapse-hint {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* "Export CSV" button that lives inside the Recent Leads heading.
   Sits at the right edge of the heading, doesn't toggle the collapse. */
.leads-export-btn {
  margin-left: auto;
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.leads-export-btn:hover:not(:disabled) {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.leads-export-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* --- Summary cards --- */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
}
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.card-label { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.card-value { font-size: 1.6rem; font-weight: 700; margin-top: 0.2rem; }
.card-sub { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.15rem; }

/* Health badge */
.health-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: capitalize;
  cursor: help;
  position: relative;
}
.health-healthy { background: var(--green-bg); color: var(--green); }
.health-warning { background: var(--yellow-bg); color: var(--yellow); }
.health-critical { background: var(--red-bg); color: var(--red); }

/* Multi-line tooltip for system health — richer than status-badge version */
.health-badge[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 400;
  background: #1f2937;
  color: #f9fafb;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.45;
  text-transform: none;
  white-space: pre-line;
  width: max-content;
  max-width: 380px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.28);
  pointer-events: none;
  text-align: left;
}
.health-badge[data-tip]:hover::before {
  content: '';
  position: absolute;
  top: calc(100% + 4px);
  right: 1rem;
  z-index: 400;
  border: 6px solid transparent;
  border-bottom-color: #1f2937;
  pointer-events: none;
}

/* --- Sticky top panel (tabs + summary cards) --- */
.top-panel {
  position: sticky;
  top: 49px;
  z-index: 99;
  background: #eef0f4;
  margin: -1.25rem -1.5rem 0;
  padding: 0.75rem 1.5rem 0.85rem;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

/* --- Period row: period tabs + AI-cost pill --- */
.period-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.period-tabs {
  display: flex; gap: 0.25rem;
}
.period-tab {
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.period-tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* Custom date-range picker popover */
.period-custom-wrap {
  position: relative;
  display: inline-block;
}
.period-custom-popover {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 300;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  box-shadow: 0 8px 22px rgba(0,0,0,0.12);
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
/* The HTML `hidden` attribute sets display:none by default, but our
   explicit `display: flex` above overrides it. This makes hidden win. */
.period-custom-popover[hidden] { display: none !important; }
.period-custom-popover label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 600;
}
.period-custom-popover input[type="date"] {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.85rem;
  width: 160px;
}
.period-custom-presets {
  font-size: 0.75rem;
}
.period-custom-presets button {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.75rem;
}
.period-custom-presets button:hover { background: var(--card-bg); border-color: var(--blue); }
.period-custom-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
}
.period-custom-actions button {
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}
.period-custom-actions button.primary {
  background: var(--blue); color: #fff; border-color: var(--blue);
}
.period-custom-actions button:hover:not(.primary) { background: var(--bg); }

/* --- AI Cost pill (top-right of period row) --- */
.ai-cost-pill {
  position: relative;
}
.ai-cost-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-bg);
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: background 0.15s, border-color 0.15s;
}
.ai-cost-toggle:hover { background: var(--bg); border-color: var(--blue); color: var(--text); }
.ai-cost-pill.open .ai-cost-toggle { background: var(--bg); border-color: var(--blue); color: var(--text); }
.ai-cost-toggle .ai-cost-label { font-weight: 500; }
.ai-cost-toggle .ai-cost-total { font-weight: 700; color: var(--text); }
.ai-cost-toggle .ai-cost-chevron {
  font-size: 0.7rem;
  transition: transform 0.15s ease;
}
.ai-cost-pill.open .ai-cost-toggle .ai-cost-chevron { transform: rotate(180deg); }

.ai-cost-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: 150;
  min-width: 340px;
  max-width: 420px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 0.75rem;
}
.ai-cost-dropdown-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.ai-cost-dropdown .ai-cost-card {
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
}
.ai-cost-dropdown .ai-cost-card h4 {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
@media (max-width: 720px) {
  .period-row { flex-direction: column; align-items: stretch; }
  .ai-cost-dropdown { right: auto; left: 0; min-width: 100%; }
  .ai-cost-dropdown-grid { grid-template-columns: 1fr; }
}

/* --- Charts --- */
.chart-container {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.chart-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 0.75rem;
}

/* --- Tables --- */
.table-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: visible;
}
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
thead th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: sticky;
  top: var(--sticky-header-offset, 160px);
  background: var(--card-bg);
  z-index: 50;
}
thead th:hover { color: var(--text); }
thead th .sort-arrow { font-size: 0.65rem; margin-left: 0.25rem; }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr:hover { background: #f0f2f5; }
td { padding: 0.55rem 0.75rem; white-space: nowrap; }

/* CPL color coding */
.cpl-good { color: var(--green); font-weight: 600; }
.cpl-moderate { color: var(--yellow); font-weight: 600; }
.cpl-bad { color: var(--red); font-weight: 600; }

/* Status badge */
.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
  cursor: help;
  position: relative;
}
.status-active { background: var(--green-bg); color: var(--green); }
.status-paused { background: var(--yellow-bg); color: var(--yellow); }
.status-retired { background: #f1f5f9; color: #64748b; }
.status-challenger { background: var(--blue-bg); color: var(--blue); }
.status-budget_paused { background: var(--yellow-bg); color: var(--yellow); }
.status-listing_removed { background: #f1f5f9; color: #64748b; }
.status-running { background: var(--blue-bg); color: var(--blue); }
.status-completed { background: var(--green-bg); color: var(--green); }
.status-no_winner { background: #f1f5f9; color: #64748b; }

/* Live Meta delivery states — surfaced by renderLiveStatusBadge()
   using computeDisplayStatus() on the backend. Each `kind` gets a
   distinct color so the true state is obvious at a glance. */
.live-active          { background: var(--green-bg); color: var(--green); }
.live-challenger      { background: var(--blue-bg); color: var(--blue); }
.live-learning        { background: #ede9fe; color: #6d28d9; }       /* purple — in learning phase */
.live-learning_limited{ background: #fef3c7; color: #92400e; }       /* amber — stuck in learning */
.live-preparing       { background: #e0f2fe; color: #075985; }       /* sky blue — warming up */
.live-review          { background: #e0e7ff; color: #3730a3; }       /* indigo — Meta reviewing */
.live-rejected        { background: var(--red-bg); color: var(--red); }
.live-paused          { background: var(--yellow-bg); color: var(--yellow); }
.live-unknown         { background: #f1f5f9; color: #64748b; }

/* Subtle pulse on learning/preparing badges to signal "in motion" */
@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.72; }
}
.live-learning, .live-preparing, .live-review {
  animation: live-pulse 2.4s ease-in-out infinite;
}

/* Custom tooltip on status badges — shows on hover, richer than the native title attribute */
.status-badge[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: #1f2937;
  color: #f9fafb;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.35;
  text-transform: none;
  white-space: normal;
  width: max-content;
  max-width: 320px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  pointer-events: none;
}
.status-badge[data-tip]:hover::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  border: 6px solid transparent;
  border-top-color: #1f2937;
  pointer-events: none;
}

/* --- A/B Test cards --- */
.test-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0.75rem; }

/* A/B test card content — variant diff, data row, progress footer */
.variant-diff {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  margin: 0.35rem 0;
  font-size: 0.82rem;
  line-height: 1.4;
}
.variant-diff .vs {
  color: var(--text-secondary);
  font-size: 0.75rem;
  margin: 0 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.variant-diff code {
  background: rgba(0,0,0,0.05);
  padding: 0 0.25rem;
  border-radius: 3px;
  font-size: 0.78rem;
}
.variant-diff .muted { color: var(--text-secondary); font-weight: 600; margin-right: 0.25rem; }

.test-data {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin: 0.4rem 0;
  font-size: 0.78rem;
}
.test-data-col {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.55rem;
  line-height: 1.4;
}
.test-data-h {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 0.2rem;
}

.test-progress {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin: 0.35rem 0 0.3rem;
}

.test-winner-note {
  font-size: 0.78rem;
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px dashed var(--border);
  color: var(--text);
}

.test-card-title .muted {
  color: var(--text-secondary);
  font-weight: 400;
  font-size: 0.85em;
}

.test-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.test-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.test-card-title { font-weight: 600; font-size: 0.9rem; }
.test-meta { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.5rem; }
.confidence-bar {
  height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden; margin-top: 0.5rem;
}
.confidence-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.confidence-label { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.2rem; }

/* --- AI Cost --- */
.ai-cost-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.ai-cost-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.ai-cost-card h4 { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.5rem; text-transform: uppercase; letter-spacing: 0.03em; }
.ai-cost-row { display: flex; justify-content: space-between; padding: 0.25rem 0; font-size: 0.85rem; }
.ai-cost-row span:last-child { font-weight: 600; }

/* --- Ad copy preview popup --- */
.ad-copy-trigger {
  position: relative;
  cursor: pointer;
  font-size: 0.85rem;
  margin-left: 2px;
}
.ad-copy-popup {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  width: 320px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  padding: 0.85rem 1rem;
  z-index: 200;
  text-align: left;
  white-space: normal;
  line-height: 1.45;
}
.ad-copy-trigger:hover .ad-copy-popup {
  display: block;
}
.ad-copy-headline {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
}
.ad-copy-headline a {
  color: var(--blue);
  text-decoration: none;
}
.ad-copy-headline a:hover {
  text-decoration: underline;
}
.ad-copy-body {
  font-size: 0.82rem;
  color: var(--text);
  margin-bottom: 0.4rem;
  border-top: 1px solid var(--border);
  padding-top: 0.4rem;
}
.ad-copy-cta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
  border-top: 1px solid var(--border);
  padding-top: 0.35rem;
}

/* --- Budget inline edit --- */
.budget-cell { position: relative; }
.budget-display {
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  font-weight: 600;
  color: var(--text);
}
.budget-display:hover {
  background: var(--blue-bg);
  border-color: var(--blue);
}
.budget-input {
  width: 72px;
  padding: 0.15rem 0.35rem;
  border: 1.5px solid var(--blue);
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  outline: none;
  background: #fff;
}

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* --- Loading --- */
.loading { text-align: center; padding: 2rem; color: var(--text-secondary); }

/* --- Responsive — comprehensive mobile pass (refreshed 2026-05-29) --- */

/* Tablet / large phone landscape */
@media (max-width: 900px) {
  /* Tables become horizontally scrollable instead of overflowing the page.
     `overflow: visible` was set globally on .table-wrap so the ad-copy
     popup could escape — but on mobile we'd rather scroll. */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 640px; } /* preserve column readability while scrolling */
}

/* Phones */
@media (max-width: 768px) {
  main { padding: 0.5rem; }

  /* Header: stack brand row above period controls; left-align so labels
     remain readable rather than centred on a small screen. */
  header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    text-align: left;
    padding: 0.6rem 0.75rem;
  }
  header h1 { font-size: 1rem; }
  .header-right { width: 100%; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; }

  /* Period row + tabs: wrap cleanly, larger tap targets */
  .period-row { flex-direction: column; align-items: stretch; gap: 0.5rem; }
  .period-tabs { flex-wrap: wrap; gap: 0.4rem; }
  .period-tab {
    padding: 0.55rem 0.85rem;       /* hit-friendly */
    font-size: 0.85rem;
    flex: 1 1 auto;                  /* fill rows evenly */
    min-width: 80px;
    text-align: center;
  }

  /* Custom-range popover: anchor to viewport, not the toggle, so it
     doesn't shoot off-screen on a small phone. */
  .period-custom-popover {
    position: fixed;
    top: auto;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    min-width: 0;
    max-width: none;
    z-index: 500;
  }

  /* AI Cost pill — full-width dropdown so it stays inside the screen */
  .ai-cost-pill { width: 100%; }
  .ai-cost-toggle { width: 100%; justify-content: space-between; padding: 0.5rem 0.75rem; }
  .ai-cost-dropdown {
    position: fixed;
    top: auto;
    bottom: 1rem;
    left: 0.5rem;
    right: 0.5rem;
    min-width: 0;
    max-width: none;
    max-height: 70vh;
    overflow-y: auto;
  }
  .ai-cost-dropdown-grid { grid-template-columns: 1fr; }

  /* Summary cards: 2 per row instead of 7 */
  .summary-cards { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
  .card { padding: 0.6rem 0.75rem; }
  .card-label { font-size: 0.7rem; }
  .card-value { font-size: 1.3rem; }

  /* Charts stack */
  .chart-row { grid-template-columns: 1fr; }

  /* AI Cost section + test cards stack */
  .ai-cost-grid { grid-template-columns: 1fr; }
  .test-cards { grid-template-columns: 1fr; }
  .test-card { padding: 0.75rem; }

  /* Tables: smaller font + tighter padding, but cells still tappable */
  table { font-size: 0.78rem; }
  td, thead th { padding: 0.45rem 0.5rem; }

  /* Section titles: a touch smaller, but still readable */
  .section-title { font-size: 0.95rem; margin: 1rem 0 0.5rem 0; }

  /* Leads CSV export button: visible + tappable on mobile */
  .leads-export-btn { padding: 0.45rem 0.85rem; font-size: 0.8rem; }

  /* Ad-copy popup: switch to fixed bottom-sheet so it never gets
     clipped by the scrollable table wrapper. */
  .ad-copy-popup {
    position: fixed !important;
    left: 0.5rem !important;
    right: 0.5rem !important;
    bottom: 1rem !important;
    top: auto !important;
    max-width: none !important;
    width: auto !important;
    z-index: 500;
  }
}

/* Small phones */
@media (max-width: 480px) {
  .summary-cards { grid-template-columns: 1fr; }
  .card-value { font-size: 1.15rem; }

  /* Hide low-priority columns on the Property table to keep core
     fields readable without forcing horizontal scroll. Property,
     Leads, Spend, CPL, Status are the must-haves. */
  #property-table th[data-col="metro"],
  #property-table td:nth-child(3),
  #property-table th[data-col="impressions"],
  #property-table td:nth-child(4),
  #property-table th[data-col="clicks"],
  #property-table td:nth-child(5),
  #property-table th[data-col="dailyBudget"],
  #property-table td:nth-child(9) { display: none; }

  /* Same idea on the Recent Leads table — drop Source + Unit, keep
     Name / Property / Email / Phone / Time. */
  #leads-table th[data-lcol="unitType"],
  #leads-table td:nth-child(3),
  #leads-table th[data-lcol="source"],
  #leads-table td:nth-child(6) { display: none; }

  table { min-width: 0; }  /* allow tables to shrink with the hidden cols */
}
