* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4F46E5;
    --primary-light: #6366F1;
    --primary-dark: #4338CA;
    --secondary: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --gray-900: #111827;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 0.5rem;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
}

.container {
    display: grid;
    grid-template-columns: 280px 1fr 350px;
    height: 100vh;
    gap: 0;
    background: white;
}

/* ===== SIDEBAR ===== */
.sidebar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    overflow-y: auto;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.nav-menu {
    flex: 1;
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    margin: 0 0.5rem;
    border-radius: var(--radius);
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.nav-item.active {
    background: rgba(255, 255, 255, 0.25);
    color: white;
    font-weight: 600;
}

.nav-item .icon {
    font-size: 1.25rem;
}

.nav-item span:nth-child(2) {
    flex: 1;
}

.badge {
    background: var(--danger);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    min-width: 1.5rem;
    text-align: center;
}

.badge:empty {
    display: none;
}

.sidebar-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.2);
    margin: 1rem 0;
}

.settings-section {
    padding: 1rem;
}

.settings-section h3 {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    opacity: 0.7;
    margin-bottom: 0.75rem;
}

.btn-settings {
    width: 100%;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-settings:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ===== MAIN CONTENT ===== */
.main-content {
    display: flex;
    flex-direction: column;
    background: white;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    gap: 1rem;
}

.search-box {
    flex: 1;
}

.search-box input {
    width: 100%;
    padding: 0.5rem 1rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.top-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    padding: 0.5rem 0.75rem;
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--gray-200);
}

.email-list-container {
    flex: 1;
    overflow-y: auto;
}

.email-list {
    display: flex;
    flex-direction: column;
}

.email-item {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    cursor: pointer;
    transition: all 0.2s ease;
    gap: 1rem;
}

.email-item:hover {
    background: var(--gray-50);
}

.email-item.unread {
    background: rgba(79, 70, 229, 0.05);
    font-weight: 600;
}

.email-item-star {
    cursor: pointer;
    font-size: 1.25rem;
    user-select: none;
}

.email-item-content {
    flex: 1;
    min-width: 0;
}

.email-item-from {
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 0.25rem;
}

.email-item-subject {
    color: var(--gray-700);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.email-item-preview {
    font-size: 0.85rem;
    color: var(--gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-item-date {
    font-size: 0.85rem;
    color: var(--gray-500);
    white-space: nowrap;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--gray-400);
}

.empty-state p {
    font-size: 2rem;
}

.empty-state small {
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

/* ===== EMAIL DETAIL ===== */
.email-detail {
    background: white;
    border-left: 1px solid var(--gray-200);
    padding: 1.5rem;
    overflow-y: auto;
    display: none;
}

.email-detail.active {
    display: flex;
    flex-direction: column;
}

.detail-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

#email-content {
    flex: 1;
}

.email-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.email-from {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.email-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
}

.email-sender-info h3 {
    margin-bottom: 0.25rem;
}

.email-sender-info p {
    font-size: 0.85rem;
    color: var(--gray-500);
}

.email-meta {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1rem;
}

.email-subject {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.email-body {
    line-height: 1.7;
    color: var(--gray-700);
}

/* ===== MODALS ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content.modal-lg {
    max-width: 700px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-500);
    transition: all 0.2s ease;
}

.btn-close:hover {
    color: var(--gray-900);
}

/* ===== FORMS ===== */
form {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.95rem;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group textarea {
    resize: vertical;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
}

/* ===== BUTTONS ===== */
.btn-primary,
.btn-secondary {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-900);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

/* ===== UTILITIES ===== */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .container {
        grid-template-columns: 1fr 350px;
    }

    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.active {
        transform: translateX(0);
    }
}

@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
    }

    .email-detail {
        position: absolute;
        right: 0;
        top: 0;
        width: 100%;
        height: 100%;
        z-index: 50;
    }

    .modal-content {
        width: 95%;
    }

    .top-bar {
        flex-direction: column;
    }

    .search-box {
        order: 2;
    }

    .top-actions {
        order: 1;
        width: 100%;
    }
}
