/* styles.css — shared across index.html, admin.html, report.html, and signup.html
   Design intent: a dense operational tool, not a CRM dashboard. No cards,
   no avatars, no big whitespace — the owner processes hundreds of rows in
   one sitting, so every pixel of vertical space is budgeted. */

:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --border: #e1e4e8;
  --border-strong: #c7cbd1;
  --text: #16181d;
  --text-muted: #6b7280;
  --text-faint: #9aa1ab;
  --accent: #0f6a4f;       /* primary action (Send) */
  --accent-dark: #0b5340;
  --accent-contrast: #ffffff;
  --warn: #b45309;
  --danger: #b91c1c;
  --danger-bg: #fdecec;
  --highlight-bg: #eaf7f1;
  --info: #1d64c9;          /* daily send cap: comfortably under */
  --row-height: 64px;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body { padding-bottom: env(safe-area-inset-bottom); }

a { color: var(--accent-dark); }

button, input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom-on-focus */
}

button {
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 12px;
  min-height: 40px;
}
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: var(--accent-dark); }

button.subtle {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

button.danger { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="url"], input[type="tel"], select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.hint { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

.insert-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.insert-chip {
  flex: 0 0 auto;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  min-height: unset;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-top: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.emoji-btn {
  min-height: unset;
  padding: 4px;
  font-size: 18px;
  line-height: 1.2;
  background: transparent;
  border: none;
}
.emoji-btn:hover { background: var(--surface); border-radius: var(--radius); }
.image-url-preview {
  display: block;
  max-width: 100%;
  max-height: 240px;
  margin-top: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.tabular { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---------- App shell ---------- */

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.screen { padding: 12px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px calc(8px + env(safe-area-inset-top) * 0);
}

.topbar-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.topbar-row:last-child { margin-bottom: 0; }
.topbar-row select { flex: 1; min-width: 0; }
.icon-btn { width: 40px; flex: 0 0 40px; padding: 8px; text-align: center; }
/* The ☰ menu button sits next to the message select, which renders a few
   px taller than the 40px other icon buttons use (its own padding/border/
   line-height). Bumped to a slightly larger square (still 1:1) to match. */
.icon-btn.subtle { width: 44px; flex: 0 0 44px; height: 44px; font-size: 20px; }

.daily-cap-row { margin-bottom: 14px; }
.daily-cap-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.daily-cap-track { height: 5px; border-radius: 999px; background: var(--border); overflow: hidden; }
.daily-cap-fill { height: 100%; border-radius: 999px; background: var(--info); }
.daily-cap-fill.warn { background: var(--warn); }
.daily-cap-fill.danger { background: var(--danger); }

.filter-row { display: flex; gap: 6px; overflow-x: auto; }
.filter-chip {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  min-height: unset;
}
.filter-chip.active { background: var(--text); color: #fff; border-color: var(--text); }
input.count-filter-input {
  flex: 0 0 auto;
  width: 48px;
  padding: 6px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  text-align: center;
}
input.date-filter-input {
  flex: 0 0 auto;
  width: 132px;
  padding: 6px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  min-height: unset;
}
.date-filter-clear {
  flex: 0 0 auto;
  width: 28px;
  min-height: unset;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1;
}

/* ---------- Contact list ---------- */

.list-wrap { flex: 1; position: relative; }

.contact-row {
  display: grid;
  grid-template-columns: 1fr 56px 64px 28px 46px 28px 28px;
  align-items: center;
  gap: 6px;
  min-height: var(--row-height);
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  transition: background-color 0.25s ease;
}
.contact-row.just-highlighted { background: var(--highlight-bg); }

/* Virtualized main list only (not the archived-contacts list, which stays a
   normal flowed list): rows are absolutely positioned at a fixed height
   within .list-wrap, which is sized to the full virtual row count so the
   page's scrollbar/height stays correct even though only the visible window
   of rows actually exists in the DOM. This height MUST match ROW_HEIGHT in
   app.js. Two-row-per-contact layout (added 2026-08-01, DECISIONS.md D43):
   name+phone stacked in column 1, send-count/last-sent/open status stacked
   above the Edit/Send buttons in columns 2-3 — grid-column/grid-row are set
   explicitly below (not relying on auto-placement) so this stays independent
   of the archived list's own single-row 3-column layout, which still uses
   the bare .contact-row/.contact-name/.contact-phone classes unscoped.
   */
.contact-row.virtual-row {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--row-height);
  min-height: 0;
  grid-template-columns: 1fr 52px 56px;
  grid-template-rows: auto auto;
  column-gap: 8px;
  row-gap: 4px;
}
.contact-row.virtual-row .contact-name { grid-column: 1; grid-row: 1; }
.contact-row.virtual-row .contact-phone { grid-column: 1; grid-row: 2; }
.contact-row.virtual-row .contact-meta { grid-column: 2 / 4; grid-row: 1; }
.contact-row.virtual-row .edit-btn { grid-column: 2; grid-row: 2; }
.contact-row.virtual-row .send-btn { grid-column: 3; grid-row: 2; }

.contact-name { line-height: 1.15; min-width: 0; }
.contact-name .first, .contact-name .last, .contact-name .name-line { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-name .last { color: var(--text-muted); }
.contact-name .phone-only { color: var(--text-muted); font-size: 13px; }

.contact-phone { color: var(--text-muted); font-size: 13px; text-align: left; }

.contact-meta { text-align: center; font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; }
.contact-meta .clicked { color: var(--accent); }
.contact-meta .not-clicked { color: var(--text-faint); }
.contact-meta .dot { color: var(--border-strong); padding: 0 3px; }

.send-btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.02em;
  padding: 0;
  height: 34px;
  min-height: 34px;
  border-radius: var(--radius);
}
.send-btn:disabled { background: var(--border-strong); border-color: var(--border-strong); color: var(--text-faint); }

.edit-btn {
  background: var(--surface);
  border: 1px solid var(--text-muted);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  padding: 0;
  height: 34px;
  min-height: 34px;
  border-radius: var(--radius);
}

.list-headers {
  display: grid;
  grid-template-columns: 1fr 52px 56px;
  gap: 8px;
  padding: 6px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
}

.empty-list-note { padding: 24px 16px; text-align: center; color: var(--text-muted); }

/* ---------- Empty state / onboarding ---------- */

.empty-state {
  padding: 32px 20px;
  text-align: center;
}
.empty-state h2 { margin: 0 0 8px; font-size: 20px; }
.empty-state p { color: var(--text-muted); margin: 0 0 20px; }
.empty-state .actions { display: flex; flex-direction: column; gap: 10px; max-width: 320px; margin: 0 auto; }

/* ---------- Toast / undo ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.toast button { background: transparent; border: none; color: #7ee0bd; min-height: unset; padding: 0; font-weight: 700; }

/* ---------- Modals / sheets ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 14px 14px 0 0;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.sheet h3 { margin: 0 0 12px; }
.sheet .subdued-url { color: var(--text-faint); font-size: 12px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet-actions button { flex: 1; }

@media (min-width: 560px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 12px; max-width: 480px; }
}

/* ---------- Login / auth ---------- */

.auth-card {
  max-width: 360px;
  margin: 48px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}
.auth-card h1 { font-size: 18px; margin: 0 0 4px; }
.auth-card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.auth-error { background: var(--danger-bg); color: var(--danger); padding: 8px 10px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }

/* ---------- Import wizard ---------- */

.import-steps { display: flex; gap: 4px; margin-bottom: 16px; font-size: 12px; color: var(--text-faint); }
.import-steps .step.active { color: var(--accent); font-weight: 700; }

.mapping-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.mapping-row .label { width: 110px; flex: 0 0 110px; font-size: 13px; color: var(--text-muted); }

.preview-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }

/* Local Rank sub-tabs (#rk-body) can render long lists (counties, keywords,
   runs, leaderboard rows, reports, links) directly into the page flow —
   cap each table's own height and let it scroll internally instead of the
   whole page growing very tall. */
#rk-body .preview-table-wrap { max-height: 60vh; overflow-y: auto; }
table.preview-table { border-collapse: collapse; width: 100%; font-size: 12px; }
table.preview-table th, table.preview-table td {
  border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; white-space: nowrap;
}
table.preview-table tr.invalid td { background: var(--danger-bg); }

.summary-box { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.summary-box .metric { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.summary-box .metric b { font-variant-numeric: tabular-nums; }

.progress-bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin: 12px 0; }
.progress-bar > div { height: 100%; background: var(--accent); transition: width 0.2s ease; }

/* ---------- Settings / overflow menu ---------- */

.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-list li { border-bottom: 1px solid var(--border); }
.menu-list button {
  width: 100%; text-align: left; border: none; background: transparent; border-radius: 0;
  padding: 12px 4px; font-size: 15px;
}

/* ---------- Admin-specific ---------- */

.admin-shell { max-width: 1100px; }
.admin-tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); padding: 8px 10px 0; background: var(--surface); position: sticky; top: 0; z-index: 20; }
.admin-tab { border: none; background: transparent; padding: 10px 12px; border-bottom: 2px solid transparent; color: var(--text-muted); border-radius: 0; min-height: unset; }
.admin-tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); }
table.data-table th, table.data-table td { border-bottom: 1px solid var(--border); padding: 8px; text-align: left; }
table.data-table th { font-size: 11px; text-transform: uppercase; color: var(--text-faint); letter-spacing: 0.03em; }

/* Virtualized admin Contacts table only — fixed row height so the spacer-row
   math in admin.js stays accurate (must match ADMIN_ROW_HEIGHT there).
   Content is single-line/ellipsis-free today, so this is a hard height, not
   a min-height, to guarantee spacer-row math never drifts out of sync. */
#contacts-table tbody tr.contact-data-row { height: 41px; overflow: hidden; }
#contacts-table tbody tr.spacer-row td { padding: 0; border: 0; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.active { background: #e6f4ea; color: #1e7e34; }
.badge.disabled { background: var(--danger-bg); color: var(--danger); }
.badge.invited { background: #fff4e5; color: var(--warn); }
.badge.accepted { background: #e6f4ea; color: #1e7e34; }

.section-title { font-size: 16px; font-weight: 700; margin: 20px 0 10px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1; min-width: 160px; }

.small-note { font-size: 12px; color: var(--text-faint); }

.loading-state, .blocked-state { padding: 40px 16px; text-align: center; color: var(--text-muted); }

@media (min-width: 720px) {
  #app.owner-app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* ---------- Public ranking report (report.html, Phase D.2) ---------- */

.report-header { padding: 16px 16px 0; }
.report-header h1 { font-size: 18px; margin: 0 0 4px; }
.report-body { padding: 12px 16px 24px; }

.report-map {
  height: 60vh;
  min-height: 320px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 12px;
}

.report-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.report-legend-item { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-muted); }
.report-legend-swatch { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

/* Leaflet's divIcon markers (ranking-map.js) — a colored circle carrying
   the rank number/NR directly, per spec sections 35-39. */
.ranking-map-marker-wrap { position: relative; width: 34px; height: 34px; }
.ranking-map-marker-inner {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 11px; font-weight: 600;
  border: 2px solid rgba(255,255,255,0.85);
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* Secondary historical-movement badge (Phase D.3, spec sections 33/34/38)
   — never replaces the marker's own fill color, which always represents
   CURRENT ranking quality only. */
.ranking-map-marker-badge {
  position: absolute;
  top: 36px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  background: #fff;
  padding: 1px 5px;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.35);
  white-space: nowrap;
}

/* ---------- Phase D.3: reporting date/compare selectors + summary panel ---------- */

.report-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.report-controls .field { flex: 1 1 140px; margin: 0; }

.report-summary {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.report-summary-dates { margin: 0 0 8px; }
.report-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}
.report-summary-stat .report-summary-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.report-summary-stat .report-summary-value {
  font-size: 16px;
  font-weight: 600;
}
.report-summary-movement { font-size: 12px; font-weight: 700; margin-left: 6px; }

/* ---------- Phase D.4: geography selector (spec section 42) ---------- */

.report-geo-option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
}
.report-geo-option input { width: auto; }
.report-geo-cities { margin-left: 22px; }
