/**
 * Mahak Invoice Generator Widget CSS
 * Responsive styling for invoice forms, preview, and print layout
 */
@font-face {
    font-family: 'Vazirmatn';
    src: url('/wp-content/plugins/shopmahak-core/assets/fonts/Vazirmatn-Regular.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
}

.mahak-invoice-generator {
    max-width: 100%;
    margin: 0 auto;
    padding: 5mm;
    box-sizing: border-box;
    direction: rtl;
    font-size: 9pt;
    line-height: 1.5;
    font-family: 'Vazirmatn', sans-serif;
    color: #000;
}

/* Tabs */
.mahak-invoice-generator .tabs {
    display: flex;
    gap: 3mm;
    margin-bottom: 5mm;
    background: #f5f5f5;
    padding: 3mm;
    border-radius: 2mm;
}

.mahak-invoice-generator .tab {
    flex: 1;
    padding: 3mm 5mm;
    border: 1pt solid #ccc;
    background: #fff;
    cursor: pointer;
    text-align: center;
    font-size: 9pt;
    border-radius: 2mm;
    transition: background 0.2s, color 0.2s;
}

.mahak-invoice-generator .tab.active,
.mahak-invoice-generator .tab:hover {
    background: #005a87;
    color: #fff;
    border-color: #005a87;
}

/* Invoice Content */
.mahak-invoice-generator .invoice-content {
    display: flex;
    flex-direction: column;
    gap: 5mm;
}

.mahak-invoice-generator .mahak-invoice-tab {
    display: none;
}

.mahak-invoice-generator .mahak-invoice-tab.active {
    display: block;
}

/* Form Styling */
.mahak-invoice-form {
    background: #fff;
    padding: 5mm;
    border: 1pt solid #ccc;
    border-radius: 2mm;
}

.form-section {
    margin-bottom: 5mm;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 3mm;
    padding: 3mm 5mm;
    background: #f0f0f0;
    cursor: pointer;
    font-size: 9pt;
    font-weight: bold;
    border: 1pt solid #ccc;
    border-radius: 2mm;
    transition: background 0.2s;
}

.section-header:hover {
    background: #e0e0e0;
}

.section-header[aria-expanded="true"] .toggle-icon {
    transform: rotate(180deg);
}

.section-icon,
.toggle-icon {
    font-size: 8pt;
}

.form-content {
    padding: 5mm;
    border: 1pt solid #ccc;
    border-top: none;
    border-radius: 0 0 2mm 2mm;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 3mm;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 8pt;
    margin-bottom: 2mm;
    color: #333;
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: 3mm;
    border: 1pt solid #ccc;
    border-radius: 2mm;
    font-size: 8pt;
    font-family: 'Vazirmatn', sans-serif;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: #005a87;
    outline: none;
}

.form-group input[readonly] {
    background: #f5f5f5;
    cursor: not-allowed;
}

.form-group textarea {
    min-height: 40mm;
    resize: vertical;
}

.items-container {
    margin-bottom: 5mm;
}

.item-row {
    display: grid;
    grid-template-columns: 25px repeat(auto-fit, minmax(60px, 1fr));
    gap: 3mm;
    padding: 3mm 0;
    border-bottom: 1pt solid #eee;
}

.item-row .form-group label {
    font-size: 7pt;
    margin-bottom: 1mm;
}

.item-row .form-group input {
    padding: 2mm;
    font-size: 7pt;
}

.remove-item {
    background: #d63638;
    color: #fff;
    border: none;
    border-radius: 2mm;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3mm;
    transition: background 0.2s;
}

.remove-item:hover {
    background: #b32d2e;
}

.add-item {
    background: #005a87;
    color: #fff;
    border: none;
    padding: 3mm 5mm;
    border-radius: 2mm;
    cursor: pointer;
    font-size: 8pt;
    margin-top: 5mm;
    transition: background 0.2s;
}

.add-item:hover {
    background: #003d5b;
}

.form-actions {
    display: flex;
    gap: 3mm;
    justify-content: flex-end;
    margin-top: 5mm;
}

.form-actions button {
    padding: 3mm 5mm;
    border: none;
    border-radius: 2mm;
    cursor: pointer;
    font-size: 8pt;
    transition: background 0.2s;
}

.preview-invoice {
    background: #005a87;
    color: #fff;
}

.preview-invoice:hover {
    background: #003d5b;
}

.download-pdf {
    background: #17a2b8;
    color: #fff;
}

.download-pdf:hover {
    background: #117a8b;
}

.print-invoice {
    background: #444;
    color: #fff;
}

.print-invoice:hover {
    background: #222;
}

/* Preview Styling */
.mahak-invoice-preview {
    margin-top: 5mm;
}

.preview-container {
    max-width: 297mm;
    margin: 0 auto;
    padding: 8mm;
    border: 1pt solid #E3E3E3;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 1px 6px rgba(0,0,0,0.1);
    position: relative;
    min-height: 210mm;
    transition: opacity 0.3s ease;
    font-family: 'Vazirmatn', sans-serif;
}

.preview-container.show {
    opacity: 1;
}

.preview-wrapper {
    padding: 0;
}

.invoice-container {
    font-size: 10pt;
    color: #333;
    line-height: 1.4;
}

.invoice-header {
    text-align: center;
    border-bottom: 1px solid #E3E3E3;
    padding-bottom: 6mm;
    margin-bottom: 6mm;
}

.invoice-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: #333;
    margin: 0 0 3mm;
    text-align: center;
}

