/**
 * SHARPI Hero Banners — Frontend CSS
 *
 * Wpasowuje się w istniejącą siatkę hero. Obsługuje dwa scenariusze:
 *   • Mu-plugin: wrapper `.shp-hero__media` (po prawej stronie .shp-hero__copy)
 *   • Motyw:    wrapper `.hero-image`       (po prawej stronie .hero-text w .hero-content)
 *
 * Wszystkie style nakładane są przez klasę-marker `.shb-media`, więc działają
 * niezależnie od tego, w którym wrapperze siedzą.
 *
 * Pełna responsywność: desktop / tablet / mobile.
 */

/* CSS custom properties used:
   --shb-radius   : border radius for cards (px)
   --shb-overlay  : 0..1 opacity for dark overlay over images for text readability
   --shb-ar       : aspect-ratio CSS value (e.g. "4/3", "16/9", "auto") */

.shb-media {
    /* Override default media padding to give banners more breathing room */
    padding: 14px !important;
    overflow: hidden;
    /* Force the wrapper to behave the same in both scenarios */
    width: 100%;
    box-sizing: border-box;
}

/* ============================================================
 * OVERRIDE sharpi-hotfix.php constraints on .hero-image
 * ============================================================
 *
 * Mu-plugin sharpi-hotfix.php ustawia na .sharpi-hero .hero-image:
 *   - flex: 1; display: flex; justify-content: flex-end;
 *   - max-width: 520px na <img>
 *   - .sharpi-hero .hero-content { max-width: 540px }
 * Te reguły zaciskają nasz banner do małego okienka. Musimy je rozluźnić.
 */

/* === Wspólne override (oba layout modes) === */
.sharpi-hero .hero-image.shb-media,
.hero-section .hero-image.shb-media,
.hero-image.shb-media {
    flex: 1 1 auto !important;
    display: block !important;
    justify-content: initial !important;
    align-items: initial !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    height: auto !important;
}

/* === LAYOUT: SIDE (banner po prawej, obok tekstu) === */
.shb-layout-side {
    min-height: 320px;
}
/* Zwężamy lewą kolumnę żeby banner miał więcej miejsca: 540 → 420 */
.sharpi-hero:has(.shb-layout-side) .hero-content {
    max-width: 420px !important;
}
/* Banner po prawej dostaje większy minimum: ~750px na desktop */
.sharpi-hero .hero-image.shb-layout-side {
    flex: 2 1 0 !important;
    min-width: 0 !important;
}

/* === LAYOUT: FULL (banner jako absolute overlay całego hero) === */
/*
 * KLUCZOWE: gdy banner ma layout=full, JS dodatkowo ustawia inline style:
 *   - hero-section: position:relative; overflow:hidden; min-height:480px
 *   - banner:       position:absolute; inset:0; width:100%; height:100%; z-index:5
 * Plus klasę .shb-full-active na hero-section.
 *
 * To gwarantuje że banner pokryje WSZYSTKO:
 *   - tło hero (gradient z mu-pluginu sharpi-hotfix)
 *   - ::before z grafiką "hero-knives.jpg" z motywu
 *   - tekst hero (hero-content)
 */
.shb-layout-full {
    /* Inline styles applied by JS take priority, but these as fallback */
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border-radius: 0 !important;
}

/* Hide theme's ::before overlay (hero-knives.jpg with opacity 0.25) when full mode active */
.shb-full-active::before,
.shb-full-active::after {
    display: none !important;
    content: none !important;
}
/* Hide hero content (h1, p, buttons) when full mode active */
.shb-full-active .hero-content {
    display: none !important;
}
/* Make sure hero section has proper height in full mode */
.shb-full-active {
    position: relative !important;
    overflow: hidden !important;
    min-height: 480px !important;
    padding: 0 !important;
    margin: 0 !important;
    max-height: none !important; /* override mobile constraint from sharpi-hotfix */
}
/* Banner slider in full mode: fills entire hero, no border-radius (edge-to-edge) */
.shb-layout-full .shb-slider,
.shb-layout-full .shb-collage {
    width: 100% !important;
    height: 100% !important;
    border-radius: 0 !important;
    aspect-ratio: auto !important; /* override aspect-ratio; hero defines height */
}
.shb-layout-full .shb-slide {
    width: 100% !important;
    height: 100% !important;
}
.shb-layout-full .shb-card {
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: #0a0a0a !important; /* dark background for letterboxing */
}
/* In full mode, respect user's object-fit setting via CSS variable.
   - cover (default) — banner fills hero, may crop edges. Best for 16:5+ banners.
   - contain         — full banner visible, may show side bars. Use if banner aspect doesn't match hero. */
.shb-layout-full .shb-card__img {
    object-fit: var(--shb-fit, cover) !important;
    object-position: center center !important;
    background: #0a0a0a;
}
/* In full mode, hide the per-card text overlay since the banner image already has text baked in */
.shb-layout-full .shb-card__overlay {
    display: none !important;
}
/* Disable hover zoom in full mode */
.shb-layout-full .shb-card:hover .shb-card__img {
    transform: none !important;
}

