/* assets/css/style.css - Adaptado para/* assets/css/style.css */
:root {
    /* Dimca Toyota Brand Colors */
    --primary-color: #CC161E;
    /* Rojo */
    --primary-hover: #a80f15;
    --dark-color: #13130E;
    /* Nuevo Oscuro */
    --light-bg: #f4f6f9;
    --reader-surface: #ffffff;
    --reader-border: #e2e8f0;
    --reader-muted: #64748b;
    --reader-api: #0f766e;
    --reader-api-soft: #ecfdf5;
    --reader-ai: #4f46e5;
    --reader-ai-soft: #eef2ff;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--light-bg);
}

/* ============================================= */
/* MODAL GLASS EFFECT - APPLE STYLE             */
/* ============================================= */

/* Backdrop semi-transparente SIN blur */
#composeModal+.modal-backdrop,
.modal-backdrop.show {
    background-color: rgba(0, 0, 0, 0.12) !important;
}

/* Estilos del modal de redacción */
#composeModal .modal-content {
    background: rgba(255, 255, 255, 0.65) !important;
    backdrop-filter: blur(40px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(40px) saturate(180%) !important;
    box-shadow:
        0 25px 50px -12px rgba(0, 0, 0, 0.25),
        0 0 0 1px rgba(255, 255, 255, 0.2) inset,
        0 1px 0 0 rgba(255, 255, 255, 0.4) inset !important;
    border-radius: 16px !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
}

/* The signature manager can be launched from inside the compose modal. Keep
   its dialog above Bootstrap's backdrop on both desktop and mobile. */
#signatureManagerModal {
    z-index: 4000;
}

#signatureManagerModal .modal-content {
    position: relative;
    z-index: 4001;
}

#composeModal .modal-header {
    background: rgba(255, 255, 255, 0.35) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.4) !important;
    border-radius: 16px 16px 0 0 !important;
}

#composeModal .modal-body {
    background: rgba(255, 255, 255, 0.25) !important;
}

#composeModal .modal-footer {
    background: rgba(255, 255, 255, 0.35) !important;
    border-radius: 0 0 16px 16px !important;
    border-top: 1px solid rgba(255, 255, 255, 0.3) !important;
}

/* Inputs dentro del modal glass */
#composeModal .form-control {
    background: rgba(255, 255, 255, 0.5) !important;
    border-color: rgba(0, 0, 0, 0.08) !important;
}

#composeModal .form-control:focus {
    background: rgba(255, 255, 255, 0.7) !important;
    box-shadow: 0 0 0 3px rgba(204, 22, 30, 0.15) !important;
}

/* Force override of Bootstrap Primary - AGGRESSIVE */
.text-primary {
    color: var(--primary-color) !important;
}

.bg-primary {
    background-color: var(--primary-color) !important;
}

.btn-primary {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
    background-color: var(--primary-hover) !important;
    border-color: var(--primary-hover) !important;
    box-shadow: 0 4px 12px rgba(204, 22, 30, 0.4) !important;
}

.btn-outline-primary {
    color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
}

.btn-outline-primary:hover {
    background-color: var(--primary-color) !important;
    color: white !important;
}

