/* ==========================================================================
   AI Match — page-scoped styles. Reuses Home V3 shared variables
   (--eb-ink, --eb-muted, --eb-border, --eb-accent, --eb-success, --eb-radius-*)
   wherever available; page-only colors are declared under .ai-match-page.
   ========================================================================== */

.ai-match-page {
    --aim-blue: #2563eb;
    --aim-blue-hover: #1d4ed8;
    --aim-navy: var(--eb-ink, #0f172a);
    --aim-muted: var(--eb-muted, #64748b);
    --aim-border: var(--eb-border, #e2e8f0);
    --aim-amber: var(--eb-accent, #f8b622);
    --aim-green: var(--eb-success, #159447);
    --aim-surface: #fff;
    --aim-surface-muted: #f8fafc;
    --aim-radius-card: var(--eb-radius-card, 14px);
    --aim-radius-lg: 16px;

    max-width: 1440px;
    margin: 0 auto;
    padding: 24px 28px 60px;
    font-family: var(--eb-font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif);
    color: var(--aim-navy);
}

.ai-match-page * {
    box-sizing: border-box;
}

/* Header nav active-state — scoped so it only ever visually applies on the
   AI Match page itself (only this page loads this stylesheet). */
body.eb-home-v3:has(.ai-match-page) .eb-desktop-nav a[href="ai_match.php"],
body.eb-home-v3:has(.ai-match-page) .eb-mobile-nav a[href="ai_match.php"] {
    position: relative;
    color: var(--eb-ink);
    font-weight: 700;
}

body.eb-home-v3:has(.ai-match-page) .eb-desktop-nav a[href="ai_match.php"]::after {
    content: "";
    position: absolute;
    left: 2px;
    right: 2px;
    bottom: -8px;
    height: 2px;
    border-radius: 2px;
    background: var(--eb-accent, #f5b82e);
}

/* ---------- Intro ---------- */

.ai-match-intro {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.ai-match-intro-text {
    max-width: 640px;
}

.ai-match-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.ai-match-title-row h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    color: var(--aim-navy);
}

.ai-match-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 12px;
    border: 1px solid var(--aim-green);
    border-radius: 999px;
    color: var(--aim-green);
    font-size: 12px;
    font-weight: 600;
    background: rgba(21, 148, 71, .06);
}

.ai-match-intro-text p {
    margin: 0;
    color: var(--aim-muted);
    font-size: 13px;
    line-height: 1.5;
}

.ai-match-stats {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.ai-match-stat {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: 1px solid var(--aim-border);
    border-radius: var(--aim-radius-card);
    background: var(--aim-surface);
    font-size: 12px;
    color: var(--aim-muted);
    white-space: nowrap;
}

.ai-match-stat svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: var(--aim-navy);
    stroke-width: 1.8;
    flex-shrink: 0;
}

.ai-match-stat div {
    display: flex;
    align-items: baseline;
    gap: 5px;
}

.ai-match-stat strong {
    font-size: 15px;
    font-weight: 700;
    color: var(--aim-navy);
}

.ai-match-stat-muted svg {
    stroke: var(--aim-muted);
}

/* ---------- Empty state ---------- */

.ai-match-empty {
    display: grid;
    justify-items: center;
    gap: 16px;
    padding: 48px 24px;
    border: 1px solid var(--aim-border);
    border-radius: var(--aim-radius-lg);
    background: var(--aim-surface);
    text-align: center;
}

.ai-match-empty p {
    margin: 0;
    max-width: 480px;
    color: var(--aim-muted);
    font-size: 14px;
}

/* ---------- Buttons ---------- */

.btn-primary-ai,
.btn-secondary-ai {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 9px 18px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.btn-primary-ai {
    background: var(--aim-blue);
    color: #fff;
}

.btn-primary-ai:hover,
.btn-primary-ai:focus-visible {
    background: var(--aim-blue-hover);
}

.btn-secondary-ai {
    background: var(--aim-surface);
    border-color: var(--aim-border);
    color: var(--aim-navy);
}

.btn-secondary-ai:hover,
.btn-secondary-ai:focus-visible {
    background: var(--aim-surface-muted);
}

.ai-match-page a:focus-visible,
.ai-match-page button:focus-visible,
.ai-match-page select:focus-visible,
.ai-match-page input:focus-visible {
    outline: 2px solid var(--aim-blue);
    outline-offset: 2px;
}

/* ---------- Three-column layout ---------- */

.ai-match-body {
    display: grid;
    grid-template-columns: minmax(250px, 270px) minmax(0, 1fr) minmax(340px, 400px);
    gap: 18px;
    align-items: start;
}

.ai-match-col-sources,
.ai-match-col-detail {
    position: sticky;
    top: 16px;
    display: grid;
    gap: 16px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
}

.ai-match-panel {
    padding: 16px;
    border: 1px solid var(--aim-border);
    border-radius: var(--aim-radius-lg);
    background: var(--aim-surface);
}

.ai-match-panel h2 {
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 700;
}

.ai-match-panel-subtitle {
    margin-bottom: 10px !important;
}

.ai-match-panel-hint {
    margin: 0 0 12px;
    font-size: 12px;
    color: var(--aim-muted);
}

/* ---------- Source (own-listing) list ---------- */

.ai-match-source-list {
    display: grid;
    gap: 8px;
    margin: 0 0 10px;
    padding: 0;
    list-style: none;
}

.ai-match-source-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border: 1px solid var(--aim-border);
    border-radius: 10px;
    background: var(--aim-surface);
    text-decoration: none;
    color: var(--aim-navy);
    position: relative;
    transition: border-color .15s ease, background-color .15s ease;
}

.ai-match-source-item:hover {
    border-color: var(--aim-blue);
}

.ai-match-source-item.is-selected {
    background: #fff8e8;
    border-color: var(--aim-amber);
}

.ai-match-source-item.is-selected::before {
    content: "";
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 3px;
    background: var(--aim-amber);
}

.ai-match-source-thumb {
    display: block;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 8px;
    overflow: hidden;
    background: var(--aim-surface-muted);
}

.ai-match-source-thumb img,
.ai-match-source-thumb .home-v3-image-placeholder {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-match-source-body {
    display: grid;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.ai-match-source-body strong {
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-match-source-body span {
    font-size: 12px;
    color: var(--aim-muted);
}

.ai-match-source-check {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--aim-blue);
    color: #fff;
}

.ai-match-source-check svg {
    width: 13px;
    height: 13px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
}

.ai-match-more-link {
    display: block;
    text-align: center;
    padding: 9px;
    border: 1px solid var(--aim-border);
    border-radius: 10px;
    color: var(--aim-navy);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

.ai-match-more-link:hover {
    background: var(--aim-surface-muted);
}

/* ---------- Quick filter chips ---------- */

.ai-match-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.ai-match-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1px solid var(--aim-border);
    border-radius: 999px;
    background: var(--aim-surface);
    color: var(--aim-navy);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
}

.ai-match-chip svg {
    width: 13px;
    height: 13px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

.ai-match-chip:hover {
    border-color: var(--aim-blue);
}

.ai-match-chip.is-active {
    background: #fff8e8;
    border-color: var(--aim-amber);
    color: #92660a;
}

.ai-match-filters-details summary {
    cursor: pointer;
    padding: 8px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--aim-blue);
    list-style: none;
}

.ai-match-filters-details summary::-webkit-details-marker {
    display: none;
}

.ai-match-filters-details summary::before {
    content: "▸ ";
}

.ai-match-filters-details[open] summary::before {
    content: "▾ ";
}

.ai-match-filters {
    display: grid;
    gap: 12px;
    margin-top: 8px;
}

.ai-match-filter-row {
    display: grid;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
}

.ai-match-filter-row select,
.ai-match-filter-row input {
    min-height: 38px;
    padding: 6px 10px;
    border: 1px solid var(--aim-border);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
}

.ai-match-filter-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 500;
}

.ai-match-filter-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

/* ---------- Results column ---------- */

.ai-match-col-results {
    min-width: 0;
}

.ai-match-results-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.ai-match-results-head h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.ai-match-count {
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--aim-surface-muted);
    color: var(--aim-muted);
    font-size: 12px;
    font-weight: 600;
}

.ai-match-sort-form {
    margin-left: auto;
    display: flex;
    align-items: center;
}

.ai-match-sort-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--aim-muted);
}

.ai-match-sort-label select {
    min-height: 34px;
    padding: 4px 8px;
    border: 1px solid var(--aim-border);
    border-radius: 8px;
    font-size: 12px;
    font-family: inherit;
    color: var(--aim-navy);
}

.ai-match-candidate-list {
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.ai-match-candidate {
    display: grid;
    grid-template-columns: 96px 1fr auto auto;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border: 1px solid var(--aim-border);
    border-radius: var(--aim-radius-lg);
    background: var(--aim-surface);
    text-decoration: none;
    color: var(--aim-navy);
    position: relative;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.ai-match-candidate:hover {
    border-color: var(--aim-blue);
}

.ai-match-candidate.is-selected {
    border-color: var(--aim-blue);
}

.ai-match-candidate.is-selected::before {
    content: "";
    position: absolute;
    left: 12px;
    right: 12px;
    top: 0;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--aim-amber);
}

.ai-match-candidate-media {
    width: 96px;
    height: 80px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--aim-surface-muted);
    flex-shrink: 0;
}

.ai-match-candidate-media img,
.ai-match-candidate-media .home-v3-image-placeholder {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-match-candidate-body {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.ai-match-candidate-body strong {
    font-size: 15px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-match-candidate-price {
    font-size: 14px;
    font-weight: 700;
    color: var(--aim-green);
}

.ai-match-candidate-location,
.ai-match-candidate-owner {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--aim-muted);
}

.ai-match-candidate-location svg,
.ai-match-candidate-owner svg {
    width: 13px;
    height: 13px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    flex-shrink: 0;
}

.ai-match-candidate-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
}

.ai-match-tag {
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(21, 148, 71, .08);
    color: var(--aim-green);
    font-size: 11px;
    font-weight: 600;
}

.ai-match-candidate-score {
    display: grid;
    justify-items: center;
    gap: 2px;
    width: 56px;
}

.ai-match-candidate-score svg {
    width: 44px;
    height: 44px;
    transform: rotate(-90deg);
}

.ai-match-score-track {
    fill: none;
    stroke: var(--aim-border);
    stroke-width: 3.5;
}

.ai-match-score-value {
    fill: none;
    stroke: var(--aim-green);
    stroke-width: 3.5;
    stroke-linecap: round;
    stroke-dasharray: 97.4;
    stroke-dashoffset: calc(97.4 - (97.4 * var(--ai-match-score-pct, 0) / 100));
    transition: stroke-dashoffset .3s ease;
}

.ai-match-candidate-score strong {
    font-size: 13px;
    font-weight: 700;
    color: var(--aim-navy);
}

.ai-match-candidate-chevron {
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    color: var(--aim-muted);
}

.ai-match-candidate-chevron svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

/* ---------- Detail panel ---------- */

.ai-match-detail h2 {
    margin-bottom: 14px;
}

.ai-match-compare {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.ai-match-compare-side {
    display: grid;
    justify-items: center;
    gap: 4px;
    text-align: center;
}

.ai-match-compare-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--aim-muted);
    text-transform: uppercase;
    letter-spacing: .02em;
}

.ai-match-compare-thumb {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 10px;
    overflow: hidden;
    background: var(--aim-surface-muted);
}

.ai-match-compare-thumb img,
.ai-match-compare-thumb .home-v3-image-placeholder {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-match-compare-side strong {
    font-size: 13px;
    font-weight: 600;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-match-compare-side span {
    font-size: 13px;
    font-weight: 700;
    color: var(--aim-green);
}

.ai-match-compare-swap {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--aim-surface-muted);
    color: var(--aim-navy);
    flex-shrink: 0;
}

.ai-match-compare-swap svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

.ai-match-total-score {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 14px;
    margin-bottom: 14px;
    border-radius: var(--aim-radius-card);
    background: rgba(21, 148, 71, .06);
}

.ai-match-total-score strong {
    font-size: 32px;
    font-weight: 700;
    color: var(--aim-green);
}

.ai-match-total-score span {
    font-size: 13px;
    color: var(--aim-muted);
}

.ai-match-total-score em {
    margin-left: auto;
    font-style: normal;
    font-size: 12px;
    font-weight: 700;
    color: var(--aim-green);
}

.ai-match-breakdown {
    margin-bottom: 16px;
}

.ai-match-breakdown h3,
.ai-match-price-calc h3 {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 700;
}

.ai-match-breakdown-row {
    display: grid;
    grid-template-columns: 130px 1fr 40px;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--aim-muted);
}

.ai-match-breakdown-bar {
    display: block;
    height: 6px;
    border-radius: 999px;
    background: var(--aim-surface-muted);
    overflow: hidden;
}

.ai-match-breakdown-bar span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--aim-green);
}

.ai-match-breakdown-pct {
    text-align: right;
    font-weight: 700;
    color: var(--aim-navy);
}

.ai-match-reason-list {
    margin: 0 0 16px;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 8px;
}

.ai-match-reason-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.ai-match-reason-list svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: var(--aim-green);
    stroke-width: 2.2;
    flex-shrink: 0;
}

