/**
 * Gmail-Style Email History UI for AI Sales SDR v3
 */

/* Email History Container */
.email-history-tab {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: hidden;
    height: 100%;
}

.email-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: linear-gradient(135deg, #a4c3b2, #6b8b75);
    color: white;
    border-bottom: 1px solid rgba(255,255,255,0.2);
}

.email-history-title {
    margin: 0;
    font-size: 1.3em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.email-history-title::before {
    content: "📧";
    font-size: 1.1em;
}

.email-history-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.refresh-toggle, .export-button, .compose-button, .manual-refresh {
    padding: 6px 12px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 20px;
    color: white;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.refresh-toggle:hover, .export-button:hover, .compose-button:hover, .manual-refresh:hover {
    background: rgba(255,255,255,0.25);
    transform: translateY(-1px);
}

/* Gmail-Style Inbox Container */
.inbox-container {
    height: calc(100vh - 250px);
    max-height: 650px;
    min-height: 400px;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    border-radius: 0 0 8px 8px;
}

.inbox-header {
    padding: 12px 16px;
    background: #fff;
    border-bottom: 1px solid #e1e5e9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9em;
    color: #5f6368;
}

.inbox-stats {
    display: flex;
    gap: 20px;
    align-items: center;
}

.inbox-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.inbox-stat .count {
    color: #1a73e8;
    font-weight: 600;
}

/* Email List */
.email-list {
    flex: 1;
    overflow-y: auto;
    background: #fff;
}

.email-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    border-bottom: 1px solid #f1f3f4;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

.email-item:hover {
    background: #f8f9fa;
    box-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0;
    transform: translateX(2px);
}

.email-item.selected {
    background: #e8f0fe;
    border-left: 3px solid #1a73e8;
}

.email-item.unread {
    background: #fff;
    font-weight: 600;
}

.email-item.unread::before {
    content: "";
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 4px;
    background: #1a73e8;
    border-radius: 50%;
}

/* Direction Indicator */
.direction-indicator {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8em;
    font-weight: 600;
    margin-right: 12px;
    flex-shrink: 0;
}

.direction-indicator.outbound {
    background: linear-gradient(135deg, #a4c3b2, #6b8b75);
    color: white;
}

.direction-indicator.inbound {
    background: linear-gradient(135deg, #74b9ff, #0984e3);
    color: white;
}

.direction-indicator.outbound::after {
    content: "📤";
}

.direction-indicator.inbound::after {
    content: "📥";
}

/* Email Content Preview */
.email-preview {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.email-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.email-from {
    font-weight: 600;
    color: #202124;
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.email-time {
    font-size: 0.8em;
    color: #5f6368;
    white-space: nowrap;
    margin-left: 8px;
}

.email-subject {
    font-size: 0.9em;
    color: #202124;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-snippet {
    font-size: 0.8em;
    color: #5f6368;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Tracking Status Indicators */
.tracking-indicators {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    flex-shrink: 0;
}

.tracking-icon {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7em;
}

.tracking-icon.delivered {
    background: #34a853;
    color: white;
}

.tracking-icon.opened {
    background: #fbbc04;
    color: white;
}

.tracking-icon.clicked {
    background: #4285f4;
    color: white;
}

.tracking-icon.replied {
    background: #ea4335;
    color: white;
}

/* Email Overlay Modal */
.email-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.email-overlay.show {
    display: flex;
}

.email-modal {
    background: white;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.email-modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e1e5e9;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: #f8f9fa;
}

.email-modal-info {
    flex: 1;
}

.email-modal-subject {
    font-size: 1.3em;
    font-weight: 600;
    color: #202124;
    margin: 0 0 8px 0;
    line-height: 1.3;
}

.email-modal-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.9em;
    color: #5f6368;
}

.email-modal-meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.email-modal-meta-label {
    font-weight: 500;
    min-width: 50px;
}

.email-modal-close {
    background: none;
    border: none;
    font-size: 1.5em;
    color: #5f6368;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.email-modal-close:hover {
    background: #f1f3f4;
}

.email-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.email-content {
    line-height: 1.6;
    color: #202124;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.95em;
}

.email-modal-tracking {
    padding: 16px 24px;
    border-top: 1px solid #e1e5e9;
    background: #f8f9fa;
}

.tracking-title {
    font-size: 0.9em;
    font-weight: 600;
    color: #5f6368;
    margin-bottom: 8px;
}

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

.tracking-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: 500;
}

.tracking-item.delivered {
    background: #e8f5e8;
    color: #137333;
}

.tracking-item.opened {
    background: #fef7e0;
    color: #b06000;
}

.tracking-item.clicked {
    background: #e8f0fe;
    color: #1565c0;
}

.tracking-item.replied {
    background: #fce8e6;
    color: #c5221f;
}

/* Loading State */
.loading-state {
    text-align: center;
    padding: 80px 20px;
    color: #5f6368;
}

.loading-spinner {
    font-size: 4em;
    margin-bottom: 16px;
    opacity: 0.8;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.8;
        transform: scale(1);
    }
    50% {
        opacity: 0.4;
        transform: scale(1.1);
    }
}

.loading-state h3 {
    margin: 0 0 8px 0;
    color: #202124;
    font-weight: 500;
}

.loading-state p {
    margin: 0;
    font-size: 0.9em;
    color: #5f6368;
}

/* No Messages State */
.no-messages {
    text-align: center;
    padding: 80px 20px;
    color: #5f6368;
}

.no-messages-icon {
    font-size: 4em;
    margin-bottom: 16px;
    opacity: 0.6;
}

.no-messages h3 {
    margin: 0 0 8px 0;
    color: #202124;
    font-weight: 500;
}

.no-messages p {
    margin: 0;
    font-size: 0.9em;
    color: #5f6368;
}

/* Error State */
.error-message {
    text-align: center;
    padding: 60px 20px;
    color: #ea4335;
}

.error-icon {
    font-size: 3em;
    margin-bottom: 16px;
    opacity: 0.8;
}

.error-message h3 {
    margin: 0 0 8px 0;
    color: #ea4335;
    font-weight: 500;
}

.error-message p {
    margin: 0 0 16px 0;
    color: #5f6368;
    font-size: 0.9em;
}

.retry-button {
    padding: 10px 20px;
    background: #ea4335;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.2s ease;
}

.retry-button:hover {
    background: #d33b2c;
}

/* Responsive Design */
@media (max-width: 768px) {
    .email-history-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
        padding: 12px 16px;
    }

    .email-history-controls {
        flex-wrap: wrap;
        width: 100%;
        gap: 6px;
    }

    .inbox-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    .email-item {
        padding: 12px 16px;
    }

    .email-from {
        max-width: 150px;
    }

    .email-modal {
        margin: 10px;
        max-width: calc(100% - 20px);
        max-height: calc(100vh - 20px);
    }

    .email-modal-header {
        padding: 16px 20px;
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    .email-modal-close {
        position: absolute;
        right: 16px;
        top: 16px;
    }

    .email-modal-body {
        padding: 20px;
    }

    .tracking-list {
        gap: 8px;
    }
}

/* Scrollbar Styling */
.email-list::-webkit-scrollbar,
.email-modal-body::-webkit-scrollbar {
    width: 6px;
}

.email-list::-webkit-scrollbar-track,
.email-modal-body::-webkit-scrollbar-track {
    background: #f1f3f4;
    border-radius: 3px;
}

.email-list::-webkit-scrollbar-thumb,
.email-modal-body::-webkit-scrollbar-thumb {
    background: #dadce0;
    border-radius: 3px;
}

.email-list::-webkit-scrollbar-thumb:hover,
.email-modal-body::-webkit-scrollbar-thumb:hover {
    background: #bdc1c6;
}

/* Animation for smooth interactions */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.email-overlay.show .email-modal {
    animation: fadeIn 0.2s ease-out;
}

/* Sync notification styles */
.sync-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    animation: slideInRight 0.3s ease-out, fadeOut 0.3s ease-in 2.7s forwards;
}

.sync-notification-content {
    background: #4caf50;
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
    font-weight: 500;
    white-space: nowrap;
}

.sync-icon {
    font-size: 1.2em;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}