/**
 * Car Price Guide Plugin Styles - Single Table Layout
 * Version: 2.0.0
 */

/* Theme tokens (light defaults; dark via media query or host page) */
.car-price-guide,
.cpg-sticky-header-clone {
    --cpg-bg: #fff;
    --cpg-bg-muted: #d4e4f7;
    --cpg-text: #000;
    --cpg-text-secondary: #111;
    --cpg-text-muted: #666;
    --cpg-border: #d2d3d4;
    --cpg-border-strong: #999;
    --cpg-border-hover: #b8b8b8;
    --cpg-dropdown-hover: #e8f4fc;
    --cpg-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --cpg-sticky-shadow: 2px 0 4px rgba(0, 0, 0, 0.1);
    --cpg-clone-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    .car-price-guide,
    .cpg-sticky-header-clone {
        --cpg-bg: #1a1a1c;
        --cpg-bg-muted: #2a3544;
        --cpg-text: #fff;
        --cpg-text-secondary: #fff;
        --cpg-text-muted: rgba(255, 255, 255, 0.82);
        --cpg-border: #48484a;
        --cpg-border-strong: #6e6e73;
        --cpg-border-hover: #6a6a6e;
        --cpg-dropdown-hover: #3a4555;
        --cpg-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
        --cpg-sticky-shadow: 2px 0 4px rgba(0, 0, 0, 0.35);
        --cpg-clone-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
        color-scheme: dark;
    }
}

:is(
    html.dark,
    html.is-dark,
    html[data-theme="dark"],
    html[data-bs-theme="dark"],
    body.dark,
    body.dark-mode,
    body.is-dark,
    body.wp-dark-mode-active
) :is(.car-price-guide, .cpg-sticky-header-clone) {
    --cpg-bg: #1a1a1c;
    --cpg-bg-muted: #2a3544;
    --cpg-text: #fff;
    --cpg-text-secondary: #fff;
    --cpg-text-muted: rgba(255, 255, 255, 0.82);
    --cpg-border: #48484a;
    --cpg-border-strong: #6e6e73;
    --cpg-border-hover: #6a6a6e;
    --cpg-dropdown-hover: #3a4555;
    --cpg-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    --cpg-sticky-shadow: 2px 0 4px rgba(0, 0, 0, 0.35);
    --cpg-clone-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
}

/* Main Container */
.car-price-guide {
    overflow: visible; /* Ensure no clipping */
    position: relative;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    line-height: 1.4;
    color: var(--cpg-text);
    background: var(--cpg-bg);
    width: fit-content;
    box-shadow: var(--cpg-shadow);
	display: grid;
}

/* Header */
.cpg-header {
    padding: 15px 20px;
    background: var(--cpg-bg);
}

.cpg-category {
    font-size: 32px;
    font-weight: bold;
    margin: 0;
    padding: 0;
    text-transform: uppercase;
    color: var(--cpg-text);
}

