/* Thread View Styles */

.thread-view-container {
    display: none;
    flex: 1;
    background: #fff;
    overflow: hidden;
}

.thread-view-container.active {
    display: flex;
}

/* Main content area + sidebar layout */
.thread-view-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.thread-sidebar {
    width: 320px;
    min-width: 320px;
    background: #f8f9fa;
    border-left: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: width 0.3s ease, min-width 0.3s ease;
}

/* Collapsed sidebar */
.thread-view-container.sidebar-collapsed .thread-sidebar {
    width: 0;
    min-width: 0;
    overflow: hidden;
}

.thread-view-container.sidebar-collapsed .sidebar-collapse span {
    transform: rotate(180deg);
}

/* Header Bar */
.thread-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid #e0e0e0;
    background: #fff;
}

.thread-nav {
    display: flex;
    gap: 4px;
}

.thread-actions {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.btn-icon {
    padding: 8px 12px;
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
}

.btn-icon:hover {
    background: #f1f3f4;
    border-color: #bbb;
}

.btn-icon:active {
    background: #e8eaed;
}

/* Thread Content */
.thread-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.thread-content .email-subject {
    font-size: 20px;
    font-weight: 500;
    color: #202124;
    margin: 0 0 24px 0;
    line-height: 1.3;
}

/* Thread Messages - Timeline Layout */
.thread-messages {
    margin-bottom: 24px;
    position: relative;
}

.thread-message {
    border-bottom: 1px solid #e8e8e8;
    margin-bottom: 0;
    background: #fff;
    overflow: visible;
    transition: all 0.2s;
}

.thread-message:last-child {
    border-bottom: none;
}

.thread-message:hover {
    background: #fafafa;
}

/* Thread count header */
.thread-count-header {
    padding: 8px 16px;
    margin-bottom: 16px;
    background: #e8f0fe;
    border-radius: 8px;
    color: #1967d2;
    font-size: 14px;
    font-weight: 500;
}

/* Stale thread warning banner */
.stale-thread-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 1px solid #f59e0b;
    border-radius: 8px;
    color: #92400e;
    font-size: 14px;
    font-weight: 500;
    transition: opacity 0.3s ease;
}

.stale-thread-banner .stale-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.stale-thread-banner .stale-message {
    flex: 1;
}

.stale-thread-banner .stale-dismiss {
    background: none;
    border: none;
    color: #92400e;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.stale-thread-banner .stale-dismiss:hover {
    opacity: 1;
}

/* Timeline styling for messages */
.timeline-message {
    position: relative;
    padding-left: 16px;
    border-left: 3px solid transparent;
    margin-bottom: 4px;
}

/* Received messages - left aligned, blue accent */
.timeline-message.message-received {
    border-left-color: #1a73e8;
    background: #ffffff;
}

.timeline-message.message-received:hover {
    background: #f8f9fa;
}

/* Sent messages - subtle green accent and lighter background */
.timeline-message.message-sent {
    border-left-color: #34a853;
    background: #f0fdf4;
}

.timeline-message.message-sent:hover {
    background: #e6f7ed;
}

/* Make sent message header slightly different */
.timeline-message.message-sent .sender-name {
    color: #188038;
    font-weight: 600;
}

.timeline-message.message-sent .message-date {
    color: #188038;
}

