:root {
    --bg: #f4f6f9;
    --panel: #ffffff;
    --text: #1f2937;
    --muted: #667085;
    --border: #d9e0ea;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --radius: 8px;
    --shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
}

button,
input,
select,
textarea {
    font: inherit;
}

.mailbox-app {
    min-height: 100vh;
    padding: 18px;
}

.mailbox-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 16px 18px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.mailbox-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 260px;
}

.brand-icon {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: #e8f0ff;
    color: var(--primary);
    font-size: 20px;
}

.mailbox-brand h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
}

.mailbox-brand p,
.panel-header p,
.preview-header p {
    margin: 4px 0 0;
    color: var(--muted);
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.refresh-status {
    color: var(--muted);
    margin-right: 4px;
    white-space: nowrap;
}

.button-primary,
.button-secondary,
.button-danger,
.button-small,
.button-text,
.icon-button {
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}

.button-primary {
    background: var(--primary);
    color: #fff;
    padding: 10px 14px;
}

.button-primary:hover {
    background: var(--primary-dark);
}

.button-secondary {
    background: #fff;
    color: #344054;
    border-color: var(--border);
    padding: 10px 12px;
}

.button-secondary:hover,
.button-small:hover,
.button-text:hover {
    background: #f2f4f7;
}

.button-danger {
    background: #fff;
    color: var(--danger);
    border-color: #fecaca;
    padding: 10px 12px;
}

.button-danger:hover {
    background: #fff1f2;
}

.button-primary:disabled {
    background: #93b4f8;
    cursor: not-allowed;
}

.button-text {
    background: transparent;
    color: var(--primary);
    padding: 6px 8px;
}

.danger-text {
    color: var(--danger);
}

.button-small {
    background: #fff;
    border-color: var(--border);
    color: #344054;
    padding: 7px 10px;
    font-size: 13px;
}

.button-small:disabled {
    color: #98a2b3;
    background: #f2f4f7;
    cursor: not-allowed;
}

.button-small.primary {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.button-small.danger {
    color: var(--danger);
    border-color: #fecaca;
}

.icon-button {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: #475467;
    font-size: 24px;
}

.safety-notice {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 0;
    padding: 10px 14px;
    background: #fff8e6;
    border: 1px solid #f6d58d;
    color: #7a4a00;
    border-radius: var(--radius);
}

.access-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 12px 0;
}

.access-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    display: grid;
    gap: 14px;
}

.access-card-header {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.access-card-header i {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: var(--primary);
    background: #e8f0ff;
    font-size: 18px;
    flex: 0 0 auto;
}

.access-card h2 {
    margin: 0;
    font-size: 20px;
}

.access-card p,
.access-code-notice p {
    margin: 4px 0 0;
    color: var(--muted);
}

.access-card label {
    display: grid;
    gap: 7px;
    color: #344054;
}

.access-card input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 11px 12px;
    outline: none;
}

.access-card input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.access-code-notice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin: 12px 0;
    padding: 14px 16px;
    background: #eef5ff;
    border: 1px solid #b9cdfb;
    border-radius: var(--radius);
}

.access-code-notice code {
    display: inline-flex;
    margin-left: 6px;
    padding: 5px 8px;
    border-radius: 6px;
    background: #fff;
    color: #175cd3;
    font-weight: 700;
    letter-spacing: 0;
}

.mailbox-layout {
    display: grid;
    grid-template-columns: minmax(520px, 3fr) 8px minmax(360px, 2fr);
    grid-template-areas:
        "import resize preview"
        "accounts resize preview";
    gap: 14px;
    align-items: start;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.import-panel {
    grid-area: import;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    padding: 14px;
}

.drop-zone {
    min-height: 92px;
    border: 1px dashed #9eb3d9;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #f8fbff;
    color: #475467;
    cursor: pointer;
    text-align: center;
}

.drop-zone i {
    color: var(--primary);
    font-size: 22px;
}

.drop-zone.is-dragover {
    border-color: var(--primary);
    background: #eef5ff;
}

.drop-zone.is-disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.import-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.accounts-panel {
    grid-area: accounts;
    padding: 16px;
}

.layout-resizer {
    grid-area: resize;
    align-self: stretch;
    min-height: 100%;
    border-radius: 999px;
    cursor: col-resize;
    background: transparent;
    position: relative;
}

.layout-resizer::before {
    content: "";
    position: absolute;
    left: 3px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    border-radius: 999px;
    background: #d0d5dd;
}

.layout-resizer:hover::before,
.is-resizing-layout .layout-resizer::before {
    background: var(--primary);
}

.is-resizing-layout {
    cursor: col-resize;
    user-select: none;
}

.preview-panel {
    grid-area: preview;
    padding: 16px;
    position: sticky;
    top: 18px;
    max-height: calc(100vh - 36px);
    display: flex;
    flex-direction: column;
    min-height: 640px;
}

.panel-header,
.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}

.panel-header h2,
.preview-header h2 {
    margin: 0;
    font-size: 19px;
}

.list-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.select-all,
.per-page-control {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--muted);
}