.cpg-filters {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    padding: 10px 16px 14px;
    background: var(--cpg-bg);
    overflow: scroll;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.cpg-filters::-webkit-scrollbar {
    display: none;
}

.cpg-filter-scroll {
    flex: 0 0 auto;
    position: absolute;
    z-index: 2;
    min-width: 25px;
    padding: 8px 0px;
    border: 0;
    background: var(--cpg-bg);
    color: var(--cpg-text-secondary);
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
    outline: none;
    box-shadow: none;
    -webkit-tap-highlight-color: transparent;
}

.cpg-filter-scroll:focus,
.cpg-filter-scroll:active,
.cpg-filter-scroll:focus-visible {
    outline: none;
    box-shadow: none;
    border: 0;
}
.cpg-filter-scroll-prev {
	left: 2%;
	background: var(--cpg-bg);
	margin-left: -7px;
	padding-left: 0;
	width: 0;
	position: absolute;
}

.cpg-filter-scroll-next {
	right: 0;
	background: var(--cpg-bg);
	margin-right: 0;
	padding-right: 0;
	width: 0;
}

.cpg-filter-pill[data-cpg-filter="all"] {
    margin-left: 1%;
}


.cpg-filter-pill {
    display: inline-block;
    padding: 7px 16px;
    border: 1px solid var(--cpg-border);
    border-radius: 999px;
    background: var(--cpg-bg);
    color: var(--cpg-text-secondary);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.25;
    white-space: nowrap;
    cursor: pointer;
    box-sizing: border-box;
	width: fit-content;
    text-decoration: none;
}

.cpg-filter-pill:hover,
.cpg-filter-pill:focus,
.cpg-filter-pill:visited {
    color: var(--cpg-text-secondary);
    text-decoration: none;
}

.cpg-filter-pill:hover {
    border-color: var(--cpg-border-hover);
}

.cpg-filter-pill.is-active,
.cpg-filter-pill.is-active:hover,
.cpg-filter-pill.is-active:focus,
.cpg-filter-pill.is-active:visited {
    background: #4aa8e8;
    border-color: #4aa8e8;
    color: #fff;
}

.cpg-filter-brand,
.cpg-filter-range {
    position: relative;
}

.cpg-brand-dropdown,
.cpg-range-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 300;
    min-width: 220px;
    max-height: 280px;
    overflow-y: auto;
    background: var(--cpg-bg);
    border: 1px solid var(--cpg-border);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.cpg-brand-option,
.cpg-range-option {
    display: block;
    width: 100%;
    margin: 0;
    padding: 8px 14px;
    background: transparent;
    color: var(--cpg-text-secondary);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.cpg-brand-option:hover,
.cpg-brand-option.is-selected,
.cpg-range-option:hover,
.cpg-range-option.is-selected {
    background: var(--cpg-dropdown-hover);
}

/* Table Scroll Container */
.cpg-table-scroll {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    /* height: 80vh; */
    /* height: 1000px; */
    /* max-height: calc(100vh + 200px); */
}

/* Main Table */
.cpg-main-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    border-spacing: 0;
    font-size: 10px;
    background: var(--cpg-bg);
}

/* Sticky Header Row */
.cpg-main-table thead {
    background: var(--cpg-bg);
}

.cpg-main-table thead th {
    padding: 8px 6px;
    text-align: left;
    font-weight: bold;
    font-size: 9px;
    color: var(--cpg-text);
    text-transform: uppercase;
    white-space: nowrap;
    vertical-align: middle;
    border-bottom: 2px solid var(--cpg-border-strong);
    box-sizing: border-box;
    background: var(--cpg-bg);
    position: sticky;
    top: 0;
    z-index: 100;
}

.cpg-main-table tbody td {
    color: var(--cpg-text);
}

.cpg-main-table thead th:last-child {
    border-right: none;
}

.cpg-main-table thead th[data-sortable] {
    cursor: pointer;
    user-select: none;
}

.cpg-main-table thead th[data-sortable]:hover {
    text-decoration: underline;
}

.cpg-main-table thead th.cpg-sort-asc::after {
    content: ' \25B2';
    font-size: 8px;
}

.cpg-main-table thead th.cpg-sort-desc::after {
    content: ' \25BC';
    font-size: 8px;
}

.cpg-sorted-row td.cpg-col-brand-panel {
    font-weight: bold;
    font-size: 10px;
    white-space: normal;
    pointer-events: auto;
}

.cpg-sorted-brand-name {
    padding: 4px 6px 6px;
}

.cpg-sorted-row .cpg-deferred-image {
    display: block;
    width: 100%;
    height: auto;
    min-height: 40px;
    background: #111;
}

/* Alternating header colors - match table pattern starting with price column */
.cpg-main-table thead th { background: var(--cpg-bg); }
.cpg-main-table thead th.cpg-col-price,
.cpg-main-table thead th.cpg-col-engine,
.cpg-main-table thead th.cpg-col-power,
.cpg-main-table thead th.cpg-col-trans,
.cpg-main-table thead th.cpg-col-torque,
.cpg-main-table thead th.cpg-col-max-speed,
.cpg-main-table thead th.cpg-col-airbags { background: var(--cpg-bg-muted); }

/* Sticky Brand Panel Column */
.cpg-col-brand-panel {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--cpg-bg);
    width: 120px;
    min-width: 120px;
    max-width: 120px;
    vertical-align: top;
    padding: 0;
    box-shadow: var(--cpg-sticky-shadow);
    pointer-events: none;
}

.cpg-main-table thead th.cpg-col-brand-panel {
    z-index: 101; /* above sticky header */
}

/* Sticky Model Column (adjacent to brand panel) */
.cpg-main-table thead th.cpg-col-model {
    position: sticky;
    left: 120px; /* brand panel width */
    top: 0;
    z-index: 102; /* above brand panel header */
    background: var(--cpg-bg);
}