/* Avatar styling based on message type */
.sender-avatar.avatar-received {
    background: linear-gradient(135deg, #1a73e8 0%, #4285f4 100%);
}

.sender-avatar.avatar-sent {
    background: linear-gradient(135deg, #34a853 0%, #5bb974 100%);
}

/* Expanded message gets a subtle shadow for depth */
.timeline-message.expanded {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-bottom: 8px;
}

/* Collapsed messages are more compact */
.timeline-message.collapsed {
    opacity: 0.85;
}

.timeline-message.collapsed:hover {
    opacity: 1;
}

/* Message Header */
.message-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    background: transparent;
}

.message-header:hover {
    background: #f5f5f5;
}

.message-sender {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.sender-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.sender-info {
    flex: 1;
}

.sender-name {
    font-weight: 500;
    color: #202124;
    font-size: 14px;
}

.sender-to {
    font-size: 12px;
    color: #5f6368;
}

.message-date {
    font-size: 12px;
    color: #5f6368;
    white-space: nowrap;
}

.expand-toggle {
    padding: 4px 8px;
}

/* Message Body */
.message-body {
    padding: 16px;
    display: none;
    overflow-x: auto; /* Handle wide email content */
    max-width: 100%;
}

.thread-message.expanded .message-body {
    display: block;
}

.thread-message.collapsed .icon-expanded {
    display: none;
}

.thread-message.expanded .icon-collapsed {
    display: none;
}

.message-cc {
    font-size: 12px;
    color: #5f6368;
    margin-bottom: 12px;
}

.message-content {
    font-size: 14px;
    line-height: 1.6;
    color: #202124;
    word-wrap: break-word;
    overflow-x: auto; /* Handle wide content */
    max-width: 100%;
}

/* Only apply pre-wrap to plain text emails, not HTML iframes */
.message-content .plain-text-email {
    white-space: pre-wrap;
}

/* Attachments */
.message-attachments {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e0e0e0;
}

.message-attachments h5 {
    font-size: 13px;
    font-weight: 600;
    color: #5f6368;
    margin: 0 0 8px 0;
}

.attachment-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    transition: all 0.2s;
}

.attachment-item:hover {
    background: #f1f3f4;
    border-color: #d0d0d0;
}

.attachment-icon {
    font-size: 24px;
}

.attachment-info {
    flex: 1;
}

.attachment-name {
    font-size: 13px;
    font-weight: 500;
    color: #202124;
}

.attachment-size {
    font-size: 11px;
    color: #5f6368;
}

/* Thread Attachments Panel (consolidated view) */
.thread-attachments-panel {
    margin: 16px 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
}

.thread-attachments-panel .panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
}

.thread-attachments-panel .panel-icon {
    font-size: 18px;
}

.thread-attachments-panel .panel-title {
    font-size: 14px;
    font-weight: 600;
    color: #202124;
}

.thread-attachments-panel .panel-body {
    padding: 8px;
}

.thread-attachment-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 6px;
    transition: background 0.15s;
}

.thread-attachment-row:hover {
    background: #f1f3f4;
}

.thread-attachment-row .attachment-icon {
    font-size: 28px;
    flex-shrink: 0;
}

.thread-attachment-row .attachment-details {
    flex: 1;
    min-width: 0;
}

.thread-attachment-row .attachment-name {
    font-size: 14px;
    font-weight: 500;
    color: #202124;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-attachment-row .attachment-meta {
    font-size: 12px;
    color: #5f6368;
    margin-top: 2px;
}

.thread-attachment-row .attachment-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.btn-attachment {
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #dadce0;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    color: #1a73e8;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-attachment:hover {
    background: #e8f0fe;
    border-color: #1a73e8;
}

/* Email Actions (in thread view only) */
.thread-content .email-actions {
    display: flex;
    gap: 8px;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 8px;
}

.btn-primary {
    padding: 10px 20px;
    background: #1a73e8;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: #1765cc;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
    padding: 10px 20px;
    background: #fff;
    color: #5f6368;
    border: 1px solid #dadce0;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #f8f9fa;
    border-color: #dadce0;
}

/* Sidebar */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid #e0e0e0;
    background: #fff;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #202124;
}

.sidebar-content {
    padding: 16px;
}

.sidebar-section {
    margin-bottom: 20px;
}

