/* ========================================
   Template Selector
   ======================================== */

.template-selector-section {
    padding: var(--spacing-md) var(--spacing-lg);
    background: rgba(255, 255, 255, 0.5);
    border-bottom: 1px solid var(--border-color-light);
}

.template-selector-section label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

.template-selector {
    width: 100%;
    padding: 12px 16px;
    font-family: var(--font-system);
    font-size: var(--font-size-base);
    color: var(--text-primary);
    background: white;
    border: 2px solid var(--ios-blue);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.template-selector:hover {
    border-color: var(--ios-teal);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
}

.template-selector:focus {
    outline: none;
    border-color: var(--ios-blue);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15);
}

/* ========================================
   TEMPLATE 2: CLASSIC
   ======================================== */

[data-template="classic"] .invoice-content {
    background: white;
    border: 2px solid #000;
    font-family: 'Georgia', 'Times New Roman', serif;
}

[data-template="classic"] .invoice-header {
    border-bottom: 3px double #000;
    padding-bottom: var(--spacing-md);
}

[data-template="classic"] .preview-company-name {
    font-size: 24px;
    color: #000;
    text-transform: uppercase;
    letter-spacing: 2px;
}

[data-template="classic"] .invoice-title-section h1 {
    color: #000;
    font-size: 32px;
    border: 3px solid #000;
    padding: 8px 16px;
    display: inline-block;
}

[data-template="classic"] .invoice-meta,
[data-template="classic"] .customer-info-preview {
    background: #f5f5f5;
    border: 1px solid #000;
}

[data-template="classic"] .invoice-table thead {
    background: #000;
    color: white;
}

[data-template="classic"] .invoice-table tbody tr {
    border-bottom: 1px solid #ccc;
}

[data-template="classic"] .invoice-totals {
    background: #f5f5f5;
    border: 2px solid #000;
}

[data-template="classic"] .totals-row.grand-total {
    background: #000;
    color: white;
    padding: 12px;
    margin: 0 -12px -12px -12px;
}

/* ========================================
   TEMPLATE 3: MINIMAL
   ======================================== */

[data-template="minimal"] .invoice-content {
    background: white;
    box-shadow: none;
    border: 1px solid #e0e0e0;
}

[data-template="minimal"] .invoice-header {
    border-bottom: 1px solid #e0e0e0;
}

[data-template="minimal"] .preview-company-name {
    font-weight: 300;
    font-size: 20px;
    color: #333;
}

[data-template="minimal"] .invoice-title-section h1 {
    color: #666;
    font-weight: 300;
    font-size: 36px;
}

[data-template="minimal"] .invoice-meta,
[data-template="minimal"] .customer-info-preview {
    background: transparent;
    border: none;
    border-left: 3px solid #e0e0e0;
    padding-left: var(--spacing-md);
}

[data-template="minimal"] .invoice-table thead {
    background: #f8f8f8;
    color: #666;
}

[data-template="minimal"] .invoice-table th {
    border-bottom: 2px solid #e0e0e0;
    font-weight: 500;
}

[data-template="minimal"] .invoice-totals {
    background: transparent;
    border-top: 2px solid #e0e0e0;
}

[data-template="minimal"] .totals-row.grand-total {
    border-top: 2px solid #333;
}

/* ========================================
/* ========================================
   TEMPLATE 4: MODERN PROFESSIONAL (Clean & Practical)
   ======================================== */

[data-template="colorful"] .invoice-content {
    background: white;
    padding: 30px;
    border: 1px solid #e2e8f0;
}

[data-template="colorful"] .invoice-content>* {
    background: transparent;
    border-radius: 0;
    padding: 0;
    margin-bottom: 0;
}

[data-template="colorful"] .invoice-header {
    background: white;
    color: #0f172a;
    border-bottom: 2px solid #0f172a;
    padding-bottom: 20px;
    margin-bottom: 30px;
}

[data-template="colorful"] .preview-company-name {
    color: #4338ca;
    /* Indigo 700 */
    font-weight: 700;
    text-transform: uppercase;
    font-size: 24px;
}

[data-template="colorful"] .invoice-title-section h1 {
    color: #0f172a;
    font-size: 32px;
    font-weight: 800;
}