.ai-match-price-calc {
    padding: 14px;
    margin-bottom: 16px;
    border-radius: var(--aim-radius-card);
    background: #fff8e8;
}

.ai-match-price-formula {
    margin: 0 0 6px;
    font-size: 15px;
    font-weight: 600;
    color: var(--aim-navy);
}

.ai-match-price-formula strong {
    color: #92660a;
}

.ai-match-price-verdict {
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    color: #92660a;
}

.ai-match-price-verdict-muted {
    color: var(--aim-muted);
    font-weight: 500;
}

.ai-match-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.ai-match-badge-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 999px;
    background: var(--aim-surface-muted);
    font-size: 11px;
    font-weight: 600;
    color: var(--aim-navy);
}

.ai-match-badge-verified {
    background: rgba(21, 148, 71, .08);
    color: var(--aim-green);
}

.ai-match-badge-verified svg {
    width: 13px;
    height: 13px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

.ai-match-actions {
    display: grid;
    gap: 8px;
}

.ai-match-action-primary,
.ai-match-action-secondary {
    width: 100%;
}

.ai-match-action-link {
    text-align: center;
    padding: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--aim-muted);
    text-decoration: underline;
}

.ai-match-detail-empty {
    display: grid;
    justify-items: center;
    padding: 40px 16px;
    text-align: center;
}

