/**
 * Invoice Generator Styles
 * Professional invoice generator with PayNow QR integration
 */

/* ========================================
   1. CSS VARIABLES (inherit from global)
   ======================================== */
:root {
    --paynow-purple: #7d1979;
    --paynow-purple-hover: #6a1567;
    --paynow-purple-light: #f9f5ff;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-900: #111827;
}

/* ========================================
   2. HERO SECTION (full-width like WooCommerce v2)
   ======================================== */
.invoice-hero-section {
    width: 100vw;
    margin-left: calc(-50vw + 50%);
    padding-left: calc(50vw - 50%);
    padding-right: calc(50vw - 50%);
    background: linear-gradient(to bottom, var(--paynow-purple-light), #ffffff);
    padding-top: 3rem;
    padding-bottom: 3rem;
    text-align: center;
}

.invoice-hero-section h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 1rem;
}

.invoice-hero-section .lead {
    font-size: 1.125rem;
    color: var(--gray-700);
    margin-bottom: 0;
}

/* ========================================
   3. FORM STYLES
   ======================================== */
.invoice-generator-section {
    background: var(--gray-50);
    width: 100vw;
    margin-left: calc(-50vw + 50%);
    padding-left: calc(50vw - 50%);
    padding-right: calc(50vw - 50%);
    padding-top: 2rem;
    padding-bottom: 2rem;
}

.invoice-form-wrapper {
    background: white;
    border-radius: 0.5rem;
    padding: 1.5rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

.form-heading {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 1.5rem;
}

.sticky-form {
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.form-section {
    border-bottom: 1px solid var(--gray-200);
    padding-bottom: 1rem;
}

.form-section:last-of-type {
    border-bottom: none;
}

.form-section-title {
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--paynow-purple);
    box-shadow: 0 0 0 0.25rem rgba(125, 25, 121, 0.15);
}

.form-check-input:checked {
    background-color: var(--paynow-purple);
    border-color: var(--paynow-purple);
}

/* Line Items */
.line-item {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.line-item .form-control {
    background: white;
    padding: 0.375rem 0.5rem;
    font-size: 0.875rem;
}

.line-item .item-qty {
    text-align: center;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
}

.line-item .remove-item-btn {
    color: #dc2626;
    border: none;
    background: transparent;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

.line-item .remove-item-btn:hover {
    opacity: 0.7;
}

/* Totals Container */
.totals-container {
    border: 2px solid var(--paynow-purple-light);
}

/* Buttons */
#generate-invoice-btn {
    background-color: var(--paynow-purple);
    border-color: var(--paynow-purple);
    font-weight: 600;
}

#generate-invoice-btn:hover {
    background-color: var(--paynow-purple-hover);
    border-color: var(--paynow-purple-hover);
}

#add-item-btn {
    border-color: var(--paynow-purple);
    color: var(--paynow-purple);
}

#add-item-btn:hover {
    background-color: var(--paynow-purple);
    color: white;
}

/* ========================================
   4. INVOICE PREVIEW STYLES
   ======================================== */
.invoice-preview-wrapper {
    position: sticky;
    top: 20px;
}

.invoice-preview-container {
    background: #e5e7eb;
    padding: 1.5rem;
    border-radius: 0.5rem;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.invoice-preview {
    background: white;
    padding: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    min-height: 600px;
    font-size: 12px;
    transform: scale(0.85);
    transform-origin: top left;
    width: 117.65%; /* 100% / 0.85 to compensate for scale */
}

/* Invoice Header */
.invoice-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--paynow-purple);
}

.invoice-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--paynow-purple);
    margin: 0;
}

.invoice-number-display {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-700);
}

/* Parties Section */
.invoice-parties {
    margin-bottom: 1.5rem;
}

.party-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--gray-600);
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.party-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--gray-900);
    margin-bottom: 0.25rem;
}

.party-details {
    font-size: 0.875rem;
    color: var(--gray-600);
    white-space: pre-line;
}

/* Dates Section */
.invoice-dates {
    margin-bottom: 1.5rem;
    padding: 0.75rem;
    background: var(--gray-50);
    border-radius: 0.25rem;
}

.date-label {
    font-weight: 600;
    color: var(--gray-700);
}

/* Items Table */
.invoice-items-table {
    margin-bottom: 1.5rem;
}

.invoice-items-table .table {
    margin-bottom: 0;
}

.invoice-items-table thead {
    background: var(--paynow-purple-light);
}

.invoice-items-table thead th {
    border: none;
    font-weight: 600;
    color: var(--gray-900);
    padding: 0.75rem;
    font-size: 0.875rem;
}

