/* Lead Scraper UI — dense operations console.
   Tokens defined light-first; dark mode redefines tokens only. */

@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500&family=Fira+Sans:wght@400;500;600;700&display=swap');

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --fg: #020617;
  --fg-muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #0f172a;
  --on-primary: #ffffff;
  --accent: #0369a1;
  --accent-weak: #e0f2fe;
  --danger: #dc2626;
  --danger-weak: #fee2e2;
  --ok: #047857;
  --ok-weak: #d1fae5;
  --warn: #b45309;
  --warn-weak: #fef3c7;
  --ring: #0369a1;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(2, 6, 23, .06), 0 1px 3px rgba(2, 6, 23, .04);
  --sans: 'Fira Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Fira Code', ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111a2b;
    --surface-2: #16223a;
    --fg: #e6edf7;
    --fg-muted: #94a3b8;
    --border: #1f2c40;
    --border-strong: #2c3d57;
    --primary: #e6edf7;
    --on-primary: #0b1220;
    --accent: #38bdf8;
    --accent-weak: #0c2b3f;
    --danger: #f87171;
    --danger-weak: #3b1a1a;
    --ok: #34d399;
    --ok-weak: #0f3529;
    --warn: #fbbf24;
    --warn-weak: #3a2d0c;
    --ring: #38bdf8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

/* a class rule beats the UA's [hidden] at equal specificity, so state it loudly:
   el.hidden must always win, whatever display the element's class sets */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: 4px;
}

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

.shell { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  width: 208px;
  flex: 0 0 208px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--s4) var(--s3);
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
}

.brand {
  display: flex; align-items: center; gap: var(--s2);
  font-weight: 700; letter-spacing: -.01em; color: var(--fg);
}
.brand svg { color: var(--accent); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: var(--s2);
  min-height: 44px; padding: 0 var(--s3);
  border-radius: var(--radius);
  color: var(--fg-muted); font-weight: 500; text-decoration: none;
  transition: background 160ms ease, color 160ms ease;
}
.nav a:hover { background: var(--surface-2); color: var(--fg); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-weak); color: var(--accent); }
.nav svg { flex: 0 0 18px; }

.sidebar-foot { margin-top: auto; font-size: 13px; color: var(--fg-muted); }

.main { flex: 1; min-width: 0; padding: var(--s5); }

.page-head {
  display: flex; flex-wrap: wrap; gap: var(--s3);
  align-items: center; justify-content: space-between;
  margin-bottom: var(--s5);
}
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 var(--s3); }
.sub { color: var(--fg-muted); font-size: 14px; margin: var(--s1) 0 0; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--s4);
}
.card + .card { margin-top: var(--s4); }

.grid { display: grid; gap: var(--s3); }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s3) var(--s4); }
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-muted); }
.stat .value { font: 600 26px/1.2 var(--mono); font-variant-numeric: tabular-nums; margin-top: var(--s1); }

/* ---------------------------------------------------------------- forms */

label { display: block; font-weight: 600; font-size: 13px; margin-bottom: var(--s1); }
.hint { font-size: 12px; color: var(--fg-muted); margin-top: var(--s1); }

input[type=text], input[type=number], input[type=password], input[type=search],
input[type=date], input[type=time], textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 10px var(--s3);
  font: 400 15px var(--sans);
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
textarea { min-height: 96px; resize: vertical; font-family: var(--mono); font-size: 14px; }
.field + .field { margin-top: var(--s4); }

