/* SalloqMail - Main Styles */

:root {
    /* Colors - Light Theme (improved contrast) */
    --bg-primary: #ffffff;
    --bg-secondary: #f5f6f8;
    --bg-tertiary: #ebedf0;
    --bg-hover: #e0e3e8;
    
    --text-primary: #111111;
    --text-secondary: #444950;
    --text-muted: #6b7280;
    
    --accent-blue: #2563eb;
    --accent-blue-hover: #1d4ed8;
    --accent-green: #059669;
    --accent-yellow: #d97706;
    --accent-red: #dc2626;
    
    --border-color: #c8ccd2;
    --border-light: #dde0e5;
    
    /* Sizing */
    --sidebar-width: 240px;
    --header-height: 56px;
    --message-list-width: 380px;
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.12);
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.2s ease;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #1a1b1e;
    --bg-secondary: #212225;
    --bg-tertiary: #2a2b2f;
    --bg-hover: #35363b;
    
    --text-primary: #e4e5e8;
    --text-secondary: #a8aab0;
    --text-muted: #72747a;
    
    --accent-blue: #4d8ef7;
    --accent-blue-hover: #3b7df0;
    --accent-green: #34d399;
    --accent-yellow: #fbbf24;
    --accent-red: #f87171;
    
    --border-color: #363739;
    --border-light: #2e2f33;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.35);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.4);
}

/* Dark mode: invert email HTML content that has light backgrounds */
[data-theme="dark"] .preview-body {
    background: #1e1e22;
    color: var(--text-primary);
}

[data-theme="dark"] .preview-body table,
[data-theme="dark"] .preview-body td,
[data-theme="dark"] .preview-body th {
    border-color: var(--border-color) !important;
}

/* Compose editor in dark mode */
[data-theme="dark"] .compose-editor {
    color: var(--text-primary);
}

[data-theme="dark"] .compose-editor blockquote {
    border-left-color: var(--border-color);
    color: var(--text-muted);
}

/* Scrollbar for dark mode */
[data-theme="dark"] ::-webkit-scrollbar {
    width: 8px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 4px;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: #444;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

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

::-webkit-scrollbar-thumb {
    background: #c4c7cc;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8abb2;
}

/* ==========================================
   LAYOUT
   ========================================== */

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

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

.sidebar-header {
    height: var(--header-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--accent-blue), #8b5cf6);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 14px;
}

/* Accounts List */
.accounts-section {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.account-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background var(--transition-fast);
    position: relative;
}

.account-item:hover {
    background: var(--bg-hover);
}

.account-item.active {
    background: var(--bg-tertiary);
}

.account-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent-blue);
}

.account-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.account-indicator.has-unread {
    animation: pulse 2s infinite;
}

.account-drag-handle {
    flex-shrink: 0;
    color: var(--text-muted);
    opacity: 0;
    cursor: grab;
    padding: 2px;
    transition: opacity var(--transition-fast);
}

.account-drag-handle:active {
    cursor: grabbing;
}

.account-item:hover .account-drag-handle {
    opacity: 0.5;
}

.account-item.account-dragging {
    opacity: 0.3;
}

.account-item.account-drop-before {
    box-shadow: 0 -2px 0 0 var(--accent-blue);
}

