/*
 * 論文ニュース 中川先生AIパネル
 *
 * 1.0.2（2026-10-02 山下さんの指摘・ゆゆ決定）:
 *   - 右端の「< AI」タブ → 左下の「（中川先生の顔）AIに質問する」ボタン（PC・スマホとも）
 *     大きさは参考サイト（新聞印刷.jp の「AIに質問」）と同じ高さ40px・文字16px・角丸15px
 *   - 押すと PC は右下に浮かぶ窓（端から10px・幅540×高さ764px が基準）、991px 以下は全画面
 *   - 窓の上部に「大きくする」（PC・会員のみ）と「最小化」。開いている間はボタンを隠す
 *   - 端をドラッグして大きさを変える機能は廃止
 * 1.0.0〜1.0.1 から引き継ぐもの:
 *   - すべてのセレクタを .ai-panel 配下に限定（テーマや他プラグインへ漏らさない）
 *   - 色は緑のグラデーション（#3DCBB1 → #2BA890）＋白文字、文字はサイトのフォントを受け継ぐ
 *   - WP 管理バー（body.admin-bar）が出ている時は、窓の上端を管理バーの下に収める
 *   - 開いている間（body.ronbun-ai-open）は右下の会員登録画像とスマホのメニューボタンを隠す
 *   - 未ログイン向けの案内（.ai-panel-guest）、中川先生のアイコン
 *   - 案内のボタン（<a>）はテーマの a:hover { opacity:0.5 } を受けないよう、hover 時も opacity:1 に固定
 */

.ai-panel,
.ai-panel *,
.ai-panel *::before,
.ai-panel *::after {
    box-sizing: border-box;
}

/* 外枠は入れ物だけ（ボタンと窓はそれぞれ画面に固定） */
.ai-panel {
    position: static;
}

/* ---------- 左下のボタン ---------- */

.ai-panel .ai-panel-toggle {
    position: fixed;
    left: 25px;
    bottom: 50px;
    z-index: 10000;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    min-height: 0;
    width: auto;
    margin: 0;
    padding: 0 16px 0 7px;
    border: none !important;
    border-radius: 15px;
    background: linear-gradient(135deg, #3DCBB1, #2BA890) !important; /* テーマの button の高特異性ルールに負けないよう !important */
    color: #fff !important;
    font-family: inherit;
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    letter-spacing: 0.02em;
    text-transform: none;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.22), 0 3px 6px rgba(0, 0, 0, 0.12);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-panel .ai-panel-toggle:hover {
    background: linear-gradient(135deg, #2BA890, #239078) !important;
    transform: translateY(-2px);
    box-shadow: 0 14px 26px rgba(0, 0, 0, 0.26), 0 4px 8px rgba(0, 0, 0, 0.14);
}

.ai-panel .ai-panel-toggle:focus-visible {
    outline: 3px solid #1c7a67;
    outline-offset: 3px;
}

.ai-panel .ai-panel-toggle-icon {
    display: block;
    flex: none;
    width: 26px;
    height: 26px;
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    object-fit: cover;
    background: #fbf4e9;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.ai-panel .ai-panel-toggle-label {
    display: block;
    color: #fff;
}

/* 開いている間はボタンを隠す（窓の「最小化」で戻る） */
.ai-panel.open .ai-panel-toggle {
    display: none;
}

/* ---------- 窓（PC は右下に浮かぶ） ---------- */

.ai-panel .ai-panel-content {
    position: fixed;
    right: 10px;
    bottom: 10px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    width: min(540px, calc(100vw - 20px));
    height: min(764px, calc(100vh - 20px));
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28), 0 2px 8px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(16px) scale(0.98);
    transform-origin: right bottom;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s, width 0.25s ease, height 0.25s ease;
}

.ai-panel.open .ai-panel-content {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0s, width 0.25s ease, height 0.25s ease;
}

/* 大きくした時（PC・会員のみ） */
.ai-panel.expanded .ai-panel-content {
    width: min(960px, calc(100vw - 20px));
    height: calc(100vh - 20px);
}

/* 未ログインの案内は中身に合わせた高さ */
.ai-panel.ai-panel--guest .ai-panel-content {
    height: auto;
    max-height: calc(100vh - 20px);
}

.ai-panel .ai-panel-content iframe {
    display: block;
    flex: 1;
    min-height: 0;
    width: 100%;
    margin: 0;
    border: none;
}

/* ---------- 窓の上部 ---------- */

.ai-panel .ai-panel-header {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    padding: 0 8px 0 16px;
    background: linear-gradient(135deg, #3DCBB1, #2BA890);
    color: #fff;
}

.ai-panel .ai-panel-title {
    margin: 0;
    color: #fff;
    font-size: 15px;
    font-weight: bold;
    line-height: 1.2;
    letter-spacing: 0.02em;
}

.ai-panel .ai-panel-controls {
    display: flex;
    align-items: center;
    gap: 2px;
}

.ai-panel .ai-panel-control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: none !important;
    border-radius: 6px;
    background: transparent !important;
    box-shadow: none;
    color: #fff !important;
    line-height: 1;
    cursor: pointer;
    opacity: 0.9;
    transition: background-color 0.15s ease, opacity 0.15s ease;
}

.ai-panel .ai-panel-control:hover {
    background: rgba(255, 255, 255, 0.2) !important;
    opacity: 1;
}

.ai-panel .ai-panel-control:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 1px;
    opacity: 1;
}

.ai-panel .ai-panel-control svg {
    display: block;
    width: 18px;
    height: 18px;
}

.ai-panel .ai-panel-icon-shrink {
    display: none !important;
}

