/**
 * Engagement & Retention CSS
 * Recently Viewed, Favorites, Comparator Widget
 */

:root {
    --engagement-primary: #ff6b00;
    --engagement-heart: #ef4444;
    --engagement-success: #22c55e;
    --engagement-warning: #f59e0b;
    --engagement-error: #ef4444;
    --engagement-info: #3b82f6;
}

/* ============================================
   RECENTLY VIEWED
   ============================================ */

.recently-viewed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.recently-viewed-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
    color: #0f172a;
}

.clear-recent {
    background: none;
    border: none;
    color: #64748b;
    font-size: 0.875rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    transition: all 150ms ease;
}

.clear-recent:hover {
    background: #f1f5f9;
    color: #334155;
}

.recently-viewed-empty {
    text-align: center;
    padding: 2rem 1rem;
}

.recently-viewed-empty svg {
    color: #cbd5e1;
    margin: 0 auto 1rem;
    display: block;
}

.recently-viewed-empty p {
    color: #64748b;
    font-size: 0.875rem;
    margin: 0;
}

.recently-viewed-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.recently-viewed-card {
    position: relative;
    border: 1px solid #e2e8f0;
    background: #fff;
    overflow: hidden;
    transition: all 200ms ease;
}

.recently-viewed-card:hover {
    border-color: var(--engagement-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.recently-viewed-card a {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    text-decoration: none;
    color: inherit;
}

.recently-viewed-card img {
    width: 80px;
    height: 60px;
    object-fit: cover;
    flex-shrink: 0;
}

.recently-viewed-card .card-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.recently-viewed-card .card-info h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recently-viewed-card .card-info .year {
    font-size: 12px;
    color: #475569;
    margin: 0;
}

.recently-viewed-card .card-info .price {
    font-size: 0.875rem;
    font-weight: 700;
    color: #16a34a;
    margin: 0;
}

.remove-recent {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: all 150ms ease;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.recently-viewed-card:hover .remove-recent {
    opacity: 1;
}

.remove-recent:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

/* Mobile: 2-column grid */
@media (max-width: 768px) {
    .recently-viewed-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .recently-viewed-card a {
        flex-direction: column;
    }

    .recently-viewed-card img {
        width: 100%;
        height: 100px;
    }

    .recently-viewed-card .card-info h4 {
        white-space: normal;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        line-clamp: 2;
        display: -webkit-box;
    }
}

/* ============================================
   FAVORITES
   ============================================ */

/* Favorite Button on Cards */
.favorite-button {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 200ms ease;
    padding: 0;
    margin: 0;
}

.favorite-button:hover {
    transform: scale(1.1);
}

.favorite-button .heart-icon {
    width: 24px;
    height: 24px;
    color: #64748b;
    transition: all 200ms ease;
}

.favorite-button:hover .heart-icon {
    color: var(--engagement-heart);
}

.favorite-button.is-favorite .heart-icon {
    fill: var(--engagement-heart);
    stroke: var(--engagement-heart);
}

/* Heart animation */
@keyframes heartBeat {

    0%,
    100% {
        transform: scale(1);
    }

    25% {
        transform: scale(1.3);
    }

    50% {
        transform: scale(0.9);
    }

    75% {
        transform: scale(1.1);
    }
}

.favorite-button.animate-heart {
    animation: heartBeat 600ms ease;
}

/* Favorites Badge in Header */
.favorites-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.favorites-badge {
    position: absolute;
    top: -4px;
    right: -8px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: var(--engagement-heart);
    color: white;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Favorites Page */
.favorites-empty {
    text-align: center;
    padding: 4rem 1rem;
}

.favorites-empty svg {
    color: #cbd5e1;
    margin: 0 auto 1.5rem;
    display: block;
}

.favorites-empty h2 {
    margin: 0 0 1rem;
    color: #0f172a;
}

.favorites-empty p {
    color: #475569;
    margin: 0 0 2rem;
}

.favorites-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #e2e8f0;
    flex-wrap: wrap;
    gap: 1rem;
}

.favorites-header .header-info h1 {
    margin: 0 0 0.5rem;
}

.favorites-header .header-info p {
    color: #475569;
    margin: 0;
}

.favorites-header .header-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.favorites-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.favorite-card {
    border: 1px solid #e2e8f0;
    background: #fff;
    overflow: hidden;
    transition: all 200ms ease;
}

.favorite-card:hover {
    border-color: var(--engagement-primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    transform: translateY(-4px);
}

.favorite-card .card-image {
    position: relative;
    aspect-ratio: 4/3;
}

.favorite-card .card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.favorite-card .favorite-remove {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    font-size: 20px;
    cursor: pointer;
    transition: all 150ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.favorite-card .favorite-remove:hover {
    background: white;
    transform: scale(1.1);
}

.favorite-card .card-content {
    padding: 1rem;
}

.favorite-card .card-content h3 {
    margin: 0 0 0.5rem;
    font-size: 1.125rem;
}

.favorite-card .card-content h3 a {
    text-decoration: none;
    color: inherit;
    transition: color 150ms ease;
}

.favorite-card .card-content h3 a:hover {
    color: var(--engagement-primary);
}

.favorite-card .card-version {
    color: #475569;
    font-size: 0.875rem;
    margin: 0 0 0.75rem;
}

.favorite-card .card-specs {
    display: flex;
    gap: 0.5rem;
    color: #475569;
    font-size: 0.875rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.favorite-card .card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
}

.favorite-card .card-price {
    font-size: 1.25rem;
    font-weight: 700;
    color: #16a34a;
    margin: 0;
}

.favorite-card .card-actions {
    display: flex;
    gap: 0.5rem;
}

/* Buttons */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: #0f172a;
    color: white;
    border: none;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 150ms ease;
}

.btn-primary:hover {
    background: #1e293b;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: #fff;
    color: #334155;
    border: 1px solid #e2e8f0;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 150ms ease;
}

.btn-secondary:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: #0f172a;
    color: white;
    padding: 0.75rem 1.25rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    transform: translateY(100px);
    opacity: 0;
    transition: all 300ms ease;
    z-index: 10000;
    font-size: 0.875rem;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast-success {
    background: var(--engagement-success);
}

.toast-warning {
    background: var(--engagement-warning);
}

.toast-error {
    background: var(--engagement-error);
}

.toast-info {
    background: var(--engagement-info);
}

/* Mobile */
@media (max-width: 768px) {
    .favorites-header {
        flex-direction: column;
    }

    .favorites-header .header-actions {
        width: 100%;
        flex-direction: column;
    }

    .favorites-header .header-actions button {
        width: 100%;
    }

    .favorites-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   COMPARATOR WIDGET
   ============================================ */

.comparator-widget {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    width: 320px;
    background: #fff;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    transform: translateY(calc(100% + 40px));
    opacity: 0;
    transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9999;
}

.comparator-widget.visible {
    transform: translateY(0);
    opacity: 1;
}

.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.widget-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.widget-close {
    width: 28px;
    height: 28px;
    background: #f1f5f9;
    border: none;
    color: #475569;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: all 150ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.widget-close:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.widget-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
}

.comparator-slot {
    min-height: 80px;
    border: 2px dashed #e2e8f0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    transition: all 200ms ease;
}

.comparator-slot.has-vehicle {
    border-style: solid;
    border-color: var(--engagement-primary);
    background: rgba(255, 107, 0, 0.02);
}

.comparator-slot img {
    width: 64px;
    height: 48px;
    object-fit: cover;
    flex-shrink: 0;
}

.slot-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.slot-info strong {
    font-size: 0.875rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.slot-info span {
    font-size: 12px;
    color: #475569;
}

.slot-remove {
    width: 24px;
    height: 24px;
    background: #e2e8f0;
    border: none;
    color: #334155;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    transition: all 150ms ease;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.slot-remove:hover {
    background: var(--engagement-error);
    color: white;
}

.slot-empty {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: #94a3b8;
}

.slot-empty svg {
    color: #cbd5e1;
}

.slot-empty span {
    font-size: 12px;
}

.widget-footer {
    padding: 1rem;
    border-top: 1px solid #e2e8f0;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

#compareButton:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

/* Mobile */
@media (max-width: 768px) {
    .comparator-widget {
        width: calc(100% - 32px);
        left: 16px;
        right: 16px;
    }
}

/* Animation */
@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.comparator-widget.visible {
    animation: slideUp 400ms cubic-bezier(0.4, 0, 0.2, 1);
}