/* =============================================================
 * ZippyLaptop Cookie Consent (ZPL-ADR-007 v1.1)
 *
 * 設計指針:
 *   - Pattern B: Accept All と Reject Non-Essential を完全同サイズ・同視認性
 *     (CNIL / ICO の「拒否は同階層・1 クリック」要求)
 *   - Manage Preferences はテキストリンクで可。
 *   - jp は CSS 自体ロードしない（PHP 側で enqueue をスキップ）。
 *   - 既存テーマの CSS 変数（--color-accent 等が無い場合に備えて fallback 値を持つ）。
 * =============================================================== */

/* ---- 共通: ZPL ブランドカラーのローカル変数 ---- */
.zpl-cookie-banner,
.zpl-cookie-panel,
.footer-cookie-preferences,
.footer-privacy-choices {
    --zpl-cc-accent: var(--brand-primary, #0066cc);
    --zpl-cc-accent-hover: #0052a3;
    --zpl-cc-text: #1f2933;
    --zpl-cc-text-soft: #4a5562;
    --zpl-cc-bg: #ffffff;
    --zpl-cc-bg-soft: #f4f6f9;
    --zpl-cc-border: #cfd5dd;
    /* Reject ボタン枠線専用: WCAG 1.4.11 Non-text Contrast 3:1 を満たす (#9ca7b3 ≒ 3.20:1 on #ffffff) */
    --zpl-cc-btn-border: #9ca7b3;
    --zpl-cc-shadow: 0 -4px 20px rgba(15, 23, 42, 0.18);
    --zpl-cc-radius: 10px;
    --zpl-cc-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* =============================================================
 * バナー本体（画面下部固定）
 * =============================================================== */
.zpl-cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    background: var(--zpl-cc-bg);
    color: var(--zpl-cc-text);
    border-top: 3px solid var(--zpl-cc-accent);
    box-shadow: var(--zpl-cc-shadow);
    padding: 20px 24px;
    font-family: var(--zpl-cc-font);
    animation: zpl-cookie-slideup 0.35s ease-out;
}

@keyframes zpl-cookie-slideup {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

.zpl-cookie-banner[hidden] { display: none !important; }

.zpl-cookie-banner__inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}

.zpl-cookie-banner__text {
    flex: 1 1 320px;
    min-width: 280px;
}

.zpl-cookie-banner__title {
    margin: 0 0 6px;
    font-size: 1.05em;
    font-weight: 700;
    color: var(--zpl-cc-text);
    line-height: 1.3;
}

.zpl-cookie-banner__desc {
    margin: 0;
    font-size: 0.9em;
    line-height: 1.55;
    color: var(--zpl-cc-text-soft);
}

.zpl-cookie-banner__actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

.zpl-cookie-banner__primary {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

/* =============================================================
 * ボタン: Accept / Reject / Save
 * Accept と Reject は CSS で「完全に同一サイズ」を保つこと（ADR v1.1 変更 3）。
 * =============================================================== */
.zpl-cookie-btn {
    /* 同サイズ要件: padding / font / line-height / min-width を完全に揃える */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 160px;
    padding: 12px 24px;
    border: 2px solid transparent;
    border-radius: 8px;
    font-family: var(--zpl-cc-font);
    font-size: 0.95em;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    white-space: nowrap;
    text-align: center;
}

.zpl-cookie-btn:focus-visible {
    outline: 3px solid var(--zpl-cc-accent);
    outline-offset: 2px;
}

/* Accept All: アクセントカラー */
.zpl-cookie-btn--accept {
    background: var(--zpl-cc-accent);
    color: #ffffff;
    border-color: var(--zpl-cc-accent);
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.30);
}
.zpl-cookie-btn--accept:hover {
    background: var(--zpl-cc-accent-hover);
    border-color: var(--zpl-cc-accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 102, 204, 0.40);
}

/* Reject Non-Essential: 白 + 枠線（同視認性: text contrast / size は accept と同等）
   枠線は WCAG 1.4.11 Non-text Contrast 3:1 を満たす濃色を使用 */
.zpl-cookie-btn--reject {
    background: #ffffff;
    color: var(--zpl-cc-text);
    border-color: var(--zpl-cc-btn-border);
}
.zpl-cookie-btn--reject:hover {
    background: var(--zpl-cc-bg-soft);
    border-color: var(--zpl-cc-text);
}

/* Save: 中間（パネル下部用）— ボタンとして同様に枠線コントラスト 3:1 を担保 */
.zpl-cookie-btn--save {
    background: var(--zpl-cc-bg-soft);
    color: var(--zpl-cc-text);
    border-color: var(--zpl-cc-btn-border);
}
.zpl-cookie-btn--save:hover {
    background: #e7eaef;
    border-color: var(--zpl-cc-text);
}

/* Manage Preferences はテキストリンクで OK */
.zpl-cookie-link {
    background: none;
    border: none;
    padding: 4px 8px;
    margin: 0;
    color: var(--zpl-cc-text);
    font-family: var(--zpl-cc-font);
    font-size: 0.88em;
    font-weight: 500;
    text-decoration: underline;
    cursor: pointer;
}
.zpl-cookie-link:hover {
    color: var(--zpl-cc-accent);
}
.zpl-cookie-link:focus-visible {
    outline: 2px solid var(--zpl-cc-accent);
    outline-offset: 2px;
}

/* =============================================================
 * Manage Preferences パネル（モーダル）
 * EU/UK と US の Your Privacy Choices で共用
 * =============================================================== */
.zpl-cookie-panel {
    position: fixed;
    inset: 0;
    z-index: 10001;
    font-family: var(--zpl-cc-font);
    color: var(--zpl-cc-text);
}
.zpl-cookie-panel[hidden] { display: none !important; }

.zpl-cookie-panel__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
}