/* Sidebar Branding */
.sidebar {
    background: linear-gradient(180deg, #13130E 0%, #1a0505 100%) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

#mainSidebar {
    width: 260px;
    background: linear-gradient(180deg, #111111 0%, #1a1a1a 100%);
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.3);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar .nav-link {
    color: rgba(255, 255, 255, 0.7) !important;
    font-weight: 500;
    margin-bottom: 4px;
    border-radius: 8px;
    padding: 10px 15px;
    transition: all 0.2s ease;
}

.sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white !important;
    transform: translateX(4px);
}

.sidebar .nav-link.active {
    background: linear-gradient(90deg, #CC161E 0%, #a80f15 100%) !important;
    color: white !important;
    box-shadow: 0 4px 15px rgba(204, 22, 30, 0.4) !important;
    font-weight: 600;
}

/* Glassmorphism Logic for Login */
.glass-effect {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.glass-card {
    background: rgba(19, 19, 14, 0.6);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 3rem;
    color: white;
}

/* Utilities */
.avatar-circle {
    width: 40px;
    height: 40px;
    object-fit: cover;
}

.email-item {
    cursor: pointer;
    transition: background 0.2s;
    border-left: 3px solid transparent;
}

.email-item:hover {
    background-color: #fff0f0;
    /* Slight red tint on hover */
    border-left-color: var(--primary-color);
}

.email-item.unread {
    background-color: #ffffff;
    border-left-color: var(--primary-color);
}

/* Vista previa de correo: texto plano, no HTML ni imágenes externas. */
.email-preview-popover {
    position: fixed;
    z-index: 2100;
    width: min(320px, calc(100vw - 24px));
    min-height: 76px;
    padding: 12px 14px;
    border: 1px solid rgba(23, 32, 51, .12);
    border-radius: 10px;
    background: #fff;
    color: #172033;
    box-shadow: 0 12px 30px rgba(23, 32, 51, .18);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity .18s ease, transform .18s ease;
}

.email-preview-popover.show {
    opacity: 1;
    transform: translateY(0);
}

.email-preview-popover-title {
    margin-bottom: 5px;
    color: var(--primary-color);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.email-preview-popover-body {
    height: 112px;
    overflow: hidden;
}

.email-preview-frame {
    display: block;
    width: 100%;
    height: 112px;
    border: 0;
    background: #fff;
}

.email-preview-popover-body p,
.email-preview-popover-body div,
.email-preview-popover-body ul,
.email-preview-popover-body ol {
    margin: 0 0 .35rem;
}

.email-preview-popover-body img,
.email-preview-popover-body video,
.email-preview-popover-body table {
    max-width: 100%;
    height: auto;
}

@media (prefers-reduced-motion: reduce) {
    .email-preview-popover { transition: none; }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Global Layout Fixes */
/* Global Box Sizing Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Global Layout Fixes - Robust Flow */
.dashboard-container {
    display: flex;
    min-height: 100vh;
    /* Allow grouping to grow */
    width: 100%;
    position: relative;
}

.main-content {
    flex: 1;
    padding: 2rem;
    width: 100%;
    /* No overflow-y: auto here; let the window scroll */
}

/* Sidebar behavior */
.sidebar {
    background: linear-gradient(180deg, #13130E 0%, #1a0505 100%) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    width: 250px;
    /* Default width */
    flex-shrink: 0;
}

/* Fix for responsive images globally */
img,
svg,
video {
    max-width: 100%;
    height: auto;
}

/* RESPONSIVE DESIGN */
@media (min-width: 768px) {

    /* Desktop: Sidebar is sticky */
    #mainSidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        max-height: 100vh;
        overflow-y: auto;
        display: flex !important;
        flex-direction: column;
        width: 260px !important;
        min-width: 260px !important;
    }
}

@media (max-width: 767.98px) {

    /* Mobile: Sidebar is fixed overlay off-canvas */
    #mainSidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
        z-index: 2000;
        transition: transform 0.3s ease-in-out;
        box-shadow: none;
        /* Start hidden/shown logic handled by JS class toggle usually, 
           but based on previous code it seemed it might be always there or toggled.
           Assuming d-none handles visibility. */
    }

    /* Content stacks vertically on mobile */
    #email-view-container {
        flex-direction: column;
    }

    /* Reset widths for stacking */
    .col-md-4.col-lg-3,
    .col-md-8.col-lg-9 {
        width: 100% !important;
        flex: none !important;
        height: auto !important;
        /* Allow natural growth */
    }

    .col-md-4.col-lg-3 {
        border-right: none !important;
        border-bottom: 1px solid #dee2e6;
        margin-bottom: 1rem;
    }

    .col-md-8.col-lg-9 {
        height: auto !important;
    }

    .main-content {
        padding: 1rem;
        /* Less padding on mobile */
    }
}

/* ========================================================================== *
 * DIMCA MAIL UI/UX SYSTEM — visual layer only
 * Keeps the current PHP, AJAX, API and mail actions intact.
 * ========================================================================== */
:root {
    --dimca-primary: #b5121d;
    --dimca-primary-strong: #8f1018;
    --dimca-primary-soft: #fff0f1;
    --dimca-ink: #17202f;
    --dimca-muted: #667085;
    --dimca-canvas: #f5f7fb;
    --dimca-surface: #ffffff;
    --dimca-sidebar: #191b21;
    --dimca-sidebar-raised: #252832;
    --dimca-border: #e4e8ef;
    --dimca-blue: #2764d8;
    --dimca-success: #16845b;
    --dimca-warning: #a86a00;
    --dimca-danger: #b42318;
    --dimca-shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --dimca-shadow-md: 0 14px 34px rgba(16, 24, 40, .10);
    --dimca-radius-sm: 10px;
    --dimca-radius-md: 16px;
    --dimca-radius-lg: 22px;
    --dimca-motion: 180ms cubic-bezier(.2, .8, .2, 1);
}

html { font-size: 16px; }

body,
body.bg-light,
body.app-page {
    background: var(--dimca-canvas) !important;
    color: var(--dimca-ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a,
button,
select,
input,
textarea,
[role="button"] { touch-action: manipulation; }

a { color: var(--dimca-primary); }
a:hover { color: var(--dimca-primary-strong); }

:focus-visible {
    outline: 3px solid rgba(39, 100, 216, .35) !important;
    outline-offset: 2px;
}

.text-primary { color: var(--dimca-primary) !important; }
.bg-primary { background-color: var(--dimca-primary) !important; }
.btn-primary {
    background: var(--dimca-primary) !important;
    border-color: var(--dimca-primary) !important;
    box-shadow: 0 5px 12px rgba(181, 18, 29, .15) !important;
}
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
    background: var(--dimca-primary-strong) !important;
    border-color: var(--dimca-primary-strong) !important;
    box-shadow: 0 8px 18px rgba(181, 18, 29, .22) !important;
}
.btn-outline-primary {
    color: var(--dimca-primary) !important;
    border-color: rgba(181, 18, 29, .38) !important;
}
.btn-outline-primary:hover,
.btn-outline-primary:focus,
.btn-outline-primary:active {
    color: #fff !important;
    background: var(--dimca-primary) !important;
    border-color: var(--dimca-primary) !important;
}
.btn,
.form-control,
.form-select { border-radius: var(--dimca-radius-sm); }
.btn { min-height: 42px; font-weight: 600; }
.btn-sm { min-height: 36px; }
.btn:disabled,
.btn.disabled { cursor: not-allowed; }

/* Login */
body.login-screen {
    min-height: 100dvh;
    background: #17191f !important;
    color: #fff;
    overflow: auto;
}
body.login-screen::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 85% 10%, rgba(181, 18, 29, .35), transparent 34%),
        radial-gradient(circle at 10% 90%, rgba(39, 100, 216, .14), transparent 30%);
}
body.login-screen .login-card {
    position: relative;
    max-width: 420px;
    padding: 42px !important;
    border: 1px solid rgba(255, 255, 255, .12) !important;
    border-radius: var(--dimca-radius-lg) !important;
    background: rgba(31, 34, 42, .94) !important;
    box-shadow: 0 28px 70px rgba(0, 0, 0, .34) !important;
}
body.login-screen .login-card .form-control {
    min-height: 48px;
    background: rgba(255, 255, 255, .07) !important;
    border-color: rgba(255, 255, 255, .14) !important;
}
body.login-screen .login-card .form-control:focus {
    border-color: rgba(255, 103, 111, .85) !important;
    box-shadow: 0 0 0 4px rgba(181, 18, 29, .2) !important;
}
body.login-screen .btn-brand {
    min-height: 50px;
    background: var(--dimca-primary) !important;
    border-radius: 12px !important;
}

/* Shared standalone pages */
body.app-page > main,
body.app-page > .container,
body.app-page > .container-fluid {
    position: relative;
}
body.app-page .card,
body.app-page .modal-content {
    border: 1px solid var(--dimca-border) !important;
    border-radius: var(--dimca-radius-md) !important;
    box-shadow: var(--dimca-shadow-sm) !important;
}
body.app-page .card-header,
body.app-page .card-footer { border-color: var(--dimca-border) !important; }
body.app-page h1,
body.app-page h2,
body.app-page h3,
body.app-page h4,
body.app-page h5 { letter-spacing: -.02em; }
body.app-page .form-control,
body.app-page .form-select {
    min-height: 44px;
    border-color: var(--dimca-border);
    background: var(--dimca-surface);
}
body.app-page .form-control:focus,
body.app-page .form-select:focus {
    border-color: rgba(39, 100, 216, .7);
    box-shadow: 0 0 0 4px rgba(39, 100, 216, .12);
}
body.app-page .table { --bs-table-border-color: var(--dimca-border); }
body.app-page .table thead th {
    color: #475467;
    font-size: .72rem;
    letter-spacing: .06em;
    text-transform: uppercase;
    white-space: nowrap;
}
body.app-page .table tbody tr { transition: background var(--dimca-motion); }
body.app-page .table tbody tr:hover { --bs-table-hover-bg: #fff7f7; }
body.app-page .alert { border-radius: var(--dimca-radius-sm); }

/* Modern mail shell */
body:has(.mail-app-shell) { overflow: hidden; }
.mail-app-shell {
    min-height: 100dvh !important;
    background: var(--dimca-canvas);
}
#mainSidebar {
    flex: 0 0 272px;
    width: 272px !important;
    min-width: 272px !important;
    padding: 22px 16px !important;
    background: var(--dimca-sidebar) !important;
    border-right: 1px solid rgba(255, 255, 255, .07) !important;
    box-shadow: 8px 0 28px rgba(16, 24, 40, .08);
}
#mainSidebar > div:first-child { padding: 0 8px 20px; margin-bottom: 18px !important; border-bottom: 1px solid rgba(255, 255, 255, .08); }
#mainSidebar img { max-height: 40px !important; margin-right: 10px !important; }
#mainSidebar .nav { gap: 3px; }
#mainSidebar .nav-link {
    display: flex;
    align-items: center;
    min-height: 44px;
    margin: 0 !important;
    padding: 10px 12px !important;
    color: rgba(255, 255, 255, .68) !important;
    border: 1px solid transparent;
    border-radius: 11px;
    font-size: .9rem;
    font-weight: 600;
    transition: background var(--dimca-motion), color var(--dimca-motion), border var(--dimca-motion);
}
#mainSidebar .nav-link i { width: 20px; text-align: center; margin-right: 10px !important; }
#mainSidebar .nav-link:hover {
    color: #fff !important;
    background: rgba(255, 255, 255, .07);
    transform: none;
}
#mainSidebar .nav-link.active {
    color: #fff !important;
    background: rgba(181, 18, 29, .22) !important;
    border-color: rgba(255, 117, 125, .24);
    box-shadow: inset 3px 0 0 var(--dimca-primary) !important;
}
#mainSidebar .nav-link .badge { margin-left: auto; }
#mainSidebar .text-white-50 { color: rgba(255, 255, 255, .48) !important; }
#mainSidebar .btn-primary {
    min-height: 48px;
    border-radius: 12px !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
}
#mailbox-switcher button {
    min-height: 44px;
    color: #fff !important;
    background: rgba(255, 255, 255, .06) !important;
    border: 1px solid rgba(255, 255, 255, .14) !important;
}
#mailbox-switcher .dropdown-menu { border: 1px solid rgba(255, 255, 255, .1); border-radius: 12px !important; }
#mainSidebar > .mt-auto { border-color: rgba(255, 255, 255, .1) !important; }
#mainSidebar > .mt-auto > a:hover { background: rgba(255, 255, 255, .07); }

#email-view-container {
    min-width: 0;
    background: var(--dimca-canvas);
}
.mail-list-pane,
.mail-detail-pane { background: var(--dimca-canvas) !important; }
.mail-list-pane { border-color: var(--dimca-border) !important; }
.mail-list-pane > .p-2 {
    padding: 18px !important;
    background: rgba(255, 255, 255, .86) !important;
    border-color: var(--dimca-border) !important;
}
.search-input {
    min-height: 46px;
    border: 1px solid var(--dimca-border) !important;
    border-radius: 12px !important;
    background: #fff !important;
}
.search-input:focus { border-color: rgba(39, 100, 216, .65) !important; box-shadow: 0 0 0 4px rgba(39, 100, 216, .1) !important; }
.mail-search-filters .form-select { min-height: 38px; font-size: .78rem; }
#clear-mail-filters { min-width: 38px; }
#email-list-container { padding: 8px 12px 18px; }
.email-item {
    margin: 4px 0;
    padding: 14px !important;
    border: 1px solid var(--dimca-border) !important;
    border-radius: 13px;
    background: #fff !important;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .03);
    transition: border var(--dimca-motion), box-shadow var(--dimca-motion), transform var(--dimca-motion), background var(--dimca-motion);
}
.email-item:hover,
.email-item:focus-visible {
    background: #fff !important;
    border-color: rgba(181, 18, 29, .32) !important;
    box-shadow: 0 8px 20px rgba(16, 24, 40, .08);
    transform: translateY(-1px);
}
.email-item.unread { border-left: 3px solid var(--dimca-primary) !important; }
.email-item .email-subject { color: var(--dimca-ink); font-weight: 700; }
.email-item .email-preview { color: var(--dimca-muted) !important; }
.email-item .fa-star { min-width: 24px; min-height: 24px; display: inline-flex; align-items: center; justify-content: center; }
.email-preview-popover { border-color: var(--dimca-border); border-radius: 14px; box-shadow: var(--dimca-shadow-md); }