.invoice-items-table tbody td {
    padding: 0.75rem;
    vertical-align: middle;
    border-color: var(--gray-200);
}

.invoice-items-table .empty-row td {
    border: none;
}

/* Totals Section */
.invoice-totals {
    margin-bottom: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-200);
}

.totals-row {
    display: flex;
    justify-content: flex-end;
    gap: 2rem;
    padding: 0.5rem 0;
    font-size: 0.95rem;
}

.totals-row span:first-child {
    min-width: 80px;
    text-align: right;
}

.totals-row span:last-child {
    min-width: 100px;
    text-align: right;
}

.total-row {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--paynow-purple);
    border-top: 2px solid var(--gray-200);
    padding-top: 0.75rem;
    margin-top: 0.5rem;
}

/* Payment Section */
.invoice-payment {
    background: var(--paynow-purple-light);
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
}

.payment-header {
    font-weight: 700;
    font-size: 1rem;
    color: var(--paynow-purple);
    margin-bottom: 1rem;
}

.qr-placeholder {
    width: 180px;
    height: 180px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.qr-placeholder.empty {
    border: 2px dashed var(--gray-200);
    border-radius: 0.5rem;
}

.qr-placeholder-text {
    color: var(--gray-600);
    font-size: 0.75rem;
}

.qr-placeholder-text i {
    font-size: 2rem;
    display: block;
    margin-bottom: 0.5rem;
    color: var(--gray-400);
}

.qr-placeholder img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.payment-details {
    font-size: 0.875rem;
    color: var(--gray-700);
}

.payment-details p {
    margin-bottom: 0.25rem;
}

/* Invoice Footer */
.invoice-footer {
    text-align: center;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-200);
    font-size: 0.75rem;
    color: var(--gray-600);
}

/* ========================================
   5. INFO SECTIONS
   ======================================== */
.how-to-section {
    background: white;
}

