/**
 * Page Builder Frontend Styles
 * Styles for displaying page builder content on the public-facing website
 */

/* Section Layout */
.pb-section,
.pb-section * {
    box-sizing: border-box;
}

.pb-section {
    position: relative;
    width: 100%;
    overflow: visible;
    /* Use auto z-index to prevent stacking context issues */
    z-index: auto;
}

/* 
 * SECTION STACKING FIX FOR NEGATIVE MARGINS
 * ==========================================
 * Problem: When using negative margins to overlap sections, earlier sections cover later ones.
 * Solution: Later sections get higher z-index to appear on TOP.
 * 
 * This works at ANY nesting level - inside columns, inside other sections, etc.
 */

/* First section in any container */
.pb-section:first-child,
.pb-section:nth-of-type(1) {
    z-index: 1 !important;
}

/* Each subsequent section gets progressively higher z-index */
.pb-section:nth-of-type(2) { z-index: 2 !important; }
.pb-section:nth-of-type(3) { z-index: 3 !important; }
.pb-section:nth-of-type(4) { z-index: 4 !important; }
.pb-section:nth-of-type(5) { z-index: 5 !important; }
.pb-section:nth-of-type(6) { z-index: 6 !important; }
.pb-section:nth-of-type(7) { z-index: 7 !important; }
.pb-section:nth-of-type(8) { z-index: 8 !important; }
.pb-section:nth-of-type(9) { z-index: 9 !important; }
.pb-section:nth-of-type(10) { z-index: 10 !important; }
.pb-section:nth-of-type(11) { z-index: 11 !important; }
.pb-section:nth-of-type(12) { z-index: 12 !important; }
.pb-section:nth-of-type(13) { z-index: 13 !important; }
.pb-section:nth-of-type(14) { z-index: 14 !important; }
.pb-section:nth-of-type(15) { z-index: 15 !important; }
.pb-section:nth-of-type(16) { z-index: 16 !important; }
.pb-section:nth-of-type(17) { z-index: 17 !important; }
.pb-section:nth-of-type(18) { z-index: 18 !important; }
.pb-section:nth-of-type(19) { z-index: 19 !important; }
.pb-section:nth-of-type(20) { z-index: 20 !important; }

/* Adjacent sibling selector - guaranteed to work for consecutive sections */
.pb-section + .pb-section { z-index: 2 !important; }
.pb-section + .pb-section + .pb-section { z-index: 3 !important; }
.pb-section + .pb-section + .pb-section + .pb-section { z-index: 4 !important; }
.pb-section + .pb-section + .pb-section + .pb-section + .pb-section { z-index: 5 !important; }

/* Sections nested inside columns */
.pb-column > .pb-section:first-of-type { z-index: 1 !important; }
.pb-column > .pb-section:nth-of-type(2) { z-index: 2 !important; }
.pb-column > .pb-section:nth-of-type(3) { z-index: 3 !important; }
.pb-column > .pb-section:nth-of-type(4) { z-index: 4 !important; }
.pb-column > .pb-section:nth-of-type(5) { z-index: 5 !important; }

/* Prevent columns from creating new stacking contexts */
.pb-column {
    z-index: auto !important;
}

/* Ensure section content doesn't interfere with stacking */
.pb-section-content {
    z-index: auto;
}

/* Background Overlays */
.pb-background-overlay,
.pb-image-overlay,
.pb-carousel-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: none;
}

.pb-section .pb-background-overlay {
    z-index: 1;
}

.pb-column .pb-background-overlay {
    z-index: 0;
}

.pb-element[data-type="image"] .pb-image-overlay {
    z-index: 1;
}

.pb-carousel-container .pb-carousel-overlay {
    z-index: 1;
}

/* Add top padding to first section to clear header */
.pb-section:first-child {
    padding-top: 80px;
}

.pb-section-content {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    margin: 0 auto;
    position: relative;
    /* Changed from z-index: 2 to auto - prevents stacking context interference with nested sections */
    z-index: auto;
    overflow: visible;
}