.zpl-cookie-panel__dialog {
    position: relative;
    max-width: 560px;
    width: calc(100% - 32px);
    max-height: calc(100vh - 64px);
    margin: 32px auto 0;
    background: var(--zpl-cc-bg);
    border-radius: var(--zpl-cc-radius);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    outline: none;
}

.zpl-cookie-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--zpl-cc-border);
}

.zpl-cookie-panel__title {
    margin: 0;
    font-size: 1.1em;
    font-weight: 700;
}

.zpl-cookie-panel__close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.6em;
    line-height: 1;
    color: var(--zpl-cc-text-soft);
    padding: 4px 8px;
    border-radius: 4px;
}
.zpl-cookie-panel__close:hover { color: var(--zpl-cc-text); background: var(--zpl-cc-bg-soft); }
.zpl-cookie-panel__close:focus-visible {
    outline: 2px solid var(--zpl-cc-accent);
    outline-offset: 2px;
}

.zpl-cookie-panel__body {
    padding: 18px 20px;
    overflow-y: auto;
}

/* カテゴリ */
.zpl-cookie-category {
    padding: 14px 0;
    border-bottom: 1px solid var(--zpl-cc-border);
}
.zpl-cookie-category:last-child { border-bottom: none; }

.zpl-cookie-category__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}

.zpl-cookie-category__label {
    font-weight: 600;
    font-size: 0.98em;
    color: var(--zpl-cc-text);
}

.zpl-cookie-category__desc {
    margin: 0;
    font-size: 0.86em;
    line-height: 1.55;
    color: var(--zpl-cc-text-soft);
}

/* Locked indicator (Strictly Necessary) */
.zpl-cookie-category__toggle--locked {
    font-size: 0.78em;
    font-weight: 600;
    color: var(--zpl-cc-text-soft);
    background: var(--zpl-cc-bg-soft);
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--zpl-cc-border);
}

/* スイッチ */
.zpl-cookie-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.zpl-cookie-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.zpl-cookie-switch__track {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--zpl-cc-border);
    border-radius: 24px;
    transition: background-color 0.2s ease;
}
.zpl-cookie-switch__track::before {
    content: "";
    position: absolute;
    left: 3px;
    top: 3px;
    width: 18px;
    height: 18px;
    background: #ffffff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease;
}
.zpl-cookie-switch input:checked + .zpl-cookie-switch__track {
    background: var(--zpl-cc-accent);
}
.zpl-cookie-switch input:checked + .zpl-cookie-switch__track::before {
    transform: translateX(20px);
}
.zpl-cookie-switch input:focus-visible + .zpl-cookie-switch__track {
    outline: 2px solid var(--zpl-cc-accent);
    outline-offset: 2px;
}
.zpl-cookie-switch input:disabled + .zpl-cookie-switch__track {
    opacity: 0.6;
    cursor: not-allowed;
}

/* フッター */
.zpl-cookie-panel__footer {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--zpl-cc-border);
    justify-content: flex-end;
    background: var(--zpl-cc-bg-soft);
}
.zpl-cookie-panel__footer .zpl-cookie-btn {
    min-width: 140px;
    padding: 10px 18px;
    font-size: 0.9em;
}

/* =============================================================
 * フッター撤回リンク
 * =============================================================== */
.footer-cookie-preferences,
.footer-privacy-choices {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 16px;
    color: inherit;
    font-size: 0.86em;
    text-decoration: underline;
    opacity: 0.85;
}
.footer-cookie-preferences:hover,
.footer-privacy-choices:hover {
    opacity: 1;
    color: var(--zpl-cc-accent);
}

.footer-privacy-choices__icon {
    width: 30px;
    height: 14px;
    display: inline-block;
    vertical-align: middle;
}

/* =============================================================
 * レスポンシブ
 * =============================================================== */
@media (max-width: 768px) {
    .zpl-cookie-banner {
        padding: 12px 14px;
    }
    .zpl-cookie-banner__inner {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .zpl-cookie-banner__text {
        min-width: auto;
        flex: 0 0 auto;
    }
    .zpl-cookie-banner__title {
        font-size: 0.95em;
        margin-bottom: 4px;
    }
    .zpl-cookie-banner__desc {
        font-size: 0.82em;
        line-height: 1.45;
    }
    .zpl-cookie-banner__actions {
        align-items: stretch;
        gap: 6px;
    }
    .zpl-cookie-banner__primary {
        /* モバイルでも Accept と Reject は等幅 = flex-1 で完全同サイズを維持 */
        flex-direction: row;
        width: 100%;
        gap: 8px;
    }
    .zpl-cookie-banner__primary .zpl-cookie-btn {
        flex: 1 1 0;
        min-width: 0;
        padding: 9px 6px;
        font-size: 0.85em;
    }
    .zpl-cookie-link {
        align-self: center;
        font-size: 0.82em;
    }
    .zpl-cookie-panel__footer {
        flex-direction: column-reverse;
    }
    .zpl-cookie-panel__footer .zpl-cookie-btn {
        width: 100%;
    }
}
