/* CSS Custom Properties (Design Tokens) for Email View */
:root {
    /* Email Colors */
    --email-primary-blue: #1976d2;
    --email-primary-blue-light: #1565c0;
    --email-primary-blue-dark: #0d47a1;
    --email-background-white: #fff;
    --email-background-light: #f5f5f5;
    --email-background-lighter: #fafafa;
    --email-background-blue-light: #e3f0fc;
    --email-background-blue-lighter: #d0e6fa;
    --email-border-gray: #e0e0e0;
    --email-text-muted: #494949;
    --email-background-error: #f8d7da;
    
    /* Email Spacing */
    --email-spacing-xs: 5px;
    --email-spacing-sm: 10px;
    --email-spacing-md: 15px;
    --email-spacing-lg: 20px;
    --email-spacing-xl: 40px;
    
    /* Email Layout */
    --email-border-radius: 8px;
    --email-max-width: 700px;
    --email-transition-duration: 0.2s;
    --email-avatar-size: 40px;
    
    /* Performance Optimizations */
    --email-box-shadow-light: 0 2px 4px rgba(0, 0, 0, 0.03);
    --email-box-shadow-medium: 0 2px 8px rgba(0,0,0,0.06);
    --email-box-shadow-blue: 0 2px 8px rgba(33, 150, 243, 0.10);
}

/* Outlook-style Email View Styling */

.email-outlook-view {
    background-color: var(--email-background-light);
    padding: 0;
}

.email-message-container {
    background: var(--email-background-white);
    border: 1px solid var(--email-border-gray);
    border-radius: var(--email-border-radius);
    margin-bottom: var(--email-spacing-lg);
    box-shadow: var(--email-box-shadow-light);
    padding: var(--email-spacing-lg);
    max-width: var(--email-max-width);
    margin-left: auto;
    margin-right: auto;
    overflow: hidden;
    transition: all var(--email-transition-duration) ease;
}

/* Outlook-style Action Buttons Bar - Keep for Reply/Forward */
.email-actions-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: var(--email-spacing-sm) var(--email-spacing-md);
    background-color: var(--email-background-lighter);
    border-bottom: 1px solid var(--email-border-gray);
    gap: var(--email-spacing-sm);
}

.email-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    margin: 0;
    border: none;
    background-color: transparent;
    color: var(--email-primary-blue);
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    border-radius: 2px;
    transition: background-color 0.2s ease;
    text-transform: none;
    height: auto;
    line-height: normal;
}

.email-action-btn:hover {
    background-color: #edebe9;
}

.email-action-btn:active {
    background-color: #e1dfdd;
}

.email-action-btn i {
    font-size: 18px;
    width: 18px;
    height: 18px;
    line-height: 18px;
}

.email-action-label {
    font-size: 14px;
    line-height: 18px;
}

.email-reply-btn {
    color: var(--email-primary-blue);
}

.email-reply-btn:hover {
    background-color: var(--email-background-blue-light);
}

.email-forward-btn {
    color: var(--email-primary-blue);
}

.email-forward-btn:hover {
    background-color: var(--email-background-blue-light);
}

.email-delete-btn {
    color: #d13438;
}

.email-delete-btn:hover {
    background-color: var(--email-background-error);
}

/* Delete button overlay icon */
.delete-mail-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
    cursor: pointer;
    background: var(--email-background-white);
    border-radius: 50%;
    padding: 4px;
    transition: background 0.15s ease;
}

.delete-mail-icon:hover {
    background: var(--email-background-error);
}

/* Email Action Buttons Container (Reply, Reply All, Forward, Delete) */
.email-action-buttons {
    position: absolute;
    top: var(--email-spacing-sm);
    right: var(--email-spacing-sm);
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 10;
    background-color: var(--email-background-white);
    padding: 4px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.email-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    margin: 0;
    border: none;
    background-color: transparent;
    color: var(--email-primary-blue);
    font-size: 13px;
    font-weight: 400;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    text-transform: none;
    height: auto;
    line-height: normal;
    white-space: nowrap;
}

.email-action-btn:hover {
    background-color: #edebe9;
}

.email-action-btn:active {
    background-color: #e1dfdd;
}

.email-action-btn i {
    font-size: 18px;
    width: 18px;
    height: 18px;
    line-height: 18px;
    color: var(--email-primary-blue);
}

.email-action-btn-delete {
    color: var(--email-primary-blue);
}

.email-action-btn-delete:hover {
    background-color: #ffebee;
    color: var(--email-primary-blue);
}