.sidebar-section h4 {
    margin: 0 0 8px 0;
    font-size: 13px;
    font-weight: 600;
    color: #5f6368;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* AI Summary */
.ai-summary {
    font-size: 14px;
    line-height: 1.5;
    color: #202124;
    background: #e8f0fe;
    padding: 12px;
    border-radius: 4px;
    margin: 0;
}

/* Badges */
.category-badge,
.priority-badge,
.relationship-badge {
    display: inline-block;
    padding: 6px 12px;
    background: #e8f0fe;
    color: #1967d2;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
}

.priority-badge.priority-critical {
    background: #fce8e6;
    color: #c5221f;
}

.priority-badge.priority-high {
    background: #fef7e0;
    color: #ea8600;
}

.priority-badge.priority-normal {
    background: #e8f5e9;
    color: #1e8e3e;
}

.priority-badge.priority-low {
    background: #f1f3f4;
    color: #5f6368;
}

.no-relationship {
    font-size: 13px;
    color: #5f6368;
    font-style: italic;
    margin-bottom: 8px;
}

/* Sender Trust Status */
.sender-trust {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 8px;
}

.sender-verified {
    background: #e6f4ea;
    color: #1e8e3e;
}

.sender-partial {
    background: #fef7e0;
    color: #b06000;
}

.sender-unverified {
    background: #fce8e6;
    color: #c5221f;
}

.btn-trust {
    padding: 4px 10px;
    font-size: 12px;
    background: #1a73e8;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}

.btn-trust:hover {
    background: #1557b0;
}

#relationship-selector {
    margin-top: 8px;
}

.confidence-score {
    font-size: 12px;
    color: #5f6368;
    margin-top: 4px;
}

/* Action Flags (legacy) */
.action-flags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.action-flag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: #fff3cd;
    color: #856404;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 500;
}

/* Action Items (v6 schema) */
.action-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.action-item {
    background: #fff;
    border: 1px solid #dadce0;
    border-radius: 6px;
    padding: 10px 12px;
    border-left: 3px solid #5f6368;
}

.action-item.action-low {
    border-left-color: #5f6368;
}

.action-item.action-medium {
    border-left-color: #f9ab00;
    background: #fffbf0;
}

.action-item.action-high {
    border-left-color: #ea8600;
    background: #fef7e0;
}

.action-item.action-critical {
    border-left-color: #d93025;
    background: #fce8e6;
}

.action-item.action-overdue {
    border-left-color: #c5221f;
    background: #fce8e6;
    animation: pulse-overdue 2s infinite;
}

@keyframes pulse-overdue {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

.action-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.action-icon {
    font-size: 16px;
}

.action-type {
    font-weight: 500;
    color: #202124;
    flex: 1;
}

.action-importance {
    font-size: 11px;
    font-weight: 500;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
}

.action-importance.importance-low {
    background: #f1f3f4;
    color: #5f6368;
}

.action-importance.importance-medium {
    background: #fef7e0;
    color: #b06000;
}

.action-importance.importance-high {
    background: #fce8e6;
    color: #c5221f;
}

.action-due {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 12px;
    color: #5f6368;
}

.due-icon {
    font-size: 12px;
}

.due-date {
    color: #5f6368;
}

.due-date.overdue {
    color: #c5221f;
    font-weight: 500;
}

/* Action item user-corrected indicator */
.action-item.user-corrected {
    border: 1px solid #1a73e8;
}

.corrected-badge {
    font-size: 9px;
    background: #1a73e8;
    color: white;
    padding: 1px 4px;
    border-radius: 3px;
    text-transform: uppercase;
    font-weight: 600;
}

/* Action details (type-specific info) */
.action-details {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(0,0,0,0.08);
}

.action-detail {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #5f6368;
    margin-bottom: 4px;
}

.action-detail:last-child {
    margin-bottom: 0;
}

.detail-icon {
    font-size: 11px;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.detail-label {
    color: #80868b;
    font-weight: 500;
    flex-shrink: 0;
}

.detail-value {
    color: #202124;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.detail-value.overdue {
    color: #c5221f;
    font-weight: 500;
}

/* Section hint */
.section-hint {
    font-size: 10px;
    color: #9aa0a6;
    font-weight: 400;
}

/* Add action button */
.btn-add-action {
    margin-top: 8px;
    padding: 6px 12px;
    background: transparent;
    border: 1px dashed #dadce0;
    border-radius: 4px;
    color: #5f6368;
    cursor: pointer;
    font-size: 12px;
    width: 100%;
    transition: all 0.2s;
}

.btn-add-action:hover {
    background: #f1f3f4;
    border-color: #1a73e8;
    color: #1a73e8;
}

/* Action context menu */
.action-context-menu {
    position: fixed;
    z-index: 10000;
    background: white;
    border: 1px solid #dadce0;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    min-width: 200px;
    padding: 6px 0;
    font-size: 13px;
}

.action-context-menu .context-menu-header {
    padding: 8px 16px;
    font-weight: 600;
    color: #202124;
    border-bottom: 1px solid #e8eaed;
    margin-bottom: 4px;
}

.action-context-menu .context-menu-label {
    padding: 4px 16px;
    font-size: 11px;
    color: #5f6368;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.action-context-menu .context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    cursor: pointer;
    color: #202124;
    transition: background 0.1s;
}

.action-context-menu .context-menu-item:hover {
    background: #f1f3f4;
}

.action-context-menu .context-menu-item.selected {
    background: #e8f0fe;
    color: #1a73e8;
}

.action-context-menu .context-menu-item.danger {
    color: #c5221f;
}

.action-context-menu .context-menu-item.danger:hover {
    background: #fce8e6;
}

.action-context-menu .context-menu-divider {
    height: 1px;
    background: #e8eaed;
    margin: 6px 0;
}

.importance-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.importance-dot.low {
    background: #5f6368;
}

.importance-dot.medium {
    background: #f9ab00;
}

.importance-dot.high {
    background: #d93025;
}

/* Add action dialog */
.action-add-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-add-dialog .dialog-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
}

.action-add-dialog .dialog-content {
    position: relative;
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    min-width: 320px;
}

.action-add-dialog h3 {
    margin: 0 0 16px 0;
    font-size: 18px;
    color: #202124;
}

.action-add-dialog .dialog-field {
    margin-bottom: 16px;
}

.action-add-dialog .dialog-field label {
    display: block;
    font-size: 12px;
    color: #5f6368;
    margin-bottom: 4px;
}

.action-add-dialog .dialog-field select,
.action-add-dialog .dialog-field input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #dadce0;
    border-radius: 4px;
    font-size: 14px;
}

