/* ============================================================
 * Mail System · 清爽明亮 CSS
 * ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --color-primary: #4f7cff;
    --color-primary-hover: #3f69e6;
    --color-success: #22c55e;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;

    --text-main: #1f2937;
    --text-muted: #6b7280;
    --text-light: #9ca3af;

    --bg-page: #f4f6fb;
    --bg-card: #ffffff;
    --bg-soft: #f7f9fc;
    --bg-input: #ffffff;

    --border-color: #e5e7eb;
    --border-light: #eef1f5;

    --shadow-sm: 0 1px 2px 0 rgba(16, 24, 40, 0.05);
    --shadow-md: 0 4px 24px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 10px 40px rgba(79, 124, 255, 0.15);

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
            "Hiragino Sans GB", "Microsoft YaHei", Helvetica, Arial, sans-serif;
}

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-main);
    background: var(--bg-page);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-hover); }

/* ================= 登录页 ================= */

.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #eef3ff 0%, #f5f7ff 50%, #ffffff 100%);
    padding: 24px;
}

.auth-container {
    width: 100%;
    max-width: 460px;
    text-align: center;
}

.auth-card {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
}

.auth-logo { margin-bottom: 28px; }

.logo-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: linear-gradient(135deg, #4f7cff 0%, #7c9cff 100%);
    color: #fff;
    font-size: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    box-shadow: 0 8px 20px rgba(79, 124, 255, 0.3);
}
.logo-icon.small {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 0;
    margin-right: 8px;
    box-shadow: none;
}

.auth-logo h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 4px;
}

.auth-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    letter-spacing: 1px;
}

.auth-form { text-align: left; }

/* ================= 表单元素 ================= */

.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 13px;
    color: var(--text-main);
    font-weight: 500;
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--bg-input);
    color: var(--text-main);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
.form-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.12);
}
.form-input-lg { padding: 12px 16px; font-size: 15px; }
.form-input-sm { padding: 7px 12px; font-size: 13px; }

.form-help {
    display: block;
    color: var(--text-light);
    font-size: 12px;
    margin-top: 6px;
    line-height: 1.5;
}

.form-help code {
    background: var(--bg-soft);
    padding: 1px 6px;
    border-radius: 4px;
    color: var(--color-primary);
    font-size: 12px;
    font-family: Consolas, Monaco, monospace;
}

.form-divider {
    position: relative;
    text-align: center;
    margin: 22px 0;
}
.form-divider::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--border-light);
}
.form-divider span {
    position: relative;
    background: #fff;
    padding: 0 16px;
    color: var(--text-light);
    font-size: 12px;
}

/* ================= 按钮 ================= */

.btn {
    display: inline-block;
    padding: 10px 18px;
    font-size: 14px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: #fff;
    color: var(--text-main);
    cursor: pointer;
    font-family: inherit;
    line-height: 1;
    transition: background-color .15s, border-color .15s, color .15s, transform .05s;
    white-space: nowrap;
    user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; font-weight: 500; }

.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); color: #fff; }

.btn-outline { border-color: var(--border-color); color: var(--text-main); background: #fff; }
.btn-outline:hover { border-color: var(--color-primary); color: var(--color-primary); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-soft); color: var(--text-main); }

/* ================= 提示框 ================= */

.alert {
    padding: 12px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 20px;
    border: 1px solid;
}
.alert-error { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.alert-info  { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

.auth-footer {
    margin-top: 24px;
    font-size: 12px;
    color: var(--text-light);
    text-align: center;
}
.auth-footer code {
    background: var(--bg-soft);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--text-muted);
}

.copyright {
    color: var(--text-light);
    font-size: 12px;
    margin-top: 24px;
}

/* ================= 主界面通用 ================= */

.app-body {
    min-height: 100vh;
    background: var(--bg-page);
}

.app-header {
    background: #fff;
    border-bottom: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand { display: flex; align-items: center; }
.brand-name { font-size: 16px; font-weight: 600; color: var(--text-main); }

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}
.user-email {
    color: var(--text-muted);
    font-size: 13px;
    padding: 4px 10px;
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
}

.app-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 20px;
}

.app-sidebar {
    background: #fff;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    padding: 20px;
    height: fit-content;
    position: sticky;
    top: 72px;
    box-shadow: var(--shadow-sm);
}

.app-content {
    background: #fff;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    padding: 20px 24px 28px;
    min-height: 520px;
    box-shadow: var(--shadow-sm);
}

/* ================= 同步框 ================= */

.sync-box .form-label { margin-bottom: 8px; }

.sync-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}
.sync-row .form-input { flex: 1; }