/* When sitting inside theme's .hero-image (which often has fixed height on mobile) */
.hero-image.shb-media {
    order: initial !important;
}

.shb-media * { box-sizing: border-box; }

/* ============ Universal card ============ */
.shb-card {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: var(--shb-radius, 14px);
    overflow: hidden;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.10);
    box-shadow: 0 6px 18px rgba(0,0,0,0.18);
    isolation: isolate;
}

.shb-card__img {
    width: 100%;
    height: 100%;
    object-fit: var(--shb-fit, cover);
    object-position: center;
    display: block;
    transition: transform .6s ease;
    /* Improve image rendering quality on retina */
    image-rendering: auto;
    image-rendering: -webkit-optimize-contrast;
    /* When using contain, give a neutral background so non-filled area is clean */
    background: rgba(0, 0, 0, 0.04);
}

.shb-card:hover .shb-card__img {
    transform: scale(1.04);
}

/* If contain mode is active, disable the zoom-on-hover so we don't crop image */
.shb-media[style*="--shb-fit:contain"] .shb-card:hover .shb-card__img {
    transform: none;
}

.shb-card__overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        180deg,
        rgba(0,0,0,0) 0%,
        rgba(0,0,0, calc(var(--shb-overlay, 0.35) * 0.55)) 45%,
        rgba(0,0,0, var(--shb-overlay, 0.35)) 100%
    );
    display: flex;
    align-items: flex-end;
    padding: 20px;
    pointer-events: none;
}

.shb-card__content {
    width: 100%;
    pointer-events: auto;
    color: #fff;
}

.shb-card__title {
    margin: 0 0 6px;
    font-size: clamp(18px, 1.8vw, 24px);
    line-height: 1.2;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    letter-spacing: 0.2px;
}

.shb-card__subtitle {
    margin: 0 0 12px;
    font-size: clamp(13px, 1.2vw, 15px);
    line-height: 1.4;
    color: rgba(255,255,255,0.92);
    text-shadow: 0 1px 4px rgba(0,0,0,0.5);
    max-width: 50ch;
}

.shb-card__btn {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    background: #ff7a00;
    color: #fff !important;
    text-decoration: none !important;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.3px;
    transition: background .15s, transform .15s, box-shadow .15s;
    box-shadow: 0 4px 12px rgba(255,122,0,0.35);
    border: none;
    line-height: 1;
}
.shb-card__btn:hover {
    background: #e36a00;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(255,122,0,0.45);
    color: #fff !important;
}
.shb-card__btn:active {
    transform: translateY(0);
}

/* Whole-card link (when no btn label set but URL exists) */
.shb-card__link {
    position: absolute;
    inset: 0;
    z-index: 2;
    text-indent: -9999px;
    overflow: hidden;
}

/* ============ Slider mode ============ */
.shb-media.shb-mode-slider .shb-slider,
.shb-media.shb-mode-single .shb-slider {
    position: relative;
    width: 100%;
    aspect-ratio: var(--shb-ar, 4/3);
    overflow: hidden;
    border-radius: var(--shb-radius, 14px);
}

/* aspect-ratio: auto means the wrapper takes intrinsic image size */
.shb-media[style*="--shb-ar:auto"] .shb-slider {
    aspect-ratio: auto;
    min-height: 280px;
}

.shb-track {
    position: relative;
    width: 100%;
    height: 100%;
}

.shb-slide {
    position: absolute;
    inset: 0;
    opacity: 0;
    visibility: hidden;
    transition: opacity .55s ease;
    pointer-events: none;
}
.shb-slide.is-active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    z-index: 1;
}

.shb-slide .shb-card {
    border: none;
    box-shadow: none;
    border-radius: 0;
    background: transparent;
}

/* Arrows */
.shb-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.92);
    color: #1a1a1a;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    z-index: 3;
    opacity: 0;
    transition: opacity .2s, background .15s, transform .15s;
}
.shb-slider:hover .shb-arrow,
.shb-slider:focus-within .shb-arrow {
    opacity: 1;
}
.shb-arrow:hover {
    background: #fff;
}
.shb-arrow:focus-visible {
    opacity: 1;
    outline: 2px solid #ff7a00;
    outline-offset: 2px;
}
.shb-arrow--prev { left: 10px; }
.shb-arrow--next { right: 10px; }

/* On touch devices, keep arrows visible */
@media (hover: none) {
    .shb-arrow { opacity: 0.85; }
}

/* Dots */
.shb-dots {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 3;
    padding: 6px 10px;
    background: rgba(0,0,0,0.35);
    border-radius: 100px;
    backdrop-filter: blur(8px);
}
.shb-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.55);
    cursor: pointer;
    padding: 0;
    transition: background .2s, width .2s;
}
.shb-dot:hover { background: rgba(255,255,255,0.85); }
.shb-dot.is-active {
    background: #ff7a00;
    width: 22px;
    border-radius: 4px;
}
.shb-dot:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ============ Single mode ============ */
.shb-media.shb-mode-single .shb-track .shb-slide {
    position: relative;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}