.action-add-dialog .dialog-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

.action-add-dialog .btn-cancel {
    padding: 8px 16px;
    background: #f1f3f4;
    border: none;
    border-radius: 4px;
    color: #5f6368;
    cursor: pointer;
    font-size: 14px;
}

.action-add-dialog .btn-save {
    padding: 8px 16px;
    background: #1a73e8;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.action-add-dialog .btn-cancel:hover {
    background: #e8eaed;
}

.action-add-dialog .btn-save:hover {
    background: #1557b0;
}

/* Quick Actions */
.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.btn-action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    background: #fff;
    border: 1px solid #dadce0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #5f6368;
    transition: all 0.2s;
}

.btn-action:hover {
    background: #f8f9fa;
    border-color: #bbb;
}

.btn-action span {
    font-size: 16px;
}

/* Related Emails Section */
#related-emails-section h4 {
    margin-bottom: 12px;
}

.related-group {
    margin-bottom: 12px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 3px solid #1a73e8;
}

.related-group.link-strong {
    border-left-color: #1e8e3e;
}

.related-group.link-medium {
    border-left-color: #f9ab00;
}

.related-group.link-weak {
    border-left-color: #dadce0;
    opacity: 0.85;
}

.related-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 500;
}

.related-icon {
    font-size: 16px;
}

.related-label {
    color: #202124;
    flex: 1;
}

.related-count {
    color: #5f6368;
    font-weight: 400;
}

.related-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.related-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.15s;
}

.related-item:hover {
    background: #e8f0fe;
}

.related-date {
    color: #5f6368;
    font-size: 11px;
    min-width: 55px;
}

.related-subject {
    color: #202124;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Form Controls */
.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #dadce0;
    border-radius: 4px;
    font-size: 14px;
    color: #202124;
    background: #fff;
}

.form-control:focus {
    outline: none;
    border-color: #1a73e8;
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.1);
}

/* Loading & Error States */
.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: #5f6368;
    font-size: 14px;
}

.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px;
    text-align: center;
}

.error-state h3 {
    color: #c5221f;
    margin: 0 0 8px 0;
}

