/**
 * adnotice — 浮動廣告
 *
 * z-index 集中定義為 CSS 變數，佈景端可依案件覆寫（規格 §13.3）。
 */

:root {
    --adnotice-z-ad:        9000;
    --adnotice-z-cc-banner: 9500;
    --adnotice-z-cc-modal:  9600;
    --adnotice-z-edit:      9700;
    /* 媒體選擇器疊在編輯頁之上。必須高於佈景自己的固定元件 ——
       CADCH_00040A 的 .yh-navwrap 是 1030、.yh-bottom 是 1035，
       原本的 z-index:1/2 會被它們蓋住，看起來像「面板開了但沒有圖」。 */
    --adnotice-z-media:     9800;
}

/*
 * ⚠ !important 是必要的，不是偷懶。
 * 下面各 skin 都會設 .adnotice-float{display:flex}，類別選擇器的權重
 * 高於瀏覽器 UA 樣式的 [hidden]{display:none}。少了 !important，
 * 廣告會在 JS 判斷之前就顯示出來，而且是在快取頁上，測試環境不一定重現得出來。
 */
.adnotice-float[hidden] {
    display: none !important;
}

.adnotice-float {
    position: fixed;
    z-index: var(--adnotice-z-ad);
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: calc(100vw - 32px);
    box-sizing: border-box;
}

.adnotice-ad {
    position: relative;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .18);
    overflow: hidden;
    animation: adnotice-in .28s ease-out;
}

@media (prefers-reduced-motion: reduce) {
    .adnotice-ad { animation: none; }
}

@keyframes adnotice-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
}

.adnotice-body {
    padding: 20px;
}

.adnotice-body img {
    max-width: 100%;
    height: auto;
    display: block;
}

.adnotice-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.adnotice-close {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 1;
    width: 32px;
    height: 32px;
    padding: 0;
    line-height: 1;
    font-size: 22px;
    color: #333;
    background: rgba(255, 255, 255, .85);
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.adnotice-close:hover,
.adnotice-close:focus-visible {
    background: #fff;
    outline: 2px solid #666;
    outline-offset: 1px;
}

/* --- skin: default（右下角卡片） --- */
.adnotice-skin-default {
    right: 16px;
    bottom: 16px;
    width: 360px;
}

/* --- skin: corner（左下角小卡） --- */
.adnotice-skin-corner {
    left: 16px;
    bottom: 16px;
    width: 300px;
}

/* --- skin: bar（底部橫幅長條） --- */
.adnotice-skin-bar {
    left: 0;
    right: 0;
    bottom: 0;
    max-width: none;
}

.adnotice-skin-bar .adnotice-ad {
    border-radius: 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, .14);
}

.adnotice-skin-bar .adnotice-body {
    padding: 14px 56px 14px 20px;
    text-align: center;
}

/* --- skin: center（置中彈窗） ---
 * ⚠ 行動裝置上這是 Google 侵入式插頁廣告的典型樣態。
 *   後台已擋掉「顯示裝置含行動裝置 + center」的組合（ADR-6 第 2 條），
 *   這裡再加一層：真的到了小螢幕，退化成底部長條。
 */
.adnotice-skin-center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 440px;
}

@media (max-width: 767.98px) {
    .adnotice-skin-center {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        transform: none;
        width: auto;
        max-width: none;
    }

    .adnotice-skin-center .adnotice-ad {
        border-radius: 12px 12px 0 0;
    }

    .adnotice-skin-default,
    .adnotice-skin-corner {
        left: 12px;
        right: 12px;
        bottom: 12px;
        width: auto;
    }
}

/*
 * 同意橫幅顯示時往上讓位。
 * --adnotice-cc-h 由 cookieconsent.js 寫入（Phase 6），未定義時為 0。
 *
 * ⚠ 這個變數只准用來調整固定定位元件的 bottom / top，
 *   嚴禁拿去改 body 的 padding 或 margin —— 那會造成 CLS（規格 §13.4）。
 */
.adnotice-skin-default,
.adnotice-skin-corner {
    bottom: calc(16px + var(--adnotice-cc-h, 0px));
}

.adnotice-skin-bar {
    bottom: var(--adnotice-cc-h, 0px);
}

/* ---------------------------------------------------------------------------
 * 前台編輯（Phase 5）
 *
 * 編輯按鈕由 JS 在有權限時才插入，區塊的 HTML 輸出裡沒有它。
 * ------------------------------------------------------------------------- */

/* 整頁模式輸出 <a>、浮動視窗模式輸出 <button>，兩者外觀必須一致。
   <a> 預設是 inline、文字不置中、還會帶底線，所以這裡不能只靠 button 的預設值。 */
.adnotice-edit {
    position: absolute;
    top: 6px;
    right: 44px;          /* 讓開關閉鈕 */
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 32px;
    height: 32px;
    padding: 0;
    line-height: 1;
    font-size: 16px;
    text-decoration: none;
    color: #333;
    background: rgba(255, 255, 255, .85);
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.adnotice-edit:hover,
.adnotice-edit:focus-visible {
    background: #fff;
    outline: 2px solid #666;
    outline-offset: 1px;
}

/* --- iframe modal --- */

.adnotice-modal {
    position: fixed;
    inset: 0;
    z-index: var(--adnotice-z-edit);
    display: flex;
    align-items: center;
    justify-content: center;
}

.adnotice-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .45);
}

.adnotice-modal-panel {
    position: relative;
    width: min(920px, calc(100vw - 32px));
    height: min(720px, calc(100vh - 48px));
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .3);
    overflow: hidden;
}

.adnotice-modal-frame {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.adnotice-modal-close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1;
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 24px;
    line-height: 1;
    color: #333;
    background: rgba(255, 255, 255, .9);
    border: 1px solid #ddd;
    border-radius: 50%;
    cursor: pointer;
}

/* --- 媒體選擇器（在 edit.php 內以 iframe 開啟） --- */

.adnotice-media-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .4);
    z-index: var(--adnotice-z-media);
}

.adnotice-media-panel {
    position: fixed;
    inset: 24px;
    z-index: calc(var(--adnotice-z-media) + 1);
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .3);
}

.adnotice-media-panel iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.adnotice-media-close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1;
    width: 36px;
    height: 36px;
    font-size: 24px;
    line-height: 1;
    background: rgba(255, 255, 255, .9);
    border: 1px solid #ddd;
    border-radius: 50%;
    cursor: pointer;
}

.adnotice-media-grid {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.adnotice-media-grid .adnotice-media-choose {
    display: block;
    width: 100%;
    padding: 6px;
    text-align: left;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
}

.adnotice-media-grid .adnotice-media-choose:hover {
    border-color: #666;
}

.adnotice-media-grid img {
    width: 100%;
    height: 110px;
    object-fit: contain;
    background: #f6f6f6;
    display: block;
}

.adnotice-media-name,
.adnotice-media-dim {
    display: block;
    font-size: 12px;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.adnotice-media-dim { color: #777; }

.adnotice-media-upload {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 10px;
    background: #f7f7f7;
    border-radius: 8px;
}

.adnotice-media-hint {
    flex-basis: 100%;
    margin: 0;
    font-size: 12px;
    color: #777;
}
