/* ============================================================
   Results Grid — Heatmap Table with Grouped Headers
   ============================================================ */

/* ---------- Legend ---------- */
.rg-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    font-size: 0.8rem;
    color: #555;
}

.rg-legend__item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.rg-legend__swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.1);
}

.rg-legend__swatch--best  { background-color: hsl(130, 45%, 90%); }
.rg-legend__swatch--good  { background-color: hsl(96, 45%, 90%); }
.rg-legend__swatch--avg   { background-color: hsl(52, 45%, 90%); }
.rg-legend__swatch--poor  { background-color: hsl(0, 45%, 90%); }

/* ---------- Table wrapper ---------- */
.rg-wrap {
    position: relative;
    margin-bottom: 8px;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
}

.rg-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Scroll shadow on right edge (on wrapper, not scroll container) */
.rg-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 28px;
    pointer-events: none;
    background: linear-gradient(to left, rgba(255,255,255,0.9), transparent);
    z-index: 5;
    transition: opacity 0.2s;
}

.rg-scroll-hint {
    text-align: center;
    padding: 6px;
    font-size: 0.75rem;
    color: #888;
    background: #f8f9fa;
    border-top: 1px solid #eee;
    transition: opacity 0.3s;
}

/* ---------- Base table ---------- */
.rg-table {
    border-collapse: collapse;
    font-size: 0.82rem;
    line-height: 1.4;
}

/* ---------- Header: Group row ---------- */
.rg-table__group-row th {
    padding: 8px 8px;
    text-align: center;
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: none;
    white-space: nowrap;
}

.rg-table__group-hdr {
    color: #fff;
    border-left: 2px solid rgba(255,255,255,0.4);
}

.rg-table__group-hdr:first-of-type {
    border-left: none;
}

/* Corner / Tyre / Total header cells (span 2 rows) */
.rg-table__corner {
    width: 38px;
    min-width: 38px;
    background: #f8f9fa !important;
    color: #495057;
    font-size: 0.75rem;
    text-align: center;
    vertical-align: middle;
    position: sticky;
    left: 0;
    z-index: 4;
    border-right: 1px solid #dee2e6;
}

.rg-table__tyre-hdr {
    min-width: 160px;
    max-width: 220px;
    background: #f8f9fa !important;
    color: #495057;
    font-weight: 600;
    text-align: left;
    vertical-align: middle;
    padding-left: 10px;
    position: sticky;
    left: 38px;
    z-index: 4;
    border-right: 2px solid #dee2e6;
}

.rg-table__total-hdr {
    width: 68px;
    min-width: 68px;
    background: #f8f9fa !important;
    color: #495057;
    font-weight: 700;
    text-align: center;
    vertical-align: middle;
    border-right: 2px solid #dee2e6;
}

/* ---------- Header: Column row ---------- */
.rg-table__col-row th {
    background: #f1f3f5;
    border-bottom: 2px solid #dee2e6;
}

.rg-table__col-hdr {
    padding: 6px 4px 8px;
    text-align: center;
    vertical-align: bottom;
    font-weight: 500;
    color: #555;
    white-space: normal;
    word-wrap: break-word;
    min-width: 58px;
    max-width: 80px;
}

.rg-table__col-name {
    display: block;
    font-size: 0.7rem;
    line-height: 1.2;
}

.rg-table__col-unit {
    display: block;
    font-size: 0.62rem;
    color: #888;
    font-weight: 400;
    margin-top: 1px;
}

/* Group start separator — thicker left border */
.rg-table__group-start {
    border-left: 2px solid #ccc !important;
}

/* ---------- Group subtotal column ---------- */
.rg-table__subtotal-hdr {
    font-size: 0.68rem;
    font-weight: 700;
    color: #555;
    text-align: center;
    border-left: 1px dashed #bbb;
    min-width: 48px;
    width: 48px;
    padding: 4px 2px;
    background: #f1f3f5;
    vertical-align: bottom;
}

.rg-table__subtotal {
    text-align: center;
    font-weight: 700;
    font-size: 0.78rem;
    color: #212529;
    padding: 8px 5px;
    border-left: 1px dashed #bbb;
    white-space: nowrap;
    min-width: 48px;
}

/* ---------- Body rows ---------- */
.rg-table__row {
    transition: background-color 0.15s ease;
}

.rg-table__row:hover .rg-table__cell,
.rg-table__row:hover .rg-table__subtotal {
    filter: saturate(1.5) brightness(0.97);
}

