/* ==========================================================================
   Page-Specific Layouts
   Tegel Funnel
   ========================================================================== */

/* --------------------------------
   Shared Page Layout
   -------------------------------- */

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page__header {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-subtle);
    backdrop-filter: blur(12px);
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 var(--space-6);
    max-width: var(--container-max);
    margin: 0 auto;
    width: 100%;
}

.header__logo {
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    text-decoration: none;
}

.header__logo span {
    color: var(--accent-primary);
}

.header__nav {
    display: flex;
    align-items: center;
    gap: var(--space-6);
}

.header__step {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.header__step--active {
    color: var(--text-primary);
}

.header__step-number {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
}

.header__step--active .header__step-number {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: var(--text-inverse);
}

.header__step--completed .header__step-number {
    background: var(--success);
    border-color: var(--success);
    color: var(--text-primary);
}

.page__content {
    flex: 1;
    padding: var(--space-12) 0;
}

.page__footer {
    padding: var(--space-8) 0;
    border-top: 1px solid var(--border-subtle);
    text-align: center;
}

.page__footer p {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* --------------------------------
   Page 1: Configurator Layout
   -------------------------------- */

.configurator {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-12);
    align-items: start;
}

.configurator__preview {
    position: sticky;
    top: 100px;
    /* Fallback */
    top: calc(var(--header-height) + var(--space-8));
    height: fit-content;
    /* Critical for sticky to work if child is taller */
    z-index: 5;
}

.configurator__panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
}

.preview-frame {
    position: relative;
    aspect-ratio: 1;
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-frame::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 12px solid var(--bg-elevated);
    border-radius: var(--radius-xl);
    pointer-events: none;
}

.preview-frame__image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-frame__placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    color: var(--text-muted);
}

.preview-frame__placeholder svg {
    width: 80px;
    height: 80px;
    opacity: 0.5;
}

.section-title {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-4);
}

.section-subtitle {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-bottom: var(--space-4);
}

/* --------------------------------
   Page 2: Upsells Layout
   -------------------------------- */

.upsells {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-12);
    align-items: start;
}

.upsells__main {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
}

.upsells__sidebar {
    position: sticky;
    top: calc(var(--header-height) + var(--space-8));
}

.order-summary {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    overflow: hidden;
}

.order-summary__header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--border-subtle);
}

.order-summary__title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
}

.order-summary__items {
    padding: var(--space-4);
}

.order-item {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.order-item:hover {
    background: var(--bg-elevated);
}

.order-item__image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--radius-md);
    background: var(--bg-primary);
}

.order-item__details {
    flex: 1;
}

.order-item__name {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-primary);
}

.order-item__meta {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: var(--space-1);
}

.order-item__price {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--accent-primary);
}

.order-summary__footer {
    padding: var(--space-6);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
}

.order-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
}

.order-total__label {
    font-size: var(--text-base);
    color: var(--text-secondary);
}

.order-total__value {
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    color: var(--accent-primary);
}

/* Upsell Cards Grid */
.upsell-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-6);
}

.upsell-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    overflow: hidden;
    transition: all var(--transition-normal);
}

.upsell-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.upsell-card--selected {
    border-color: var(--accent-primary);
}

.upsell-card__image {
    aspect-ratio: 4/3;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.upsell-card__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.upsell-card__body {
    padding: var(--space-5);
}

.upsell-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-3);
}

.upsell-card__name {
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
}

.upsell-card__price {
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    color: var(--accent-primary);
}

.upsell-card__desc {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-bottom: var(--space-4);
}

/* --------------------------------
   Page 3: Checkout Layout
   -------------------------------- */

.checkout {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: var(--space-12);
    align-items: start;
}

.checkout__form {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
}

.checkout__summary {
    position: sticky;
    top: calc(var(--header-height) + var(--space-8));
}

.form-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
}

.form-section__title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

/* Cart Line Items */
.cart-items {
    display: flex;
    flex-direction: column;
}

.cart-item {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.cart-item:last-child {
    border-bottom: none;
}

.cart-item__image {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: var(--radius-md);
    background: var(--bg-primary);
}

.cart-item__details {
    flex: 1;
}

.cart-item__name {
    font-weight: var(--font-medium);
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.cart-item__variant {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.cart-item__accessories {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: var(--space-2);
}

.cart-item__price {
    font-weight: var(--font-semibold);
    color: var(--accent-primary);
    white-space: nowrap;
}

.cart-item__remove {
    color: var(--text-muted);
    padding: var(--space-2);
    transition: color var(--transition-fast);
}

.cart-item__remove:hover {
    color: var(--error);
}

/* Price Breakdown */
.price-breakdown {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    margin-top: var(--space-4);
}

.price-row {
    display: flex;
    justify-content: space-between;
}

.price-row__label {
    color: var(--text-secondary);
}

.price-row__value {
    font-weight: var(--font-medium);
    color: var(--text-primary);
}

.price-row--total {
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-subtle);
}

.price-row--total .price-row__label {
    font-weight: var(--font-semibold);
    color: var(--text-primary);
}

.price-row--total .price-row__value {
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    color: var(--accent-primary);
}

/* --------------------------------
   Responsive Layouts
   -------------------------------- */

@media (max-width: 1024px) {

    .configurator,
    .upsells,
    .checkout {
        grid-template-columns: 1fr;
    }

    /* Configurator: Preview at top */
    .configurator__preview {
        position: sticky;
        top: 20px;
        /* Space from top */
        z-index: 10;
        margin-bottom: var(--space-6);
        background: var(--bg-primary);
        /* Ensure no transparency issues */
        padding-bottom: var(--space-4);
        /* Add some padding */
    }

    /* Upsells: Hide desktop sidebar (JS handles mobile view) */
    .upsells__sidebar {
        display: none;
    }

    /* Checkout: Summary at bottom (default order) */
    .checkout__summary {
        position: static;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 0 var(--space-4);
    }

    .header__nav {
        display: flex;
        gap: var(--space-3);
    }

    .header__step span:not(.header__step-number) {
        display: none;
    }

    .page__content {
        padding: var(--space-8) 0;
    }

    .container {
        padding: 0 var(--space-4);
    }

    .size-selector {
        flex-direction: column;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .upsell-grid {
        grid-template-columns: 1fr;
    }
}

/* Mobile Sticky CTA Bar - Matches sidebar disappearance at 1024px */
@media (max-width: 1024px) {
    .mobile-cta-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background: var(--bg-primary);
        border-top: 1px solid var(--border-subtle);
        padding: var(--space-4) 0;
        z-index: var(--z-sticky);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);
        animation: slideUp 0.3s ease-out;
        /* Display is managed by JS to match sidebar logic, but we provide base layout here */
    }

    .mobile-cta-bar__content {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-4);
    }

    .mobile-cta-bar__info {
        display: flex;
        flex-direction: column;
    }

    .mobile-cta-bar__label {
        font-size: var(--text-xs);
        color: var(--text-muted);
    }

    .mobile-cta-bar__total {
        font-size: var(--text-lg);
        font-weight: var(--font-bold);
        color: var(--accent-primary);
    }

    .btn--mobile-cta {
        flex: 1;
        justify-content: center;
    }

    /* Add padding to prevent content from being hidden behind sticky bar */
    .upsells {
        padding-bottom: 80px;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }

        to {
            transform: translateY(0);
        }
    }
}