/* ===========================================================================
   SMTP Manager — interface styles

   Everything is served from this origin. There is no CDN, no web font fetched
   from a third party, and no inline style without a CSP nonce: that is what
   makes `default-src 'none'` in the Content-Security-Policy achievable.
   =========================================================================== */

/* --- Design tokens ------------------------------------------------------ */
:root {
    color-scheme: light dark;

    --bg:            #f6f7f9;
    --bg-elevated:   #ffffff;
    --bg-sunken:     #eceef2;
    --bg-hover:      #e8ebf0;

    --border:        #dde1e8;
    --border-strong: #c3cad6;

    --text:          #1a1d23;
    --text-muted:    #5f6672;
    --text-subtle:   #8b929e;

    --accent:        #3b6fd4;
    --accent-hover:  #2f5ab0;
    --accent-soft:   #e8eefc;
    --accent-text:   #ffffff;

    --success:       #1f7a4d;
    --success-soft:  #e3f4ea;
    --warning:       #9a6410;
    --warning-soft:  #fdf1dd;
    --danger:        #b3261e;
    --danger-soft:   #fdeceb;
    --info:          #2a6a8c;
    --info-soft:     #e4f1f7;

    --radius:        10px;
    --radius-sm:     6px;
    --radius-lg:     16px;

    --shadow-sm:     0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
    --shadow:        0 4px 12px rgba(16, 24, 40, .08), 0 1px 3px rgba(16, 24, 40, .04);
    --shadow-lg:     0 12px 32px rgba(16, 24, 40, .12);

    --sidebar-width: 248px;

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

@media (prefers-color-scheme: dark) {
    :root {
        --bg:            #0f1116;
        --bg-elevated:   #171a21;
        --bg-sunken:     #0a0c10;
        --bg-hover:      #1f232c;

        --border:        #272c37;
        --border-strong: #39414f;

        --text:          #e6e9ef;
        --text-muted:    #9aa2b1;
        --text-subtle:   #6d7585;

        --accent:        #5b8def;
        --accent-hover:  #7ba3f5;
        --accent-soft:   #1a2540;
        --accent-text:   #0b0d12;

        --success:       #4ade80;
        --success-soft:  #10241a;
        --warning:       #fbbf5c;
        --warning-soft:  #2a2011;
        --danger:        #f87171;
        --danger-soft:   #2a1414;
        --info:          #67c5e8;
        --info-soft:     #10222b;

        --shadow-sm:     0 1px 2px rgba(0, 0, 0, .4);
        --shadow:        0 4px 14px rgba(0, 0, 0, .45);
        --shadow-lg:     0 16px 40px rgba(0, 0, 0, .55);
    }
}

/* --- Reset -------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: .95rem; }
p  { margin: 0 0 1em; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, kbd { font-family: var(--mono); font-size: .875em; }
code { background: var(--bg-sunken); padding: .12em .38em; border-radius: 4px; border: 1px solid var(--border); }
pre {
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    overflow-x: auto;
    margin: 0 0 1rem;
}
pre code { background: none; border: 0; padding: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}

/* --- Layout ------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-weight: 650;
    font-size: 1rem;
    letter-spacing: -.02em;
    color: var(--text);
}
.sidebar__brand:hover { text-decoration: none; }
.sidebar__mark {
    width: 30px; height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: grid; place-items: center;
    color: #fff; font-weight: 700; font-size: .82rem;
    flex-shrink: 0;
}

.sidebar__nav { padding: .75rem .6rem; flex: 1; }
.sidebar__section {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-subtle);
    padding: .9rem .65rem .35rem;
    font-weight: 650;
}
.sidebar__link {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .5rem .65rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 1px;
}
.sidebar__link:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.sidebar__link.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar__icon { width: 17px; text-align: center; flex-shrink: 0; opacity: .85; }
.sidebar__badge {
    margin-left: auto;
    background: var(--accent);
    color: var(--accent-text);
    border-radius: 99px;
    padding: 0 .42rem;
    font-size: .68rem;
    font-weight: 700;
    min-width: 18px;
    text-align: center;
}

.sidebar__footer {
    padding: .85rem 1.25rem;
    border-top: 1px solid var(--border);
    font-size: .78rem;
    color: var(--text-subtle);
}
.sidebar__user { display: flex; align-items: center; gap: .55rem; margin-bottom: .6rem; }
.sidebar__avatar {
    width: 28px; height: 28px; border-radius: 99px;
    background: var(--accent-soft); color: var(--accent);
    display: grid; place-items: center; font-weight: 700; font-size: .72rem;
    flex-shrink: 0;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .9rem 1.75rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 1.1rem; }
.topbar__spacer { flex: 1; }

.content { padding: 1.75rem; flex: 1; max-width: 1400px; width: 100%; }
.content--narrow { max-width: 860px; }

/* --- Cards -------------------------------------------------------------- */
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.25rem;
    overflow: hidden;
}
.card__header {
    padding: .95rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: .75rem;
}
.card__header h2, .card__header h3 { margin: 0; font-size: .98rem; }
.card__header .card__spacer { flex: 1; }
.card__body { padding: 1.25rem; }
.card__body--flush { padding: 0; }
.card__footer {
    padding: .85rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--bg-sunken);
}

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