.email-action-btn-delete i {
    color: var(--email-primary-blue);
}

/* Responsive: Hide text on smaller screens, show only icons */
@media (max-width: 768px) {
    .email-action-btn span {
        display: none;
    }
    
    .email-action-btn {
        padding: 6px;
        min-width: 32px;
        justify-content: center;
    }
}

/* Email Reply Compose Area */
.email-reply-compose {
    margin-top: var(--email-spacing-md);
    border-top: 1px solid var(--email-border-gray);
    background-color: var(--email-background-white);
    border-radius: 0 0 var(--email-border-radius) var(--email-border-radius);
    padding: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.email-reply-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: var(--email-spacing-xs) var(--email-spacing-sm);
    border-bottom: 1px solid var(--email-border-gray);
    background-color: var(--email-background-lighter);
}

.email-reply-header-left {
    display: flex;
    align-items: center;
    gap: 4px;
}

.email-reply-action-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    color: #605e5c;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.email-reply-action-btn:hover {
    background-color: #edebe9;
    color: #323130;
}

.email-reply-action-btn:focus {
    background-color: #edebe9;
    outline: none;
}

.email-reply-action-btn i {
    font-size: 20px;
}

.email-reply-discard:hover {
    background-color: #edebe9;
    color: #323130;
}

.email-reply-discard i {
    color: #605e5c;
}

.email-reply-discard:hover i {
    color: #323130;
}

.email-reply-discard:focus {
    background-color: #edebe9;
    outline: none;
}

.email-reply-discard:focus i {
    color: #323130;
}

.email-reply-fields {
    padding: var(--email-spacing-sm) var(--email-spacing-md);
    border-bottom: 1px solid var(--email-border-gray);
    background-color: var(--email-background-white);
}

.email-reply-field-row {
    display: flex;
    align-items: center;
    margin-bottom: var(--email-spacing-xs);
    font-size: 14px;
    line-height: 1.5;
}

.email-reply-field-row:last-child {
    margin-bottom: 0;
}

.email-reply-field-label {
    color: var(--email-text-muted);
    font-weight: 500;
    min-width: 50px;
    margin-right: var(--email-spacing-sm);
    flex-shrink: 0;
}

.email-reply-field-value {
    color: #323130;
    flex: 1;
    word-break: break-word;
}

.email-reply-body {
    padding: var(--email-spacing-md);
    background-color: var(--email-background-white);
}

.email-reply-textarea {
    width: 100%;
    min-height: 200px;
    padding: var(--email-spacing-sm);
    border: none;
    border-radius: 0;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    box-sizing: border-box;
    transition: none;
    background-color: var(--email-background-white);
    color: #323130;
    line-height: 1.5;
}

.email-reply-textarea:focus {
    outline: none;
    border: none;
    box-shadow: none;
}

.email-reply-footer {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: var(--email-spacing-sm) var(--email-spacing-md);
    border-top: 1px solid var(--email-border-gray);
    background-color: var(--email-background-lighter);
}

.email-reply-send-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background-color: var(--email-primary-blue);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
    text-transform: none;
}

.email-reply-send-btn:hover:not(:disabled) {
    background-color: var(--email-primary-blue-light);
}

.email-reply-send-btn:active:not(:disabled) {
    background-color: var(--email-primary-blue-dark);
}

.email-reply-send-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

.email-reply-send-btn i {
    font-size: 18px;
    width: 18px;
    height: 18px;
    line-height: 18px;
}

/* Outlook-style Email Header */
.outlook-mail-card {
    background: var(--email-background-white);
    border: 1px solid var(--email-border-gray);
    border-radius: var(--email-border-radius);
    margin-bottom: var(--email-spacing-lg);
    box-shadow: var(--email-box-shadow-light);
    padding: var(--email-spacing-lg);
    max-width: var(--email-max-width);
    margin-left: auto;
    margin-right: auto;
    position: relative;
}

.outlook-mail-header {
    display: flex;
    align-items: center;
    margin-bottom: var(--email-spacing-sm);
}

.avatar {
    width: var(--email-avatar-size);
    height: var(--email-avatar-size);
    flex-shrink: 0;
}

.avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.avatar.collapsed,
.avatar.collapsed img {
    width: 28px;
    height: 28px;
}

.mail-info {
    margin-left: var(--email-spacing-md);
    flex: 1;
    cursor: pointer;
}

.mail-info.collapsed {
    font-size: 12px;
    padding: 2px 8px;
}