.sync-status {
    margin-top: 10px;
    padding: 8px 10px;
    border-radius: var(--radius);
    font-size: 12px;
    line-height: 1.5;
}
.sync-status.ok  { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.sync-status.err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.history-note {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.7;
    background: var(--bg-soft);
    padding: 12px;
    border-radius: var(--radius);
}

/* ================= 统计 ================= */

.stats-box {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px dashed var(--border-light);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.stat-item {
    background: var(--bg-soft);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
}
.stat-num {
    font-size: 22px;
    font-weight: 600;
    color: var(--color-primary);
    line-height: 1.2;
}
.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.nav-links {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px dashed var(--border-light);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.nav-links a {
    padding: 8px 12px;
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 13px;
    transition: background-color .15s, color .15s;
}
.nav-links a:hover { background: var(--bg-soft); color: var(--color-primary); }
.nav-links a.active { background: #eef3ff; color: var(--color-primary); font-weight: 500; }

/* ================= 搜索框 ================= */

.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
    flex-wrap: wrap;
    gap: 12px;
}
.content-header h2 { font-size: 18px; font-weight: 600; }

.search-box {
    display: flex;
    gap: 8px;
    align-items: center;
}
.search-box .form-input-sm { width: 240px; }
.search-box-compact .form-input-sm { width: auto; min-width: 140px; max-width: 200px; }

/* ================= 空状态 ================= */

.empty {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: .5; }
.empty h3 { font-size: 16px; margin-bottom: 6px; color: var(--text-main); }
.empty p { font-size: 13px; }

/* ================= 邮件列表 ================= */

.table-wrap {
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    overflow: hidden;
}

.mail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.mail-table th, .mail-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
.mail-table th {
    background: var(--bg-soft);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 12px;
    letter-spacing: 0.5px;
}
.mail-table tbody tr:last-child td { border-bottom: none; }
.mail-table tbody tr:hover { background: #fafbff; cursor: pointer; }

.mail-row.unread td { background: #fbfcff; font-weight: 500; }
.mail-row.unread td.mail-subject a { color: var(--text-main); }

.mail-status { text-align: center; }
.dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-primary);
}
.flag { color: var(--color-warning); margin-left: 2px; }

.mail-subject a { color: var(--text-main); }
.mail-subject a:hover { color: var(--color-primary); }

.mail-from, .mail-time, .mail-attach { color: var(--text-muted); }
.mail-attach { text-align: center; }

/* ================= 分页 ================= */

.pagination {
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}
.page-link {
    min-width: 34px;
    height: 34px;
    line-height: 32px;
    text-align: center;
    padding: 0 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    background: #fff;
    font-size: 13px;
}
.page-link:hover { border-color: var(--color-primary); color: var(--color-primary); }
.page-link.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}
.page-info {
    margin-left: 12px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ================= 邮件详情 ================= */

.email-main {
    padding: 32px 20px 60px;
}

.email-wrap {
    max-width: 820px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* -------- 通用卡片 -------- */
.card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04),
                0 1px 2px rgba(15, 23, 42, 0.03);
    padding: 28px 32px;
}

.card-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f2f5;
}

.card-heading-icon {
    font-size: 16px;
    flex-shrink: 0;
}

/* -------- 卡片 1：主题 -------- */
.card-subject {
    background: linear-gradient(135deg, #ffffff 0%, #f5f7ff 100%);
    text-align: center;
    padding: 32px;
}

.subject-text {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.5;
    color: #111827;
    margin: 0;
    word-break: break-word;
}

/* -------- 卡片 2：元信息 -------- */
.card-meta {
    padding: 18px 32px;
}

.meta-item {
    display: flex;
    align-items: flex-start;
    padding: 10px 0;
    font-size: 14px;
    line-height: 1.7;
}

.meta-item + .meta-item {
    border-top: 1px dashed #eef0f3;
}

.meta-label {
    flex-shrink: 0;
    width: 70px;
    color: #6b7280;
    font-weight: 500;
    font-size: 13px;
    padding-top: 2px;
}

.meta-content {
    flex: 1;
    color: #111827;
    word-break: break-word;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.meta-name {
    font-weight: 600;
    color: #111827;
    margin-right: 4px;
}

.meta-email-link {
    color: #4f7cff;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 13px;
    margin-right: 8px;
}

.meta-value {
    color: #111827;
    font-size: 14px;
}

.meta-label-space {
    margin-left: 28px;
    width: auto;
}

.meta-item-info {
    gap: 0;
    padding: 10px 0;
}

/* 邮箱地址胶囊（收件人/抄送） */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f5f7fa;
    padding: 3px 10px;
    border-radius: 20px;
    margin: 2px 4px 2px 0;
    font-size: 12.5px;
    color: #374151;
    border: 1px solid #e8eaf0;
}

.chip-name {
    font-weight: 600;
    color: #111827;
}

.chip-email {
    color: #4f7cff;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 12px;
}

/* 卡片内的小型复制按钮（发件人行右侧） */
.btn-inline-copy {
    margin-left: auto;
    flex-shrink: 0;
    padding: 3px 10px !important;
    font-size: 12px !important;
    min-width: 60px;
}

/* chip 内的微型复制按钮 */
.btn-chip-copy {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 0 2px;
    margin-left: 2px;
    color: #9ca3af;
    transition: color 0.15s, transform 0.15s;
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.btn-chip-copy:hover {
    color: #4f7cff;
    transform: scale(1.15);
}

.btn-chip-copy:disabled {
    color: #10b981;
}

/* -------- 卡片 3：附件 -------- */
.card-attachments {
    background: #fbfcff;
    padding: 22px 32px;
}

.attachment-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.attachment-row {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #ffffff;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid #ebeef3;
}

.attachment-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.attachment-data {
    flex: 1;
    min-width: 0;
}

.attachment-filename {
    font-size: 14px;
    font-weight: 500;
    color: #111827;
    word-break: break-all;
}

.attachment-meta {
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
}

/* -------- 卡片 4：邮件正文 -------- */
.card-body {
    padding: 28px 32px;
    background: #ffffff;
}

.body-container {
    font-size: 15px;
    line-height: 1.8;
    color: #111827;
    word-break: break-word;
    max-width: 100%;
    overflow: hidden;
}

.body-container p {
    margin-bottom: 12px;
    max-width: 100%;
}

.body-container a {
    color: #4f7cff;
    text-decoration: underline;
}

/* --- HTML 正文：温和的布局保护，防止邮件内联样式破坏卡片 --- */
.body-html {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
    padding: 8px 4px;
}

/* 全局基础约束：确保不超出卡片 */
.body-html * {
    box-sizing: border-box;
    max-width: 100%;
}

/* 表格：防止内容横向撑开卡片 */
.body-html table {
    border-collapse: collapse;
    max-width: 100%;
    table-layout: auto;
}

.body-html td,
.body-html th {
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

/* 图片：自适应、圆角 */
.body-html img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 12px auto;
    border-radius: 6px;
}

.body-html iframe,
.body-html object,
.body-html embed {
    max-width: 100%;
    display: block;
    margin: 12px auto;
}

/* 正文链接颜色 */
.body-html a {
    color: #4f7cff;
    text-decoration: underline;
}

/* 正文文字基础样式（确保可读性） */
.body-html p,
.body-html div,
.body-html span,
.body-html li {
    font-size: 15px;
    line-height: 1.75;
}

.body-html h1,
.body-html h2,
.body-html h3,
.body-html h4 {
    font-weight: 600;
    line-height: 1.5;
    margin: 16px 0 8px;
}

/* 纯文本正文样式 */
.body-text {
    white-space: pre-wrap;
    background: #fafbfd;
    padding: 22px;
    border-radius: 8px;
    font-family: -apple-system, 'Segoe UI', 'PingFang SC', system-ui, sans-serif;
    border: 1px solid #eef1f6;
}

/* -------- 响应式 -------- */
@media (max-width: 680px) {
    .email-main { padding: 18px 12px 40px; }
    .card,
    .card-subject,
    .card-meta,
    .card-attachments,
    .card-body {
        padding: 20px 18px;
    }
    .subject-text { font-size: 19px; }
    .meta-item {
        flex-direction: column;
        gap: 4px;
    }
    .meta-label { width: auto; }
    .meta-item-info { flex-direction: row; flex-wrap: wrap; }
    .meta-label-space { margin-left: 0; }
    .attachment-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .attachment-row .btn {
        align-self: stretch;
        text-align: center;
    }
}

/* ================= 响应式 ================= */

@media (max-width: 900px) {
    .app-main {
        grid-template-columns: 1fr;
    }
    .app-sidebar {
        position: static;
    }
    .content-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .search-box { width: 100%; flex-wrap: wrap; }
    .search-box .form-input-sm { width: 100%; }
    .mail-table th:nth-child(3),
    .mail-table td:nth-child(3) { display: none; }
}

@media (max-width: 560px) {
    .user-email { display: none; }
    .auth-card { padding: 28px 20px; }
}

/* ============================================================
 * ͨ�õ��� Modal
 * ============================================================ */
.modal { position: fixed; inset: 0; z-index: 999; display: flex; align-items: center; justify-content: center; }
.modal-mask { position: absolute; inset: 0; background: rgba(17, 24, 39, 0.45); backdrop-filter: blur(2px); }
.modal-card { position: relative; width: 100%; max-width: 480px; background: #fff; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,0.18); padding: 22px 24px 20px; margin: 16px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { font-size: 18px; color: #1f2937; font-weight: 600; }
.modal-close { width: 30px; height: 30px; border: none; background: #f3f4f6; color: #6b7280; font-size: 20px; line-height: 1; border-radius: 6px; cursor: pointer; transition: background 0.15s; }
.modal-close:hover { background: #e5e7eb; color: #374151; }
.modal-body { margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }

