/* ========================================
   NINJAMAIL — EMAIL INBOX STYLES
   Unified inbox layout and components
   ======================================== */

/* ===== EMAIL SECTION — FULL BLEED ===== */
#section-email.app-section {
    padding: 0;
    max-width: 100%;
    flex-direction: column;
    height: calc(100vh - 49px); /* topbar: 36px min-height + 6px*2 padding + 1px border */
    overflow: hidden;
}

#section-email.app-section.active {
    display: flex;
}

#section-email.app-section:not(.active) {
    display: none;
}

#section-email .section-header-bar {
    display: none;
}

#section-email .email-section-tabs {
    padding: 0 12px;
    flex-shrink: 0;
}

#section-email .email-tab {
    padding: 10px 14px;
}

#section-email .email-tab-content {
    flex: 1;
    overflow: hidden;
}

#section-email .email-tab-content.active {
    display: flex;
    flex-direction: column;
}

#section-email #emailTabInbox.email-tab-content {
    padding: 0;
}

#section-email .email-tab-content:not(#emailTabInbox) {
    padding: var(--spacing-lg);
    overflow-y: auto;
}

#section-email #emailTabInbox {
    flex: 1;
    overflow: hidden;
}

#section-email #inboxContainer {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Resend stats — compact inline in tabs bar */
.email-tabs-wrapper {
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-card);
    flex-shrink: 0;
}

.email-tabs-wrapper .email-section-tabs {
    flex: 1;
    border-bottom: none;
}

.email-usage-inline {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
    white-space: nowrap;
}

.email-usage-inline .usage-stat {
    display: flex;
    align-items: center;
    gap: 4px;
}

.email-usage-inline .usage-stat .stat-value {
    font-weight: 700;
    color: var(--text-secondary);
}

.email-usage-inline .usage-bar {
    width: 40px;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    overflow: hidden;
}

.email-usage-inline .usage-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s;
}

.email-usage-inline .plan-badge {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
}

/* ===== LAYOUT ===== */
.inbox-layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    flex: 1;
    background: var(--bg-card);
    border-top: 1px solid var(--border-light);
    overflow: hidden;
}

/* ===== SIDEBAR ===== */
.inbox-sidebar {
    background: var(--bg-card);
    border-right: 1px solid var(--border-light);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.inbox-compose-btn {
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.15s;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    font-family: inherit;
}

.inbox-compose-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.inbox-folders {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.inbox-folder-item {
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
}

.inbox-folder-item:hover {
    background: var(--bg-body);
}

.inbox-folder-item.active {
    background: #eef2ff;
    color: var(--primary);
    font-weight: 600;
}

.inbox-folder-label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
}

.inbox-folder-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.inbox-folder-count {
    font-size: 11px;
    background: var(--bg-body);
    border-radius: 10px;
    padding: 2px 8px;
    color: var(--text-muted);
    font-weight: 600;
    flex-shrink: 0;
}

.inbox-folder-item.active .inbox-folder-count {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
}

/* ===== MAIN AREA ===== */
.inbox-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ===== TOOLBAR ===== */
.inbox-toolbar {
    display: flex;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    gap: 8px;
    align-items: center;
}

.inbox-search {
    flex: 1;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    background: var(--bg-card);
    color: var(--text-primary);
    transition: border-color 0.15s;
    outline: none;
}

.inbox-search:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.inbox-search::placeholder {
    color: var(--text-muted);
}

/* ===== SELECT ALL + BULK ACTIONS ===== */
.inbox-select-all {
    display: flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.inbox-select-all input[type="checkbox"],
.inbox-thread-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #667eea;
    margin: 0;
}

.inbox-thread-checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.inbox-bulk-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.inbox-bulk-btn {
    background: none;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

.inbox-bulk-btn:hover {
    border-color: #667eea;
    color: #667eea;
    background: #eef2ff;
}

.inbox-bulk-count {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    margin-left: 4px;
}

/* ===== THREAD LIST ===== */
.inbox-thread-list {
    flex: 1;
    overflow-y: auto;
}

.inbox-thread-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    display: grid;
    grid-template-columns: 24px 24px 180px 1fr auto;
    gap: 8px;
    align-items: center;
    transition: background 0.1s;
}

.inbox-thread-item.selected {
    background: #eef2ff;
}

.inbox-thread-item:hover {
    background: #f8fafc;
}

.inbox-thread-item:last-child {
    border-bottom: none;
}

.inbox-thread-item.unread {
    font-weight: 600;
    border-left: 3px solid var(--primary);
}

/* ===== STAR BUTTON ===== */
.inbox-star-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    opacity: 0.3;
    padding: 0;
    line-height: 1;
    transition: opacity 0.15s;
    color: #d97706;
}

