*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --primary: #001A8E;
    --primary-dark: #001166;
    --primary-light: #1a3ab8;
    --accent: #C9A227;
    --text: #12122a;
    --text-muted: #5b6478;
    --border: #d8dee9;
    --white: #ffffff;
    --error: #b42318;
    --error-bg: #fef3f2;
    --shadow: 0 25px 50px -12px rgba(0, 26, 142, 0.22);
    --radius: 16px;
    --kit: #1f7a4d;
}

body {
    font-family: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.loader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.88);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.loader-overlay.show {
    opacity: 1;
    visibility: visible;
}

.loader-overlay img {
    width: 48px;
    height: 48px;
}

.form-page {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 28px 20px 40px;
    position: relative;
}

.form-bg {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 90% 60% at 0% 0%, rgba(201, 162, 39, 0.35), transparent 55%),
        radial-gradient(ellipse 70% 50% at 100% 10%, rgba(26, 58, 184, 0.55), transparent 50%),
        radial-gradient(ellipse 60% 40% at 50% 100%, rgba(0, 17, 102, 0.5), transparent 55%),
        linear-gradient(145deg, #000d4d 0%, #001A8E 38%, #1a3ab8 68%, #2a4fd4 100%);
    z-index: 0;
}

.form-wrapper {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 720px;
}

.form-wrapper-wide {
    max-width: 1180px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--white);
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    margin-bottom: 16px;
    opacity: 0.9;
}

.back-link:hover {
    opacity: 1;
    color: var(--white);
}

.form-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 36px 32px;
}

