/* ==========================================================================
   Mail Control Center — design system
   Dark-first operations console. Dense, scannable, keyboard-friendly.
   No frameworks, no build step.
   ========================================================================== */

:root {
    /* Surfaces */
    --bg:            #0d1117;
    --bg-raised:     #131a23;
    --bg-panel:      #171f2a;
    --bg-hover:      #1e2836;
    --bg-input:      #0a0f16;

    /* Lines */
    --border:        #253041;
    --border-strong: #35455c;

    /* Text */
    --text:          #e4ebf5;
    --text-muted:    #8b9bb4;
    --text-dim:      #64748b;

    /* Accent */
    --accent:        #3b82f6;
    --accent-hover:  #2563eb;
    --accent-soft:   rgba(59, 130, 246, .13);

    /* Status */
    --ok:            #22c55e;
    --ok-soft:       rgba(34, 197, 94, .13);
    --warn:          #f59e0b;
    --warn-soft:     rgba(245, 158, 11, .13);
    --danger:        #ef4444;
    --danger-soft:   rgba(239, 68, 68, .13);
    --info:          #06b6d4;
    --info-soft:     rgba(6, 182, 212, .13);

    /* Geometry */
    --radius:    8px;
    --radius-sm: 5px;
    --sidebar-w: 232px;
    --topbar-h:  56px;
    --shadow:    0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }

code, pre, .mono { font-family: var(--mono); font-size: .85em; }