/* Column Layout */
.pb-column {
    flex: 1;
    min-width: 0;
    padding: 15px;
    display: flex;
    flex-direction: column;
    overflow: visible;
    position: relative;
}

/* Responsive Column Breakpoints */
/* Only apply specific widths when they are NOT 100% (to preserve flex behavior) */
.pb-column[data-width-desktop]:not([data-width-desktop="100%"]) {
    width: var(--col-width-desktop) !important;
    flex-basis: var(--col-width-desktop) !important;
    flex-grow: 0 !important;
    flex-shrink: 0 !important;
}

@media (max-width: 768px) {
    /* Stack columns by default on tablet */
    .pb-section-content {
        flex-wrap: wrap; /* Ensure wrapping is allowed */
    }

    .pb-section .pb-column {
        flex-basis: 100% !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-right: 0 !important;
        margin-bottom: 15px; /* Add spacing between stacked columns */
    }
    
    .pb-section .pb-column:last-child {
        margin-bottom: 0;
    }
    
    /* Override for columns with explicit tablet widths */
    .pb-section .pb-column[data-width-tablet]:not([data-width-tablet="100%"]) {
        width: var(--col-width-tablet) !important;
        flex-basis: var(--col-width-tablet) !important;
        flex-grow: 0 !important;
        flex-shrink: 0 !important;
        margin-bottom: 0; /* Let grid handling manage vertical spacing if side-by-side */
    }
}

@media (max-width: 480px) {
    /* Stack columns by default on mobile */
    .pb-section-content {
        flex-direction: column; /* Force vertical stacking on mobile */
    }

    .pb-section .pb-column {
        flex-basis: 100% !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-right: 0 !important;
        margin-bottom: 15px; /* Add spacing between stacked columns */
    }

    .pb-section .pb-column:last-child {
        margin-bottom: 0;
    }
    
    /* Override for columns with explicit mobile widths */
    .pb-section .pb-column[data-width-mobile]:not([data-width-mobile="100%"]) {
        width: var(--col-width-mobile) !important;
        flex-basis: var(--col-width-mobile) !important;
        flex-grow: 0 !important;
        flex-shrink: 0 !important;
        max-width: var(--col-width-mobile) !important;
        margin-bottom: 0; /* Reset for custom widths */
    }
}

/* Element Spacing - only apply default margin if no inline style is set */
.pb-element:not([style*="margin"]) {
    margin-bottom: 15px;
}

/* Allow elements to overflow their containers for negative margins */
.pb-element {
    position: relative;
}

/* Remove margin from sections to allow flush stacking */
.pb-section.pb-element {
    margin-bottom: 0;
}

/* Default Heading Styles (Fix for Tailwind Preflight/Resets) */
/* These are base styles - inline styles from the editor will override them */
.pb-element h1:not([style*="font-size"]) { font-size: 2.5rem; }
.pb-element h2:not([style*="font-size"]) { font-size: 2rem; }
.pb-element h3:not([style*="font-size"]) { font-size: 1.75rem; }
.pb-element h4:not([style*="font-size"]) { font-size: 1.5rem; }
.pb-element h5:not([style*="font-size"]) { font-size: 1.25rem; }
.pb-element h6:not([style*="font-size"]) { font-size: 1rem; }

.pb-element h1:not([style*="font-weight"]),
.pb-element h2:not([style*="font-weight"]) { font-weight: 700; }
.pb-element h3:not([style*="font-weight"]),
.pb-element h4:not([style*="font-weight"]),
.pb-element h5:not([style*="font-weight"]),
.pb-element h6:not([style*="font-weight"]) { font-weight: 600; }

.pb-element h1:not([style*="line-height"]) { line-height: 1.2; }
.pb-element h2:not([style*="line-height"]) { line-height: 1.3; }
.pb-element h3:not([style*="line-height"]) { line-height: 1.4; }
.pb-element h4:not([style*="line-height"]) { line-height: 1.5; }
.pb-element h5:not([style*="line-height"]) { line-height: 1.6; }
.pb-element h6:not([style*="line-height"]) { line-height: 1.7; }