.header-info {
    display: flex;
    justify-content: flex-start;
    gap: 3mm;
    width: 100%;
}

.invoice-details {
    flex: 0 0 auto;
    text-align: right;
}

.invoice-details p {
    margin: 1mm 0;
    font-size: 10px;
    color: #555;
}

.notes {
    flex: 1;
    font-size: 10px;
    color: #555;
    text-align: right;
}

.invoice-section {
    margin-bottom: 6mm;
}

.invoice-section h2 {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    background: #E3E3E3;
    padding: 2mm 4mm;
    border-radius: 3px;
    margin: 0 0 3mm;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 3mm;
    padding: 4mm;
    border: 1px solid #E3E3E3;
    border-radius: 3px;
    background: #fafafa;
}

.info-grid div {
    font-size: 10px;
    color: #333;
}

.info-grid div strong {
    color: #333;
    margin-left: 4px;
}

.signature {
    text-align: center;
}

.signature img {
    max-width: 40mm;
    max-height: 15mm;
    margin-top: 2mm;
    border: 1px solid #E3E3E3;
    border-radius: 3px;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 4mm;
    border: 1px solid #E3E3E3;
}

.invoice-table th,
.invoice-table td {
    border: 1px solid #E3E3E3;
    padding: 2mm;
    text-align: center;
    font-size: 10px;
    color: #333;
}

.invoice-table th {
    background: #E3E3E3;
    color: #333;
    font-weight: 600;
}

.invoice-table td {
    background: #fff;
}

.invoice-table tfoot td {
    background: #E3E3E3;
    font-weight: 600;
    color: #333;
}

.invoice-table th:nth-child(1), /* ردیف */
.invoice-table td:nth-child(1) {
    width: 5%;
}

.invoice-table th:nth-child(2), /* کد کالا (for official) */
.invoice-table td:nth-child(2) {
    width: 5%;
}

.invoice-table th:nth-child(3), /* شرح کالا/خدمات */
.invoice-table td:nth-child(3) {
    width: 20%;
    text-align: right;
}

.invoice-table th:nth-child(4), /* تعداد */
.invoice-table td:nth-child(4) {
    width: 5%;
}

.invoice-table th:nth-child(5), /* واحد */
.invoice-table td:nth-child(5) {
    width: 5%;
}

.invoice-table th:nth-child(6), /* مبلغ واحد */
.invoice-table td:nth-child(6) {
    width: 5%;
}

.invoice-table th:nth-child(7), /* مبلغ کل */
.invoice-table td:nth-child(7) {
    width: 10%;
}

.invoice-table th:nth-child(8), /* مبلغ تخفیف */
.invoice-table td:nth-child(8) {
    width: 5%;
}

.invoice-table th:nth-child(9), /* مبلغ مالیات و عوارض (for official) */
.invoice-table td:nth-child(9) {
    width: 5%;
}

.invoice-table th:nth-child(10), /* مبلغ نهایی (official) */
.invoice-table td:nth-child(10) {
    width: 10%;
}

.invoice-table th:nth-child(8), /* مبلغ نهایی (simple) */
.invoice-table td:nth-child(8) {
    width: 10%;
}

.invoice-footer {
    display: flex;
    text-align: center;
    justify-content: space-between;
    padding: 4mm;
    border-top: 1px solid #E3E3E3;
    margin-top: 6mm;
    font-size: 9px;
    color: #666;
    background: #E3E3E3;
    border-radius: 0 0 6px 6px;
}

.invoice-footer p {
    margin: 1mm 0;
}

