/* ───────────────────────────────────────────────────────────────────────
   compare.css — Finding Android Comparison Page
   Material Design 3 inspired dark theme
   ─────────────────────────────────────────────────────────────────────── */

:root {
    /* Slot specific colors */
    --slot-1-accent: var(--md-primary);
    --slot-2-accent: var(--md-secondary);
    --slot-3-accent: var(--md-tertiary);
}

body.compare-page {
    background-color: var(--md-surface);
    color: var(--md-on-surface);
    font-family: 'Inter', sans-serif;
    line-height: 1.6;
}

.compare-main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 2rem 1.5rem 5rem;
    min-height: 80vh;
}

/* ─── Sticky Bar ──────────────────────────────────────────────────────── */
.compare-sticky-bar {
    position: sticky;
    top: 5.5rem;
    z-index: 50;
    background-color: var(--md-surface);
    opacity: 0.98;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 1.5rem;
    border-radius: var(--md-radius-2xl);
    border: 1px solid var(--md-outline-variant);
    margin-bottom: 3rem;
    box-shadow: 0 16px 40px var(--md-shadow-color);
    transition: background-color 0.3s ease;
}



.comparison-slots {
    display: grid;
    /* Default: Match 3-device table columns */
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    transition: grid-template-columns 0.4s cubic-bezier(0.2, 0, 0, 1);
}

/* Offset grid when labels are present (1-2 devices) */
body:not(.three-devices-mode) .comparison-slots {
    grid-template-columns: 250px 1fr 1fr;
}

.comparison-spacer {
    display: flex;
    align-items: center;
    padding-left: 0.5rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--md-primary);
    opacity: 0.7;
}

body.three-devices-mode .comparison-spacer {
    display: none;
}

.slot {
    background-color: var(--md-surface-container-low);
    border: 2px dashed var(--md-outline-variant);
    border-radius: var(--md-radius-xl);
    padding: 1rem;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.slot:hover {
    border-color: var(--md-primary);
    background-color: var(--md-surface-container);
    transform: translateY(-2px);
}

.slot-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--md-on-surface-variant);
}

.slot-empty span {
    font-size: 2rem;
    transition: transform 0.2s;
}

.slot:hover .slot-empty span {
    transform: scale(1.1);
    color: var(--md-primary);
}

.slot-empty p {
    margin: 0;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* Filled Slot Styles */
.slot.filled {
    border-style: solid;
    justify-content: flex-start;
    padding: 0.75rem 1.25rem;
    gap: 1rem;
    border-width: 2px;
}

.slot[data-slot="1"].filled { border-color: var(--slot-1-accent); background-color: var(--md-primary-container); }
.slot[data-slot="2"].filled { border-color: var(--slot-2-accent); background-color: var(--md-secondary-container); }
.slot[data-slot="3"].filled { border-color: var(--slot-3-accent); background-color: var(--md-tertiary-container); }

.slot-thumb {
    width: 60px;
    height: 60px;
    object-fit: contain;
    filter: drop-shadow(0 8px 16px var(--md-shadow-color));
}

.slot-info {
    flex: 1;
    min-width: 0;
}

.slot-model {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--md-on-surface);
}

.slot-brand {
    font-size: 0.65rem;
    color: var(--md-on-surface-variant);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
    margin: 0;
}

.remove-slot {
    background: var(--md-surface-container-highest);
    border: none;
    color: var(--md-on-surface-variant);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 50%;
    display: flex;
    transition: all 0.2s;
}

.remove-slot:hover {
    color: #fff;
    background-color: var(--md-error);
    transform: rotate(90deg);
}

/* ───────────────────────────────────────────────────────────────────────
   COMPARISON MODAL (Search Dialog)
   ─────────────────────────────────────────────────────────────────────── */

.compare-dialog {
    padding: 0;
    border: none;
    border-radius: var(--md-radius-2xl);
    background-color: var(--md-surface-container-high);
    color: var(--md-on-surface);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
    max-width: 500px;
    width: 90%;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    overflow: visible;
}

.compare-dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.compare-modal-content {
    display: flex;
    flex-direction: column;
}

.compare-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--md-outline-variant);
}

.compare-modal-header h3 {
    margin: 0;
    font-family: 'Manrope', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--md-primary);
}