.pb-element h1:not([style*="margin"]),
.pb-element h2:not([style*="margin"]),
.pb-element h3:not([style*="margin"]),
.pb-element h4:not([style*="margin"]),
.pb-element h5:not([style*="margin"]),
.pb-element h6:not([style*="margin"]) { margin-bottom: 0.5em; }

.pb-element:last-child {
    margin-bottom: 0;
}

/* HTML Code Element */
.pb-html-code {
    display: block;
    width: 100%;
    box-sizing: border-box;
}

.pb-html-code * {
    /* Ensure child elements are visible */
    box-sizing: border-box;
}

.pb-html-code h1,
.pb-html-code h2,
.pb-html-code h3,
.pb-html-code h4,
.pb-html-code h5,
.pb-html-code h6 {
    display: block;
    margin: 0;
    padding: 0;
    font-weight: bold;
}

.pb-html-code h1 {
    font-size: 2em;
}

.pb-html-code h2 {
    font-size: 1.5em;
}

.pb-html-code h3 {
    font-size: 1.17em;
}

.pb-html-code h4 {
    font-size: 1em;
}

.pb-html-code h5 {
    font-size: 0.83em;
}

.pb-html-code h6 {
    font-size: 0.67em;
}

/* Remove editor-only styles on frontend */
.pb-element {
    cursor: default !important;
}

/* Shape Dividers */
.pb-shape-divider {
    position: absolute;
    left: 0;
    right: 0;
    width: 100%;
    overflow: hidden;
    line-height: 0;
    pointer-events: none;
    z-index: 1;
}

.pb-shape-divider-top {
    top: 0;
}

.pb-shape-divider-bottom {
    bottom: 0;
}

.pb-shape-divider svg {
    display: block;
    width: 100%;
    position: relative;
}

.pb-shape-flip-x svg {
    transform: scaleX(-1);
}

.pb-shape-flip-y svg {
    transform: scaleY(-1);
}

/* Animations */
[data-animation] {
    opacity: 0;
    animation-fill-mode: both;
}

.pb-animated {
    opacity: 1;
}

