/* public/assets/css/comparison.css */

/* ============ Comparison dock (desktop) / bottom sheet (mobile) ============ */

.compare-sidebar {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 320px;
    max-width: calc(100vw - 24px);
    background: var(--surface, #fff);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
    border-radius: 14px;
    z-index: 990;
    display: none;
    overflow: hidden;
    border: 1px solid var(--border-color, #e2e8f0);
}

.compare-sidebar.open {
    animation: compareDockIn .18s ease-out;
}

@keyframes compareDockIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.compare-sidebar-content {
    padding: 14px;
}

.compare-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    font-weight: 700;
}

.compare-header .compare-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: .9rem;
}

.btn-text {
    background: none;
    border: none;
    color: var(--danger, #c5221f);
    cursor: pointer;
    font-size: .8rem;
    text-decoration: underline;
    padding: 2px 4px;
}

.compare-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 220px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.compare-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-light, #f8f9fa);
    padding: 6px 8px;
    border-radius: 10px;
}

.compare-item img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    background: #fff;
    border-radius: 6px;
    flex: 0 0 auto;
}

.compare-item-name {
    flex: 1;
    font-size: .85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remove-item {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 1.15rem;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 6px;
}

.remove-item:hover {
    color: #c5221f;
    background: rgba(197, 34, 31, .08);
}

.compare-actions .btn {
    width: 100%;
}

.compare-actions .disabled {
    opacity: .6;
    pointer-events: none;
}

/* ============ Compare page: header, actions, slots ============ */

.compare-page .compare-page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.compare-page-header h1 {
    margin: 0 0 .35rem;
}

.compare-page-actions {
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-wrap: wrap;
}

.diff-toggle {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    cursor: pointer;
    user-select: none;
    background: var(--bg-light, #f1f3f4);
    padding: .5rem .85rem;
    border-radius: 10px;
    font-size: .85rem;
    font-weight: 600;
}

.diff-toggle input {
    width: auto;
    margin: 0;
    cursor: pointer;
}

.btn-danger-soft {
    color: var(--danger, #b3261e);
    border-color: var(--danger, #b3261e);
}

.btn-danger-soft:hover {
    background: rgba(197, 34, 31, .08);
    color: var(--danger, #b3261e);
}

.compare-slots {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 1.5rem;
}

.compare-slot {
    position: relative;
    border: 1.5px dashed var(--border-color, #cbd5e1);
    border-radius: 14px;
    padding: 14px;
    background: var(--surface, #fff);
    min-height: 150px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.compare-slot.filled {
    border-style: solid;
    border-color: var(--primary-color, #2563eb);
}

.compare-slot-thumb img {
    height: 72px;
    max-width: 100%;
    object-fit: contain;
}

.compare-slot-count {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary-color, #2563eb);
    color: #fff;
    font-size: .78rem;
    font-weight: 800;
}

.compare-slot .compare-slot-count {
    flex: 0 0 auto;
}

.compare-slot-name {
    font-weight: 600;
    font-size: .9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.compare-slot-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.slot-btn {
    border: 1px solid var(--border-color, #cbd5e1);
    background: var(--surface, #fff);
    color: var(--text-color, #334155);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: grid;
    place-items: center;
    font-size: .85rem;
}

.slot-btn:hover {
    border-color: var(--primary-color, #2563eb);
    color: var(--primary-color, #2563eb);
}

.slot-btn.danger:hover {
    border-color: var(--danger, #c5221f);
    color: var(--danger, #c5221f);
}

/* Search in an empty slot */
.compare-slot-search {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border-color, #cbd5e1);
    border-radius: 10px;
    padding: 8px 10px;
    color: var(--text-light, #94a3b8);
}

.compare-slot-search:focus-within {
    border-color: var(--primary-color, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.slot-search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: .9rem;
    color: inherit;
    min-width: 0;
}

.slot-suggestions {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    z-index: 60;
    background: var(--surface, #fff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, .18);
    max-height: 260px;
    overflow-y: auto;
    text-align: left;
}

.suggestion {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: .88rem;
    color: var(--text-color, #334155);
}

.suggestion:hover,
.suggestion:focus-visible {
    background: var(--bg-light, #f1f3f4);
    outline: none;
}

.suggestion img {
    width: 34px;
    height: 34px;
    object-fit: contain;
    flex: 0 0 auto;
    background: #fff;
    border-radius: 6px;
}

.suggestion.empty-suggestion {
    color: var(--text-light, #94a3b8);
    cursor: default;
}

.empty-state.compare-empty {
    border: 1px dashed var(--border-color, #cbd5e1);
}

/* ============ Comparison table ============ */

.comparison-table-wrapper {
    overflow-x: auto;
    background: var(--surface, #fff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 14px;
    margin-bottom: 2rem;
}

.comparison-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 760px;
}

.comparison-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface, #fff);
    z-index: 10;
    padding: 15px;
    text-align: center;
    vertical-align: bottom;
    border-bottom: 2px solid var(--primary-color, #2563eb);
}

.comparison-table thead th:first-child {
    z-index: 11;
    left: 0;
    min-width: 200px;
    text-align: left;
    border-right: 1px solid var(--border-color, #e2e8f0);
}

.device-col-header img {
    height: 100px;
    object-fit: contain;
    margin-bottom: 10px;
    background: var(--bg-light, #f8f9fa);
    border-radius: 10px;
    padding: 6px;
}

.device-col-name {
    font-weight: 600;
    font-size: .9rem;
}

.device-col-brand {
    color: var(--text-light, #94a3b8);
    font-size: .8rem;
    margin-top: 2px;
}

.comparison-table thead .device-col-header a {
    color: inherit;
    text-decoration: none;
}

.comparison-table tbody tr.group-header td {
    background: #e8f0fe;
    color: #1967d2;
    font-weight: 700;
    padding: 10px 15px;
    text-transform: uppercase;
    font-size: .82rem;
    letter-spacing: .6px;
}

.comparison-table td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    text-align: center;
    min-width: 160px;
    font-size: .9rem;
}

.comparison-table td:first-child {
    position: sticky;
    left: 0;
    background: var(--bg-light, #fafafa);
    text-align: left;
    font-weight: 500;
    border-right: 1px solid var(--border-color, #e2e8f0);
    color: var(--text-light, #64748b);
    min-width: 200px;
}

.comparison-table tr.spec-row.different td {
    background: #fff3cd;
}

.comparison-table tr.spec-row.different td:first-child {
    background: #ffefb8;
    color: #7a5c00;
}

/* ============ Mobile: dock becomes bottom sheet ============ */

@media (max-width: 600px) {
    .compare-sidebar {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        max-height: 68vh;
        display: none;
    }

    .compare-sidebar.open {
        display: block;
    }

    .compare-items {
        flex-direction: row;
        overflow-x: auto;
        max-height: none;
        padding-bottom: 4px;
    }

    .compare-item {
        flex: 0 0 190px;
    }

    .compare-slots {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .compare-slot {
        min-height: 130px;
        padding: 10px;
    }

    .compare-page-actions {
        width: 100%;
    }

    .diff-toggle {
        margin-left: 0;
    }
}

@media (max-width: 380px) {
    .compare-slots {
        grid-template-columns: 1fr;
    }
}

/* ============ Key differences summary (before the table) ============ */

.differences-summary {
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 14px;
    background: var(--surface, #fff);
    margin-bottom: 1rem;
    overflow: hidden;
}

.differences-summary-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .85rem 1rem;
    background: var(--bg-light, #f1f3f4);
    font-weight: 700;
    font-size: .95rem;
}

.differences-summary-header .diff-count {
    display: inline-grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--primary-color, #2563eb);
    color: #fff;
    font-size: .75rem;
    font-weight: 800;
}

.differences-summary.none .differences-summary-header {
    color: #1e7e34;
}

.differences-list {
    padding: 0 1rem 1rem;
}

.diff-item {
    padding: .6rem 0;
    border-bottom: 1px dashed var(--border-color, #e2e8f0);
}

.diff-item:last-child {
    border-bottom: none;
}

.diff-spec {
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-light, #64748b);
    margin-bottom: .35rem;
    font-weight: 600;
}

.diff-values {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: .4rem .8rem;
}

.diff-val {
    font-size: .88rem;
}

.diff-device {
    display: block;
    font-weight: 600;
    font-size: .75rem;
    color: var(--text-light, #64748b);
}

.diff-value {
    font-weight: 500;
}

/* ============ Comparison table horizontal-scroll affordance ============ */

.comparison-table-wrapper {
    position: relative;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

/* Right-edge fade: appears only when the wrapper actually overflows */
.comparison-table-wrapper.has-overflow::after {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0; width: 34px;
    pointer-events: none;
    background: linear-gradient(to left, rgba(0, 0, 0, .10), transparent);
    border-radius: 0 14px 14px 0;
    z-index: 12;
}

/* Left-edge fade: appears only while scrolled away from the start */
.comparison-table-wrapper.has-overflow.can-scroll-left::before {
    content: '';
    position: absolute;
    top: 0; left: 0; bottom: 0; width: 34px;
    pointer-events: none;
    background: linear-gradient(to right, rgba(0, 0, 0, .10), transparent);
    border-radius: 14px 0 0 14px;
    z-index: 14;
}

/* Shadow on the pinned first column once content slides beneath it */
.comparison-table-wrapper.can-scroll-left .comparison-table thead th:first-child,
.comparison-table-wrapper.can-scroll-left .comparison-table td:first-child {
    box-shadow: 5px 0 10px -6px rgba(0, 0, 0, .20);
}

/* Swipe hint pill (injected by compare.js when there is overflow) */
.compare-scroll-hint {
    position: absolute;
    z-index: 15;
    top: 10px; right: 10px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    max-width: calc(100% - 20px);
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(15, 23, 42, .84);
    color: #fff;
    font-size: .78rem;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
    pointer-events: none;
    opacity: 1;
    transition: opacity .25s ease;
    white-space: nowrap;
}

.compare-scroll-hint i {
    font-size: .85rem;
}

.comparison-table-wrapper.scrolled .compare-scroll-hint {
    opacity: 0;
}

@media (max-width: 600px) {
    .comparison-table-wrapper.has-overflow::after,
    .comparison-table-wrapper.has-overflow.can-scroll-left::before {
        width: 22px;
    }
    .compare-scroll-hint {
        font-size: .74rem;
        padding: 6px 10px;
    }
}
