/**
 * SidebarBanner Plugin - Front-end Stylesheet
 * 画面左右両端の固定フロート追従バナー (Floating Edge Banners)
 */

:root {
    --sidebar-banner-width: 140px;
    --sidebar-banner-offset-x: 12px;
    --sidebar-banner-zindex: 1050;
}

body {
    position: relative;
}

/* バナー配置コンテナ基本設計 */
.ec-sidebarBanner {
    z-index: var(--sidebar-banner-zindex, 1050);
    width: var(--sidebar-banner-width, 140px);
    max-width: 16vw;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0;
    padding: 0;
    pointer-events: none;
    /* コンテナ外のクリックを透過 */
    max-height: 85vh;
    overflow-y: auto;
    overflow-x: visible;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

.ec-sidebarBanner::-webkit-scrollbar {
    display: none;
    /* Chrome, Safari */
}

/* 画面左端に配置 */
.ec-sidebarBanner--left {
    left: var(--sidebar-banner-offset-x, 12px);
    right: auto;
}

/* 画面右端に配置 */
.ec-sidebarBanner--right {
    right: var(--sidebar-banner-offset-x, 12px);
    left: auto;
}

/* スクロール追従固定 (is_sticky: ON) -> 画面スクロール時も上部に常時固定表示 */
.ec-sidebarBanner--sticky {
    position: fixed;
    top: 100px;
    transform: none;
}

/* スクロール追従なし (is_sticky: OFF) -> ページ上部に配置され、スクロールすると通常コンテンツと一緒に流れる */
.ec-sidebarBanner--static {
    position: absolute;
    top: 160px;
    transform: none;
}

/* クラス未指定時のフォールバック (デフォルト: スクロール追従固定) */
.ec-sidebarBanner:not(.ec-sidebarBanner--static):not(.ec-sidebarBanner--sticky) {
    position: fixed;
    top: 100px;
    transform: none;
}

/* 各バナーアイテム */
.ec-sidebarBanner__item {
    position: relative;
    pointer-events: auto;
    /* バナー自体のクリックを有効化 */
    margin: 0;
    border-radius: 8px;
    overflow: hidden;
    background: #ffffff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s ease;
}

.ec-sidebarBanner__item:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.ec-sidebarBanner__link {
    display: block;
    line-height: 0;
    text-decoration: none;
    color: inherit;
}

.ec-sidebarBanner__item img,
.ec-sidebarBanner__img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
}

/* デバイス別表示制御 (テーマ非依存・自立型) */
.ec-sidebarBanner__item--pc {
    display: block;
}

.ec-sidebarBanner__item--sp {
    display: none;
}

@media (max-width: 769px) {
    .ec-sidebarBanner__item--pc {
        display: none;
    }

    .ec-sidebarBanner__item--sp {
        display: block;
    }
}

/* HTML / スクリプトバナー用コンテナ */
.ec-sidebarBanner__html {
    max-width: 100%;
    overflow: hidden;
    text-align: center;
    line-height: normal;
    padding: 6px;
}

.ec-sidebarBanner__html iframe,
.ec-sidebarBanner__html img {
    max-width: 100%;
    height: auto;
}

/* 閉じるボタン (✕) */
.ec-sidebarBanner__close {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    line-height: 18px;
    text-align: center;
    background: rgba(30, 30, 30, 0.7);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.85);
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    font-family: Arial, sans-serif;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease, transform 0.2s ease;
    z-index: 10;
    padding: 0;
}

.ec-sidebarBanner__item:hover .ec-sidebarBanner__close {
    opacity: 1;
}

.ec-sidebarBanner__close:hover {
    background: #e74c3c;
    border-color: #ffffff;
    transform: scale(1.15);
}

/* 大画面 (1440px以上) では横幅を160pxに拡大 */
@media (min-width: 1440px) {
    :root {
        --sidebar-banner-width: 160px;
        --sidebar-banner-offset-x: 0;
    }
}

/* 中画面・PC (770px - 991px) */
@media (min-width: 770px) and (max-width: 991.98px) {
    :root {
        --sidebar-banner-width: 115px;
        --sidebar-banner-offset-x: 8px;
    }
}

/* 画面幅 769px 以下のデバイス（スマートフォン・小型タブレット）では非表示
 * （画面幅 769px 超のPC・大画面でのみ表示） */
@media (max-width: 769px) {
    .ec-sidebarBanner {
        display: none;
    }
}

/* ==========================================================================
 * Smart Layout Neutralizer (レイアウト自動復元)
 * サイドバーブロック配置時でも、テーマのメインコンテンツ幅(100%)を自動維持
 * ========================================================================== */

/* サイドバーにバナーのみ配置されている場合、空になったサイドバー列を非表示化 */
.ec-layoutRole__left:has(> .ec-sidebarBanner:only-child),
.ec-layoutRole__right:has(> .ec-sidebarBanner:only-child) {
    display: none;
    width: 0;
    padding: 0;
    margin: 0;
}

/* 両側のサイドバーがバナーのみの場合、50%に圧縮されたメインコンテンツを100%全幅に復元 */
.ec-layoutRole:has(.ec-layoutRole__left > .ec-sidebarBanner:only-child):has(.ec-layoutRole__right > .ec-sidebarBanner:only-child) .ec-layoutRole__mainBetweenColumn {
    width: 100%;
}

/* 片側のみバナーの場合、75%に圧縮されたメインコンテンツを100%全幅に復元 */
.ec-layoutRole:has(.ec-layoutRole__left > .ec-sidebarBanner:only-child) .ec-layoutRole__mainWithColumn,
.ec-layoutRole:has(.ec-layoutRole__right > .ec-sidebarBanner:only-child) .ec-layoutRole__mainWithColumn {
    width: 100%;
}

/* ==========================================================================
 * Dynamic State Classes (インラインCSS排除・クリーンクラス設計)
 * ========================================================================== */

.ec-sidebarBanner.is-hidden,
.ec-sidebarBanner__item.is-hidden {
    display: none;
}

.ec-sidebarBanner__item.is-closing {
    opacity: 0;
    transform: scale(0.85);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.ec-layoutRole__sideCol--neutralized {
    display: none;
    width: 0;
    padding: 0;
    margin: 0;
}

.ec-layoutRole__main--fullwidth {
    width: 100%;
}