.per-page-control select {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    background: #fff;
    color: var(--text);
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.search-wrap {
    position: relative;
    flex: 1;
    min-width: 240px;
}

.search-wrap i {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: #98a2b3;
}

.search-wrap input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px 10px 34px;
    outline: none;
}

.search-wrap input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.filter-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.chip {
    border: 1px solid var(--border);
    background: #fff;
    color: #344054;
    border-radius: 999px;
    padding: 7px 12px;
    cursor: pointer;
}

.chip.active {
    background: #e8f0ff;
    border-color: #b9cdfb;
    color: var(--primary);
}

.table-wrap {
    position: relative;
    overflow-x: auto;
}

.mailbox-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 780px;
}

.mailbox-table th,
.mailbox-table td {
    border-bottom: 1px solid #edf0f4;
    padding: 12px 10px;
    text-align: left;
    vertical-align: middle;
}

.mailbox-table th {
    color: #667085;
    font-weight: 600;
    background: #f8fafc;
    white-space: nowrap;
}

.mailbox-table tr:hover td {
    background: #fbfdff;
}

.check-column {
    width: 38px;
}

.email-cell {
    font-weight: 600;
    color: #1d2939;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.remark-button {
    border: none;
    background: transparent;
    color: var(--primary);
    padding: 0;
    cursor: pointer;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.success {
    color: #067647;
    background: #dcfae6;
}

.status-badge.warning {
    color: #b54708;
    background: #fef0c7;
}

.status-badge.danger {
    color: #b42318;
    background: #fee4e2;
}

.status-badge.muted {
    color: #475467;
    background: #f2f4f7;
}

.status-badge.neutral {
    color: #175cd3;
    background: #e8f0ff;
}

.action-cell {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.mailbox-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 2px 0;
    color: var(--muted);
    flex-wrap: wrap;
}

.pagination-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.empty-state,
.empty-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 240px;
    color: var(--muted);
    text-align: center;
}

.empty-state[hidden] {
    display: none;
}

.empty-state i,
.empty-message i {
    font-size: 34px;
    color: #98a2b3;
}

.empty-state h3 {
    margin: 0;
    color: #344054;
}

.inbox-toolbar {
    margin-bottom: 12px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.window-select {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    white-space: nowrap;
}

.window-select select {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 9px 8px;
    background: #fff;
    color: var(--text);
}

.message-list {
    flex: 1;
    overflow-y: auto;
    display: grid;
    align-content: start;
    gap: 7px;
    padding-right: 4px;
    min-width: 0;
}

.message-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 7px;
    width: 100%;
    min-height: 92px;
    text-align: left;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 7px;
    padding: 10px 12px;
    color: var(--text);
    cursor: pointer;
    min-width: 0;
    overflow: hidden;
    line-height: 1.28;
}

.message-item:hover {
    border-color: #aac0f6;
    background: #fbfdff;
}

.message-title-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.message-subject {
    font-size: 14px;
    font-weight: 700;
    color: #1d2939;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    align-self: center;
}

.message-time {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
    text-align: right;
    align-self: center;
}

.message-meta {
    color: #475467;
    font-size: 12px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal[hidden],
[hidden] {
    display: none !important;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-dialog {
    width: min(980px, 96vw);
    height: min(760px, 92vh);
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header,
.modal-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
    line-height: 1.35;
    max-width: min(820px, 82vw);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal-header p {
    margin: 6px 0 0;
    color: var(--muted);
}

#bodyModalMeta {
    display: grid;
    gap: 4px;
    max-width: min(820px, 82vw);
}

#bodyModalMeta span {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal-actions {
    justify-content: flex-start;
}

.compact-modal {
    width: min(760px, 94vw);
    height: auto;
    max-height: 90vh;
}

.paste-import-body {
    padding: 16px;
    display: grid;
    gap: 10px;
}

.paste-import-body textarea {
    width: 100%;
    min-height: 320px;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    outline: none;
    line-height: 1.55;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.paste-import-body textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.paste-import-tip {
    color: #7a4a00;
    background: #fff8e6;
    border: 1px solid #f6d58d;
    border-radius: 6px;
    padding: 9px 10px;
}

#bodyFrame {
    border: none;
    flex: 1;
    width: 100%;
    background: #fff;
}

@media (max-width: 1180px) {
    .mailbox-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .header-actions {
        justify-content: flex-start;
    }

    .mailbox-layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "import"
            "accounts"
            "preview";
    }

    .access-panel {
        grid-template-columns: 1fr;
    }

    .layout-resizer {
        display: none;
    }

    .preview-panel {
        position: static;
        min-height: 420px;
        max-height: none;
    }
}

@media (max-width: 760px) {
    .mailbox-app {
        padding: 10px;
    }

    .import-panel {
        grid-template-columns: 1fr;
    }

    .access-code-notice {
        align-items: stretch;
        flex-direction: column;
    }

    .import-actions,
    .toolbar,
    .panel-header,
    .inbox-toolbar {
        align-items: stretch;
        flex-direction: column;
        display: flex;
    }

    .header-actions {
        width: 100%;
    }

    .header-actions button {
        flex: 1 1 auto;
    }

    .filter-chips {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 4px;
    }

    .mailbox-table {
        min-width: 760px;
    }
}
