:root {
  --warn-bg: #fef0c7;
  --warn-text: #93370d;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #d9dee5;
  --text: #1c2430;
  --muted: #5b6676;
  --accent: #0b6e8a;
  --accent-text: #ffffff;
  --danger: #b42318;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a2029;
    --border: #2c3542;
    --text: #e6ebf1;
    --muted: #9aa5b4;
    --accent: #4fb3cf;
    --accent-text: #0b1218;
    --danger: #f97066;
    --warn-bg: #4e2f0a;
    --warn-text: #fec84b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 16px;
}

p { color: var(--muted); }

[hidden] { display: none !important; }

/* ---------- Forms ---------- */

.stack { display: grid; gap: 16px; }

label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  font-size: 0.95rem;
}

input, select, textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

button:disabled { opacity: 0.6; cursor: progress; }

button.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.link-button {
  background: none;
  color: var(--accent);
  padding: 4px 0;
  font-weight: 500;
}

/* ---------- Sign-in ---------- */

.auth-page main { padding-top: 10vh; }

.auth-card {
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 24px;
}

.auth-card h1 { margin: 0 0 8px; font-size: 1.4rem; }

.lede { margin: 0; }

.qr {
  justify-self: center;
  background: #ffffff;
  padding: 8px;
  border-radius: 8px;
}

.secret {
  display: block;
  word-break: break-all;
  padding: 8px;
  background: var(--bg);
  border-radius: 6px;
}

.status { min-height: 1.5em; margin: 16px 0 0; color: var(--muted); }
.status.is-error { color: var(--danger); }

/* ---------- Signed-in layout ---------- */

body.app {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}
body.app > main { min-width: 0; width: 100%; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 8px; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.menu-toggle { display: none; }

.side-nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.side-nav a, .side-nav .nav-soon {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.side-nav a:hover { background: var(--bg); }
.side-nav a[aria-current="page"] { background: var(--bg); color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.side-nav .nav-soon { color: var(--muted); opacity: 0.65; cursor: default; }
.nav-icon { display: inline-flex; }
.soon-badge {
  margin-left: auto;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
}

.side-foot {
  margin-top: auto;
  display: grid;
  gap: 4px;
  padding: 12px 8px 0;
  border-top: 1px solid var(--border);
}
.side-email { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.side-foot .link-button { justify-self: start; }

/* Phones and narrow windows: the sidebar becomes a top bar with a Menu button. */
@media (max-width: 800px) {
  body.app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 12px; gap: 0; border-right: 0; border-bottom: 1px solid var(--border); }
  .menu-toggle { display: inline-block; padding: 6px 12px; background: var(--bg); color: var(--text); border: 1px solid var(--border); }
  .sidebar nav, .side-foot { display: none; }
  .sidebar.is-open nav { display: block; margin-top: 12px; }
  .sidebar.is-open .side-foot { display: grid; margin-top: 12px; }
}

a { color: var(--accent); }
h1 { margin: 0; font-size: 1.6rem; }
h2 { margin: 0 0 12px; font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

main.wide { max-width: 1280px; padding-top: 24px; }

.page-head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 0; }

/* ---------- Pipeline summary ---------- */

.pipeline { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; }

.stage {
  display: grid;
  gap: 2px;
  min-width: 96px;
  text-align: left;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
  font-size: 0.85rem;
}
.stage-count { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.stage.is-active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* ---------- Filters ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.filters label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.filters .grow { flex: 1 1 220px; }
.filters select { min-width: 120px; }
.filters .check { display: flex; align-items: center; gap: 6px; padding-bottom: 10px; color: var(--text); font-weight: 500; }

/* ---------- Table ---------- */

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
table.leads { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.leads th, .leads td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.leads th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); white-space: nowrap; }
.leads tbody tr:last-child td { border-bottom: 0; }
.leads tbody tr:hover { background: var(--bg); }
.leads tbody[aria-busy="true"] { opacity: 0.5; }
.row-link { font-weight: 600; text-decoration: none; }
.row-link:hover { text-decoration: underline; }
.contact-cell { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; white-space: nowrap; }
.overdue { color: var(--danger); font-weight: 600; }

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 16px 0; }

/* ---------- Pills and tags ---------- */

.pill, .tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.tag-warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.pill.status-contacted, .pill.status-researched { color: var(--accent); border-color: var(--accent); }
.pill.status-replied, .pill.status-interested, .pill.status-demo_built, .pill.status-proposal {
  background: var(--accent); color: var(--accent-text); border-color: var(--accent);
}
.pill.status-won { background: #12b76a; color: #ffffff; border-color: #12b76a; }
.pill.status-lost, .pill.status-do_not_contact { text-decoration: line-through; }

/* ---------- Lead page ---------- */

.back-link { display: inline-block; margin-bottom: 16px; text-decoration: none; }

.lead-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 20px; }
.lead-head p { margin: 4px 0 0; }
.lead-controls { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.lead-controls label { font-size: 0.8rem; color: var(--muted); }
.lead-controls p { margin: 0 0 10px; min-width: 60px; }

.lead-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .lead-grid { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }

.details { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0; font-size: 0.92rem; }
.details dt { color: var(--muted); font-weight: 600; }
.details dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }

.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
textarea { width: 100%; resize: vertical; }

.timeline { list-style: none; margin: 20px 0 0; padding: 0; display: grid; gap: 16px; }
.timeline li { border-left: 2px solid var(--border); padding-left: 12px; }
.timeline .kind-note, .timeline .kind-call { border-left-color: var(--accent); }
.timeline-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 0.82rem; color: var(--muted); }
.timeline-body { margin: 6px 0 0; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- Shared page pieces ---------- */

h3 { margin: 8px 0 0; font-size: 1rem; }
code { font-size: 0.9em; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.danger { color: var(--danger); }

.banner {
  padding: 12px 16px;
  margin-bottom: 16px;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn-text);
}
.banner.is-ok { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.banner ul { margin: 6px 0 0; padding-left: 20px; }

.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }

.empty-state { text-align: center; padding: 32px 16px; }
.empty-state p { margin: 0 0 12px; }

.table-wrap.flat { border: 0; border-radius: 0; background: none; }
.leads tr.is-inactive td { opacity: 0.6; }
.leads td.actions { text-align: right; }

.billing-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 960px) { .billing-grid { grid-template-columns: 1fr; } }

.dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
.dialog::backdrop { background: rgb(0 0 0 / 50%); }
.dialog h2 { margin: 0; }
.row .grow { flex: 1 1 160px; }

/* ---------- Lead page: customer + email ---------- */

.customer-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.lead-controls > button { margin-bottom: 0; }

.email-preview, .preview-box { border-top: 1px solid var(--border); padding-top: 12px; }
#email-hint:empty, #preview-warnings:empty, #tp-warnings:empty, #template-error:empty { display: none; }
.preview-body {
  margin: 12px 0 0;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.92rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- Outreach ---------- */

.template-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.template-item {
  width: 100%;
  display: grid;
  gap: 2px;
  text-align: left;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
}
.template-item.is-active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.editor { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--accent);
  border: 1px solid var(--border);
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  font-weight: 500;
}

.result-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 2px; }

