:root {
    color-scheme: light;
    --bg: #f3f4f8;
    --bg-accent: linear-gradient(180deg, #eef1fb 0%, #f3f4f8 320px);
    --card: #ffffff;
    --card-border: #e6e8f0;
    --text: #1a1d29;
    --muted: #6b7280;
    --muted-2: #9095a3;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-soft: #eef0fe;
    --accent: #6366f1;
    --border: #e5e7eb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --danger-border: #fecaca;
    --success: #16a34a;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --radius: 14px;
    --radius-sm: 9px;
    /* 主按钮固定用这两个饱和一点的紫色,亮/暗色模式都一样,
       这样按钮上的白色文字任何主题下都够清楚,不用另外切换文字颜色。 */
    --btn-start: #6366f1;
    --btn-end: #4f46e5;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg-accent), var(--bg);
    background-attachment: fixed;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.wrap {
    max-width: 1080px;
    margin: 0 auto;
    padding: 20px 16px 40px;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

/* 需要保持窄栏阅读宽度的页面内容(邮件详情、后台登录等)用这个包一层 */
.narrow { max-width: 640px; margin: 0 auto; width: 100%; }

@media (min-width: 840px) {
    .wrap { padding-left: 28px; padding-right: 28px; }
}

/* ---------- Header ---------- */

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 4px 26px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 19px;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.01em;
}

.brand-icon {
    display: inline-flex;
    color: var(--primary);
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 38px;
    height: 38px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--card-border);
    background: var(--card);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background 0.15s ease, transform 0.1s ease;
}
.icon-btn:hover { background: var(--primary-soft); color: var(--primary); }
.icon-btn:active { transform: translateY(1px); }

.theme-btn { padding: 0; width: 38px; }
.icon-sun, .icon-moon { display: none; }
.icon-moon { display: inline-flex; }
:root[data-theme="dark"] .icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: inline-flex; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .icon-moon { display: none; }
    :root:not([data-theme="light"]) .icon-sun { display: inline-flex; }
}

/* ---------- Layout building blocks ---------- */

main { flex: 1; }

.card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.card-tight { padding: 18px 22px; }

h1 { font-size: 24px; margin: 0 0 8px; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 0 0 14px; font-weight: 650; }
p.hint { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 0 18px; }

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-soft);
    padding: 5px 12px;
    border-radius: 999px;
    margin-bottom: 14px;
}

/* ---------- Home / form ---------- */

.hero-grid {
    display: flex;
    flex-direction: column;
    gap: 28px;
    max-width: 680px;
    margin: 0 auto;
    width: 100%;
}
.hero-copy { padding: 4px 2px; }
.hero-copy h1 { font-size: 28px; }
.hero-copy .hint { margin-bottom: 0; }

.hero-steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-top: 26px;
}
.hero-step {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}
.hero-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 10px;
}
.hero-step-title { font-size: 13.5px; font-weight: 650; margin-bottom: 3px; }
.hero-step-desc { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

@media (min-width: 840px) {
    .hero-copy h1 { font-size: 34px; }
    .hero-copy .hint { font-size: 15px; }
}

/* ---------- Inbox layout ---------- */

.inbox-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
}

.mail-panes {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    align-items: stretch;
}
.mail-list-pane { display: flex; flex-direction: column; }
.mail-content-pane { min-width: 0; display: flex; flex-direction: column; }
.mail-content-placeholder { text-align: center; color: var(--muted); }
.mail-content-pane .mail-content-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 内容面板的卡片跟着面板一起拉伸,正文区域再撑满卡片剩余空间,
   这样左侧列表和右侧邮件正文这两块看起来就是同一个高度。 */
.mail-content-pane .mail-content-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.msg-meta-block { padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--card-border); }

/* 独立的邮件详情页(message.php)不参与两栏拉伸,msg-body-frame 保留下面
   "message detail" 里定义的固定高度;只有在收件箱两栏布局里才撑满剩余空间。 */