.account-item.account-drop-after {
    box-shadow: 0 2px 0 0 var(--accent-blue);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.account-info {
    flex: 1;
    min-width: 0;
}

.account-label {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-email {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-badge {
    background: var(--accent-blue);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* Folders */
.folders-section {
    border-top: 1px solid var(--border-color);
    padding: 12px 0;
}

.folder-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px 8px 32px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

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

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

.folder-icon {
    width: 18px;
    height: 18px;
    opacity: 0.7;
}

.folder-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-count {
    font-size: 12px;
    color: var(--text-muted);
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    padding: 8px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.user-menu:hover {
    background: var(--bg-hover);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==========================================
   MAIN CONTENT
   ========================================== */

.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Message List Panel */
.message-list-panel {
    width: var(--message-list-width);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.message-list-header {
    height: var(--header-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.search-box {
    flex: 1;
    position: relative;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-icon {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

/* Message List */
.message-list {
    flex: 1;
    overflow-y: auto;
    contain: strict;
    will-change: scroll-position;
}

.message-item {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    border-left: 3px solid transparent;
    cursor: pointer;
    transition: background 0.1s ease;
    contain: layout style;
}

.message-item:hover {
    background: var(--bg-secondary);
}

.message-item.active {
    background: var(--bg-tertiary);
}

.message-item.unread {
    background: rgba(59, 130, 246, 0.08);
    border-left: 3px solid var(--accent-blue);
}

.message-item.unread .message-from {
    font-weight: 700;
    color: var(--text-primary);
}

.message-item.unread .message-subject {
    font-weight: 600;
    color: var(--text-primary);
}

.message-checkbox {
    flex-shrink: 0;
    padding-top: 2px;
}

.message-checkbox input {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent-blue);
}

.message-item.selected {
    background: color-mix(in srgb, var(--accent-blue) 8%, var(--bg-primary));
}

.message-item.selected:hover {
    background: color-mix(in srgb, var(--accent-blue) 12%, var(--bg-primary));
}

.btn-danger-icon {
    color: var(--accent-red, #EF4444);
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-danger-icon:hover {
    background: color-mix(in srgb, var(--accent-red, #EF4444) 12%, transparent);
}

.btn-danger-icon span {
    font-size: 11px;
    font-weight: 600;
}

.btn-warning-icon {
    color: #d97706;
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-warning-icon:hover {
    background: color-mix(in srgb, #d97706 12%, transparent);
}

.btn-warning-icon span {
    font-size: 11px;
    font-weight: 600;
}

.message-star {
    flex-shrink: 0;
    color: var(--text-muted);
    cursor: pointer;
    transition: color var(--transition-fast);
}

.message-star:hover,
.message-star.starred {
    color: var(--accent-yellow);
}

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

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.message-from {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-date {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--text-muted);
}

.message-subject {
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-snippet {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-attachment-icon {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 12px;
    margin-left: 8px;
}

/* ==========================================
   MESSAGE VIEW
   ========================================== */

.message-view-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.message-view-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.message-view-subject {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
}

.message-view-meta {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.sender-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    flex-shrink: 0;
}

.sender-info {
    flex: 1;
}

.sender-name {
    font-weight: 500;
}

.sender-email {
    font-size: 13px;
    color: var(--text-muted);
}

.message-recipients {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.message-view-date {
    color: var(--text-muted);
    font-size: 13px;
}

.message-view-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

/* Message Body */
.message-view-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.message-body-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 24px;
    max-width: 900px;
}

.message-body-content img {
    max-width: 100%;
    height: auto;
}

/* Attachments */
.message-attachments {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.attachments-header {
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.attachment-item:hover {
    background: var(--bg-hover);
}

.attachment-icon {
    width: 32px;
    height: 32px;
    background: var(--accent-blue);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.attachment-info {
    min-width: 0;
}

.attachment-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.attachment-size {
    font-size: 12px;
    color: var(--text-muted);
}

/* ==========================================
   COMPOSE
   ========================================== */

.compose-modal {
    position: fixed;
    bottom: 0;
    right: 24px;
    width: 600px;
    background: var(--bg-secondary);
    border-radius: 12px 12px 0 0;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    max-height: 80vh;
    overflow: hidden;
}

.compose-modal > .modal-header {
    flex-shrink: 0;
}

.compose-modal #compose-form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.compose-modal #compose-form > .form-row:not(.compose-body) {
    flex-shrink: 0;
}

.compose-modal .compose-body,
.compose-modal .form-row.compose-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: 0;
}

.compose-modal .compose-toolbar {
    flex-shrink: 0;
}

.compose-modal .compose-editor {
    flex: 1;
    overflow-y: auto;
    min-height: 100px;
}

.compose-modal .compose-attachments {
    flex-shrink: 0;
}

.compose-modal .modal-footer {
    flex-shrink: 0;
}

.compose-modal.minimized {
    height: 48px;
    overflow: hidden;
}

.compose-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: 12px 12px 0 0;
    cursor: pointer;
}

.compose-title {
    font-weight: 600;
}

.compose-controls {
    display: flex;
    gap: 8px;
}

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

.compose-field {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
}

.compose-field label {
    width: 60px;
    color: var(--text-muted);
    font-size: 13px;
}

.compose-field input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

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

.compose-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.tb-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 0;
}

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

.tb-sep {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    margin: 0 4px;
}

.tb-select {
    width: 72px;
    flex: none;
    height: 28px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 12px;
    padding: 0 4px;
    cursor: pointer;
}

.tb-color {
    width: 28px;
    height: 28px;
    flex: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px;
    cursor: pointer;
    background: var(--bg-primary);
}

.compose-editor {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    min-height: 200px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.6;
    outline: none;
}

.compose-editor:empty::before {
    content: 'Write your message...';
    color: var(--text-muted);
    pointer-events: none;
}

.compose-editor blockquote {
    border-left: 3px solid var(--border-color);
    padding-left: 12px;
    margin: 12px 0;
    color: var(--text-muted);
}

.compose-editor a {
    color: var(--accent-blue);
}

.compose-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
}

.compose-actions {
    display: flex;
    gap: 8px;
}

/* ==========================================
   BUTTONS
   ========================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--accent-blue-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

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

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 8px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

/* ==========================================
   EMPTY STATES
   ========================================== */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 48px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state-text {
    max-width: 400px;
}

/* ==========================================
   LOADING
   ========================================== */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Sync indicator */
.sync-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s;
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
}

.sync-indicator.visible {
    opacity: 1;
}

.sync-spinner {
    width: 12px;
    height: 12px;
    border: 1.5px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Ensure panel header is positioned for absolute child */
.messages-panel .panel-header {
    position: relative;
}

/* Current folder name - don't let it overlap buttons */
#current-folder-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Select all checkbox in header */
.select-all-checkbox {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 4px;
    margin-right: 8px;
    flex-shrink: 0;
}

.select-all-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent-blue);
}

/* Skeleton loading states */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

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

.message-item.skeleton {
    pointer-events: none;
}

.message-item.skeleton .skeleton-checkbox {
    width: 16px;
    height: 16px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    flex-shrink: 0;
}

.message-item.skeleton .skeleton-star {
    width: 14px;
    height: 14px;
    background: var(--bg-tertiary);
    border-radius: 50%;
    flex-shrink: 0;
}

.preview-skeleton {
    padding: 0;
}

.preview-skeleton .preview-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.preview-skeleton .preview-body {
    padding: 24px 20px;
}

/* ==========================================
   FORMS (Login, Account Setup)
   ========================================== */

.form-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    padding: 24px;
}

.form-container {
    width: 100%;
    max-width: 400px;
}

.form-header {
    text-align: center;
    margin-bottom: 32px;
}

.form-header .logo {
    justify-content: center;
    margin-bottom: 16px;
}

.form-header h1 {
    font-size: 24px;
    margin-bottom: 8px;
}

.form-header p {
    color: var(--text-secondary);
}

.form-card {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 32px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.form-group small {
    display: block;
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 12px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-section {
    margin-bottom: 32px;
}

.form-section h3 {
    font-size: 16px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.form-actions .btn {
    flex: 1;
}

/* Aliases */
.form-help {
    font-size: 12px;
    color: var(--text-muted);
    margin: -8px 0 12px;
}

.aliases-list {
    margin-bottom: 12px;
}

.alias-empty {
    font-size: 13px;
    color: var(--text-muted);
    padding: 8px 0;
}

.alias-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    margin-bottom: 6px;
}

.alias-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.alias-email {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

.alias-name {
    font-size: 11px;
    color: var(--text-muted);
}

.alias-remove-btn {
    flex-shrink: 0;
    color: var(--text-muted);
}

.alias-remove-btn:hover {
    color: #ef4444;
}

.alias-add-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.alias-input {
    flex: 1;
    padding: 7px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
}

.alias-input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #6ee7b7;
}

/* ==========================================
   DROPDOWN MENUS
   ========================================== */

.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    min-width: 180px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    display: none;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: var(--text-primary);
    text-decoration: none;
    transition: background var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--bg-hover);
}

.dropdown-item.danger {
    color: var(--accent-red);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* ==========================================
   UTILITIES
   ========================================== */

.hidden {
    display: none !important;
}

.text-muted {
    color: var(--text-muted);
}

.text-secondary {
    color: var(--text-secondary);
}

.text-danger {
    color: var(--accent-red);
}

.text-success {
    color: var(--accent-green);
}

.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 1200px) {
    .message-list-panel {
        width: 320px;
    }
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transition: left var(--transition-normal);
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .message-list-panel {
        width: 100%;
    }
    
    .message-view-panel {
        position: fixed;
        top: 0;
        left: 100%;
        right: 0;
        bottom: 0;
        z-index: 100;
        transition: left var(--transition-normal);
    }
    
    .message-view-panel.open {
        left: 0;
    }
}

/* ==========================================
   LOGIN SCREEN
   ========================================== */

.screen { height: 100vh; }
.screen.hidden { display: none; }

#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
}

.login-box {
    width: 100%;
    max-width: 380px;
    padding: 40px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

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

.login-brand svg {
    color: var(--accent-blue);
    margin-bottom: 12px;
}

.login-brand h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-full { width: 100%; }

.error-message {
    color: var(--accent-red);
    font-size: 13px;
    margin-top: 12px;
    text-align: center;
}

/* ==========================================
   MAIN APP LAYOUT (4-panel)
   ========================================== */

#main-screen {
    display: flex;
    flex-direction: column;
}

.app-header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
    flex-shrink: 0;
    overflow: hidden;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
}

.app-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    display: none;
}

.app-logo {
    height: 32px;
    max-height: 32px;
    max-width: 160px;
    width: auto;
    display: block;
    object-fit: contain;
}

.login-brand .app-logo {
    height: 48px;
    max-height: 48px;
    max-width: 240px;
    margin: 0 auto 12px;
}

.header-center {
    flex: 1;
    max-width: 480px;
    margin: 0 auto;
}

.search-box .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    z-index: 1;
}

.search-box input {
    width: 100%;
    padding: 8px 80px 8px 40px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 13px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

#user-name {
    font-size: 13px;
    color: var(--text-secondary);
}

.theme-toggle {
    position: relative;
    width: 44px;
    height: 24px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: background var(--transition-normal);
}

.theme-toggle-track {
    position: absolute;
    inset: 2px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
}

.theme-toggle-track svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.theme-toggle-sun {
    color: #f59e0b;
}

.theme-toggle-moon {
    color: #6366f1;
}

.theme-toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: transform var(--transition-normal);
}

[data-theme="dark"] .theme-toggle-knob {
    transform: translateX(20px);
    background: #374151;
}

[data-theme="dark"] .theme-toggle {
    background: var(--bg-hover);
}

.app-body {
    display: flex;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

/* Accounts sidebar */
.accounts-sidebar {
    width: 220px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}

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

.accounts-sidebar.collapsed {
    width: 0;
    overflow: hidden;
}

.sidebar-footer .icon-btn {
    opacity: 0.6;
    transition: opacity 0.15s;
}

.sidebar-footer .icon-btn:hover {
    opacity: 1;
}

.spam-mgr-tab {
    padding: 6px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.spam-mgr-tab.active {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
}

.spam-mgr-tab:hover:not(.active) {
    color: var(--text-primary);
}

.form-select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
}

.sidebar-header, .panel-header {
    padding: 0 16px;
    height: 44px;
    min-height: 44px;
    max-height: 44px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    box-sizing: border-box;
}

.account-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    gap: 10px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.account-item:hover { background: var(--bg-hover); }
.account-item.active { background: var(--bg-tertiary); }

.account-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.account-indicator.has-unread {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.account-info { flex: 1; min-width: 0; }

.account-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-email {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-badge {
    background: var(--accent-blue);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    flex-shrink: 0;
}

.account-edit-btn {
    opacity: 0;
    flex-shrink: 0;
    padding: 4px !important;
    transition: opacity var(--transition-fast);
}

.account-item:hover .account-edit-btn {
    opacity: 0.6;
}

.account-edit-btn:hover {
    opacity: 1 !important;
}

/* Folders panel */
.folders-panel {
    width: 180px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.folders-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.folder-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

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

.folder-icon { width: 16px; height: 16px; flex-shrink: 0; }

.folder-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.folder-count {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-blue);
}

.folder-actions {
    margin-top: auto;
    padding: 8px 16px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* Messages panel */
.messages-panel {
    width: 360px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    position: relative;
    z-index: 5;
}

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

.message-item {
    display: flex;
    align-items: flex-start;
    padding: 12px 16px;
    gap: 8px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
}

.message-item:hover { background: var(--bg-hover); }
.message-item.active { background: var(--bg-tertiary); }

.message-item.unread .message-from {
    font-weight: 700;
    color: var(--text-primary);
}

.message-item.unread .message-subject {
    font-weight: 600;
    color: var(--text-primary);
}

.message-star {
    padding: 2px;
    cursor: pointer;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-top: 2px;
}

.message-star.starred { color: var(--accent-yellow); }

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

.message-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.message-from {
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-date {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.message-subject {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.message-snippet {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.message-attachment {
    color: var(--text-muted);
    flex-shrink: 0;
    margin-top: 2px;
}

/* Drag and drop */
.message-item.dragging {
    opacity: 0.4;
}

.message-item[draggable="true"] {
    cursor: grab;
}

.message-item[draggable="true"]:active {
    cursor: grabbing;
}

.folder-item.drop-target {
    background: color-mix(in srgb, var(--accent-blue) 15%, var(--bg-primary));
    outline: 2px solid var(--accent-blue);
    outline-offset: -2px;
    border-radius: 4px;
}

.drag-ghost {
    position: fixed;
    top: -100px;
    left: -100px;
    background: var(--accent-blue);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10000;
}

/* Move modal */
.move-modal {
    max-width: 320px;
}

.move-folder-list {
    padding: 8px 0;
    max-height: 400px;
    overflow-y: auto;
}

.move-folder-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    transition: background var(--transition-fast);
}

.move-folder-item:hover {
    background: var(--bg-hover);
}

.move-folder-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-secondary);
}

/* Preview panel */
.preview-panel {
    flex: 1;
    min-width: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
}

.message-preview {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.preview-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.preview-subject {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.preview-meta {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.8;
}

.preview-meta strong { color: var(--text-muted); }

.preview-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.preview-attachments {
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    color: var(--accent-blue);
    text-decoration: none;
    font-size: 12px;
}

.attachment-link:hover { background: var(--bg-hover); }

.preview-body {
    padding: 24px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
}

.preview-body pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
}

.preview-body img { max-width: 100%; height: auto; }

/* ==========================================
   MODALS
   ========================================== */

.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden { display: none; }

.modal-backdrop {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.35);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.compose-modal { max-width: 640px; }
.modal-sm { max-width: 420px; }
.modal-sm .modal-body { padding: 20px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.close-btn:hover { color: var(--text-primary); }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

/* When footer has left and right groups */
.modal-footer:has(.modal-footer-right) {
    justify-content: space-between;
}

.modal-footer-right {
    display: flex;
    gap: 8px;
}

/* Form elements */
.form-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.form-section h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.form-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 20px;
}

.form-row label {
    width: 50px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    flex-shrink: 0;
}

.form-row > input,
.form-row > select {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
}

.form-row > input:focus,
.form-row > select:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.compose-body {
    align-items: stretch;
}

.compose-editor {
    min-height: 200px;
}

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
}

.form-group-sm { width: 100px; }

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
}

/* Settings sections */
.settings-section {
    margin-bottom: 24px;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 12px 0;
    padding: 0;
    border: none;
}

.settings-section .checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.settings-section .checkbox-label:last-of-type {
    margin-bottom: 0;
}

.settings-section .checkbox-label:hover {
    background: var(--bg-hover);
}

.settings-section .checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-blue);
    cursor: pointer;
}

.settings-section .checkbox-label span {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.settings-section p.text-muted {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0 0 12px 0;
    line-height: 1.5;
}

.settings-section p.text-muted:last-child {
    margin-bottom: 0;
}

.settings-section .btn {
    margin-top: 4px;
}

/* ==========================================
   BUTTONS
   ========================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
}

.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-primary:hover { background: var(--accent-blue-hover); }

.btn-danger { color: var(--accent-red); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.1); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

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

.icon-btn.active {
    background: color-mix(in srgb, var(--accent-blue) 15%, transparent);
    color: var(--accent-blue);
}

/* ==========================================
   STATES
   ========================================== */

.hidden { display: none !important; }

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

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

.empty-state-icon { margin-bottom: 16px; opacity: 0.4; }
.empty-state-title { font-size: 15px; font-weight: 500; margin-bottom: 4px; }
.empty-state-text { font-size: 13px; }

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: white;
    z-index: 10000;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
}

.toast-error { background: var(--accent-red); }
.toast-success { background: var(--accent-green); }
.toast-info { background: var(--accent-blue); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 1100px) {
    .messages-panel { width: 300px; }
    .folders-panel { width: 160px; }
}

/* ==========================================
   MOBILE (≤768px) — single-panel navigation
   ========================================== */

@media (max-width: 768px) {
    /* Header adjustments */
    .app-header { padding: 0 8px; }
    .app-title { display: none !important; }
    .header-center { display: none; }
    .header-right #user-name { display: none; }
    
    .app-logo {
        max-height: 28px;
        max-width: 120px;
    }

    .header-right {
        gap: 8px;
        margin-left: auto;
    }

    /* Make all panels full-screen and hidden by default */
    .app-body {
        position: relative;
    }

    .accounts-sidebar,
    .folders-panel,
    .messages-panel,
    .preview-panel {
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        width: 100% !important;
        border-right: none;
        z-index: 1;
        display: none;
    }

    /* Active panel is visible */
    .accounts-sidebar.mobile-active,
    .folders-panel.mobile-active,
    .messages-panel.mobile-active,
    .preview-panel.mobile-active {
        display: flex;
    }

    /* Override collapsed state on mobile */
    .accounts-sidebar.collapsed.mobile-active {
        width: 100% !important;
        overflow: visible;
        transform: none;
    }

    /* Mobile back buttons */
    .mobile-back-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        color: var(--accent-blue);
        cursor: pointer;
        padding: 4px;
        margin-right: 4px;
        flex-shrink: 0;
    }

    .mobile-back-btn svg {
        width: 20px;
        height: 20px;
    }

    /* Panel headers on mobile */
    .sidebar-header, .panel-header {
        padding: 0 12px;
    }

    /* Accounts panel tweaks */
    .account-item { padding: 14px 16px; }
    .account-edit-btn { opacity: 0.7; }
    .account-drag-handle { opacity: 0.4; }

    /* Folder items bigger touch targets */
    .folder-item { padding: 12px 16px; font-size: 14px; }

    /* Message items bigger touch targets */
    .message-item { padding: 14px 12px; }
    .message-from { font-size: 14px; }
    .message-subject { font-size: 14px; }
    .message-snippet { font-size: 13px; }

    /* Preview panel adjustments */
    .preview-header { padding: 16px; }
    .preview-subject { font-size: 18px; }
    .preview-body { padding: 16px; }
    .preview-actions { flex-wrap: wrap; gap: 6px; }
    .preview-actions .btn { flex: 1; min-width: 0; justify-content: center; }

    /* Compose modal full-screen on mobile */
    .compose-modal {
        right: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        top: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }

    .compose-editor {
        min-height: 150px;
    }

    .compose-toolbar {
        gap: 1px;
        padding: 4px 8px;
    }

    .tb-btn {
        width: 28px;
        height: 26px;
    }

    .tb-sep {
        margin: 0 2px;
    }

    /* Account modal full-screen on mobile */
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }

    /* Search bar for mobile — add to messages panel header */
    .mobile-search-bar {
        display: flex !important;
        padding: 8px 12px;
        border-bottom: 1px solid var(--border-color);
    }

    .mobile-search-bar input {
        width: 100%;
        padding: 8px 12px;
        border: 1px solid var(--border-color);
        border-radius: 6px;
        font-size: 14px;
        background: var(--bg-secondary);
        color: var(--text-primary);
    }

    /* Thread child indent smaller on mobile */
    .thread-child {
        padding-left: 24px !important;
        margin-left: 8px;
    }

    /* Context menu positioned better */
    .context-menu {
        max-width: calc(100vw - 32px);
    }

    /* Toast full-width on mobile */
    .toast {
        left: 16px !important;
        right: 16px !important;
        transform: none !important;
        max-width: none;
    }

    /* Hide desktop menu toggle, we handle navigation differently */
    #menu-toggle { display: none; }
}

/* Hide mobile elements on desktop */
@media (min-width: 769px) {
    .mobile-back-btn { display: none !important; }
    .mobile-search-bar { display: none !important; }
}

/* Provider Help */
.provider-help {
    background: var(--bg-tertiary);
    border: 1px solid var(--accent-blue);
    border-left: 3px solid var(--accent-blue);
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 12px;
    font-size: 13px;
    line-height: 1.5;
}

.provider-help-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    color: var(--accent-blue);
}

.provider-help-header strong {
    flex: 1;
}

.provider-help-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0 4px;
}

.provider-help-close:hover {
    color: var(--text-primary);
}

.provider-help-body ol,
.provider-help-body ul {
    margin: 0;
    padding-left: 20px;
}

.provider-help-body li {
    margin-bottom: 4px;
    color: var(--text-secondary);
}

.provider-help-body a {
    color: var(--accent-blue);
    text-decoration: underline;
}

.provider-help-body .help-note {
    margin-top: 8px;
    padding: 6px 10px;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-size: 12px;
    color: var(--text-muted);
}

/* Compose Attachments */
.compose-attachments {
    padding: 8px 20px;
    border-top: 1px solid var(--border-color);
}

.attachment-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all var(--transition-fast);
}

.attachment-add-btn:hover {
    color: var(--accent-blue);
    background: var(--bg-tertiary);
}

.attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 4px 10px;
    font-size: 12px;
    color: var(--text-secondary);
}

.attachment-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-size {
    color: var(--text-muted);
    font-size: 11px;
}

.attachment-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
    margin-left: 2px;
}

.attachment-remove:hover {
    color: var(--accent-red, #dc2626);
}

/* Thread View */
.thread-group {
    border-bottom: 1px solid var(--border-color);
}

.thread-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    gap: 8px;
    transition: background var(--transition-fast);
}

.thread-header:hover {
    background: var(--bg-hover);
}

.thread-expand-icon {
    flex-shrink: 0;
    color: var(--text-muted);
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thread-count {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    flex-shrink: 0;
    margin-left: 4px;
}

.thread-participants {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-header .message-subject.has-unread {
    font-weight: 600;
    color: var(--text-primary);
}

.thread-children {
    border-top: 1px solid var(--border-color);
}

.thread-child {
    padding-left: 36px !important;
    border-left: 2px solid var(--accent-blue);
    margin-left: 16px;
}

.thread-child + .thread-child {
    border-top: 1px solid var(--border-color);
}

#thread-toggle-btn.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

/* Context Menu */
.context-menu {
    position: fixed;
    z-index: 9999;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    padding: 4px 0;
    min-width: 160px;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    white-space: nowrap;
}

.context-menu-item:hover {
    background: var(--bg-hover);
}

/* Hidden folders */
.folder-item.folder-hidden {
    opacity: 0.45;
}

.folder-item.folder-hidden .folder-name {
    font-style: italic;
}

.folder-toggle-hidden {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    border-top: 1px solid var(--border-color);
    margin-top: 4px;
}

.folder-toggle-hidden:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

/* ==========================================
   SEARCH SCOPE BADGE
   ========================================== */

.search-scope-badge {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    padding: 3px 10px;
    border-radius: 10px;
    background: var(--accent-blue);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    border: none;
    line-height: 14px;
    transition: background 0.15s;
    z-index: 1;
}

.search-scope-badge:hover {
    background: var(--accent-blue-hover, #1d5bbf);
}

.search-result-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 500;
    white-space: nowrap;
    margin-left: 6px;
    flex-shrink: 0;
}

/* ==========================================
   DRAFT INDICATOR & DRAFTS PICKER
   ========================================== */

.modal-footer-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.draft-indicator {
    font-size: 11px;
    color: var(--success-color);
    opacity: 0;
    transition: opacity 0.3s;
}

.draft-indicator.visible {
    opacity: 1;
}

.drafts-picker {
    position: absolute;
    bottom: 60px;
    left: 16px;
    right: 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    z-index: 50;
    max-height: 300px;
    display: flex;
    flex-direction: column;
}

.drafts-picker-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.drafts-picker-list {
    overflow-y: auto;
    max-height: 240px;
}

.draft-item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.1s;
}

.draft-item:hover {
    background: var(--bg-hover);
}

.draft-item:last-child {
    border-bottom: none;
}

.draft-info {
    flex: 1;
    min-width: 0;
}

.draft-to {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.draft-subject {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.draft-date {
    font-size: 11px;
    color: var(--text-muted);
}

.draft-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    margin-left: 8px;
    line-height: 1;
}

.draft-delete-btn:hover {
    color: var(--danger-color);
}

/* ==========================================
   SPAM RULES
   ========================================== */

.spam-rules-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.spam-tab {
    padding: 6px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.spam-tab.active {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
}

.spam-tab:hover:not(.active) {
    color: var(--text-primary);
}

.spam-rules-list {
    max-height: 180px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.spam-rules-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.spam-rule-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

.spam-rule-item:last-child {
    border-bottom: none;
}

.spam-rule-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.spam-rule-value {
    flex: 1;
    color: var(--text-primary);
    font-weight: 500;
}

.spam-rule-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
}

.spam-rule-remove:hover {
    color: var(--danger-color);
}

.spam-rule-add-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.spam-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
}

/* Spam/Not Spam action buttons */
.btn-warning-outline {
    color: #d97706;
    border-color: #d9770640;
    background: #d9770610;
}

.btn-warning-outline:hover {
    background: #d9770620;
    border-color: #d97706;
}

.btn-success-outline {
    color: #059669;
    border-color: #05966940;
    background: #05966910;
}

.btn-success-outline:hover {
    background: #05966920;
    border-color: #059669;
}

/* ==========================================
   FILTERS MODAL
   ========================================== */

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

.filters-body {
    padding: 20px;
}

.filters-list {
    margin-bottom: 16px;
}

.filters-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 13px;
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 8px;
    transition: background 0.1s;
}

.filter-item:hover {
    background: var(--bg-hover);
}

.filter-item.filter-disabled {
    opacity: 0.5;
}

.filter-toggle {
    flex-shrink: 0;
}

.filter-info {
    flex: 1;
    min-width: 0;
}

.filter-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.filter-desc {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.filter-account {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.filter-actions-btns {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* Small toggle switch */
.switch-sm {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
}

.switch-sm input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider-sm {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--border-color);
    border-radius: 18px;
    transition: 0.2s;
}

.switch-slider-sm::before {
    content: '';
    position: absolute;
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: 0.2s;
}

.switch-sm input:checked + .switch-slider-sm {
    background: var(--accent-blue);
}

.switch-sm input:checked + .switch-slider-sm::before {
    transform: translateX(14px);
}

/* Filter editor form */
.filter-condition-row,
.filter-action-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

.filter-field,
.filter-operator,
.filter-action-type {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
}

.filter-field { width: 100px; }
.filter-operator { width: 110px; }
.filter-action-type { width: 150px; }

.filter-value,
.filter-action-value {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
}

.filter-action-value.hidden {
    display: none;
}

.filter-remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
}

.filter-remove-btn:hover {
    color: var(--danger-color);
}

.form-help-inline {
    font-weight: 400;
    font-size: 12px;
    color: var(--text-muted);
}

.folder-actions .btn {
    flex: 1;
    justify-content: center;
    font-size: 11px;
    gap: 4px;
}

/* ==========================================
   MOBILE OVERRIDES FOR NEW FEATURES
   ========================================== */

@media (max-width: 768px) {
    .search-scope-badge {
        padding: 1px 6px;
        font-size: 9px;
    }

    .filter-condition-row,
    .filter-action-row {
        flex-wrap: wrap;
    }

    .filter-field,
    .filter-operator,
    .filter-action-type {
        width: auto;
        flex: 1;
        min-width: 80px;
    }

    .spam-rule-add-row {
        flex-wrap: wrap;
    }

    .drafts-picker {
        left: 8px;
        right: 8px;
        bottom: 50px;
    }
}

/* ==========================================
   CONTACTS
   ========================================== */

.contacts-toolbar {
    margin-bottom: 16px;
}

.contacts-list {
    max-height: 400px;
    overflow-y: auto;
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
}

.contact-item:hover {
    background: var(--bg-hover);
}

.contact-item:last-child {
    border-bottom: none;
}

.contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-blue), #06b6d4);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-name {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-email {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

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

/* ==========================================
   AUTOCOMPLETE
   ========================================== */

.autocomplete-dropdown {
    position: fixed;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    z-index: 10000;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}

.autocomplete-dropdown.visible {
    display: block;
}

.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.1s;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: var(--bg-hover);
}

.autocomplete-name {
    font-weight: 500;
    color: var(--text-primary);
}

.autocomplete-email {
    font-size: 12px;
    color: var(--text-muted);
}

/* ==========================================
   HEADERS MODAL
   ========================================== */

.headers-content {
    max-height: 500px;
    overflow: auto;
}

.headers-pre {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 8px;
    margin: 0;
    color: var(--text-primary);
}

.modal-lg {
    max-width: 800px;
    width: 90%;
}

/* ==========================================
   LOAD MORE
   ========================================== */

.load-more-container {
    padding: 16px;
    text-align: center;
}

.load-more-btn {
    width: 100%;
    justify-content: center;
}

.loading-spinner-small {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