.sender-name {
    font-weight: bold;
    margin-right: var(--email-spacing-sm);
}

.to-label,
.from-label {
    color: var(--email-text-muted);
    margin-right: var(--email-spacing-xs);
}


.cc-label,
.bcc-label {
    font-size: 12px;
}

.cc-name,
.bcc-name {
    font-size: 12px;
}

.mail-date {
    color: var(--email-text-muted);
    font-size: 12px;
    margin-top: 2px;
    text-align: right;
}

.mail-date.collapsed {
    font-size: 11px;
    padding: 0 4px;
}

.outlook-mail-subject {
    font-size: 18px;
    font-weight: 500;
    margin-bottom: var(--email-spacing-sm);
    line-height: 1.6;
}

.email-header {
    background-color: var(--email-background-white);
    border-bottom: 1px solid var(--email-border-gray);
}

.email-header-fields {
    padding: var(--email-spacing-md);
}

.email-header-row {
    display: flex;
    align-items: flex-start;
    margin-bottom: 12px;
    line-height: 1.5;
}

.email-header-row:last-child {
    margin-bottom: 0;
}

.email-header-label {
    font-weight: 600;
    color: #323130;
    min-width: 80px;
    font-size: 14px;
    margin-right: var(--email-spacing-sm);
    flex-shrink: 0;
}

.email-header-value {
    color: #323130;
    font-size: 14px;
    word-break: break-word;
    flex: 1;
}

.email-subject {
    font-weight: 600;
    font-size: 16px;
    color: #201f1e;
}

.outlook-mail-body {
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-line;
}

/* HTML email body - override white-space to allow proper HTML rendering */
.outlook-mail-body-html {
    white-space: normal;
}

/* Email Body */
.email-body {
    padding: var(--email-spacing-md);
    background-color: var(--email-background-white);
}

.outlook-mail-attachments {
    margin-top: var(--email-spacing-sm);
}

.attachment-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: var(--email-spacing-sm);
}

.attachment-card {
    position: relative;
    width: 160px;
    height: 160px;
    margin: 8px;
    border-radius: 12px;
    box-shadow: var(--email-box-shadow-medium);
    background: var(--email-background-lighter);
    overflow: hidden;
}

.attachment-thumb {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
}

.attachment-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 0;
}

.attachment-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.attachment-ribbon {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 38px;
    background: rgba(0,0,0,0.55);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    opacity: 0;
    transition: opacity 0.15s ease;
    padding: 0 8px;
    z-index: 2;
}

.attachment-ribbon.show {
    opacity: 1;
}

.attachment-ribbon a {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 4px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    transition: background var(--email-transition-duration) ease;
    box-shadow: none;
}

.attachment-ribbon a:hover {
    background: var(--email-background-blue-light);
    box-shadow: var(--email-box-shadow-blue);
}

.attachment-ribbon .material-icons {
    font-size: 22px;
    color: var(--email-primary-blue);
    transition: color var(--email-transition-duration) ease;
}

.attachment-ribbon a:hover .material-icons {
    color: var(--email-primary-blue-light);
}

.document-attachment {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 10px;
}

.document-attachment img {
    margin-bottom: 8px;
}

.document-attachment span {
    font-size: 12px;
    color: var(--email-text-muted);
    word-break: break-word;
    line-height: 1.2;
}

.show-all-attachments-btn {
    flex-basis: 100%;
    width: 100%;
    display: flex;
    justify-content: flex-start;
    margin-top: 8px;
    margin-bottom: 4px;
}

.show-all-attachments-btn button {
    background: var(--email-background-blue-light);
    color: var(--email-primary-blue);
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--email-transition-duration) ease;
}

.show-all-attachments-btn button:hover {
    background: var(--email-background-blue-lighter);
}

.email-message-content {
    width: 100%;
}

.email-message-content .chat-text {
    background-color: transparent;
    padding: 0;
}

.email-message-content p {
    margin: 0;
    padding: 0;
    background-color: transparent !important;
    color: #323130 !important;
    font-size: 14px !important;
    line-height: 1.6;
}

