/**
 * Drawers - Nav, Cart, Filter, Search
 * Simple slide-in panels with overlay
 */

/* Prevent layout shift when drawer opens */
html {
    scrollbar-gutter: stable;
}

/* Lock body scroll when any drawer is open - modern approach */
body.drawer-open {
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;           /* iOS Safari */
    -webkit-overflow-scrolling: none;
}

/* ==========================================================================
   OVERLAY
   ========================================================================== */

.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-overlay);
}

/* Alpine transition utilities (Tailwind-compatible) */
.translate-x-0 { transform: translateX(0) !important; }
.translate-x-full { transform: translateX(100%) !important; }
.-translate-x-full { transform: translateX(-100%) !important; }
.opacity-0 { opacity: 0 !important; }
.opacity-100 { opacity: 1 !important; }
.transition { transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); }
.ease-out { transition-timing-function: cubic-bezier(0, 0, 0.2, 1); }
.ease-in { transition-timing-function: cubic-bezier(0.4, 0, 1, 1); }
.duration-200 { transition-duration: 200ms; }
.duration-300 { transition-duration: 300ms; }

/* ==========================================================================
   DRAWER BASE
   ========================================================================== */

.drawer {
    position: fixed;
    top: 0;
    height: 100vh; /* Fallback for older browsers */
    height: 100svh; /* Small viewport - stable, always fits on iOS */
    width: min(85vw, var(--drawer-width));
    background: var(--surface);
    z-index: var(--z-drawer);
    display: flex;
    flex-direction: column;
    /* Safe area insets for iPhone notch/Dynamic Island */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    /* No transform here - Alpine x-show handles visibility,
       Alpine x-transition handles slide animation */
}

.drawer--left {
    left: 0;
}

.drawer--right {
    right: 0;
    border-left: solid 2px black;
}

/* Drawer header */
.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--outline-variant);
}

.drawer-header h2 {
    font-size: var(--text-lg);
    margin: 0;
}

.drawer-close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
}

/* Drawer body */
.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4) var(--space-6);
}

/* Drawer footer */
.drawer-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--outline-variant);
}

/* ==========================================================================
   NAV DRAWER
   ========================================================================== */

.drawer-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.drawer-nav a {
    display: block;
    padding: var(--space-3) 0;
    font-size: var(--text-lg);
    color: var(--on-surface);
    text-decoration: none;
    border-bottom: 1px solid var(--outline-variant);
}

/* Mobile language/currency in drawer footer */
.drawer-switcher {
    margin-bottom: var(--space-4);
}

.drawer-switcher__label {
    display: block;
    font-size: var(--text-sm);
    color: var(--on-surface-variant);
    margin-bottom: var(--space-2);
}

.drawer-switcher__options {
    display: flex;
    gap: var(--space-2);
}

.drawer-switcher__btn {
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--outline-variant);
    border-radius: var(--radius-sm);
    background: none;
    font-size: var(--text-sm);
    cursor: pointer;
    text-decoration: none;
    color: var(--on-surface);
}

.drawer-switcher__btn.is-active {
    background: var(--surface-container);
    border-color: var(--primary);
}

/* ==========================================================================
   CART DRAWER
   ========================================================================== */

.cart-drawer {
    width: min(90vw, 420px);
}

.cart-item {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-4) 0;
    border-bottom: 1px solid var(--outline-variant);
}

.cart-item__image {
    width: 80px;
    height: 100px;
    object-fit: cover;
    border-radius: var(--radius-sm);
}

.cart-item__details {
    flex: 1;
}

.cart-item__name {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    margin-bottom: var(--space-1);
}

.cart-item__meta {
    font-size: var(--text-xs);
    color: var(--on-surface-variant);
}

.cart-item__price {
    font-size: var(--text-sm);
    margin-top: var(--space-2);
}

.cart-item__remove {
    background: none;
    border: none;
    font-size: var(--text-xs);
    color: var(--on-surface-variant);
    cursor: pointer;
    text-decoration: underline;
}

/* Cart totals */
.cart-totals {
    padding: var(--space-4) 0;
}

.cart-totals__row {
    display: flex;
    justify-content: space-between;
    margin-bottom: var(--space-2);
}

.cart-totals__total {
    font-size: var(--text-lg);
    font-weight: var(--font-medium);
}

/* Cart actions */
.cart-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

/* ==========================================================================
   CART EMPTY STATE
   ========================================================================== */

.cart-empty-state {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-top: var(--space-4);
}

.cart-empty-content {
    margin-bottom: var(--space-10);
}

.cart-empty-title {
    font-family: var(--font-serif);
    font-size: var(--text-fluid-2xl);
    font-weight: var(--font-normal);
    line-height: var(--leading-tight);
    color: var(--on-surface);
    margin: 0 0 var(--space-3) 0;
}

