/* Colors follow the agency logo: navy #1a345a, light blue #5d9fe1 */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #dfe5ed;
  --text: #17243a;
  --muted: #5f6b7e;
  --accent: #1a345a;
  --accent-text: #ffffff;
  --link: #2b67ad;
  --logo-navy: #1a345a;
  --logo-blue: #5d9fe1;
  --ok: #1a7f4b;
  --ok-bg: #e3f4ea;
  --warn: #9a5b00;
  --warn-bg: #fdf0d5;
  --err: #c0262d;
  --err-bg: #fbe4e4;
  --info: #2b67ad;
  --info-bg: #e5effa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(26, 52, 90, .06);
  color-scheme: light;
}
/* Dark mode: follows the system unless a theme is chosen in the header (data-theme on <html>) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --bg: #0f151e;
  --surface: #17202c;
  --surface-2: #202b39;
  --border: #2b394b;
  --text: #e5eaf1;
  --muted: #96a3b6;
  --accent: #5d9fe1;
  --accent-text: #0c1828;
  --link: #8dbcef;
  --logo-navy: #e5eaf1;
  --logo-blue: #5d9fe1;
  --ok: #5fd39a;
  --ok-bg: #173527;
  --warn: #f3b955;
  --warn-bg: #3a2c12;
  --err: #ff7b7f;
  --err-bg: #3d1a1c;
  --info: #8dbcef;
  --info-bg: #1c2f4a;
  --shadow: none;
  color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f151e;
  --surface: #17202c;
  --surface-2: #202b39;
  --border: #2b394b;
  --text: #e5eaf1;
  --muted: #96a3b6;
  --accent: #5d9fe1;
  --accent-text: #0c1828;
  --link: #8dbcef;
  --logo-navy: #e5eaf1;
  --logo-blue: #5d9fe1;
  --ok: #5fd39a;
  --ok-bg: #173527;
  --warn: #f3b955;
  --warn-bg: #3a2c12;
  --err: #ff7b7f;
  --err-bg: #3d1a1c;
  --info: #8dbcef;
  --info-bg: #1c2f4a;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; word-break: break-all; }
code.block { display: block; padding: 8px 10px; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
h3:first-child { margin-top: 0; }
p { margin: 0 0 10px; }
[hidden] { display: none !important; }

.wrap { max-width: 1320px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 64px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; min-height: 56px; gap: 16px; flex-wrap: wrap; }
.brand { color: var(--text); display: flex; align-items: center; gap: 12px; }
.brand:hover { text-decoration: none; }
.brand-logo { height: 17px; width: auto; display: block; flex: none; }
.brand-name { padding-left: 12px; border-left: 1px solid var(--border); color: var(--muted); font-weight: 600; }
.brand:hover .brand-name { color: var(--text); }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.topbar nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
.topbar nav a:hover, .topbar nav a.active { color: var(--text); background: var(--surface-2); text-decoration: none; }
.topbar nav a.nav-icon { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border-radius: 50%; }
.nav-icon svg { width: 19px; height: 19px; }
.topbar nav a.nav-logout:hover { color: var(--err); background: var(--err-bg); }
.theme-toggle { font: inherit; font-size: 13px; color: var(--muted); background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 5px 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.theme-toggle:hover { color: var(--text); background: var(--surface-2); }
.theme-toggle svg { width: 15px; height: 15px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.back { font-size: 13px; color: var(--muted); }
.head-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card.flush { padding: 0; overflow: hidden; }
.card.empty { text-align: center; padding: 48px 20px; }
.card-danger { border-color: color-mix(in srgb, var(--err) 35%, var(--border)); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; margin-bottom: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi-accent .kpi-value { color: var(--accent); }
.kpi-error .kpi-value { color: var(--err); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
table.compact th, table.compact td { padding: 6px 8px; }
.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trunc { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: " ↕"; opacity: .35; }
th.sorted-asc::after { content: " ↑"; opacity: 1; }
th.sorted-desc::after { content: " ↓"; opacity: 1; }
.site-link { font-weight: 600; }
table.sortable tbody tr:hover { background: var(--surface-2); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-error { background: var(--err-bg); color: var(--err); }
.pill-info { background: var(--info-bg); color: var(--info); }
.pill-new { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.tag { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 0 7px; border-radius: 999px; background: var(--info-bg); color: var(--info); }
.text-bad { color: var(--err); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
ul.plain { padding-left: 18px; margin: 4px 0; }

.score { display: inline-grid; place-items: center; min-width: 28px; height: 24px; font-weight: 700; border-radius: 6px; padding: 0 6px; font-variant-numeric: tabular-nums; }
.score-good { background: var(--ok-bg); color: var(--ok); }
.score-mid { background: var(--warn-bg); color: var(--warn); }
.score-bad { background: var(--surface-2); color: var(--muted); }

.btn {
  display: inline-block; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 7px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 3px 9px; font-size: 12.5px; }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn-danger:hover { background: var(--err); filter: brightness(1.08); }
.btn-danger-text { color: var(--err); }
.link-btn { font: inherit; background: none; border: 0; padding: 0; color: var(--text); cursor: pointer; text-align: left; }
.link-btn:hover { color: var(--link); }

input[type=text], input[type=email], input[type=url], input[type=password], input[type=search], input[type=number], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 7px 10px; min-width: 0; max-width: 100%;
}
textarea { width: 100%; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.input-count { width: 76px; }
.input-sm { width: 170px; padding: 4px 8px; }
.filter { width: 260px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 550; font-size: 13px; }
.login-card { max-width: 420px; margin: 40px auto; }

.settings-form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.settings-form h2 { margin: 0; }
.settings-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 550; font-size: 13px; }
.settings-form label .muted { font-weight: 400; }
.settings-form input[type=text], .settings-form input[type=email], .settings-form input[type=number], .settings-form textarea { width: 100%; }
.settings-form .span-2 { grid-column: 1 / -1; }
.check-inline { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 500 !important; }
.fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px 14px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.fieldset legend { font-weight: 650; padding: 0 6px; }
.schedule-row { gap: 10px 14px; }
.notice { background: var(--warn-bg); color: var(--text); border-radius: 8px; padding: 12px 14px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.notice strong:first-child { color: var(--warn); }
.notice ul { margin: 0; padding-left: 18px; }
.notice li { margin: 3px 0; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 550; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--err-bg); color: var(--err); }

.checklist { list-style: none; padding: 0; margin: 0 0 12px; }
.checklist li { padding: 3px 0; }
.checklist .ok { color: var(--ok); font-weight: 700; }
.checklist .bad { color: var(--err); font-weight: 700; }

/* Accordions */
details > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
details > summary::-webkit-details-marker { display: none; }
.acc-icon { position: relative; width: 20px; height: 20px; flex: none; border-radius: 50%; background: var(--surface-2); transition: transform .25s ease, background .2s; }
.acc-icon::before, .acc-icon::after { content: ""; position: absolute; left: 50%; top: 50%; width: 10px; height: 2px; margin: -1px 0 0 -5px; background: var(--muted); border-radius: 1px; }
.acc-icon::after { transform: rotate(90deg); }
details[open] > summary > .acc-icon { transform: rotate(45deg); background: color-mix(in srgb, var(--accent) 15%, transparent); }
details[open] > summary > .acc-icon::before, details[open] > summary > .acc-icon::after { background: var(--accent); }
details[open] > summary { margin-bottom: 12px; }
.brief-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.brief-body p { margin: 0; }
.brief .trunc { flex: 1; min-width: 0; }