/* Responsive Design */
@media (max-width: 768px) {
    .email-actions-bar {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .email-action-btn {
        flex: 1 1 auto;
        min-width: 100px;
        justify-content: center;
    }

    .email-header-label {
        min-width: 60px;
        font-size: 13px;
    }

    .email-header-value {
        font-size: 13px;
    }

    .email-subject {
        font-size: 15px;
    }
}

/* RTL Support */
[dir="rtl"] .email-header-row {
    flex-direction: row-reverse;
}

[dir="rtl"] .email-header-label {
    margin-right: 0;
    margin-left: 8px;
}

[dir="rtl"] .email-actions-bar {
    flex-direction: row-reverse;
}

/* Ensure proper spacing for attachments in email view */
.email-body .chat-text img,
.email-body .chat-text video,
.email-body .chat-text audio {
    max-width: 100%;
    margin: 8px 0;
}

/* Outlook-style message bubbles (if needed) */
.email-outlook-view .chat-right .chat-text {
    background-color: #e8f4f8;
    border-left: 3px solid #0078d4;
    padding-left: 12px;
}

.email-outlook-view .chat-text:not(.chat-right) {
    background-color: #faf9f8;
    border-left: 3px solid #605e5c;
    padding-left: 12px;
}

/* System messages styling */
.email-outlook-view .chat-system-msg {
    background-color: var(--email-background-lighter);
    border: 1px solid var(--email-border-gray);
    border-radius: var(--email-border-radius);
    margin-bottom: var(--email-spacing-md);
}

/* Optimized body wrapper transitions */
.outlook-mail-body-wrapper {
    transform: translateY(-10px);
    opacity: 0;
    overflow: hidden;
    transition: transform 0.15s ease,
                opacity 0.15s ease;
    padding-top: 0;
    padding-bottom: 0;
    transform-style: preserve-3d;
    backface-visibility: hidden;
}

.outlook-mail-body-wrapper.expanded {
    transform: translateY(0);
    opacity: 1;
}

.outlook-mail-card.closed .outlook-mail-body-wrapper {
    transform: translateY(-10px);
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    transition: transform 0.1s ease,
                opacity 0.1s ease;
}

.closed-preview-container {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
}

.closed-preview {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
    padding: 6px 0 6px 0;
}

.closed-preview span {
    color: var(--email-text-muted);
    font-size: 12px;
    min-height: 24px;
    padding: 4px 0;
}

/* Optimized extra info transitions */
.mail-extra-info-transition {
    display: block;
    max-height: 500px;
    opacity: 1;
    overflow: hidden;
    transition: max-height var(--email-transition-duration) ease,
                opacity var(--email-transition-duration) ease;
}

.mail-extra-info-transition.ng-hide {
    max-height: 0;
    opacity: 0;
}

/* Email Thread Styles */
.email-thread-toggle {
    margin-top: var(--email-spacing-md);
    padding-top: var(--email-spacing-sm);
    border-top: 1px solid var(--email-border-gray);
}

.thread-toggle-btn {
    background: #e3f2fd;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--email-primary-blue);
    transition: all 0.2s ease;
    min-width: 32px;
    height: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.thread-toggle-btn:hover {
    background-color: #bbdefb;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.thread-toggle-btn.expanded {
    background-color: #bbdefb;
}

.thread-toggle-btn i {
    font-size: 18px;
    color: var(--email-primary-blue);
}

.email-thread-content {
    margin-top: var(--email-spacing-md);
    border: 1px solid var(--email-border-gray);
    border-radius: 4px;
    background-color: var(--email-background-lighter);
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    opacity: 0;
    transform: translateY(-5px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.email-thread-content.expanded {
    opacity: 1;
    transform: translateY(0);
}

.thread-body {
    padding: var(--email-spacing-md);
    max-height: 400px;
    overflow-y: auto;
    font-size: 13px;
    line-height: 1.5;
    color: #424242;
    background-color: var(--email-background-white);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    border-left: 3px solid var(--email-border-gray);
    margin-left: var(--email-spacing-sm);
    padding-left: var(--email-spacing-md);
}

/* Thread tail styling - Outlook-like appearance */
.thread-body blockquote,
.thread-body div[style*="border-left"],
.thread-body .gmail_quote {
    border-left: 2px solid #d0d0d0;
    padding-left: var(--email-spacing-md);
    margin-left: 0;
    color: #666;
    font-size: 12px;
}

.thread-body::-webkit-scrollbar {
    width: 8px;
}

.thread-body::-webkit-scrollbar-track {
    background: var(--email-background-light);
    border-radius: 4px;
}

.thread-body::-webkit-scrollbar-thumb {
    background: #c0c0c0;
    border-radius: 4px;
}

.thread-body::-webkit-scrollbar-thumb:hover {
    background: #a0a0a0;
}

.thread-body p {
    margin: 0 0 8px 0;
}

.thread-body br {
    margin-bottom: 4px;
}