.choices { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 0; padding: 0; border: 0; }
.choices legend { font-weight: 600; font-size: 0.95rem; margin-bottom: 6px; padding: 0; }
#reply-error:empty { display: none; }
.timeline .kind-reply { border-left-color: #12b76a; }

/* ---------- Website report card ---------- */

a.button {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  text-decoration: none;
}
.report-card h3 { margin: 16px 0 6px; font-size: 0.95rem; }
.report-card .card-head { flex-wrap: wrap; }
.score-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.score-badge {
  display: grid;
  min-width: 78px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  text-align: center;
}
.score-value { font-size: 1.3rem; font-weight: 700; }
.score-label { font-size: 0.72rem; color: var(--muted); }
.score-good .score-value, .score-chip.score-good { color: #12b76a; }
.score-fair .score-value, .score-chip.score-fair { color: #f79009; }
.score-poor .score-value, .score-chip.score-poor { color: #f04438; }
.score-chip { font-weight: 700; }
.shots { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; }
.shot { display: block; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--bg); }
.shot img { display: block; width: 100%; height: auto; }
.shot-desktop { flex: 3 1 0; }
.shot-mobile { flex: 1 1 0; max-width: 120px; }
.bullets { margin: 0; padding-left: 20px; }
.prose { white-space: pre-line; margin: 0; }
.findings { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.findings summary { cursor: pointer; font-weight: 600; }
.findings .plain-list, .findings .details { margin-top: 10px; }
.pill.sev-high { background: #f04438; color: #fff; border-color: #f04438; }
.pill.sev-medium { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }

/* ---------- Email card ---------- */

.email-card .from-line { margin: 0; }
.email-card label { font-weight: 600; }
.status.success, .small.success { color: #12b76a; }
.small.danger { color: var(--danger); }
#email-card .status:empty { display: none; }

/* ---------- Results ---------- */

.results-controls { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; margin-bottom: 16px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.segmented button {
  background: none;
  color: var(--muted);
  border-radius: 0;
  padding: 8px 14px;
  font-weight: 500;
  border-right: 1px solid var(--border);
}
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.inline-label { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--muted); }

.results-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; margin-bottom: 16px; }
@media (max-width: 960px) { .results-grid { grid-template-columns: 1fr; } }

.funnel { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 14px; }
.funnel-step { display: grid; gap: 4px; }
.funnel-label { display: flex; justify-content: space-between; font-weight: 500; }
.funnel-label strong { font-size: 1.1rem; }
.funnel-track { height: 12px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.funnel-bar { height: 100%; background: var(--accent); border-radius: 999px; }
.funnel-step:last-child .funnel-bar { background: #12b76a; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { display: grid; gap: 2px; padding: 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.kpi-value { font-size: 1.4rem; font-weight: 700; }
.kpi-label { font-size: 0.85rem; font-weight: 600; }
.kpi-note { font-size: 0.78rem; color: var(--muted); }
.kpi.kpi-bad .kpi-value { color: var(--danger); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.dot-ok { background: #12b76a; }
.dot-bad { background: #f79009; }

.how-counted summary { cursor: pointer; font-weight: 600; }
.how-counted .details { margin-top: 12px; }
.how-counted { margin-top: 16px; }
#by-source-card { margin-top: 0; }

.hint { margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.hint:empty { display: none; }

.contact-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.contact-head .link-button { padding: 0; }
