/* Compare page (investor backlog #13) — side-by-side columns for 2-3
   watched properties. Page-specific rules only; shared components (cards,
   badges, buttons, empty states) come from styles.css. */

/* ---- picker ---------------------------------------------------------- */

.compare-picker {
    margin-bottom: var(--space-xl);
}

.compare-picker-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.compare-picker-count {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    white-space: nowrap;
}

.compare-picker-rows {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    max-height: 340px;
    overflow-y: auto;
    padding-right: var(--space-xs);
}

.compare-pick-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
}

.compare-pick-row.selected {
    border-color: var(--color-primary);
    /* Translucent tint, not a hardcoded light hex: styles.css swaps the
       tokens under prefers-color-scheme, and an opaque light background
       here would wash out the theme text color in dark mode. */
    background: rgba(20, 184, 166, 0.12);
}

.compare-pick-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.compare-pick-county {
    color: var(--color-primary-dark);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.compare-pick-address {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.compare-pick-side {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-shrink: 0;
}

.compare-pick-bid {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.compare-pick-btn {
    min-width: 96px;
    padding: var(--space-xs) var(--space-sm);
}

.compare-pick-btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
}

.empty-state-hint {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin-top: 8px;
}

/* ---- actions row ------------------------------------------------------ */

.compare-actions {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
}

/* An author display beats the UA's [hidden] rule — restate it, or the
   packet/clear buttons render on an empty comparison. */
.compare-actions[hidden] {
    display: none;
}

/* ---- comparison grid -------------------------------------------------- */

/* Wide comparisons scroll inside this wrapper; the page body never
   scrolls sideways. */
.compare-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* The frame (border/radius/background) lives on the SCROLL WRAPPER, not the
   grid: sticky positioning pins to the nearest ancestor with a scroll box
   (any overflow other than visible), so an overflow:hidden grid would
   capture its own sticky labels — and the grid never scrolls, so they would
   quietly stop sticking. The wrapper also keeps the frame stationary while
   the columns scroll inside it. `.has-grid` is toggled by renderColumns so
   the empty-state hint stays frameless. */
.compare-scroll.has-grid {
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    background: var(--color-bg-secondary);
}

/* One shared grid for every cell — the row label plus one column per
   property per row — so rows stay aligned no matter how tall a cell gets. */
.cmp-grid {
    display: grid;
    min-width: min-content;
}

.cmp-grid[data-count="1"] { grid-template-columns: minmax(120px, max-content) minmax(260px, 460px); }
.cmp-grid[data-count="2"] { grid-template-columns: minmax(120px, max-content) repeat(2, minmax(250px, 1fr)); }
.cmp-grid[data-count="3"] { grid-template-columns: minmax(120px, max-content) repeat(3, minmax(250px, 1fr)); }

.cmp-row-label {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 600;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
}

.cmp-cell {
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--color-border);
    border-left: 1px solid var(--color-border);
    font-variant-numeric: tabular-nums;
    position: relative;
}

/* Last grid row (1 label + N cells): remove the doubled border at the
   grid's bottom edge. The count attribute tells us how many cells that is. */
.cmp-grid[data-count="1"] > :nth-last-child(-n+2),
.cmp-grid[data-count="2"] > :nth-last-child(-n+3),
.cmp-grid[data-count="3"] > :nth-last-child(-n+4) {
    border-bottom: none;
}

.cmp-head-label {
    background: var(--color-bg-tertiary);
}

.cmp-head-cell {
    padding: 0;
}

.cmp-head {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
}

.cmp-remove {
    position: absolute;
    top: var(--space-xs);
    right: var(--space-xs);
    z-index: 2;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--border-radius-full);
    background: rgba(17, 24, 39, 0.55);
    color: #fff;
    font-size: var(--font-size-sm);
    cursor: pointer;
    line-height: 1;
}

.cmp-remove:hover {
    background: var(--color-error);
}

.compare-media {
    display: block;
    height: 150px;
    background: var(--color-bg-tertiary);
}

.compare-photo {
    width: 100%;
    height: 150px;
    object-fit: cover;
    display: block;
}

.compare-media.no-photo {
    display: flex;
    align-items: center;
    justify-content: center;
}

.compare-media-fallback {
    text-align: center;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    padding: var(--space-sm) var(--space-md);
}

.compare-media-fallback .fallback-icon {
    font-size: var(--font-size-xl);
    margin-bottom: var(--space-xs);
}

.cmp-head-body {
    padding: var(--space-sm) var(--space-md) var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.cmp-address {
    font-size: var(--font-size-base);
    font-weight: 700;
    margin: 0;
    line-height: 1.3;
}

.cmp-badges {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    align-items: center;
}

.cmp-offlist {
    font-size: var(--font-size-xs);
    color: var(--color-warning);
    border: 1px solid currentColor;
    border-radius: var(--border-radius-full);
    padding: 1px 8px;
    white-space: nowrap;
}

.cmp-detail-link {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-primary-dark);
    text-decoration: none;
    margin-top: var(--space-xs);
}

.cmp-detail-link:hover {
    text-decoration: underline;
}

.cmp-empty {
    color: var(--color-border-dark);
}

.cmp-muted {
    color: var(--color-text-muted);
}

.cmp-strong {
    font-weight: 700;
}

.cmp-subnote,
.cmp-evidence {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    margin-top: 2px;
    line-height: 1.35;
}

.cmp-note {
    color: var(--color-text-secondary);
    font-size: var(--font-size-xs);
    margin-top: var(--space-xs);
    line-height: 1.4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* "Largest" highlight — only ever applied where bigger is unambiguously
   better (discount / margin), never a judgement that a property "wins".
   Translucent for the same dark-mode reason as .selected above. */
.cmp-best {
    background: rgba(22, 163, 74, 0.14);
}

.cmp-best-tag {
    display: inline-block;
    margin-left: var(--space-xs);
    padding: 0 6px;
    border-radius: var(--border-radius-full);
    background: #dcfce7;
    color: var(--color-success);
    font-size: var(--font-size-xs);
    font-weight: 600;
    vertical-align: middle;
}

/* ---- small screens ---------------------------------------------------- */

@media (max-width: 640px) {
    .compare-pick-side .score-badge {
        display: none;
    }

    .cmp-grid[data-count="1"] { grid-template-columns: minmax(96px, max-content) minmax(220px, 1fr); }
    .cmp-grid[data-count="2"] { grid-template-columns: minmax(96px, max-content) repeat(2, minmax(220px, 1fr)); }
    .cmp-grid[data-count="3"] { grid-template-columns: minmax(96px, max-content) repeat(3, minmax(220px, 1fr)); }

    .cmp-row-label {
        font-size: var(--font-size-xs);
        padding: var(--space-sm);
    }

    .cmp-cell {
        padding: var(--space-sm);
    }
}

/* My-rating picker in the Deal grade row. Translucent tint, not a hardcoded
   light hex: styles.css swaps the tokens under prefers-color-scheme, and an
   opaque light background would wash out the theme text colour in dark mode. */
.cmp-rating-select {
    width: 100%;
    margin-top: 8px;
    padding: 5px 8px;
    font-size: var(--font-size-xs);
    font-family: inherit;
    color: var(--color-text);
    background: rgba(127, 127, 127, 0.08);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm, 6px);
    cursor: pointer;
}
.cmp-rating-select:focus { outline: none; border-color: var(--color-primary); }
