/**
 * Upload History Styling
 * Clean, modern design for upload tracking
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Upload History Wrapper - Integrated into main app */
.upload-history-wrapper {
    width: 100%;
    max-width: 100%;
}

.header-controls {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 24px;
}

/* Search Input */
.search-input {
    padding: 10px 16px;
    border: 2px solid #E5E7EB;
    border-radius: 6px;
    width: 300px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: #3B82F6;
}

/* Upload List */
.upload-history-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Upload Card */
.upload-card {
    background: white;
    border: 2px solid #E5E7EB;
    border-radius: 8px;
    padding: 20px;
    transition: all 0.2s;
}

.upload-card:hover {
    border-color: #3B82F6;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.upload-card.status-processing {
    border-left: 4px solid #F59E0B;
}

.upload-card.status-completed {
    border-left: 4px solid #10B981;
}

.upload-card.status-failed {
    border-left: 4px solid #EF4444;
}

/* Upload Card Header */
.upload-card-header {
    margin-bottom: 16px;
}

.filename-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 16px;
}

.filename-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filename {
    font-weight: 600;
    font-size: 16px;
    color: #111827;
    word-break: break-word;
}

.session-id {
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    color: #6B7280;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.status-badge.status-processing {
    background: #FEF3C7;
    color: #92400E;
}

.status-badge.status-completed {
    background: #D1FAE5;
    color: #065F46;
}

.status-badge.status-failed {
    background: #FEE2E2;
    color: #991B1B;
}

.metadata-row {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: #6B7280;
    flex-wrap: wrap;
}

/* Upload Stats */
.upload-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat {
    background: #F9FAFB;
    padding: 12px;
    border-radius: 6px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 12px;
    color: #6B7280;
    margin-bottom: 4px;
}

.stat-value {
    display: block;
    font-size: 20px;
    font-weight: 700;
    color: #111827;
}

.stat.stat-success .stat-value {
    color: #10B981;
}

.stat.stat-warning .stat-value {
    color: #F59E0B;
}

.stat.stat-danger .stat-value {
    color: #EF4444;
}

.stat.stat-unknown .stat-value {
    color: #F97316; /* Orange for unknown watches */
    font-weight: 800;
}

/* Error Message */
.error-message {
    background: #FEE2E2;
    border: 1px solid #FCA5A5;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 16px;
    font-size: 14px;
    color: #991B1B;
}

.error-message strong {
    font-weight: 600;
}

/* Upload Actions */
.upload-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: #3B82F6;
    color: white;
}

.btn-primary:hover {
    background: #2563EB;
}

.btn-secondary {
    background: #F3F4F6;
    color: #374151;
}

.btn-secondary:hover {
    background: #E5E7EB;
}

.btn-danger {
    background: #EF4444;
    color: white;
}

.btn-danger:hover {
    background: #DC2626;
}

/* Load More Button */
.load-more-btn {
    width: 100%;
    padding: 12px;
    margin-top: 24px;
    background: white;
    border: 2px dashed #D1D5DB;
    border-radius: 6px;
    color: #6B7280;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.load-more-btn:hover {
    border-color: #3B82F6;
    color: #3B82F6;
}

/* Loading and Empty States */
.loading,
.empty-state,
.error {
    text-align: center;
    padding: 60px 20px;
    color: #9CA3AF;
    font-size: 16px;
}

.error {
    color: #EF4444;
}

/* Modal Styles */
.upload-history-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 2px solid #E5E7EB;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #111827;
}

