/* ==========================================================================
   Inbox — Email Client Layout
   Two-panel layout: email list (left) + detail view (right)
   ========================================================================== */

/* --------------------------------------------------------------------------
   Container — Full height two-panel split
   -------------------------------------------------------------------------- */
.inbox-container {
    display: flex;
    height: calc(100vh - 64px);
    overflow: hidden;
    background: var(--bg-primary, #fff);
    border-radius: 8px;
    border: 1px solid var(--border-color, #e2e8f0);
}

/* --------------------------------------------------------------------------
   Left Panel — Email List
   -------------------------------------------------------------------------- */
.inbox-list-panel {
    width: 380px;
    min-width: 300px;
    max-width: 450px;
    border-right: 1px solid var(--border-color, #e2e8f0);
    display: flex;
    flex-direction: column;
    background: var(--bg-primary, #fff);
}

.inbox-toolbar {
    padding: 16px 16px 0;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    flex-shrink: 0;
}

.inbox-toolbar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.inbox-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
    margin: 0;
}

.inbox-toolbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Search */
.inbox-search {
    position: relative;
    margin-bottom: 12px;
}

.inbox-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary, #94a3b8);
    pointer-events: none;
}

.inbox-search-input {
    width: 100%;
    padding: 8px 12px 8px 34px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg-secondary, #f8fafc);
    color: var(--text-primary, #1e293b);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.inbox-search-input:focus {
    outline: none;
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Folder Tabs */
.inbox-tabs {
    display: flex;
    gap: 0;
    padding-bottom: 0;
}

.inbox-tab {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary, #64748b);
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.inbox-tab:hover {
    color: var(--text-primary, #1e293b);
}

.inbox-tab.active {
    color: var(--primary, #3b82f6);
    border-bottom-color: var(--primary, #3b82f6);
}

.inbox-tab-badge {
    background: var(--danger, #ef4444);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* Email List */
.inbox-email-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.inbox-loading,
.inbox-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--text-tertiary, #94a3b8);
    font-size: 14px;
}

.inbox-loading .spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color, #e2e8f0);
    border-top-color: var(--primary, #3b82f6);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Email List Item */
.inbox-email-item {
    display: flex;
    flex-direction: column;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    cursor: pointer;
    transition: background-color 0.1s;
    position: relative;
}

.inbox-email-item:hover {
    background: var(--bg-hover, #f1f5f9);
}

.inbox-email-item.selected {
    background: var(--primary-bg, #eff6ff);
    border-left: 3px solid var(--primary, #3b82f6);
    padding-left: 13px;
}

.inbox-email-item.unread {
    background: var(--bg-primary, #fff);
}

.inbox-email-item.unread .inbox-item-sender {
    font-weight: 600;
    color: var(--text-primary, #1e293b);
}

.inbox-email-item.unread .inbox-item-subject {
    font-weight: 600;
    color: var(--text-primary, #1e293b);
}

/* Item Row 1: Sender + Time */
.inbox-item-row1 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2px;
    gap: 8px;
}

.inbox-item-sender-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
}

.inbox-item-unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary, #3b82f6);
    flex-shrink: 0;
}

.inbox-item-sender {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary, #64748b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.inbox-item-time {
    font-size: 12px;
    color: var(--text-tertiary, #94a3b8);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Item Row 2: Subject */
.inbox-item-subject {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-primary, #1e293b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

/* Item Row 3: Preview */
.inbox-item-preview {
    font-size: 12px;
    color: var(--text-tertiary, #94a3b8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

/* Item Row 4: Badges */
.inbox-item-badges {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    align-items: center;
}

.inbox-item-badge {
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 4px;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.inbox-item-badge.badge-contact {
    background: #dbeafe;
    color: #1e40af;
}

.inbox-item-badge.badge-deal {
    background: #dcfce7;
    color: #166534;
}

.inbox-item-badge.badge-company {
    background: #fef3c7;
    color: #92400e;
}

.inbox-item-badge.badge-attachment {
    background: var(--bg-secondary, #f1f5f9);
    color: var(--text-secondary, #64748b);
    display: flex;
    align-items: center;
    gap: 3px;
}

.inbox-item-direction {
    font-size: 11px;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--bg-secondary, #f1f5f9);
    color: var(--text-tertiary, #94a3b8);
}

/* Pagination */
.inbox-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 8px 16px;
    border-top: 1px solid var(--border-color, #e2e8f0);
    flex-shrink: 0;
}

.inbox-page-info {
    font-size: 12px;
    color: var(--text-secondary, #64748b);
}

/* --------------------------------------------------------------------------
   Right Panel — Email Detail
   -------------------------------------------------------------------------- */
.inbox-detail-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary, #fff);
}

.inbox-detail-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-tertiary, #94a3b8);
    padding: 40px;
    text-align: center;
}

.inbox-detail-empty h3 {
    margin: 0;
    font-size: 16px;
    color: var(--text-secondary, #64748b);
}

.inbox-detail-empty p {
    margin: 0;
    font-size: 14px;
}

.inbox-detail-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.inbox-back-btn {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--primary, #3b82f6);
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

/* Detail Header */
.inbox-detail-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.inbox-detail-subject {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
    margin: 0 0 12px;
    line-height: 1.3;
}

.inbox-detail-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.inbox-detail-from,
.inbox-detail-to,
.inbox-detail-date {
    font-size: 13px;
    color: var(--text-secondary, #64748b);
}

.inbox-detail-from strong,
.inbox-detail-to strong {
    color: var(--text-primary, #1e293b);
    font-weight: 500;
}

.inbox-detail-actions {
    display: flex;
    gap: 8px;
}

/* Detail Body */
.inbox-detail-body {
    flex: 1;
    padding: 20px 24px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary, #1e293b);
    overflow-y: auto;
}

.inbox-detail-body iframe {
    border: none;
    width: 100%;
    min-height: 200px;
}

.inbox-detail-body img {
    max-width: 100%;
    height: auto;
}

/* Attachments */
.inbox-detail-attachments {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color, #e2e8f0);
}

.inbox-detail-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary, #64748b);
    margin: 0 0 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.inbox-attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.inbox-attachment-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-primary, #1e293b);
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
    cursor: pointer;
}

.inbox-attachment-item:hover {
    background: var(--bg-hover, #f1f5f9);
    border-color: var(--primary, #3b82f6);
}

.inbox-attachment-icon {
    color: var(--text-tertiary, #94a3b8);
    flex-shrink: 0;
}

.inbox-attachment-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inbox-attachment-size {
    font-size: 11px;
    color: var(--text-tertiary, #94a3b8);
    flex-shrink: 0;
}

/* Assignments */
.inbox-detail-assignments {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border-color, #e2e8f0);
}

.inbox-assign-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.inbox-assign-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.inbox-assign-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
}

.inbox-assign-chip.chip-contact {
    background: #dbeafe;
    color: #1e40af;
}

.inbox-assign-chip.chip-deal {
    background: #dcfce7;
    color: #166534;
}

.inbox-assign-chip.chip-company {
    background: #fef3c7;
    color: #92400e;
}

.inbox-assign-chip .chip-remove {
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.15s;
    display: flex;
    align-items: center;
}

.inbox-assign-chip .chip-remove:hover {
    opacity: 1;
}

.inbox-assign-chip .chip-link {
    color: inherit;
    text-decoration: none;
}

.inbox-assign-chip .chip-link:hover {
    text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Assignment Modal
   -------------------------------------------------------------------------- */
.inbox-assign-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

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

.inbox-assign-modal {
    background: var(--bg-primary, #fff);
    border-radius: 12px;
    width: 90%;
    max-width: 440px;
    max-height: 70vh;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.2s ease;
}

@keyframes slideUp {
    from { transform: translateY(16px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.inbox-assign-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.inbox-assign-modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
}

.inbox-assign-modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.inbox-assign-search {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 12px;
    background: var(--bg-secondary, #f8fafc);
    color: var(--text-primary, #1e293b);
}

.inbox-assign-search:focus {
    outline: none;
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.inbox-assign-results {
    max-height: 300px;
    overflow-y: auto;
}

.inbox-assign-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-tertiary, #94a3b8);
    font-size: 13px;
}

.inbox-assign-result-item {
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.inbox-assign-result-item:hover {
    background: var(--bg-hover, #f1f5f9);
}

.inbox-assign-result-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary, #1e293b);
}

.inbox-assign-result-detail {
    font-size: 12px;
    color: var(--text-tertiary, #94a3b8);
}

/* --------------------------------------------------------------------------
   Sync animation
   -------------------------------------------------------------------------- */
.inbox-syncing #inbox-sync-btn svg {
    animation: spin 1s linear infinite;
}

/* --------------------------------------------------------------------------
   Nav badge for sidebar
   -------------------------------------------------------------------------- */
.nav-inbox-badge {
    background: var(--danger, #ef4444);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 8px;
    min-width: 16px;
    text-align: center;
    margin-left: auto;
}

/* --------------------------------------------------------------------------
   Responsive — Mobile
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .inbox-container {
        height: calc(100vh - 56px);
    }

    .inbox-list-panel {
        width: 100%;
        max-width: 100%;
    }

    .inbox-detail-panel {
        position: absolute;
        inset: 0;
        z-index: 10;
        transform: translateX(100%);
        transition: transform 0.25s ease;
    }

    .inbox-container.show-detail .inbox-detail-panel {
        transform: translateX(0);
    }

    .inbox-container.show-detail .inbox-list-panel {
        display: none;
    }

    .inbox-back-btn {
        display: flex;
    }

    .btn-label-desktop {
        display: none;
    }

    .inbox-detail-header {
        padding: 16px;
    }

    .inbox-detail-body {
        padding: 16px;
    }

    .inbox-detail-attachments,
    .inbox-detail-assignments {
        padding: 12px 16px;
    }
}

/* --------------------------------------------------------------------------
   Dark Mode
   -------------------------------------------------------------------------- */
[data-theme="dark"] .inbox-container {
    border-color: var(--border-color);
}

[data-theme="dark"] .inbox-email-item.unread {
    background: var(--bg-secondary);
}

[data-theme="dark"] .inbox-email-item.selected {
    background: rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] .inbox-item-badge.badge-contact {
    background: rgba(59, 130, 246, 0.15);
    color: #93c5fd;
}

[data-theme="dark"] .inbox-item-badge.badge-deal {
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
}

[data-theme="dark"] .inbox-item-badge.badge-company {
    background: rgba(245, 158, 11, 0.15);
    color: #fcd34d;
}

[data-theme="dark"] .inbox-assign-chip.chip-contact {
    background: rgba(59, 130, 246, 0.15);
    color: #93c5fd;
}

[data-theme="dark"] .inbox-assign-chip.chip-deal {
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
}

[data-theme="dark"] .inbox-assign-chip.chip-company {
    background: rgba(245, 158, 11, 0.15);
    color: #fcd34d;
}

[data-theme="dark"] .inbox-assign-modal {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .inbox-attachment-item:hover {
    background: var(--bg-hover);
}