.ai-match-detail-empty p {
    margin: 0;
    color: var(--aim-muted);
    font-size: 13px;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
    .ai-match-score-value,
    .btn-primary-ai,
    .btn-secondary-ai,
    .ai-match-source-item,
    .ai-match-candidate {
        transition: none;
    }
}

/* ---------- Tablet (768–1279px) ---------- */

@media (max-width: 1279px) and (min-width: 768px) {
    .ai-match-body {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "sources sources"
            "results detail";
    }

    .ai-match-col-sources {
        grid-area: sources;
        position: static;
        max-height: none;
    }

    .ai-match-col-sources .ai-match-source-list {
        display: flex;
        overflow-x: auto;
        padding-bottom: 4px;
    }

    .ai-match-col-sources .ai-match-source-item {
        min-width: 200px;
        flex-shrink: 0;
    }

    .ai-match-col-results {
        grid-area: results;
    }

    .ai-match-col-detail {
        grid-area: detail;
        position: static;
        max-height: none;
    }
}

/* ---------- Mobile (<=767px) ---------- */

@media (max-width: 767px) {
    .ai-match-page {
        padding: 16px 14px 40px;
    }

    .ai-match-intro {
        flex-direction: column;
    }

    .ai-match-stats {
        width: 100%;
    }

    .ai-match-stat {
        flex: 1 1 auto;
    }

    .ai-match-body {
        grid-template-columns: 1fr;
    }

    .ai-match-col-sources,
    .ai-match-col-detail {
        position: static;
        max-height: none;
    }

    .ai-match-col-sources .ai-match-source-list {
        display: flex;
        overflow-x: auto;
        gap: 8px;
        padding-bottom: 4px;
    }

    .ai-match-col-sources .ai-match-source-item {
        min-width: 190px;
        flex-shrink: 0;
    }

    .ai-match-candidate {
        grid-template-columns: 72px 1fr;
        grid-template-areas:
            "media body"
            "score score";
    }

    .ai-match-candidate-media {
        width: 72px;
        height: 64px;
        grid-area: media;
    }

    .ai-match-candidate-body {
        grid-area: body;
    }

    .ai-match-candidate-score {
        grid-area: score;
        width: auto;
        flex-direction: row;
        justify-content: flex-start;
        gap: 8px;
        margin-top: 8px;
    }

    .ai-match-candidate-score svg {
        width: 28px;
        height: 28px;
    }

    .ai-match-candidate-chevron {
        display: none;
    }

    .btn-primary-ai,
    .btn-secondary-ai {
        min-height: 44px;
    }

    .ai-match-source-item,
    .ai-match-chip {
        min-height: 44px;
    }
}
