:root {
    --email-sidebar-width: 280px;
    --primary-soft: #eef2ff;
    --accent-color: #4f46e5;
    --accent-hover: #4338ca;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --bg-light: #f9fafb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --unread-bg: #f8faff;
    --unread-dot: #4338ca;
}

/* --- Layout Structure --- */
.email-wrapper {
    display: flex;
    height: calc(100vh - 60px); 
    background-color: var(--bg-light);
    overflow: hidden;
    position: relative;
}

/* --- Sidebar & Account Switcher --- */
.email-sidebar {
    width: var(--email-sidebar-width);
    background: white;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    flex-shrink: 0;
    z-index: 2001;
    height: 100%;
}

.btn-compose {
    background: var(--accent-color);
    color: white !important;
    border-radius: 12px;
    padding: 12px;
    font-weight: 600;
    border: none;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
    margin-bottom: 1.5rem;
    transition: all 0.2s ease;
}

.btn-compose:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 10px 15px -3px rgba(79, 70, 229, 0.3);
}

.nav-link-custom {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 10px;
    font-weight: 500;
    margin-bottom: 4px;
    transition: 0.2s;
}

.nav-link-custom i { width: 30px; font-size: 1.1rem; }
.nav-link-custom:hover { background: #f3f4f6; color: var(--text-main); }
.nav-link-custom.active { background: var(--primary-soft); color: var(--accent-color); }

/* --- Account Switcher Area --- */
.account-switcher-area {
    margin-top: auto;
    padding: 1.25rem 0.5rem;
    border-top: 1px solid var(--border-color);
    background: linear-gradient(to bottom, transparent, #fafafa);
}

#accountDropdown {
    transition: all 0.2s ease;
    background: white;
}

#accountDropdown:hover {
    background: white;
    border-color: var(--accent-color) !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05) !important;
}

.active-account-item {
    background-color: var(--primary-soft) !important;
    position: relative;
}

.active-account-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    bottom: 20%;
    width: 3px;
    background: var(--accent-color);
    border-radius: 0 4px 4px 0;
}

.avatar-box-sm {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    box-shadow: inset 0 -2px 0 rgba(0,0,0,0.1);
}

/* --- Main Content & Toolbar --- */
.email-content { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    min-width: 0;
}

.email-toolbar {
    background: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    height: 64px;
    z-index: 10;
}

.search-box {
    background: #f3f4f6;
    border-radius: 12px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 400px;
}

.search-box input { 
    background: transparent; 
    border: none; 
    outline: none; 
    padding-left: 10px;
    width: 100%; 
}

/* --- Email List Item States --- */
.email-list-container { 
    flex: 1; 
    overflow-y: auto; 
    background: white; 
}

.email-item {
    display: grid;
    grid-template-columns: 48px 200px 1fr 100px 80px;
    align-items: center;
    padding: 10px 1.5rem;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    transition: background 0.15s ease;
}

/* Hover Effect */
.email-item:hover { 
    background: #f8fafc; 
    box-shadow: inset 4px 0 0 var(--accent-color);
}

.email-item:hover .action-icons {
    opacity: 1;
}

/* Unread State */
.email-item.unread {
    background-color: var(--unread-bg);
}

.email-item.unread .sender-name,
.email-item.unread .subject-line {
    font-weight: 700;
    color: var(--text-main);
}

.unread-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: var(--unread-dot);
    border-radius: 50%;
    margin-right: 8px;
}

/* Read State */
.email-item.read .sender-name,
.email-item.read .subject-line {
    font-weight: 500;
    color: var(--text-muted);
}

.email-item.read .avatar-box {
    opacity: 0.7;
}

/* UI Components */
.avatar-box {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
}

.action-icons {
    opacity: 0;
    transition: opacity 0.2s;
    white-space: nowrap;
}

/* --- Compose Window --- */
.compose-popup {
    position: fixed;
    bottom: 0;
    right: 30px;
    width: 540px;
    max-height: 80vh;
    background: white;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 10px 50px rgba(0,0,0,0.15);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.compose-popup.minimized { transform: translateY(calc(100% - 48px)); }
.compose-header { background: #1f2937; color: white; padding: 12px 16px; border-radius: 11px 11px 0 0; cursor: pointer; }
.compose-body input { border: none; border-bottom: 1px solid var(--border-color); padding: 12px 16px; width: 100%; outline: none; }
.compose-body textarea { min-height: 300px; resize: none; border: none; padding: 16px; width: 100%; outline: none; }

/* --- Mobile Styling --- */
@media (max-width: 991px) {
    .email-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        transition: 0.3s ease-in-out;
    }

    .email-sidebar.show { left: 0; }
    
    .sidebar-overlay { display: none; }
    .email-sidebar.show + .sidebar-overlay { display: block; }

    .email-item {
        grid-template-columns: 48px 1fr 80px;
        grid-template-rows: auto auto;
        padding: 12px;
    }

    .email-item .avatar-box { grid-row: 1 / 3; }
    .email-item .email-main { grid-column: 2 / 4; grid-row: 2; padding-top: 4px; }
    .email-item .email-sender { grid-column: 2; grid-row: 1; font-size: 0.95rem; }
    .email-item .email-date { grid-column: 3; grid-row: 1; font-size: 0.8rem; text-align: right; }
    
    .action-icons, .email-checkbox { display: none; }

    .compose-popup { width: 100%; height: 100%; right: 0; border-radius: 0; max-height: 100vh; }
}

.hidden { display: none !important; }