/* Error Message */
.error {
    display: none;
    padding: 3mm;
    background: #d63638;
    color: #fff;
    border-radius: 2mm;
    margin-bottom: 5mm;
    text-align: center;
    font-size: 8pt;
}

.error.show {
    display: block;
}

/* Responsive Design */
@media screen and (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .item-row {
        grid-template-columns: 25px 1fr;
    }

    .item-row .form-group {
        grid-column: span 1;
    }

    .invoice-table th,
    .invoice-table td {
        font-size: 8pt;
        padding: 1.5mm;
    }

    .info-grid div {
        font-size: 8pt;
    }
}

@media screen and (max-width: 480px) {
    .mahak-invoice-generator {
        padding: 3mm;
    }

    .section-header {
        font-size: 8pt;
        padding: 2mm 3mm;
    }

    .form-group label {
        font-size: 7pt;
    }

    .form-group input,
    .form-group textarea,
    .form-group select {
        font-size: 7pt;
        padding: 2mm;
    }

    .add-item,
    .preview-invoice,
    .download-pdf,
    .print-invoice {
        font-size: 7pt;
        padding: 2mm 4mm;
    }

    .invoice-header h1 {
        font-size: 16px;
    }

    .invoice-details p,
    .notes {
        font-size: 8px;
    }

    .invoice-section h2 {
        font-size: 12px;
    }

    .info-grid div {
        font-size: 8px;
    }

    .invoice-table th,
    .invoice-table td {
        font-size: 7px;
        padding: 1mm;
    }

    .invoice-footer {
        font-size: 7px;
    }
}