.cart-empty-subtitle {
    font-family: var(--font-serif);
    font-size: var(--text-fluid-lg);
    font-style: italic;
    font-weight: var(--font-normal);
    color: var(--on-surface-variant);
    margin: 0;
}

.cart-empty-links {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    margin-bottom: var(--space-10);
}

.cart-empty-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    color: var(--on-surface);
    text-decoration: none;
    font-size: var(--text-lg);
    transition: color var(--duration-fast);
}

.cart-empty-link:hover {
    color: var(--primary);
    text-decoration: none;
}

.cart-empty-link .icon {
    width: 1.25rem;
    height: 1.25rem;
    transition: transform var(--duration-normal);
}

.cart-empty-link:hover .icon {
    transform: translateX(4px);
}

.cart-empty-link span {
    border-bottom: 1px solid transparent;
    transition: border-color var(--duration-fast);
}

.cart-empty-link:hover span {
    border-color: currentColor;
}

.cart-empty-image {
    margin-top: auto;
}

.cart-empty-image img {
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 4;
    object-fit: cover;
}

/* Mobile: smaller image */
@media (max-width: 480px) {
    .cart-empty-image img {
        max-height: 280px;
    }
}

/* ==========================================================================
   SEARCH BAR
   ========================================================================== */

.search-bar {
    background: var(--surface);
    border-top: 1px solid var(--outline-variant);
    padding: var(--space-4) var(--gutter-fluid);
}

.search-bar form {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    max-width: var(--container-narrow);
    margin: 0 auto;
}

.search-field {
    flex: 1;
    display: flex;
    align-items: center;
    border: 1px solid var(--outline-variant);
    border-radius: var(--radius-sm);
    background: var(--surface);
    overflow: hidden;
}

.search-field input,
.search-field input[type="search"] {
    flex: 1;
    padding: var(--space-3);
    border: 0;
    background: transparent;
    font-size: var(--text-base);
    outline: none;
    min-height: auto;
    box-shadow: none;
}

.search-field input:focus {
    box-shadow: none;
}

.search-field button {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    border-left: 0;
    outline: none;
    cursor: pointer;
}

.search-bar__close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
}

/* ==========================================================================
   FILTER DRAWER
   ========================================================================== */

.filter-group {
    margin-bottom: var(--space-6);
}

.filter-group__title {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    margin-bottom: var(--space-3);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

.filter-option {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) 0;
    cursor: pointer;
}

.filter-option input {
    width: auto;
}

/* ==========================================================================
   GEO MODAL
   ========================================================================== */

.geo-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-4);
}

.geo-modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    max-width: 400px;
    text-align: center;
    position: relative;
}

.geo-modal__close {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    background: none;
    border: none;
    font-size: var(--text-2xl);
    cursor: pointer;
    line-height: 1;
}

.geo-modal h2 {
    margin-bottom: var(--space-2);
}

.geo-modal p {
    color: var(--on-surface-variant);
    margin-bottom: var(--space-6);
}

.geo-modal__actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

/* ==========================================================================
   COLOR DRAWER
   ========================================================================== */

.drawer--color {
    width: min(90vw, 480px);
}

@media (max-width: 480px) {
    .drawer--color {
        width: 100vw;
    }
}

.drawer--color .drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.drawer-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--on-surface-variant);
    border-radius: 50%;
    transition: background-color var(--duration-fast);
}

.drawer-close:hover {
    background-color: var(--surface-variant);
}

.color-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
}

.color-drawer-selected {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    background: var(--surface-variant);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-4);
}

.color-drawer-selected__label {
    font-size: var(--text-sm);
    color: var(--on-surface-variant);
}

.color-drawer-selected__value {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--on-surface);
}

.color-drawer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: var(--space-3);
    flex: 1;
    align-content: space-evenly;
}

.color-drawer-swatch {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    cursor: pointer;
    transition: transform var(--duration-fast);
}

.color-drawer-swatch__preview {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 0;
    background-size: cover;
    background-position: center;
    border: 3px solid #fff;
}

.color-drawer-swatch.is-selected .color-drawer-swatch__preview {
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}

.color-drawer-swatch:hover {
    transform: scale(1.1);
}


.color-drawer-swatch__name {
    display: none;
}

/* [x-cloak] - defined in base.css */

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */

.smart-cart-toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.875rem 1.5rem;
    background: var(--surface);
    color: var(--on-surface);
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 500;
    z-index: var(--z-toast);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast--success {
    background: #22c55e;
    color: #fff;
}

.toast--error {
    background: #ef4444;
    color: #fff;
}
