/* All css goes here */


/* Small custom CSS to support list/grid toggle and suggestion dropdown */
.product-card {
    transition: all .15s ease-in-out;
}

.product-card .card-image {
    overflow: hidden;
    border-radius: 0.375rem;
}

.product-card .card-image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Grid default: cards stack vertically with a consistent image band */
.results-grid .product-card {
    display: flex;
    flex-direction: column;
    min-height: 18rem;
}

.results-grid .product-card .card-image {
    height: 12rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
}

/* List view: image left, body right. Force the results container to a single column
   and ensure each card expands full width. This overrides the grid classes applied
   by Tailwind for the results element so list view renders as a full-width list. */
/* Use grid with a single column to avoid interactions with Tailwind's responsive utilities.
   Use !important to ensure this takes precedence over injected/compiled Tailwind classes. */
.list-view #results {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-auto-flow: row !important;
    gap: 1rem !important;
}

/* Make list items layout robust:
   - image fixed-width column on the left
   - body takes remaining space and truncates gracefully
   - actions placed in a compact column on the right without stretching to card height
*/
.list-view .product-card {
    display: flex !important;
    flex-direction: row !important;
    gap: 1rem !important;
    padding: 1rem !important;
    width: 100% !important;
    box-sizing: border-box !important;
    align-items: flex-start !important;
}

/* Image column: fixed comfortable width to avoid proportional shrink that causes wrapping */
.list-view .product-card .card-image {
    flex: 0 0 160px !important;
    width: 160px !important;
    min-width: 120px !important;
    height: auto !important;
}

/* Body column: flexible, allow truncation (min-width:0) so long text doesn't force overflow */
.list-view .product-card .card-body {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    width: auto !important;
}

/* Actions column: keep compact, stack buttons vertically on desktop and avoid flexing to full height */
.list-view .product-card .card-actions {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
    flex: 0 0 auto !important;
    align-items: stretch !important;
    align-self: flex-start !important;
    min-width: 120px !important;
}

/* Prevent buttons inside the actions column from expanding to fill card height */
.list-view .product-card .card-actions .flex-1 {
    flex: none !important;
}

/* Suggestion dropdown */
.suggest-box {
    position: relative;
}

.suggest-list {
    position: absolute;
    z-index: 50;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    border-radius: 0.375rem;
    max-height: 18rem;
    overflow: auto;
}

.suggest-item {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
    align-items: center;
    cursor: pointer;
}

.suggest-item:hover {
    background: #f1f5f9;
}

.suggest-item img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    flex: 0 0 48px;
}

/* Comparison table improvements: compact full-width table, avoid horizontal scrollbars,
   ensure all content wraps and remains visible. */
.compare-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.compare-table th, .compare-table td {
    padding: 0.75rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid #e6e6e6;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.compare-table thead th {
    background: #f3f4f6;
    font-weight: 600;
}

.compare-table th.attr-col {
    width: 20%;
    min-width: 160px;
}

.compare-thumb {
    width: 64px;
    height: 64px;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
    display: inline-block;
    vertical-align: middle;
}

/* Reduce spacing in compact comparison to show more specs */
.compare-compact .compare-table th, .compare-compact .compare-table td {
    padding: 0.5rem;
    font-size: 0.85rem;
}

/* Ensure compare container doesn't force horizontal scroll on narrow content:
   allow cells to wrap and expand vertically instead. */
.compare-container {
    overflow-x: visible;
}

/* Small responsive adjustments */
@media (max-width: 768px) {
    .list-view .product-card {
        flex-direction: column;
    }

    .list-view .product-card .card-image {
        width: 100%;
        min-width: unset;
    }

    .list-view .product-card .card-body {
        width: 100%;
    }

    /* On small screens make actions flow horizontally under content and allow buttons to flex again */
    .list-view .product-card .card-actions {
        flex-direction: row !important;
        width: 100% !important;
    }

    .list-view .product-card .card-actions .flex-1 {
        flex: 1 !important;
    }

    .compare-table th.attr-col {
        width: 30%;
    }

    .compare-table th, .compare-table td {
        font-size: 0.82rem;
        padding: 0.45rem;
    }
}

/* Selected compare list UI */
#compare-selected-list {
    display: inline-flex;
    gap: 0.5rem;
    align-items: center;
    margin-left: 0.5rem;
    flex-wrap: wrap;
}

.compare-selected-item {
    background: #eef2ff;
    color: #1f2937;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    display: inline-flex;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.85rem;
}

.compare-remove-btn {
    background: transparent;
    border: 0;
    color: #7f1d1d;
    cursor: pointer;
    padding: 0 0.25rem;
    font-weight: 600;
}

/* Ensure #results becomes a single-column grid when list-view is active,    with !important to override Tailwind responsive grid classes. */
.list-view #results {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-auto-flow: row !important;
}

.list-view .product-card {
    width: 100% !important;
    margin-bottom: 1rem;
    box-sizing: border-box !important;
}

.list-view .product-card {
    display: flex !important;
    flex-direction: row !important;
    gap: 1rem !important;
    align-items: stretch !important;
}

.list-view .product-card .card-image {
    width: 28% !important;
    min-width: 160px !important;
    flex: 0 0 28% !important;
}

.list-view .product-card .card-body {
    width: 72% !important;
    flex: 1 1 auto !important;
}

/* Ensure action/buttons area (the element immediately after .card-body) becomes a compact action column */
.list-view .product-card .card-body + * {
    align-self: center !important;
    margin-top: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
    flex: 0 0 160px !important;
    min-width: 140px !important;
}

.list-view .product-card .card-body + * .flex-1 {
    width: 100% !important;
}

@media (max-width: 768px) {
    .list-view .product-card {
        flex-direction: column !important;
    }

    .list-view .product-card .card-image {
        width: 100% !important;
        min-width: unset !important;
    }

    .list-view .product-card .card-body {
        width: 100% !important;
    }

    .list-view .product-card .card-body + * {
        flex-direction: row !important;
        flex: 1 1 auto !important;
        min-width: unset !important;
    }
}

/* Comparison table improvements: ensure compare tables are full-width and wrap cells to avoid horizontal scrolling */
#compare-section .overflow-x-auto {
    overflow-x: visible !important;
}

.compare-table {
    width: 100% !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
}

.compare-table th, .compare-table td {
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    hyphens: auto !important;
    vertical-align: top !important;
    padding: 0.5rem !important;
}

.compare-table .w-20 {
    width: 80px !important;
    height: 80px !important;
}

.compare-table .w-20 img {
    max-width: 80px !important;
    max-height: 80px !important;
    object-fit: contain !important;
}