/* Print Styles */
@media print {
    @page {
        size: A4 landscape;
        margin: 8mm;
    }

    body {
        margin: 0;
        padding: 0;
        background: #fff;
        font-family: 'Vazirmatn', sans-serif;
        color: #333;
    }

    .mahak-invoice-generator,
    .mahak-invoice-tab,
    .mahak-invoice-form,
    .form-section,
    .form-content,
    .form-grid,
    .form-group,
    .items-container,
    .item-row,
    .form-actions,
    .tabs,
    .error {
        display: none !important;
    }

    .mahak-invoice-preview {
        display: block !important;
        margin: 0;
        padding: 0;
        border: none;
        background: #fff;
    }

    .preview-container {
        padding: 0;
        max-width: 297mm;
        margin: 0 auto;
        position: relative;
        background: #fff;
        box-shadow: none;
        min-height: 210mm;
        font-family: 'Vazirmatn', sans-serif;
    }

    .preview-wrapper {
        padding: 0;
    }

    .invoice-container {
        font-size: 10pt;
        color: #333;
        line-height: 1.4;
    }

    .invoice-header {
        text-align: center;
        border-bottom: 1px solid #E3E3E3;
        padding-bottom: 6mm;
        margin-bottom: 6mm;
    }

    .invoice-header h1 {
        font-size: 18px;
    }

    .invoice-details {
        text-align: right;
    }

    .invoice-details p {
        font-size: 9px;
    }

    .notes {
        font-size: 9px;
    }

    .invoice-section h2 {
        font-size: 13px;
    }

    .info-grid div {
        font-size: 9px;
    }

    .invoice-table th,
    .invoice-table td {
        font-size: 9px;
        padding: 1.5mm;
    }

    .invoice-table th:nth-child(1), /* ردیف */
    .invoice-table td:nth-child(1) {
        width: 5%;
    }

    .invoice-table th:nth-child(2), /* کد کالا (for official) */
    .invoice-table td:nth-child(2) {
        width: 5%;
    }

    .invoice-table th:nth-child(3), /* شرح کالا/خدمات */
    .invoice-table td:nth-child(3) {
        width: 20%;
        text-align: right;
    }

    .invoice-table th:nth-child(4), /* تعداد */
    .invoice-table td:nth-child(4) {
        width: 5%;
    }

    .invoice-table th:nth-child(5), /* واحد */
    .invoice-table td:nth-child(5) {
        width: 5%;
    }

    .invoice-table th:nth-child(6), /* مبلغ واحد */
    .invoice-table td:nth-child(6) {
        width: 5%;
    }

    .invoice-table th:nth-child(7), /* مبلغ کل */
    .invoice-table td:nth-child(7) {
        width: 10%;
    }

    .invoice-table th:nth-child(8), /* مبلغ تخفیف */
    .invoice-table td:nth-child(8) {
        width: 5%;
    }

    .invoice-table th:nth-child(9), /* مبلغ مالیات و عوارض (for official) */
    .invoice-table td:nth-child(9) {
        width: 5%;
    }

    .invoice-table th:nth-child(10), /* مبلغ نهایی (official) */
    .invoice-table td:nth-child(10),
    .invoice-table th:nth-child(8), /* مبلغ نهایی (simple) */
    .invoice-table td:nth-child(8) {
        width: 10%;
    }

    .invoice-footer {
        font-size: 8px;
    }

    @page :left {
        margin-left: 12mm;
    }

    @page :right {
        margin-right: 12mm;
    }

    /* Support for A5 and Letter */
    @media print and (max-width: 148mm) {
        @page {
            size: A5 landscape;
        }

        .invoice-table th,
        .invoice-table td {
            font-size: 7px;
            padding: 1mm;
        }

        .invoice-table th:nth-child(1), /* ردیف */
        .invoice-table td:nth-child(1) {
            width: 5%;
        }

        .invoice-table th:nth-child(2), /* کد کالا (for official) */
        .invoice-table td:nth-child(2) {
            width: 5%;
        }

        .invoice-table th:nth-child(3), /* شرح کالا/خدمات */
        .invoice-table td:nth-child(3) {
            width: 20%;
            text-align: right;
        }

        .invoice-table th:nth-child(4), /* تعداد */
        .invoice-table td:nth-child(4) {
            width: 5%;
        }

        .invoice-table th:nth-child(5), /* واحد */
        .invoice-table td:nth-child(5) {
            width: 5%;
        }

        .invoice-table th:nth-child(6), /* مبلغ واحد */
        .invoice-table td:nth-child(6) {
            width: 5%;
        }

        .invoice-table th:nth-child(7), /* مبلغ کل */
        .invoice-table td:nth-child(7) {
            width: 10%;
        }

        .invoice-table th:nth-child(8), /* مبلغ تخفیف */
        .invoice-table td:nth-child(8) {
            width: 5%;
        }

        .invoice-table th:nth-child(9), /* مبلغ مالیات و عوارض (for official) */
        .invoice-table td:nth-child(9) {
            width: 5%;
        }

        .invoice-table th:nth-child(10), /* مبلغ نهایی (official) */
        .invoice-table td:nth-child(10),
        .invoice-table th:nth-child(8), /* مبلغ نهایی (simple) */
        .invoice-table td:nth-child(8) {
            width: 10%;
        }

        .info-grid div {
            font-size: 7px;
        }

        .invoice-section h2 {
            font-size: 11px;
        }

        .invoice-footer {
            font-size: 6px;
        }
    }

    @media print and (max-width: 216mm) and (max-height: 279mm) {
        @page {
            size: Letter landscape;
        }

        .invoice-table th,
        .invoice-table td {
            font-size: 7px;
            padding: 1.2mm;
        }

        .invoice-table th:nth-child(1), /* ردیف */
        .invoice-table td:nth-child(1) {
            width: 5%;
        }

        .invoice-table th:nth-child(2), /* کد کالا (for official) */
        .invoice-table td:nth-child(2) {
            width: 5%;
        }

        .invoice-table th:nth-child(3), /* شرح کالا/خدمات */
        .invoice-table td:nth-child(3) {
            width: 20%;
            text-align: right;
        }

        .invoice-table th:nth-child(4), /* تعداد */
        .invoice-table td:nth-child(4) {
            width: 5%;
        }

        .invoice-table th:nth-child(5), /* واحد */
        .invoice-table td:nth-child(5) {
            width: 5%;
        }

        .invoice-table th:nth-child(6), /* مبلغ واحد */
        .invoice-table td:nth-child(6) {
            width: 5%;
        }

        .invoice-table th:nth-child(7), /* مبلغ کل */
        .invoice-table td:nth-child(7) {
            width: 10%;
        }

        .invoice-table th:nth-child(8), /* مبلغ تخفیف */
        .invoice-table td:nth-child(8) {
            width: 5%;
        }

        .invoice-table th:nth-child(9), /* مبلغ مالیات و عوارض (for official) */
        .invoice-table td:nth-child(9) {
            width: 5%;
        }

        .invoice-table th:nth-child(10), /* مبلغ نهایی (official) */
        .invoice-table td:nth-child(10),
        .invoice-table th:nth-child(8), /* مبلغ نهایی (simple) */
        .invoice-table td:nth-child(8) {
            width: 10%;
        }

        .info-grid div {
            font-size: 8px;
        }

        .invoice-section h2 {
            font-size: 12px;
        }

        .invoice-footer {
            font-size: 7px;
        }
    }
}