/**
 * Unified Booking Layout Styles - [roomcloud_booking] Shortcode
 *
 * Provides responsive grid layout with sticky cart sidebar for the
 * complete booking interface combining form, results, and cart.
 *
 * @package    wp_roomcloud
 * @subpackage wp_roomcloud/public/css
 * @since      1.4.102
 */

/* ==========================================================================
   Base Layout Structure
   ========================================================================== */

/**
 * Main container for the unified booking interface.
 * Uses flexbox for vertical stacking of header and body sections.
 */
.wpr-booking-layout {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    width: 100%;
    /* max-width: 1200px; */
    margin: 0 auto;
}

/* Header Section (Search Form) */
.wpr-booking-layout__header {
    width: 100%;
}

/* Body Container (Results + Sidebar Grid) */
.wpr-booking-layout__body {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    align-items: start;
    width: 100%;
}

/* Content Area (Results) */
.wpr-booking-layout__content {
    min-width: 0;
    /* Prevents grid overflow with long content */
    width: 100%;
}

.wpr-booking-layout__results {
    width: 100%;
}

/* Search state wrapper — ensures consistent width in all states (results / no-results) */
.wpr-roomcloud-search-state {
    display: block;
    width: 100%;
}

/* Sidebar (Cart) */
.wpr-booking-layout__sidebar {
    position: relative;
    /* Context for sticky child */
    width: 100%;
}

.wpr-booking-layout__cart {
    width: 100%;
}

/* ==========================================================================
   Layout Variants
   ========================================================================== */

/* Sidebar Right (Default Desktop Layout) */
.wpr-booking-layout--sidebar-right .wpr-booking-layout__body {
    grid-template-columns: 1fr 350px;
    grid-template-areas: "content sidebar";
}

.wpr-booking-layout--sidebar-right .wpr-booking-layout__content {
    grid-area: content;
}

.wpr-booking-layout--sidebar-right .wpr-booking-layout__sidebar {
    grid-area: sidebar;
}

/* Sidebar Left */
.wpr-booking-layout--sidebar-left .wpr-booking-layout__body {
    grid-template-columns: 350px 1fr;
    grid-template-areas: "sidebar content";
}

.wpr-booking-layout--sidebar-left .wpr-booking-layout__content {
    grid-area: content;
}

.wpr-booking-layout--sidebar-left .wpr-booking-layout__sidebar {
    grid-area: sidebar;
}

/* Stacked (No Sidebar) */
.wpr-booking-layout--stacked .wpr-booking-layout__body {
    grid-template-columns: 1fr;
}

.wpr-booking-layout--stacked .wpr-booking-layout__sidebar {
    display: none;
}

/* ==========================================================================
   Sticky Layout Behavior - Form and Cart Fixed, Results Scrollable
   ========================================================================== */

/**
 * Cuando el layout tiene sticky activado:
 * - El header (form) se fija al top
 * - El sidebar (cart) se fija al top
 * - Solo el contenido (results) hace scroll
 */
.wpr-booking-layout--sticky-cart .wpr-booking-layout__header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #fff;
    /* border-bottom: 1px solid #e0e0e0;
    padding-bottom: 1rem; */
    margin-bottom: 0;
}

.wpr-booking-layout--sticky-cart .wpr-booking-layout__body {
    position: relative;
}

.wpr-booking-layout--sticky-cart .wpr-booking-layout__sidebar {
    position: sticky;
    top: 0;
    align-self: flex-start;
    max-height: 100vh;
    overflow-y: auto;
    z-index: 90;
}

/* El cart wrapper se ajusta al espacio disponible */
.wpr-booking-layout--sticky-cart .wpr-booking-layout__cart {
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    overflow-x: hidden;
}

/* Visual indicators cuando están stuck */
.wpr-booking-layout--sticky-cart .wpr-booking-layout__header.is-stuck {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.wpr-booking-layout--sticky-cart .wpr-booking-layout__cart.is-stuck {
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.05);
}

/* Smooth scrollbar para cart (webkit) */
.wpr-booking-layout--sticky-cart .wpr-booking-layout__cart::-webkit-scrollbar {
    width: 6px;
}

