.email-module {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(15, 23, 42, .54);
}

.email-module.hidden,
.email-settings-view.hidden,
.email-compose-modal.hidden {
    display: none;
}

.email-shell {
    width: min(1280px, 100%);
    height: min(850px, calc(100vh - 36px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #15202b;
    background: #f8fafc;
    border: 1px solid rgba(255,255,255,.5);
    border-radius: 18px;
    box-shadow: 0 28px 80px rgba(15, 23, 42, .28);
}

.email-topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 72px;
    padding: 14px 20px;
    background: #fff;
    border-bottom: 1px solid #e8edf2;
}

.email-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 145px;
}

.email-brand-mark {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, #00a884, #087f68);
    border-radius: 11px;
}

.email-brand h2 {
    margin: 0;
    font-size: 18px;
    letter-spacing: -.02em;
}

.email-search {
    position: relative;
    flex: 1;
    max-width: 600px;
}

.email-search i {
    position: absolute;
    top: 12px;
    left: 14px;
    color: #94a3b8;
}

.email-search input {
    width: 100%;
    height: 40px;
    padding: 0 14px 0 38px;
    color: #1e293b;
    background: #f1f5f9;
    border: 1px solid transparent;
    border-radius: 10px;
    outline: none;
    box-sizing: border-box;
}

.email-search input:focus {
    background: #fff;
    border-color: #8ad8ca;
    box-shadow: 0 0 0 3px rgba(0,168,132,.1);
}

.email-top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.email-icon-btn,
.email-close-btn {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    color: #64748b;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
}

.email-icon-btn:hover,
.email-close-btn:hover {
    color: #008f73;
    border-color: #9eddd1;
    background: #f0fdfa;
}

.email-primary-btn {
    height: 40px;
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: #fff;
    background: #00a884;
    border: 0;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
}

.email-primary-btn:hover { background: #008f73; }

.email-body {
    min-height: 0;
    display: grid;
    grid-template-columns: 190px minmax(300px, 410px) minmax(0, 1fr);
    flex: 1;
}

.email-sidebar {
    padding: 16px 10px;
    background: #f1f5f9;
    border-right: 1px solid #e5eaf0;
}

.email-folder-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    color: #475569;
    background: transparent;
    border: 0;
    border-radius: 9px;
    text-align: left;
    font-size: 13px;
    cursor: pointer;
}