.rg-table__row:hover .rg-table__tyre {
    background-color: #f0f7ff !important;
}

.rg-table__row--best .rg-table__pos {
    color: #1a7a32;
}

/* Alternating row stripes for readability (frozen columns) */
.rg-table tbody tr:nth-child(even) .rg-table__pos,
.rg-table tbody tr:nth-child(even) .rg-table__tyre {
    background-color: #fafbfc;
}

.rg-table tbody tr:nth-child(odd) .rg-table__pos,
.rg-table tbody tr:nth-child(odd) .rg-table__tyre {
    background-color: #fff;
}

/* Bottom border on rows for visual separation */
.rg-table__row td {
    border-bottom: 1px solid #eee;
}

/* ---------- Position column ---------- */
.rg-table__pos {
    text-align: center;
    font-weight: 700;
    font-size: 0.78rem;
    color: #888;
    padding: 8px 3px;
    position: sticky;
    left: 0;
    z-index: 2;
    border-right: 1px solid #eee;
    min-width: 38px;
    width: 38px;
    vertical-align: middle;
}

/* ---------- Tyre name column ---------- */
.rg-table__tyre {
    padding: 8px 10px 8px 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: sticky;
    left: 38px;
    z-index: 2;
    border-right: 2px solid #dee2e6;
    max-width: 220px;
}

.rg-table__tyre a {
    color: #212529;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.82rem;
}

