/* ── RxLink Email Client ─────────────────────────── */
:root {
    --em-bg: #f0f2f5;
    --em-topbar: #1a1a2e;
    --em-sidebar: #fff;
    --em-surface: #fff;
    --em-border: #e0e0e0;
    --em-primary: #1a73e8;
    --em-primary-light: #e8f0fe;
    --em-text: #202124;
    --em-muted: #5f6368;
    --em-hover: #f5f5f5;
    --em-selected: #e8f0fe;
    --em-unread: #1a1a2e;
    --em-danger: #d93025;
    --em-success: #188038;
    --em-radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--em-bg); overflow: hidden; height: 100vh; }

/* ── Login ────────────────────────────────────────── */
.email-login {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 1.5rem 1rem 4rem;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}
.email-login-card {
    background: #fff; border-radius: 16px; padding: 2.5rem;
    width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    text-align: center;
}
.email-login-logo { font-size: 3rem; color: var(--em-primary); margin-bottom: 0.5rem; }
.email-login-card h2 { font-weight: 800; margin-bottom: 0.25rem; color: var(--em-text); }
.email-login-card p { margin-bottom: 1.5rem; font-size: 0.9rem; }
.email-login-card .form-label { font-weight: 600; font-size: 0.85rem; text-align: left; display: block; }
.email-login-card .form-control { border-radius: 8px; }
.email-login-card .btn-primary {
    background: var(--em-primary); border: none; border-radius: 8px;
    padding: 0.6rem; font-weight: 700; font-size: 0.95rem;
}
.email-back-link {
    display: inline-block; margin-top: 1.25rem;
    color: var(--em-muted); text-decoration: none; font-size: 0.85rem;
}
.email-back-link:hover { color: var(--em-primary); }
.email-login-options { margin-top: 1rem; }
.email-link-btn {
    border: none; background: transparent; color: var(--em-primary);
    font-size: 0.88rem; font-weight: 600; cursor: pointer;
}
.email-link-btn:hover { color: #1557b0; text-decoration: underline; }
.email-reset-panel h2 { font-weight: 800; margin-bottom: 0.35rem; color: var(--em-text); }
.email-reset-panel p { margin-bottom: 1rem; font-size: 0.9rem; }

/* ── Top Bar ──────────────────────────────────────── */
.email-topbar {
    background: var(--em-topbar); color: #fff;
    height: 52px; display: flex; align-items: center;
    padding: 0 1rem; gap: 1rem; z-index: 100;
}
.email-topbar-left { display: flex; align-items: center; gap: 0.5rem; min-width: 200px; }
.email-brand-icon { font-size: 1.3rem; color: var(--em-primary); }
.email-brand { font-weight: 800; font-size: 1rem; white-space: nowrap; }
.email-topbar-center { flex: 1; display: flex; justify-content: center; }
.email-search {
    display: flex; align-items: center; gap: 0.5rem;
    background: rgba(255,255,255,0.1); border-radius: 8px;
    padding: 0 0.75rem; width: 100%; max-width: 500px; height: 36px;
}
.email-search i { color: rgba(255,255,255,0.5); font-size: 0.85rem; }
.email-search input {
    background: transparent; border: none; color: #fff;
    font-size: 0.85rem; flex: 1; outline: none;
}
.email-search input::placeholder { color: rgba(255,255,255,0.4); }
.email-search kbd {
    font-size: 0.65rem; background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.5);
    padding: 0.1rem 0.35rem; border-radius: 4px; border: none;
}
.email-topbar-right { display: flex; align-items: center; gap: 0.25rem; }
.email-topbar-btn {
    background: transparent; border: none; color: rgba(255,255,255,0.7);
    padding: 0.4rem; border-radius: 6px; font-size: 1.1rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    text-decoration: none;
}
.email-topbar-btn:hover { color: #fff; background: rgba(255,255,255,0.1); }
.email-user-info { display: flex; align-items: center; gap: 0.25rem; margin-left: 0.5rem; }
.email-user-info span { font-size: 0.78rem; color: rgba(255,255,255,0.6); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Layout ───────────────────────────────────────── */
.email-app { display: flex; flex-direction: column; height: 100vh; padding-bottom: 2rem; }
.email-layout { display: flex; flex: 1; overflow: hidden; }

.email-powered-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    text-align: center;
    padding: 0.4rem 0.75rem;
    font-size: 0.76rem;
    font-weight: 600;
    color: rgba(255,255,255,0.82);
    background: rgba(15, 23, 42, 0.84);
    backdrop-filter: blur(8px);
}

/* ── Sidebar ──────────────────────────────────────── */
.email-sidebar {
    width: 220px; min-width: 220px; background: var(--em-sidebar);
    border-right: 1px solid var(--em-border); padding: 0.75rem;
    display: flex; flex-direction: column; overflow-y: auto;
}
.email-compose-btn {
    background: var(--em-primary); color: #fff; border: none;
    border-radius: 16px; padding: 0.6rem 1.25rem; font-weight: 700;
    font-size: 0.9rem; cursor: pointer; display: flex; align-items: center;
    gap: 0.5rem; justify-content: center; margin-bottom: 0.75rem;
    transition: background 0.15s; width: 100%;
}
.email-compose-btn:hover { background: #1557b0; }

.email-folder-list { display: flex; flex-direction: column; gap: 2px; }
.email-folder {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.5rem 0.75rem; border-radius: 8px;
    cursor: pointer; font-size: 0.85rem; color: var(--em-text);
    transition: all 0.12s; user-select: none;
}
.email-folder:hover { background: var(--em-hover); }
.email-folder.active { background: var(--em-selected); color: var(--em-primary); font-weight: 700; }
.email-folder i { font-size: 1rem; width: 20px; text-align: center; }
.email-folder-name { flex: 1; }
.email-folder-badge {
    font-size: 0.7rem; font-weight: 700; color: #fff;
    background: var(--em-primary); border-radius: 999px;
    padding: 0.1rem 0.45rem; min-width: 20px; text-align: center;
}
.email-folder-badge.zero { display: none; }

/* ── Message List ─────────────────────────────────── */
.email-list-pane {
    width: 380px; min-width: 320px; max-width: 420px;
    border-right: 1px solid var(--em-border);
    display: flex; flex-direction: column; background: var(--em-surface);
}
.email-list-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--em-border);
    min-height: 44px;
}
.email-list-title { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 0.9rem; }
.email-count { font-size: 0.75rem; color: var(--em-muted); font-weight: 400; }
.email-list-actions { display: flex; gap: 0.15rem; }
.email-action-btn {
    background: transparent; border: none; color: var(--em-muted);
    padding: 0.3rem; border-radius: 6px; font-size: 0.9rem; cursor: pointer;
}
.email-action-btn:hover { background: var(--em-hover); color: var(--em-text); }

