/* Mailium — ops dashboard. Light theme, mobile-first.
   Every text/background pair below is >= 4.5:1 (WCAG AA). The previous dark palette
   put the whole sidebar and every table header at 3.5-3.9:1, and five page templates
   already shipped light-themed <style> blocks with no background set, so they rendered
   pale text on the dark shell. Light is what those pages were written for. */

:root {
    /* surfaces */
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f1f3f7;
    --border: #d8dde5;
    --border-strong: #c2c9d4;

    /* text — verified on both --bg and --surface */
    --text: #111827;         /* 16.7:1 on bg */
    --text-muted: #5a6572;   /*  5.6:1 on bg, 5.9:1 on white */

    /* accents — all >= 5:1 on white */
    --primary: #1d4ed8;
    --primary-hover: #1739a8;
    --green: #15803d;
    --yellow: #a15c00;
    --red: #b42318;
    --purple: #5b3ea1;

    /* tinted fills for badges/pills */
    --green-bg: #e6f6ec;
    --yellow-bg: #fff4e5;
    --red-bg: #fde8e8;
    --blue-bg: #e8f1fe;
    --purple-bg: #f1eefe;
    --neutral-bg: #eef1f6;

    --sidebar-w: 220px;
    --topbar-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    font-size: 15px;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ===================== */
/* Mobile-first: Topbar  */
/* ===================== */
.topbar {
    display: flex;
    align-items: center;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar .logo { font-size: 1.15rem; font-weight: 700; color: var(--primary); }
.topbar .menu-toggle {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.6rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    margin-right: 0.75rem;
    line-height: 1;
}

/* ===================== */
/* Sidebar / Nav overlay */
/* ===================== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
}
.sidebar.open { transform: translateX(0); }

.sidebar .sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.sidebar .sidebar-header h2 { font-size: 1.2rem; font-weight: 700; color: var(--primary); }
.sidebar .close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.sidebar ul { list-style: none; padding: 0.5rem 0; flex: 1; display: flex; flex-direction: column; }
.sidebar li.spacer { flex: 1; }
/* nav was --text-muted (3.5:1) — the primary navigation of the app sat below AA */
.sidebar a {
    display: block;
    padding: 0.7rem 1.25rem;
    color: var(--text);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: color 0.15s, background 0.15s;
}
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active {
    color: var(--primary);
    background: #eef4ff;
    border-left-color: var(--primary);
    font-weight: 600;
}

/* Backdrop for mobile nav */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(17,24,39,0.4);
    z-index: 150;
}
.sidebar-backdrop.visible { display: block; }

/* ===================== */
/* Main content          */
/* ===================== */
main {
    padding: 1rem;
    min-height: calc(100vh - var(--topbar-h));
}

/* ===================== */
/* Desktop: sidebar      */
/* ===================== */
@media (min-width: 769px) {
    .topbar .menu-toggle { display: none; }
    .sidebar {
        transform: translateX(0);
        top: 0;
    }
    .sidebar .close-btn { display: none; }
    .sidebar-backdrop { display: none !important; }
    main.with-sidebar { margin-left: var(--sidebar-w); }
    main { padding: 2rem; }
    .topbar {
        position: sticky;
        padding-left: calc(var(--sidebar-w) + 1rem);
    }
    .topbar.with-sidebar .logo { display: none; }
}

/* ===================== */
/* Page header           */
/* ===================== */
.page-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.page-header h1 { font-size: 1.5rem; font-weight: 650; letter-spacing: -0.01em; }

/* ===================== */
/* Stats row             */
/* ===================== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
@media (min-width: 769px) {
    .stats-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
}
.stat-card.alert { border-color: var(--red); border-width: 1.5px; }
.stat-value { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    font-weight: 500;
}

/* ===================== */
/* Cards                 */
/* ===================== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    overflow-x: auto;
}
@media (min-width: 769px) { .card { padding: 1.5rem; margin-bottom: 1.5rem; } }
.card h2 { font-size: 1.1rem; font-weight: 650; margin-bottom: 0.75rem; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 769px) { .grid-2 { grid-template-columns: 1fr 1fr; gap: 1.5rem; } }

/* ===================== */
/* Tables — responsive   */
/* ===================== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1rem; padding: 0 1rem; }
@media (min-width: 769px) { .table-wrap { margin: 0; padding: 0; } }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.6rem 0.7rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
/* headers were 12px uppercase in the failing grey — bumped and darkened */
th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border-strong);
}
tbody tr:hover { background: #fafbfd; }
td a { color: var(--primary); text-decoration: none; font-weight: 500; }
td a:hover { text-decoration: underline; }
td.num, .num { text-align: right; font-variant-numeric: tabular-nums; }
@media (min-width: 769px) {
    table { font-size: 0.92rem; }
    th, td { padding: 0.65rem 0.8rem; }
}

/* ===================== */
/* Badges                */
/* ===================== */
.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    /* default so an unknown status is still legible rather than transparent */
    background: var(--neutral-bg);
    color: #46505e;
}
/* green — healthy / done */
.badge-green, .badge-warming, .badge-active, .badge-served, .badge-completed,
.badge-sent, .badge-genuine_engagement { background: var(--green-bg); color: var(--green); }
/* amber — in progress / needs attention */
.badge-yellow, .badge-dns_configured, .badge-provisioning, .badge-running,
.badge-unsub, .badge-pending { background: var(--yellow-bg); color: var(--yellow); }
/* red — bad */
.badge-red, .badge-burned, .badge-retired, .badge-complaint,
.badge-failed, .badge-bounced { background: var(--red-bg); color: var(--red); }
/* blue — informational */
.badge-genuine, .badge-ready, .badge-reserved, .badge-queued { background: var(--blue-bg); color: #1c4e9c; }
/* purple — test / non-production. seed and dryrun must never read as 'sent' */
.badge-seed, .badge-dryrun, .badge-test { background: var(--purple-bg); color: var(--purple); }
/* neutral */
.badge-paused, .badge-draft, .badge-skipped { background: var(--neutral-bg); color: #46505e; }

/* ===================== */
/* Definition list       */
/* ===================== */
dl { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem 0.85rem; }
dt { color: var(--text-muted); font-size: 0.86rem; font-weight: 500; }
dd { font-size: 0.9rem; word-break: break-word; }

/* ===================== */
/* Alerts list           */
/* ===================== */
.alert-list { list-style: none; }
.alert-item { padding: 0.6rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.alert-item.acked { opacity: 0.55; }
.alert-item small { display: block; color: var(--text-muted); font-size: 0.8rem; margin-top: 0.15rem; }

/* ===================== */
/* Login                 */
/* ===================== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    padding: 1rem;
    background: var(--bg);
}
.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(17,24,39,0.06), 0 8px 24px rgba(17,24,39,0.06);
}
.login-box h1 { font-size: 1.6rem; color: var(--primary); margin-bottom: 0.25rem; }
.login-box .subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }

/* ===================== */
/* Forms                 */
/* ===================== */
.form-group { margin-bottom: 0.85rem; text-align: left; }
.form-group label { display: block; font-size: 0.86rem; color: var(--text-muted); margin-bottom: 0.3rem; font-weight: 500; }

input[type="text"], input[type="date"], input[type="password"], input[type="number"],
input[type="email"], select, textarea {
    width: 100%;
    padding: 0.55rem 0.65rem;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.92rem;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29,78,216,0.15);
}
::placeholder { color: #8a94a2; }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 0.75rem; margin-bottom: 1rem; }
@media (min-width: 769px) { .form-grid { grid-template-columns: 1fr 1fr; } }

.form-help { display: block; font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

.form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.form-actions .btn { width: auto; }
.form-actions .btn:not(.btn-primary) { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.form-actions .btn:not(.btn-primary):hover { background: var(--surface-2); }

/* ===================== */
/* Buttons               */
/* ===================== */
.btn {
    padding: 0.5rem 1.1rem;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text);
    background: var(--surface);
    text-decoration: none;
    display: inline-block;
    font-family: inherit;
}
.btn:hover { background: var(--surface-2); }
.btn-primary, .btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover, .btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.warn { border-color: var(--red); color: var(--red); }
.btn.warn:hover { background: var(--red-bg); }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.82rem; }

.action-links { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.action-links .btn { width: auto; }

/* ===================== */
/* Alerts / Flash        */
/* ===================== */
.alert.error, .alert-error {
    background: var(--red-bg);
    border: 1px solid #f0b4ae;
    color: var(--red);
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}
.alert-success {
    background: var(--green-bg);
    border: 1px solid #a8ddbc;
    color: var(--green);
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}
.flash-messages { margin-bottom: 0.75rem; }
/* page templates use a bare .flash */
.flash {
    background: #eef6ff;
    border: 1px solid #cfe3fb;
    color: #1a3c5e;
    padding: 0.6rem 0.85rem;
    border-radius: 6px;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    white-space: pre-wrap;
}

/* ===================== */
/* Settings test result  */
/* ===================== */
.test-result { margin-top: 0.75rem; padding: 0.65rem; border-radius: 6px; font-size: 0.9rem; }
.test-loading { background: var(--yellow-bg); border: 1px solid #e8c48a; color: var(--yellow); }
.test-success { background: var(--green-bg); border: 1px solid #a8ddbc; color: var(--green); }
.test-error { background: var(--red-bg); border: 1px solid #f0b4ae; color: var(--red); }

/* ===================== */
/* Utilities             */
/* ===================== */
.muted { color: var(--text-muted); }
small.muted, small { font-size: 0.82rem; }
pre { overflow-x: auto; font-size: 0.86rem; }
code, pre {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.86rem;
}
code {
    background: var(--surface-2);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
}
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
a { color: var(--primary); }

/* ===================== */
/* Sidebar section heads */
/* ===================== */
.sidebar li.nav-section {
    padding: 0.9rem 1.25rem 0.3rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #7b8593;
}
.sidebar li.nav-user {
    padding: 0.5rem 1.25rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

/* Engagement lifecycle states (autotrim owns the transitions) */
.badge-new      { background: var(--blue-bg);    color: #1c4e9c; }
.badge-engaged  { background: var(--green-bg);   color: var(--green); }
.badge-cooling  { background: var(--yellow-bg);  color: var(--yellow); }
.badge-dormant  { background: var(--purple-bg);  color: var(--purple); }
.badge-dead     { background: var(--red-bg);     color: var(--red); }

/* Suppression reasons */
.badge-manual      { background: var(--neutral-bg); color: #46505e; }
.badge-hard_bounce { background: var(--red-bg);     color: var(--red); }
.badge-blacklist   { background: var(--red-bg);     color: var(--red); }

/* ===================== */
/* Dashboard             */
/* ===================== */
.goal-card { border-left: 4px solid var(--primary); }
.goal-main { display: flex; justify-content: space-between; align-items: flex-start;
             gap: 1rem; flex-wrap: wrap; }
.goal-num { font-size: 3rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1;
            font-variant-numeric: tabular-nums; }
.goal-of { font-size: 1.25rem; font-weight: 500; color: var(--text-muted); margin-left: .35rem; }
.goal-meta { text-align: right; font-size: .9rem; }
.meter { height: 8px; background: var(--surface-2); border-radius: 999px;
         overflow: hidden; margin-top: .9rem; }
.meter-fill { height: 100%; background: var(--primary); border-radius: 999px; }

.stat-sub { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }
.trend { font-size: .75rem; font-weight: 600; vertical-align: middle; }
.trend-up { color: var(--green); }
.trend-down { color: var(--red); }
.trend-flat { color: var(--text-muted); }
.good   { color: var(--green); }
.bad    { color: var(--red); }
.warn-v { color: var(--yellow); }

.spark { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.spark-fill { height: 100%; background: var(--primary); opacity: .75; border-radius: 999px; }
tr.today-row td { background: #eef4ff; font-weight: 600; }