/* --- Stats -------------------------------------------------------------- */
.stat { padding: 1.1rem 1.25rem; }
.stat__label {
    font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-subtle); font-weight: 650; margin-bottom: .3rem;
}
.stat__value { font-size: 1.65rem; font-weight: 680; letter-spacing: -.02em; line-height: 1.1; }
.stat__value--sm { font-size: 1.15rem; }
.stat__meta { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }

/* --- Tables ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th {
    text-align: left;
    padding: .6rem 1rem;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-subtle);
    font-weight: 650;
    border-bottom: 1px solid var(--border);
    background: var(--bg-sunken);
    white-space: nowrap;
}
table.data td { padding: .62rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--bg-hover); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.nowrap { white-space: nowrap; }
.row-unread td { font-weight: 600; }

/* --- Badges & pills ----------------------------------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .12rem .5rem;
    border-radius: 99px;
    font-size: .72rem;
    font-weight: 650;
    line-height: 1.5;
    white-space: nowrap;
}
.badge--neutral { background: var(--bg-sunken); color: var(--text-muted); border: 1px solid var(--border); }
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.badge--info    { background: var(--info-soft);    color: var(--info); }
.badge--accent  { background: var(--accent-soft);  color: var(--accent); }

.dot { width: 8px; height: 8px; border-radius: 99px; display: inline-block; flex-shrink: 0; }
.dot--ok   { background: var(--success); }
.dot--warn { background: var(--warning); }
.dot--bad  { background: var(--danger); }
.dot--idle { background: var(--text-subtle); }

/* --- Buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .48rem .9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--bg-elevated);
    color: var(--text);
    font: inherit;
    font-weight: 550;
    font-size: .86rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.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.08); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn--sm { padding: .28rem .6rem; font-size: .78rem; }
.btn--block { width: 100%; }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* --- Forms -------------------------------------------------------------- */
.field { margin-bottom: 1.05rem; }
.field__label { display: block; font-weight: 600; font-size: .84rem; margin-bottom: .32rem; }
.field__hint { font-size: .79rem; color: var(--text-muted); margin-top: .32rem; }
.field__error { font-size: .79rem; color: var(--danger); margin-top: .32rem; font-weight: 550; }

input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="url"], input[type="search"], input[type="datetime-local"], input[type="date"],
select, textarea {
    width: 100%;
    padding: .5rem .7rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: .88rem;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: var(--text-subtle); }
textarea { min-height: 90px; resize: vertical; }
select { cursor: pointer; }