.inbox-star-btn:hover {
    opacity: 0.7;
}

.inbox-star-btn.active {
    opacity: 1;
}

/* ===== THREAD ITEM PARTS ===== */
.inbox-thread-sender {
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}

.inbox-thread-content {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.inbox-thread-subject {
    font-size: 13px;
    color: var(--text-primary);
}

.inbox-thread-snippet {
    font-size: 12px;
    color: var(--text-muted);
}

.inbox-thread-meta {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

.inbox-thread-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.inbox-msg-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    font-size: 10px;
    font-weight: 700;
    background: var(--bg-body);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
}

/* ===== BADGES ===== */
.inbox-badge {
    display: inline-flex;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
}

.inbox-badge.campaign {
    background: #fef3c7;
    color: #b45309;
}

/* Tab unread badge */
.inbox-count-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    border-radius: 10px;
    min-width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    line-height: 1;
}

/* ===== PAGINATION ===== */
.inbox-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-top: 1px solid var(--border-light);
    font-size: 12px;
    color: var(--text-muted);
}

.inbox-page-btn {
    padding: 6px 14px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: var(--bg-card);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.inbox-page-btn:hover {
    border-color: #667eea;
    color: #667eea;
}

.inbox-page-info {
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== EMPTY STATE ===== */
.inbox-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.inbox-empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.inbox-empty-text {
    font-size: 14px;
}

/* ===== LOADING STATE ===== */
.inbox-loading {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.inbox-loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-light);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: inboxSpin 0.8s linear infinite;
}

@keyframes inboxSpin {
    to { transform: rotate(360deg); }
}

/* ===== THREAD DETAIL VIEW ===== */
.inbox-thread-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
}

.inbox-back-btn {
    background: none;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.15s;
    font-family: inherit;
}

.inbox-back-btn:hover {
    border-color: #667eea;
    color: #667eea;
}

.inbox-thread-actions {
    display: flex;
    gap: 4px;
}

.inbox-thread-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    opacity: 0.6;
    transition: opacity 0.15s;
    border-radius: 6px;
}

.inbox-thread-actions button:hover {
    opacity: 1;
    background: var(--bg-body);
}

.inbox-thread-subject-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    padding: 16px 16px 8px;
    margin: 0;
}

/* ===== MESSAGES ===== */
.inbox-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.inbox-message-card {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-light);
    overflow: hidden;
}

.inbox-message-card.outbound {
    background: #f8fafc;
}

.inbox-message-header {
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
    font-size: 12px;
    color: var(--text-secondary);
}

.inbox-message-sender {
    font-weight: 600;
    color: var(--text-primary);
}

.inbox-message-date {
    color: var(--text-muted);
}

.inbox-message-body {
    padding: 16px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.inbox-message-body img {
    max-width: 100%;
    height: auto;
}

/* ===== REPLY BOX ===== */
.inbox-reply-box {
    margin: 0 16px 16px;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    overflow: hidden;
}

.inbox-reply-box textarea {
    width: 100%;
    min-height: 120px;
    border: none;
    padding: 12px 16px;
    resize: vertical;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-card);
    outline: none;
    box-sizing: border-box;
}

.inbox-reply-box textarea::placeholder {
    color: var(--text-muted);
}

