:root {
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
}

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

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; padding: 14px 28px;
    background: #0f172a; color: #fff;
    box-shadow: 0 2px 10px rgba(15,23,42,.18);
}
.topbar .brand { font-weight: 700; font-size: 16px; letter-spacing: .3px; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a {
    color: #cbd5e1; padding: 7px 12px; border-radius: 8px; font-size: 13px;
}
.topbar nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.topbar nav a.active { background: var(--primary); color: #fff; }

main { max-width: 1220px; margin: 0 auto; padding: 24px 20px 60px; }

.cards {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px; margin-bottom: 20px;
}
.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.card-num { font-size: 30px; font-weight: 700; line-height: 1.1; }
.card-label { color: var(--muted); margin-top: 6px; font-size: 13px; }

.panel {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 22px; margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.panel h2 { font-size: 16px; margin: 0 0 6px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

.alert {
    border-radius: 10px; padding: 12px 16px; margin-bottom: 16px;
    border: 1px solid transparent; font-size: 14px;
}
.alert.success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert.danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert.warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert ul { margin: 8px 0 0 18px; padding: 0; }

.grid-form {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px; align-items: end; margin-top: 12px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font-size: 12px; }
.field input, .field select, .filters input, .filters select, .inline-form input[type=text] {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border);
    border-radius: 9px; background: #fff; color: var(--text); font-size: 14px;
    outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .filters input:focus, .filters select:focus, .inline-form input[type=text]:focus {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 10px; align-items: center; margin: 10px 0; }
.inline-form input[type=text] { max-width: 320px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 14px; border-radius: 9px; border: 1px solid var(--border);
    background: #fff; color: var(--text); font-size: 13px; cursor: pointer;
    white-space: nowrap; transition: all .15s;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.disabled { opacity: .45; pointer-events: none; }

.link {
    background: none; border: none; padding: 0; margin: 0;
    color: var(--primary); cursor: pointer; font-size: 13px;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }

.table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 600; background: #f8fafc; }
tbody tr:hover { background: #f8fafc; }
td.empty { text-align: center; color: var(--muted); padding: 28px; }
.actions { display: flex; gap: 12px; align-items: center; }
.actions form { display: inline; margin: 0; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.off { background: #f1f5f9; color: #64748b; }

.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0 4px; }
.filters input { max-width: 260px; }
.filters select { max-width: 220px; }

.pager { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 16px; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px 24px; margin-top: 10px; }
.kv div { display: flex; gap: 10px; align-items: baseline; }
.kv span { color: var(--muted); min-width: 56px; }
code { background: #f1f5f9; padding: 2px 6px; border-radius: 5px; font-size: 12px; }

.stats-inline { display: flex; gap: 20px; margin: 10px 0 16px; color: var(--muted); }
.stats-inline b { color: var(--text); font-size: 18px; }

/* login */
.login-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(1200px 600px at 20% 10%, #1e3a8a 0%, #0f172a 45%, #020617 100%);
    padding: 20px;
}
.login-card {
    width: 100%; max-width: 380px; background: #fff; border-radius: 16px;
    padding: 34px 30px; box-shadow: 0 30px 80px rgba(0,0,0,.35);
}
.login-logo { font-size: 38px; text-align: center; }
.login-card h1 { text-align: center; font-size: 21px; margin: 6px 0 4px; }
.login-card > p { text-align: center; margin: 0 0 20px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card .field input { padding: 11px 12px; }
.login-card .muted.small { text-align: center; margin-top: 16px; }

@media (max-width: 640px) {
    .topbar { padding: 12px 14px; flex-direction: column; align-items: flex-start; }
    main { padding: 16px 12px 40px; }
    .panel { padding: 16px; }
}

/* mail feed */
.mail-table td.mail-subject { min-width: 320px; max-width: 560px; }
.unread-dot {
    display: inline-block; width: 7px; height: 7px; border-radius: 50%;
    background: var(--primary); margin-right: 6px; vertical-align: middle;
}
.strong { font-weight: 600; }
.preview {
    color: var(--muted); font-size: 12px; margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 560px;
}
.attach-icon { margin-left: 6px; }
.mail-view-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 12px; }
.mail-view-subject { font-size: 21px; margin: 4px 0 8px; line-height: 1.35; }
.mail-meta {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 8px 24px; margin: 6px 0 18px; color: var(--muted); font-size: 13px;
}
.mail-meta b { color: var(--text); font-weight: 500; }
.mail-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tab-btn {
    background: none; border: none; padding: 8px 13px; cursor: pointer;
    color: var(--muted); border-bottom: 2px solid transparent; font-size: 13px;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }
.mail-text {
    white-space: pre-wrap; word-break: break-word; background: #f8fafc;
    border: 1px solid var(--border); border-radius: 10px; padding: 16px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px; max-height: 70vh; overflow: auto; margin: 0;
}
.mail-html { width: 100%; min-height: 70vh; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.attach-list { list-style: none; margin: 0; padding: 0; }
.attach-list li {
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
    margin-bottom: 8px; display: flex; justify-content: space-between; gap: 12px;
}
.view-toggle { display: flex; gap: 8px; flex-wrap: wrap; }