.check { display: flex; align-items: flex-start; gap: .55rem; margin-bottom: .7rem; }
.check input[type="checkbox"], .check input[type="radio"] {
    margin: .22rem 0 0; width: 15px; height: 15px; flex-shrink: 0; accent-color: var(--accent); cursor: pointer;
}
.check label { font-size: .87rem; cursor: pointer; }
.check__hint { display: block; font-size: .79rem; color: var(--text-muted); font-weight: 400; }

.field-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    margin: 0 0 1.25rem;
}
.fieldset legend {
    font-weight: 650; font-size: .84rem; padding: 0 .45rem;
    text-transform: uppercase; letter-spacing: .05em; color: var(--text-subtle);
}

/* --- Alerts ------------------------------------------------------------- */
.alert {
    padding: .8rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid;
    margin-bottom: 1.1rem;
    font-size: .87rem;
    display: flex; gap: .6rem; align-items: flex-start;
}
.alert__icon { flex-shrink: 0; font-size: 1rem; line-height: 1.35; }
.alert--success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.alert--error   { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }
.alert--warning { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.alert--info    { background: var(--info-soft);    border-color: var(--info);    color: var(--info); }
.alert strong { font-weight: 700; }

/* --- Progress ----------------------------------------------------------- */
.progress {
    height: 8px; border-radius: 99px; background: var(--bg-sunken);
    overflow: hidden; border: 1px solid var(--border);
}
.progress__bar { height: 100%; background: var(--accent); transition: width .3s ease; }
.progress__bar--warn { background: var(--warning); }
.progress__bar--danger { background: var(--danger); }

/* --- Mail view ---------------------------------------------------------- */
.mail-layout { display: grid; grid-template-columns: 230px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .mail-layout { grid-template-columns: 1fr; } }

.folder-list { list-style: none; margin: 0; padding: .4rem; }
.folder-list a {
    display: flex; align-items: center; gap: .5rem;
    padding: .4rem .6rem; border-radius: var(--radius-sm);
    color: var(--text-muted); font-size: .86rem;
}
.folder-list a:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.folder-list a.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folder-list .count { margin-left: auto; font-size: .74rem; color: var(--text-subtle); font-variant-numeric: tabular-nums; }
.folder-list .depth-1 { padding-left: 1.5rem; }
.folder-list .depth-2 { padding-left: 2.4rem; }
.folder-list .depth-3 { padding-left: 3.3rem; }

.msg-subject { font-weight: 550; }
.msg-from { color: var(--text-muted); font-size: .84rem; }

.headers-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.headers-table th {
    text-align: left; vertical-align: top; padding: .3rem 1rem .3rem 0;
    color: var(--text-subtle); font-weight: 600; white-space: nowrap; width: 1%;
}
.headers-table td { padding: .3rem 0; word-break: break-word; }

/* --- Diff / JSON viewer ------------------------------------------------- */
.json-view {
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .85rem 1rem;
    font-family: var(--mono);
    font-size: .78rem;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    max-height: 460px;
    overflow-y: auto;
}

/* --- Timeline ----------------------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
    display: flex; gap: .75rem; padding: .6rem 1.25rem;
    border-bottom: 1px solid var(--border); font-size: .86rem;
}
.timeline li:last-child { border-bottom: 0; }
.timeline__when { color: var(--text-subtle); font-size: .78rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.timeline__what { flex: 1; min-width: 0; }
.timeline__actor { color: var(--text-muted); font-size: .78rem; }

/* --- Checklist ---------------------------------------------------------- */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li {
    display: flex; gap: .75rem; align-items: flex-start;
    padding: .75rem 1.25rem; border-bottom: 1px solid var(--border);
}
.checklist li:last-child { border-bottom: 0; }
.checklist__mark {
    width: 20px; height: 20px; border-radius: 99px; flex-shrink: 0;
    display: grid; place-items: center; font-size: .7rem; font-weight: 700;
    margin-top: .1rem;
}
.checklist__mark--done { background: var(--success-soft); color: var(--success); }
.checklist__mark--todo { background: var(--bg-sunken); color: var(--text-subtle); border: 1px dashed var(--border-strong); }
.checklist__text { flex: 1; }
.checklist__detail { font-size: .81rem; color: var(--text-muted); }

/* --- Auth / setup screens ------------------------------------------------ */
.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
    background:
        radial-gradient(900px 500px at 15% -10%, var(--accent-soft), transparent 60%),
        radial-gradient(700px 400px at 90% 110%, var(--info-soft), transparent 60%),
        var(--bg);
}
.auth-card {
    width: 100%;
    max-width: 430px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
}
.auth-card--wide { max-width: 720px; }
.auth-card__brand { display: flex; align-items: center; gap: .7rem; margin-bottom: 1.4rem; }
.auth-card__brand .sidebar__mark { width: 36px; height: 36px; font-size: .9rem; }
.auth-card__title { font-size: 1.3rem; margin: 0; }
.auth-card__sub { color: var(--text-muted); font-size: .87rem; margin: .15rem 0 0; }