.inbox-reply-actions {
    padding: 8px 16px;
    display: flex;
    justify-content: flex-end;
    background: #f8fafc;
    border-top: 1px solid var(--border-light);
}

/* ===== SEND BUTTON ===== */
.inbox-send-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: opacity 0.15s;
    font-family: inherit;
}

.inbox-send-btn:hover {
    opacity: 0.9;
}

/* ===== COMPOSE MODAL ===== */
.inbox-compose-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.inbox-compose-modal {
    background: var(--bg-card);
    border-radius: 16px;
    width: 600px;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.inbox-compose-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
}

.inbox-compose-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

.inbox-compose-close:hover {
    background: var(--bg-body);
    color: var(--text-primary);
}

.inbox-compose-body {
    padding: 16px 20px;
    flex: 1;
    overflow-y: auto;
}

.inbox-compose-field {
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.inbox-compose-field label {
    width: 60px;
    font-size: 12px;
    color: var(--text-secondary);
    text-align: right;
    flex-shrink: 0;
    font-weight: 500;
}

.inbox-compose-field input,
.inbox-compose-field select {
    flex: 1;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-card);
    outline: none;
    transition: border-color 0.15s;
}

.inbox-compose-field input:focus,
.inbox-compose-field select:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.inbox-compose-body > textarea {
    width: 100%;
    min-height: 200px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    resize: vertical;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-card);
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.15s;
}

.inbox-compose-body > textarea:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.inbox-compose-body > textarea::placeholder {
    color: var(--text-muted);
}

.inbox-compose-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
}

/* ===== AUTOCOMPLETE ===== */
.inbox-autocomplete {
    position: absolute;
    top: 100%;
    left: 68px;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.inbox-autocomplete.show {
    display: block;
}

.inbox-autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    transition: background 0.1s;
}

.inbox-autocomplete-item:hover {
    background: var(--bg-body);
}

.inbox-autocomplete-item:first-child {
    border-radius: 8px 8px 0 0;
}

.inbox-autocomplete-item:last-child {
    border-radius: 0 0 8px 8px;
}

.inbox-autocomplete-name {
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inbox-autocomplete-email {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ===== RESPONSIVE (max-width: 768px) ===== */
@media (max-width: 768px) {
    .inbox-layout {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .inbox-sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border-light);
        padding: 12px;
        gap: 8px;
    }

    .inbox-compose-btn {
        padding: 8px 16px;
        font-size: 12px;
    }

    .inbox-folders {
        flex-direction: row;
        overflow-x: auto;
        gap: 4px;
        -webkit-overflow-scrolling: touch;
    }

    .inbox-folder-item {
        padding: 6px 12px;
        border-radius: 20px;
        background: var(--bg-body);
        white-space: nowrap;
        flex-shrink: 0;
        font-size: 12px;
    }

    .inbox-folder-item.active {
        background: #eef2ff;
    }

    .inbox-thread-item {
        grid-template-columns: 24px 24px 1fr auto;
        gap: 6px;
        padding: 10px 12px;
    }

    /* Hide snippet on mobile, sender takes content column */
    .inbox-thread-sender {
        display: none;
    }

    .inbox-thread-content {
        grid-column: 3;
    }

    .inbox-thread-snippet {
        display: none;
    }

    .inbox-compose-modal {
        width: 95vw;
        max-height: 90vh;
        border-radius: 12px;
    }

    .inbox-compose-field {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }

    .inbox-compose-field label {
        width: auto;
        text-align: left;
    }

    .inbox-thread-subject-title {
        font-size: 16px;
        padding: 12px 12px 8px;
    }

    .inbox-messages {
        padding: 12px;
        gap: 12px;
    }

    .inbox-reply-box {
        margin: 0 12px 12px;
    }

    .inbox-autocomplete {
        left: 0;
    }

    .email-usage-inline {
        display: none;
    }

    .email-tabs-wrapper {
        flex-wrap: wrap;
    }
}