[data-template="colorful"] .invoice-meta,
[data-template="colorful"] .customer-info-preview {
    background: #f8fafc;
    /* Slate 50 */
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 15px;
}

[data-template="colorful"] .invoice-meta .label {
    color: #64748b;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
}

[data-template="colorful"] .invoice-meta .value {
    color: #0f172a;
    font-weight: 600;
    font-size: 1rem;
}

[data-template="colorful"] .invoice-table thead {
    background: #f1f5f9;
    color: #334155;
    border-bottom: 2px solid #cbd5e1;
}

[data-template="colorful"] .invoice-table th {
    font-weight: 700;
    color: #334155;
}

[data-template="colorful"] .invoice-table tbody tr {
    border-bottom: 1px solid #e2e8f0;
}

[data-template="colorful"] .invoice-table tbody tr:nth-child(even) {
    background: #f8fafc;
}

[data-template="colorful"] .invoice-totals {
    background: white;
    border: 1px solid #e2e8f0;
    padding: 20px;
}

[data-template="colorful"] .invoice-totals .label {
    color: #64748b;
}

[data-template="colorful"] .invoice-totals .value {
    color: #0f172a;
}

[data-template="colorful"] .totals-row.grand-total {
    border-top: 2px solid #4338ca;
    margin-top: 15px;
    padding-top: 15px;
}

[data-template="colorful"] .totals-row.grand-total .value {
    color: #4338ca;
    font-size: 1.5rem;
}

/* ========================================
   TEMPLATE 5: CORPORATE (Official Executive)
   ======================================== */

[data-template="corporate"] .invoice-content {
    background: white;
    border: none;
    padding: 40px;
}