.check { display: flex; align-items: center; gap: var(--s2); min-height: 44px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.check label { margin: 0; font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: 0 var(--s4);
  font: 600 15px var(--sans);
  border-radius: var(--radius); border: 1px solid transparent;
  background: var(--accent); color: #fff; cursor: pointer;
  transition: filter 160ms ease, background 160ms ease;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--fg); border-color: var(--border-strong); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { min-height: 36px; padding: 0 var(--s3); font-size: 14px; }

.toolbar { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: flex-end; }
.toolbar .field { margin: 0; }
.toolbar > * { min-width: 0; }

/* ---------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px var(--s3); text-align: left; white-space: nowrap; }
th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--fg-muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-top: 1px solid var(--border); }
tbody tr:hover { background: var(--surface-2); }
td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 220px; }

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px var(--s2); border-radius: 999px;
  font: 600 12px var(--sans); border: 1px solid transparent;
}
.badge-a { background: var(--ok-weak); color: var(--ok); }
.badge-b { background: var(--accent-weak); color: var(--accent); }
.badge-c { background: var(--warn-weak); color: var(--warn); }
.badge-d { background: var(--surface-2); color: var(--fg-muted); border-color: var(--border); }
.badge-danger { background: var(--danger-weak); color: var(--danger); }
.badge-neutral { background: var(--surface-2); color: var(--fg-muted); border-color: var(--border); }

.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--fg-muted); }

/* ---------------------------------------------------------------- progress */

.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > span {
  display: block; height: 100%; width: 0;
  background: var(--accent); border-radius: 999px;
  transition: width 300ms ease;
}
.bar.ok > span { background: var(--ok); }

.progress-row { display: grid; grid-template-columns: 150px 1fr 90px; gap: var(--s3); align-items: center; }
.progress-row + .progress-row { margin-top: var(--s3); }
.progress-row .k { font-size: 13px; color: var(--fg-muted); }
.progress-row .v { font: 500 13px var(--mono); font-variant-numeric: tabular-nums; text-align: right; }

.live {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--fg-muted);
}
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* ---------------------------------------------------------------- misc */

.empty { text-align: center; padding: var(--s6) var(--s4); color: var(--fg-muted); }
.empty p { margin: var(--s2) 0 var(--s4); }

.reasons { list-style: none; margin: 0; padding: 0; }
.reasons li { display: flex; gap: var(--s3); padding: var(--s2) 0; border-top: 1px solid var(--border); }
.reasons li:first-child { border-top: 0; }
.reasons .pts { font: 600 13px var(--mono); min-width: 44px; }
.reasons .plus { color: var(--ok); }
.reasons .minus { color: var(--danger); }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: var(--s2) var(--s3); font-size: 14px; }
.kv dt { color: var(--fg-muted); }
.kv dd { margin: 0; word-break: break-word; }

.notice {
  padding: var(--s3) var(--s4); border-radius: var(--radius);
  border: 1px solid var(--warn); background: var(--warn-weak); color: var(--warn);
  font-size: 14px; margin-bottom: var(--s4);
}
.notice-danger { border-color: var(--danger); background: var(--danger-weak); color: var(--danger); }
.notice-ok { border-color: var(--ok); background: var(--ok-weak); color: var(--ok); }
/* a jump link should land with the card's heading in view, not under the page edge */
#delete-campaign { scroll-margin-top: var(--s4); }
.notice-neutral { border-color: var(--border); background: var(--surface-2); color: var(--fg-muted); }

/* a row of small forms that must stay separate elements: HTML forbids nesting */
.actions-row { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin-top: var(--s4); }
.actions-row form { margin: 0; }
/* one mailbox per row, collapsed: the list stays readable at a glance and the
   eight fields only appear for the one being edited */
/* "only this page / select all N" sits inside the bulk bar, next to the count */
.bulkbar .reach { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; font-size: 13px; color: var(--fg-muted); }
.linkish {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: 600 13px var(--sans); color: var(--accent); text-decoration: underline;
}
.linkish:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mailbox {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: var(--s3) var(--s4);
}
.mailbox + .mailbox, .mailbox-add { margin-top: var(--s2); }
.mailbox > summary {
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3);
  align-items: center; justify-content: space-between;
  min-height: 44px; cursor: pointer; list-style: none;
}
.mailbox > summary::-webkit-details-marker { display: none; }
.mailbox > summary::before {
  content: "\203A"; color: var(--fg-muted); font-size: 18px; line-height: 1;
  transition: transform 160ms ease;
}
.mailbox[open] > summary::before { transform: rotate(90deg); }
.mailbox > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mailbox-id { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: baseline; flex: 1; min-width: 0; }
.mailbox-meta { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.mailbox[open] > summary { margin-bottom: var(--s3); border-bottom: 1px solid var(--border); padding-bottom: var(--s3); }

.danger-zone {
  margin-top: var(--s5); padding-top: var(--s4);
  border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; justify-content: space-between;
}

.pager { display: flex; gap: var(--s2); justify-content: flex-end; margin-top: var(--s3); }

/* composer: editor beside a live preview of the real rendered email */
.composer { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s4); align-items: start; }
.composer textarea { min-height: 260px; }