.how-to-section h3 {
    color: var(--gray-900);
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

.how-to-section .text-primary {
    color: var(--paynow-purple) !important;
}

.faq-section .accordion-button:not(.collapsed) {
    background-color: var(--paynow-purple-light);
    color: var(--paynow-purple);
    box-shadow: none;
}

.faq-section .accordion-button:focus {
    box-shadow: 0 0 0 0.25rem rgba(125, 25, 121, 0.15);
    border-color: var(--paynow-purple);
}

/* ========================================
   6. PRINT STYLES
   ======================================== */
@media print {
    /* Reset visibility */
    body,
    body * {
        visibility: hidden;
    }

    /* Show only invoice preview */
    .invoice-preview-container,
    .invoice-preview-container *,
    .invoice-preview,
    .invoice-preview * {
        visibility: visible !important;
    }

    .invoice-generator-section {
        width: 100% !important;
        margin-left: 0 !important;
        padding: 0 !important;
        background: none !important;
    }

    .invoice-preview-container {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        background: none !important;
        padding: 0 !important;
        box-shadow: none !important;
    }

    .invoice-preview {
        position: relative;
        max-width: 180mm;
        margin: 0 auto;
        padding: 10mm !important;
        box-shadow: none !important;
        min-height: auto;
        transform: none !important;
        font-size: 11pt !important;
    }

    /* Hide buttons and non-essential elements */
    #print-invoice-btn,
    .invoice-hero-section,
    .how-to-section,
    .faq-section,
    .related-products-section,
    .invoice-form-wrapper,
    .invoice-preview-wrapper > .d-flex,
    nav,
    footer,
    .col-lg-6:first-child {
        display: none !important;
    }

    /* Compact table for print */
    .invoice-items-table .table {
        font-size: 10pt !important;
    }

    .invoice-items-table th,
    .invoice-items-table td {
        padding: 0.4rem 0.5rem !important;
    }

    /* Percentage-based column widths for print */
    .invoice-items-table th:first-child,
    .invoice-items-table td:first-child {
        width: 50% !important;
    }

    .invoice-items-table th:nth-child(2),
    .invoice-items-table td:nth-child(2) {
        width: 10% !important;
    }

    .invoice-items-table th:nth-child(3),
    .invoice-items-table td:nth-child(3),
    .invoice-items-table th:nth-child(4),
    .invoice-items-table td:nth-child(4) {
        width: 20% !important;
    }

    /* Compact header for print */
    .invoice-header {
        margin-bottom: 1rem !important;
        padding-bottom: 0.5rem !important;
        border-bottom-color: #7d1979 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .invoice-title {
        font-size: 1.5rem !important;
        color: #7d1979 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Compact parties section */
    .invoice-parties {
        margin-bottom: 1rem !important;
    }

    .party-name {
        font-size: 0.9rem !important;
    }

    .party-details {
        font-size: 0.8rem !important;
    }

    /* Compact dates */
    .invoice-dates {
        margin-bottom: 1rem !important;
        padding: 0.5rem !important;
    }

    /* Compact totals */
    .invoice-totals {
        margin-bottom: 1rem !important;
    }

    .totals-row {
        font-size: 0.85rem !important;
        padding: 0.25rem 0 !important;
    }

    .total-row {
        font-size: 1rem !important;
        color: #7d1979 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Compact payment section */
    .invoice-payment {
        padding: 1rem !important;
        margin-bottom: 1rem !important;
        background: #f9f5ff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .payment-header {
        font-size: 0.9rem !important;
        margin-bottom: 0.5rem !important;
    }

    .payment-details {
        font-size: 0.8rem !important;
    }

    .invoice-items-table thead {
        background: #f9f5ff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Invoice footer - ensure it's visible */
    .invoice-footer {
        visibility: visible !important;
        display: block !important;
        margin-top: 1rem;
        padding-top: 0.5rem;
        border-top: 1px solid #e5e7eb;
        text-align: center;
        font-size: 9pt;
        color: #4b5563 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* QR code print optimization */
    .qr-placeholder {
        width: 120px !important;
        height: 120px !important;
    }

    .qr-placeholder img {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Page settings - let browser/user control margins */
    @page {
        size: A4;
        /* No margin specified - internal padding on invoice-preview provides breathing room */
    }
}

/* ========================================
   7. RESPONSIVE STYLES
   ======================================== */
@media (max-width: 991px) {
    .invoice-hero-section {
        padding-top: 2rem;
        padding-bottom: 2rem;
    }

    .invoice-hero-section h1 {
        font-size: 1.75rem;
    }

    .sticky-form {
        position: static;
        max-height: none;
    }

    .invoice-preview-wrapper {
        position: static;
        margin-top: 2rem;
    }

    .invoice-preview-container {
        padding: 1rem;
    }

    .invoice-preview {
        padding: 1.5rem;
        min-height: auto;
    }
}

@media (max-width: 767px) {
    .invoice-hero-section {
        padding-top: 1.5rem;
        padding-bottom: 1.5rem;
    }

    .invoice-hero-section h1 {
        font-size: 1.5rem;
    }

    .invoice-hero-section .lead {
        font-size: 1rem;
    }

    .invoice-generator-section {
        padding-top: 1rem;
        padding-bottom: 1rem;
    }

    /* Simplified form styling on mobile - no box shadow, minimal padding */
    .invoice-form-wrapper {
        padding: 1rem;
        box-shadow: none;
        border-radius: 0;
        background: white;
    }

    .form-heading {
        font-size: 1.125rem;
        margin-bottom: 1rem;
    }

    .invoice-parties .row > div {
        margin-bottom: 1rem;
    }

    .invoice-preview-container {
        padding: 0.5rem;
    }

    .invoice-preview {
        font-size: 11px;
        padding: 1rem;
        transform: scale(0.75);
        width: 133.33%; /* 100% / 0.75 to compensate for scale */
    }

    .invoice-title {
        font-size: 1.5rem;
    }

    .invoice-payment .row {
        flex-direction: column;
        text-align: center;
    }

    .invoice-payment .col-auto {
        margin-bottom: 1rem;
    }

    .qr-placeholder {
        margin: 0 auto;
    }

    .totals-row {
        gap: 1rem;
    }

    #print-invoice-btn {
        width: 100%;
        margin-top: 0.5rem;
    }

    .line-item {
        padding: 0.5rem;
        margin-bottom: 0.375rem;
        border-radius: 0.25rem;
    }

    .line-item .form-control {
        padding: 0.25rem 0.375rem;
        font-size: 0.8125rem;
    }

    .line-item .item-qty {
        padding-left: 0.125rem;
        padding-right: 0.125rem;
    }

    .line-item .row > div {
        margin-bottom: 0.25rem;
    }

    .line-item .row.g-2 {
        --bs-gutter-x: 0.375rem;
        --bs-gutter-y: 0.25rem;
    }

    /* Reduce form field spacing on mobile */
    .form-section {
        padding-bottom: 0.75rem;
        margin-bottom: 0.75rem !important;
    }

    .mb-3 {
        margin-bottom: 0.75rem !important;
    }
}
