/* ============================================================
   CloudMail — Elegant Webmail Stylesheet
   Modern, clean, professional email client design
   ============================================================ */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    
    --bg-body: #f1f5f9;
    --bg-sidebar: #ffffff;
    --bg-panel: #ffffff;
    --bg-hover: #f8fafc;
    --bg-active: #eef2ff;
    --bg-input: #f8fafc;
    
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;
    
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --header-height: 68px;
    
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-panel: #1e293b;
    --bg-hover: #334155;
    --bg-active: #312e81;
    --bg-input: #334155;
    
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    
    --border: #334155;
    --border-light: #1e293b;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
}

/* Screens */
.screen {
    display: none;
    height: 100vh;
    width: 100vw;
}

.screen.active {
    display: flex;
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
#login-screen {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    position: relative;
    overflow: hidden;
}

#login-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.login-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    padding: 48px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-xl);
    position: relative;
    z-index: 1;
    animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-brand {
    text-align: center;
    margin-bottom: 36px;
}

.login-brand .logo {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.3);
}

.login-brand .logo i {
    font-size: 32px;
    color: white;
}

.login-brand h1 {
    font-family: 'Playfair Display', serif;
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.login-brand p {
    color: var(--text-muted);
    font-size: 0.95rem;
    letter-spacing: 0.5px;
}

.login-form .input-group {
    position: relative;
    margin-bottom: 18px;
}

.login-form .input-group i:first-child {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 16px;
}

.login-form input {
    width: 100%;
    padding: 14px 16px 14px 46px;
    border: 2px solid var(--border-light);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: var(--transition);
    font-family: inherit;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary-light);
    background: white;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.login-form .toggle-password {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

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

.btn-full {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
}

.btn-icon {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-compose {
    margin: 0 20px 20px;
    padding: 14px;
    font-size: 1rem;
    border-radius: var(--radius-lg);
}

.error-message {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 12px;
    text-align: center;
    min-height: 20px;
}

.login-footer {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--border-light);
    text-align: center;
}

.login-footer p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.security-badges {
    display: flex;
    justify-content: center;
    gap: 16px;
}

.security-badges i {
    font-size: 18px;
    color: var(--success);
}

/* ============================================================
   MAIN APP LAYOUT
   ============================================================ */
#main-screen {
    display: none;
}

#main-screen.active {
    display: flex;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    flex-shrink: 0;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    border-bottom: 1px solid var(--border-light);
}

.sidebar-header .logo {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-header .logo i {
    color: white;
    font-size: 16px;
}

.sidebar-header .brand {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 1.3rem;
    color: var(--text-primary);
    flex: 1;
}

.sidebar-toggle {
    opacity: 0.6;
}

.sidebar-toggle:hover {
    opacity: 1;
}

/* Folders */
.folder-list {
    flex: 1;
    padding: 8px 12px;
    overflow-y: auto;
}

.folder-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
    margin-bottom: 2px;
    position: relative;
}

.folder-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.folder-item.active {
    background: var(--bg-active);
    color: var(--primary);
    font-weight: 500;
}

.folder-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 3px;
    background: var(--primary);
    border-radius: 0 3px 3px 0;
}

.folder-item i {
    width: 20px;
    text-align: center;
    font-size: 15px;
}

.folder-item span:nth-child(2) {
    flex: 1;
    font-size: 0.92rem;
}

.badge {
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.badge-warning {
    background: var(--warning);
}

.badge:empty,
.badge[style*="0"] {
    display: none;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.user-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
   EMAIL LIST PANEL
   ============================================================ */
.email-list-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    min-width: 380px;
    border-right: 1px solid var(--border);
}

.list-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.list-title h2 {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.email-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.list-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-box {
    position: relative;
    width: 260px;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 13px;
}

.search-box input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: inherit;
    transition: var(--transition);
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Email List */
.email-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.email-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px 18px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2px;
    position: relative;
    border: 1px solid transparent;
}

.email-item:hover {
    background: var(--bg-hover);
    border-color: var(--border);
}

.email-item.active {
    background: var(--bg-active);
    border-color: var(--primary-light);
}

.email-item.unread {
    background: rgba(99, 102, 241, 0.03);
}

.email-item.unread .email-from,
.email-item.unread .email-subject {
    font-weight: 600;
}

.email-item.unread::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
}

.email-sender-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--primary-dark);
    flex-shrink: 0;
}

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

.email-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.email-from {
    font-size: 0.92rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 70%;
}

.email-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.email-subject {
    font-size: 0.88rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.email-preview {
    font-size: 0.82rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: var(--transition);
}

.email-item:hover .email-actions {
    opacity: 1;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    padding: 60px 20px;
}

.empty-state i {
    font-size: 56px;
    margin-bottom: 20px;
    opacity: 0.4;
}

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

/* ============================================================
   READING PANE
   ============================================================ */
.reading-pane {
    width: 45%;
    min-width: 400px;
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.reading-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.reading-empty i {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.3;
}

.email-read-header {
    padding: 24px 28px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.email-read-actions {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
}

.email-read-subject {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
    line-height: 1.3;
}

.email-read-meta {
    display: flex;
    align-items: center;
    gap: 14px;
}

.email-read-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--primary-dark);
    font-size: 1rem;
}

.email-read-sender-info {
    flex: 1;
}

.email-read-from {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.email-read-to {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.email-read-date {
    font-size: 0.82rem;
    color: var(--text-muted);
    text-align: right;
}

.email-read-body {
    flex: 1;
    padding: 28px;
    overflow-y: auto;
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.email-read-body a {
    color: var(--primary);
}

.email-read-body blockquote {
    border-left: 3px solid var(--border);
    padding-left: 16px;
    margin-left: 0;
    color: var(--text-secondary);
}

/* ============================================================
   COMPOSE MODAL
   ============================================================ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.compose-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-light);
}

.compose-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.compose-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.compose-field {
    display: flex;
    align-items: center;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-light);
    gap: 12px;
}

.compose-field label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    width: 60px;
    flex-shrink: 0;
}

.compose-field input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.95rem;
    color: var(--text-primary);
    font-family: inherit;
    padding: 4px;
}

.compose-field input:focus {
    outline: none;
}

.compose-body {
    flex: 1;
    overflow: hidden;
}

.compose-body textarea {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    padding: 20px 24px;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text-primary);
    line-height: 1.7;
    resize: none;
}

.compose-body textarea:focus {
    outline: none;
}

.compose-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-top: 1px solid var(--border-light);
    gap: 12px;
}

.toolbar-left {
    display: flex;
    gap: 4px;
}

.toolbar-right {
    display: flex;
    gap: 10px;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-radius: var(--radius);
    background: var(--bg-panel);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    animation: toastIn 0.3s ease-out;
    min-width: 280px;
    max-width: 420px;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast.info {
    border-left: 4px solid var(--info);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

.toast i {
    font-size: 18px;
}

.toast.success i { color: var(--success); }
.toast.error i { color: var(--danger); }
.toast.info i { color: var(--info); }

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(2px);
    z-index: 3000;
    align-items: center;
    justify-content: center;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
    .reading-pane {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 500;
        width: 100%;
    }
    
    .reading-pane.active {
        display: flex;
    }
    
    .email-list-panel {
        border-right: none;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 400;
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .email-list-panel {
        min-width: auto;
    }
    
    .search-box {
        width: 160px;
    }
    
    .login-container {
        margin: 20px;
        padding: 32px 24px;
    }
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