.preview {
  position: sticky; top: var(--s4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.preview-head { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.preview-head .to { font: 500 13px var(--mono); color: var(--fg-muted); }
.preview-head .subject { font-weight: 600; margin-top: 2px; }
.preview-body {
  padding: var(--s4); white-space: pre-wrap; font: 400 14px/1.6 var(--sans);
  max-height: 460px; overflow-y: auto;
}

/* city picker: an input with a suggestion list under it. The textarea beneath
   keeps the chosen names, so the form still works with JS off or a place Google
   does not know. */
.combo { position: relative; }
.combo-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  margin: 0; padding: 4px; list-style: none;
  max-height: 272px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: 0 10px 28px rgba(2, 6, 23, .18);
}
.combo-list li {
  display: flex; flex-wrap: wrap; gap: 2px var(--s2); align-items: baseline;
  min-height: 44px; padding: 8px var(--s3);
  border-radius: calc(var(--radius) - 2px); cursor: pointer;
}
.combo-list li.active { background: var(--accent-weak); }
.combo-list .main { font-weight: 600; font-size: 14px; }
.combo-list .secondary { font-size: 13px; color: var(--fg-muted); }
.loc-chosen { margin-top: var(--s2); min-height: 76px; }

/* the HTML part, rendered as the recipient sees it, under its plain-text twin */
.preview-html {
  display: block; width: 100%; min-height: 260px;
  border: 0; border-top: 1px solid var(--border); background: #fff;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--s2); }
.chip {
  font: 500 12px var(--mono); padding: 3px var(--s2); border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--fg-muted);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* gates: say why the button is disabled instead of just disabling it */
.gates { list-style: none; margin: 0; padding: 0; }
.gates li { display: flex; gap: var(--s3); padding: var(--s2) 0; border-top: 1px solid var(--border); }
.gates li:first-child { border-top: 0; }
.gates .mark { flex: 0 0 18px; font-weight: 700; }
.gates .pass { color: var(--ok); }
.gates .fail { color: var(--danger); }
.gates .what { font-weight: 500; }
.gates .hint { font-size: 13px; color: var(--fg-muted); }

@media (max-width: 1024px) {
  .composer { grid-template-columns: 1fr; }
  .preview { position: static; }
}

/* bulk selection bar — appears only when rows are ticked */
.bulkbar {
  position: sticky; bottom: var(--s3); z-index: 20;
  display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center;
  margin-top: var(--s3); padding: var(--s3) var(--s4);
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(2, 6, 23, .16);
}
.bulkbar .count { font-weight: 600; white-space: nowrap; }
.bulkbar select, .bulkbar input[type=text] { min-width: 170px; width: auto; }
.bulkbar .spacer { flex: 1 1 auto; }

td.tick, th.tick { width: 34px; padding-right: 0; }
td.tick input, th.tick input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
/* an 18px box is a small target — the label stretches the hit area to 44px */
.tickwrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 44px; min-width: 34px; margin: -10px 0; cursor: pointer;
}
tr.picked { background: var(--accent-weak); }

.list-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px var(--s2); margin: 0 4px 4px 0;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); font-size: 12px;
}

/* login */
.login-wrap { display: grid; place-items: center; min-height: 100dvh; padding: var(--s4); }
.login-card { width: 100%; max-width: 360px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    flex-direction: row; align-items: center; gap: var(--s3);
    overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .nav { flex-direction: row; }
  .nav a span { display: none; }
  .nav a { padding: 0 var(--s3); }
  .sidebar-foot { display: none; }
  .main { padding: var(--s4) var(--s3); }
  .progress-row { grid-template-columns: 110px 1fr 70px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