/* Leads */
.leads-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.leads-bar h2 { margin: 0; }
.empty-inner { padding: 32px 16px; text-align: center; }
.leads-table tbody.lead { border-bottom: 1px solid var(--border); }
.leads-table tbody.lead td { border-bottom: 0; }
.leads-table tbody.lead:hover .lead-row { background: var(--surface-2); }
.leads-table tbody.lead.open .lead-row { background: var(--surface-2); }
.lead-name { font-weight: 600; }
.contact-cell { word-break: break-word; max-width: 240px; }
.status-select { padding: 3px 6px; font-size: 12.5px; font-weight: 600; border-radius: 999px; }
.status-new { color: var(--link); }
.status-interesting { color: var(--info); background: var(--info-bg); border-color: transparent; }
.status-contacted { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.status-customer { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.status-not_interested, .status-unsuitable { color: var(--muted); background: var(--surface-2); border-color: transparent; }
.lead.done .lead-row td:not(:nth-child(6)) { opacity: .6; }
.lead-detail > td { background: var(--surface-2); padding: 16px; }
.detail-grid { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 20px; }
.detail-grid p { max-width: 70ch; }
.contact-list { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-direction: column; gap: 8px; }
.contact-list li { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.contact-list .small { display: flex; gap: 4px 10px; flex-wrap: wrap; margin-top: 2px; }
.source-list { word-break: break-all; }
.notes { background: var(--surface); }
.notes-actions { margin-top: 8px; }
.notes-actions .btn-danger-text { margin-left: auto; }

/* Live run status */
.run-status {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.run-status-stale { border-left-color: var(--warn); }
.run-status-done { border-left-color: var(--ok); }
.run-status-failed { border-left-color: var(--err); }
.run-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.run-line { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.run-pct { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.run-current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-check { width: 22px; height: 22px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); display: grid; place-items: center; font-weight: 700; flex: none; }
.run-x { background: var(--err-bg); color: var(--err); }
.spinner { width: 22px; height: 22px; flex: none; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--accent); animation: spin .9s linear infinite; }
.progress { display: block; width: 100%; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress span { display: block; height: 100%; border-radius: 4px; transition: width .6s ease; background-image: linear-gradient(110deg, var(--accent) 40%, color-mix(in srgb, var(--accent) 55%, #fff) 50%, var(--accent) 60%); background-size: 200% 100%; animation: shimmer 1.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes flash-in { from { background: color-mix(in srgb, var(--accent) 22%, transparent); } to { background: transparent; } }
.lead.fresh .lead-row { animation: flash-in 2.5s ease; }
@media (prefers-reduced-motion: reduce) { .spinner, .progress span, .lead.fresh .lead-row { animation: none; } .acc-icon { transition: none; } }

.help-section ol, .help-section ul { padding-left: 20px; }
.help-section li { margin: 5px 0; max-width: 85ch; }
.help-section p { max-width: 85ch; }

@media (max-width: 1000px) { .detail-grid { grid-template-columns: 1fr 1fr; } .detail-grid > div:first-child { grid-column: 1 / -1; } }
@media (max-width: 760px) {
  .brand-logo { height: 14px; }
  .brand-name { display: none; }
  .settings-form { grid-template-columns: 1fr; }
  .head-actions { align-items: stretch; }
  .detail-grid { grid-template-columns: 1fr; }
  .filter { width: 100%; }
  .leads-bar .row { width: 100%; }
  .trunc { max-width: 220px; }
}