/* Animation Keyframes */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translate3d(0, 100%, 0);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translate3d(0, -100%, 0);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes fadeInLeft {
    from {
        opacity: 0;
        transform: translate3d(-100%, 0, 0);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes fadeInRight {
    from {
        opacity: 0;
        transform: translate3d(100%, 0, 0);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale3d(.3, .3, .3);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes bounceIn {

    from,
    20%,
    40%,
    60%,
    80%,
    to {
        animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
    }

    0% {
        opacity: 0;
        transform: scale3d(.3, .3, .3);
    }

    20% {
        transform: scale3d(1.1, 1.1, 1.1);
    }

    40% {
        transform: scale3d(.9, .9, .9);
    }

    60% {
        opacity: 1;
        transform: scale3d(1.03, 1.03, 1.03);
    }

    80% {
        transform: scale3d(.97, .97, .97);
    }

    to {
        opacity: 1;
        transform: scale3d(1, 1, 1);
    }
}

.animate-fadeIn {
    animation-name: fadeIn;
}

.animate-fadeInUp {
    animation-name: fadeInUp;
}

.animate-fadeInDown {
    animation-name: fadeInDown;
}

.animate-fadeInLeft {
    animation-name: fadeInLeft;
}

.animate-fadeInRight {
    animation-name: fadeInRight;
}

.animate-zoomIn {
    animation-name: zoomIn;
}

.animate-bounceIn {
    animation-name: bounceIn;
}

/* Responsive Visibility Classes */
@media (min-width: 1025px) {
    .hide-desktop {
        display: none !important;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .hide-tablet {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Button Styles */
.pb-element a {
    text-decoration: none;
}

/* Image Responsive */
.pb-element img {
    max-width: 100%;
    height: auto;
    display: inline-block;
    vertical-align: middle;
}

/* Image Alignment Support */
.pb-element[data-type="image"] {
    display: block;
    text-align: left;
    /* Default, overridden by inline style */
}

.pb-element[data-type="image"][style*="text-align: center"] {
    text-align: center;
}

.pb-element[data-type="image"][style*="text-align: right"] {
    text-align: right;
}

/* Video Wrapper */
.pb-video-wrapper {
    position: relative;
    width: 100%;
}

.pb-video-aspect {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
}

.pb-video-aspect iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Icon Box */
.pb-icon-box:not([style*="display"]) {
    display: flex;
}

.pb-icon-box:not([style*="align-items"]) {
    align-items: flex-start;
}

.pb-icon-box:not([style*="gap"]) {
    gap: 10px;
}

.pb-icon-box-icon {
    flex-shrink: 0;
}

.pb-icon-box-content {
    flex: 1;
}

/* Only apply default margins if no inline style is set */
.pb-icon-box-content h3:not([style*="margin"]) {
    margin: 0 0 10px 0;
}

.pb-icon-box-content p:not([style*="margin"]) {
    margin: 0;
}

/* Ensure inline styles take precedence for typography */
.pb-icon-box-title[style],
.pb-icon-box-desc[style] {
    /* Force inline styles to apply */
}

/* Social Icons */
.pb-social-icons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.pb-social-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.3s;
}

.pb-social-icon:hover {
    transform: translateY(-2px);
}

/* Tabs */
.pb-tabs-container {
    width: 100%;
}

.pb-tabs-header {
    display: flex;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 20px;
}

.pb-tab-btn {
    padding: 12px 24px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s;
    margin-bottom: -2px;
}

.pb-tab-btn.active {
    border-bottom-color: #9b27b0;
    color: #9b27b0;
    font-weight: 600;
}

.pb-tab-pane {
    animation: fadeIn 0.3s;
}

/* Carousel */
.pb-carousel-container {
    position: relative;
    width: 100%;
    overflow: hidden;
}

/* Divider - Only apply defaults if no inline style set */
.pb-element hr:not([style*="border"]) {
    border: none;
    border-top: 1px solid #e0e0e0;
}
.pb-element hr:not([style*="margin"]) {
    margin: 20px 0;
}

/* Spacer */
.pb-element[data-type="spacer"] {
    min-height: 20px;
}

/* Wide Section Support */
.pb-section[data-width="full"] .pb-section-content {
    max-width: 100%;
}

.pb-section[data-width="boxed"] .pb-section-content {
    max-width: 1200px;
    margin: 0 auto;
}

/* Default to boxed if no data-width attribute */
.pb-section:not([data-width]) .pb-section-content {
    max-width: 1200px;
    margin: 0 auto;
}

/* Text Alignment Utilities */
[style*="text-align: center"] {
    text-align: center;
}

[style*="text-align: right"] {
    text-align: right;
}

[style*="text-align: left"] {
    text-align: left;
}

/* Blog Posts Element */
.pb-blog-grid {
    display: grid;
    gap: 20px;
}

.pb-post-card {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.pb-post-image {
    display: block;
    width: 100%;
    height: 200px;
    overflow: hidden;
}

.pb-post-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pb-post-content {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.pb-post-meta {
    font-size: 12px;
    color: #999;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.pb-post-title {
    font-size: 18px;
    margin: 0 0 10px 0;
    line-height: 1.4;
    text-align: left;
}

.pb-post-title a {
    color: inherit;
    text-decoration: none;
}

.pb-post-excerpt {
    font-size: 14px;
    color: #666;
    margin-bottom: 20px;
    flex: 1;
    text-align: left;
}

.pb-post-readmore {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary, #2196f3);
    text-decoration: none;
}

/* List View */
.pb-post-list {
    flex-direction: row;
    align-items: center;
}

.pb-post-list .pb-post-image {
    width: 300px;
    height: 100%;
    min-height: 200px;
}

@media (max-width: 768px) {
    .pb-post-list {
        flex-direction: column;
    }

    .pb-post-list .pb-post-image {
        width: 100%;
    }
}

/* Store Products Element */
.pb-store-grid {
    display: grid;
    gap: 20px;
}

.pb-product-card {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.pb-product-image {
    display: block;
    width: 100%;
    height: 250px;
    overflow: hidden;
    background: #f9f9f9;
}

.pb-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pb-product-content {
    padding: 15px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pb-product-title {
    font-size: 16px;
    margin: 0;
    line-height: 1.4;
    font-weight: 600;
}

.pb-product-title a {
    color: inherit;
    text-decoration: none;
}

.pb-product-price {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.pb-product-price-current {
    font-size: 18px;
    color: #333;
}

.pb-product-price-sale {
    font-size: 18px;
    color: #e53935;
}

.pb-product-price-regular {
    font-size: 14px;
    color: #999;
    text-decoration: line-through;
}

.pb-product-add-to-cart {
    width: 100%;
    padding: 10px 20px;
    background: #2196f3;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

/* List layout */
.pb-product-list {
    flex-direction: row;
    align-items: flex-start;
}

.pb-product-list .pb-product-image {
    width: 200px;
    height: 200px;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .pb-product-list {
        flex-direction: column;
    }

    .pb-product-list .pb-product-image {
        width: 100%;
    }
}

/* Booking Widget Styles */
.pb-booking-widget {
    min-height: 200px;
    position: relative;
}

.pb-booking-widget iframe {
    display: block;
    width: 100%;
    pointer-events: auto;
    /* Enable interactions on frontend */
}

.pb-booking-container {
    position: relative;
    width: 100%;
}

.pb-booking-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none;
}

/* Connect Form Styles */
.pb-connect-form {
    min-height: 200px;
    position: relative;
}

.pb-connect-form iframe {
    display: block;
    width: 100%;
    pointer-events: auto;
    /* Enable interactions on frontend */
}

.pb-form-container {
    position: relative;
    width: 100%;
}

.pb-form-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none;
}

/* Image Gallery */
.pb-gallery-container {
    display: grid;
    width: 100%;
}

.pb-gallery-item {
    position: relative;
    overflow: hidden;
}

.pb-gallery-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.pb-gallery-item:hover .pb-gallery-img {
    transform: scale(1.05);
}

.pb-lightbox-trigger {
    display: block;
    width: 100%;
    height: 100%;
    cursor: zoom-in;
}

/* Responsive Gallery */
@media (max-width: 768px) {
    .pb-gallery-container {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
}

@media (max-width: 480px) {
    .pb-gallery-container {
        grid-template-columns: 1fr !important;
    }
}

/* Gallery Hidden State */
.pb-gallery-hidden {
    display: none;
}
.pb-gallery-load-more:hover {
    opacity: 0.9;
}

/* Lightbox Styles */
.pb-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.pb-lightbox.active {
    opacity: 1;
    pointer-events: auto;
}

.pb-lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
}

.pb-lightbox-content {
    position: relative;
    z-index: 1;
    max-width: 90%;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pb-lightbox-img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.pb-lightbox-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: transparent;
    border: none;
    color: white;
    font-size: 30px;
    cursor: pointer;
    padding: 0 10px;
}

.pb-lightbox-prev,
.pb-lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    font-size: 24px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
}

.pb-lightbox-prev:hover,
.pb-lightbox-next:hover {
    background: rgba(0, 0, 0, 0.8);
}

.pb-lightbox-prev {
    left: -70px;
}

.pb-lightbox-next {
    right: -70px;
}

@media (max-width: 768px) {
    .pb-lightbox-prev {
        left: 10px;
    }
    .pb-lightbox-next {
        right: 10px;
    }
}
