/**
 * IDK Mail - Enhancement Styles
 * Multi-theme support, Skeleton loading, Email preview, Touch gestures, Pull to refresh
 *
 * @version 2.0.0
 */

/* ============== SKELETON LOADING FOR CLS FIX ============== */
.skeleton-row td {
    padding: 12px 15px;
}

.skeleton-box {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
    display: inline-block;
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

[data-theme="dark"] .skeleton-box {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
}

/* Hide skeleton when content loads */
.skeleton-row.hidden,
#emailList.loaded .skeleton-row {
    display: none !important;
}

/* ============== THEME TOGGLE BUTTON ============== */
.theme-toggle-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    background: var(--bg-light);
    border: 2px solid var(--border-color);
    font-size: 1.2em;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
}

.theme-toggle-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    transform: scale(1.1);
}

/* ============== THEME PICKER MODAL ============== */
.theme-picker-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.theme-picker-overlay.show {
    opacity: 1;
    visibility: visible;
}

.theme-picker-modal {
    background: var(--bg-white);
    border-radius: 20px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
}

.theme-picker-overlay.show .theme-picker-modal {
    transform: scale(1) translateY(0);
}

.theme-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.theme-picker-header h3 {
    margin: 0;
    font-size: 1.3em;
    color: var(--text-primary);
}

.theme-picker-close {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-light);
    border-radius: 50%;
    font-size: 1.2em;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-picker-close:hover {
    background: var(--danger-color, #ef4444);
    color: white;
    transform: rotate(90deg);
}

.theme-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
}

.theme-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 8px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-light);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-option:hover {
    border-color: var(--primary-color, #667eea);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-color);
}

.theme-option.active {
    border-color: var(--primary-color, #667eea);
    background: rgba(102, 126, 234, 0.1);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.theme-preview {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease;
}

.theme-option:hover .theme-preview {
    transform: scale(1.05);
}

.theme-icon {
    font-size: 1.8em;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.theme-name {
    font-size: 0.85em;
    font-weight: 500;
    color: var(--text-primary);
    text-align: center;
}

/* Mobile responsive */
@media (max-width: 480px) {
    .theme-picker-modal {
        padding: 16px;
        border-radius: 16px 16px 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        max-height: 70vh;
        transform: translateY(100%);
    }

    .theme-picker-overlay.show .theme-picker-modal {
        transform: translateY(0);
    }

    .theme-picker-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .theme-preview {
        width: 50px;
        height: 50px;
    }

    .theme-icon {
        font-size: 1.5em;
    }

    .theme-name {
        font-size: 0.75em;
    }
}

/* ============== SKELETON LOADING ============== */
.skeleton-row td {
    padding: 16px 15px;
}

.skeleton {
    background: linear-gradient(90deg,
        var(--bg-light) 25%,
        var(--bg-white) 50%,
        var(--bg-light) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
}

.skeleton-checkbox {
    width: 18px;
    height: 18px;
    border-radius: 4px;
}

.skeleton-text {
    height: 16px;
    border-radius: 4px;
}

.skeleton-text-small {
    height: 12px;
    border-radius: 3px;
    opacity: 0.6;
}

.skeleton-title {
    height: 24px;
    border-radius: 6px;
}

.skeleton-body {
    border-radius: 8px;
}

@keyframes skeleton-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Dark mode skeleton */
[data-theme="dark"] .skeleton {
    background: linear-gradient(90deg,
        #1e293b 25%,
        #334155 50%,
        #1e293b 75%
    );
    background-size: 200% 100%;
}

/* ============== EMAIL PREVIEW ============== */
.email-subject-line {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.email-preview-text {
    font-size: 0.85em;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

tr.unread .email-preview-text {
    color: var(--text-secondary);
}

tr:hover .email-preview-text {
    color: var(--text-secondary);
}

/* Hide preview on mobile for cleaner look */
@media (max-width: 480px) {
    .email-preview-text {
        display: none;
    }
}

/* ============== TOUCH GESTURES - SWIPE TO DELETE ============== */
#emailList tr {
    position: relative;
    background: var(--bg-white);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

#emailList tr::before {
    content: '🗑️ Xóa';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100px;
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9em;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: -1;
    border-radius: 0 8px 8px 0;
}

#emailList tr.swipe-delete::before {
    opacity: 1;
}

/* ============== PULL TO REFRESH ============== */
.pull-refresh-indicator {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-60px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 15px 25px;
    background: var(--bg-white);
    border-radius: 30px;
    box-shadow: 0 4px 20px var(--shadow-color);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    z-index: 100;
}

.pull-refresh-icon {
    font-size: 1.5em;
    transition: transform 0.3s ease;
}

.pull-refresh-indicator.ready .pull-refresh-icon {
    transform: rotate(180deg);
}

.pull-refresh-text {
    font-size: 0.85em;
    color: var(--text-secondary);
    font-weight: 500;
}

.pull-refresh-indicator.refreshing .pull-refresh-icon {
    animation: spin 1s linear infinite;
}

.spinner-small {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: inline-block;
}

/* ============== KEYBOARD NAVIGATION ============== */
#emailList tr.keyboard-focus {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    background: rgba(102, 126, 234, 0.1);
}

[data-theme="dark"] #emailList tr.keyboard-focus {
    background: rgba(102, 126, 234, 0.2);
}

/* ============== KEYBOARD SHORTCUTS HELP ============== */
.keyboard-help-content {
    max-width: 600px;
}

.shortcuts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-top: 15px;
}

.shortcut-group h4 {
    color: var(--primary);
    font-size: 0.9em;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
}

.shortcut {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 0.9em;
}

.shortcut kbd {
    min-width: 28px;
    text-align: center;
    padding: 4px 8px;
    font-family: monospace;
    font-size: 0.85em;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 2px 0 var(--border-color);
}

.shortcut span {
    color: var(--text-secondary);
}

/* ============== MORE OPTIONS MENU ============== */
.more-options-content {
    max-width: 350px;
    padding: 0;
    overflow: hidden;
}

.more-options-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
}

.more-options-header h3 {
    margin: 0;
    color: white;
}

.more-options-header .close-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.more-options-list {
    padding: 10px;
}

.option-item {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
    padding: 14px 16px;
    background: transparent;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    color: var(--text-primary);
    box-shadow: none;
}

.option-item:hover {
    background: var(--bg-light);
    transform: translateX(5px);
}

.option-icon {
    font-size: 1.3em;
    width: 30px;
    text-align: center;
}

.option-text {
    flex: 1;
    font-weight: 500;
}

.option-status {
    font-size: 0.75em;
    padding: 3px 8px;
    background: var(--primary);
    color: white;
    border-radius: 10px;
    font-weight: 600;
}

/* ============== STATS MODAL ============== */
.stats-content {
    max-width: 450px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-light);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    transition: transform 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
}