.email-message-list { flex: 1; overflow-y: auto; }
.email-msg-row {
    display: flex; align-items: flex-start; gap: 0.5rem;
    padding: 0.6rem 0.75rem; border-bottom: 1px solid #f0f0f0;
    cursor: pointer; transition: background 0.1s;
}
.email-msg-row:hover { background: var(--em-hover); }
.email-msg-row.active { background: var(--em-selected); }
.email-msg-row.unread { font-weight: 600; }
.email-msg-row.unread .email-msg-from { color: var(--em-unread); }
.email-msg-row.unread .email-msg-subject { color: var(--em-unread); }

.email-msg-check {
    margin-top: 2px; flex-shrink: 0;
    accent-color: var(--em-primary);
}
.email-msg-content { flex: 1; min-width: 0; }
.email-msg-top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.email-msg-from { font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.email-msg-date { font-size: 0.7rem; color: var(--em-muted); white-space: nowrap; flex-shrink: 0; }
.email-msg-subject {
    font-size: 0.82rem; color: var(--em-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.email-msg-snippet {
    font-size: 0.78rem; color: var(--em-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 1px;
}
.email-msg-badges { display: flex; gap: 0.25rem; margin-top: 3px; }
.email-badge-attach { font-size: 0.7rem; color: var(--em-muted); }
.email-badge-flag { font-size: 0.7rem; color: #f4b400; }

/* ── Pagination ───────────────────────────────────── */
.email-pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 0.5rem; padding: 0.5rem; border-top: 1px solid var(--em-border);
    font-size: 0.8rem; color: var(--em-muted);
}
.email-pagination button {
    background: transparent; border: 1px solid var(--em-border);
    border-radius: 6px; padding: 0.25rem 0.5rem; cursor: pointer;
    font-size: 0.8rem; color: var(--em-text);
}
.email-pagination button:hover { background: var(--em-hover); }
.email-pagination button:disabled { opacity: 0.4; cursor: default; }

/* ── Detail Pane ──────────────────────────────────── */
.email-detail-pane {
    flex: 1; display: flex; flex-direction: column;
    background: var(--em-surface); overflow: hidden;
}
.email-detail-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    flex: 1; color: var(--em-muted);
}
.email-detail-empty i { font-size: 3rem; margin-bottom: 0.75rem; opacity: 0.3; }
.email-detail-empty p { font-size: 0.9rem; }

/* Message Detail View */
.email-detail-view { display: flex; flex-direction: column; height: 100%; }
.email-detail-toolbar {
    display: flex; align-items: center; gap: 0.25rem;
    padding: 0.5rem 1rem; border-bottom: 1px solid var(--em-border);
}
.email-detail-toolbar .email-action-btn { font-size: 1rem; padding: 0.4rem 0.5rem; }
.email-detail-toolbar .email-action-btn span { font-size: 0.78rem; margin-left: 0.25rem; }
.email-detail-toolbar .spacer { flex: 1; }

.email-detail-header { padding: 1.25rem 1.5rem 0.75rem; }
.email-detail-subject { font-size: 1.2rem; font-weight: 800; color: var(--em-text); margin-bottom: 0.75rem; }
.email-detail-meta { display: flex; align-items: flex-start; gap: 0.75rem; }
.email-detail-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--em-primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1rem; flex-shrink: 0;
}
.email-detail-sender { flex: 1; }
.email-detail-sender-name { font-weight: 700; font-size: 0.9rem; }
.email-detail-sender-email { font-size: 0.78rem; color: var(--em-muted); }
.email-detail-recipients { font-size: 0.78rem; color: var(--em-muted); margin-top: 0.25rem; }
.email-detail-date { font-size: 0.78rem; color: var(--em-muted); white-space: nowrap; }
.email-detail-attachments {
    padding: 0.5rem 1.5rem; display: flex; flex-wrap: wrap; gap: 0.5rem;
    border-bottom: 1px solid var(--em-border);
}
.email-attachment-chip {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.35rem 0.75rem; background: #f1f3f4; border-radius: 8px;
    font-size: 0.78rem; color: var(--em-text); cursor: pointer;
    border: 1px solid var(--em-border); text-decoration: none;
}
.email-attachment-chip:hover { background: #e8eaed; }
.email-attachment-chip i { color: var(--em-muted); }

.email-detail-body {
    flex: 1; overflow-y: auto; padding: 0;
}
.email-detail-body iframe {
    width: 100%; border: none; min-height: 300px;
}
.email-detail-body .text-body {
    padding: 1.25rem 1.5rem; white-space: pre-wrap; font-size: 0.9rem;
    line-height: 1.6; color: var(--em-text);
}

/* ── Compose ──────────────────────────────────────── */
.email-compose { display: flex; flex-direction: column; height: 100%; }
.email-compose-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.75rem 1rem; border-bottom: 1px solid var(--em-border);
    background: #f8f9fa;
}
.email-compose-header h3 { font-size: 1rem; font-weight: 700; margin: 0; }
.email-compose-close {
    background: transparent; border: none; font-size: 1.2rem;
    color: var(--em-muted); cursor: pointer; padding: 0.25rem;
}
.email-compose-fields { padding: 0; }
.email-compose-field {
    display: flex; align-items: center; padding: 0.4rem 1rem;
    border-bottom: 1px solid #f0f0f0; gap: 0.5rem;
}
.email-compose-field label {
    font-size: 0.82rem; color: var(--em-muted); font-weight: 600;
    min-width: 50px;
}
.email-compose-field input {
    border: none; outline: none; flex: 1; font-size: 0.85rem;
    padding: 0.3rem 0;
}
.email-compose-body {
    flex: 1; display: flex; flex-direction: column; overflow: hidden;
}
.email-compose-body textarea, .email-compose-body .compose-editor {
    flex: 1; border: none; outline: none; padding: 1rem;
    font-size: 0.9rem; line-height: 1.6; resize: none;
    font-family: inherit;
}
.email-compose-body .compose-editor {
    overflow-y: auto; min-height: 200px;
}
.email-compose-body .compose-editor:focus { outline: none; }
.email-compose-toolbar {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.5rem 1rem; border-top: 1px solid var(--em-border);
}
.email-compose-toolbar .btn-send {
    background: var(--em-primary); color: #fff; border: none;
    border-radius: 20px; padding: 0.5rem 1.5rem; font-weight: 700;
    font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; gap: 0.4rem;
}
.email-compose-toolbar .btn-send:hover { background: #1557b0; }
.email-compose-toolbar .btn-discard {
    background: transparent; border: none; color: var(--em-muted);
    font-size: 1.1rem; cursor: pointer; margin-left: auto; padding: 0.3rem;
}

/* ── Loading / Empty ──────────────────────────────── */
.email-loading {
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 2rem; color: var(--em-muted); font-size: 0.85rem;
}
.email-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 3rem 1rem; color: var(--em-muted); text-align: center;
}
.email-empty i { font-size: 2.5rem; opacity: 0.3; margin-bottom: 0.5rem; }
.email-empty p { font-size: 0.85rem; }

/* ── Toast ────────────────────────────────────────── */
.email-toast {
    position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
    background: #323232; color: #fff; padding: 0.75rem 1.5rem;
    border-radius: 8px; font-size: 0.85rem; z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3); animation: toastIn 0.3s;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 1100px) {
    .email-sidebar { width: 60px; min-width: 60px; padding: 0.5rem; }
    .email-compose-btn span { display: none; }
    .email-compose-btn { padding: 0.5rem; border-radius: 50%; width: 42px; height: 42px; justify-content: center; }
    .email-folder-name, .email-folder-badge { display: none; }
    .email-folder { justify-content: center; padding: 0.5rem; }
    .email-folder i { width: auto; font-size: 1.15rem; }
}
@media (max-width: 768px) {
    .email-list-pane { width: 100%; max-width: none; }
    .email-detail-pane { display: none; }
    .email-detail-pane.active { display: flex; position: absolute; inset: 52px 0 0 0; z-index: 50; }
    .email-layout.detail-open .email-list-pane { display: none; }
    .email-layout.detail-open .email-sidebar { display: none; }
    .email-layout.detail-open .email-detail-pane { display: flex; }
    .email-topbar-center { display: none; }
    .email-user-info span { display: none; }
    .email-powered-footer { font-size: 0.72rem; }
}

@media print {
    body { overflow: visible; height: auto; padding-bottom: 14mm; }
    .email-powered-footer {
        position: fixed;
        background: #fff;
        color: #475569;
        border-top: 1px solid #e2e8f0;
    }
}
