:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-soft: #eef4f1;
    --line: #d9dee4;
    --text: #19212a;
    --muted: #687381;
    --brand: #16745f;
    --brand-strong: #0f5d4c;
    --accent: #b33f62;
    --warn: #9a5b12;
    --danger: #b3261e;
    --shadow: 0 16px 36px rgba(21, 31, 42, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: Arial, "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: 58px;
    padding: 0 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
}

.brand, .nav, .actions, .status-line {
    display: flex;
    align-items: center;
}

.brand {
    gap: 10px;
    font-weight: 800;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    min-width: 48px;
    height: 30px;
    border: 1px solid #a8cabe;
    border-radius: 6px;
    color: var(--brand-strong);
    background: var(--surface-soft);
    font-size: 12px;
}

.nav { gap: 6px; }
.nav a, .nav button {
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    color: var(--muted);
    background: transparent;
    font: inherit;
    cursor: pointer;
}
.nav a:hover, .nav button:hover { background: #edf0f3; color: var(--text); }
.nav form { margin: 0; }

.shell {
    width: min(100% - 28px, 1280px);
    margin: 0 auto;
    padding: 24px 0 40px;
}

.page-head {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: flex-end;
    margin-bottom: 18px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 28px; line-height: 1.2; }
h2 { font-size: 17px; line-height: 1.25; }
p, .status-line, small { color: var(--muted); }

.status-line {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    font-size: 12px;
}

.status-line span {
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.metrics div {
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.metrics span {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.metrics strong {
    display: block;
    margin-top: 4px;
    font-size: 24px;
    line-height: 1.1;
}

.metrics .small {
    font-size: 15px;
    word-break: break-all;
}

.grid {
    display: grid;
    gap: 14px;
    margin-bottom: 14px;
}

.grid.two {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.panel {
    min-width: 0;
    margin-bottom: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel-head {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.inline-form, .form-grid, .search-form {
    display: grid;
    gap: 10px;
    padding: 14px 16px;
}

.inline-form {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
}

.inline-form.split {
    border-top: 1px solid var(--line);
}

.split-form {
    border-top: 1px solid var(--line);
}

.form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.span-2 { grid-column: 1 / -1; }

label {
    display: grid;
    gap: 5px;
    min-width: 0;
}

label span {
    color: var(--muted);
    font-size: 12px;
}

input {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    background: #fff;
    font: inherit;
}

input:focus {
    outline: 2px solid rgba(22, 116, 95, 0.18);
    border-color: var(--brand);
}

.btn, .icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--text);
    background: #fff;
    font: inherit;
    cursor: pointer;
}

.btn:hover, .icon-btn:hover { border-color: #b7c0ca; background: #f5f7f8; }
.btn.primary {
    border-color: var(--brand);
    color: #fff;
    background: var(--brand);
}
.btn.primary:hover { background: var(--brand-strong); }
.btn.danger {
    border-color: #e0aaa5;
    color: var(--danger);
    background: #fff7f6;
}
.btn.danger:hover {
    border-color: var(--danger);
    background: #fff0ee;
}
.btn svg, .icon-btn svg { width: 16px; height: 16px; }

.icon-btn {
    width: 36px;
    height: 36px;
    padding: 0;
}

.table-wrap { overflow: auto; }
.bulk-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 10px 16px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}
.check-col {
    width: 42px;
    min-width: 42px;
    text-align: center;
}
.check-col input {
    width: 16px;
    min-height: 16px;
    height: 16px;
    padding: 0;
}
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}
th {
    color: var(--muted);
    background: #fafbfc;
    font-size: 12px;
    font-weight: 700;
}
td { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
tr:last-child td { border-bottom: 0; }
.compact-table td { font-size: 13px; }
.mono {
    font-family: Consolas, "Courier New", monospace;
    word-break: break-all;
}
.code {
    color: var(--accent);
    font-family: Consolas, "Courier New", monospace;
    font-size: 18px;
    font-weight: 800;
}
.actions { gap: 6px; }

.list {
    display: grid;
}

.message-row {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 4px 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}
.message-row:hover { background: #f7faf9; }
.message-row strong {
    grid-row: span 2;
    align-self: center;
    color: var(--accent);
    font-size: 20px;
}
.message-row span, .message-row small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty {
    padding: 22px 16px;
    color: var(--muted);
    text-align: center;
}

.flash-stack {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
}

.flash {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}
.flash.success {
    border-color: #a5cdbc;
    background: #eef8f3;
    color: #135d4e;
}
.flash.error {
    border-color: #efbbb6;
    background: #fff3f2;
    color: var(--danger);
}

.search-form {
    grid-template-columns: minmax(220px, 360px) auto;
    padding: 0;
}

.search-form.wide-search {
    grid-template-columns: minmax(260px, 430px) minmax(220px, 340px) auto;
}

.mail-body {
    margin: 0;
    min-height: 240px;
    padding: 16px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font: 14px/1.55 Consolas, "Courier New", monospace;
}
.mail-body-readable {
    min-height: 120px;
    max-height: 520px;
}
.mail-body-raw {
    max-height: 360px;
}

.code-callout {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: #fffaf3;
}
.code-callout span {
    color: var(--muted);
    font-size: 12px;
}
.code-callout strong {
    color: var(--accent);
    font-family: Consolas, "Courier New", monospace;
    font-size: 28px;
    line-height: 1;
    letter-spacing: 0;
}

.html-detail {
    border-top: 1px solid var(--line);
    padding: 12px 16px 16px;
}
.html-detail summary {
    cursor: pointer;
    color: var(--muted);
}
.safe-mail-html {
    width: 100%;
    max-height: 520px;
    margin-top: 12px;
    padding: 14px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    word-break: break-word;
}
.safe-mail-html img,
.safe-mail-html iframe,
.safe-mail-html object,
.safe-mail-html embed,
.safe-mail-html form {
    display: none !important;
}
.safe-mail-html table {
    width: auto;
    max-width: 100%;
}
.safe-mail-html th,
.safe-mail-html td {
    white-space: normal;
}
.html-detail iframe {
    width: 100%;
    min-height: 420px;
    margin-top: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
}

.login-wrap {
    display: grid;
    place-items: center;
    min-height: calc(100vh - 150px);
}

.login-panel {
    display: grid;
    gap: 14px;
    width: min(100%, 420px);
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.login-panel h1 {
    font-size: 24px;
}

@media (max-width: 820px) {
    .topbar, .page-head {
        align-items: stretch;
        flex-direction: column;
    }
    .topbar { padding: 12px 16px; }
    .status-line { justify-content: flex-start; }
    .metrics, .grid.two, .form-grid {
        grid-template-columns: 1fr;
    }
    .inline-form, .search-form {
        grid-template-columns: 1fr;
    }
    .search-form.wide-search {
        grid-template-columns: 1fr;
    }
    .bulk-toolbar {
        align-items: stretch;
        flex-direction: column;
    }
    .span-2 { grid-column: auto; }
    th, td { padding: 9px 10px; }
    .message-row {
        grid-template-columns: 1fr;
    }
    .message-row strong { grid-row: auto; }
}
