/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #1a5f7a;
    --primary-dark: #134b5f;
    --secondary-color: #57837b;
    --accent-color: #c38e70;
    --background-dark: #1a1a2e;
    --background-light: #16213e;
    --surface-color: #0f3460;
    --text-primary: #e8e8e8;
    --text-secondary: #a8a8a8;
    --text-muted: #6b7280;
    --border-color: #2d4a6d;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --gift-color: #f472b6;
    --intimate-color: #ec4899;
    --logistics-color: #60a5fa;
    --visit-color: #34d399;
    --business-color: #fbbf24;
    --critical-color: #f87171;
    --khashoggi-color: #dc2626;
}

html {
    font-size: 16px;
}

body {
    font-family: 'Cairo', 'Tajawal', 'Almarai', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, var(--background-dark) 0%, var(--background-light) 100%);
    color: var(--text-primary);
    line-height: 1.9;
    min-height: 100vh;
    direction: rtl;
    font-weight: 400;
    letter-spacing: 0.01em;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.main-header {
    background: linear-gradient(90deg, var(--primary-dark) 0%, var(--surface-color) 100%);
    padding: 1.5rem 2rem;
    border-bottom: 2px solid var(--accent-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.header-content h1 {
    font-size: 1.75rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 0.25rem;
    font-family: 'Cairo', 'Tajawal', sans-serif;
}

.header-content .subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.date-range {
    background: var(--background-dark);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--accent-color);
    border: 1px solid var(--border-color);
}

/* Main Layout */
.main-layout {
    display: grid;
    grid-template-columns: 280px 380px 1fr;
    flex: 1;
    gap: 0;
    max-height: calc(100vh - 85px);
}

/* Sidebar */
.sidebar {
    background: var(--background-light);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 1rem;
}

.sidebar-section {
    margin-bottom: 1.5rem;
}

.sidebar-section h3 {
    font-size: 1rem;
    color: var(--accent-color);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

/* People Filters */
.people-filters {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.person-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.8rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: 'Cairo', 'Tajawal', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: right;
}

.person-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.person-btn.active {
    background: var(--primary-color);
    border-color: var(--accent-color);
}

/* Person Headshots */
.person-headshot {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
    background: var(--surface-color);
}

.person-btn:hover .person-headshot,
.person-btn.active .person-headshot {
    border-color: var(--accent-color);
}

/* Generic avatar and all-icon SVG styling */
.person-headshot.generic-avatar,
.person-headshot.all-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #3a3a4a 0%, #2a2a3a 100%);
    color: #888;
}

.person-headshot svg {
    width: 18px;
    height: 18px;
}

.person-btn:hover .person-headshot.generic-avatar,
.person-btn:hover .person-headshot.all-icon,
.person-btn.active .person-headshot.generic-avatar,
.person-btn.active .person-headshot.all-icon {
    color: var(--accent-color);
}

/* Tag Filters */
.tag-filters {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tag-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: 'Cairo', 'Tajawal', sans-serif;
    font-size: 0.9rem;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: right;
}

.tag-btn:hover {
    background: var(--primary-dark);
}

.tag-btn.active {
    background: var(--primary-color);
    border-color: var(--accent-color);
}

.tag-btn[data-tag="gift"].active { border-color: var(--gift-color); }
.tag-btn[data-tag="intimate"].active { border-color: var(--intimate-color); }
.tag-btn[data-tag="logistics"].active { border-color: var(--logistics-color); }
.tag-btn[data-tag="visit"].active { border-color: var(--visit-color); }
.tag-btn[data-tag="business"].active { border-color: var(--business-color); }
.tag-btn[data-tag="critical"].active { border-color: var(--critical-color); }
.tag-btn[data-tag="khashoggi"].active { border-color: var(--khashoggi-color); }

.tag-icon {
    font-size: 1rem;
}

.tag-count {
    background: var(--background-dark);
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    min-width: 1.5rem;
    text-align: center;
}

/* Timeline Filters */
.timeline-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.timeline-btn {
    padding: 0.4rem 0.8rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.timeline-btn:hover {
    background: var(--primary-dark);
}

.timeline-btn.active {
    background: var(--primary-color);
    border-color: var(--accent-color);
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.stat-item {
    background: var(--surface-color);
    padding: 0.75rem;
    border-radius: 8px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-color);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Email List */
.email-list {
    background: var(--background-dark);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.list-header {
    padding: 1rem;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
}

.list-header h2 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.list-header h2 span {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.9rem;
}

.search-box input {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--background-dark);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: 'Cairo', 'Tajawal', sans-serif;
    font-size: 0.95rem;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.threads-container {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

/* Thread Item */
.thread-item {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    overflow: hidden;
}

.thread-item:hover {
    border-color: var(--primary-color);
    transform: translateX(-2px);
}

.thread-item.active {
    border-color: var(--accent-color);
    background: var(--primary-dark);
}

.thread-header {
    padding: 0.75rem 1rem;
}

.thread-date {
    font-size: 0.75rem;
    color: var(--accent-color);
    margin-bottom: 0.25rem;
}

.thread-title {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.35rem;
    line-height: 1.6;
    font-family: 'Cairo', 'Tajawal', sans-serif;
}

.thread-preview {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.7;
    font-family: 'Tajawal', 'Cairo', sans-serif;
}

.thread-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    padding: 0.5rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid var(--border-color);
}

.thread-tag {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    color: #fff;
}

.thread-tag.gift { background: var(--gift-color); }
.thread-tag.intimate { background: var(--intimate-color); }
.thread-tag.logistics { background: var(--logistics-color); }
.thread-tag.visit { background: var(--visit-color); }
.thread-tag.business { background: var(--business-color); }
.thread-tag.critical { background: var(--critical-color); }
.thread-tag.khashoggi { background: var(--khashoggi-color); }

/* Email Detail */
.email-detail {
    background: var(--background-light);
    overflow-y: auto;
    padding: 0;
}

.detail-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

.placeholder-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Detail Content */
.detail-header {
    background: var(--surface-color);
    padding: 1.5rem;
    border-bottom: 2px solid var(--border-color);
}

.detail-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.detail-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: #fff;
    font-family: 'Cairo', 'Tajawal', sans-serif;
    flex: 1;
}

.share-btn {
    background: var(--primary-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-family: 'Cairo', 'Tajawal', sans-serif;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.share-btn:hover {
    background: var(--accent-color);
    color: #000;
}

.share-btn.copied {
    background: var(--success-color);
    color: #fff;
    border-color: var(--success-color);
}

.detail-meta {
    display: flex;
    gap: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.detail-meta span {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.detail-participants {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.participant-badge {
    background: var(--primary-dark);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.participant-badge.main {
    background: var(--accent-color);
    color: #000;
    font-weight: 600;
}

/* Participant Photos */
.participants-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.participant-photo-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.participant-photo-item img {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--accent-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.participant-photo-item img:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(195, 142, 112, 0.4);
}

.participant-photo-item .photo-name {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: center;
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Summary Section */
.detail-summary {
    padding: 1.5rem;
    background: var(--background-dark);
    border-bottom: 1px solid var(--border-color);
}

.summary-title {
    font-size: 1rem;
    color: var(--accent-color);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.summary-text {
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 2;
    font-family: 'Tajawal', 'Cairo', sans-serif;
}

/* Thread Content */
.detail-thread {
    padding: 1.5rem;
}

.thread-content-title {
    font-size: 1rem;
    color: var(--accent-color);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.email-message {
    background: var(--surface-color);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    border-right: 4px solid var(--border-color);
}

.email-message.from-epstein {
    border-right-color: var(--danger-color);
    background: linear-gradient(90deg, var(--surface-color) 0%, rgba(239, 68, 68, 0.1) 100%);
}

.email-message.from-epstein .sender-photo-col .msg-photo {
    border-color: var(--danger-color);
}

.email-message.from-aziza {
    border-right-color: var(--gift-color);
    background: linear-gradient(90deg, var(--surface-color) 0%, rgba(244, 114, 182, 0.1) 100%);
}

.email-message.from-aziza .sender-photo-col .msg-photo {
    border-color: var(--gift-color);
}

.email-message.from-staff {
    border-right-color: var(--logistics-color);
}

.email-message.from-sultan {
    border-right-color: var(--business-color);
    background: linear-gradient(90deg, var(--surface-color) 0%, rgba(251, 191, 36, 0.1) 100%);
}

.email-message.from-sultan .sender-photo-col .msg-photo {
    border-color: var(--business-color);
}

.email-message.from-staff .sender-photo-col .msg-photo {
    border-color: var(--logistics-color);
}

/* Forward messages */
.email-message.is-forward {
    border-right-style: double;
    border-right-width: 5px;
}

.forward-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 0.3rem;
}

.forward-arrow {
    font-size: 1rem;
    color: var(--accent-color);
    line-height: 1;
}

.forward-indicator .msg-photo,
.forward-indicator .msg-photo-fallback {
    width: 30px;
    height: 30px;
    border-color: var(--secondary-color);
    opacity: 0.9;
}

.forward-badge {
    background: linear-gradient(90deg, var(--secondary-color), transparent);
    color: var(--text-primary);
    font-size: 0.75rem;
    padding: 0.3rem 0.75rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    display: inline-block;
}

/* Separate/Private conversation - visually distinct */
.email-message.separate-thread {
    margin-top: 1.5rem;
    border: 2px dashed var(--warning-color);
    border-right: 4px solid var(--warning-color);
    background: linear-gradient(90deg, var(--background-dark) 0%, rgba(245, 158, 11, 0.15) 100%);
    position: relative;
}

.email-message.separate-thread::before {
    content: "⚡ محادثة منفصلة";
    position: absolute;
    top: -12px;
    right: 10px;
    background: var(--warning-color);
    color: #000;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
}

/* Group message indicator */
.email-message.group-message {
    border-right-color: var(--visit-color);
    position: relative;
}

.email-message.group-message::before {
    content: "👥 رسالة جماعية";
    position: absolute;
    top: -12px;
    right: 10px;
    background: var(--visit-color);
    color: #000;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
}

/* Message with photos layout */
.message-with-photos {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.sender-photo-col {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.message-main {
    flex: 1;
    min-width: 0;
}

.recipient-photos-col {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding-right: 0.75rem;
    border-right: 1px dashed var(--border-color);
}

.recipient-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.msg-photo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
}

.sender-photo-col .msg-photo {
    width: 45px;
    height: 45px;
    border-color: var(--accent-color);
}

.recipient-photos-col .msg-photo {
    width: 32px;
    height: 32px;
    border-color: var(--text-muted);
}

.msg-photo-fallback {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.sender-photo-col .msg-photo-fallback {
    width: 45px;
    height: 45px;
}

.recipient-photos-col .msg-photo-fallback {
    width: 32px;
    height: 32px;
    font-size: 1rem;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.message-sender {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.message-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.message-content {
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 2;
    white-space: pre-wrap;
    font-family: 'Tajawal', 'Cairo', sans-serif;
    font-weight: 400;
}

.message-content a {
    color: var(--accent-color);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

/* Key Findings */
.detail-findings {
    padding: 1.5rem;
    background: var(--background-dark);
    border-top: 2px solid var(--critical-color);
}

.findings-title {
    font-size: 1rem;
    color: var(--critical-color);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.findings-list {
    list-style: none;
}

.findings-list li {
    padding: 0.6rem 0;
    padding-right: 1.75rem;
    position: relative;
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.8;
    border-bottom: 1px solid var(--border-color);
    font-family: 'Tajawal', 'Cairo', sans-serif;
}

.findings-list li:last-child {
    border-bottom: none;
}

.findings-list li::before {
    content: "⚠️";
    position: absolute;
    right: 0;
    top: 0.5rem;
    font-size: 0.9rem;
}

.findings-list li.highlight {
    background: rgba(220, 38, 38, 0.15);
    padding: 0.75rem;
    padding-right: 2rem;
    border-radius: 6px;
    margin: 0.5rem 0;
}

/* Attachments */
.detail-attachments {
    padding: 1.5rem;
    background: var(--background-dark);
    border-top: 2px solid var(--accent-color);
}

.attachments-title {
    font-size: 1rem;
    color: var(--accent-color);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.attachments-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.attachment-item {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.attachment-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.attachment-header:hover {
    background: var(--primary-dark);
}

.attachment-icon {
    font-size: 1.2rem;
}

.attachment-name {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text-primary);
    font-family: 'Cairo', 'Tajawal', sans-serif;
}

.attachment-id {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: monospace;
    background: var(--background-dark);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

.attachment-toggle {
    color: var(--accent-color);
    font-size: 0.8rem;
    transition: transform 0.2s ease;
}

.attachment-preview {
    border-top: 1px solid var(--border-color);
    background: var(--background-light);
}

.pdf-iframe {
    width: 100%;
    height: 600px;
    border: none;
    background: #fff;
}

/* Inline Attachments in Messages */
.inline-attachment {
    margin: 1rem 0;
    border: 2px solid var(--accent-color);
    border-radius: 8px;
    overflow: hidden;
    background: var(--background-dark);
}

.inline-attachment-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: linear-gradient(90deg, var(--surface-color), var(--primary-dark));
    cursor: pointer;
    transition: background 0.2s ease;
}

.inline-attachment-header:hover {
    background: linear-gradient(90deg, var(--primary-dark), var(--primary-color));
}

.inline-attachment-header .attachment-icon {
    font-size: 1.3rem;
}

.inline-attachment-header .attachment-title {
    flex: 1;
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
}

.inline-attachment-header .attachment-doc-id {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: monospace;
    background: var(--background-dark);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

.inline-attachment-header .attachment-expand-btn {
    font-size: 0.8rem;
    color: var(--accent-color);
    font-weight: 600;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--accent-color);
    border-radius: 4px;
    transition: all 0.2s ease;
}

.inline-attachment-header .attachment-expand-btn:hover {
    background: var(--accent-color);
    color: #000;
}

.inline-attachment-header .attachment-expand-btn.expanded {
    background: var(--accent-color);
    color: #000;
}

.inline-attachment-content {
    border-top: 1px solid var(--border-color);
    background: #525659;
    padding: 0;
}

.inline-pdf-viewer {
    width: 100%;
    height: 85vh;
    min-height: 700px;
    display: block;
    border: none;
}

.inline-pdf-viewer p {
    padding: 2rem;
    text-align: center;
    color: var(--text-primary);
}

.inline-pdf-viewer p a {
    color: var(--accent-color);
}

.pdf-download-link {
    padding: 0.75rem;
    background: var(--surface-color);
    text-align: center;
    border-top: 1px solid var(--border-color);
}

.pdf-download-link a {
    color: var(--accent-color);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--accent-color);
    border-radius: 4px;
    display: inline-block;
    transition: all 0.2s ease;
}

.pdf-download-link a:hover {
    background: var(--accent-color);
    color: #000;
}

/* Documents Reference */
.detail-documents {
    padding: 1.5rem;
    background: var(--surface-color);
}

.documents-title {
    font-size: 1rem;
    color: var(--accent-color);
    margin-bottom: 0.75rem;
}

.documents-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.doc-ref {
    background: var(--background-dark);
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: monospace;
    border: 1px solid var(--border-color);
}

/* Findings Panel (Overlay) */
.findings-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 400px;
    height: 100vh;
    background: var(--background-light);
    border-right: 2px solid var(--accent-color);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.findings-panel.open {
    transform: translateX(0);
}

.findings-header {
    padding: 1rem 1.5rem;
    background: var(--surface-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.findings-header h3 {
    color: var(--accent-color);
}

.close-findings {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.close-findings:hover {
    color: var(--text-primary);
}

.findings-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Context Box */
.detail-context {
    padding: 1.5rem;
    background: rgba(195, 142, 112, 0.1);
    border-right: 4px solid var(--accent-color);
    margin: 1rem;
    border-radius: 8px;
}

.context-title {
    font-size: 0.9rem;
    color: var(--accent-color);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.context-text {
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.9;
    font-family: 'Tajawal', 'Cairo', sans-serif;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Mobile Elements - Hidden on Desktop */
.mobile-menu-btn,
.mobile-close-btn,
.mobile-back-btn,
.sidebar-overlay {
    display: none;
}

/* Responsive */
@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 250px 320px 1fr;
    }
}

@media (max-width: 992px) {
    .main-layout {
        grid-template-columns: 280px 1fr;
        max-height: none;
    }

    .email-detail {
        display: none;
    }

    .email-detail.mobile-active {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100;
        max-height: 100vh;
    }

    .email-list {
        max-height: calc(100vh - 85px);
    }
}

/* Mobile Styles */
@media (max-width: 768px) {
    html {
        font-size: 15px;
    }

    .main-header {
        padding: 1rem;
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }

    .header-content h1 {
        font-size: 1.4rem;
    }

    .header-content .subtitle {
        font-size: 0.85rem;
    }

    .date-range {
        font-size: 0.8rem;
    }

    .main-layout {
        grid-template-columns: 1fr;
        max-height: none;
    }

    /* Mobile Sidebar Toggle */
    .sidebar {
        display: none;
        position: fixed;
        top: 0;
        right: 0;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        z-index: 200;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .sidebar.mobile-open {
        display: block;
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 199;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Mobile Menu Button */
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 1rem;
        right: 1rem;
        width: 48px;
        height: 48px;
        background: var(--surface-color);
        color: var(--accent-color);
        border: 2px solid var(--accent-color);
        border-radius: 12px;
        cursor: pointer;
        z-index: 150;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    }

    .mobile-menu-btn svg {
        width: 24px;
        height: 24px;
    }

    .mobile-menu-btn:active {
        transform: scale(0.95);
        background: var(--accent-color);
        color: #000;
    }

    /* Thread Nav on Mobile - hide globally, show only in mobile detail */
    .thread-nav-buttons {
        display: none !important;
    }

    .thread-nav-buttons.mobile-detail-visible {
        display: flex !important;
        bottom: 1rem;
        padding: 0.4rem;
        gap: 0.3rem;
        z-index: 105;
    }

    .thread-nav-buttons .nav-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .thread-nav-buttons .nav-btn span {
        display: none;
    }

    .thread-nav-buttons .nav-btn svg {
        width: 18px;
        height: 18px;
    }

    .thread-nav-buttons .nav-counter {
        font-size: 0.75rem;
        padding: 0 0.5rem;
        min-width: 50px;
    }

    /* Mobile Close Button */
    .mobile-close-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: var(--danger-color);
        color: #fff;
        border: none;
        border-radius: 50%;
        font-size: 1.2rem;
        cursor: pointer;
        margin: 1rem;
        margin-bottom: 0;
    }

    /* Email List Mobile */
    .email-list {
        max-height: calc(100vh - 140px);
        border-left: none;
    }

    .list-header {
        padding: 0.75rem;
    }

    .list-header h2 {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }

    .search-box input {
        padding: 0.6rem 0.8rem;
        font-size: 0.9rem;
    }

    .threads-container {
        padding: 0.5rem;
    }

    .thread-item {
        margin-bottom: 0.75rem;
    }

    .thread-header {
        padding: 0.75rem;
    }

    .thread-title {
        font-size: 0.9rem;
    }

    .thread-preview {
        font-size: 0.8rem;
        -webkit-line-clamp: 2;
    }

    .thread-tags {
        padding: 0.4rem 0.75rem;
    }

    /* Email Detail Mobile */
    .email-detail {
        display: none;
    }

    .email-detail.mobile-active {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100;
        overflow-y: auto;
    }

    /* Mobile Back Button */
    .mobile-back-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        padding: 1rem;
        background: var(--primary-dark);
        color: var(--accent-color);
        border: none;
        border-bottom: 2px solid var(--accent-color);
        font-family: 'Cairo', 'Tajawal', sans-serif;
        font-size: 1rem;
        font-weight: 600;
        cursor: pointer;
        width: 100%;
        text-align: center;
        position: sticky;
        top: 0;
        z-index: 110;
    }

    .mobile-back-btn:active {
        background: var(--accent-color);
        color: #000;
    }

    .detail-header {
        padding: 1rem;
    }

    .detail-title {
        font-size: 1.1rem;
    }

    .detail-title-row {
        flex-direction: column;
        gap: 0.75rem;
    }

    .share-btn {
        align-self: flex-start;
    }

    .detail-meta {
        flex-wrap: wrap;
        gap: 0.75rem;
        font-size: 0.8rem;
    }

    .detail-participants {
        gap: 0.4rem;
    }

    .participant-badge {
        font-size: 0.75rem;
        padding: 0.3rem 0.6rem;
    }

    .participants-photos {
        gap: 0.75rem;
    }

    .participant-photo-item img {
        width: 50px;
        height: 50px;
    }

    .detail-summary,
    .detail-thread,
    .detail-findings,
    .detail-attachments,
    .detail-documents {
        padding: 1rem;
    }

    .summary-text {
        font-size: 0.95rem;
        line-height: 1.9;
    }

    /* Message Mobile */
    .message-with-photos {
        gap: 0.75rem;
    }

    .msg-photo {
        width: 35px;
        height: 35px;
    }

    .sender-photo-col .msg-photo {
        width: 40px;
        height: 40px;
    }

    .recipient-photos-col {
        display: none;
    }

    .email-message {
        padding: 0.75rem 1rem;
        border-radius: 10px;
    }

    .message-content {
        font-size: 0.9rem;
        line-height: 1.85;
    }

    .message-sender {
        font-size: 0.85rem;
    }

    .message-date {
        font-size: 0.7rem;
    }

    /* Findings Mobile */
    .findings-list li {
        font-size: 0.9rem;
        padding-right: 1.5rem;
    }

    /* Attachments Mobile */
    .inline-pdf-viewer {
        height: 70vh;
        min-height: 400px;
    }

    .attachment-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .attachment-id {
        order: 3;
        width: 100%;
    }

    /* Stats Mobile */
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.4rem;
    }

    .stat-item {
        padding: 0.5rem;
    }

    .stat-value {
        font-size: 1.2rem;
    }

    .stat-label {
        font-size: 0.65rem;
    }

    /* Findings Panel Mobile */
    .findings-panel {
        width: 100%;
    }

    /* Person Buttons Mobile */
    .person-btn {
        padding: 0.6rem 0.75rem;
    }

    .person-headshot {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    /* Tag Buttons Mobile */
    .tag-btn {
        padding: 0.5rem 0.7rem;
        font-size: 0.85rem;
    }
}

/* Very Small Screens */
@media (max-width: 380px) {
    html {
        font-size: 14px;
    }

    .header-content h1 {
        font-size: 1.2rem;
    }

    .thread-title {
        font-size: 0.85rem;
    }

    .detail-title {
        font-size: 1rem;
    }

    .mobile-menu-btn {
        width: 50px;
        height: 50px;
        font-size: 1.3rem;
        bottom: 1rem;
        right: 1rem;
    }
}

/* Thread Navigation Buttons - Only visible in detail view */
.thread-nav-buttons {
    display: none;
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    padding: 0.5rem;
    gap: 0.5rem;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 95;
}

/* Show nav buttons only when thread is selected (desktop) */
.thread-nav-buttons.visible {
    display: flex;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1rem;
    background: var(--primary-dark);
    border: 1px solid var(--border-color);
    border-radius: 25px;
    color: var(--text-primary);
    font-family: 'Cairo', 'Tajawal', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-btn:hover {
    background: var(--primary-color);
    border-color: var(--accent-color);
}

.nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.nav-btn:disabled:hover {
    background: var(--primary-dark);
    border-color: var(--border-color);
}

.nav-btn svg {
    flex-shrink: 0;
}

.nav-counter {
    padding: 0 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: 'Cairo', sans-serif;
    min-width: 60px;
    text-align: center;
}

/* Highlight Text */
.highlight-text {
    background: rgba(244, 114, 182, 0.3);
    padding: 0 0.25rem;
    border-radius: 3px;
}

/* Critical Badge */
.critical-badge {
    background: var(--critical-color);
    color: #fff;
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    margin-right: 0.5rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Thread Links - Cross-references between threads */
.thread-link {
    display: inline-block;
    margin: 0.5rem 0;
    padding: 0.5rem 1rem;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(59, 130, 246, 0.15));
    border: 1px solid var(--accent-color);
    border-radius: 8px;
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
}

.thread-link:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.3), rgba(59, 130, 246, 0.3));
    transform: translateX(-3px);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.thread-link::before {
    content: "🔗 ";
}