.mail-content-pane .msg-meta-block { flex-shrink: 0; }
.mail-content-pane .msg-body-block { flex: 1; min-height: 0; display: flex; }
.mail-content-pane .msg-body-block .msg-body-frame { flex: 1; height: auto; }
.mail-content-pane .msg-body-block .msg-body-text { flex: 1; overflow-y: auto; }

@media (min-width: 860px) {
    .mail-panes { grid-template-columns: 340px 1fr; }
    .mail-list-pane,
    .mail-content-pane {
        position: sticky;
        top: 20px;
        min-height: 70vh;
        max-height: calc(100vh - 40px);
        overflow-y: auto;
    }
}

.mode-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
    background: var(--bg);
    padding: 4px;
    border-radius: 11px;
}
.mode-tabs label {
    flex: 1;
    text-align: center;
    padding: 9px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
    transition: all 0.15s ease;
}
.mode-tabs input { display: none; }
.mode-tabs input:checked + span {
    color: var(--primary);
}
.mode-tabs label:has(input:checked) {
    background: var(--card);
    box-shadow: var(--shadow-sm);
}

.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 7px; }

input[type=text], input[type=password], select {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type=text]:focus, input[type=password]:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.address-input-group { display: flex; align-items: center; gap: 8px; }
.address-input-group span { color: var(--muted); font-weight: 500; }

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: linear-gradient(180deg, var(--btn-start), var(--btn-end));
    color: #fff;
    border: none;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    box-shadow: 0 1px 2px rgba(79, 70, 229, 0.25), 0 4px 12px rgba(79, 70, 229, 0.18);
    transition: filter 0.15s ease, transform 0.1s ease;
}
button:hover, .btn:hover { filter: brightness(1.06); }
button:active, .btn:active { transform: translateY(1px); }

.btn-secondary {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow-sm);
}
.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid var(--danger-border);
    box-shadow: none;
}
.btn-block { width: 100%; }

.feature-list {
    list-style: none;
    margin: 20px 0 0;
    padding: 16px 0 0;
    border-top: 1px dashed var(--border);
    display: flex;
    flex-direction: column;
    gap: 9px;
}
.feature-list li {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    font-size: 13.5px;
    color: var(--muted);
}
.feature-list svg { flex-shrink: 0; margin-top: 2px; color: var(--success); }

.error-box {
    background: var(--danger-soft);
    border: 1px solid var(--danger-border);
    color: var(--danger);
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
}

/* ---------- Inbox ---------- */

.mailbox-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.mailbox-address-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.mailbox-address {
    font-size: 19px;
    font-weight: 700;
    word-break: normal;
    overflow-wrap: anywhere;
    letter-spacing: -0.01em;
}
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 12.5px;
    font-weight: 600;
}
.mailbox-ttl {
    font-size: 13px;
    color: var(--muted);
}
.mailbox-footer {
    display: flex;
    justify-content: flex-end;
    padding-top: 14px;
    border-top: 1px solid var(--card-border);
}
.mailbox-footer .btn {
    width: auto;
    padding: 9px 18px;
    font-size: 14px;
}