.stat-icon {
    font-size: 2em;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 2em;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

.stat-label {
    font-size: 0.85em;
    color: var(--text-muted);
    margin-top: 5px;
}

.stats-section {
    margin-top: 20px;
}

.stats-section h4 {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-bottom: 12px;
}

.top-senders {
    background: var(--bg-light);
    border-radius: 10px;
    overflow: hidden;
}

.sender-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
}

.sender-item:last-child {
    border-bottom: none;
}

.sender-rank {
    font-weight: 700;
    color: var(--primary);
    min-width: 30px;
}

.sender-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sender-count {
    background: var(--primary);
    color: white;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 0.85em;
    font-weight: 600;
}

/* ============== SETTINGS MODAL ============== */
.settings-content {
    max-width: 400px;
    padding: 0;
}

.settings-body {
    padding: 20px;
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 0;
    border-bottom: 1px solid var(--border-color);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-info {
    flex: 1;
}

.setting-label {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 3px;
}

.setting-desc {
    font-size: 0.85em;
    color: var(--text-muted);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--border-color);
    border-radius: 28px;
    transition: 0.3s;
}

.toggle-slider::before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

.settings-body select {
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.9em;
    cursor: pointer;
}

.setting-select {
    min-width: 140px;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.95em;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23667eea' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 35px;
}

