/* Dashboard and login styles. Served as a file so the CSP can refuse inline styles. */
:root {
  --bg: #fafaf9; --panel: #ffffff; --ink: #1c1917; --muted: #6b6560; --line: #e7e5e4; --chip: #f5f5f4;
  --good: #15803d; --good-bg: #dcfce7; --warn: #a16207; --warn-bg: #fef3c7; --bad: #b91c1c; --bad-bg: #fee2e2;
  --info: #1d4ed8; --info-bg: #dbeafe; --focus: #2563eb; --shadow: 0 1px 2px rgba(0,0,0,.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0a09; --panel: #1c1917; --ink: #f5f5f4; --muted: #a8a29e; --line: #2e2a27; --chip: #292524;
    --good: #4ade80; --good-bg: #14532d; --warn: #fbbf24; --warn-bg: #422006; --bad: #f87171; --bad-bg: #450a0a;
    --info: #93c5fd; --info-bg: #1e3a8a; --focus: #60a5fa; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0a09; --panel: #1c1917; --ink: #f5f5f4; --muted: #a8a29e; --line: #2e2a27; --chip: #292524;
  --good: #4ade80; --good-bg: #14532d; --warn: #fbbf24; --warn-bg: #422006; --bad: #f87171; --bad-bg: #450a0a;
  --info: #93c5fd; --info-bg: #1e3a8a; --focus: #60a5fa; --shadow: none;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif; overflow-x: hidden; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 16px; }
h2 { font-size: 18px; }
h3 { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0; }
.meta { color: var(--muted); font-size: 12px; }
.sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.err { color: var(--bad); }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- buttons and inputs ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 5px 12px; font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.btn:hover { background: var(--chip); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary:hover { opacity: .9; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
/* Fixed red in both themes: the dark theme's lighter red would not carry white text. */
.btn.danger.solid { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn.danger.solid:hover { background: #991b1b; }
.btn.small { min-height: 26px; padding: 2px 9px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=email], input[type=number], input[type=password], select { width: 100%; min-height: 34px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; font-size: 14px; }
input[type=checkbox], input[type=radio] { accent-color: var(--ink); }

/* ---------- top status bar ---------- */
.topbar { position: relative; z-index: 30; background: var(--panel); border-bottom: 1px solid var(--line); box-shadow: var(--shadow); }
.topbar-in { max-width: 1120px; margin: 0 auto; padding: 12px 16px; display: grid; gap: 10px; }
.brand { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.brand .tools { display: flex; gap: 8px; align-items: center; }
.brand form { margin: 0; }
.status-line { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.status-text { flex: 1 1 320px; font-size: 16px; font-weight: 600; min-width: 0; }
.status-text .why { display: block; font-size: 13px; font-weight: 400; color: var(--muted); margin-top: 2px; }
.healthrow { display: flex; gap: 6px 14px; align-items: center; flex-wrap: wrap; }
.health { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink); background: none; border: 0; padding: 2px 0; font: inherit; font-size: 12px; cursor: help; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.green { background: var(--good); }
.dot.amber { background: var(--warn); }
.dot.red { background: var(--bad); }
.killwrap { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-weight: 700; font-size: 12px; white-space: nowrap; }
.pill.dry { background: var(--warn-bg); color: var(--warn); }
.pill.live { background: #b91c1c; color: #fff; }
.pill.killed { background: var(--ink); color: var(--bg); }
.pill.idle { background: var(--chip); color: var(--muted); }

/* ---------- page and sections ---------- */
.page { max-width: 1120px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; gap: 8px 12px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin-bottom: 14px; }
.card-head > div { min-width: 0; }
.toast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 60; max-width: calc(100vw - 32px); background: var(--ink); color: var(--bg); border-radius: 10px; padding: 10px 14px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.3); }
.toast.bad { background: var(--bad); color: #fff; }
.toast[hidden] { display: none; }

/* Right now */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.fact { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.fact .k { color: var(--muted); font-size: 12px; display: flex; align-items: center; }
.fact .v { font-weight: 600; font-size: 15px; margin-top: 2px; overflow-wrap: anywhere; }
.fact .v.good { color: var(--good); }
.fact .v.warn { color: var(--warn); }
.fact .v.bad { color: var(--bad); }
.fact .meta { margin-top: 2px; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }

/* Today */
.groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.group { border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-width: 0; }
.group h3 { display: flex; align-items: center; margin-bottom: 8px; }
.group .total { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.group .total small { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.stats { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; }
.stats li { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 3px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.stats li:last-child { border-bottom: 0; }
.stats li b { font-variant-numeric: tabular-nums; }
.stats li.bad b, .stats li.bad span:first-child { color: var(--bad); }
.stats .lbl { display: flex; align-items: center; min-width: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 8px; }
.tile { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.tile b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 12px; display: flex; align-items: center; }

/* Rules */
.notice { border-left: 3px solid var(--info); background: var(--info-bg); color: var(--ink); padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.rules { display: grid; gap: 12px; }
.rule { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 10px; min-width: 0; }
.rule.off { opacity: .75; }
.rule-top { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.rule-top .name { font-weight: 600; font-size: 15px; flex: 1 1 160px; min-width: 0; overflow-wrap: anywhere; }
.badge { display: inline-block; font-weight: 800; font-size: 13px; letter-spacing: .06em; border-radius: 6px; padding: 3px 10px; }
.badge.copy { background: var(--info-bg); color: var(--info); }
.badge.remove { background: var(--bad-bg); color: var(--bad); }
.sentence { font-size: 14px; }
.est { font-size: 12px; color: var(--muted); }
.warnline { font-size: 12px; color: var(--warn); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; user-select: none; }
.switch input { appearance: none; -webkit-appearance: none; width: 38px; height: 22px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; margin: 0; transition: background .15s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: left .15s; }
.switch input:checked { background: var(--good); }
.switch input:checked::after { left: 19px; }
.rule-form { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 12px; }
.rule-form[hidden] { display: none; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > .lt, fieldset legend { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; align-items: center; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0; padding: 8px 12px 10px; min-width: 0; }
fieldset legend { padding: 0 4px; }
.choice { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; cursor: pointer; font-size: 13px; }
.choice input { margin-top: 3px; }
.choice small { display: block; color: var(--muted); font-size: 12px; }
.rule[data-kind="all"] .scoped { opacity: .4; pointer-events: none; }
.preview { background: var(--chip); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.newrule { justify-self: start; }

.hist { display: grid; gap: 3px; font-size: 12px; font-variant-numeric: tabular-nums; max-width: 520px; }
.hist div { display: grid; grid-template-columns: 22px 1fr 40px; gap: 8px; align-items: center; }
.hist i { display: block; height: 8px; background: var(--good); border-radius: 4px; min-width: 1px; width: 0; }
details.more { margin-top: 12px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details.more[open] summary { margin-bottom: 8px; }

/* multi-select for clients and campaigns */
.ms { position: relative; }
.ms-btn { width: 100%; justify-content: flex-start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 34px; }
.ms-panel { position: absolute; z-index: 20; left: 0; top: calc(100% + 4px); width: min(360px, calc(100vw - 48px)); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.ms-panel[hidden] { display: none; }
.ms-list { max-height: 260px; overflow: auto; margin-top: 6px; display: grid; gap: 1px; }
.ms-row { display: flex; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 6px; font-size: 13px; color: var(--ink); cursor: pointer; }
.ms-row:hover { background: var(--chip); }
.ms-row .nm { flex: 1; overflow-wrap: anywhere; }
.sbadge { font-size: 10px; border-radius: 999px; padding: 0 6px; background: var(--chip); color: var(--muted); }
.sbadge.ACTIVE { background: var(--good-bg); color: var(--good); }
.sbadge.PAUSED { background: var(--warn-bg); color: var(--warn); }
.ms-note { font-size: 12px; color: var(--muted); padding: 2px 6px; }

/* state chips */
.chip { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 12px; background: var(--chip); color: var(--ink); white-space: nowrap; }
.chip.done { background: var(--good-bg); color: var(--good); }
.chip.prog { background: var(--warn-bg); color: var(--warn); }
.chip.fail { background: var(--bad-bg); color: var(--bad); }
.chip.skip { background: var(--chip); color: var(--muted); }
.chip.score { font-weight: 700; }
.chip.hi { background: var(--good-bg); color: var(--good); }
.chip.mid { background: var(--warn-bg); color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Recent leads table; turns into stacked cards on narrow screens so the page never scrolls sideways */
.tablewrap { overflow-x: auto; }
table.leads { width: 100%; border-collapse: collapse; font-size: 13px; }
table.leads th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.leads td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.leads td.email { overflow-wrap: anywhere; font-weight: 500; min-width: 180px; }
table.leads td.when { white-space: nowrap; }
table.leads td .meta { display: block; }
table.leads td.errcell { color: var(--bad); font-size: 12px; overflow-wrap: anywhere; max-width: 260px; }
@media (max-width: 760px) {
  table.leads thead { display: none; }
  table.leads, table.leads tbody, table.leads tr, table.leads td { display: block; width: 100%; }
  table.leads tr { border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; margin-bottom: 8px; }
  table.leads td { border: 0; padding: 3px 0; display: flex; gap: 10px; justify-content: space-between; text-align: right; }
  table.leads td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: none; }
  table.leads td.email { font-size: 14px; }
  table.leads td.errcell { max-width: none; }
  table.leads td:empty { display: none; }
  table.leads td .cv { min-width: 0; overflow-wrap: anywhere; }
  table.leads td.email .cv { font-weight: 600; }
  .tablewrap { overflow: visible; }
}

/* Reply feed */
.feedbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.feed { display: grid; gap: 8px; }
.reply { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.reply .top { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.reply .who { font-weight: 600; overflow-wrap: anywhere; }
.reply .camp { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.reply .when { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.reply .chips { margin-top: 6px; }
.reply .reason { margin-top: 6px; font-size: 13px; }
.reply details { margin-top: 6px; color: var(--muted); font-size: 13px; }
.reply details pre { white-space: pre-wrap; font: inherit; color: var(--ink); margin: 6px 0 0; overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: 20px 0; text-align: center; }

/* info tips */
.i { display: inline-grid; place-items: center; width: 16px; height: 16px; margin-left: 5px; padding: 0; border: 1px solid var(--muted); border-radius: 50%; background: transparent; color: var(--muted); font: 700 10px/1 Georgia, serif; font-style: italic; cursor: help; vertical-align: middle; text-transform: none; letter-spacing: 0; flex: none; }
.i:hover, .i:focus-visible { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tipbox { position: fixed; z-index: 70; max-width: min(320px, calc(100vw - 32px)); background: var(--ink); color: var(--bg); border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.45; font-weight: 400; text-transform: none; letter-spacing: 0; box-shadow: 0 6px 24px rgba(0,0,0,.3); pointer-events: none; }
.tipbox[hidden] { display: none; }

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: grid; gap: 12px; box-shadow: var(--shadow); }
.login h1 { font-size: 20px; }
.login-form { display: grid; gap: 8px; }
.login-form label { font-size: 13px; font-weight: 600; }
.login-form .btn { justify-content: center; min-height: 38px; margin-top: 4px; }
.login-error { background: var(--bad-bg); color: var(--bad); border-radius: 8px; padding: 8px 10px; font-size: 13px; }

/* Pinned only where there is room; on a phone it would cover half the screen. */
@media (min-width: 761px) { .topbar { position: sticky; top: 0; } }
@media (max-width: 560px) {
  .status-text { font-size: 15px; flex-basis: 100%; }
  .killwrap { margin-left: 0; }
  .card { padding: 14px; }
  .groups { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
/* While a rule is being edited, its on/off switch lives in the form only, so the two cannot disagree. */
.rule[data-editing] .rule-top .switch, .rule[data-editing] .rule-top [data-edit] { display: none; }

/* Remove one lead */
.one-find { display: grid; gap: 4px; max-width: 520px; }
.one-row { display: flex; gap: 8px; align-items: stretch; }
.one-row input { flex: 1 1 auto; min-width: 0; }
.one-result, .one-progress { margin-top: 12px; display: grid; gap: 10px; min-width: 0; }
.one-result:empty, .one-progress:empty { display: none; }
.one-result .meta, .one-progress .meta { overflow-wrap: anywhere; }
table.leads td.tick { width: 1%; white-space: nowrap; }
table.leads td.tick input { width: 18px; height: 18px; margin: 0; }
.one-why { color: var(--muted); font-size: 12px; }
.one-confirm { border: 1px solid var(--bad); border-radius: 10px; padding: 12px; display: grid; gap: 8px; max-width: 520px; }
.one-confirm label { font-size: 13px; font-weight: 600; }
.one-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.one-list li { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.one-list li:last-child { border-bottom: 0; }
.one-list .who { font-weight: 500; overflow-wrap: anywhere; min-width: 0; }
.one-list .when { margin-left: auto; color: var(--muted); font-size: 12px; }
.one-list .err { flex-basis: 100%; font-size: 12px; overflow-wrap: anywhere; }