.toolbar { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.section-head h2 { margin: 0; }
.section-head-title { display: flex; align-items: center; gap: 8px; }

.refresh-btn { padding: 0; width: 34px; height: 34px; min-width: 34px; }
.refresh-btn svg { transition: transform 0.2s ease; }
.refresh-btn.is-spinning svg { animation: spin 0.7s linear infinite; }

.message-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.message-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
    background: var(--card);
    transition: border-color 0.15s ease, transform 0.1s ease;
}
.message-item:hover { border-color: var(--primary); transform: translateY(-1px); }
.message-item.active { border-color: var(--primary); background: var(--primary-soft); }
.message-dot {
    flex-shrink: 0;
    width: 9px; height: 9px;
    border-radius: 50%;
    margin-top: 6px;
    background: var(--primary);
}
.message-item.read .message-dot { background: transparent; border: 1px solid var(--border); }
.message-body-col { min-width: 0; flex: 1; }
.message-from { font-size: 12.5px; color: var(--muted); }
.message-subject {
    font-size: 15px;
    font-weight: 600;
    margin: 3px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.message-item.read .message-subject { font-weight: 500; }
.message-time { font-size: 12px; color: var(--muted-2); white-space: nowrap; flex-shrink: 0; }

.empty-state {
    text-align: center;
    padding: 46px 16px 40px;
}
.empty-icon {
    position: relative;
    width: 78px;
    height: 78px;
    margin: 0 auto 20px;
}
.empty-icon-spin {
    position: absolute;
    inset: 0;
    color: var(--muted-2);
    animation: spin 2.4s linear infinite reverse;
}
.empty-icon-static {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--primary);
}
.empty-title {
    font-size: 16px;
    font-weight: 650;
    color: var(--text);
    margin-bottom: 4px;
}
.empty-subtitle {
    font-size: 13.5px;
    color: var(--primary);
    opacity: 0.8;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- Message detail ---------- */

.msg-meta-row { font-size: 13.5px; color: var(--muted); margin-bottom: 4px; }
.msg-meta-row strong { color: var(--text); font-weight: 500; }
.msg-body-frame {
    width: 100%;
    height: 62vh;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    background: #fff;
}
.msg-body-text {
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-size: 14px;
    line-height: 1.7;
}

form.inline { display: inline; }

/* ---------- Footer ---------- */

.site-footer {
    margin-top: auto;
    padding-top: 24px;
    text-align: center;
}
.site-footer p {
    font-size: 12.5px;
    color: var(--muted-2);
    max-width: 480px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ---------- Dark mode ---------- */

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0d0e13;
        --bg-accent: linear-gradient(180deg, #171225 0%, #0d0e13 320px);
        --card: #16181f;
        --card-border: #262933;
        --text: #eceef2;
        --muted: #9aa0ac;
        --muted-2: #6c7280;
        --primary: #818cf8;
        --primary-dark: #6366f1;
        --primary-soft: rgba(129, 140, 248, 0.14);
        --accent: #818cf8;
        --border: #2a2e37;
        --danger: #f87171;
        --danger-soft: rgba(248, 113, 113, 0.1);
        --danger-border: rgba(248, 113, 113, 0.3);
        --success: #4ade80;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0d0e13;
    --bg-accent: linear-gradient(180deg, #171225 0%, #0d0e13 320px);
    --card: #16181f;
    --card-border: #262933;
    --text: #eceef2;
    --muted: #9aa0ac;
    --muted-2: #6c7280;
    --primary: #818cf8;
    --primary-dark: #6366f1;
    --primary-soft: rgba(129, 140, 248, 0.14);
    --accent: #818cf8;
    --border: #2a2e37;
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.1);
    --danger-border: rgba(248, 113, 113, 0.3);
    --success: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* ---------- Confirm modal (替代原生 confirm()) ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 14, 19, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
    animation: fade-in 0.15s ease;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 22px;
    max-width: 360px;
    width: 100%;
    box-shadow: var(--shadow);
    animation: modal-pop 0.15s ease;
}
.modal-message {
    margin: 0 0 18px;
    font-size: 14.5px;
    line-height: 1.6;
    color: var(--text);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions button { padding: 9px 16px; font-size: 14px; }

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes modal-pop {
    from { opacity: 0; transform: scale(0.96) translateY(4px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---------- Turnstile 验证码 ---------- */

.captcha-row { margin: 4px 0 16px; display: flex; justify-content: center; }

/* ---------- 后台管理 ---------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 12px;
    margin-bottom: 4px;
}
.stat-tile {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
}
.stat-tile .stat-value { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.stat-tile .stat-label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.admin-table th, .admin-table td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--card-border);
    white-space: nowrap;
}
.admin-table td.wrap-cell { white-space: normal; word-break: break-all; }
.admin-table th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.table-scroll { overflow-x: auto; }

.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    font-size: 13px;
    text-decoration: none;
    color: var(--text);
}
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

.search-form { display: flex; gap: 8px; margin-bottom: 16px; }
.search-form input { flex: 1; }

/* ---------- Responsive ---------- */

@media (max-width: 480px) {
    .wrap { padding: 14px 12px 32px; }
    .card { padding: 18px; }
    .brand span:last-child { display: none; }
    .icon-btn.lang-btn { padding: 0 10px; }
}