.ai-panel.expanded .ai-panel-icon-expand {
    display: none !important;
}

.ai-panel.expanded .ai-panel-icon-shrink {
    display: block !important;
}

/* ---------- 未ログイン向けの案内 ---------- */

.ai-panel .ai-panel-guest {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 36px 28px 32px;
    background: #fff;
    color: #333;
    text-align: center;
}

.ai-panel .ai-panel-guest-inner {
    width: 100%;
    max-width: 340px;
}

/* 中川先生のアイコン（assets/nakagawa-sensei.jpg・160px を 80px で表示） */
.ai-panel .ai-panel-guest-icon {
    display: block;
    width: 80px;
    height: 80px;
    max-width: none;
    margin: 0 auto 18px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    object-fit: cover;
    background: #fbf4e9;
    box-shadow: 0 0 0 3px #e3f6f1, 0 2px 8px rgba(0, 0, 0, 0.12);
}

.ai-panel .ai-panel-guest-text {
    margin: 0 0 24px;
    padding: 0;
    color: #333;
    font-size: 15px;
    line-height: 1.8;
    text-align: center;
}

.ai-panel .ai-panel-guest-actions {
    margin: 0;
    padding: 0;
}

.ai-panel .ai-panel-guest-btn {
    display: block;
    width: 100%;
    margin: 0;
    padding: 12px 16px;
    border-radius: 999px;
    font-size: 15px;
    font-weight: bold;
    line-height: 1.4;
    text-align: center;
    text-decoration: none !important;
    cursor: pointer;
    transition: background-color 0.2s ease, opacity 0.2s ease;
}

/* テーマの a:hover { opacity: 0.5 } を打ち消す */
.ai-panel .ai-panel-guest-btn:hover {
    opacity: 1;
}

.ai-panel .ai-panel-guest-btn + .ai-panel-guest-btn {
    margin-top: 12px;
}

.ai-panel .ai-panel-guest-btn--primary {
    background: #1c7a67;
    border: 2px solid #1c7a67;
    color: #fff !important;
}

.ai-panel .ai-panel-guest-btn--primary:hover {
    background: #16604f;
    border-color: #16604f;
}

.ai-panel .ai-panel-guest-btn--secondary {
    background: #fff;
    border: 2px solid #3DCBB1;
    color: #1c7a67 !important;
}

.ai-panel .ai-panel-guest-btn--secondary:hover {
    background: #effaf7;
}

.ai-panel .ai-panel-guest-btn:focus-visible {
    outline: 2px solid #1c7a67;
    outline-offset: 2px;
}

/* ---------- WP 管理バーが出ている時（主に管理者） ---------- */

@media (min-width: 783px) {
    body.admin-bar .ai-panel .ai-panel-content {
        height: min(764px, calc(100vh - 52px));
    }
    body.admin-bar .ai-panel.expanded .ai-panel-content {
        height: calc(100vh - 52px);
    }
    body.admin-bar .ai-panel.ai-panel--guest .ai-panel-content {
        height: auto;
        max-height: calc(100vh - 52px);
    }
}

/* ---------- タブレット・スマホ（991px 以下）: ボタンは左下、窓は全画面 ---------- */

@media (max-width: 991px) {
    /* スマホは少しだけ詰める（高さ40pxは同じ）。右下の会員登録画像（未ログイン時）と横に並ぶため、
       幅360pxでも重ならないようにしている（2026-10-02 本番で 360/375/393/414/430px を実測） */
    .ai-panel .ai-panel-toggle {
        left: 10px;
        bottom: 16px;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        gap: 6px;
        padding: 0 12px 0 6px;
        font-size: 14px;
    }
    .ai-panel .ai-panel-toggle-icon {
        width: 24px;
        height: 24px;
    }
    .ai-panel .ai-panel-content,
    .ai-panel.expanded .ai-panel-content,
    .ai-panel.ai-panel--guest .ai-panel-content {
        top: 10px;
        left: 10px;
        right: 10px;
        bottom: 10px;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        width: auto;
        height: auto;
        max-height: none;
        border-radius: 12px;
        transform: translateY(12px);
        transform-origin: center bottom;
    }
    .ai-panel.open .ai-panel-content {
        transform: none;
    }
    /* 全画面なので「大きくする」は出さない */
    .ai-panel .ai-panel-expand {
        display: none !important;
    }
    body.admin-bar .ai-panel .ai-panel-content,
    body.admin-bar .ai-panel.expanded .ai-panel-content,
    body.admin-bar .ai-panel.ai-panel--guest .ai-panel-content {
        top: 42px;
        height: auto;
        max-height: none;
    }
}

/* 幅360px未満のとても小さい画面では、未ログイン時だけボタンを会員登録画像の上に逃がす */
@media (max-width: 359px) {
    .ai-panel.ai-panel--guest .ai-panel-toggle {
        bottom: 110px;
        bottom: calc(110px + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 782px) {
    body.admin-bar .ai-panel .ai-panel-content,
    body.admin-bar .ai-panel.ai-panel--guest .ai-panel-content {
        top: 56px;
    }
}

/* 動きを減らす設定の人にはアニメーションを付けない */
@media (prefers-reduced-motion: reduce) {
    .ai-panel .ai-panel-toggle,
    .ai-panel .ai-panel-content,
    .ai-panel.open .ai-panel-content {
        transition: none;
    }
}

/* ---------- 開いている間は、窓と重なるサイトの固定要素を隠す ---------- */

body.ronbun-ai-open .st-float-cta,
body.ronbun-ai-open #vk-mobile-nav-menu-btn {
    display: none !important;
}