.close-modal-btn {
    background: transparent;
    border: none;
    color: var(--md-on-surface-variant);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.close-modal-btn:hover {
    color: var(--md-primary);
}

.compare-modal-body {
    padding: 2rem;
}

.compare-modal-body p {
    margin-top: 0;
    margin-bottom: 1.5rem;
    color: var(--md-on-surface-variant);
}

.search-box-wrapper {
    position: relative;
    background-color: var(--md-surface-container-lowest);
    border: 1px solid var(--md-outline-variant);
    border-radius: var(--md-radius-xl);
    padding: 0 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box-wrapper:focus-within {
    border-color: var(--md-primary);
    box-shadow: 0 0 0 2px rgba(152, 203, 255, 0.2);
}

#compare-search-input {
    background: transparent;
    border: none;
    color: var(--md-on-surface);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    padding: 1rem 0;
    width: 100%;
    outline: none;
}

/* ─── Autocomplete Results ─────────────────────────────────────────── */
.autocomplete-results {
    width: 100%;
    margin-top: 0.5rem;
    background-color: var(--md-surface-container-highest);
    border-radius: var(--md-radius-xl);
    max-height: 40vh;
    overflow-y: auto;
    z-index: 10;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.1);
    display: none;
    border: 1px solid var(--md-outline-variant);
}

.autocomplete-result-item {
    padding: 1rem 1.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    color: var(--md-on-surface);
}

.autocomplete-result-item:hover {
    background-color: var(--md-primary-container);
    color: var(--md-on-primary-container);
}

.autocomplete-result-item:last-child {
    border-radius: 0 0 var(--md-radius-xl) var(--md-radius-xl);
}

/* ─── Comparison Table ────────────────────────────────────────────────── */
.comparison-container {
    margin-top: 2rem;
    border-radius: var(--md-radius-2xl);
    background-color: var(--md-surface-container-low);
    border: 1px solid var(--md-outline-variant);
    overflow: hidden;
    transition: all 0.3s ease;
}

.empty-comparison {
    padding: 8rem 2rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    animation: fadeIn 0.5s ease;
}

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

.empty-comparison span {
    font-size: 5rem;
    color: var(--md-surface-container-highest);
    background: linear-gradient(135deg, var(--md-primary), var(--md-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    opacity: 0.5;
}

.empty-comparison h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
    color: var(--md-on-surface);
}

.empty-comparison p {
    color: var(--md-on-surface-variant);
    max-width: 450px;
    font-size: 1.1rem;
    line-height: 1.6;
}

/* Data Table Grid */
.compare-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.compare-row-category {
    background-color: var(--md-surface-container);
}

.compare-row-category td {
    padding: 1rem 1.5rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--md-primary);
    border-bottom: 2px solid var(--md-outline);
}

.compare-row-spec td {
    padding: 1.5rem;
    border-bottom: 1px solid var(--md-outline-variant);
    vertical-align: top;
    transition: background-color 0.2s;
}

.compare-row-spec:hover {
    background-color: var(--md-surface-container-high);
}

.spec-label-cell {
    width: 250px;
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--md-on-surface-variant);
    background-color: var(--md-surface-container-low);
}

.spec-value-cell {
    font-size: 0.95rem;
    color: var(--md-on-surface);
    line-height: 1.5;
}

.spec-category-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Default hidden label for inline spec metadata */
.mobile-inline-label {
    display: none;
}