.cpg-main-table thead th.cpg-col-model > div {
    position: sticky;
    left: 120px;
    top: 0;
    background: inherit;
}


.cpg-model-row td.cpg-col-model {
    position: sticky;
    left: 120px; /* brand panel width */
    z-index: 2; /* above regular cells but below header */
    background: var(--cpg-bg); /* ensure opaque background when overlapping */
    pointer-events: none;
}

/* Brand Panel Content */
.cpg-brand-panel-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.cpg-brand-header {
    background: #FFCC00;
    padding: 12px 10px;
    margin: 0;
}

.cpg-brand-name {
    font-size: 16px;
    font-weight: bold;
    margin: 0;
    padding: 0;
    color: #000;
    line-height: 1.2;
}

.cpg-brand-image {
    background: #000;
    padding: 0;
    margin: 0;
}

.cpg-brand-image img {
    width: 100%;
    height: auto;
    display: block;
}

.cpg-brand-description {
    background: #000;
    color: #fff;
    padding: 8px 10px;
    font-size: 9px;
    line-height: 1.3;
    margin: 0;
}

.cpg-brand-description p {
    margin: 0;
}

/* Make brand header and description rows stick on horizontal scroll */
/* Sticky brand header and model description cells */
.cpg-brand-header-cell {
    position: relative; /* just relative, not sticky */
    padding: 0;
    background: #FFCC00;
    pointer-events: none;
}

.cpg-model-description-cell {
    position: relative; /* just relative, not sticky */
    padding: 0;
    background: #000;
    color: #fff;
    pointer-events: none;
}

/* Overlay for sticky effect */
.cpg-brand-header-overlay {
    position: sticky;
    left: 0;
    top: 0;
    /* z-index: 70; above data cells */
    z-index: 89; /* above data cells */
    width: 300px; /* covers sticky columns */
    pointer-events: none;
    display: flex;
    align-items: stretch;
}

.cpg-model-description-overlay {
    position: sticky;
    left: 0;
    z-index: 60; /* above data cells */
    width: 300px; /* covers sticky columns */
    pointer-events: none;
    display: flex;
    align-items: stretch;
}

/* Content div that gets pushed by the overlay */
.cpg-brand-header-content,
.cpg-model-description-content {
    padding-left: 300px; /* Match the width of the overlay */
}

.cpg-model-description-content {
    padding-left: 300px;
    background: #000; /* Add this */
}

.cpg-model-description-content > div {
    margin: 0;
    padding: 8px 10px;
    color: #fff;
    font-size: 12px;
    font-weight: bold;
    line-height: 1.3;
}

.cpg-brand-header-content {
    background: #FFCC00;
}

.cpg-brand-header-content h2 {
    margin: 0;
    padding: 12px 10px;
    font-size: 16px;
    font-weight: bold;
    color: #000;
    line-height: 1.2;
}

.cpg-brand-header-row {
    position: sticky;
    top: 29px;
    z-index: 100;
    background: var(--cpg-bg);
}

/* Style the content inside the overlay */
.cpg-brand-header-overlay h2,
.cpg-model-description-overlay > div {
    pointer-events: auto;
    margin: 0;
    padding: 12px 10px;
}

.cpg-brand-header-overlay {
    background: #FFCC00;
}

.cpg-model-description-overlay {
    background: #000;
}

/* Brand header specific styles */
.cpg-brand-header-overlay h2 {
    font-size: 16px;
    font-weight: bold;
    color: #000;
    line-height: 1.2;
    pointer-events: auto;
    margin: 0;
    padding: 12px 10px;
}

/* Model description specific styles */
.cpg-model-description-overlay > div {
    color: #fff;
    font-size: 11px;
    line-height: 1.3;
    pointer-events: auto;
    margin: 0;
    padding: 8px 10px;
    font-weight: bold;
}

/* Range image row */
.cpg-range-image-row {
    background: #000;
}

.cpg-range-image-cell {
    padding: 0;
    background: #000;
}

