/**
 * Modal Invoice/BL CSS
 * Système de modal pour afficher le contenu détaillé des factures et BLs
 * Inspiré du système de modal du projet perimes
 */

/* ========================================
 * MODAL BASE STRUCTURE
 * ======================================== */

.modal-invoice {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
}

.modal-invoice.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-invoice-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ========================================
 * MODAL HEADER
 * ======================================== */

.modal-invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 2px solid #e0e0e0;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px 12px 0 0;
}

.modal-invoice-title {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.modal-invoice-title h2 {
    margin: 0;
    color: #2c3e50;
    font-size: 22px;
    font-weight: 700;
}

.modal-invoice-subtitle {
    font-size: 13px;
    color: #7f8c8d;
    font-weight: 400;
}

.modal-invoice-close {
    background: none;
    border: none;
    font-size: 32px;
    font-weight: 300;
    cursor: pointer;
    color: #7f8c8d;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.modal-invoice-close:hover {
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
    transform: scale(1.1);
}

/* ========================================
 * MODAL BODY
 * ======================================== */

.modal-invoice-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

/* ========================================
 * DOCUMENT HEADER (Infos fournisseur/date)
 * ======================================== */

.document-info-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.info-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.info-block-label {
    font-size: 12px;
    font-weight: 600;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-block-value {
    font-size: 16px;
    font-weight: 600;
    color: #2c3e50;
}

.info-block-value.highlight {
    color: #2E7D32;
    font-size: 18px;
}

/* ========================================
 * PRODUCTS TABLE
 * ======================================== */

.products-section {
    margin-bottom: 30px;
}

.products-section h3 {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 700;
    color: #2c3e50;
    display: flex;
    align-items: center;
    gap: 8px;
}

.products-section h3::before {
    content: "📦";
    font-size: 18px;
}

.products-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
}

.products-table thead {
    background: #34495e;
    color: white;
}

.products-table th {
    padding: 12px 8px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.products-table th.text-right {
    text-align: right;
}

.products-table tbody tr {
    border-bottom: 1px solid #ecf0f1;
    transition: background-color 0.2s ease;
}

.products-table tbody tr:last-child {
    border-bottom: none;
}

.products-table tbody tr:hover {
    background: #f8f9fa;
}

.products-table td {
    padding: 12px 8px;
    font-size: 13px;
    color: #2c3e50;
}

.products-table td.text-right {
    text-align: right;
    font-weight: 600;
}

.product-designation {
    font-weight: 600;
    color: #2c3e50;
    line-height: 1.4;
}

.product-codes {
    font-size: 11px;
    color: #7f8c8d;
    margin-top: 4px;
    font-family: 'Courier New', monospace;
}

.discount-badge {
    display: inline-block;
    padding: 2px 8px;
    background: #fff3cd;
    color: #856404;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

/* ========================================
 * TOTALS SECTION
 * ======================================== */

.totals-section {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-top: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px solid #e0e0e0;
}

.total-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-width: 300px;
    padding: 8px 0;
    font-size: 15px;
}

.total-line.main {
    border-top: 2px solid #34495e;
    margin-top: 8px;
    padding-top: 16px;
}

.total-label {
    font-weight: 600;
    color: #2c3e50;
}

.total-line.main .total-label {
    font-size: 18px;
    color: #2E7D32;
}

.total-value {
    font-weight: 700;
    color: #2c3e50;
}

.total-line.main .total-value {
    font-size: 22px;
    color: #2E7D32;
}

/* ========================================
 * DEDUCTION LINE (gratuits/remises)
 * ======================================== */

.total-line.deduction {
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    margin: 4px -12px;
    padding: 8px 12px;
    border-radius: 6px;
}

.total-line.deduction .total-label {
    color: #059669;
    font-style: italic;
}

.total-line.deduction .total-value {
    color: #059669;
}

.text-success {
    color: #059669 !important;
    font-weight: 700;
}

.total-separator {
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, #d1d5db, transparent);
    margin: 8px 0;
}

/* ========================================
 * EMPTY STATE
 * ======================================== */

.products-empty {
    text-align: center;
    padding: 40px 20px;
    color: #7f8c8d;
}

.products-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

/* ========================================
 * RESPONSIVE - MOBILE
 * ======================================== */

@media (max-width: 768px) {
    .modal-invoice {
        padding: 10px;
    }
    
    .modal-invoice-content {
        max-width: 100%;
        max-height: calc(100vh - 20px);
        border-radius: 8px;
    }
    
    .modal-invoice-header {
        padding: 16px;
    }
    
    .modal-invoice-title h2 {
        font-size: 18px;
    }
    
    .modal-invoice-body {
        padding: 16px;
    }
    
    .document-info-header {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 16px;
    }
    
    .products-table {
        font-size: 12px;
    }
    
    .products-table th,
    .products-table td {
        padding: 8px 6px;
    }
    
    /* Masquer certaines colonnes sur mobile */
    .products-table .hide-mobile {
        display: none;
    }
    
    .total-line {
        min-width: 100%;
        font-size: 14px;
    }
    
    .total-line.main .total-label,
    .total-line.main .total-value {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .modal-invoice-header {
        padding: 12px;
    }
    
    .modal-invoice-title h2 {
        font-size: 16px;
    }
    
    .modal-invoice-subtitle {
        font-size: 11px;
    }
    
    .modal-invoice-body {
        padding: 12px;
    }
    
    .document-info-header {
        padding: 12px;
    }
    
    .info-block-label {
        font-size: 10px;
    }
    
    .info-block-value {
        font-size: 14px;
    }
    
    .products-table {
        font-size: 11px;
    }
    
    .products-table th {
        font-size: 10px;
        padding: 8px 4px;
    }
    
    .products-table td {
        padding: 8px 4px;
    }
}

/* ========================================
 * LOADING STATE
 * ======================================== */

.modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #7f8c8d;
}

.modal-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #ecf0f1;
    border-top-color: #2E7D32;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.modal-loading-text {
    font-size: 14px;
    font-weight: 600;
}

/* ========================================
 * CONFIDENCE INDICATORS
 * ======================================== */

.confidence-high {
    color: #22c55e !important;
    font-weight: 700;
}

.confidence-medium {
    color: #f59e0b !important;
    font-weight: 700;
}

.confidence-low {
    color: #ef4444 !important;
    font-weight: 700;
}

/* ========================================
 * VALIDATION WARNING
 * ======================================== */

.validation-warning {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 1px solid #f59e0b;
    border-left: 4px solid #f59e0b;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 13px;
    font-weight: 500;
    color: #92400e;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ========================================
 * VAT VALIDATION WARNING (TVA validée)
 * ======================================== */

.validation-warning.vat-warning {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
    border-color: #22c55e;
    border-left-color: #22c55e;
    color: #166534;
    flex-direction: row;
    align-items: flex-start;
}

.validation-warning .warning-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.validation-warning .warning-content {
    flex: 1;
}

.validation-warning .warning-content strong {
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
}

/* ========================================
 * VAT DETAILS (Détails TVA)
 * ======================================== */

.vat-details {
    margin-top: 12px;
}

.vat-details summary {
    cursor: pointer;
    font-size: 12px;
    color: #166534;
    font-weight: 600;
    padding: 4px 0;
}

.vat-details summary:hover {
    text-decoration: underline;
}

.vat-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 8px;
    background: white;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid #e0e0e0;
}

.vat-table th,
.vat-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #e0e0e0;
}

.vat-table thead {
    background: #f0fdf4;
}

.vat-table th {
    font-weight: 600;
    color: #166534;
    font-size: 11px;
    text-transform: uppercase;
}

.vat-table tbody tr.vat-match {
    background: rgba(34, 197, 94, 0.1);
}

.vat-table tbody tr.vat-mismatch {
    background: rgba(239, 68, 68, 0.1);
}

.vat-table tfoot {
    background: #f0fdf4;
    font-weight: 700;
}

.vat-table tfoot td {
    border-bottom: none;
}

.vat-table .text-right {
    text-align: right;
}

.vat-table .text-center {
    text-align: center;
}