.steps { display: flex; gap: .4rem; margin-bottom: 1.5rem; }
.steps__item {
    flex: 1; height: 4px; border-radius: 99px; background: var(--bg-sunken);
}
.steps__item.is-done { background: var(--success); }
.steps__item.is-current { background: var(--accent); }

/* --- Requirement list ---------------------------------------------------- */
.req-list { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.req-list li {
    display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
    padding: .42rem 0; border-bottom: 1px solid var(--border);
}
.req-list li:last-child { border-bottom: 0; }
.req-list__name { flex: 1; }
.req-list__detail { color: var(--text-subtle); font-size: .79rem; }

/* The remedy for a failed check: the command to run, or the setting to
   change. Wraps onto its own line inside the same row, and breaks inside long
   absolute paths rather than pushing the card sideways. */
.req-list__hint {
    flex-basis: 100%; margin: .2rem 0 .1rem calc(8px + .6rem);
    color: var(--text-muted); font-family: var(--mono); font-size: .74rem;
    line-height: 1.5; overflow-wrap: anywhere;
}

/* --- Utilities ----------------------------------------------------------- */
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.small { font-size: .81rem; }
.tiny { font-size: .74rem; }
.mono { font-family: var(--mono); }
.nums { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.stack > * + * { margin-top: 1rem; }
.inline-form { display: inline; }
.flex { display: flex; gap: .6rem; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.empty-state { padding: 3rem 1.5rem; text-align: center; color: var(--text-muted); }
.empty-state__icon { font-size: 2.2rem; opacity: .45; margin-bottom: .6rem; }

.pagination { display: flex; gap: .35rem; align-items: center; justify-content: center; padding: 1rem; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: .32rem .62rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border); font-size: .82rem; color: var(--text-muted);
}
.pagination a:hover { background: var(--bg-hover); text-decoration: none; }
.pagination .is-current { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 650; }

.filters {
    display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end;
    padding: .9rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--bg-sunken);
}
.filters .field { margin: 0; min-width: 150px; }
.filters .field__label { font-size: .74rem; }

/* --- Print --------------------------------------------------------------- */
@media print {
    .sidebar, .topbar, .btn, .filters, .pagination { display: none !important; }
    .content { padding: 0; }
    .card { box-shadow: none; border-color: #ccc; }
}

/* --- Small screens -------------------------------------------------------- */
@media (max-width: 780px) {
    .shell { flex-direction: column; }
    .sidebar {
        width: 100%; height: auto; position: static;
        flex: none; border-right: 0; border-bottom: 1px solid var(--border);
    }
    .sidebar__nav { display: flex; flex-wrap: wrap; gap: .2rem; padding: .5rem; }
    .sidebar__section { display: none; }
    .sidebar__link { padding: .4rem .6rem; font-size: .82rem; }
    .content { padding: 1rem; }
    .topbar { padding: .75rem 1rem; }
}
