/*
 * Robbie Rose Gallery - Purchase Drawer Styles
 * UNIFIED: This file is now the single source of truth for all drawer styles.
 */

/* --- Main Drawer Container & Overlay --- */
.purchase-drawer-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    pointer-events: none;
    display: flex;
    justify-content: flex-end; /* Default to right alignment */
    transition: opacity 0.3s ease; /* Smooth fade for container */
}

.purchase-drawer-overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.5s ease;
    cursor: pointer;
}

.purchase-drawer-container.open {
    pointer-events: auto;
    opacity: 1;
}
.purchase-drawer-container.open .purchase-drawer-overlay {
    opacity: 1;
}

/* --- Drawer Panel --- */
.purchase-drawer {
    position: absolute;
    background: var(--background-color);
    transition: transform 0.5s cubic-bezier(0.645, 0.045, 0.355, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Make width responsive and capped */
    width: 90vw; /* Take up 90% of viewport width on mobile */
    max-width: 450px; /* Capped width for desktop */
    height: 100vh;
    box-shadow: -5px 0 25px rgba(0,0,0,0.15);
    transform: translateX(100%); /* Default to hidden on the right */
    right: 0; /* Ensure right alignment */
}

.purchase-drawer-container.open .purchase-drawer {
    transform: translateX(0);
}

/* Button styling for all purchase-related buttons */
.purchase-drawer .purchase-text-btn,
.purchase-drawer .purchase-drawer-option-link,
.purchase-drawer .request-option,
.purchase-drawer .submit-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xs) var(--space-md);
    background: transparent;
    color: var(--color-silver-600);
    border: 1px solid var(--color-silver-400);
    border-radius: 8px; /* Unified border radius */
    font-family: var(--primary-font);
    font-size: var(--font-md);
    font-weight: var(--weight-light);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    width: fit-content; /* Fit to content */
}

.purchase-drawer .purchase-text-btn::before,
.purchase-drawer .purchase-drawer-option-link::before,
.purchase-drawer .request-option::before,
.purchase-drawer .submit-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.purchase-drawer .purchase-text-btn:hover::before,
.purchase-drawer .purchase-drawer-option-link:hover::before,
.purchase-drawer .request-option:hover::before,
.purchase-drawer .submit-button:hover::before {
    left: 100%;
}

.purchase-drawer .purchase-text-btn:hover,
.purchase-drawer .purchase-drawer-option-link:hover,
.purchase-drawer .request-option:hover,
.purchase-drawer .submit-button:hover {
    background-color: var(--color-silver-800);
    color: var(--color-silver-100);
    border-color: var(--color-silver-800);
}

.purchase-drawer .purchase-text-btn:focus,
.purchase-drawer .purchase-drawer-option-link:focus,
.purchase-drawer .request-option:focus,
.purchase-drawer .submit-button:focus {
    outline: 2px solid var(--color-silver-600);
    outline-offset: 2px;
}

/* Specific overrides for option links in selection view */
.purchase-drawer-option-link {
    width: 100%;
    margin-bottom: var(--space-sm);
    border-radius: 8px; /* Less rounded for option links */
    font-size: var(--font-lg);
}

.request-option {
    background: transparent;
    border: 1px solid var(--color-silver-400);
    margin-top: var(--space-md);
}

.request-option:hover {
    background-color: var(--color-silver-800);
    color: var(--color-silver-100);
    border-color: var(--color-silver-800);
}

/* Back button styles */
.purchase-drawer .drawer-back-btn {
    background: none;
    border: none;
    color: var(--color-silver-700);
    font-size: var(--font-sm);
    cursor: pointer;
    text-decoration: none;
    padding: 0;
    margin-bottom: var(--space-md);
    transition: color 0.2s ease;
}

.purchase-drawer .drawer-back-btn:hover {
    color: var(--color-silver-800);
}

/* Close button in drawer (matches HTML class) */
.purchase-drawer-close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--color-silver-500);
    position: absolute;
    top: var(--space-md);
    right: var(--space-lg);
    padding: var(--space-sm);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    justify-content: center;
    transition: all 0.3s ease;
}