.wpr-booking-layout--sticky-cart .wpr-booking-layout__cart::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.wpr-booking-layout--sticky-cart .wpr-booking-layout__cart::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 3px;
}

.wpr-booking-layout--sticky-cart .wpr-booking-layout__cart::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}

/* ==========================================================================
   WordPress Admin Bar Compatibility
   ========================================================================== */

/**
 * Ajustar top cuando existe admin bar de WordPress.
 * Admin bar height: 32px (desktop), 46px (mobile)
 */
.admin-bar .wpr-booking-layout--sticky-cart .wpr-booking-layout__header {
    top: 32px;
}

.admin-bar .wpr-booking-layout--sticky-cart .wpr-booking-layout__sidebar {
    top: 170px;
    max-height: calc(100vh - 32px);
}

.admin-bar .wpr-booking-layout--sticky-cart .wpr-booking-layout__cart {
    max-height: calc(100vh - 32px - 2rem);
}

@media screen and (max-width: 782px) {
    .admin-bar .wpr-booking-layout--sticky-cart .wpr-booking-layout__header {
        top: 46px;
    }

    .admin-bar .wpr-booking-layout--sticky-cart .wpr-booking-layout__sidebar {
        top: 46px;
        max-height: calc(100vh - 46px);
    }

    .admin-bar .wpr-booking-layout--sticky-cart .wpr-booking-layout__cart {
        max-height: calc(100vh - 46px - 2rem);
    }
}

/* ==========================================================================
   Error Messages
   ========================================================================== */

/**
 * Dependency error message styling.
 * Shown when WooCommerce or required components are missing.
 */