.rg-table__tyre a:hover {
    color: var(--tyre-reviews-blue, #0db1e7);
}

/* Rank change arrows */
.rg-table__change {
    font-size: 0.55rem;
    font-weight: 700;
    display: inline;
    margin-left: 1px;
    vertical-align: middle;
}

.rg-table__change--up   { color: #28a745; }
.rg-table__change--down { color: #dc3545; }

/* ---------- Total score column ---------- */
.rg-table__total {
    text-align: center;
    padding: 8px 6px;
    border-right: 2px solid #dee2e6;
    font-weight: 700;
    font-size: 0.88rem;
    position: relative;
}

.rg-table__total-val {
    color: #212529;
}

.rg-table__row--best .rg-table__total-val {
    color: #1a7a32;
}

/* ---------- Data cells (the heatmap) ---------- */
.rg-table__cell {
    text-align: center;
    padding: 8px 5px;
    position: relative;
    border-left: 1px solid rgba(0,0,0,0.04);
    transition: filter 0.15s;
    min-width: 58px;
    white-space: nowrap;
}

.rg-table__val {
    font-size: 0.82rem;
    font-weight: 500;
    color: #212529;
    position: relative;
    z-index: 1;
}

/* Best-in-class star indicator */
.rg-table__best-indicator {
    position: absolute;
    top: 1px;
    right: 2px;
    font-size: 0.6rem;
    color: #d4a017;
    line-height: 1;
}

/* Top-3 rank number indicator */
.rg-table__rank-indicator {
    position: absolute;
    top: 1px;
    right: 2px;
    font-size: 0.55rem;
    font-weight: 700;
    color: rgba(0,0,0,0.3);
    line-height: 1;
}

.rg-table__row:hover .rg-table__rank-indicator {
    color: rgba(0,0,0,0.55);
}

/* ---------- Print ---------- */
@media print {
    .rg-table__best-indicator,
    .rg-table__rank-indicator {
        font-size: 0.5rem;
    }

    .rg-table__tyre {
        position: static;
    }

    .rg-table__pos {
        position: static;
    }

    .rg-wrap {
        border: none;
    }
}

/* ============================================================
   Mobile Card View
   ============================================================ */

.rg-mobile {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ---------- Card ---------- */
.rg-card {
    border: 1px solid #dee2e6;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}

.rg-card--best {
    border-color: #28a745;
    box-shadow: 0 0 0 1px #28a745;
}

/* Card header */
.rg-card__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
}

.rg-card__rank {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #f1f3f5;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #495057;
}

.rg-card--best .rg-card__rank {
    background: #28a745;
    color: #fff;
}

.rg-card__info {
    flex: 1;
    min-width: 0;
}

.rg-card__name {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    color: #212529;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rg-card__name:hover {
    color: var(--tyre-reviews-blue, #0db1e7);
}

.rg-card__score {
    flex-shrink: 0;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.95rem;
    color: #212529;
}

/* Group summary pills */
.rg-card__groups {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
}

.rg-card__group-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 20px;
    border: 1.5px solid;
    font-size: 0.75rem;
}

.rg-card__group-label {
    font-weight: 500;
    color: #444;
}

.rg-card__group-pct {
    font-weight: 700;
    color: #212529;
}

/* Expandable details */
.rg-card__details {
    border-top: 1px solid #eee;
}

.rg-card__details-toggle {
    display: block;
    padding: 8px 12px;
    font-size: 0.78rem;
    color: var(--tyre-reviews-blue, #0db1e7);
    cursor: pointer;
    font-weight: 500;
    list-style: none;
}

.rg-card__details-toggle::-webkit-details-marker {
    display: none;
}

.rg-card__details-toggle::before {
    content: '\f054';
    font-family: FontAwesome;
    font-size: 0.65rem;
    margin-right: 6px;
    display: inline-block;
    transition: transform 0.2s;
}

.rg-card__details[open] .rg-card__details-toggle::before {
    transform: rotate(90deg);
}

.rg-card__details-body {
    padding: 0 12px 12px;
}

.rg-card__detail-group {
    margin-bottom: 8px;
}

.rg-card__detail-group:last-child {
    margin-bottom: 0;
}

.rg-card__detail-group-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #666;
    padding: 4px 0 2px;
    border-bottom: 1px solid #eee;
    margin-bottom: 2px;
}

.rg-card__detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 6px;
    border-radius: 4px;
    margin: 1px 0;
}

.rg-card__detail-name {
    font-size: 0.78rem;
    color: #444;
}

.rg-card__detail-value {
    font-size: 0.8rem;
    font-weight: 600;
    color: #212529;
    white-space: nowrap;
}

.rg-card__detail-unit {
    font-size: 0.65rem;
    color: #888;
    font-weight: 400;
}

.rg-card__detail-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    font-size: 0.6rem;
    font-weight: 700;
    margin-left: 4px;
    vertical-align: middle;
}

.rg-card__detail-badge--best {
    background: #fef3cd;
    color: #d4a017;
}

.rg-card__detail-badge--top3 {
    background: #e8f5e9;
    color: #2e7d32;
}

/* Card footer */
.rg-card__footer {
    padding: 8px 12px;
    border-top: 1px solid #eee;
    text-align: right;
}

/* ============================================================
   Weight Controls — Modern Slider UI
   ============================================================ */

.rg-weights {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* Header */
.rg-weights__title {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 4px;
    color: #212529;
}

.rg-weights__intro {
    font-size: 0.82rem;
    color: #6c757d;
    margin: 0 0 16px;
    line-height: 1.45;
}

/* External-test warning callout */
.rg-weights__notice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    margin: 8px 0 16px;
    border-radius: 8px;
    background: #fff8e1;
    border-left: 4px solid #f9a825;
    font-size: 0.82rem;
    line-height: 1.5;
    color: #5d4037;
}

.rg-weights__notice i {
    flex-shrink: 0;
    margin-top: 2px;
    color: #f9a825;
    font-size: 1rem;
}

/* ---------- Preset Chips ---------- */
.rg-weights__presets {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
}

.rg-weights__presets::-webkit-scrollbar { display: none; }

.rg-weights__preset {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1.5px solid #dee2e6;
    background: #fff;
    color: #495057;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.rg-weights__preset:hover {
    border-color: var(--tyre-reviews-blue, #0db1e7);
    color: var(--tyre-reviews-blue, #0db1e7);
    background: #f0faff;
}

.rg-weights__preset--active {
    background: var(--tyre-reviews-blue, #0db1e7);
    border-color: var(--tyre-reviews-blue, #0db1e7);
    color: #fff;
}

.rg-weights__preset--active:hover {
    background: var(--tyre-reviews-blue-dark, #0a9bcc);
    border-color: var(--tyre-reviews-blue-dark, #0a9bcc);
    color: #fff;
}

.rg-weights__preset i {
    font-size: 0.78rem;
}

/* ---------- Distribution Bar ---------- */
.rg-weights__distbar {
    display: flex;
    height: 32px;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 6px;
    background: #eee;
}

.rg-weights__distbar-seg {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: width 0.2s ease;
    min-width: 0;
}

.rg-weights__distbar-label {
    font-size: 0.68rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
    padding: 0 4px;
}

.rg-weights__distbar-seg--narrow .rg-weights__distbar-label {
    display: none;
}

/* ---------- Percentage Summary ---------- */
.rg-weights__summary {
    text-align: center;
    font-size: 0.75rem;
    color: #666;
    margin-bottom: 18px;
    line-height: 1.6;
}

.rg-weights__summary span {
    font-weight: 600;
    color: #444;
}

/* ---------- Range Sliders ---------- */
.rg-weights__sliders {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px 24px;
    margin-bottom: 16px;
}

.rg-weights__slider-row {
    display: grid;
    grid-template-columns: 90px 1fr;
    align-items: center;
    gap: 10px;
}

.rg-weights__slider-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rg-weights__range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    background: #ddd;
}

.rg-weights__range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #999;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.rg-weights__range::-webkit-slider-thumb:hover {
    border-color: #666;
    box-shadow: 0 1px 5px rgba(0,0,0,0.25);
}

.rg-weights__range::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #999;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.rg-weights__range::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: transparent;
}

/* ---------- Subcategory Fine-tuning ---------- */
.rg-weights__subcats {
    border-top: 1px solid #eee;
    margin-bottom: 16px;
}

.rg-weights__subcats-toggle {
    display: block;
    padding: 12px 0;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--tyre-reviews-blue, #0db1e7);
    cursor: pointer;
    list-style: none;
}

.rg-weights__subcats-toggle::-webkit-details-marker {
    display: none;
}

.rg-weights__subcats-toggle i {
    margin-right: 6px;
    font-size: 0.75rem;
}

.rg-weights__subcats-body {
    padding: 0 0 8px;
}

.rg-weights__subcat-group {
    margin-bottom: 16px;
}

.rg-weights__subcat-group:last-child {
    margin-bottom: 0;
}

.rg-weights__subcat-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #555;
    margin: 0 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid #eee;
}

.rg-weights__subcat-sliders {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 8px 24px;
}

.rg-weights__subcat-row {
    display: grid;
    grid-template-columns: 120px 1fr;
    align-items: center;
    gap: 8px;
}

.rg-weights__subcat-label {
    font-size: 0.75rem;
    color: #555;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rg-weights__subcat-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: #ddd;
    outline: none;
    cursor: pointer;
}

.rg-weights__subcat-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #aaa;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}

.rg-weights__subcat-range::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #aaa;
    cursor: pointer;
}

.rg-weights__subcat-range::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: transparent;
}

/* ---------- Action Buttons ---------- */
.rg-weights__actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
}

.rg-weights__reset {
    padding: 8px 18px;
    border: 1.5px solid #dee2e6;
    border-radius: 6px;
    background: #fff;
    color: #495057;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.rg-weights__reset:hover {
    border-color: #adb5bd;
    color: #212529;
}

.rg-weights__apply {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 22px;
    border: none;
    border-radius: 6px;
    background: var(--tyre-reviews-blue, #0db1e7);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.rg-weights__apply:hover {
    background: var(--tyre-reviews-blue-dark, #0a9bcc);
    box-shadow: 0 2px 8px rgba(13, 177, 231, 0.3);
}

/* ---------- Legend Help Popover ---------- */
.rg-legend__help {
    position: relative;
    margin-left: auto;
}

.rg-legend__help-btn {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.8rem;
    color: var(--tyre-reviews-blue, #0db1e7);
    cursor: pointer;
    white-space: nowrap;
}

.rg-legend__help-btn:hover {
    text-decoration: underline;
}

.rg-help-popover {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: 280px;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 12px 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    z-index: 100;
}

.rg-help-popover p {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.5;
    color: #444;
}

/* ---------- Mobile responsive ---------- */
@media (max-width: 768px) {
    .rg-weights {
        padding: 16px;
    }

    .rg-weights__presets {
        flex-wrap: nowrap;
    }

    .rg-weights__sliders {
        grid-template-columns: 1fr;
    }

    .rg-weights__subcat-sliders {
        grid-template-columns: 1fr;
    }

    .rg-weights__actions {
        flex-wrap: wrap;
    }

    .rg-weights__reset,
    .rg-weights__apply {
        flex: 1;
    }

    .rg-help-popover {
        width: 240px;
    }
}

/* ============================================================
   Results Grid Footnote
   ============================================================ */

.rg-footnote {
    background: #f8f9fa;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 18px 22px;
    margin-top: 20px;
    margin-bottom: 32px;
}

.rg-footnote__item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.82rem;
    line-height: 1.5;
    color: #5a6370;
    margin-bottom: 10px;
}

.rg-footnote__item:last-child {
    margin-bottom: 0;
}

.rg-footnote__item i {
    flex-shrink: 0;
    margin-top: 2px;
    color: #94a3b8;
    font-size: 0.88rem;
    width: 16px;
    text-align: center;
}

@media (max-width: 768px) {
    .rg-footnote {
        padding: 14px 16px;
    }
}