[data-template="corporate"] .invoice-header {
    background: #1e3a8a;
    /* Navy Blue */
    color: white;
    padding: 30px;
    margin: -40px -40px 30px -40px;
    /* Full width bleeding */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

[data-template="corporate"] .preview-company-name {
    color: white;
    font-size: 26px;
    letter-spacing: 1px;
    font-family: 'Times New Roman', serif;
}

[data-template="corporate"] .preview-company-address,
[data-template="corporate"] .preview-company-phone,
[data-template="corporate"] .preview-company-email,
[data-template="corporate"] .preview-company-tax {
    color: white !important;
    opacity: 1;
}

[data-template="corporate"] .invoice-title h2 {
    color: white;
    font-size: 32px;
    text-transform: uppercase;
    font-weight: 400;
    letter-spacing: 4px;
    text-align: right;
    margin: 0;
}

[data-template="corporate"] .invoice-title p {
    color: rgba(255, 255, 255, 0.7);
    text-align: right;
}

[data-template="corporate"] .invoice-info-section {
    display: flex;
    justify-content: space-between;
    gap: 40px;
    margin-bottom: 30px;
    border-bottom: 2px solid #1e3a8a;
    padding-bottom: 20px;
}

[data-template="corporate"] .customer-info-preview {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0;
}

[data-template="corporate"] .customer-info-preview h3 {
    color: #1e3a8a;
    font-size: 14px;
    text-transform: uppercase;
    border-bottom: 1px solid #ccc;
    padding-bottom: 5px;
    margin-bottom: 10px;
    display: inline-block;
}

[data-template="corporate"] .invoice-meta {
    flex: 0 0 300px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    padding: 15px;
}

[data-template="corporate"] .invoice-table thead {
    background: #1e3a8a;
    color: white;
}

[data-template="corporate"] .invoice-table th {
    font-family: 'Times New Roman', serif;
    font-weight: normal;
    letter-spacing: 1px;
    text-transform: uppercase;
}

[data-template="corporate"] .invoice-table tbody tr {
    border-bottom: 1px solid #e2e8f0;
}

[data-template="corporate"] .invoice-table tbody td {
    padding: 10px 12px;
}

[data-template="corporate"] .invoice-totals {
    background: transparent;
    border: none;
    margin-top: 20px;
    padding: 0;
    width: 300px;
}

[data-template="corporate"] .totals-row {
    border-bottom: 1px solid #eee;
    padding: 8px 0;
}

[data-template="corporate"] .totals-row.grand-total {
    background: #1e3a8a;
    color: white;
    padding: 10px 15px;
    margin-top: 10px;
    border: none;
}

[data-template="corporate"] .totals-row.grand-total .label,
[data-template="corporate"] .totals-row.grand-total .value {
    color: white;
}

[data-template="corporate"] .invoice-notes {
    border-left: 4px solid #1e3a8a;
    background: #f8fafc;
    margin-top: 30px;
}

/* ========================================
   A4 Print Layout Optimization
   ======================================== */

@media print {
    @page {
        size: A4 portrait;
        margin: 0;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    html,
    body {
        background: white !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
    }

    /* Hide all UI elements */
    .app-header,
    .form-panel,
    .template-selector-section,
    .panel-header,
    .action-buttons,
    .header-btn,
    .content-section,
    .site-footer,
    .cookie-banner {
        display: none !important;
    }

    .container {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        height: auto !important;
        width: 100% !important;
        grid-template-columns: 100% !important;
    }

    .preview-panel {
        width: 100% !important;
        max-width: 100% !important;
        background: white !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        overflow: visible !important;
        padding: 0 !important;
        margin: 0 !important;
        height: auto !important;
    }

    .invoice-preview {
        padding: 0 !important;
        width: 210mm !important;
        max-width: 210mm !important;
        min-height: 297mm !important;
        margin: 0 auto !important;
        overflow: visible !important;
        height: auto !important;
        transform: none !important;
    }

    .invoice-content {
        width: 100% !important;
        max-width: 100% !important;
        min-height: 287mm !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        border: none !important;
        padding: 15mm !important;
        margin: 0 !important;
        font-size: 14px !important;
        box-sizing: border-box !important;
    }

    .invoice-header {
        padding-bottom: 10px !important;
        margin-bottom: 10px !important;
    }

    .invoice-table {
        width: 100% !important;
        margin-bottom: 10px !important;
    }

    .invoice-table th,
    .invoice-table td {
        padding: 6px 8px !important;
        font-size: 13px !important;
    }

    .invoice-table tr {
        page-break-inside: avoid;
    }

    .invoice-table thead {
        display: table-header-group;
    }

    .invoice-info {
        margin-bottom: 10px !important;
    }

    .invoice-bottom-section {
        margin-top: 10px !important;
        gap: 10px !important;
    }

    .invoice-totals {
        padding: 10px !important;
    }

    .invoice-notes {
        padding: 10px !important;
    }

    .invoice-signatures {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-around !important;
        gap: 20px !important;
        margin-top: 15px !important;
        margin-bottom: 15px !important;
    }

    .signature-box {
        flex: 0 0 45% !important;
        text-align: center !important;
    }

    .signature-line {
        height: 40px !important;
    }

    .invoice-payment-info {
        padding: 10px !important;
        margin-top: 10px !important;
    }

    .invoice-footer {
        padding: 10px !important;
        margin-top: 10px !important;
        font-size: 12px !important;
    }

    /* Corporate template print */
    [data-template="corporate"] .invoice-header,
    [data-template="corporate"] .invoice-table thead,
    [data-template="corporate"] .totals-row.grand-total,
    [data-template="corporate"] .invoice-footer {
        background: #1e3a8a !important;
        color: white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    [data-template="corporate"] .invoice-table thead th {
        color: white !important;
    }

    /* Colorful (Modern) template print */
    [data-template="colorful"] .invoice-header,
    [data-template="colorful"] .invoice-totals {
        background: white !important;
        color: #0f172a !important;
    }

    [data-template="colorful"] .preview-company-name {
        color: #4338ca !important;
    }

    [data-template="colorful"] .totals-row.grand-total .value {
        color: #4338ca !important;
    }

    [data-template="colorful"] .invoice-table thead {
        background: #f1f5f9 !important;
        color: #334155 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Side-by-side layout for print */
    .invoice-header {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
    }

    .company-info {
        flex: 1 !important;
    }

    .invoice-title {
        text-align: right !important;
        flex: 0 0 auto !important;
    }

    .invoice-info {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        gap: 20px !important;
    }

    .customer-info-preview {
        flex: 1 !important;
    }

    .invoice-meta {
        flex: 0 0 200px !important;
        text-align: right !important;
    }
}