.mail-detail-pane {
    background: #fff !important;
    border-left: 1px solid var(--dimca-border);
}
.email-detail-header {
    padding: 22px 26px !important;
    background: #fff !important;
    border-color: var(--dimca-border) !important;
}
.email-reader-kicker { color: var(--dimca-muted); font-size: .7rem; letter-spacing: .1em; font-weight: 800; text-transform: uppercase; }
.email-reader-subject { color: var(--dimca-ink); font-size: clamp(1.15rem, 1.8vw, 1.7rem); }
.email-reader-actions { align-items: flex-start !important; }
.email-reader-actions .btn-group { flex-wrap: wrap; gap: 6px; box-shadow: none !important; }
.email-reader-actions .btn {
    min-width: 42px;
    border-radius: 9px !important;
    border-color: var(--dimca-border) !important;
    color: #475467 !important;
    background: #fff !important;
    box-shadow: none !important;
}
.email-reader-actions .btn:hover,
.email-reader-actions .btn:focus-visible { color: var(--dimca-primary) !important; border-color: rgba(181, 18, 29, .4) !important; background: var(--dimca-primary-soft) !important; }
.email-transport-badge { border-radius: 999px; font-weight: 700; }
.email-body-shell { background: #fff !important; }
.email-render-note {
    margin: 14px 22px 0;
    padding: 9px 12px;
    color: var(--dimca-muted);
    border: 1px solid var(--dimca-border);
    border-radius: 10px;
    background: #fafbfc;
    font-size: .78rem;
}
.email-content-frame { min-height: 360px; background: #fff; }
.message-attachments { background: #fafbfc !important; border-color: var(--dimca-border) !important; }
.message-attachments__tile { border-radius: 10px; overflow: hidden; }
.message-attachments__tile .btn { min-height: 42px; border-color: var(--dimca-border) !important; background: #fff; }
.message-attachments__tile .btn:hover { background: var(--dimca-primary-soft); color: var(--dimca-primary); }

/* Compose and editor */
#composeModal .modal-dialog { max-width: 860px; }
#composeModal .modal-content {
    background: #fff !important;
    border: 1px solid var(--dimca-border) !important;
    border-radius: var(--dimca-radius-lg) !important;
    box-shadow: 0 28px 72px rgba(16, 24, 40, .22) !important;
    backdrop-filter: none !important;
}
#composeModal .modal-header,
#composeModal .modal-footer,
#composeModal .modal-body {
    background: #fff !important;
    border-color: var(--dimca-border) !important;
}
#composeModal .modal-header { padding: 18px 24px !important; }
#composeModal .modal-title { font-size: 1rem; }
#composeModal .modal-body { padding: 22px 24px 0 !important; }
#composeModal .modal-footer { padding: 16px 24px 20px !important; }
#composeModal .form-control,
#composeModal .form-select { background: #fff !important; border-color: var(--dimca-border) !important; }
#composeModal .form-control:focus,
#composeModal .form-select:focus { border-color: rgba(39, 100, 216, .7) !important; box-shadow: 0 0 0 4px rgba(39, 100, 216, .1) !important; }
#composeModal .ql-toolbar,
#template-quill-toolbar {
    padding: 9px 10px !important;
    background: #f8fafc !important;
    border: 1px solid var(--dimca-border) !important;
    border-radius: 11px 11px 0 0 !important;
    box-shadow: none !important;
}
#composeModal .ql-toolbar .ql-formats,
#template-quill-toolbar .ql-formats {
    padding: 0 5px;
    background: transparent;
    border: 0;
    box-shadow: none;
}
#composeModal .ql-toolbar button,
#composeModal .ql-toolbar .ql-picker-label,
#template-quill-toolbar button,
#template-quill-toolbar .ql-picker-label { width: 34px !important; height: 34px !important; }
#composeModal .ql-toolbar button:hover,
#composeModal .ql-toolbar .ql-picker-label:hover,
#template-quill-toolbar button:hover,
#template-quill-toolbar .ql-picker-label:hover { background: var(--dimca-primary-soft) !important; transform: none; }
#quill-editor,
#template-quill-editor { min-height: 220px; border-color: var(--dimca-border) !important; border-radius: 0 0 11px 11px !important; }
#composeModal .modal-footer .btn { min-height: 44px; }
.email-input-wrapper { min-height: 46px; border-color: var(--dimca-border) !important; border-radius: 11px !important; background: #fff !important; }
.recipient-tag { min-height: 30px; background: #f2f4f7; border-color: #e4e7ec; color: #344054; }
.recipient-tag.invalid { background: #fff1f0; border-color: #fecdca; color: var(--dimca-danger); }
#file-list { display: flex; flex-wrap: wrap; gap: 6px; }
#file-list > * { border: 1px solid var(--dimca-border); border-radius: 9px; background: #f8fafc; padding: 6px 9px; }

/* Compact attachment pills and temporary-send feedback */
.compose-attachment-summary { min-width: 0; }
.compose-attachment-summary__meta { min-height: 24px; }
.compose-attachment-summary__meta small { line-height: 1.25; }
.compose-attachment-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 86px;
    overflow-y: auto;
    padding: 2px 2px 3px;
}
.compose-file-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: min(100%, 290px);
    min-height: 34px;
    padding: 3px 5px 3px 9px;
    border: 1px solid var(--dimca-border);
    border-radius: 999px;
    color: #344054;
    background: #f8fafc;
    font-size: .75rem;
    line-height: 1.2;
}
.compose-file-pill--danger { border-color: #fecdca; background: #fff5f4; }
.compose-file-pill--forwarded { border-color: #c9d8f7; background: #f5f8ff; }
.compose-file-pill--temporary { border-color: #f4c56b; background: #fff9eb; }
.compose-file-pill__icon { flex: 0 0 auto; color: #667085; }
.compose-file-pill--forwarded .compose-file-pill__icon { color: var(--dimca-primary); }
.compose-file-pill--temporary .compose-file-pill__icon { color: #b7791f; }
.compose-file-pill__name {
    min-width: 0;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}
.compose-file-pill__size { flex: 0 0 auto; color: #667085; }
.compose-file-pill__remove,
.compose-file-pill__extend {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 32px;
    min-height: 32px;
    padding: 0 7px;
    border: 0;
    border-radius: 999px;
    color: #667085;
    background: transparent;
    font-size: .72rem;
    font-weight: 700;
}
.compose-file-pill__extend { min-width: auto; color: #8a5a0a; }
.compose-file-pill__remove:hover,
.compose-file-pill__remove:focus-visible,
.compose-file-pill__extend:hover,
.compose-file-pill__extend:focus-visible { color: var(--dimca-primary); background: rgba(181, 18, 29, .08); outline: none; }
.temporary-bundle-progress {
    width: min(100%, 420px);
    padding: 5px 0 2px;
}
.temporary-bundle-progress__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: #475467;
    font-size: .76rem;
    line-height: 1.35;
}
.temporary-bundle-progress__meta strong { color: var(--dimca-primary); font-size: .72rem; }
.temporary-bundle-progress .progress {
    height: 6px;
    margin-top: 5px;
    overflow: hidden;
    border-radius: 999px;
    background: #e8edf5;
}
.temporary-bundle-progress .progress-bar { background: var(--dimca-primary); transition: width .25s ease; }
.temporary-bundle-progress__detail { display: block; margin-top: 4px; color: #98a2b3; font-size: .68rem; }

/* Retention choices: clear, compact, and keyboard accessible */
#temporaryBundleOptionsModal { z-index: 4100; }
#temporaryBundleOptionsModal + .modal-backdrop { z-index: 4090; }
.temporary-bundle-modal {
    overflow: hidden;
    border: 1px solid #e4e7ec;
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(16, 24, 40, .18);
}
.temporary-bundle-modal .modal-header { padding: 20px 22px 14px; border-bottom: 0; }
.temporary-bundle-modal .modal-body { padding: 0 22px 18px; }
.temporary-bundle-modal .modal-footer { gap: 8px; padding: 14px 22px 20px; border-top: 1px solid #eef1f5; }
.temporary-bundle-modal .modal-footer .btn { min-height: 44px; }
.temporary-bundle-modal__eyebrow { color: var(--dimca-primary); font-size: .66rem; font-weight: 800; letter-spacing: .08em; }
.temporary-bundle-modal .modal-title { margin-top: 4px; color: #101828; font-size: 1.05rem; font-weight: 750; }
.temporary-bundle-modal__summary {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 12px;
    border: 1px solid #d9e3f5;
    border-radius: 12px;
    color: #344054;
    background: #f5f8ff;
    font-size: .76rem;
}
.temporary-bundle-modal__summary strong,
.temporary-bundle-modal__summary span { display: block; }
.temporary-bundle-modal__summary span { margin-top: 2px; color: #667085; font-size: .7rem; }
.temporary-bundle-modal__summary-icon {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    margin: 0 !important;
    border-radius: 10px;
    color: var(--dimca-primary) !important;
    background: #fff;
    font-size: .9rem !important;
}
.temporary-bundle-modal__copy { margin: 15px 0 14px; color: #667085; font-size: .76rem; line-height: 1.55; }
.temporary-bundle-modal__legend { margin-bottom: 8px; color: #344054; font-size: .76rem; font-weight: 750; }
.temporary-retention-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.temporary-retention-option { position: relative; display: block; margin: 0; cursor: pointer; }
.temporary-retention-option input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.temporary-retention-option__card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 64px;
    padding: 9px 11px;
    border: 1px solid #d0d5dd;
    border-radius: 11px;
    color: #344054;
    background: #fff;
    transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.temporary-retention-option__card strong { font-size: .8rem; }
.temporary-retention-option__card small { margin-top: 2px; color: #98a2b3; font-size: .67rem; }
.temporary-retention-option input:checked + .temporary-retention-option__card {
    border-color: var(--dimca-primary);
    color: var(--dimca-primary);
    background: #fff7f7;
    box-shadow: 0 0 0 3px rgba(181, 18, 29, .1);
}
.temporary-retention-option input:focus-visible + .temporary-retention-option__card { outline: 3px solid rgba(39, 100, 216, .22); outline-offset: 2px; }

@media (max-width: 575.98px) {
    .temporary-bundle-modal .modal-dialog { margin: .75rem; }
    .temporary-bundle-modal .modal-footer { flex-wrap: nowrap; }
    .temporary-bundle-modal .modal-footer .btn { flex: 1 1 0; }
    .compose-file-pill { max-width: 100%; }
    .compose-file-pill__name { max-width: 135px; }
}

@media (prefers-reduced-motion: reduce) {
    .temporary-bundle-progress .progress-bar,
    .temporary-retention-option__card { transition: none; }
}

/* Mobile navigation and mail detail */
.toggle-sidebar-btn {
    width: 46px !important;
    height: 46px !important;
    border-radius: 12px !important;
    background: var(--dimca-sidebar) !important;
    border: 1px solid rgba(255, 255, 255, .12) !important;
    box-shadow: 0 8px 20px rgba(16, 24, 40, .18) !important;
}
.mobile-menu-backdrop { background: rgba(16, 24, 40, .58) !important; backdrop-filter: blur(3px); }
.mobile-menu {
    max-width: 360px !important;
    border: 1px solid rgba(255, 255, 255, .12) !important;
    border-radius: 20px !important;
    background: #20232b !important;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .38) !important;
    backdrop-filter: none !important;
}
.mobile-menu-item { min-height: 44px; border-radius: 10px !important; }
.mobile-menu-item.active,
.mobile-menu-item:hover { background: rgba(181, 18, 29, .26) !important; box-shadow: none !important; }
.mobile-menu-compose { min-height: 48px; border-radius: 11px !important; background: var(--dimca-primary) !important; box-shadow: none !important; }
.mobile-back-btn { border-radius: 11px !important; background: #fff !important; border-color: var(--dimca-border) !important; box-shadow: var(--dimca-shadow-sm); }

/* Standalone attachments */
.app-page--attachments .file-card { overflow: hidden; border-radius: var(--dimca-radius-md) !important; }
.app-page--attachments .file-card:hover { transform: translateY(-3px); box-shadow: var(--dimca-shadow-md) !important; }
.app-page--attachments .thumb { background: #f8fafc; border-bottom: 1px solid var(--dimca-border); }
.app-page--attachments .progress { height: 9px !important; background: #eaecf0; border-radius: 999px; }
.app-page--attachments .progress-bar { background: var(--dimca-primary); border-radius: inherit; }
.app-page--attachments .attachment-action { min-width: 44px; min-height: 44px; }

/* Tables, CRM pages and admin */
#pageSidebar,
.app-page .sidebar {
    background: var(--dimca-sidebar) !important;
    border-right: 1px solid rgba(255, 255, 255, .07) !important;
}
#pageSidebar .nav-link,
.app-page .sidebar .nav-link { min-height: 44px; border-radius: 10px; font-weight: 600; }
#pageSidebar .nav-link.active,
.app-page .sidebar .nav-link.active { background: rgba(181, 18, 29, .24) !important; box-shadow: inset 3px 0 0 var(--dimca-primary) !important; }
.app-page .main-content { padding: 32px !important; }
.app-page .card.shadow-sm,
.app-page .card.border-0 { box-shadow: var(--dimca-shadow-sm) !important; }
.app-page .card-header { background: #fff !important; }
.app-page .table-dark { --bs-table-bg: var(--dimca-sidebar); --bs-table-color: #fff; }
.app-page .badge { font-weight: 700; }
.app-page--diagnostics .log-table { font-size: .82rem; }
.app-page--diagnostics code { color: #475467; }

/* Quill, signature and template cards */
.template-card,
.signature-card { border: 1px solid var(--dimca-border) !important; border-radius: var(--dimca-radius-md) !important; box-shadow: var(--dimca-shadow-sm) !important; }
.template-card:hover,
.signature-card:hover { transform: translateY(-3px); box-shadow: var(--dimca-shadow-md) !important; }
.template-preview::after { background: linear-gradient(transparent, #fff) !important; }
#signature-editor { border-radius: var(--dimca-radius-md) !important; }
#signature-content { border-color: var(--dimca-border) !important; border-radius: 11px !important; }

/* Legacy screens receive the same visual language while behavior remains intact. */
body:has(.email-list-item) .sidebar,
body:has(#legacy-email-frame) .sidebar { background: var(--dimca-sidebar) !important; }
body:has(.email-list-item) .email-list-item {
    border: 1px solid var(--dimca-border) !important;
    border-radius: 12px !important;
    background: #fff !important;
    margin: 6px 0;
    transition: box-shadow var(--dimca-motion), border var(--dimca-motion), transform var(--dimca-motion);
}
body:has(.email-list-item) .email-list-item:hover { border-color: rgba(181, 18, 29, .32) !important; box-shadow: var(--dimca-shadow-sm); transform: translateY(-1px); }
body:has(#legacy-email-frame) .email-content-frame { border: 1px solid var(--dimca-border); border-radius: 12px; background: #fff; }

@media (max-width: 767.98px) {
    body:has(.mail-app-shell) { overflow: auto; }
    #mainSidebar { width: 100% !important; min-width: 0 !important; }
    .mail-list-pane > .p-2 { padding: 14px !important; }
    #email-list-container { padding: 6px 10px 14px; }
    .email-detail-header { padding: 18px 16px !important; }
    .email-reader-toolbar { gap: 12px !important; }
    .email-reader-actions { width: 100%; justify-content: flex-start; }
    .email-reader-actions .btn-group { width: 100%; }
    .email-reader-actions .btn { flex: 0 0 auto; }
    .email-render-note { margin: 12px 14px 0; }
    .app-page .main-content { padding: 68px 14px 20px !important; }
    body.app-page > main,
    body.app-page > .container,
    body.app-page > .container-fluid { padding-left: 14px !important; padding-right: 14px !important; }
    body.app-page .table-responsive { border-radius: 12px; }
    body.app-page .table { min-width: 680px; }
    #composeModal .modal-body { padding: 16px 14px 0 !important; }
    #composeModal .modal-footer { padding: 12px 14px 16px !important; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

.avatar-circle {
    width: 48px;
    height: 48px;
    font-size: 1.25rem;
    flex-shrink: 0;
}

/* Skeleton Loading Animation */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

.skeleton {
    background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-highlight) 50%, var(--skeleton-base) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
    display: inline-block;
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
    width: 100%;
}

.skeleton-heading {
    height: 1.5em;
    width: 80%;
    margin-bottom: 1em;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

/* Scrollbars custom (Chrome/Edge/Safari) */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.2);
}

/* Glass effect helpers */
.glass {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Toast Container Position */
.toast-container {
    z-index: 1060;
}

/* Tag Input Styles */
.recipient-tag {
    background-color: #e9ecef;
    color: #495057;
    border-radius: 16px;
    padding: 2px 10px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    border: 1px solid #ced4da;
}

.recipient-tag .tag-remove {
    margin-left: 6px;
    cursor: pointer;
    font-weight: bold;
    color: #6c757d;
    font-size: 1.1em;
    line-height: 0.8;
}

.recipient-tag .tag-remove:hover {
    color: var(--primary-color);
}

.recipient-tag.invalid {
    background-color: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

/* Attachments Section Styles */
.attachments-section {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

.attachments-section .btn-outline-secondary {
    background: white;
    border-color: #dee2e6;
    transition: all 0.2s ease;
}

.attachments-section .btn-outline-secondary:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(204, 22, 30, 0.25);
}

.attachments-section .btn-outline-secondary:hover i,
.attachments-section .btn-outline-secondary:hover span {
    color: white !important;
}

/* File type icon colors */
.text-purple {
    color: #7c3aed !important;
}

/* Email content images responsive */
.email-content-block img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

/* Email content block styling */
.email-content-block {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.email-content-block table {
    max-width: 100%;
    overflow-x: auto;
    display: block;
}

/* Inline image previews */
.email-content-block img[src^="data:"] {
    max-width: 100%;
    border-radius: 4px;
    margin: 0.5rem 0;
}

/* Attachment badges */
.badge.bg-secondary.rounded-pill {
    font-size: 0.7rem;
    font-weight: 500;
}

/* ============================================= */
/* QUILL EDITOR STYLES - PREMIUM UI             */
/* ============================================= */

/* Toolbar container - Glassmorphism */
#quill-toolbar,
.ql-toolbar.ql-snow {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 249, 250, 0.98) 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    border-radius: 12px 12px 0 0;
    padding: 10px 14px !important;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

/* Format button groups */
.ql-toolbar .ql-formats {
    display: inline-flex !important;
    align-items: center;
    gap: 2px;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    margin-right: 6px !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: all 0.2s ease;
}

.ql-toolbar .ql-formats:hover {
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

/* Individual toolbar buttons */
.ql-toolbar button,
.ql-toolbar .ql-picker-label {
    width: 32px !important;
    height: 32px !important;
    padding: 6px !important;
    border-radius: 6px !important;
    border: none !important;
    background: transparent !important;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1) !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.ql-toolbar button:hover,
.ql-toolbar .ql-picker-label:hover {
    background: rgba(204, 22, 30, 0.1) !important;
    transform: scale(1.08);
}

.ql-toolbar button.ql-active,
.ql-toolbar .ql-picker-label.ql-active {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%) !important;
    border-radius: 6px !important;
    box-shadow: 0 3px 12px rgba(204, 22, 30, 0.35) !important;
    transform: scale(1.02);
}

.ql-toolbar button.ql-active .ql-stroke,
.ql-toolbar button.ql-active .ql-fill,
.ql-toolbar .ql-picker-label.ql-active .ql-stroke {
    stroke: white !important;
    fill: white !important;
}

/* SVG icons styling */
.ql-toolbar .ql-stroke {
    stroke: #495057 !important;
    stroke-width: 1.8 !important;
    transition: all 0.15s ease !important;
}

.ql-toolbar .ql-fill {
    fill: #495057 !important;
    transition: all 0.15s ease !important;
}

.ql-toolbar button:hover .ql-stroke,
.ql-toolbar .ql-picker-label:hover .ql-stroke {
    stroke: var(--primary-color) !important;
}

.ql-toolbar button:hover .ql-fill,
.ql-toolbar .ql-picker-label:hover .ql-fill {
    fill: var(--primary-color) !important;
}

/* Picker dropdowns styling */
.ql-toolbar .ql-picker {
    height: 32px !important;
}

.ql-toolbar .ql-picker-options {
    background: white !important;
    border: 1px solid rgba(0, 0, 0, 0.1) !important;
    border-radius: 8px !important;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15) !important;
    padding: 6px !important;
}

.ql-toolbar .ql-picker-item {
    border-radius: 4px !important;
    padding: 4px 8px !important;
    transition: background 0.15s ease !important;
}

.ql-toolbar .ql-picker-item:hover {
    background: rgba(204, 22, 30, 0.08) !important;
    color: var(--primary-color) !important;
}

/* Quill editor container */
#quill-editor {
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-top: none;
    border-radius: 0 0 12px 12px;
    transition: box-shadow 0.2s ease;
}

#quill-editor:focus-within {
    box-shadow: 0 0 0 3px rgba(204, 22, 30, 0.15);
}

.ql-container.ql-snow {
    border-color: rgba(0, 0, 0, 0.08) !important;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
}

.ql-editor {
    padding: 16px 20px !important;
    line-height: 1.6;
}

.ql-editor.ql-blank::before {
    color: #adb5bd;
    font-style: normal;
}

/* Custom toolbar buttons - Emoji & Template */
.ql-emoji,
.ql-template {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 32px !important;
    height: 32px !important;
    border-radius: 6px !important;
    transition: all 0.15s ease !important;
}

.ql-emoji i,
.ql-template i {
    font-size: 1rem;
    color: #495057;
    transition: all 0.15s ease;
}

.ql-emoji:hover,
.ql-template:hover {
    background: rgba(204, 22, 30, 0.1) !important;
    transform: scale(1.08);
}

.ql-emoji:hover i,
.ql-template:hover i {
    color: var(--primary-color);
}

/* Emoji picker container */
#emoji-picker-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

#emoji-grid button {
    border: none !important;
    border-radius: 6px;
    transition: all 0.12s ease;
}

#emoji-grid button:hover {
    transform: scale(1.25);
    background-color: rgba(204, 22, 30, 0.1) !important;
}

/* Template cards hover effect */
.template-card {
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease;
    border-radius: 12px;
}

.template-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.18) !important;
}

/* Quill editor image sizing */
.ql-editor img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Links in sent emails */
.email-content-block a {
    color: #0d6efd;
    text-decoration: underline;
    transition: color 0.15s ease;
}

.email-content-block a:hover {
    color: var(--primary-color);
}

/* ============================================= */
/* MOBILE OPTIMIZATION - FLOATING MENU          */
/* ============================================= */

@media (max-width: 767.98px) {

    /* ===== HIDE DESKTOP SIDEBAR ===== */
    #mainSidebar,
    #pageSidebar {
        display: none !important;
    }

    /* ===== FLOATING MENU GLASS ===== */
    .mobile-menu-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 3000;
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .mobile-menu-container.show {
        opacity: 1;
        visibility: visible;
    }

    .mobile-menu-backdrop {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }

    .mobile-menu {
        position: relative;
        width: 90%;
        max-width: 300px;
        max-height: 85vh;
        overflow-y: auto;
        background: rgba(25, 25, 20, 0.88);
        backdrop-filter: blur(40px) saturate(180%);
        -webkit-backdrop-filter: blur(40px) saturate(180%);
        border-radius: 20px;
        padding: 20px;
        box-shadow:
            0 25px 60px rgba(0, 0, 0, 0.5),
            0 0 0 1px rgba(255, 255, 255, 0.08) inset,
            0 1px 0 0 rgba(255, 255, 255, 0.1) inset;
        border: 1px solid rgba(255, 255, 255, 0.06);
        transform: scale(0.9) translateY(20px);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .mobile-menu-container.show .mobile-menu {
        transform: scale(1) translateY(0);
    }

    .mobile-menu-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 20px;
        padding-bottom: 16px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .mobile-menu-logo {
        display: flex;
        align-items: center;
        gap: 10px;
        color: white;
        font-weight: 600;
        font-size: 1.1rem;
    }

    .mobile-menu-logo i {
        color: var(--primary-color);
    }

    .mobile-menu-close {
        width: 36px;
        height: 36px;
        border: none;
        background: rgba(255, 255, 255, 0.1);
        color: white;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .mobile-menu-close:hover {
        background: rgba(255, 255, 255, 0.2);
        transform: rotate(90deg);
    }

    .mobile-menu-nav {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .mobile-menu-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 11px 14px;
        color: rgba(255, 255, 255, 0.85);
        text-decoration: none;
        border-radius: 10px;
        font-weight: 500;
        font-size: 0.95rem;
        transition: all 0.2s ease;
        background: transparent;
        border: none;
        width: 100%;
        text-align: left;
        cursor: pointer;
    }

    .mobile-menu-item:hover,
    .mobile-menu-item.active {
        background: rgba(255, 255, 255, 0.1);
        color: white;
    }

    .mobile-menu-item.active {
        background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
        box-shadow: 0 4px 15px rgba(204, 22, 30, 0.4);
    }

    .mobile-menu-item i {
        width: 20px;
        text-align: center;
        font-size: 1.1rem;
    }

    .mobile-menu-divider {
        height: 1px;
        background: rgba(255, 255, 255, 0.08);
        margin: 12px 0;
    }

    .mobile-menu-compose {
        margin-top: 16px;
        padding: 14px;
        background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
        color: white;
        border: none;
        border-radius: 12px;
        font-weight: 600;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        cursor: pointer;
        transition: all 0.2s ease;
        box-shadow: 0 4px 15px rgba(204, 22, 30, 0.35);
    }

    .mobile-menu-compose:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(204, 22, 30, 0.45);
    }

    /* Hamburger button floating */
    .toggle-sidebar-btn {
        display: flex !important;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 2500;
        width: 48px;
        height: 48px;
        align-items: center;
        justify-content: center;
        background: rgba(19, 19, 14, 0.6);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        color: white;
        border-radius: 14px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
        border: 1px solid rgba(255, 255, 255, 0.1);
        transition: all 0.2s ease;
    }

    .toggle-sidebar-btn:hover {
        background: rgba(19, 19, 14, 0.8);
        transform: scale(1.05);
    }

    /* ===== MAIN CONTENT LAYOUT ===== */
    .main-content {
        padding: 60px 10px 10px 10px !important;
        margin-left: 0 !important;
    }

    /* Email view container - stack columns */
    #email-view-container,
    .row.flex-grow-1 {
        flex-direction: column !important;
    }

    /* Email list column - FULL SCREEN on mobile */
    .col-md-4.col-lg-3,
    [class*="col-md-4"][class*="col-lg-3"] {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        border-right: none !important;
        border-bottom: none !important;
        max-height: calc(100vh - 70px);
        min-height: calc(100vh - 70px);
        overflow-y: auto;
    }

    /* Email detail column - OVERLAY on mobile */
    .col-md-8.col-lg-9,
    [class*="col-md-8"][class*="col-lg-9"] {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        background: white;
        z-index: 1500;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        padding-top: 50px !important;
    }

    .col-md-8.col-lg-9.show-mobile,
    [class*="col-md-8"][class*="col-lg-9"].show-mobile {
        transform: translateX(0);
    }

    /* Back button for mobile detail view */
    /* Close button for mobile detail view (Right side) */
    .mobile-back-btn {
        position: fixed;
        top: 12px;
        right: 12px;
        left: auto;
        /* Reset left */
        z-index: 2000;
        width: 40px;
        height: 40px;
        background: rgba(0, 0, 0, 0.1);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        color: #333;
        border: 1px solid rgba(0, 0, 0, 0.1);
        border-radius: 50%;
        display: none;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .mobile-back-btn:active {
        background: rgba(0, 0, 0, 0.2);
        transform: scale(0.95);
    }

    .mobile-back-btn.show {
        display: flex;
    }

    /* ===== MODAL RESPONSIVE ===== */
    /* The mobile reading pane uses z-index:1500. Bootstrap's default modal
       z-index (1055) would leave the backdrop visible while hiding the modal
       content underneath the reading pane. Keep every modal above that pane. */
    .modal {
        z-index: 4000 !important;
    }

    .modal-backdrop {
        z-index: 3990 !important;
    }

    .modal-dialog {
        margin: 10px !important;
        max-width: calc(100vw - 20px) !important;
    }

    .modal-lg,
    .modal-xl {
        max-width: calc(100vw - 20px) !important;
    }

    #composeModal .modal-content {
        border-radius: 12px !important;
    }

    #composeModal .modal-body {
        padding: 12px !important;
    }

    /* Quill toolbar compact on mobile */
    #quill-toolbar,
    .ql-toolbar.ql-snow {
        padding: 6px !important;
        gap: 3px !important;
        flex-wrap: wrap !important;
    }

    .ql-toolbar .ql-formats {
        padding: 2px 4px !important;
        margin-right: 3px !important;
        margin-bottom: 3px !important;
    }

    .ql-toolbar button,
    .ql-toolbar .ql-picker-label {
        width: 28px !important;
        height: 28px !important;
        padding: 4px !important;
    }

    /* Modal footer - stack buttons */
    #composeModal .modal-footer {
        flex-direction: column !important;
        gap: 8px;
        padding: 12px !important;
    }

    #composeModal .modal-footer>div {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    #composeModal .modal-footer .btn {
        width: 100% !important;
        padding: 12px !important;
    }

    /* ===== TABLES RESPONSIVE ===== */
    .table-responsive-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table.table {
        min-width: 600px;
    }

    /* Card tables for mobile */
    .table-responsive {
        border: none !important;
    }

    /* ===== TOUCH TARGETS ===== */
    .btn {
        min-height: 44px;
        padding: 10px 16px !important;
    }

    .btn-sm {
        min-height: 38px;
        padding: 8px 12px !important;
    }

    .nav-link {
        padding: 12px 16px !important;
        min-height: 44px;
    }

    /* Email list items - larger touch area */
    .email-item,
    .list-group-item {
        padding: 14px 12px !important;
    }

    /* ===== FORM ELEMENTS ===== */
    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 16px !important;
        /* Prevent zoom on iOS */
    }

    /* Search input */
    .search-input {
        font-size: 16px !important;
    }

    /* ===== HEADER ADJUSTMENTS ===== */
    .email-detail-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px;
    }

    .email-detail-header .btn-group {
        width: 100%;
        justify-content: flex-end;
    }

    /* ===== CHAT SECTION ===== */
    #chat-section {
        height: calc(100vh - 120px) !important;
    }

    .chat-input-container {
        padding: 8px !important;
    }

    .chat-input-container .form-control {
        font-size: 16px !important;
    }

    /* ===== UTILITIES ===== */
    .d-mobile-none {
        display: none !important;
    }

    .d-mobile-block {
        display: block !important;
    }

    .text-truncate-mobile {
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Hide right panel placeholder on mobile */
    .email-placeholder-panel {
        display: none !important;
    }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 991.98px) {
    .col-md-4.col-lg-3 {
        width: 35% !important;
        flex: 0 0 35% !important;
    }

    .col-md-8.col-lg-9 {
        width: 65% !important;
        flex: 0 0 65% !important;
    }

    .modal-lg {
        max-width: 90vw !important;
    }
}

/* ============================================= */
/* EMAIL READER - SINGLE SCROLL, CONTENT FIRST   */
/* ============================================= */
.mail-app-shell,
#email-view-container,
.mail-list-pane,
.mail-detail-pane {
    min-width: 0;
}

.mail-detail-pane {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.email-detail-header {
    position: sticky;
    top: 0;
    z-index: 20;
}

.email-body-shell {
    flex: 0 0 auto;
    width: 100%;
    min-height: 360px;
    background: #fff;
}

.email-content-frame {
    display: block;
    width: 100%;
    min-height: 360px;
    border: 0;
    background: #fff;
    overflow: hidden;
}

/* Same safe-reader geometry used by Hostinger: the outer pane owns the
 * scrolling and the message iframe only grows to the sanitized document. */
.iframe-safe-renderer {
    position: relative;
    max-width: 100%;
    max-height: none;
    transition: height .2s ease;
}

#legacy-email-frame {
    min-height: 500px;
}

@media screen and (min-width: 768px) {
    .mail-app-shell {
        height: 100dvh;
        min-height: 100dvh !important;
        overflow: hidden;
    }

    #email-view-container {
        height: 100dvh !important;
        min-height: 0;
        overflow: hidden;
    }

    .mail-list-pane,
    .mail-detail-pane {
        height: 100%;
        min-height: 0;
    }

    .mail-list-pane {
        overflow: hidden;
    }

    #email-list-container {
        min-height: 0;
    }
}

@media screen and (max-width: 767.98px) {
    .mail-app-shell {
        min-height: 100dvh;
    }

    .mail-list-pane {
        max-height: calc(100dvh - 70px) !important;
        min-height: calc(100dvh - 70px) !important;
    }

    .mail-detail-pane {
        height: 100dvh !important;
        max-height: 100dvh !important;
        padding-top: 52px !important;
        -webkit-overflow-scrolling: touch;
    }

    .email-detail-header {
        padding: .45rem .55rem !important;
        gap: .35rem !important;
    }

    /* Keep the subject and actions on one compact row. The previous mobile
     * width:100% on .btn-group forced the subject into a very narrow column. */
    .email-detail-header > .d-flex:first-child {
        width: 100%;
        flex-wrap: nowrap !important;
        gap: .35rem !important;
        margin-bottom: .35rem !important;
        align-items: center !important;
    }

    .email-detail-header h4 {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none !important;
        padding-right: 0;
        font-size: .95rem !important;
        line-height: 1.15 !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        word-break: normal !important;
    }

    .email-detail-header > .d-flex:first-child .btn-group {
        width: auto !important;
        max-width: 52vw;
        flex: 0 0 auto;
        overflow-x: auto;
        overflow-y: hidden;
        justify-content: flex-start !important;
        flex-wrap: nowrap !important;
        box-shadow: none !important;
    }

    .email-detail-header > .d-flex:first-child .btn-group .btn {
        flex: 0 0 auto;
        padding: .25rem .45rem;
        font-size: .75rem;
        line-height: 1.2;
    }

    .email-detail-header > .d-flex:nth-child(2) {
        width: 100%;
        flex-wrap: nowrap !important;
        gap: .45rem !important;
        align-items: center !important;
    }

    .email-detail-header .avatar-circle {
        width: 30px !important;
        height: 30px !important;
        font-size: .9rem !important;
    }

    .email-detail-header .fs-6 {
        font-size: .78rem !important;
    }

    .email-detail-header .sender-email-display,
    .email-detail-header .text-muted.small {
        font-size: .68rem !important;
    }

    .email-detail-header .recipient-chip {
        max-width: 58vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding: .15rem .35rem !important;
    }

    .email-detail-header .text-nowrap.text-md-end {
        font-size: .68rem !important;
        margin-top: 0 !important;
    }

    .email-detail-header .recipient-panel,
    .email-detail-header .btn-toggle-recipients {
        font-size: .72rem;
    }

    .email-body-shell,
    .email-content-frame {
        min-height: calc(100dvh - 220px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .mail-detail-pane,
    .mobile-back-btn,
    .toggle-sidebar-btn {
        transition: none !important;
    }
}

/* ============================================= */
/* API-FIRST EMAIL READER                        */
/* ============================================= */
.email-detail-header {
    background: var(--reader-surface) !important;
    border-color: var(--reader-border) !important;
}

.email-reader-toolbar {
    min-width: 0;
}

.email-reader-title-wrap {
    min-width: 0;
    flex: 1 1 auto;
}

.email-reader-kicker {
    margin-bottom: .25rem;
    color: var(--reader-muted);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    line-height: 1;
    text-transform: uppercase;
}

.email-reader-subject {
    max-width: 100% !important;
    color: #172033;
    font-size: clamp(1rem, 1.45vw, 1.3rem) !important;
    overflow-wrap: anywhere;
}

.email-reader-actions {
    flex: 0 0 auto;
}

.email-reader-actions .btn-group {
    border-radius: 10px;
    overflow: hidden;
}

.email-reader-actions .btn {
    min-height: 38px;
}

.email-transport-badge {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    min-height: 32px;
    padding: .35rem .6rem;
    border: 1px solid var(--reader-border);
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .02em;
    white-space: nowrap;
}

.email-transport-badge--api {
    color: var(--reader-api);
    background: var(--reader-api-soft);
    border-color: #a7f3d0;
}

.email-transport-badge--legacy {
    color: #92400e;
    background: #fffbeb;
    border-color: #fde68a;
}

.btn-ai-coming-soon {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    color: var(--reader-ai) !important;
    background: var(--reader-ai-soft) !important;
    border: 1px solid #c7d2fe !important;
    opacity: 1 !important;
    cursor: not-allowed !important;
    font-weight: 700;
}

.btn-ai-coming-soon:disabled {
    color: var(--reader-ai) !important;
}

.email-coming-soon-label {
    display: inline-flex;
    align-items: center;
    padding: .12rem .32rem;
    border-radius: 4px;
    background: rgba(79, 70, 229, .12);
    font-size: .6rem;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
}

.email-body-shell--api {
    background: var(--reader-surface);
}

.email-render-note {
    display: flex;
    align-items: center;
    gap: .45rem;
    min-height: 30px;
    padding: .35rem .85rem;
    color: var(--reader-muted);
    background: #f8fafc;
    border-bottom: 1px solid var(--reader-border);
    font-size: .7rem;
}

.email-render-note i {
    color: var(--reader-api);
}

.message-attachments {
    background: #f8fafc !important;
    border-color: var(--reader-border) !important;
}

@media (max-width: 767.98px) {
    .email-reader-toolbar {
        align-items: center !important;
        gap: .5rem !important;
    }

    .email-reader-actions {
        max-width: 58vw;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .email-transport-badge {
        display: none;
    }

    .email-reader-actions .btn {
        min-height: 38px;
        padding: .45rem .55rem !important;
    }

    .email-coming-soon-label {
        display: none;
    }

    .email-render-note {
        padding-inline: .65rem;
        font-size: .66rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .email-reader-actions .btn,
    .email-transport-badge {
        transition: none !important;
    }
}

/* ============================================= */
/* PRINT STYLES - ROBUST VISIBILITY METHOD      */
/* ============================================= */
@media print {
    /* Hide EVERYTHING by default */
    body * {
        visibility: hidden;
    }

    /* Show ONLY the email content and its children */
    #email-detail-content, 
    #email-detail-content * {
        visibility: visible;
    }

    /* Position the content at the top-left of the page */
    #email-detail-content {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0;
        padding: 0;
        background: white;
        border: none;
    }

    /* Ensure specific elements inside are displayed correctly */
    #email-detail-content img {
        max-width: 100% !important;
        height: auto;
    }

    /* Adjust typography for print */
    #email-detail-content h1, 
    #email-detail-content h2, 
    #email-detail-content h3 {
        color: black !important;
        page-break-after: avoid;
    }
    
    #email-detail-content p {
        orphans: 3;
        widows: 3;
        color: black !important;
    }

    #email-detail-content a {
        text-decoration: underline;
        color: black !important;
    }

    /* Ensure background graphics (colors) are printed if browser setting allows */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* Mail list search filters */
.mail-search-filters .form-select {
    min-width: 0;
    font-size: 0.75rem;
}

#mail-status-filter {
    flex: 0 1 42%;
}

#mail-time-filter {
    flex: 1 1 58%;
}

#mail-filter-summary {
    min-height: 1rem;
    font-size: 0.7rem;
}

@media (max-width: 767.98px) {
    .mail-search-filters {
        gap: 0.35rem !important;
    }

    .mail-search-filters .form-select,
    .mail-search-filters .btn {
        min-height: 32px;
    }
}

/* Final cascade pass: this file still contains legacy rules above. These
   selectors intentionally live at EOF so the visual system wins without
   changing any interaction or business logic. */
:root {
    --primary-color: var(--dimca-primary);
    --primary-hover: var(--dimca-primary-strong);
    --light-bg: var(--dimca-canvas);
    --text-primary: var(--dimca-ink);
    --text-secondary: var(--dimca-muted);
    --border-color: var(--dimca-border);
    --accent-color: var(--dimca-primary);
    --bg-card: #fff;
}

.glass {
    background: #fff !important;
    border: 1px solid var(--dimca-border) !important;
    border-radius: var(--dimca-radius-md) !important;
    box-shadow: var(--dimca-shadow-sm) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

body:has(.email-list-item) .glass,
body:has(#legacy-email-frame) .glass { background: #fff !important; }

body:has(.email-list-item) .btn-primary,
body:has(#legacy-email-frame) .btn-primary { min-height: 42px; border-radius: 10px !important; }

body,
body.bg-light,
body.app-page { background: var(--dimca-canvas) !important; color: var(--dimca-ink) !important; }
body:has(.mail-app-shell) { overflow: hidden; }
#mainSidebar { width: 272px !important; min-width: 272px !important; background: var(--dimca-sidebar) !important; }
#mainSidebar .nav-link { min-height: 44px; margin: 0 !important; border-radius: 11px !important; transform: none !important; }
#mainSidebar .nav-link:hover { background: rgba(255,255,255,.07) !important; }
#mainSidebar .nav-link.active { background: rgba(181,18,29,.24) !important; box-shadow: inset 3px 0 0 var(--dimca-primary) !important; }
#mainSidebar .btn-primary { min-height: 48px; border-radius: 12px !important; text-transform: none !important; letter-spacing: 0 !important; }
#email-view-container,
.mail-list-pane { background: var(--dimca-canvas) !important; }
.mail-detail-pane { background: #fff !important; border-left: 1px solid var(--dimca-border) !important; }
.mail-list-pane > .p-2 { padding: 18px !important; background: rgba(255,255,255,.9) !important; border-color: var(--dimca-border) !important; }
.email-item { margin: 4px 0; padding: 14px !important; border: 1px solid var(--dimca-border) !important; border-radius: 13px !important; background: #fff !important; box-shadow: 0 1px 2px rgba(16,24,40,.03) !important; transform: none !important; }
.email-item:hover,
.email-item:focus-visible { border-color: rgba(181,18,29,.32) !important; box-shadow: 0 8px 20px rgba(16,24,40,.08) !important; transform: translateY(-1px) !important; }
.email-item.unread { border-left: 3px solid var(--dimca-primary) !important; }
.email-detail-header { padding: 22px 26px !important; background: #fff !important; border-color: var(--dimca-border) !important; }
.email-reader-actions .btn { min-width: 42px; border-radius: 9px !important; border-color: var(--dimca-border) !important; color: #475467 !important; background: #fff !important; box-shadow: none !important; }
.email-reader-actions .btn:hover,
.email-reader-actions .btn:focus-visible { color: var(--dimca-primary) !important; background: var(--dimca-primary-soft) !important; }
.email-render-note { margin: 14px 22px 0; border-color: var(--dimca-border) !important; border-radius: 10px !important; background: #fafbfc !important; }
.message-attachments { background: #fafbfc !important; border-color: var(--dimca-border) !important; }
#composeModal .modal-content { background: #fff !important; border: 1px solid var(--dimca-border) !important; border-radius: var(--dimca-radius-lg) !important; box-shadow: 0 28px 72px rgba(16,24,40,.22) !important; backdrop-filter: none !important; }
#composeModal .modal-header,
#composeModal .modal-body,
#composeModal .modal-footer { background: #fff !important; border-color: var(--dimca-border) !important; }
#composeModal .form-control,
#composeModal .form-select { background: #fff !important; border-color: var(--dimca-border) !important; }
#composeModal .ql-toolbar,
#template-quill-toolbar { background: #f8fafc !important; border-color: var(--dimca-border) !important; box-shadow: none !important; }
#composeModal .ql-toolbar button:hover,
#composeModal .ql-toolbar .ql-picker-label:hover,
#template-quill-toolbar button:hover,
#template-quill-toolbar .ql-picker-label:hover { background: var(--dimca-primary-soft) !important; transform: none !important; }
.app-page .card { border-color: var(--dimca-border) !important; border-radius: var(--dimca-radius-md) !important; box-shadow: var(--dimca-shadow-sm) !important; }
.app-page .main-content { padding: 32px !important; }
#pageSidebar,
.app-page .sidebar { background: var(--dimca-sidebar) !important; }
#pageSidebar .nav-link.active,
.app-page .sidebar .nav-link.active { background: rgba(181,18,29,.24) !important; box-shadow: inset 3px 0 0 var(--dimca-primary) !important; }
.template-card,
.signature-card { border-color: var(--dimca-border) !important; border-radius: var(--dimca-radius-md) !important; box-shadow: var(--dimca-shadow-sm) !important; }
.app-page--attachments .file-card:hover,
.template-card:hover,
.signature-card:hover { box-shadow: var(--dimca-shadow-md) !important; }
body.login-screen { min-height: 100dvh !important; height: auto !important; overflow: auto !important; background: #17191f !important; }
body.login-screen .login-card { background: rgba(31,34,42,.94) !important; border-color: rgba(255,255,255,.12) !important; border-radius: var(--dimca-radius-lg) !important; }

@media (max-width: 767.98px) {
    body:has(.mail-app-shell) { overflow: auto; }
    #mainSidebar { width: 100% !important; min-width: 0 !important; }
    .mail-list-pane > .p-2 { padding: 14px !important; }
    .email-detail-header { padding: 18px 16px !important; }
    .email-reader-actions { width: 100%; }
    .email-reader-actions .btn-group { width: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
    .email-render-note { margin: 12px 14px 0; }
    .app-page .main-content { padding: 68px 14px 20px !important; }
    body.app-page > main,
    body.app-page > .container,
    body.app-page > .container-fluid { padding-left: 14px !important; padding-right: 14px !important; }
    body.app-page .table { min-width: 680px; }
}

/* Read state and reader actions: keep the status visible and the toolbar
   stable when the subject or viewport becomes narrow. */
.mail-list-pane #email-list-container .email-item {
    position: relative;
    padding-left: 20px !important;
}

.mail-list-pane #email-list-container .email-item::before {
    content: "";
    position: absolute;
    left: 8px;
    top: 18px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #98a2b3;
    box-shadow: 0 0 0 3px rgba(152, 162, 179, .12);
}

.mail-list-pane #email-list-container .email-item.unread::before {
    background: var(--dimca-primary);
    box-shadow: 0 0 0 3px rgba(181, 18, 29, .14);
}

.mail-list-pane #email-list-container .email-item:not(.unread) {
    background: #f8fafc !important;
    border-color: #eaecf0 !important;
}

.mail-list-pane #email-list-container .email-item:not(.unread) .email-subject {
    color: #475467 !important;
    font-weight: 600 !important;
}

.mail-list-pane #email-list-container .email-item:not(.unread) .text-truncate.fw-semibold {
    color: #667085 !important;
    font-weight: 500 !important;
}

.mail-list-pane #email-list-container .email-item.unread .email-subject,
.mail-list-pane #email-list-container .email-item.unread .text-truncate.fw-semibold {
    color: var(--dimca-ink) !important;
    font-weight: 700 !important;
}

.email-reader-toolbar {
    flex-wrap: wrap !important;
}

.email-reader-title-wrap {
    min-width: 0;
    flex: 1 1 280px;
}

.email-reader-actions {
    min-width: 0;
    flex: 0 1 auto;
}

.email-reader-actions .btn-group {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center;
    justify-content: flex-end;
    gap: 6px !important;
    margin: 0 !important;
}

.email-reader-actions .btn-group > .btn,
.email-reader-actions .btn-group > .btn:first-child,
.email-reader-actions .btn-group > .btn:last-child {
    position: relative;
    flex: 0 0 auto;
    margin-left: 0 !important;
    border-radius: 9px !important;
    white-space: nowrap;
}

#composeModal .modal-footer > div:last-child {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

@media (max-width: 1040px) {
    .email-reader-toolbar {
        align-items: stretch !important;
    }

    .email-reader-actions,
    .email-reader-actions .btn-group {
        width: 100%;
    }

    .email-reader-actions .btn-group {
        justify-content: flex-start;
    }
}

@media (max-width: 767.98px) {
    .mail-list-pane #email-list-container .email-item {
        padding-left: 20px !important;
    }

    .email-reader-actions .btn-group > .btn {
        min-height: 44px;
    }

    #composeModal .modal-footer > div:last-child {
        width: 100%;
        justify-content: stretch;
    }

    #composeModal .modal-footer > div:last-child .btn {
        flex: 1 1 100%;
    }
}

/* Unified overlay layers. The mobile reader intentionally sits above the
 * application canvas; every modal must be above it and its backdrop below it.
 * Keeping this outside the mobile media query fixes the same issue on desktop
 * when the reading pane or a browser extension creates a stacking context. */
:root {
    --dimca-z-detail: 20;
    --dimca-z-mobile-detail: 1500;
    --dimca-z-menu: 3000;
    --dimca-z-modal-backdrop: 3990;
    --dimca-z-modal: 4000;
    --dimca-z-ai-modal: 5000;
    --dimca-z-toast: 6000;
}

body.dimca-ai-modal-open {
    overflow: hidden !important;
    padding-right: 0 !important;
}

.modal-backdrop {
    z-index: var(--dimca-z-modal-backdrop) !important;
}

.modal {
    z-index: var(--dimca-z-modal) !important;
}

#aiAssistantModal {
    position: fixed !important;
    inset: 0;
    z-index: var(--dimca-z-ai-modal) !important;
    padding: 16px !important;
}

#aiAssistantModal.show {
    display: block !important;
    overflow-x: hidden;
    overflow-y: auto;
}

#aiAssistantModal .modal-dialog {
    width: 100%;
    max-width: min(720px, calc(100vw - 32px)) !important;
    min-height: calc(100% - 32px);
    margin: 0 auto !important;
    display: flex;
    align-items: center;
}

#aiAssistantModal .modal-content {
    width: 100%;
    max-height: calc(100dvh - 32px);
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.16) !important;
    border-radius: 18px !important;
    box-shadow: 0 28px 80px rgba(16,24,40,.34) !important;
}

#aiAssistantModal .modal-header {
    background: var(--dimca-sidebar) !important;
    border-bottom: 1px solid rgba(255,255,255,.12) !important;
}

#aiAssistantModal .modal-body {
    overflow-y: auto;
    overscroll-behavior: contain;
}

#aiAssistantModal .modal-footer {
    border-top: 1px solid var(--dimca-border) !important;
}

.dimca-ai-backdrop {
    z-index: 4990 !important;
}

@media (max-width: 767.98px) {
    #aiAssistantModal { padding: 10px !important; }
    #aiAssistantModal .modal-dialog {
        max-width: calc(100vw - 20px) !important;
        min-height: calc(100% - 20px);
    }
    #aiAssistantModal .modal-content { max-height: calc(100dvh - 20px); border-radius: 15px !important; }
}