.setting-select:hover {
    border-color: var(--primary-color, #667eea);
}

.setting-select:focus {
    outline: none;
    border-color: var(--primary-color, #667eea);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.settings-footer {
    padding: 15px 20px;
    background: var(--bg-light);
    border-top: 1px solid var(--border-color);
}

/* ============== FAVORITES MODAL ============== */
.favorites-content {
    max-width: 400px;
}

.favorites-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.favorites-list {
    max-height: 400px;
    overflow-y: auto;
}

.favorite-item {
    display: flex;
    flex-direction: column;
    padding: 12px 15px;
    background: var(--bg-light);
    border-radius: 10px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.favorite-item:hover {
    background: var(--table-row-hover);
    transform: translateX(5px);
}

.fav-sender {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.fav-subject {
    font-size: 0.9em;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fav-date {
    font-size: 0.8em;
    color: var(--text-muted);
    margin-top: 4px;
}

.no-favorites {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

/* ============== EMPTY STATE ENHANCEMENT ============== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-state-icon {
    font-size: 4em;
    margin-bottom: 15px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

.empty-state-title {
    font-size: 1.3em;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state-desc {
    color: var(--text-muted);
    font-size: 0.95em;
}

/* ============== RESPONSIVE ADJUSTMENTS ============== */
@media (max-width: 768px) {
    .shortcuts-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .more-options-content,
    .stats-content,
    .settings-content {
        max-width: 95%;
        margin: 10px;
    }
}

@media (max-width: 480px) {
    .theme-toggle-btn {
        width: 36px;
        height: 36px;
        font-size: 1em;
    }

    .stat-card {
        padding: 15px;
    }

    .stat-value {
        font-size: 1.5em;
    }

    .option-item {
        padding: 12px 14px;
    }
}

/* ============== DARK MODE SPECIFIC ============== */
[data-theme="dark"] .option-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .stat-card {
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .pull-refresh-indicator {
    background: var(--bg-white);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .favorite-item {
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .favorite-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* ============== PRINT STYLES ============== */
@media print {
    .theme-toggle-btn,
    .pull-refresh-indicator,
    .more-options-menu,
    .keyboard-help-modal,
    .stats-modal,
    .settings-modal {
        display: none !important;
    }
}


/* ============== ENHANCED EMPTY STATE v2.0 ============== */
.empty-icon-animated {
    position: relative;
    display: inline-block;
    margin-bottom: 20px;
}

.empty-icon-animated .mailbox-icon {
    font-size: 5em;
    display: block;
    animation: mailbox-bounce 2s ease-in-out infinite;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.15));
}

@keyframes mailbox-bounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1.02); }
}

.empty-icon-animated .waiting-dots {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
}

.empty-icon-animated .waiting-dots span {
    font-size: 2em;
    color: var(--primary, #667eea);
    animation: dot-pulse 1.4s ease-in-out infinite;
}

.empty-icon-animated .waiting-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.empty-icon-animated .waiting-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dot-pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1.2); }
}

/* Empty State Shortcuts Grid */
.empty-shortcuts {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin: 25px 0;
    padding: 20px;
    background: var(--bg-light, #f7f9fc);
    border-radius: 16px;
    border: 1px dashed var(--border-color, #e2e8f0);
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-white, #fff);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    cursor: default;
}

.shortcut-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.shortcut-item kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 0.9em;
    font-weight: 600;
    color: var(--primary, #667eea);
    background: linear-gradient(135deg, #f0f4ff, #e8ecff);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 8px;
    box-shadow: 0 2px 0 rgba(102, 126, 234, 0.2);
}

.shortcut-item span {
    font-size: 0.9em;
    color: var(--text-secondary, #4a5568);
    font-weight: 500;
}

/* Empty State Actions */
.empty-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin: 25px 0 20px;
}

.empty-cta {
    padding: 14px 28px !important;
    font-size: 1em !important;
    animation: cta-glow 2s ease-in-out infinite;
}

@keyframes cta-glow {
    0%, 100% { box-shadow: 0 4px 15px rgba(46, 204, 113, 0.3); }
    50% { box-shadow: 0 6px 25px rgba(46, 204, 113, 0.5); }
}

.empty-tip {
    font-size: 0.9em !important;
    color: var(--text-muted, #718096) !important;
    margin-top: 15px;
    padding: 12px 20px;
    background: rgba(102, 126, 234, 0.08);
    border-radius: 10px;
    display: inline-block;
}

.empty-tip strong {
    color: var(--primary, #667eea);
}

/* Dark mode adjustments */
[data-theme="dark"] .empty-shortcuts {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--border-color);
}

[data-theme="dark"] .shortcut-item {
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .shortcut-item kbd {
    background: linear-gradient(135deg, #2d3748, #374151);
    border-color: rgba(102, 126, 234, 0.4);
}

[data-theme="dark"] .empty-tip {
    background: rgba(102, 126, 234, 0.15);
}

/* Responsive */
@media (max-width: 480px) {
    .empty-icon-animated .mailbox-icon {
        font-size: 4em;
    }

    .empty-shortcuts {
        padding: 15px;
        gap: 8px;
    }

    .shortcut-item {
        padding: 8px 12px;
    }

    .shortcut-item kbd {
        min-width: 28px;
        height: 28px;
        font-size: 0.85em;
    }

    .shortcut-item span {
        font-size: 0.8em;
    }

    .empty-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .empty-cta {
        width: 100%;
    }
}

/* ============== DOMAIN TOOLTIP STYLES =======
olid var(--border-color, #e2e8f0);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    font-size: 0.85em;
    white-space: nowrap;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.domain-info-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--bg-white, #fff);
}

.input-group:has(#domainSelect:focus) .domain-info-tooltip,
.input-group:has(#domainSelect:hover) .domain-info-tooltip {
    opacity: 1;
    visibility: visible;
}

/* ============== AUTO-REFRESH INDICATOR ============== */
.auto-refresh-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border-radius: 20px;
    font-size: 0.75em;
    font-weight: 600;
    margin-left: 10px;
    animation: pulse-green 2s ease-in-out infinite;
}

@keyframes pulse-green {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.auto-refresh-indicator .countdown {
    font-family: monospace;
    min-width: 20px;
    text-align: center;
}

/* ============== SEARCH FILTER ENHANCEMENTS ============== */
.search-box {
    position: relative;
    margin-bottom: 15px;
}

.search-box input {
    width: 100%;
    padding: 14px 20px 14px 45px;
    border: 2px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
    font-size: 1em;
    background: var(--bg-input, #fff);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.search-box input:focus {
    border-color: var(--primary, #667eea);
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15);
    outline: none;
}

.search-box::before {
    content: '🔍';
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.1em;
    opacity: 0.6;
    pointer-events: none;
}

.search-results-count {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85em;
    color: var(--text-muted);
    background: var(--bg-light);
    padding: 4px 10px;
    border-radius: 15px;
}

/* ============== EMAIL PREVIEW IN LIST ============== */
.email-preview-snippet {
    display: block;
    font-size: 0.82em;
    color: var(--text-muted, #718096);
    margin-top: 6px;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

tr.unread .email-preview-snippet {
    color: var(--text-secondary);
}

tr:hover .email-preview-snippet {
    color: var(--text-secondary);
}

/* Hide on mobile */
@media (max-width: 600px) {
    .email-preview-snippet {
        display: none;
    }
}

/* ============== LOADING SCREEN (replaces JS warning) ============== */
.app-loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.app-loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-logo {
    font-size: 3em;
    font-weight: 800;
    margin-bottom: 20px;
    animation: logo-pulse 1.5s ease-in-out infinite;
}

.loading-logo .idk {
    color: white;
}

.loading-logo .mail {
    color: rgba(255, 255, 255, 0.8);
}

@keyframes logo-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.9; }
}

.loading-spinner-large {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1em;
    margin-top: 20px;
    font-weight: 500;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}


/* ============== MORE OPTIONS MENU BADGE ============== */
.menu-badge {
    display: inline-block;
    padding: 2px 8px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    font-size: 0.7em;
    font-weight: 700;
    border-radius: 10px;
    margin-left: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============== AUTO-REFRESH MODAL STYLES ============== */
.auto-refresh-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary, #667eea), var(--secondary, #764ba2));
    color: white;
    border-radius: 16px 16px 0 0;
}

.auto-refresh-modal .modal-header h3 {
    margin: 0;
    color: white;
}

.auto-refresh-modal .modal-body {
    padding: 20px;
}

.auto-refresh-modal .setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 0;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.auto-refresh-modal .setting-item:last-child {
    border-bottom: none;
}

.auto-refresh-modal .setting-info {
    flex: 1;
}

.auto-refresh-modal .setting-label {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.auto-refresh-modal .setting-desc {
    font-size: 0.85em;
    color: var(--text-muted);
}

/* ============== DOMAIN PREMIUM TOOLTIP ============== */
#domainSelect option[data-premium="true"]:hover::after {
    content: attr(title);
}

/* Custom tooltip for domain select */
.domain-select-wrapper {
    position: relative;
    display: inline-block;
}

.domain-tooltip {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 12px;
    background: var(--bg-white, #fff);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.85em;
    white-space: nowrap;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 1000;
}

.domain-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--bg-white, #fff);
}

.domain-select-wrapper:hover .domain-tooltip,
.domain-select-wrapper:focus-within .domain-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Premium domain highlight in dropdown */
#domainSelect option[data-premium="true"] {
    background: linear-gradient(90deg, #fef9c3, #fef08a) !important;
    color: #854d0e;
    font-weight: 500;
}

[data-theme="dark"] #domainSelect option[data-premium="true"] {
    background: linear-gradient(90deg, #422006, #713f12) !important;
    color: #fef08a;
}


/* ============== SECURITY INFO BANNER ============== */
.security-info-banner {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.1), rgba(245, 158, 11, 0.1));
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 12px;
    font-size: 0.9em;
}

.security-info-banner .info-item {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 250px;
}

.security-info-banner .info-icon {
    font-size: 1.2em;
    flex-shrink: 0;
}

.security-info-banner .info-text {
    color: var(--text-secondary, #4a5568);
    line-height: 1.4;
}

.security-info-banner .info-text strong {
    color: var(--primary, #667eea);
    font-weight: 600;
}

.security-info-banner .security-warning .info-text {
    color: #92400e;
}

[data-theme="dark"] .security-info-banner {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(245, 158, 11, 0.1));
    border-color: rgba(245, 158, 11, 0.4);
}

[data-theme="dark"] .security-info-banner .security-warning .info-text {
    color: #fbbf24;
}

[data-theme="dark"] .security-info-banner .info-text {
    color: var(--text-secondary);
}

@media (max-width: 600px) {
    .security-info-banner {
        flex-direction: column;
        gap: 10px;
        padding: 10px 14px;
        font-size: 0.85em;
    }

    .security-info-banner .info-item {
        min-width: auto;
    }
}

/* ============== EMAIL PREVIEW ON HOVER ============== */
.email-row {
    position: relative;
}

.email-preview-tooltip {
    display: none; /* Ẩn tooltip - dùng preview snippet thay thế */
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translateX(-50%);
    width: 350px;
    max-width: 90vw;
    padding: 16px;
    background: var(--bg-white, #fff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
}

.email-preview-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 8px solid transparent;
    border-top-color: var(--bg-white, #fff);
}

.email-row:hover .email-preview-tooltip,
.email-row:focus-within .email-preview-tooltip {
    opacity: 1;
    visibility: visible;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.preview-sender {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95em;
}

.preview-date {
    font-size: 0.8em;
    color: var(--text-muted, #718096);
}

.preview-subject {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 0.9em;
}

.preview-body {
    font-size: 0.85em;
    color: var(--text-secondary, #4a5568);
    line-height: 1.5;
    max-height: 100px;
    overflow: hidden;
    position: relative;
}

.preview-body::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    background: linear-gradient(transparent, var(--bg-white, #fff));
}

.preview-attachments {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color, #e2e8f0);
    font-size: 0.8em;
    color: var(--text-muted);
}

.preview-loading {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
}

/* Dark mode */
[data-theme="dark"] .email-preview-tooltip {
    background: var(--bg-white, #1e293b);
    border-color: var(--border-color, #475569);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .email-preview-tooltip::after {
    border-top-color: var(--bg-white, #1e293b);
}

[data-theme="dark"] .preview-body::after {
    background: linear-gradient(transparent, var(--bg-white, #1e293b));
}

/* Disable preview on touch devices */
@media (hover: none) {
    .email-preview-tooltip {
        display: none !important;
    }
}

/* Position adjustment for rows near bottom */
.email-row.preview-above .email-preview-tooltip {
    bottom: auto;
    top: calc(100% + 10px);
}

.email-row.preview-above .email-preview-tooltip::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: var(--bg-white, #fff);
}

[data-theme="dark"] .email-row.preview-above .email-preview-tooltip::after {
    border-bottom-color: var(--bg-white, #1e293b);
}

/* ============== ENHANCED SEARCH WITH RESULTS COUNT ============== */
.search-box {
    position: relative;
    margin-bottom: 15px;
}

.search-results-info {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8em;
    color: var(--text-muted);
    background: var(--bg-light);
    padding: 4px 10px;
    border-radius: 12px;
    pointer-events: none;
}

.search-results-info.has-results {
    color: var(--primary, #667eea);
    background: rgba(102, 126, 234, 0.1);
}

.search-results-info.no-results {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}


/* ============== EMAIL HISTORY MODAL ============== */
.history-modal .modal-content {
    max-width: 450px;
}

.history-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary, #667eea), var(--secondary, #764ba2));
    color: white;
    border-radius: 16px 16px 0 0;
}

.history-modal .modal-header h3 {
    margin: 0;
    color: white;
}

.history-body {
    padding: 0;
    max-height: 400px;
    overflow-y: auto;
}

.empty-history {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-history .empty-icon {
    font-size: 3em;
    display: block;
    margin-bottom: 10px;
}

.history-list {
    padding: 10px;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    margin-bottom: 8px;
    background: var(--bg-light, #f7f9fc);
    border-radius: 10px;
    transition: all 0.2s ease;
}

.history-item:hover {
    background: var(--table-row-hover, #e2e8f0);
}

.history-info {
    flex: 1;
    cursor: pointer;
    overflow: hidden;
}

.history-email {
    display: block;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-date {
    font-size: 0.8em;
    color: var(--text-muted);
}

.history-actions {
    display: flex;
    gap: 5px;
}

.history-actions .icon-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-actions .icon-btn:hover {
    background: var(--bg-white, #fff);
}

.history-actions .icon-btn.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.history-footer {
    padding: 15px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626) !important;
}

/* ============== EMAIL FORWARDING MODAL ============== */
.forwarding-modal .modal-content {
    max-width: 480px;
}

.forwarding-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border-radius: 16px 16px 0 0;
}

.forwarding-modal .modal-header h3 {
    margin: 0;
    color: white;
}

.forwarding-body {
    padding: 20px;
}

.forwarding-info {
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 10px;
}

.forwarding-info p {
    margin: 0 0 8px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

.forwarding-info p:last-child {
    margin-bottom: 0;
}

.forwarding-info .warning-text {
    color: #92400e;
    font-size: 0.85em;
}

[data-theme="dark"] .forwarding-info .warning-text {
    color: #fbbf24;
}

.forwarding-form .form-field {
    margin-bottom: 15px;
}

.forwarding-form label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9em;
}

.forwarding-form input[type="text"],
.forwarding-form input[type="email"] {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 1em;
    background: var(--bg-input, #fff);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.forwarding-form input:focus {
    border-color: var(--primary, #667eea);
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.forwarding-form input[readonly] {
    background: var(--bg-light, #f7f9fc);
    cursor: not-allowed;
}

.forwarding-form .checkbox-field {
    display: flex;
    align-items: center;
}

.forwarding-form .checkbox-field label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    margin-bottom: 0;
}

.forwarding-form .checkbox-field input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.forwarding-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.forwarding-actions .action-btn {
    flex: 1;
}

/* ============== PERFORMANCE OPTIMIZATIONS ============== */
/* Reduce paint areas */
.email-row {
    contain: layout style;
}

/* GPU acceleration for animations */
.modal-overlay,
.notification,
.more-options-menu {
    will-change: opacity, transform;
}

/* Optimize font rendering */
body {
    text-rendering: optimizeSpeed;
}

/* Reduce reflows */
.email-preview-tooltip {
    contain: layout style paint;
}

/* Lazy load images below fold */
img[loading="lazy"] {
    content-visibility: auto;
}

/* ============== ATTACHMENT IMPROVEMENTS ============== */
.attachment-list {
    margin-top: 15px;
    padding: 15px;
    background: var(--bg-light, #f7f9fc);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.attachment-list h3 {
    margin: 0 0 12px;
    font-size: 1em;
    color: var(--text-primary);
}

.attachment-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--bg-white, #fff);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.attachment-item:last-child {
    margin-bottom: 0;
}

.attachment-item:hover {
    border-color: var(--primary, #667eea);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15);
}

.attachment-item span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9em;
    color: var(--text-primary);
}

.attachment-item .download-btn {
    padding: 6px 12px;
    font-size: 0.85em;
    flex-shrink: 0;
    margin-left: 10px;
}

/* File type icons */
.attachment-item[data-type="image"] span::before { content: '🖼️ '; }
.attachment-item[data-type="pdf"] span::before { content: '📕 '; }
.attachment-item[data-type="doc"] span::before { content: '📄 '; }
.attachment-item[data-type="zip"] span::before { content: '📦 '; }

/* Attachment size limit warning */
.attachment-size-warning {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 15px;
    margin-top: 10px;
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 8px;
    font-size: 0.85em;
    color: #92400e;
}

[data-theme="dark"] .attachment-size-warning {
    color: #fbbf24;
}
