/**
 * Invoice Viewer Modal Component
 * 
 * Mobile-first responsive modal for invoice viewing with optimized layout,
 * print support, and horizontal scroll protection.
 * 
 * @package Silva_Customer_Portal
 * @version 2.6.0
 */

/* ========================================
   MODAL STRUCTURE
   ======================================== */

.invoice-viewer-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}

.invoice-viewer-container {
    background: white;
    border-radius: 12px;
    max-width: 1200px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: scaleIn 0.3s ease-out;
}

/* ========================================
   MODAL HEADER
   ======================================== */

.invoice-viewer-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.invoice-viewer-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #111827;
}

.invoice-viewer-header .close-btn {
    background: #f3f4f6;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.invoice-viewer-header .close-btn:hover {
    background: #e5e7eb;
}

/* ========================================
   MODAL CONTENT
   ======================================== */

.invoice-viewer-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    -webkit-overflow-scrolling: touch;
}

/* Invoice metadata grid - responsive */
.invoice-metadata {
    margin-bottom: 24px;
}

.invoice-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.invoice-meta-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.invoice-meta-label {
    font-size: 13px;
    color: #6b7280;
    font-weight: 500;
}

.invoice-meta-value {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
}

/* Amount card */
.invoice-amount-card {
    background: linear-gradient(135deg, #f9fafb 0%, #ffffff 100%);
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    padding: 24px;
}

.invoice-amount-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.invoice-amount-row.total {
    font-size: 28px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 16px;
}

.invoice-amount-row.balance {
    font-size: 32px;
    font-weight: 800;
    color: #dc2626;
    padding-top: 16px;
    border-top: 2px dashed #e5e7eb;
}

.invoice-paid-badge {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 16px;
    background: #d1fae5;
    border-radius: 0 0 10px 10px;
    margin: 16px -24px -24px -24px;
    border-top: 2px solid #d1fae5;
}

/* ========================================
   LINE ITEMS TABLE
   ======================================== */

.invoice-breakdown-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

.invoice-breakdown-table thead {
    background: #f9fafb;
}

.invoice-breakdown-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.invoice-breakdown-table td {
    padding: 16px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 15px;
    color: #374151;
}

.invoice-breakdown-table tr:last-child td {
    border-bottom: none;
}

/* Mobile: Card-based layout for table */
@media (max-width: 768px) {
    .invoice-breakdown-table thead {
        display: none;
    }
    
    .invoice-breakdown-table,
    .invoice-breakdown-table tbody,
    .invoice-breakdown-table tr {
        display: block;
        width: 100%;
    }
    
    .invoice-breakdown-table tr {
        margin-bottom: 16px;
        background: #f9fafb;
        border-radius: 8px;
        padding: 16px;
        border: 1px solid #e5e7eb;
    }
    
    .invoice-breakdown-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border: none;
    }
    
    .invoice-breakdown-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6b7280;
        font-size: 13px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
}

/* Horizontal scroll protection */
.invoice-breakdown-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ========================================
   PAYMENT HISTORY
   ======================================== */

.invoice-payment-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0;
}

.invoice-payment-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.invoice-payment-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.invoice-payment-details {
    flex: 1;
}

.invoice-payment-method {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 4px;
}

.invoice-payment-date {
    font-size: 13px;
    color: #6b7280;
}

.invoice-payment-amount {
    font-size: 16px;
    font-weight: 700;
    color: #059669;
}

/* ========================================
   MODAL FOOTER
   ======================================== */

.invoice-viewer-footer {
    padding: 16px 24px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    flex-shrink: 0;
}

.invoice-viewer-footer button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 48px;
}

.invoice-viewer-footer .btn-close {
    background: #f3f4f6;
    color: #374151;
}

.invoice-viewer-footer .btn-close:hover {
    background: #e5e7eb;
}

.invoice-viewer-footer .btn-download {
    background: #10b981;
    color: white;
}

.invoice-viewer-footer .btn-download:hover {
    background: #059669;
}

.invoice-viewer-footer .btn-print {
    background: #3b82f6;
    color: white;
}

.invoice-viewer-footer .btn-print:hover {
    background: #2563eb;
}

/* ========================================
   MOBILE OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) {
    .invoice-viewer-modal {
        padding: 0;
    }
    
    .invoice-viewer-container {
        border-radius: 0;
        max-width: 100%;
        max-height: 100vh;
        height: 100vh;
        animation: slideUp 0.3s ease-out;
    }
    
    .invoice-viewer-header {
        padding: 16px;
    }
    
    .invoice-viewer-header h3 {
        font-size: 16px;
    }
    
    .invoice-viewer-header .close-btn {
        width: 44px;
        height: 44px;
    }
    
    .invoice-viewer-content {
        padding: 16px;
    }
    
    .invoice-meta-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .invoice-amount-card {
        padding: 20px;
    }
    
    .invoice-amount-row.total {
        font-size: 24px;
    }
    
    .invoice-amount-row.balance {
        font-size: 28px;
    }
    
    .invoice-viewer-footer {
        padding: 16px;
        gap: 8px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
    
    .invoice-viewer-footer button {
        flex: 1;
        padding: 14px 20px;
    }
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    .invoice-viewer-modal {
        position: static;
        background: white;
        padding: 0;
    }
    
    .invoice-viewer-container {
        box-shadow: none;
        max-height: none;
        max-width: none;
        border-radius: 0;
    }
    
    .invoice-viewer-header,
    .invoice-viewer-footer {
        display: none;
    }
    
    .invoice-viewer-content {
        padding: 0;
        overflow: visible;
    }
    
    .invoice-breakdown-table {
        page-break-inside: avoid;
    }
    
    /* Reset mobile styles for printing */
    .invoice-breakdown-table thead {
        display: table-header-group !important;
    }
    
    .invoice-breakdown-table tbody {
        display: table-row-group !important;
    }
    
    .invoice-breakdown-table tr {
        display: table-row !important;
        page-break-inside: avoid;
        background: white !important;
        border: none !important;
        padding: 0 !important;
    }
    
    .invoice-breakdown-table td {
        display: table-cell !important;
        border-bottom: 1px solid #e5e7eb !important;
    }
    
    .invoice-breakdown-table td::before {
        display: none !important;
    }
}