/* AI drafting bar: keep the intent field visible and the action easy to find. */
.ai-compose-assistant {
    margin: 0 0 1rem;
    padding: .85rem 1rem;
    border: 1px solid rgba(181, 18, 29, .18);
    border-radius: 14px;
    background: linear-gradient(135deg, var(--dimca-primary-soft) 0%, var(--dimca-surface) 76%);
    box-shadow: var(--dimca-shadow-sm);
}

.ai-compose-assistant__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .75rem;
}

.ai-compose-assistant__eyebrow {
    display: flex;
    align-items: center;
    gap: .45rem;
    color: var(--dimca-primary);
    font-size: .9rem;
    font-weight: 700;
}

.ai-compose-assistant__hint {
    margin: .25rem 0 0;
    color: var(--dimca-muted);
    font-size: .78rem;
    line-height: 1.45;
}

.ai-compose-assistant__status {
    flex: 0 0 auto;
    padding: .35rem .55rem;
    border-radius: 999px;
    color: var(--dimca-success);
    background: #effaf5;
    font-size: .75rem;
    font-weight: 700;
    white-space: nowrap;
}

.ai-compose-assistant__status.is-unavailable {
    color: var(--dimca-muted);
    background: #f2f4f7;
}

.ai-compose-assistant__controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 150px auto;
    gap: .75rem;
    align-items: end;
}