.cpg-range-image-wrapper {
    padding: 0;
    margin: 0;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cpg-range-image-wrapper img {
    max-width: 100%;
    height: auto;
    display: block;
}


/* Prevent horizontal drag on sticky left area */
.cpg-brand-header-cell,
.cpg-model-description-cell,
.cpg-model-description,
.cpg-col-brand-panel,
.cpg-main-table thead th.cpg-col-model,
.cpg-model-row td.cpg-col-model {
    -ms-touch-action: pan-y; /* IE/Edge legacy */
    touch-action: pan-y;     /* block horizontal panning on touch/pointer */
}

/* Ensure sticky cells receive input events for JS guards */
/* (no pointer-events: none here) */

/* Reduce browser momentum horizontal chaining */
.cpg-table-scroll {
    overscroll-behavior-x: contain;
}

/* Model Description Row */
.cpg-model-description {
    background: #000;
    color: #fff;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: bold;
    margin: 0;
}

.cpg-model-row td:last-child {
    border-right: none;
}

/* Column colors - alternating pattern starting with price column */
.cpg-model-row td { background: var(--cpg-bg); }
.cpg-model-row td.cpg-col-price,
.cpg-model-row td.cpg-col-engine,
.cpg-model-row td.cpg-col-power,
.cpg-model-row td.cpg-col-trans,
.cpg-model-row td.cpg-col-torque,
.cpg-model-row td.cpg-col-max-speed,
.cpg-model-row td.cpg-col-airbags { background: var(--cpg-bg-muted); }

/* Column Widths */
.cpg-col-model { width: 180px; font-weight: bold; }
.cpg-col-price { width: 90px; text-align: right; font-weight: bold; }
.cpg-col-hp { width: 100px; text-align: right; }
.cpg-col-engine { width: 80px; text-align: center; }
.cpg-col-fuel-supply { width: 100px; text-align: center; }
.cpg-col-power { width: 80px; text-align: right; }
.cpg-col-power-mass { width: 90px; text-align: right; }
.cpg-col-torque { width: 80px; text-align: right; }
.cpg-col-gears { width: 60px; text-align: center; }
.cpg-col-trans { width: 60px; text-align: center; }
.cpg-col-accel { width: 80px; text-align: right; }
.cpg-col-max-speed { width: 80px; text-align: right; }
.cpg-col-fuel-consumption { width: 95px; text-align: center; }
.cpg-col-airbags { width: 70px; text-align: center; }
.cpg-col-co2 { width: 60px; text-align: right; }

/* Loading placeholder */
.cpg-loading-cell {
    padding: 20px;
    text-align: center;
    color: var(--cpg-text-muted);
    font-style: italic;
}

/* Skip painting/layout for off-screen brand blocks */
.cpg-brand-body {
    content-visibility: auto;
    contain-intrinsic-size: auto 600px;
}

.cpg-brand-placeholder-body {
    content-visibility: visible;
    contain-intrinsic-size: auto 48px;
}

/* Sticky Header Clone - Fixed at top of viewport when scrolling */
.cpg-sticky-header-clone {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;
    overflow-x: hidden;
    overflow-y: hidden;
    background: var(--cpg-bg);
    box-shadow: var(--cpg-clone-shadow);
    width: fit-content;
    touch-action: pan-y;
    overscroll-behavior-x: none;
}

.cpg-sticky-header-clone .cpg-cloned-table {
    margin: 0;
    border-collapse: collapse;
}

.cpg-sticky-header-clone .cpg-main-table thead th {
    position: static; /* Override sticky positioning in clone */
    top: auto;
    border-bottom: 2px solid var(--cpg-border-strong);
}

.cpg-sticky-header-clone .cpg-col-brand-panel {
    position: sticky;
    left: 0;
    z-index: 10001;
    background: var(--cpg-bg);
    box-shadow: var(--cpg-sticky-shadow);
}

.cpg-sticky-header-clone .cpg-col-model {
    position: sticky;
    left: 120px;
    z-index: 10002;
    background: var(--cpg-bg);
}

/* Mobile adjustments for sticky clone */
@media screen and (max-width: 768px) {
    .cpg-sticky-header-clone {
        transform: none;
    }

    .cpg-sticky-header-clone .cpg-col-model {
        left: 105px;
    }

    .cpg-sticky-header-clone .cpg-col-brand-panel {
        width: 105px;
        min-width: 105px;
        max-width: 105px;
    }
}

/* Mobile Styles */
@media screen and (max-width: 768px) {
    .car-price-guide {
        width: 100%;
        margin-left: 0;
        margin-right: 0;
    }

    /* Narrower brand panel on mobile */
    .cpg-col-brand-panel {
        width: 105px;
        min-width: 105px;
        max-width: 105px;
    }

    .cpg-brand-name {
        font-size: 14px;
    }

    .cpg-brand-description {
        font-size: 8px;
        padding: 6px 8px;
        background-color: #000;
    }


    .cpg-model-row td.cpg-col-model {
        left: 105px;
    }

    .cpg-main-table thead th.cpg-col-model{
        left: 105px;
    }

    /* Make model description sticky on mobile */
    .cpg-model-description {
        position: sticky;
        left: 0;
        z-index: 55; /* above the cell */
        padding-left: 245px; /* 105px brand panel + 140px model column */
    }

    /* Smaller column widths on mobile */
    .cpg-col-model { width: 140px; }
    .cpg-col-price { width: 58px; }
    .cpg-col-hp { width: 50px; }
    .cpg-col-engine { width: 52px; }
    .cpg-col-fuel-supply { width: 69px; }
    .cpg-col-power { width: 60px; }
    .cpg-col-power-mass { width: 70px; }
    .cpg-col-torque { width: 60px; }
    .cpg-col-gears { width: 50px; }
    .cpg-col-trans { width: 50px; }
    .cpg-col-accel { width: 60px; }
    .cpg-col-max-speed { width: 60px; }
    .cpg-col-fuel-consumption { width: 75px; }
    .cpg-col-airbags { width: 55px; }
    .cpg-col-co2 { width: 50px; }
}

/* Floating valuation CTA */
.cpg-valuation-cta {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    z-index: 10050;
    display: flex;
    align-items: center;
    gap: 18px;
    width: min(740px, calc(100vw - 48px));
    padding: 14px 44px 14px 14px;
    box-sizing: border-box;
    background: linear-gradient(180deg, #2c2c2c 0%, #161616 100%);
    border-radius: 20px;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.08),
        0 10px 36px rgba(0, 0, 0, 0.45),
        0 0 28px rgba(255, 255, 255, 0.22);
    font-family: Arial, Helvetica, sans-serif;
    color: #fff;
}

.cpg-cta-close {
    position: absolute;
    top: 6px;
    right: 10px;
    width: 28px;
    height: 28px;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 22px;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
    opacity: 0.85;
}

.cpg-cta-close:hover,
.cpg-cta-close:focus {
    opacity: 1;
}

.cpg-cta-logo {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 10px;
    background: #fff;
    border-radius: 10px;
    line-height: 0;
}

.cpg-cta-logo-img {
    display: block;
    width: 118px;
    height: auto;
}

.cpg-cta-copy {
    flex: 1 1 auto;
    min-width: 0;
}

.cpg-cta-heading {
    margin: 0 0 4px;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.25;
}

.cpg-cta-sub {
    margin: 0;
    color: rgba(255, 255, 255, 0.78);
    font-size: 13px;
    font-weight: 400;
    line-height: 1.35;
}

.cpg-cta-button {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: #E31E24;
    color: #fff;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
}

.cpg-cta-button:hover,
.cpg-cta-button:focus {
    background: #c9181e;
    color: #fff;
    text-decoration: none;
}

.cpg-cta-car-icon {
    width: 22px;
    height: 14px;
    fill: currentColor;
    flex: 0 0 auto;
}

body.cpg-cta-visible .car-price-guide {
    margin-bottom: 110px;
}

@media screen and (max-width: 640px) {
    .cpg-valuation-cta {
        bottom: 12px;
        gap: 12px;
        width: calc(100vw - 24px);
        padding: 14px 36px 14px 12px;
        border-radius: 16px;
        flex-wrap: wrap;
    }

    .cpg-cta-logo {
        padding: 6px 8px;
    }

    .cpg-cta-logo-img {
        width: 96px;
    }

    .cpg-cta-copy {
        flex: 1 1 calc(100% - 70px);
    }

    .cpg-cta-heading {
        font-size: 14px;
    }

    .cpg-cta-sub {
        font-size: 12px;
    }

    .cpg-cta-button {
        width: 100%;
        padding: 11px 16px;
    }
}

/* Print Styles */
@media print {
    .cpg-valuation-cta {
        display: none;
    }

    .cpg-table-scroll {
        overflow: visible;
    }

    .cpg-main-table {
        page-break-inside: auto;
    }

    .cpg-model-row {
        page-break-inside: avoid;
        page-break-after: auto;
    }

    .cpg-col-brand-panel {
        position: static;
    }

    .cpg-main-table thead {
        position: static;
    }

    .cpg-brand-body {
        content-visibility: visible;
    }
}
