:root {
  --bg: #f4f6f9; --card: #fff; --text: #212529; --muted: #6c757d; --border: #dee2e6;
  --blue: #0d6efd; --green: #198754; --purple: #6f42c1; --dark: #212529; --red: #dc3545; --amber: #b58100;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--blue); }
h1 { font-size: 1.4rem; margin: 0 0 12px; } h2 { font-size: 1.1rem; margin: 18px 0 10px; } h3 { font-size: 1rem; margin: 18px 0 8px; }

.topbar { background: var(--blue); color: #fff; padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; text-decoration: none; }
.usernav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.usernav a, .linkbtn { color: #fff; text-decoration: none; font: inherit; }
.usernav .who { opacity: .85; font-size: .9rem; }
.linkbtn { background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 18px; margin-bottom: 16px; }
.card.narrow { max-width: 440px; margin: 40px auto; }
.grid2 { display: grid; grid-template-columns: 3fr 2fr; gap: 24px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.span-all { grid-column: 1 / -1; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }

label { display: block; font-weight: 600; margin: 4px 0 6px; }
label.check { font-weight: 400; display: flex; gap: 8px; align-items: center; margin: 4px 0; }
.checks { padding-bottom: 6px; }
select, input:not([type=checkbox]), textarea { width: 100%; padding: 8px 10px; font: inherit; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 10px; background: #fff; }
textarea { resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: .9rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row input, .row select { flex: 1; min-width: 160px; margin: 0; }
.toolbar { margin-bottom: 12px; }
form.inline { display: inline; }

.btn { display: inline-block; border: 1px solid var(--border); border-radius: 6px; padding: 8px 14px; font: inherit; font-weight: 600; color: var(--text); background: #f8f9fa; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.dark, .btn.green, .btn.purple, .btn.danger { color: #fff; border-color: transparent; }
.btn.dark { background: var(--dark); } .btn.green { background: var(--green); } .btn.purple { background: var(--purple); } .btn.danger { background: var(--red); }
.btn.sm { padding: 3px 9px; font-size: .82rem; }
.btn.full { width: 100%; margin-top: 8px; }

.tabs { display: flex; gap: 4px; margin-bottom: -1px; flex-wrap: wrap; }
.tab { border: 1px solid var(--border); border-bottom: 0; background: #e9ecef; padding: 8px 14px; border-radius: 8px 8px 0 0; font: inherit; cursor: pointer; }
.tab.active { background: var(--card); font-weight: 600; }
.panel { border-top-left-radius: 0; }
.pill { background: var(--blue); color: #fff; border-radius: 10px; padding: 0 7px; font-size: .75rem; }
.pill:empty { display: none; }

.console { background: #1e1e1e; color: #39ff14; font: 13px/1.45 ui-monospace, "Courier New", monospace; padding: 12px; border-radius: 6px; height: 340px; overflow: auto; white-space: pre-wrap; margin: 14px 0 0; }
.console .warning { color: #ffc107; } .console .error { color: #ff6b6b; }
.article { white-space: pre-wrap; margin-top: 12px; }

.muted { color: var(--muted); } .small { font-size: .85rem; }
.ok { color: var(--green); } .err { color: var(--red); }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.compact th, table.compact td { padding: 5px 8px; font-size: .9rem; }
tbody tr:nth-child(odd) { background: #f8f9fa; }
td.actions { white-space: normal; }
td.actions .btn, td.actions details { margin: 2px 0; }
.inline-details { display: inline-block; }
.inline-details summary { list-style: none; }
.inline-details[open] form { margin-top: 6px; }
.lead-site b { word-break: break-all; }
.lead-detail { margin-top: 6px; }
.lead-detail textarea { font-family: inherit; }
.signals { font-size: .85rem; color: var(--muted); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: .8rem; color: #fff; background: var(--muted); white-space: nowrap; }
.badge.green { background: var(--green); } .badge.red { background: var(--red); } .badge.amber { background: var(--amber); }
.badge.blue { background: var(--blue); } .badge.dark { background: var(--dark); }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; background: #e7f1ff; border: 1px solid #b6d4fe; }
.flash.error { background: #f8d7da; border-color: #f1aeb5; } .flash.success { background: #d1e7dd; border-color: #a3cfbb; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--red); color: #fff; padding: 10px 16px; border-radius: 6px; max-width: calc(100% - 32px); z-index: 10; }
.toast.ok-toast { background: var(--green); }