.email-folder-btn i { width: 18px; text-align: center; color: #64748b; }
.email-folder-btn:hover { background: #e2e8f0; }
.email-folder-btn.active { color: #007c68; background: #d9f7f0; font-weight: 700; }
.email-folder-btn.active i { color: #00a884; }

.email-sidebar-label {
    margin: 18px 12px 8px;
    color: #94a3b8;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.email-ai-status {
    margin: 18px 4px 0;
    padding: 12px;
    color: #475569;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 11px;
    font-size: 11px;
    line-height: 1.45;
}

.email-ai-status strong { display: block; color: #0f766e; font-size: 12px; margin-bottom: 3px; }
.email-ai-status.off strong { color: #64748b; }

.email-list-pane {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-right: 1px solid #e5eaf0;
}

.email-list-toolbar {
    min-height: 53px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid #edf1f5;
}

.email-list-toolbar span {
    margin-left: auto;
    color: #94a3b8;
    font-size: 11px;
}

.email-list {
    min-height: 0;
    flex: 1;
    height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.email-row {
    position: relative;
    display: grid;
    grid-template-columns: 22px 34px minmax(0, 1fr) auto;
    gap: 10px;
    padding: 13px 14px;
    border-bottom: 1px solid #f0f3f6;
    cursor: pointer;
}

.email-row-select {
    display: grid;
    place-items: center;
    cursor: pointer;
}

.email-row-select input,
.email-select-all input {
    width: 15px;
    height: 15px;
    accent-color: #00a884;
}

.email-select-all {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: #64748b;
    font-size: 10px;
    white-space: nowrap;
    cursor: pointer;
}

.email-list-toolbar .email-select-all span {
    margin-left: 0;
    color: #64748b;
    font-size: 10px;
}

.email-bulk-actions {
    display: inline-flex;
    gap: 5px;
}

.email-bulk-actions.hidden { display: none; }
.email-icon-btn.danger:hover { color: #b91c1c; border-color: #fecaca; background: #fff1f2; }

.email-row:hover { background: #f8fafc; }
.email-row.active { background: #effcf9; box-shadow: inset 3px 0 #00a884; }
.email-row.unread { background: #fbfffe; }
.email-row.unread .email-row-sender,
.email-row.unread .email-row-subject { color: #0f172a; font-weight: 800; }

.email-avatar {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    color: #047866;
    background: #d7f5ee;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 800;
}

.email-row-main { min-width: 0; }
.email-row-sender, .email-row-subject {
    overflow: hidden;
    color: #334155;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.email-row-subject { margin-top: 3px; color: #64748b; font-size: 12px; }
.email-row-preview { overflow: hidden; margin-top: 4px; color: #94a3b8; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.email-row-date { color: #94a3b8; font-size: 10px; white-space: nowrap; }
.email-row-flags { display: flex; gap: 6px; margin-top: 5px; color: #94a3b8; font-size: 10px; }
.email-row-flags .important { color: #f59e0b; }

.email-empty {
    padding: 60px 24px;
    color: #94a3b8;
    text-align: center;
}

.email-empty i { margin-bottom: 12px; color: #cbd5e1; font-size: 30px; }
.email-empty strong { display: block; margin-bottom: 5px; color: #64748b; font-size: 14px; }
.email-empty p { margin: 0; font-size: 12px; line-height: 1.5; }

.email-reader {
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
}

.email-reader-empty {
    flex: 1;
    display: grid;
    place-items: center;
    color: #94a3b8;
    text-align: center;
}

.email-reader-empty i { display: block; margin-bottom: 10px; font-size: 40px; color: #cbd5e1; }
.email-message-head { padding: 24px 28px 16px; background: #fff; border-bottom: 1px solid #e8edf2; }
.email-message-title { margin: 0 0 14px; color: #0f172a; font-size: 21px; line-height: 1.25; }
.email-message-meta { display: flex; align-items: flex-start; gap: 10px; color: #64748b; font-size: 12px; }
.email-message-meta strong { color: #334155; }
.email-message-meta small { display: block; margin-top: 3px; color: #94a3b8; }
.email-message-actions { display: flex; gap: 7px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.email-message-actions button { width: 32px; height: 32px; display: grid; place-items: center; color: #64748b; background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; cursor: pointer; }
.email-message-actions button:hover { color: #008f73; border-color: #9eddd1; }
.email-message-content { flex: 1; overflow-y: auto; padding: 28px; color: #334155; background: #f8fafc; font-size: 14px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.email-attachments { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 28px 20px; background: #f8fafc; }
.email-attachment { display: inline-flex; align-items: center; gap: 7px; padding: 8px 10px; color: #0369a1; background: #fff; border: 1px solid #bae6fd; border-radius: 8px; font-size: 11px; text-decoration: none; }

.email-ai-card {
    margin: 0 28px 20px;
    padding: 14px;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 11px;
}
.email-ai-card h4 { margin: 0 0 8px; color: #92400e; font-size: 12px; }
.email-ai-card p { margin: 0 0 10px; color: #78350f; font-size: 12px; white-space: pre-wrap; }
.email-ai-card button { height: 32px; padding: 0 10px; color: #92400e; background: #fef3c7; border: 1px solid #fcd34d; border-radius: 7px; font-size: 11px; font-weight: 700; cursor: pointer; }

.email-compose-modal {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, .35);
}

.email-marketing-modal {
    position: absolute;
    inset: 0;
    z-index: 3;
    overflow-y: auto;
    padding: 24px;
    background: rgba(15, 23, 42, .42);
}

.email-marketing-modal.hidden { display: none; }
.email-marketing-card {
    width: min(1080px, 100%);
    max-height: 100%;
    margin: 0 auto;
    overflow-y: auto;
    padding: 22px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(15,23,42,.22);
}
.email-marketing-card .email-compose-head small { display:block; margin-top:4px; color:#94a3b8; font-size:11px; }
.email-marketing-grid { display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:15px; }
.marketing-html-input { min-height: 180px !important; font-family: ui-monospace, SFMono-Regular, Menlo, monospace !important; font-size: 12px !important; }
.marketing-text-input { min-height: 90px !important; }
.marketing-contacts-input { min-height: 115px !important; }
.marketing-template-list { margin-top: 10px; }
.marketing-check { display:flex; align-items:center; gap:7px; margin: 4px 0 12px; color:#475569; font-size:12px; cursor:pointer; }
.marketing-check input { accent-color:#00a884; }
.email-marketing-list-head { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.email-marketing-list-head h4 { margin:0; }
.email-marketing-campaign { display:grid; grid-template-columns:minmax(0,1fr) auto auto; align-items:center; gap:12px; padding:12px 0; border-top:1px solid #edf2f7; }
.email-marketing-campaign strong { display:block; color:#334155; font-size:12px; }
.email-marketing-campaign small { display:block; margin-top:4px; color:#94a3b8; font-size:10px; }
.email-marketing-campaign-meta { display:flex; align-items:center; gap:8px; color:#64748b; font-size:10px; white-space:nowrap; }
.marketing-status { padding:4px 7px; border-radius:999px; font-weight:700; text-transform:capitalize; }
.marketing-status.active { color:#047857; background:#d1fae5; }
.marketing-status.paused { color:#92400e; background:#fef3c7; }
.marketing-status.draft { color:#475569; background:#e2e8f0; }
.marketing-status.completed { color:#1d4ed8; background:#dbeafe; }
.email-marketing-campaign-actions { display:flex; align-items:center; gap:5px; }
.email-marketing-campaign-actions .email-secondary-btn { height:30px; padding:0 9px; font-size:10px; }
.email-marketing-empty { padding:18px 0; color:#94a3b8; font-size:12px; text-align:center; }
#marketing-secret-result { color:#075985; background:#eff6ff; border-color:#bfdbfe; }
#marketing-secret-result h4 { color:#075985; }
#marketing-secret-result p { margin:0 0 8px; font-size:11px; line-height:1.45; }
#marketing-secret-result code { display:block; overflow:auto; padding:9px; color:#164e63; background:#fff; border:1px solid #bae6fd; border-radius:7px; font:12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
#marketing-secret-result pre { max-height:230px; overflow:auto; margin:9px 0; padding:9px; white-space:pre-wrap; color:#334155; background:#fff; border:1px solid #dbeafe; border-radius:7px; font:10px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.email-compose-card { width: min(680px, 100%); max-height: 90%; overflow-y: auto; padding: 22px; background: #fff; border-radius: 14px; box-shadow: 0 20px 60px rgba(15,23,42,.2); }
.email-compose-head { display:flex; align-items:center; justify-content:space-between; margin-bottom: 16px; }
.email-compose-head h3 { margin: 0; color: #0f172a; font-size: 18px; }
.email-field { margin-bottom: 12px; }
.email-field label { display:block; margin-bottom: 5px; color: #475569; font-size: 11px; font-weight: 700; }
.email-field input, .email-field textarea, .email-field select { width:100%; box-sizing:border-box; padding: 10px 11px; color:#1e293b; background:#fff; border:1px solid #dbe3eb; border-radius:8px; outline:none; font: inherit; font-size: 13px; }
.email-field textarea { min-height: 190px; resize: vertical; line-height: 1.5; }
.email-field input:focus, .email-field textarea:focus, .email-field select:focus { border-color:#6bcbbb; box-shadow:0 0 0 3px rgba(0,168,132,.1); }
.email-compose-footer { display:flex; align-items:center; gap:8px; justify-content:flex-end; margin-top: 15px; }
.email-secondary-btn { height: 38px; padding:0 13px; color:#475569; background:#fff; border:1px solid #dbe3eb; border-radius:9px; font-weight:700; cursor:pointer; }
.email-secondary-btn:hover { background:#f8fafc; }
.email-file-label { display:inline-flex; align-items:center; gap:7px; color:#64748b; font-size:11px; cursor:pointer; }

.email-settings-content { max-width: 920px; }
.email-settings-content h3 { color: var(--primary-color); }
.email-setting-card { margin-bottom: 15px; padding: 15px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; }
.email-setting-card h4 { margin:0 0 12px; color:#334155; font-size:13px; }
.email-setting-grid { display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:10px; }
.email-switch-line { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:10px 0; border-bottom:1px solid #edf2f7; }
.email-switch-line:last-child { border-bottom:0; }
.email-switch-line span { color:#475569; font-size:12px; }
.email-switch-line small { display:block; margin-top:3px; color:#94a3b8; font-size:10px; }
.email-settings-hint { padding: 11px 13px; color:#075985; background:#eff6ff; border:1px solid #bfdbfe; border-radius:9px; font-size:11px; line-height:1.45; }
.email-sensitive-card { background:#fff7ed; border-color:#fed7aa; }
.email-sensitive-card h4 { color:#9a3412; }
.email-test-recipient { flex:1; min-width:240px; height:38px; box-sizing:border-box; padding:0 11px; color:#1e293b; background:#fff; border:1px solid #dbe3eb; border-radius:9px; outline:none; font:inherit; font-size:12px; }
.email-test-recipient:focus { border-color:#6bcbbb; box-shadow:0 0 0 3px rgba(0,168,132,.1); }
.email-connection-result { margin-top:10px; padding:12px; border:1px solid #dbe3eb; border-radius:9px; color:#475569; background:#fff; font-size:11px; line-height:1.45; }
.email-connection-result.hidden { display:none; }
.email-connection-result.success { color:#065f46; background:#ecfdf5; border-color:#a7f3d0; }
.email-connection-result.error { color:#991b1b; background:#fef2f2; border-color:#fecaca; }
.email-connection-result strong { display:block; margin-bottom:6px; }
.email-connection-result pre { max-height:190px; overflow:auto; margin:0 0 8px; white-space:pre-wrap; overflow-wrap:anywhere; font:inherit; }
.email-copy-error, .email-error-toast button[data-copy-toast-error] { height:30px; padding:0 9px; color:#334155; background:#fff; border:1px solid #cbd5e1; border-radius:7px; font-size:11px; font-weight:700; cursor:pointer; }
.email-error-toast { position:fixed; right:22px; bottom:22px; z-index:1600; width:min(560px, calc(100vw - 44px)); padding:14px; color:#7f1d1d; background:#fff; border:1px solid #fca5a5; border-radius:12px; box-shadow:0 18px 50px rgba(15,23,42,.25); }
.email-error-toast-head { display:flex; align-items:center; justify-content:space-between; gap:10px; color:#991b1b; font-size:13px; }
.email-error-toast-head button { border:0; background:transparent; color:#991b1b; font-size:20px; cursor:pointer; }
.email-error-toast pre { max-height:220px; overflow:auto; margin:10px 0; padding:10px; white-space:pre-wrap; overflow-wrap:anywhere; color:#450a0a; background:#fff7f7; border:1px solid #fee2e2; border-radius:7px; font:11px/1.45 monospace; }

@media (max-width: 900px) {
    .email-body { grid-template-columns: 175px minmax(280px, 1fr); }
    .email-reader { position: absolute; inset: 72px 0 0; z-index: 2; display:none; }
    .email-reader.mobile-open { display:flex; }
    .email-brand { min-width: 110px; }
    .email-topbar { padding: 12px; }
    .email-topbar .email-primary-btn { padding: 0 10px; font-size: 0; }
    .email-topbar .email-primary-btn i { font-size: 14px; }
    .email-marketing-open { padding:0 10px; font-size:0; }
    .email-marketing-open i { font-size:14px; }
    .email-marketing-grid { grid-template-columns:1fr; }
    .email-marketing-campaign { grid-template-columns:1fr; gap:7px; }
}

@media (max-width: 560px) {
    .email-module { padding: 0; }
    .email-shell { width:100%; height:100%; border-radius:0; }
    .email-topbar { min-height: 60px; gap: 7px; }
    .email-brand { min-width: auto; }
    .email-brand h2 { font-size: 15px; }
    .email-brand-mark { width:30px; height:30px; }
    .email-search { order: 3; flex-basis:100%; max-width:none; }
    .email-topbar { flex-wrap:wrap; }
    .email-body { grid-template-columns: 64px minmax(0,1fr); }
    .email-sidebar { padding:10px 6px; }
    .email-folder-btn { justify-content:center; padding:11px 3px; }
    .email-folder-btn span, .email-sidebar-label, .email-ai-status { display:none; }
    .email-list-toolbar { padding:7px; }
    .email-row { padding:11px 8px; grid-template-columns:18px 30px minmax(0,1fr) auto; gap:5px; }
    .email-avatar { width:30px; height:30px; }
    .email-message-head, .email-message-content { padding:18px; }
    .email-attachments { padding:0 18px 14px; }
    .email-ai-card { margin:0 18px 14px; }
    .email-message-title { font-size:18px; }
    .email-message-actions { margin:12px 0 0; justify-content:flex-start; }
    .email-marketing-modal { padding:0; }
    .email-marketing-card { min-height:100%; border-radius:0; padding:16px; }
    .email-marketing-campaign-actions { flex-wrap:wrap; }
}