/* Shared activation rule: mobile OR 3-device desktop */
.compare-table.three-devices .mobile-inline-label,
.compare-table .mobile-inline-label.active {
    display: block;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    color: var(--md-primary);
    font-size: 0.75rem;
    margin-bottom: 5px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* ── Table thead (mobile sticky name row) ──────────────────────────── */
/* Hidden on desktop — the floating slot cards serve that role there */
.compare-table thead {
    display: none;
}

.compare-device-header {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    text-align: center;
    padding: 0.75rem;
    background-color: var(--md-surface-container);
    color: var(--md-on-surface);
    border-bottom: 2px solid var(--md-outline);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── Loader ──────────────────────────────────────────────────────────── */
.compare-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10rem 2rem;
    gap: 1.5rem;
}

.compare-loader span {
    font-size: 3rem;
    color: var(--md-primary);
    animation: rotate 1.5s linear infinite;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ─── Mobile Responsiveness ─────────────────────────────────────────── */
@media (max-width: 1199px) {
    .spec-label-cell {
        width: 180px;
    }
}

@media (max-width: 991px) {
    .comparison-slots {
        gap: 1rem;
    }
    
    .compare-sticky-bar {
        padding: 1.25rem;
        top: 0;
    }

    .slot-thumb {
        width: 40px;
        height: 40px;
    }

    .slot-model {
        font-size: 0.85rem;
    }
}

@media (max-width: 767px) {
    /* Allow header to scroll away on mobile for maximum density */
    body.compare-page header {
        position: static !important;
    }

    .compare-main {
        padding: 0; /* Flush to edge */
        margin-top: 0.5rem;
        /* Keep it contained to the viewport */
        width: 100%;
    }

    .mobile-scroll-wrapper {
        overflow-x: auto;
        width: 100%;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling for iOS */
        scrollbar-width: none; 
    }
    
    .mobile-scroll-wrapper::-webkit-scrollbar {
        display: none;
    }

    /* Colored slot cards stick to top on mobile as the scroll anchor */
    .compare-sticky-bar {
        position: sticky !important;
        top: 0;
        z-index: 60;
        padding: 0.4rem 0.5rem;
        margin: 0;
        border: none;
        border-radius: 0;
        box-shadow: none;
        border-bottom: 1px solid var(--md-outline-variant);
        background-color: var(--md-surface);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        overflow-x: auto;
        scrollbar-width: none;
    }
    .compare-sticky-bar::-webkit-scrollbar {
        display: none;
    }

    .compare-sticky-bar .comparison-slots {
        margin-bottom: 0;
    }

    /* The comparison-container base rule has overflow: hidden for rounded corners.
       We MUST override to visible so sticky works on elements above it. */
    #comparison-container,
    .comparison-container {
        overflow: visible !important;
        padding: 0;
        margin-top: 0;
        border: none;
        border-radius: 0;
    }

    /* 2-device: 50/50 grid — strictly enforce equal widths with minmax(0, 1fr) */
    body:not(.three-devices-mode) .comparison-slots {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
    }

    /* 3-device: let it overflow so the 3rd column peeks off-screen */
    body.three-devices-mode .comparison-slots {
        grid-template-columns: repeat(3, minmax(140px, 1fr));
        gap: 0.5rem;
        min-width: 450px; /* Match table width to keep columns aligned when scrolling */
    }

    .slot {
        min-height: auto;
        padding: 0.6rem 0.5rem;
    }

    .slot.filled {
        justify-content: center;
        text-align: center;
        padding: 0.5rem;
        gap: 0; /* Remove gap since thumb is removed via JS */
    }

    .compare-table {
        table-layout: fixed;
        width: 100%;
    }

    body.three-devices-mode #comparison-container,
    body.three-devices-mode .compare-table {
        min-width: 450px;
    }

    /* Each value column has a guaranteed minimum width and equal share */
    .compare-table td,
    .compare-table th {
        width: 150px; /* Base width for scrolling */
        min-width: 150px;
    }

    /* Force equal distribution in the fixed layout if container is wider than min-width */
    .compare-table.three-devices th.compare-device-header { width: 33.33%; }
    body:not(.three-devices-mode) .compare-table th.compare-device-header { width: 50%; }

    /* Hide the dedicated label column — inline labels replace it */
    .compare-table .spec-label-cell {
        display: none !important;
    }

    /* Hide the header spacer th that aligns with the label column */
    .compare-table .compare-device-header-spacer {
        display: none !important;
    }

    /* Activate inline labels on mobile */
    .compare-table .mobile-inline-label {
        display: block !important;
        font-family: 'Outfit', sans-serif;
        font-weight: 700;
        color: var(--md-primary);
        font-size: 0.7rem;
        margin-bottom: 4px;
        letter-spacing: 0.05em;
        text-transform: uppercase;
    }

    /* Hide the thead on mobile — the colored slot cards serve as the header */
    .compare-table thead {
        display: none;
    }

    .compare-table td,
    .compare-table th {
        padding: 0.75rem 0.5rem !important;
        font-size: 0.85rem;
    }
}


/* ─── Header Overrides ────────────────────────────────────────────────── */
body.compare-page header {
    background-color: var(--md-surface);
    opacity: 0.95;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--md-outline-variant);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

body.compare-page.light-mode header {
    background-color: var(--md-surface);
    opacity: 0.95;
    border-bottom: 1px solid var(--md-outline-variant);
}

body.compare-page header .nav-container {
    position: relative;
}

body.compare-page .mobile-menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--md-on-surface);
    cursor: pointer;
    padding: 0.5rem;
}

body.compare-page .mobile-menu-toggle .material-symbols-outlined {
    font-size: 1.75rem;
}


.theme-toggle {
    background: transparent;
    border: none;
    color: var(--md-on-surface);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}
.theme-toggle:hover {
    background-color: var(--md-surface-container-high);
}

/* ─── Add Device FAB ────────────────────────────────────────────────── */
.compare-fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background-color: var(--md-primary);
    color: var(--md-on-primary-container) !important;
    padding: 1rem 1.75rem;
    border-radius: var(--md-radius-full);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none !important;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    box-shadow: 0 8px 32px var(--md-fab-shadow);
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
    border: none;
    cursor: pointer;
}

.compare-fab:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 12px 40px var(--md-fab-shadow);
    filter: brightness(1.1);
}

@media (max-width: 1199px) {
    body:not(.three-devices-mode) .comparison-slots {
        grid-template-columns: 180px 1fr 1fr;
    }
}

@media (max-width: 767px) {
    .compare-fab .fab-label {
        display: none;
    }
    .compare-fab {
        padding: 1rem;
        bottom: 1.5rem;
        right: 1.5rem;
    }
    .comparison-spacer {
        display: none !important;
    }
    /* Override the 1199px tablet grid — must come after it in the cascade */
    body:not(.three-devices-mode) .comparison-slots {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}
