/**
 * Invoice Styles
 *
 * Print-friendly CSS for invoice templates
 *
 * @package Khaloghli_Customizations\Modules\Invoice\Assets\CSS
 */

/* Variables */
:root {
    --kh-primary-color: rgb(22,163,74);
    --kh-secondary-color: #fbbc34;
    --kh-text-color: #333;
    --kh-border-color: #ddd;
    --kh-bg-color: #f9f9f9;
    --kh-white: #fff;
    --kh-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Custom Fonts */
@font-face {
    font-family: 'IRANSansWeb';
    src: url('../fonts/IRANSansWeb_FaNum_Medium.woff2') format('woff2'),
         url('../fonts/IRANSansWeb_FaNum_Medium.woff') format('woff');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IRANSansWeb';
    src: url('../fonts/IRANSansWeb_FaNum_Bold.woff2') format('woff2'),
         url('../fonts/IRANSansWeb_FaNum_Bold.woff') format('woff');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

body {
    font-family: 'IRANSansWeb', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
}
/* Base Styles */
.kh-invoice-body {
    font-family: 'IRANSansWeb', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
    font-weight: 500;
    font-size: 14px;
    line-height: 1.6;
    color: var(--kh-text-color);
    background-color: var(--kh-bg-color);
    margin: 0;
    padding: 20px;
    direction: rtl;
}

.kh-invoice-container {
    max-width: 800px;
    margin: 0 auto;
    background-color: var(--kh-white);
    box-shadow: var(--kh-shadow);
    padding: 30px;
    border-radius: 8px;
}

/* Header Styles */
.kh-invoice-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--kh-primary-color);
    position: relative;
}

.kh-store-info {
    text-align: center;
    margin-bottom: 15px;
}

.kh-invoice-info {
    position: absolute;
    top: 0;
    left: 0;
    text-align: left;
    font-size: 13px;
}

.kh-store-logo {
    max-width: 120px;
    height: auto;
    margin-bottom: 10px;
}

.kh-invoice-title {
    font-size: 20px;
    color: var(--kh-text-color);
    margin: 0;
    font-weight: 700;
}

.kh-invoice-info > div {
    margin-bottom: 5px;
}

.kh-invoice-info strong {
    display: inline-block;
    min-width: 80px;
    font-weight: 700;
}

/* Customer Info Styles */
h3{
    font-family: 'IRANSansWeb', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
    font-weight: 700;
}
.kh-customer-info {
    margin-bottom: 30px;
    padding: 20px;
    background-color: var(--kh-bg-color);
    border-radius: 6px;
}

.kh-customer-info h3 {
    margin: 0 0 15px 0;
    color: var(--kh-primary-color);
    font-size: 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--kh-border-color);
    padding-bottom: 5px;
}

.kh-customer-details {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}

.customer-personal-info,
.customer-address-info {
    flex: 1;
    min-width: 250px;
}

.kh-customer-row {
    display: flex;
    align-items: center;
}

.kh-customer-row .kh-label {
    font-weight: 700;
    min-width: 60px;
    margin-left: 10px;
}

.kh-customer-row .kh-value {
    flex: 1;
}

/* Order Items Table */
.kh-order-items {
    margin-bottom: 30px;
}

.kh-order-items h3 {
    margin: 0 0 15px 0;
    color: var(--kh-primary-color);
    font-size: 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--kh-border-color);
    padding-bottom: 5px;
}

.kh-items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    font-size: 13px;
}

.kh-items-table th,
.kh-items-table td {
    padding: 12px 8px;
    text-align: right;
    border: 1px solid var(--kh-border-color);
}

.kh-items-table th {
    background-color: var(--kh-primary-color);
    color: var(--kh-white);
    font-weight: 700;
}

.kh-items-table tbody tr:nth-child(even) {
    background-color: #f8f8f8;
}

.kh-items-table tbody tr:hover {
    background-color: #f0f0f0;
}

.kh-items-table tfoot tr {
    font-weight: 700;
    background-color: var(--kh-bg-color);
}

.kh-total-row {
    background-color: var(--kh-primary-color) !important;
    color: var(--kh-white) !important;
}