.form-header {
    text-align: center;
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.form-header .company-logo {
    width: 200px;
    height: auto;
    margin: 0 auto 12px;
    display: block;
    border-radius: 6px;
}

.form-header .company-name {
    font-family: 'Source Serif 4', Georgia, serif;
    color: var(--primary);
    font-weight: 700;
    margin-bottom: 8px;
}

.form-header h1 {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 1.625rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.form-subtitle {
    font-size: 0.9375rem;
    color: var(--text-muted);
}

.section-card {
    background: rgba(0, 26, 142, 0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 16px;
}

.section-note,
.field-hint,
.vat-note {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.vat-note {
    margin-top: 10px;
    color: var(--primary);
}

.required {
    color: var(--error);
}

.conditional-block {
    margin-top: 4px;
}

.products-empty {
    text-align: center;
    padding: 28px 16px;
    color: var(--text-muted);
    border: 1px dashed var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.6);
}

.product-category-groups {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.product-category-group {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--white);
}

.product-category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 10px 14px;
    background: linear-gradient(135deg, #001166 0%, #001A8E 50%, #1a3ab8 100%);
    color: var(--white);
    border: 0;
    text-align: left;
    cursor: pointer;
}

.product-category-header:hover {
    filter: brightness(1.06);
}

.product-category-header:focus-visible {
    outline: 2px solid var(--gold, #c9a227);
    outline-offset: -2px;
}

.product-category-group[data-category="Kits"] .product-category-header {
    background: linear-gradient(135deg, #14532d 0%, #1f7a4d 55%, #2f9e66 100%);
}

.product-category-group:nth-of-type(1) .product-category-header {
    background: linear-gradient(135deg, #001166 0%, #001A8E 50%, #1a3ab8 100%);
}
.product-category-group:nth-of-type(2) .product-category-header {
    background: linear-gradient(135deg, #8a6508 0%, #b8860b 55%, #d4a017 100%);
}
.product-category-group:nth-of-type(3) .product-category-header {
    background: linear-gradient(135deg, #8a3a5c 0%, #b34d7a 55%, #d46b96 100%);
}
.product-category-group:nth-of-type(4) .product-category-header {
    background: linear-gradient(135deg, #15566c 0%, #1f6f8b 55%, #2f92b0 100%);
}
.product-category-group:nth-of-type(5) .product-category-header {
    background: linear-gradient(135deg, #45386a 0%, #5b4b8a 55%, #7663ad 100%);
}
.product-category-group:nth-of-type(6) .product-category-header {
    background: linear-gradient(135deg, #1f4d38 0%, #2f6b4f 55%, #3f8a66 100%);
}
.product-category-group:nth-of-type(7) .product-category-header {
    background: linear-gradient(135deg, #6a3820 0%, #8a4b2f 55%, #b0633f 100%);
}
.product-category-group:nth-of-type(8) .product-category-header {
    background: linear-gradient(135deg, #2a4060 0%, #3d5a80 55%, #5578a8 100%);
}

.product-category-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0;
    flex: 1;
}

.product-category-toggle-label {
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0.9;
    letter-spacing: 0.02em;
}

.product-category-chevron {
    flex-shrink: 0;
    width: 0.55rem;
    height: 0.55rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    opacity: 0.9;
}

.product-category-group:not(.is-collapsed) .product-category-chevron {
    transform: rotate(-135deg);
}

.product-category-body {
    overflow: hidden;
}

.products-table {
    width: 100%;
    margin: 0;
    border-collapse: collapse;
}

.products-table th,
.products-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    font-size: 0.875rem;
}

.products-table th {
    background: rgba(0, 26, 142, 0.04);
    font-weight: 600;
    color: var(--primary-dark);
}

.products-table .col-check { width: 56px; text-align: center; }
.products-table .col-qty,
.products-table .col-price,
.products-table .col-ext { width: 120px; }

.product-row.is-hidden-row {
    display: none;
}

.product-row.is-selected {
    background: rgba(0, 26, 142, 0.04);
}

.product-label {
    font-weight: 600;
    color: var(--text);
}

.table-responsive.is-empty-hidden {
    display: none;
}

.summary-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 16px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
}

.order-history-links {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
}

.order-history-links a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: underline;
}

.order-history-list-table .col-actions {
    width: 130px;
    text-align: right;
    white-space: nowrap;
}

.btn-view-order {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1.5px solid rgba(0, 26, 142, 0.25);
    background: rgba(0, 26, 142, 0.08);
    color: var(--primary);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-view-order:hover {
    background: rgba(0, 26, 142, 0.14);
}

.order-history-modal-box {
    width: min(920px, 96vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.order-history-modal-box .preview-modal-body {
    max-height: calc(90vh - 120px);
}

.order-history-table {
    margin-top: 4px;
}

.order-history-summary {
    max-width: 420px;
}

.summary-grid > div {
    display: contents;
}

.summary-grid span {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.summary-grid strong {
    text-align: right;
    font-size: 0.875rem;
}

.summary-total span,
.summary-total strong {
    font-weight: 700;
    color: var(--primary-dark);
    font-size: 1rem;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 8px;
}

.btn-preview,
.btn-submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 120px;
    padding: 12px 22px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9375rem;
    border: none;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.btn-preview {
    background: rgba(0, 26, 142, 0.08);
    color: var(--primary);
    border: 1.5px solid rgba(0, 26, 142, 0.25);
}

.btn-preview:hover:not(:disabled) {
    background: rgba(0, 26, 142, 0.14);
}

.btn-submit {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: var(--white);
}

.btn-submit:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
}

.btn-preview:disabled,
.btn-submit:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.alert-danger {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid #fecdca;
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
}

.preview-modal,
.success-modal {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.preview-modal[hidden],
.success-modal[hidden] {
    display: none !important;
}

.preview-modal-backdrop,
.success-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(18, 18, 42, 0.45);
}

.preview-modal-box,
.success-modal-box {
    position: relative;
    z-index: 1;
    width: min(860px, 100%);
    background: var(--white);
    border-radius: 14px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.preview-modal-box-pdf {
    width: min(980px, 100%);
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
}

.preview-modal-body-pdf {
    padding: 0 16px 12px;
    flex: 1;
    min-height: 70vh;
    display: flex;
    flex-direction: column;
}

.preview-pdf-loading {
    padding: 48px 20px;
    text-align: center;
    color: var(--text-muted);
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 280px;
}

.preview-pdf-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(0, 26, 142, 0.15);
    border-top-color: #001A8E;
    border-radius: 50%;
    animation: rod-spin 0.85s linear infinite;
}

@keyframes rod-spin {
    to { transform: rotate(360deg); }
}

.preview-pdf-loading-title {
    margin: 0;
    font-size: 1.05rem;
    color: var(--text);
    font-weight: 700;
}

.preview-pdf-loading-hint {
    margin: 0;
    max-width: 360px;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.45;
    color: var(--text-muted);
}

.preview-pdf-loading.is-error .preview-pdf-spinner {
    display: none;
}

.preview-pdf-loading.is-error .preview-pdf-loading-title {
    color: #b42318;
}

.preview-pdf-frame {
    width: 100%;
    flex: 1;
    min-height: 70vh;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f4f6fb;
}

.success-modal-box {
    width: min(420px, 100%);
    padding: 28px 24px;
    text-align: center;
}

.preview-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.preview-modal-header h2,
.success-modal-box h2 {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 1.25rem;
    margin: 0;
}

.preview-modal-close {
    border: none;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
}

.preview-modal-body {
    padding: 16px 20px;
    max-height: 60vh;
    overflow: auto;
}

.preview-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 12px 20px 16px;
    border-top: 1px solid var(--border);
}

.preview-modal-footer .btn-submit {
    min-width: 120px;
}

.success-countdown {
    color: var(--text-muted);
    margin: 10px 0 18px;
}

.select2-container--default .select2-selection--single {
    height: 38px;
    border: 1.5px solid rgba(0, 26, 142, 0.3);
    border-radius: 0.375rem;
    padding: 4px 8px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 28px;
    color: var(--primary-dark);
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
}

@media (max-width: 768px) {
    .form-card {
        padding: 24px 16px;
    }

    .products-table thead {
        display: none;
    }

    .products-table tr {
        display: block;
        padding: 12px;
        border-bottom: 1px solid var(--border);
    }

    .products-table td {
        display: flex;
        justify-content: space-between;
        gap: 12px;
        border: none;
        padding: 6px 0;
    }

    .products-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
    }

    .form-actions {
        flex-direction: column;
    }

    .btn-preview,
    .btn-submit {
        width: 100%;
    }
}