.purchase-drawer-close-btn:hover {
    background: var(--color-silver-200);
    color: var(--color-silver-800);
}

/* Desktop-specific button enhancements (wider than mobile) */
@media (min-width: 769px) {
    .purchase-drawer .purchase-text-btn {
        padding: var(--space-xs) var(--space-md);
        font-size: var(--font-sm);
        min-width: auto;
        justify-content: flex-end; /* Right align */
    }

    .purchase-drawer .submit-button {
        width: 100%;
        justify-content: center;
    }

    .purchase-drawer-option-link {
        padding: 0.5rem 1rem;
        font-size: var(--font-lg);
        min-height: auto;
        display: flex;
        align-items: center;
        justify-content: flex-start;
    }

    /* Right align purchase button in wrapper if needed */
    .purchase-button-wrapper {
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }

    /* Ensure drawer opens smoothly on desktop */
    .purchase-drawer {
        animation: slideInRight 0.5s cubic-bezier(0.645, 0.045, 0.355, 1);
    }

    @keyframes slideInRight {
        from {
            transform: translateX(100%);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }
}

/* Large screens (1024px+): Enhance drawer positioning and sizing */
@media (min-width: 1024px) {
    .purchase-drawer {
        max-width: 500px; /* Slightly wider drawer for more space */
    }

    .purchase-drawer-container {
        justify-content: flex-end; /* Ensure consistent right alignment */
    }

    .purchase-drawer-overlay {
        background-color: rgba(0, 0, 0, 0.3); /* Lighter overlay for larger screens */
    }
}

/* Extra large screens (1200px+): Optimize for ultra-wide displays */
@media (min-width: 1200px) {
    .purchase-drawer {
        max-width: 550px; /* Even wider for ultra-wide screens */
    }

    .purchase-drawer-container {
        justify-content: center; /* Center drawer on very wide screens */
    }

    .purchase-drawer-container.open .purchase-drawer {
        transform: translateX(0); /* Ensure no offset on centered drawers */
    }
}

/* Hide sticky bar when drawer open (reinforce JS) */
.sticky-purchase-mobile.hidden {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* --- Drawer Content --- */
.purchase-drawer-header {
    padding: var(--space-xl);
    border-bottom: 1px solid var(--color-silver-200);
    position: relative;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
}

/* Enhanced back button in header */
.drawer-back-btn {
    background: none;
    border: none;
    color: var(--color-silver-700);
    font-size: var(--font-sm);
    cursor: pointer;
    text-decoration: none;
    padding: 0.5rem 0;
    margin-bottom: var(--space-sm);
    transition: color 0.2s ease;
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
}

.drawer-back-btn:hover {
    color: var(--color-silver-800);
    text-decoration: underline;
}

/* Title and subtitle styling */
.drawer-title {
    font-family: var(--primary-font);
    font-size: var(--font-lg);
    font-weight: var(--weight-light);
    color: var(--color-silver-800);
    margin: 0 0 var(--space-sm) 0;
    align-self: flex-start;
}

.drawer-subtitle {
    font-size: var(--font-sm);
    color: var(--color-silver-600);
    font-style: italic;
    margin: 0;
    align-self: flex-start;
}

/* Made-to-order note as professional tip box */
.drawer-note {
    background-color: var(--color-silver-50);
    border: 1px solid var(--color-silver-200);
    border-radius: 8px;
    padding: var(--space-md);
    margin: var(--space-md) 0 var(--space-lg) 0;
    font-size: var(--font-sm);
    line-height: 1.6;
    color: var(--color-silver-600);
    align-self: stretch;
}

/* View transitions for multi-step */
.purchase-drawer-selection-view,
.purchase-drawer-checkout-view {
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 1;
    transform: translateX(0);
}

.purchase-drawer-selection-view.hidden,
.purchase-drawer-checkout-view.hidden {
    opacity: 0;
    transform: translateX(-20px);
    pointer-events: none;
}



.purchase-drawer-content {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
}

.purchase-drawer-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: var(--space-xl);
    display: flex;
    flex-direction: column;
    align-items: stretch; /* Ensure full width for buttons */
}

/* Loading spinner for submit */
.submit-button:disabled::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#submit-button:disabled {
    cursor: not-allowed;
    background-color: var(--color-silver-200);
    pointer-events: none;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Purchase Form --- */
.purchase-form {
    width: 100%;
}

/* Order Summary Card */
.order-summary {
    background-color: var(--color-silver-50);
    border: 1px solid var(--color-silver-300);
    border-radius: 8px;
    padding: var(--space-lg);
    margin-bottom: var(--space-xl);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) 0;
    font-size: var(--font-base);
    color: var(--color-silver-700);
    border-bottom: 1px solid var(--color-silver-200);
}