.kh-total-row td {
    border-color: var(--kh-primary-color) !important;
}

/* Payment Info Styles */
.kh-payment-info {
    margin-bottom: 30px;
    padding: 20px;
    background-color: var(--kh-bg-color);
    border-radius: 6px;
}

.kh-payment-info h3 {
    margin: 0 0 15px 0;
    color: var(--kh-primary-color);
    font-size: 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--kh-border-color);
    padding-bottom: 5px;
}

.kh-payment-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.kh-payment-row {
    display: flex;
    align-items: center;
}

.kh-payment-row .kh-label {
    font-weight: 700;
    min-width: 80px;
    margin-left: 10px;
}

.kh-payment-row .kh-value {
    flex: 1;
}

/* Loyalty score block */
.kh-loyalty-info {
    margin-bottom: 30px;
    padding: 20px;
    background-color: var(--kh-bg-color);
    border-radius: 6px;
}

.kh-loyalty-info h3 {
    margin: 0 0 15px 0;
    color: var(--kh-primary-color);
    font-size: 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--kh-border-color);
    padding-bottom: 5px;
}

.kh-loyalty-row {
    display: flex;
    align-items: center;
}

.kh-loyalty-row .kh-label {
    font-weight: 700;
    min-width: 80px;
    margin-left: 10px;
}

.kh-loyalty-row .kh-value {
    flex: 1;
}

/* Action Buttons */
.kh-invoice-actions {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--kh-border-color);
}

.kh-invoice-actions .button {
    display: inline-block;
    padding: 10px 20px;
    margin: 0 5px;
    background-color: var(--kh-primary-color);
    color: var(--kh-white);
    text-decoration: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s ease;
}

.kh-invoice-actions .button:hover {
    background-color: var(--kh-primary-color); 
    color: var(--kh-white);
}

.kh-back-button,
.kh-close-button {
    background-color: var(--kh-secondary-color);
}

.kh-back-button:hover,
.kh-close-button:hover {
    background-color: #e6a800;
}

/* Pre-invoice specific styles */

/* Admin order action buttons */
.wc-action-button-kh-view-invoice::after {
    content: "\f115"; /* WordPress dashicon for document */
    font-family: "dashicons";
}

.wc-action-button-kh-download-invoice::after {
    content: "\f316"; /* WordPress dashicon for download */
    font-family: "dashicons";
}

/* Cart pre-invoice button */
.kh-pre-invoice-button-wrapper {
    text-align: center;
    margin-top: 20px;
}

.kh-pre-invoice-button {
    background-color: var(--kh-secondary-color) !important;
    border-color: var(--kh-secondary-color) !important;
}

.kh-pre-invoice-button:hover {
    background-color: #e6a800 !important;
    border-color: #e6a800 !important;
}