.modal-close {
    background: none;
    border: none;
    font-size: 32px;
    line-height: 1;
    color: #6B7280;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #111827;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

/* Session Details Modal */
.session-details-modal {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.session-info {
    background: #F9FAFB;
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.info-label {
    font-weight: 600;
    color: #6B7280;
}

.info-value {
    color: #111827;
    font-weight: 500;
}

.info-value.status-completed {
    color: #10B981;
}

.info-value.status-processing {
    color: #F59E0B;
}

.info-value.status-failed {
    color: #EF4444;
}

.messages-container h3 {
    font-size: 16px;
    font-weight: 700;
    color: #111827;
    margin: 0 0 16px 0;
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
}

.message-item {
    background: #F9FAFB;
    border: 2px solid #E5E7EB;
    border-radius: 8px;
    padding: 12px;
    transition: all 0.2s;
}

.message-item:hover {
    border-color: #D1D5DB;
}

.message-item.has-extraction {
    border-left: 4px solid #10B981;
    background: #F0FDF4;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.message-sender {
    font-weight: 600;
    color: #111827;
}

.message-time {
    font-size: 12px;
    color: #6B7280;
}

.message-content {
    color: #374151;
    line-height: 1.5;
    word-break: break-word;
}

.extraction-badge {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 8px;
    background: #D1FAE5;
    color: #065F46;
    font-size: 12px;
    font-weight: 600;
    border-radius: 4px;
}

/* Enhanced Session Details Modal Styles */
.enhanced-session-details {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.details-section {
    background: #F9FAFB;
    border-radius: 8px;
    padding: 20px;
}

.details-section h3 {
    margin: 0 0 16px 0;
    font-size: 18px;
    font-weight: 700;
    color: #111827;
}

.details-section h4 {
    margin: 16px 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: #6B7280;
}

/* Overview Section */
.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-label {
    font-size: 12px;
    font-weight: 600;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-value {
    font-size: 14px;
    font-weight: 500;
    color: #111827;
}

.detail-value.monospace {
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

/* Statistics Section */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: white;
    border: 2px solid #E5E7EB;
    border-radius: 8px;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-card.stat-success {
    border-color: #10B981;
}

.stat-card.stat-warning {
    border-color: #F59E0B;
}

.stat-card.stat-danger {
    border-color: #EF4444;
}

.stat-details {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #111827;
}

.stat-card .stat-label {
    font-size: 12px;
    color: #6B7280;
}

/* Confidence Breakdown */
.confidence-breakdown {
    background: white;
    border-radius: 8px;
    padding: 16px;
}

.confidence-bars {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.confidence-bar-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.confidence-bar-header {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}

.confidence-label {
    font-weight: 600;
    color: #374151;
}

.confidence-count {
    font-weight: 500;
    color: #6B7280;
}

.confidence-bar-track {
    height: 8px;
    background: #E5E7EB;
    border-radius: 4px;
    overflow: hidden;
}

.confidence-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Extractions Section */
.extractions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.extractions-header h3 {
    margin: 0;
}

.btn-view-full-chat {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.2);
}

.btn-view-full-chat:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(16, 185, 129, 0.3);
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
}

.btn-view-full-chat:active {
    transform: translateY(0);
}

.extractions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
}

.extraction-header {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 8px;
}

.extraction-number {
    font-weight: 700;
    color: #6B7280;
}

.extraction-status {
    font-size: 18px;
}

.extraction-status.approved {
    color: #10B981;
}

.extraction-status.review {
    color: #F59E0B;
}

.extraction-status.pending {
    color: #9CA3AF;
}

.extraction-status.failed {
    color: #EF4444;
}

.extraction-item-compact.extraction-failed {
    background: #FEF2F2;
    border-left: 3px solid #EF4444;
}

.extraction-failure-reason {
    color: #DC2626;
    font-size: 13px;
    background: #FEE2E2;
    padding: 8px;
    border-radius: 4px;
    line-height: 1.5;
}

.extraction-failure-reason strong {
    color: #991B1B;
}

.extraction-confidence {
    font-weight: 700;
    font-size: 14px;
    margin-left: auto;
}

.extraction-details {
    display: flex;
    gap: 24px;
    margin-bottom: 8px;
    font-size: 13px;
}

/* Enterprise-grade expandable message UI */
.view-full-message-top {
    margin: 12px 0;
    text-align: right;
}

.message-content-wrapper {
    margin-top: 8px;
}

.message-text {
    background-color: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 6px;
    padding: 12px;
    margin: 8px 0;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #374151;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-x: auto;
}

.message-text.full-message {
    max-height: 600px;
    overflow-y: auto;
    border-left: 3px solid #3B82F6;
    background-color: #FFFFFF;
}

.btn-view-full-message {
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}

.btn-view-full-message:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.3);
    background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
}

.btn-view-full-message:active {
    transform: translateY(0);
}

/* Large Modal for Full Messages */
.large-modal {
    max-width: 1000px;
    width: 95%;
    max-height: 85vh;
}

.message-stats {
    font-size: 12px;
    color: #6B7280;
    font-weight: 500;
    margin-top: 4px;
}

.full-message-container {
    background: #F9FAFB;
    border: 2px solid #E5E7EB;
    border-radius: 8px;
    padding: 0;
    max-height: calc(85vh - 180px);
    overflow-y: auto;
}

.full-message-text {
    background: #FFFFFF;
    padding: 20px;
    margin: 0;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #111827;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-x: auto;
    min-height: 200px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px;
    border-top: 2px solid #E5E7EB;
    background: #F9FAFB;
}

.load-more-notice {
    text-align: center;
    padding: 12px;
    background: #FEF3C7;
    border: 1px solid #FCD34D;
    border-radius: 6px;
    color: #92400E;
    font-size: 13px;
    font-weight: 600;
    margin-top: 12px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .upload-history-container {
        padding: 16px;
    }

    .upload-history-header h1 {
        font-size: 24px;
    }

    .header-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-buttons {
        justify-content: center;
    }

    .search-input {
        width: 100%;
    }

    .upload-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .filename-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .upload-actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .modal-container {
        width: 95%;
        max-height: 95vh;
    }

    .modal-header {
        padding: 16px;
    }

    .modal-body {
        padding: 16px;
    }
}

/* Message Group Styles - Grouped extractions by message */
.message-group {
    background: white;
    border: 2px solid #E5E7EB;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.message-group:last-child {
    margin-bottom: 0;
}

.message-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.message-group-header strong {
    font-size: 14px;
    color: #374151;
}

.extraction-count-badge {
    background: #DBEAFE;
    color: #1E40AF;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.extractions-under-message {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #E5E7EB;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Compact Extraction Item - No duplicate message */
.extraction-item-compact {
    background: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 6px;
    padding: 12px;
    transition: all 0.2s;
}

.extraction-item-compact:hover {
    background: #F3F4F6;
    border-color: #D1D5DB;
}

.extraction-item-compact .extraction-header {
    margin-bottom: 8px;
}

.extraction-item-compact .extraction-details {
    display: flex;
    gap: 24px;
    font-size: 13px;
    color: #374151;
}

.extraction-item-compact .extraction-watch,
.extraction-item-compact .extraction-price {
    flex: 1;
}

/* Processing Progress Styles */
.processing-progress {
    margin-bottom: 16px;
}

.progress-info {
    background: #FEF3C7;
    border: 1px solid #FCD34D;
    border-radius: 6px;
    padding: 12px;
}

.progress-text {
    color: #92400E;
    font-size: 14px;
    font-weight: 600;
}

/* Chunk Progress Details */
.chunk-progress-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background: #FEE2E2;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #10B981 0%, #059669 100%);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-stats {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
}

.chunks-progress {
    font-weight: 600;
    color: #374151;
}

.messages-progress {
    color: #6B7280;
}

.failed-chunks {
    font-weight: 600;
}

/* Responsive Progress */
@media (max-width: 768px) {
    .progress-stats {
        font-size: 12px;
    }
}

/* Partial Data Warning Banner */
.partial-data-warning {
    background: #FEF3C7;
    border: 2px solid #FCD34D;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.warning-icon {
    font-size: 24px;
    line-height: 1;
}

.warning-content {
    flex: 1;
}

.warning-content strong {
    display: block;
    font-size: 16px;
    color: #92400E;
    margin-bottom: 6px;
}

.warning-content p {
    margin: 0 0 10px 0;
    color: #78350F;
    font-size: 14px;
    line-height: 1.5;
}

.warning-stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: #92400E;
    font-weight: 600;
}

.warning-stats span {
    display: block;
}
