:root {
    --ink: #17202b;
    --ink-soft: #243140;
    --paper: #f3eee6;
    --card: #fffdf9;
    --line: #e4dcd0;
    --copper: #c4622d;
    --copper-dark: #9a4a20;
    --muted: #6f675e;
    --danger: #9c3b32;
    --shadow: 0 24px 60px rgba(23, 32, 43, .18);
    --sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    font-family: var(--sans);
    color: var(--ink);
    background: var(--paper);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.auth {
    min-height: 100%;
    display: grid;
    grid-template-columns: 1.15fr .85fr;
}
.auth-brand {
    background:
        radial-gradient(circle at 20% 20%, rgba(196, 98, 45, .28), transparent 32%),
        var(--ink);
    color: #f6f1e8;
    padding: 72px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 18px;
}
.auth-brand h1 { margin: 0; font-size: 48px; font-weight: 650; letter-spacing: .04em; }
.auth-brand p { margin: 0; max-width: 420px; line-height: 1.7; color: #d9d1c6; }
.auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
}
.auth-panel form, .stack, .sheet-narrow form { display: flex; flex-direction: column; gap: 14px; }
#login-form { width: min(400px, 100%); }
h2, h3, h4 { margin: 0; }
h2 { font-size: 28px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, textarea, select {
    width: 100%;
    border: 1px solid var(--line);
    background: white;
    border-radius: 10px;
    padding: 11px 12px;
    outline: none;
}
textarea { min-height: 220px; resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus { border-color: var(--copper); box-shadow: 0 0 0 3px rgba(196, 98, 45, .15); }
button[type="submit"], .btn-compose, .ghost, .file-btn {
    border: 0;
    border-radius: 10px;
    padding: 11px 16px;
}
button[type="submit"], .btn-compose {
    background: var(--copper);
    color: white;
}
button[type="submit"]:hover, .btn-compose:hover { background: var(--copper-dark); }
.ghost, .file-btn { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.form-error { min-height: 1.2em; margin: 0; color: var(--danger); font-size: 13px; }
.seal {
    width: 72px;
    height: 72px;
    display: grid;
    place-items: center;
    border: 2px solid #c4622d;
    box-shadow: inset 0 0 0 4px rgba(196, 98, 45, .35);
    font-family: "Songti SC", "SimSun", serif;
    font-size: 36px;
}
.seal.sm { width: 42px; height: 42px; font-size: 20px; color: #f6f1e8; flex: none; }

.app {
    height: 100%;
    display: grid;
    grid-template-columns: 268px 360px minmax(0, 1fr);
    background: var(--card);
}
.side {
    background: var(--ink);
    color: #e7e1d8;
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    gap: 14px;
    min-height: 0;
}
.side-brand { display: flex; gap: 10px; align-items: center; padding: 4px; }
.side-brand strong, .side-brand small { display: block; }
.side-brand small {
    color: #b7b0a6;
    font-size: 12px;
    margin-top: 2px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.btn-compose { width: 100%; }
#folders { display: flex; flex-direction: column; gap: 4px; }
#folders button {
    text-align: left;
    background: transparent;
    color: #ddd6cc;
    border: 0;
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
}
#folders button.active, #folders button:hover { background: rgba(255, 255, 255, .08); }
#folders button.active { box-shadow: inset 3px 0 0 var(--copper); }
#folders em {
    font-style: normal;
    background: var(--copper);
    color: white;
    border-radius: 99px;
    padding: 0 7px;
    font-size: 12px;
}
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.side-foot button {
    background: transparent;
    color: #d9d1c6;
    border: 0;
    text-align: left;
    padding: 8px 12px;
    border-radius: 8px;
}
.side-foot button:hover { background: rgba(255, 255, 255, .08); }

.list-pane, .read-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.list-pane { background: #f7f3ed; border-right: 1px solid var(--line); }
.list-head { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.list-head h2 { font-size: 20px; }
#mail-list { overflow: auto; }
.mail-item {
    display: flex;
    align-items: flex-start;
    border-bottom: 1px solid var(--line);
}
.mail-item.active { background: #fff; }
.mail-open {
    flex: 1;
    min-width: 0;
    text-align: left;
    border: 0;
    background: transparent;
    padding: 12px 8px 12px 16px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 8px;
}
.mail-open .who { font-size: 14px; }
.mail-item.unread .who, .mail-item.unread .subject { font-weight: 700; }
.mail-open .subject { grid-column: 1; color: var(--ink); }
.mail-open .snippet { grid-column: 1 / -1; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-open .when { color: var(--muted); font-size: 12px; }
.star {
    border: 0;
    background: transparent;
    color: #b7aa9a;
    font-size: 16px;
    margin: 12px 12px 0 0;
    padding: 0 2px;
}
.star.on { color: var(--copper); }
.empty { margin: auto; color: var(--muted); padding: 32px; text-align: center; }
.read-pane { background: var(--card); }
#reader-body { overflow: auto; padding: 28px 36px 48px; }
.read-top { display: flex; gap: 8px; align-items: center; margin-bottom: 18px; }
.read-top h2 { font-size: 26px; line-height: 1.35; flex: 1; }
.meta { color: var(--muted); line-height: 1.7; margin-bottom: 20px; }
.letter { white-space: pre-wrap; line-height: 1.75; font-size: 15px; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.files a, .chip {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 10px;
    text-decoration: none;
    color: var(--ink);
    background: #fff;
    font-size: 13px;
}
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.text-btn, .linkish {
    border: 0;
    background: transparent;
    color: var(--copper-dark);
    padding: 0;
}
.danger { color: var(--danger) !important; }

.modal {
    position: fixed;
    inset: 0;
    background: rgba(23, 32, 43, .46);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 20;
}
.sheet {
    width: min(760px, 100%);
    max-height: calc(100vh - 40px);
    overflow: auto;
    background: var(--card);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 18px 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.sheet-wide { width: min(980px, 100%); }
.sheet-narrow { width: min(440px, 100%); }
.sheet-head, .sheet-foot { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.icon-btn { border: 0; background: transparent; font-size: 24px; line-height: 1; padding: 0 4px; }
.line { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 8px; }
.hint { margin: 0; color: var(--copper-dark); background: #f8ece4; border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.attach-list { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.with-domain { display: flex; align-items: center; gap: 8px; }
.with-domain em { font-style: normal; color: var(--muted); white-space: nowrap; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { flex-direction: row; align-items: center; gap: 8px; }
.check input { width: auto; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: #faf7f2; }
.ops { display: flex; gap: 10px; }
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: white;
    padding: 10px 14px;
    border-radius: 999px;
    z-index: 30;
}
.back { display: none; }

@media (max-width: 980px) {
    .auth { grid-template-columns: 1fr; }
    .auth-brand { padding: 36px 24px; min-height: 240px; }
    .auth-brand h1 { font-size: 34px; }
    .app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
    .side { padding: 10px; gap: 8px; }
    #folders { flex-direction: row; overflow: auto; }
    #folders button { white-space: nowrap; }
    .side-foot { flex-direction: row; margin-top: 0; }
    .read-pane { display: none; }
    body.reading .list-pane { display: none; }
    body.reading .read-pane { display: flex; }
    .back { display: inline-flex; }
    .admin-grid, .line, .split { grid-template-columns: 1fr; }
    #reader-body { padding: 18px; }
}