/* Print Styles */
@media print {
    /* Ensure fonts are applied in print mode */
    body,
    .kh-invoice-body,
    .kh-invoice-container,
    .kh-invoice-header,
    .kh-store-info,
    .kh-invoice-info,
    .kh-customer-info,
    .kh-payment-info,
    .kh-order-items,
    .kh-items-table,
    .kh-items-table th,
    .kh-items-table td {
        font-family: 'IRANSansWeb', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
        font-weight: 500 !important;
        font-size: 12px !important;
        line-height: 1.4 !important;
    }

    /* Force font loading for print - redefine fonts within print context */
    @font-face {
        font-family: 'IRANSansWeb';
        src: url('../fonts/IRANSansWeb_FaNum_Medium.woff2') format('woff2'),
             url('../fonts/IRANSansWeb_FaNum_Medium.woff') format('woff');
        font-weight: 500;
        font-style: normal;
        font-display: block;
    }

    @font-face {
        font-family: 'IRANSansWeb';
        src: url('../fonts/IRANSansWeb_FaNum_Bold.woff2') format('woff2'),
             url('../fonts/IRANSansWeb_FaNum_Bold.woff') format('woff');
        font-weight: 700;
        font-style: normal;
        font-display: block;
    }

    /* Additional print-specific font settings */
    * {
        -webkit-font-smoothing: antialiased !important;
        -moz-osx-font-smoothing: grayscale !important;
        text-rendering: optimizeLegibility !important;
    }

    /* Reset body and container */
    .kh-invoice-body {
        background: var(--kh-white) !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .kh-invoice-container {
        box-shadow: none !important;
        padding: 20px !important;
        max-width: none !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    /* Fix header layout for print */
    .kh-invoice-header {
        border-bottom: 2px solid var(--kh-primary-color) !important;
        position: relative !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
        margin-bottom: 25px !important;
        padding-bottom: 15px !important;
    }

    .kh-store-info {
        flex: 1;
        text-align: center;
        margin-bottom: 0 !important;
    }

    .kh-invoice-info {
        position: static !important;
        text-align: left !important;
        font-size: 12px !important;
        flex-shrink: 0;
        margin-left: 20px;
    }

    .kh-store-logo {
        max-width: 100px !important;
        margin-bottom: 8px !important;
    }

    .kh-invoice-title {
        font-size: 18px !important;
    }

    /* Customer info adjustments */
    .kh-customer-info {
        background-color: transparent !important;
        padding: 15px !important;
        margin-bottom: 20px !important;
        border: 1px solid var(--kh-border-color) !important;
        border-radius: 0 !important;
    }

    .kh-customer-info h3 {
        font-size: 15px !important;
        margin-bottom: 12px !important;
    }

    /* Payment info adjustments */
    .kh-payment-info {
        background-color: transparent !important;
        padding: 15px !important;
        margin-bottom: 20px !important;
        border: 1px solid var(--kh-border-color) !important;
        border-radius: 0 !important;
    }

    .kh-payment-info h3 {
        font-size: 15px !important;
        margin-bottom: 12px !important;
    }

    /* Table adjustments */
    .kh-order-items {
        margin-bottom: 20px !important;
    }

    .kh-order-items h3 {
        font-size: 15px !important;
        margin-bottom: 12px !important;
    }

    .kh-items-table {
        font-size: 11px !important;
        border: 1px solid var(--kh-border-color) !important;
    }

    .kh-items-table th,
    .kh-items-table td {
        padding: 6px 4px !important;
        border: 1px solid var(--kh-border-color) !important;
    }

    .kh-items-table th {
        background-color: var(--kh-primary-color) !important;
        color: var(--kh-white) !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .kh-items-table tbody tr:nth-child(even) {
        background-color: #f8f8f8 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .kh-total-row {
        background-color: var(--kh-primary-color) !important;
        color: var(--kh-white) !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .kh-total-row td {
        border-color: var(--kh-primary-color) !important;
    }

    /* Hide non-printable elements */
    .no-print {
        display: none !important;
    }

    .kh-invoice-actions {
        display: none !important;
    }

    /* Ensure proper page breaks */
    .kh-order-items {
        page-break-inside: avoid;
    }

    .kh-items-table {
        page-break-inside: avoid;
    }

    .kh-items-table thead {
        display: table-header-group;
    }

    .kh-items-table tfoot {
        display: table-footer-group;
    }

    .kh-items-table tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }

    .kh-customer-info,
    .kh-payment-info {
        page-break-inside: avoid;
    }

    /* Remove hover effects */
    .kh-items-table tbody tr:hover {
        background-color: inherit !important;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .kh-invoice-body {
        padding: 10px;
    }

    .kh-invoice-container {
        padding: 20px;
    }

    .kh-invoice-header {
        flex-direction: column;
        text-align: center;
        gap: 20px;
    }

    .kh-invoice-info {
        text-align: center;
    }

    .kh-customer-details,
    .kh-payment-details {
        grid-template-columns: 1fr;
    }

    .kh-items-table {
        font-size: 12px;
    }

    .kh-items-table th,
    .kh-items-table td {
        padding: 8px 4px;
    }

    .kh-invoice-actions .button {
        display: block;
        width: 100%;
        margin: 5px 0;
    }
}

/* RTL Support */
[dir="rtl"] .kh-items-table th:first-child,
[dir="rtl"] .kh-items-table td:first-child {
    text-align: center;
}

[dir="rtl"] .kh-items-table th:last-child,
[dir="rtl"] .kh-items-table td:last-child {
    text-align: left;
}