/* ------------------------------------------------------------------ topbar */
.topbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; justify-content: space-between;
    height: var(--topbar-h); padding: 0 1rem;
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: .75rem; }
.brand { display: flex; align-items: center; gap: .55rem; color: var(--text); font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark {
    display: grid; place-items: center;
    width: 28px; height: 28px; border-radius: var(--radius-sm);
    background: var(--accent); color: #fff; font-size: 15px;
}
.brand-text { letter-spacing: -.01em; }
.who { color: var(--text-muted); font-size: .85rem; }
.role-badge {
    padding: .15rem .5rem; border-radius: 999px;
    font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
    background: var(--bg-hover); color: var(--text-muted); border: 1px solid var(--border);
}
.role-superadmin  { background: var(--danger-soft); color: #fca5a5; border-color: rgba(239,68,68,.35); }
.role-domainadmin { background: var(--warn-soft);   color: #fcd34d; border-color: rgba(245,158,11,.35); }
.role-auditor    { background: var(--info-soft);   color: #67e8f9; border-color: rgba(6,182,212,.35); }

.nav-toggle {
    display: none; background: none; border: 0; color: var(--text);
    font-size: 1.2rem; cursor: pointer; padding: .25rem .4rem;
}

/* ------------------------------------------------------------------- shell */
.shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }

.sidebar {
    width: var(--sidebar-w); flex-shrink: 0;
    background: var(--bg-raised);
    border-right: 1px solid var(--border);
    padding: .75rem 0;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { margin: 0; }
.sidebar a {
    display: flex; align-items: center; gap: .6rem;
    padding: .5rem .9rem;
    color: var(--text-muted); font-size: .875rem;
    border-left: 2px solid transparent;
}
.sidebar a:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.sidebar a.active {
    background: var(--accent-soft); color: #93c5fd;
    border-left-color: var(--accent); font-weight: 500;
}
.sidebar .ico { width: 1.1rem; text-align: center; opacity: .85; }

.content { flex: 1; min-width: 0; padding: 1.25rem 1.5rem 2rem; }

/* ------------------------------------------------------------------ footer */
.footer {
    padding: .75rem 1.5rem; border-top: 1px solid var(--border);
    color: var(--text-dim); font-size: .78rem;
    display: flex; gap: .5rem; flex-wrap: wrap;
}
.footer .sep { opacity: .5; }

/* ------------------------------------------------------------------ panels */
.panel {
    background: var(--bg-panel); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 1rem; overflow: hidden;
}
.panel-head {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .7rem 1rem; background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
}
.panel-head h2, .panel-head h3 { margin: 0; font-size: .92rem; }
.panel-body { padding: 1rem; }
.panel-body.tight { padding: 0; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* ------------------------------------------------------------------- stats */
.stat {
    background: var(--bg-panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: .85rem 1rem;
}
.stat-label {
    color: var(--text-muted); font-size: .72rem; text-transform: uppercase;
    letter-spacing: .05em; font-weight: 600; margin-bottom: .3rem;
}
.stat-value { font-size: 1.55rem; font-weight: 600; line-height: 1.1; letter-spacing: -.02em; }
.stat-sub   { color: var(--text-dim); font-size: .76rem; margin-top: .25rem; }
.stat.ok    .stat-value { color: var(--ok); }
.stat.warn  .stat-value { color: var(--warn); }
.stat.danger .stat-value { color: var(--danger); }
.stat.info  .stat-value { color: var(--info); }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
thead th {
    text-align: left; padding: .55rem .8rem;
    background: var(--bg-raised); color: var(--text-muted);
    font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
    font-weight: 600; border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody td { padding: .55rem .8rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
td.shrink { width: 1%; white-space: nowrap; }

.empty { padding: 2rem 1rem; text-align: center; color: var(--text-dim); }

/* ------------------------------------------------------------------ badges */
.badge {
    display: inline-block; padding: .1rem .45rem; border-radius: 4px;
    font-size: .72rem; font-weight: 600; white-space: nowrap;
    background: var(--bg-hover); color: var(--text-muted);
    border: 1px solid var(--border);
}
.badge-ok     { background: var(--ok-soft);     color: #86efac; border-color: rgba(34,197,94,.32); }
.badge-warn   { background: var(--warn-soft);   color: #fcd34d; border-color: rgba(245,158,11,.32); }
.badge-danger { background: var(--danger-soft); color: #fca5a5; border-color: rgba(239,68,68,.32); }
.badge-info   { background: var(--info-soft);   color: #67e8f9; border-color: rgba(6,182,212,.32); }
.badge-muted  { background: var(--bg-hover);    color: var(--text-dim); }

/* ----------------------------------------------------------------- buttons */
.btn {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .4rem .8rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong); background: var(--bg-hover);
    color: var(--text); font-size: .84rem; font-family: inherit;
    font-weight: 500; cursor: pointer; text-decoration: none;
    transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg-panel); border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger  { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-ghost   { background: transparent; }
.btn-sm      { padding: .22rem .5rem; font-size: .78rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-row { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ------------------------------------------------------------------- forms */
label { display: block; margin-bottom: .3rem; font-size: .82rem; color: var(--text-muted); font-weight: 500; }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=search], select, textarea {
    width: 100%; padding: .45rem .6rem;
    background: var(--bg-input); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    font-family: inherit; font-size: .87rem;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 80px; resize: vertical; font-family: var(--mono); font-size: .8rem; }
.field { margin-bottom: .85rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .85rem; }
.help { color: var(--text-dim); font-size: .78rem; margin-top: .25rem; }
.checkline { display: flex; align-items: center; gap: .5rem; }
.checkline input { width: auto; }
.checkline label { margin: 0; }

.filter-bar {
    display: flex; gap: .6rem; align-items: center; flex-wrap: wrap;
    padding: .7rem 1rem; border-bottom: 1px solid var(--border); background: var(--bg-raised);
}
.filter-bar input[type=search] { max-width: 280px; }

/* ------------------------------------------------------------------ alerts */
.alert {
    padding: .6rem .85rem; border-radius: var(--radius-sm); margin-bottom: 1rem;
    border: 1px solid var(--border); background: var(--bg-panel); font-size: .87rem;
}
.alert-success { background: var(--ok-soft);     border-color: rgba(34,197,94,.35);  color: #86efac; }
.alert-error   { background: var(--danger-soft); border-color: rgba(239,68,68,.35);  color: #fca5a5; }
.alert-warning { background: var(--warn-soft);   border-color: rgba(245,158,11,.35); color: #fcd34d; }
.alert-info    { background: var(--info-soft);   border-color: rgba(6,182,212,.35);  color: #67e8f9; }

/* ------------------------------------------------------------------- login */
.app-login .shell { justify-content: center; }
.login-wrap { width: 100%; max-width: 380px; padding: 2rem 1rem; }
.login-card {
    background: var(--bg-panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow);
}
.login-card h1 { text-align: center; margin-bottom: .3rem; }
.login-card .sub { text-align: center; color: var(--text-dim); font-size: .82rem; margin-bottom: 1.25rem; }
.login-card .btn { width: 100%; justify-content: center; }

/* --------------------------------------------------------------- healthbar */
.health-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: .75rem; padding: .55rem .9rem; border-bottom: 1px solid var(--border);
}
.health-row:last-child { border-bottom: 0; }
.health-name { display: flex; align-items: center; gap: .55rem; font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-ok { background: var(--ok); box-shadow: 0 0 6px rgba(34,197,94,.6); }
.dot-bad { background: var(--danger); box-shadow: 0 0 6px rgba(239,68,68,.6); }
.health-detail { color: var(--text-dim); font-size: .78rem; text-align: right; }

/* ------------------------------------------------------------------- misc */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; font-size: .85rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

pre.code {
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: .7rem .85rem;
    overflow-x: auto; font-size: .78rem; color: #cbd5e1; margin: 0;
}

.meter { height: 5px; background: var(--bg-input); border-radius: 3px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.meter.warn > span  { background: var(--warn); }
.meter.danger > span { background: var(--danger); }

.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a {
    padding: .45rem .8rem; color: var(--text-muted); font-size: .85rem;
    border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }

.muted { color: var(--text-muted); }
.dim   { color: var(--text-dim); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.stack > * + * { margin-top: .5rem; }
.inline { display: inline; }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 860px) {
    .nav-toggle { display: block; }
    .sidebar {
        position: fixed; top: var(--topbar-h); bottom: 0; left: 0; z-index: 40;
        transform: translateX(-100%); transition: transform .18s ease;
        box-shadow: var(--shadow);
    }
    body.nav-open .sidebar { transform: translateX(0); }
    .content { padding: 1rem .9rem 2rem; }
    .brand-text { display: none; }
    .who { display: none; }
}

@media print {
    .sidebar, .topbar, .footer, .btn-row { display: none !important; }
    body { background: #fff; color: #000; }
    .panel { border-color: #ccc; }
}