.summary-row:last-child {
    border-bottom: none;
    padding-top: var(--space-md);
    font-weight: var(--weight-medium);
}

.summary-row.total {
    color: var(--color-emerald-600);
    font-size: var(--font-lg);
    font-weight: var(--weight-bold);
}

.summary-row span:first-child {
    font-weight: var(--weight-light);
}

.summary-row span:last-child {
    text-align: right;
}

/* Form Sections and Groups */
.form-section {
    margin-bottom: var(--space-xl);
}

.section-title {
    font-size: var(--font-lg);
    font-weight: var(--weight-light);
    color: var(--color-silver-800);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--color-silver-200);
}

.form-group {
    margin-bottom: var(--space-lg);
}

label {
    display: block;
    font-weight: var(--weight-medium);
    color: var(--color-silver-700);
    margin-bottom: var(--space-sm);
    font-size: var(--font-sm);
}

input[type="email"] {
    width: 100%;
    padding: var(--space-md);
    border: 1px solid var(--color-silver-300);
    border-radius: 8px;
    background-color: var(--color-silver-50);
    font-size: var(--font-base);
    font-family: var(--primary-font);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

input[type="email"]:focus {
    border-color: var(--color-primary-500);
    box-shadow: 0 0 0 2px rgba(100, 116, 139, 0.2);
    outline: none;
}

input[type="email"]:invalid {
    border-color: var(--color-red-400);
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

input[type="email"].valid {
    border-color: var(--color-emerald-400);
    background-color: var(--color-silver-50);
}

input[type="email"].valid::after {
    content: '✓';
    position: absolute;
    right: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-emerald-500);
    font-size: var(--font-base);
    font-weight: bold;
    pointer-events: none;
}

input[type="email"].invalid::after {
    content: '✗';
    position: absolute;
    right: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-red-500);
    font-size: var(--font-base);
    font-weight: bold;
    pointer-events: none;
}

.help-text {
    font-size: var(--font-sm);
    color: var(--color-silver-500);
    margin-top: var(--space-sm);
    font-style: italic;
    display: block;
}

/* Note: Other purchase form styles like .form-group, .form-section, etc.,
   are assumed to be generic and will be picked up by existing rules.
   If they need to be isolated, they can be moved here and renamed. */

.stripe-logo {
    display: block; /* Ensure block for sizing */
    width: 80px; /* Compact size */
    height: auto; /* Proportional */
    max-width: 100%; /* Responsive cap */
    margin: var(--space-md, 20px) auto 0; /* Center below card, space */
    opacity: 0; /* Initially hidden */
    transition: opacity 0.3s ease; /* Fade in */
    filter: grayscale(100%) opacity(0.7); /* Subtle branding */
}

.stripe-logo.visible { /* JS adds this class */
    opacity: 1;
    filter: none; /* Full color on show */
}

/* Mobile: Smaller */
@media (max-width: 768px) {
    .stripe-logo {
        width: 60px; /* Even smaller */
        margin: var(--space-sm, 12px) auto 0;
    }
}

/* Hide if form invalid */
#purchase-drawer-checkout-view.invalid .stripe-logo {
    display: none; /* Or opacity:0 */
}