.error-state p {
    color: #5f6368;
    margin: 0 0 16px 0;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    /* Thread container - full width */
    .thread-view-container {
        width: 100%;
        max-width: 100%;
    }

    /* Sidebar - slide in from right */
    .thread-sidebar {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        max-width: 320px;
        z-index: 1000;
        box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .thread-view-container:not(.sidebar-collapsed) .thread-sidebar {
        transform: translateX(0);
    }

    /* Content area - reduced padding */
    .thread-content {
        padding: 12px;
    }

    /* Header - stack vertically on mobile */
    .thread-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 8px 12px;
    }

    /* Subject line - smaller, better line height */
    .thread-content .email-subject {
        font-size: 18px;
        line-height: 1.3;
        margin-bottom: 16px;
    }

    /* Message header - better stacking */
    .message-header {
        padding: 10px 12px;
    }

    .message-sender {
        flex-wrap: wrap;
    }

    /* Sender avatar - slightly smaller */
    .sender-avatar {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }

    /* Sender info - full width */
    .sender-info {
        flex: 1;
        min-width: 0;
    }

    .sender-name {
        font-size: 13px;
    }

    .sender-to {
        font-size: 11px;
        word-break: break-all;
    }

    /* Date - smaller */
    .message-date {
        font-size: 11px;
    }

    /* Message body - ensure readability */
    .message-body {
        padding: 12px;
        font-size: 15px;
        line-height: 1.6;
        overflow-x: auto;
    }

    .message-content {
        font-size: 15px;
        line-height: 1.6;
    }

    /* Prevent horizontal scroll on images */
    .message-body img,
    .message-content img {
        max-width: 100%;
        height: auto;
    }

    /* Handle code blocks and pre-formatted text */
    .message-body pre,
    .message-body code,
    .message-content pre,
    .message-content code {
        overflow-x: auto;
        white-space: pre-wrap;
        word-wrap: break-word;
    }

    /* Email iframe - responsive */
    .email-iframe {
        width: 100%;
        max-width: 100%;
    }

    /* Long email addresses */
    .sender-to,
    .message-cc {
        word-break: break-all;
        font-size: 11px;
    }

    /* Action buttons - larger for touch, stack if needed */
    .thread-actions {
        flex-wrap: wrap;
        gap: 8px;
        margin-left: 0;
        width: 100%;
        justify-content: flex-start;
    }

    .btn-icon {
        padding: 10px 16px;
        font-size: 16px;
        min-height: 44px;
        min-width: 44px;
    }

    /* Email actions - full width buttons */
    .thread-content .email-actions {
        flex-direction: column;
        gap: 8px;
        padding: 12px;
    }

    .btn-primary,
    .btn-secondary {
        width: 100%;
        padding: 12px 16px;
        font-size: 14px;
        min-height: 44px;
    }

    /* Attachments - stack vertically */
    .message-attachments {
        margin-top: 12px;
        padding-top: 12px;
    }

    .attachment-list {
        flex-direction: column;
        gap: 8px;
    }

    .attachment-item {
        width: 100%;
        padding: 10px;
    }

    /* Action items - full width */
    .action-items {
        gap: 8px;
    }

    .action-item {
        padding: 12px;
    }

    .action-header {
        flex-wrap: wrap;
    }

    /* Quick actions - stack on smaller screens */
    .quick-actions {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .btn-action {
        min-height: 44px;
        padding: 12px;
        font-size: 14px;
    }

    /* Sidebar sections */
    .sidebar-content {
        padding: 12px;
    }

    .sidebar-section {
        margin-bottom: 16px;
    }

    /* Related emails - better mobile layout */
    .related-item {
        padding: 8px;
    }

    .related-date {
        min-width: 50px;
        font-size: 10px;
    }

    .related-subject {
        font-size: 11px;
    }

    /* AI Summary - better spacing */
    .ai-summary {
        font-size: 13px;
        padding: 10px;
    }

    /* Badges - slightly smaller */
    .category-badge,
    .priority-badge,
    .relationship-badge {
        font-size: 12px;
        padding: 5px 10px;
    }

    /* Thread nav - ensure touch targets */
    .thread-nav {
        gap: 6px;
    }

    /* Dialog - better mobile layout */
    .action-add-dialog .dialog-content {
        margin: 16px;
        min-width: 280px;
        max-width: calc(100vw - 32px);
    }

    /* Context menu - adjust for mobile */
    .action-context-menu {
        min-width: 180px;
        max-width: calc(100vw - 32px);
    }

    /* Repair suggestions - better mobile layout */
    .repair-actions {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .repair-actions .btn-action {
        width: 100%;
    }
}

/* Small phones - additional adjustments */
@media (max-width: 480px) {
    /* Even more compact */
    .thread-content {
        padding: 8px;
    }

    .thread-content .email-subject {
        font-size: 16px;
    }

    .message-body {
        padding: 10px;
        font-size: 14px;
    }

    .message-content {
        font-size: 14px;
    }

    /* Action buttons - full width on very small screens */
    .thread-actions {
        width: 100%;
    }

    .btn-icon {
        flex: 1;
        justify-content: center;
    }

    /* Sidebar - full width on small phones */
    .thread-sidebar {
        max-width: 100%;
    }

    /* Sender info - more compact */
    .sender-avatar {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }

    .sender-name {
        font-size: 12px;
    }

    .sender-to {
        font-size: 10px;
    }

    /* Action items - more compact */
    .action-item {
        padding: 10px;
    }

    .action-type {
        font-size: 13px;
    }

    .action-detail {
        font-size: 11px;
    }
}

/* Smooth transitions */
* {
    transition-property: background, border-color, box-shadow, transform;
    transition-duration: 0.2s;
    transition-timing-function: ease;
}

button {
    font-family: inherit;
}

/* Thread Repair Styles */
.thread-repair-suggestion,
.thread-repair-applied {
    background: #fff;
    border: 1px solid #dadce0;
    border-radius: 8px;
    padding: 12px;
}

.thread-repair-suggestion {
    border-left: 3px solid #1a73e8;
}

.thread-repair-applied {
    border-left: 3px solid #5f6368;
}

.repair-evidence {
    margin-bottom: 12px;
}

.repair-evidence p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
    color: #202124;
}

.repair-confidence {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    margin-bottom: 12px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
}

.repair-confidence strong {
    color: #202124;
}

.repair-confidence.confidence-high {
    background: #e8f5e9;
    color: #1e8e3e;
}

.repair-confidence.confidence-high strong {
    color: #1e8e3e;
}

.repair-confidence.confidence-warning {
    background: #fef7e0;
    color: #ea8600;
}

.repair-confidence.confidence-warning strong {
    color: #ea8600;
}

.repair-method {
    font-size: 11px;
    color: #5f6368;
    font-style: italic;
}

.repair-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.repair-notice {
    margin: 0 0 12px 0;
    font-size: 13px;
    line-height: 1.5;
    color: #5f6368;
    font-style: italic;
}

.thread-repair-applied .btn-action {
    width: 100%;
}

/* HTML Email Rendering */
.html-email-container {
    position: relative;
    max-width: 100%;
    overflow-x: auto; /* Allow scrolling for wide email content */
}

.image-warning {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    padding: 8px 12px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.btn-small {
    padding: 4px 8px;
    font-size: 12px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

.btn-small:hover {
    background: #0056b3;
}

.email-iframe {
    width: 100%;
    min-height: 200px;
    height: auto;
    border: none;
    background: white;
}

.html-email-container {
    width: 100%;
}

.blocked-image {
    opacity: 0.5;
    border: 1px dashed #ccc;
}

.plain-text-email {
    white-space: pre-wrap;
    font-family: inherit;
    margin: 0;
}

/* Quoted Text Collapsible Section */
.quoted-text-container {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e8eaed;
}

.quoted-text-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f8f9fa;
    border: 1px solid #dadce0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #5f6368;
    transition: all 0.2s;
    width: 100%;
    text-align: left;
}

.quoted-text-toggle:hover {
    background: #f1f3f4;
    border-color: #c1c1c1;
    color: #202124;
}

.quote-toggle-icon {
    font-size: 10px;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.quote-toggle-text {
    flex: 1;
    font-weight: 500;
}

.quoted-text-content {
    margin-top: 8px;
    padding: 12px;
    background: #f8f9fa;
    border: 1px solid #e8eaed;
    border-radius: 6px;
}

.quoted-text-content .plain-text-email {
    color: #5f6368;
    font-size: 13px;
}

/* ========================================
   DARK MODE SUPPORT
   ======================================== */
@media (prefers-color-scheme: dark) {
    /* Main containers */
    .thread-view-container,
    .thread-view-main,
    .thread-header,
    .thread-content {
        background: #1a1a1a !important;
    }

    .thread-sidebar {
        background: #1a1a1a !important;
        border-left-color: #333 !important;
    }

    /* Headers and borders */
    .thread-header {
        border-bottom-color: #333 !important;
    }

    .btn-icon {
        border-color: #444 !important;
        color: #e0e0e0 !important;
    }

    .btn-icon:hover {
        background: #2a2a2a !important;
        border-color: #555 !important;
    }

    /* Email subject */
    .thread-content .email-subject {
        color: #fff !important;
    }

    /* Thread count header */
    .thread-count-header {
        background: #1e3a5f !important;
        color: #6db3ff !important;
    }

    /* Messages */
    .thread-message {
        background: #1a1a1a !important;
        border-bottom-color: #333 !important;
    }

    .thread-message:hover {
        background: #222 !important;
    }

    /* Timeline messages */
    .timeline-message.message-received {
        background: #1a1a1a !important;
    }

    .timeline-message.message-received:hover {
        background: #222 !important;
    }

    .timeline-message.message-sent {
        background: #1a2e1a !important;
    }

    .timeline-message.message-sent:hover {
        background: #1f3a1f !important;
    }

    .timeline-message.message-sent .sender-name,
    .timeline-message.message-sent .message-date {
        color: #5bb974 !important;
    }

    /* Message header */
    .message-header:hover {
        background: #2a2a2a !important;
    }

    .sender-name {
        color: #e0e0e0 !important;
    }

    .sender-to,
    .message-date,
    .message-cc {
        color: #888 !important;
    }

    /* Message content */
    .message-content {
        color: #e0e0e0 !important;
    }

    /* Attachments */
    .message-attachments {
        border-top-color: #333 !important;
    }

    .message-attachments h5 {
        color: #888 !important;
    }

    .attachment-item {
        background: #2a2a2a !important;
        border-color: #444 !important;
    }

    .attachment-item:hover {
        background: #333 !important;
        border-color: #555 !important;
    }

    .attachment-name {
        color: #e0e0e0 !important;
    }

    .attachment-size {
        color: #888 !important;
    }

    /* Thread Attachments Panel - dark mode */
    .thread-attachments-panel {
        background: #1a1a1a !important;
        border-color: #333 !important;
    }

    .thread-attachments-panel .panel-header {
        background: #222 !important;
        border-bottom-color: #333 !important;
    }

    .thread-attachments-panel .panel-title {
        color: #e0e0e0 !important;
    }

    .thread-attachment-row:hover {
        background: #2a2a2a !important;
    }

    .thread-attachment-row .attachment-name {
        color: #e0e0e0 !important;
    }

    .thread-attachment-row .attachment-meta {
        color: #888 !important;
    }

    .btn-attachment {
        background: #2a2a2a !important;
        border-color: #444 !important;
        color: #8ab4f8 !important;
    }

    .btn-attachment:hover {
        background: #3a3a3a !important;
        border-color: #8ab4f8 !important;
    }

    /* Email actions bar */
    .thread-content .email-actions {
        background: #222 !important;
    }

    /* Buttons */
    .btn-secondary {
        background: #333 !important;
        color: #e0e0e0 !important;
        border-color: #444 !important;
    }

    .btn-secondary:hover {
        background: #3a3a3a !important;
        border-color: #555 !important;
    }

    /* Sidebar */
    .sidebar-header {
        background: #1a1a1a !important;
        border-bottom-color: #333 !important;
    }

    .sidebar-header h3 {
        color: #fff !important;
    }

    .sidebar-section h4 {
        color: #888 !important;
    }

    /* AI Summary */
    .ai-summary {
        background: #1e3a5f !important;
        color: #b3d4ff !important;
    }

    /* Badges in dark mode */
    .category-badge,
    .priority-badge,
    .relationship-badge {
        background: #1e3a5f !important;
        color: #6db3ff !important;
    }

    .priority-badge.priority-critical {
        background: #4a1a1a !important;
        color: #ff8080 !important;
    }

    .priority-badge.priority-high {
        background: #4a3a1a !important;
        color: #ffcc66 !important;
    }

    .priority-badge.priority-normal {
        background: #1a3a1a !important;
        color: #66cc66 !important;
    }

    .priority-badge.priority-low {
        background: #2a2a2a !important;
        color: #888 !important;
    }

    .no-relationship {
        color: #888 !important;
    }

    /* Sender trust */
    .sender-verified {
        background: #1a3a1a !important;
        color: #66cc66 !important;
    }

    .sender-partial {
        background: #4a3a1a !important;
        color: #ffcc66 !important;
    }

    .sender-unverified {
        background: #4a1a1a !important;
        color: #ff8080 !important;
    }

    .confidence-score {
        color: #888 !important;
    }

    /* Action items */
    .action-item {
        background: #1a1a1a !important;
        border-color: #444 !important;
    }

    .action-item.action-medium {
        background: #2a2a1a !important;
    }

    .action-item.action-high {
        background: #3a2a1a !important;
    }

    .action-item.action-critical,
    .action-item.action-overdue {
        background: #3a1a1a !important;
    }

    .action-type {
        color: #e0e0e0 !important;
    }

    .action-importance.importance-low {
        background: #2a2a2a !important;
        color: #888 !important;
    }

    .action-importance.importance-medium {
        background: #4a3a1a !important;
        color: #ffcc66 !important;
    }

    .action-importance.importance-high {
        background: #4a1a1a !important;
        color: #ff8080 !important;
    }

    .action-due,
    .due-date {
        color: #888 !important;
    }

    .due-date.overdue {
        color: #ff8080 !important;
    }

    .action-detail {
        color: #888 !important;
    }

    .detail-label {
        color: #666 !important;
    }

    .detail-value {
        color: #e0e0e0 !important;
    }

    /* Action flags */
    .action-flag {
        background: #4a3a1a !important;
        color: #ffcc66 !important;
    }

    /* Thread repair */
    .thread-repair-suggestion,
    .thread-repair-applied {
        background: #1a1a1a !important;
        border-color: #444 !important;
    }

    .repair-evidence p {
        color: #e0e0e0 !important;
    }

    .repair-confidence {
        background: #222 !important;
        color: #e0e0e0 !important;
    }

    .repair-confidence strong {
        color: #fff !important;
    }

    .repair-confidence.confidence-high {
        background: #1a3a1a !important;
        color: #66cc66 !important;
    }

    .repair-confidence.confidence-high strong {
        color: #66cc66 !important;
    }

    .repair-confidence.confidence-warning {
        background: #4a3a1a !important;
        color: #ffcc66 !important;
    }

    .repair-confidence.confidence-warning strong {
        color: #ffcc66 !important;
    }

    .repair-method,
    .repair-notice {
        color: #888 !important;
    }

    /* HTML email container */
    .image-warning {
        background: #4a3a1a !important;
        border-color: #ffcc66 !important;
        color: #ffcc66 !important;
    }

    .email-iframe {
        background: #1a1a1a !important;
    }

    .blocked-image {
        border-color: #444 !important;
    }

    /* Quoted text */
    .quoted-text-container {
        border-top-color: #333 !important;
    }

    .quoted-text-toggle {
        background: #2a2a2a !important;
        border-color: #444 !important;
        color: #888 !important;
    }

    .quoted-text-toggle:hover {
        background: #333 !important;
        border-color: #555 !important;
        color: #e0e0e0 !important;
    }

    .quoted-text-content {
        background: #222 !important;
        border-color: #333 !important;
    }

    .quoted-text-content .plain-text-email {
        color: #888 !important;
    }

    /* Plain text emails */
    .plain-text-email {
        color: #b8b8b8 !important;
    }

    /* Reading pane */
    .reading-pane-header,
    .reading-pane-body,
    .reading-pane-footer {
        background: #1a1a1a !important;
        border-color: #333 !important;
    }

    .reading-pane-header h2 {
        color: #fff !important;
    }

    .reading-pane-meta {
        color: #888 !important;
    }
}
