/* Mailium — Mobile-first ops dashboard */

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --border: #2a2d3a;
    --text: #e1e4eb;
    --text-muted: #6b7280;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --green: #22c55e;
    --yellow: #eab308;
    --red: #ef4444;
    --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.5;
    min-height: 100vh;
}

/* ===================== */
/* 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.1rem; font-weight: 700; color: var(--primary); }
.topbar .menu-toggle {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    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; }
.sidebar a {
    display: block;
    padding: 0.75rem 1.25rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    transition: color 0.15s, background 0.15s;
}
.sidebar a:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.sidebar a.active { color: var(--primary); background: rgba(59,130,246,0.08); }

/* Backdrop for mobile nav */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    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.35rem; font-weight: 600; }

/* ===================== */
/* 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); }
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.15rem; }

/* ===================== */
/* 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.05rem; font-weight: 600; 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.82rem; }
th, td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
td a { color: var(--primary); text-decoration: none; }
td a:hover { text-decoration: underline; }
@media (min-width: 769px) {
    table { font-size: 0.875rem; }
    th, td { padding: 0.6rem 0.75rem; }
}

/* ===================== */
/* Badges                */
/* ===================== */
.badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
}
.badge-green, .badge-warming { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-yellow, .badge-dns_configured { background: rgba(234,179,8,0.15); color: var(--yellow); }
.badge-red, .badge-burned, .badge-retired, .badge-complaint { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-unsub { background: rgba(234,179,8,0.15); color: var(--yellow); }
.badge-genuine { background: rgba(59,130,246,0.15); color: var(--primary); }
.badge-paused { background: rgba(107,114,128,0.15); color: var(--text-muted); }
.badge-ready { background: rgba(59,130,246,0.15); color: var(--primary); }
.badge-served { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-completed { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-running { background: rgba(234,179,8,0.15); color: var(--yellow); }
.badge-failed { background: rgba(239,68,68,0.15); color: var(--red); }

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

/* ===================== */
/* Alerts list           */
/* ===================== */
.alert-list { list-style: none; }
.alert-item { padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-size: 0.82rem; }
.alert-item.acked { opacity: 0.5; }
.alert-item small { display: block; color: var(--text-muted); font-size: 0.72rem; }

/* ===================== */
/* Login                 */
/* ===================== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    padding: 1rem;
}
.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    text-align: center;
}
.login-box h1 { font-size: 1.5rem; color: var(--primary); margin-bottom: 0.25rem; }
.login-box .subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.85rem; }

/* ===================== */
/* Forms                 */
/* ===================== */
.form-group { margin-bottom: 0.75rem; text-align: left; }
.form-group label { display: block; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.25rem; }

input[type="text"], input[type="date"], input[type="password"], input[type="number"], select, textarea {
    width: 100%;
    padding: 0.55rem 0.65rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }

.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.75rem; color: var(--text-muted); margin-top: 0.2rem; }

.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(--border); color: var(--text); }
.form-actions .btn:not(.btn-primary):hover { background: var(--text-muted); }

/* ===================== */
/* Buttons               */
/* ===================== */
.btn {
    padding: 0.55rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    color: var(--text);
    background: var(--border);
    text-decoration: none;
    display: inline-block;
}
.btn:hover { background: rgba(255,255,255,0.1); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-sm { padding: 0.25rem 0.55rem; font-size: 0.78rem; }

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

/* ===================== */
/* Alerts / Flash        */
/* ===================== */
.alert.error, .alert-error {
    background: rgba(239,68,68,0.1);
    border: 1px solid var(--red);
    color: var(--red);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    margin-bottom: 0.75rem;
    font-size: 0.82rem;
}
.alert-success {
    background: rgba(34,197,94,0.1);
    border: 1px solid var(--green);
    color: var(--green);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    margin-bottom: 0.75rem;
    font-size: 0.82rem;
}
.flash-messages { margin-bottom: 0.75rem; }

/* ===================== */
/* Settings test result  */
/* ===================== */
.test-result { margin-top: 0.75rem; padding: 0.6rem; border-radius: 6px; font-size: 0.82rem; }
.test-loading { background: rgba(234,179,8,0.1); border: 1px solid var(--yellow); color: var(--yellow); }
.test-success { background: rgba(34,197,94,0.1); border: 1px solid var(--green); color: var(--green); }
.test-error { background: rgba(239,68,68,0.1); border: 1px solid var(--red); color: var(--red); }

/* ===================== */
/* Utilities             */
/* ===================== */
.muted { color: var(--text-muted); }
small.muted, small { font-size: 0.75rem; }
pre { overflow-x: auto; font-size: 0.82rem; }
code { font-size: 0.82rem; }