.shb-media.shb-mode-single .shb-dots,
.shb-media.shb-mode-single .shb-arrow {
    display: none;
}

/* ============ Collage mode ============ */
.shb-media.shb-mode-collage .shb-collage {
    display: grid;
    gap: 12px;
    width: 100%;
}

/* Layouts depending on count: 1=full, 2=2col, 3=1+2, 4=2x2, 5+=2col masonry-ish */
.shb-collage[data-count="1"] {
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(280px, auto);
}
.shb-collage[data-count="2"] {
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: 200px;
}
.shb-collage[data-count="3"] {
    grid-template-columns: 1.4fr 1fr;
    grid-auto-rows: 140px;
}
.shb-collage[data-count="3"] .shb-card--collage:nth-child(1) {
    grid-row: span 2;
}
.shb-collage[data-count="4"] {
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: 140px;
}
.shb-collage:not([data-count="1"]):not([data-count="2"]):not([data-count="3"]):not([data-count="4"]) {
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: 140px;
}

.shb-card--collage .shb-card__title { font-size: clamp(14px, 1.4vw, 18px); }
.shb-card--collage .shb-card__subtitle { font-size: 12px; margin-bottom: 8px; }
.shb-card--collage .shb-card__btn { padding: 6px 12px; font-size: 11px; }
.shb-card--collage .shb-card__overlay { padding: 12px; }

/* ============ RESPONSIVE ============ */

/* Tablet */
@media (max-width: 980px) {
    .shb-media {
        padding: 12px !important;
    }
    .shb-collage[data-count="3"] {
        grid-template-columns: 1fr 1fr;
        grid-auto-rows: 130px;
    }
    .shb-collage[data-count="3"] .shb-card--collage:nth-child(1) {
        grid-column: span 2;
        grid-row: span 1;
    }
}

/* ============================================================
 * MOBILE — Override sharpi-hotfix.php constraints
 * ============================================================
 *
 * Mu-plugin ustawia na mobile:
 *   .sharpi-hero, .hero-section.sharpi-hero {
 *       min-height: auto !important;
 *       max-height: 55vh;       ← obcina banner!
 *       overflow: hidden;       ← chowa wystającą część!
 *   }
 *   .sharpi-hero .container { flex-direction: column; }
 *
 * Te reguły powodują że banner jest niewidoczny lub przycięty na mobile.
 * Musimy je rozbić, gdy nasz banner jest aktywny.
 */
.sharpi-hero:has(.shb-media),
.hero-section.sharpi-hero:has(.shb-media),
body .sharpi-hero,
body .hero-section.sharpi-hero {
    /* Use :has() for modern browsers; fallback below */
}

/* Reliable override (no :has dependency) — applies whenever our class is anywhere on the page */
@media (max-width: 780px) {
    .sharpi-hero,
    .hero-section.sharpi-hero {
        max-height: none !important;
        overflow: visible !important;
    }
    .sharpi-hero .container {
        gap: 20px !important;
    }
    .sharpi-hero .hero-image.shb-media,
    .hero-image.shb-media {
        width: 100% !important;
        max-width: 100% !important;
        min-height: 240px !important;
        display: block !important;
    }
}

/* Mobile */
@media (max-width: 640px) {
    .shb-media {
        padding: 10px !important;
    }

    .shb-card__overlay {
        padding: 14px;
        background: linear-gradient(
            180deg,
            rgba(0,0,0,0) 0%,
            rgba(0,0,0, calc(var(--shb-overlay, 0.35) * 0.7)) 35%,
            rgba(0,0,0, calc(var(--shb-overlay, 0.35) + 0.15)) 100%
        );
    }

    .shb-card__title  { font-size: 16px; margin-bottom: 4px; }
    .shb-card__subtitle { font-size: 12px; margin-bottom: 8px; }
    .shb-card__btn { padding: 7px 14px; font-size: 12px; }

    .shb-arrow {
        width: 34px;
        height: 34px;
        opacity: 0.9;
    }
    .shb-arrow--prev { left: 6px; }
    .shb-arrow--next { right: 6px; }

    .shb-dots {
        bottom: 8px;
        padding: 5px 8px;
    }
    .shb-dot { width: 7px; height: 7px; }
    .shb-dot.is-active { width: 18px; }

    /* Collage on mobile: always 1 column for clarity */
    .shb-media.shb-mode-collage .shb-collage,
    .shb-collage[data-count="2"],
    .shb-collage[data-count="3"],
    .shb-collage[data-count="4"],
    .shb-collage:not([data-count]) {
        grid-template-columns: 1fr !important;
        grid-auto-rows: 160px !important;
    }
    .shb-collage[data-count="3"] .shb-card--collage:nth-child(1) {
        grid-column: auto;
        grid-row: auto;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .shb-slide { transition: none; }
    .shb-card:hover .shb-card__img { transform: none; }
    .shb-card__btn { transition: none; }
}

/* Visible focus for keyboard users */
.shb-card__btn:focus-visible,
.shb-card__link:focus-visible {
    outline: 2px solid #ff7a00;
    outline-offset: 3px;
}
