/* ==============================================
   Recently Viewed Products Widget
   ============================================== */

/* ---- Toggle Button (fixed right side) ---- */
.rv-toggle-btn {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 80px;
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-right: none;
    border-radius: var(--radius-card) 0 0 var(--radius-card);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    z-index: var(--z-bottom-tab);
    transition: background 0.2s ease, color 0.2s ease;
    color: var(--color-text-muted);
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.rv-toggle-btn:hover {
    background: var(--color-primary);
    color: hsl(var(--primary-foreground));
    border-color: var(--color-primary);
}

.rv-toggle-btn svg {
    flex-shrink: 0;
}

.rv-toggle-label {
    writing-mode: vertical-rl;
    font-size: var(--text-2xs);
    font-weight: var(--font-semibold);
    letter-spacing: var(--tracking-widest);
    white-space: nowrap;
}

.rv-badge {
    position: absolute;
    top: -4px;
    left: -4px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--color-primary);
    color: hsl(var(--primary-foreground));
    font-size: var(--text-2xs);
    font-weight: var(--font-bold);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
}

/* ---- Widget Panel (desktop: sidebar, mobile: bottom strip) ---- */
.rv-widget {
    position: fixed;
    right: -320px;
    top: 0;
    width: 320px;
    height: 100%;
    background: var(--color-card-bg);
    border-left: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg, -4px 0 20px rgba(0, 0, 0, 0.08));
    z-index: var(--z-drawer-overlay);
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.rv-widget.rv-open {
    right: 0;
}

/* When panel is open, shift the toggle button out of view */
.rv-widget.rv-open ~ .rv-toggle-btn {
    right: 320px;
}

/* ---- Panel Header ---- */
.rv-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.rv-header-title {
    font-size: var(--text-base);
    font-weight: var(--font-bold);
    color: var(--color-text);
    margin: 0;
}

.rv-close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--color-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s ease;
    padding: 0;
}

.rv-close-btn:hover {
    background: var(--color-border);
}

/* ---- Product List (scrollable) ---- */
.rv-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-3);
    -webkit-overflow-scrolling: touch;
}

/* ---- Individual Product Item ---- */
.rv-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-25);
    border-radius: var(--radius-btn);
    text-decoration: none;
    color: inherit;
    transition: background 0.15s ease;
}

.rv-item:hover {
    background: var(--color-bg-hover, hsl(var(--accent)));
}

.rv-item-img-wrap {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    border-radius: var(--radius-btn);
    overflow: hidden;
    border: 1px solid var(--color-border);
    background: hsl(var(--muted, 0 0% 96%));
}

.rv-item-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.rv-item-info {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 0;
    flex: 1;
}

.rv-item-name {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--color-text);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rv-item-price {
    font-size: var(--text-sm);
    font-weight: var(--font-bold);
    color: var(--color-primary);
}

/* ---- Empty State ---- */
.rv-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 120px;
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

/* ---- Overlay (mobile backdrop) ---- */
.rv-overlay {
    display: none;
}

/* ==============================================
   Mobile: Bottom horizontal scroll strip
   ============================================== */
@media (max-width: 768px) {
    /* Hide the desktop sidebar toggle */
    .rv-toggle-btn {
        top: auto;
        bottom: calc(var(--bottom-tab-height, 56px) + var(--space-3));
        right: var(--space-3);
        transform: none;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        border-right: 1px solid var(--color-border);
        writing-mode: initial;
    }

    .rv-toggle-label {
        display: none;
    }

    .rv-badge {
        top: -3px;
        left: -3px;
    }

    /* Panel becomes bottom sheet */
    .rv-widget {
        right: 0;
        top: auto;
        bottom: -100%;
        left: 0;
        width: 100%;
        height: auto;
        max-height: 60vh;
        border-left: none;
        border-top: 1px solid var(--color-border);
        border-radius: var(--radius-card) var(--radius-card) 0 0;
        transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .rv-widget.rv-open {
        bottom: 0;
    }

    .rv-widget.rv-open ~ .rv-toggle-btn {
        right: var(--space-3);
        display: none;
    }

    /* Horizontal scroll list on mobile */
    .rv-list {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        gap: var(--space-3);
        padding: var(--space-3) var(--space-4);
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
    }

    .rv-item {
        flex-direction: column;
        align-items: center;
        text-align: center;
        flex-shrink: 0;
        width: 100px;
        padding: var(--space-15);
        scroll-snap-align: start;
    }

    .rv-item-img-wrap {
        width: 72px;
        height: 72px;
    }

    .rv-item-info {
        align-items: center;
    }

    .rv-item-name {
        font-size: var(--text-xs);
        -webkit-line-clamp: 1;
    }

    .rv-item-price {
        font-size: var(--text-xs);
    }

    .rv-empty {
        width: 100%;
        flex-shrink: 0;
        height: 80px;
    }

    /* Show backdrop overlay on mobile */
    .rv-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: var(--z-bottom-tab);
    }

    .rv-widget.rv-open ~ .rv-overlay {
        display: block;
    }
}