.ai-compose-assistant__field label {
    display: block;
    margin-bottom: .3rem;
    color: var(--dimca-ink);
    font-size: .76rem;
    font-weight: 700;
}

.ai-compose-assistant__field textarea,
.ai-compose-assistant__field select {
    min-height: 44px;
    border: 1px solid var(--dimca-border);
    border-radius: 10px;
}

.ai-compose-assistant__field textarea {
    resize: vertical;
    min-height: 56px;
    max-height: 150px;
}

.ai-compose-assistant__field textarea:focus,
.ai-compose-assistant__field select:focus {
    border-color: var(--dimca-primary);
    box-shadow: 0 0 0 3px rgba(181, 18, 29, .12);
}

#ai-draft-btn.ai-compose-button {
    width: auto !important;
    min-width: 160px;
    min-height: 44px;
    padding: .65rem 1rem !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    border: 1px solid var(--dimca-primary) !important;
    border-radius: 10px;
    color: #fff !important;
    background: var(--dimca-primary) !important;
    font-weight: 700;
    transition: background var(--dimca-motion), border-color var(--dimca-motion), box-shadow var(--dimca-motion);
}

#ai-draft-btn.ai-compose-button:hover,
#ai-draft-btn.ai-compose-button:focus-visible {
    color: #fff !important;
    background: var(--dimca-primary-strong) !important;
    border-color: var(--dimca-primary-strong) !important;
    box-shadow: 0 4px 12px rgba(181, 18, 29, .2);
}

#ai-draft-btn.ai-compose-button:disabled {
    opacity: .5;
    cursor: not-allowed;
    box-shadow: none;
}

@media (max-width: 767.98px) {
    .ai-compose-assistant__header { flex-direction: column; gap: .5rem; }
    .ai-compose-assistant__controls { grid-template-columns: 1fr; }
    #ai-draft-btn.ai-compose-button { width: 100% !important; }
}

@media (prefers-reduced-motion: reduce) {
    #ai-draft-btn.ai-compose-button { transition: none; }
}

#aiAssistantModal .ai-draft-apply-options {
    padding: .8rem .9rem;
    border: 1px solid var(--dimca-border);
    border-radius: 11px;
    background: var(--dimca-canvas);
}

#aiAssistantModal .ai-draft-apply-options .btn {
    min-height: 42px;
}