.wpr-booking-layout-error {
    padding: 1.5rem;
    /* background: #fff3cd;
    border: 1px solid #ffc107; */
    border-radius: 4px;
    /* color: #856404; */
    font-size: 1rem;
    line-height: 1.5;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

/**
 * Tablet and below: Stack sidebar below content.
 * Cart becomes a fixed bottom bar with a toggle to expand/collapse.
 */
@media (max-width: 1024px) {
    .roomcloud-cart {
        padding-top: 0 !important;
        padding-bottom: 2.5rem !important;
    }

    .wpr-booking-layout--sidebar-right .wpr-booking-layout__body,
    .wpr-booking-layout--sidebar-left .wpr-booking-layout__body {
        grid-template-columns: 1fr;
        grid-template-areas:
            "content"
            "sidebar";
    }

    /* Disable sticky header on mobile — form scrolls with page */
    .wpr-booking-layout--sticky-cart .wpr-booking-layout__header {
        position: static;
        border-bottom: none;
        padding-bottom: 0;
        margin-bottom: 2rem;
    }

    /* Remove stuck shadow on mobile */
    .wpr-booking-layout--sticky-cart .wpr-booking-layout__header.is-stuck,
    .wpr-booking-layout--sticky-cart .wpr-booking-layout__cart.is-stuck {
        box-shadow: none;
    }

    /* -----------------------------------------------------------------------
       Fixed bottom cart bar
       --------------------------------------------------------------------- */

    /* Hide the sidebar placeholder when cart is empty (JS adds wpr-mobile-cart--empty before moving to body) */
    .wpr-booking-layout--sticky-cart .wpr-booking-layout__sidebar.wpr-mobile-cart--empty {
        display: none;
    }

    /* The sidebar is moved to document.body by JS (to escape Elementor CSS transforms).
       Styling for the fixed bar is handled by .wpr-mobile-cart-bar rules below
       (outside the @media block) so they apply after the element is at body level. */

    /* -----------------------------------------------------------------------
       Strip "N units in your reservation" (rendered by the cart partial,
       bound by JS as the toggle). Colors are neutral: themes override
       background-color and color; the icon and chevron follow currentColor.
       --------------------------------------------------------------------- */

    .wpr-mobile-cart-bar .wpr-mobile-cart-toggle,
    .wpr-mobile-cart-bar .wpr-mobile-cart-toggle:hover {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        /* Full bleed: compensate the horizontal padding of .roomcloud-cart */
        width: calc(100% + 2rem);
        margin: 0 -1rem;
        padding: 0.6rem 1rem;
        background-color: #f2f2f2 !important;
        color: #333;
        border: none;
        border-radius: 0;
        font-size: 0.95rem;
        font-weight: 600;
        line-height: 1.2;
        text-align: left;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .wpr-mobile-cart-bar .wpr-mobile-cart-toggle:focus {
        outline: none;
    }

    .wpr-mobile-cart-bar .wpr-mobile-cart-toggle:focus-visible {
        outline: 2px solid currentColor;
        outline-offset: -4px;
    }

    /* Expanded: the strip stays on top of the scrolling panel */
    .wpr-mobile-cart-bar.wpr-mobile-cart--open .wpr-mobile-cart-toggle {
        position: sticky;
        top: 0;
        z-index: 11;
    }

    .wpr-mobile-cart-toggle__status,
    .wpr-mobile-cart-toggle__action {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .wpr-mobile-cart-toggle__icon {
        flex-shrink: 0;
    }

    .wpr-mobile-cart--open .wpr-mobile-cart-toggle__label--show,
    .wpr-mobile-cart-bar:not(.wpr-mobile-cart--open) .wpr-mobile-cart-toggle__label--hide {
        display: none;
    }

    /* Chevron arrow — two border lines forming a "^" or "v" shape */
    .wpr-mobile-cart-toggle__chevron {
        display: block;
        width: 9px;
        height: 9px;
        border-right: 2px solid currentColor;
        border-top: 2px solid currentColor;
        border-radius: 1px;
        /* Default (collapsed): pointing up — rotate 45° CCW + slight up nudge */
        transform: rotate(-45deg) translateY(2px);
        transition: transform 0.25s ease;
    }

    /* When expanded: flip to point down */
    .wpr-mobile-cart--open .wpr-mobile-cart-toggle__chevron {
        transform: rotate(135deg) translateY(2px);
    }

    /* -----------------------------------------------------------------------
       Swipe drag state
       --------------------------------------------------------------------- */

    /* Disable internal transitions while the user is actively dragging the bar */
    .wpr-mobile-cart-bar.wpr-mobile-cart--dragging {
        transition: none !important;
    }

    .wpr-mobile-cart-bar.wpr-mobile-cart--dragging * {
        transition: none !important;
    }
}

/* The strip only exists inside the mobile bar (.wpr-mobile-cart-bar, added by JS).
   The element selector beats theme resets like `button { display: inline-block }`
   and still loses to `.wpr-mobile-cart-bar .wpr-mobile-cart-toggle`. */
button.wpr-mobile-cart-toggle {
    display: none;
}

/* ==========================================================================
   Mobile fixed-bottom cart bar
   Applied when JS moves the sidebar to document.body to escape Elementor
   (or any other page builder's) CSS transform context.
   The class .wpr-mobile-cart-bar is added by JS on initMobileCart().
   These rules are intentionally OUTSIDE any @media block so they override
   any inherited positioning after the element is re-parented to <body>.
   ========================================================================== */

/* Fixed strip pinned to the bottom of the viewport */
.wpr-mobile-cart-bar {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0;
    right: 0;
    width: 100%;
    max-height: none;
    overflow: hidden;
    z-index: 99998;
    background: #fff;
    border-top: 2px solid #e0e0e0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.12);
    box-sizing: border-box;
    touch-action: manipulation;
    -webkit-touch-callout: none;
}

/* Expanded: fill the visible viewport, content scrolls inside if needed.
   100dvh follows Safari's dynamic toolbars: with the address bar shown,
   100vh is taller than the screen and, anchored at bottom: 0, the top of
   the panel (the "Hide" strip) ends up above it. 100vh is the fallback for
   browsers without dvh. overscroll-behavior keeps the scroll from chaining
   to the page, which would toggle the toolbars while the cart is open. */
.wpr-mobile-cart-bar.wpr-mobile-cart--open {
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Cart wrapper inside the bar: no scroll container of its own. Any overflow
   other than visible (even overflow-x alone) would make it the scroll
   container of the sticky strip, which then never sticks. The bar already
   clips horizontally (overflow: hidden above). */
.wpr-mobile-cart-bar .wpr-booking-layout__cart {
    max-height: none;
    overflow: visible;
    padding: 0;
}

/* Collapsed: hide everything except the toggle button and the mobile strip */
.wpr-mobile-cart-bar:not(.wpr-mobile-cart--open) .roomcloud-cart__title,
.wpr-mobile-cart-bar:not(.wpr-mobile-cart--open) .roomcloud-cart__summary,
.wpr-mobile-cart-bar:not(.wpr-mobile-cart--open) .roomcloud-cart__groups,
.wpr-mobile-cart-bar:not(.wpr-mobile-cart--open) .roomcloud-cart__divider,
.wpr-mobile-cart-bar:not(.wpr-mobile-cart--open) .roomcloud-cart__promo,
.wpr-mobile-cart-bar:not(.wpr-mobile-cart--open) .roomcloud-cart__actions,
.wpr-mobile-cart-bar:not(.wpr-mobile-cart--open) .roomcloud-cart__totals,
.wpr-mobile-cart-bar:not(.wpr-mobile-cart--open) .roomcloud-reservation-summary__notice,
.wpr-mobile-cart-bar:not(.wpr-mobile-cart--open) .roomcloud-cart__empty {
    display: none;
}

/* Totals row when expanded */
.wpr-mobile-cart-bar .roomcloud-cart__totals {
    padding: 0.75rem 1rem;
}

/* Mobile collapsed strip — hidden by default, only shown inside the bar when collapsed */
.wpr-mobile-cart__bar-strip {
    display: none;
}

.wpr-mobile-cart-bar:not(.wpr-mobile-cart--open) .wpr-mobile-cart__bar-strip {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
}

.wpr-mobile-cart-bar.wpr-mobile-cart--open .wpr-mobile-cart__bar-strip {
    display: none;
}

/* Dates row — check-in → check-out */
.wpr-mobile-cart__bar-dates {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #555;
    line-height: 1;
    padding-bottom: 0.15rem;
    border-bottom: 1px solid #e8e8e8;
    margin-bottom: 0.1rem;
}

.wpr-mobile-cart__bar-date-sep {
    font-size: 0.65rem;
    color: #888;
}

/* Row: total label + checkout button */
.wpr-mobile-cart__bar-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.wpr-mobile-cart__bar-total {
    flex: 1;
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.wpr-mobile-cart__bar-total-label {
    font-size: 0.7rem;
    color: #777;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.wpr-mobile-cart__bar-total-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #111;
}

.wpr-mobile-cart__bar-checkout,
.wpr-mobile-cart__bar-quote {
    margin: 0 !important;
    padding: 0.5rem 1rem !important;
    font-size: 0.85rem;
    white-space: nowrap;
}

/**
 * Mobile: Reduce spacing for compact view.
 */
@media (max-width: 600px) {
    .wpr-booking-layout {
        gap: 1.5rem;
    }

    .wpr-booking-layout__body {
        gap: 1.5rem;
    }

    .wpr-booking-layout--sidebar-right .wpr-booking-layout__body,
    .wpr-booking-layout--sidebar-left .wpr-booking-layout__body {
        gap: 1.5rem;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

/**
 * Remove sticky behavior when printing.
 * Ensure full content is visible in print output.
 */
@media print {

    .wpr-booking-layout--sticky-cart .wpr-booking-layout__header,
    .wpr-booking-layout--sticky-cart .wpr-booking-layout__sidebar {
        position: static;
    }

    .wpr-booking-layout--sticky-cart .wpr-booking-layout__cart {
        max-height: none;
        overflow: visible;
    }
}

/* ==========================================================================
   No-Results State — hide cart sidebar, restore full-width content
   ========================================================================== */

/**
 * When JS propagates data-wpr-search-no-results="1" to the layout container
 * (via publishSearchStateFlags()), hide the cart sidebar and collapse the
 * grid back to a single column so the no-availability message uses full width.
 */
.wpr-booking-layout[data-wpr-search-no-results="1"] .wpr-booking-layout__sidebar {
    display: none;
}

.wpr-booking-layout[data-wpr-search-no-results="1"].wpr-booking-layout--sidebar-right .wpr-booking-layout__body,
.wpr-booking-layout[data-wpr-search-no-results="1"].wpr-booking-layout--sidebar-left .wpr-booking-layout__body {
    grid-template-columns: 1fr;
}