:root {
    --bg: #0f1420;
    --panel: #18202f;
    --panel-2: #1f2937;
    --border: #2b3748;
    --text: #e6e9ef;
    --muted: #8b95a7;
    --accent: #4f7cff;
    --accent-hover: #6b8fff;
    --ok: #34d399;
    --warn: #fbbf24;
    --err: #f87171;
    --radius: 8px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* --- Nav --- */
.topnav {
    display: flex; align-items: center; gap: 16px;
    padding: 0 24px; height: 52px;
    background: var(--panel); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.topnav a { color: var(--muted); text-decoration: none; font-weight: 500; }
.topnav a:hover { color: var(--text); }
.brand { color: var(--text) !important; font-weight: 700; font-size: 16px; letter-spacing: 0.5px; }
.nav-sep { color: var(--border); }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.nav-user { color: var(--muted); font-size: 13px; }

/* --- Layout --- */
.container { max-width: 1240px; margin: 0 auto; padding: 24px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { margin: 0 0 12px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.panel {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
}

/* --- Stats --- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; }
.stat-num { font-size: 26px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }

/* --- Tables --- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:hover td { background: rgba(255,255,255,0.02); }
.table .num { text-align: right; }
.table-tools { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.msg-body pre { font-family: inherit; white-space: pre-wrap; margin: 0; font-size: 12.5px; color: var(--muted); max-width: 420px; }

/* --- Forms --- */
label { display: block; margin-bottom: 14px; font-weight: 500; font-size: 13px; }
label span { display: block; margin-bottom: 4px; }
input, textarea, select {
    width: 100%; padding: 8px 10px; margin-top: 4px;
    background: var(--panel-2); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); font: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
input[type="checkbox"] { width: auto; margin: 0; }
input[type="search"] { max-width: 280px; }
.inline-form { display: flex; gap: 10px; margin-top: 16px; align-items: end; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: auto; margin-top: 0; }
.inline { display: inline; }
.prompt textarea { resize: vertical; }

/* --- Buttons --- */
.btn {
    display: inline-block; padding: 8px 16px; border: 1px solid var(--border);
    background: var(--panel-2); color: var(--text); border-radius: 6px;
    font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; }
button.link { background: none; border: none; color: var(--muted); font: inherit; cursor: pointer; padding: 0; }
button.link:hover { color: var(--text); }

/* --- Badges --- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.status-new { background: #2b3748; color: #9fb3d1; }
.status-approved, .status-running { background: #1e3a2f; color: var(--ok); }
.status-paused_leads, .status-paused_messages, .status-draft { background: #3a3320; color: var(--warn); }
.status-sent, .status-contacted { background: #1f2f4a; color: #7ea4f7; }
.status-replied, .status-completed { background: #1e3a2f; color: var(--ok); }
.status-rejected, .status-failed { background: #3d2020; color: var(--err); }
.route-outreach { background: #1e3a2f; color: var(--ok); }
.route-nurture { background: #1f2f4a; color: #7ea4f7; }
.route-long_term { background: #3a3320; color: var(--warn); }
.route-reject { background: #3d2020; color: var(--err); }
.actor-agent { background: #2b2545; color: #a89bf5; }
.actor-human { background: #1f2f4a; color: #7ea4f7; }
.actor-system { background: #2b3748; color: #9fb3d1; }
.evt-opened, .evt-sent { background: #1f2f4a; color: #7ea4f7; }
.evt-clicked { background: #2b2545; color: #a89bf5; }
.evt-replied { background: #1e3a2f; color: var(--ok); }
.evt-bounced, .evt-unsubscribed { background: #3d2020; color: var(--err); }

/* --- Flash --- */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }
.flash-ok { background: #1e3a2f; color: var(--ok); border: 1px solid #2a5243; }
.flash-err { background: #3d2020; color: var(--err); border: 1px solid #5a3030; }

/* --- Auth --- */
.auth-card {
    max-width: 440px; margin: 8vh auto 0; padding: 32px;
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
}
.auth-card h1 { margin-bottom: 8px; }
.auth-card form { margin-top: 20px; }
.auth-card .btn { width: 100%; }
.qr-box { display: flex; justify-content: center; margin: 18px 0; }
.qr-box svg { width: 200px; height: 200px; background: #fff; padding: 10px; border-radius: 8px; }
.totp-secret { display: flex; align-items: center; gap: 10px; margin: 16px 0; }
.totp-secret code { font-size: 16px; letter-spacing: 2px; background: var(--panel-2); padding: 8px 14px; border-radius: 6px; }
code.wrap { word-break: break-all; display: block; margin: 8px 0; font-size: 12px; }
.recovery-codes { columns: 2; list-style: none; padding: 0; }
.recovery-codes li { margin-bottom: 6px; }
.recovery-codes code { background: var(--panel-2); padding: 4px 10px; border-radius: 4px; }

/* --- Misc --- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 16px; margin: 12px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.audit-list { list-style: none; padding: 0; margin: 0; }
.audit-list li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: min(560px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,0.6); }
details summary { cursor: pointer; color: var(--muted); }
details summary:hover { color: var(--text); }
