:root{
    --qa-main:#2b4c7e;
    --qa-main-dark:#1f365a;
    --qa-bg:#f2f4f8;
    --qa-panel:#ffffff;
    --qa-bot-bg:#ffffff;
    --qa-user-bg:#2b4c7e;
    --qa-border:#d0d7e2;
    --qa-text:#263238;
    --qa-sub:#5c6675;
    --qa-choice-bg:#e6edf7;
    --qa-choice-hover:#2b4c7e;
    --qa-danger:#b42318;
    --qa-focus:#111827;
}

*{ box-sizing:border-box; }

body{
    margin:0;
    font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans JP",sans-serif;
    color:var(--qa-text);
}

.qa-chat-wrap{
    background:var(--qa-panel);
    border-radius:18px;
    overflow:hidden;
    box-shadow:0 12px 32px rgba(23,39,63,0.14);
    display:flex;
    flex-direction:column;
}

.qa-chat-header{
    background:linear-gradient(135deg, var(--qa-main), var(--qa-main-dark));
    color:#fff;
    padding:16px 20px;
    display:flex;
    flex:0 0 auto;
    align-items:center;
    justify-content:space-between;
    gap:16px;
    position:relative;
    z-index:10;
}

.qa-chat-title{
    font-size:20px;
    font-weight:700;
    margin:0;
    line-height:1.4;
}

.qa-header-actions{
    display:flex;
    gap:8px;
    align-items:center;
}

.qa-header-button{
    border:1px solid rgba(255,255,255,0.5);
    background:rgba(255,255,255,0.12);
    color:#fff;
    padding:8px 12px;
    border-radius:999px;
    cursor:pointer;
    font-size:13px;
    min-height:44px;
    touch-action:manipulation;
}

.qa-return-link{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    text-decoration:none;
    white-space:nowrap;
}

.qa-header-button:hover{
    background:rgba(255,255,255,0.24);
}

.qa-header-button:focus-visible{
    background:rgba(255,255,255,0.24);
    outline:3px solid #ffbf47;
    outline-offset:2px;
}

.qa-chat-body{
    flex:1 1 auto;
    min-height:0;
    padding:20px;
    overflow-y:auto;
    overscroll-behavior:contain;
    -webkit-overflow-scrolling:touch;
    background:#eef2f7;
}

.qa-message{
    display:flex;
    align-items:flex-start;
    gap:12px;
    margin-bottom:16px;
}

.qa-message.qa-user{
    justify-content:flex-end;
}

.qa-message.qa-bot{
    justify-content:flex-start;
}

.qa-avatar{
    border-radius:50%;
    display:block;
    object-fit:cover;
    background:#fff;
    border:1px solid var(--qa-border);
}

.qa-bot .qa-avatar{
    width:58px;
    height:58px;
    flex:0 0 58px;
}

.qa-user .qa-avatar{
    width:40px;
    height:40px;
    flex:0 0 40px;
}

.qa-message-content{
    max-width:74%;
    display:flex;
    flex-direction:column;
    align-items:flex-start;
}

.qa-message-content:focus{
    outline:3px solid var(--qa-focus);
    outline-offset:4px;
    border-radius:18px;
}

.qa-user .qa-message-content{
    align-items:flex-end;
}

.qa-bubble{
    padding:12px 16px;
    border-radius:18px;
    line-height:1.65;
    word-break:break-word;
    white-space:pre-line;
    font-size:15px;
}

.qa-bot .qa-bubble{
    background:var(--qa-bot-bg);
    border:1px solid var(--qa-border);
    border-bottom-left-radius:5px;
}

.qa-user .qa-bubble{
    background:var(--qa-user-bg);
    color:#fff;
    border-bottom-right-radius:5px;
}

.qa-bubble a{
    color:#1f5fbf;
    font-weight:700;
    text-decoration:underline;
    text-underline-offset:3px;
}

.qa-bubble a:focus-visible{
    outline:3px solid var(--qa-focus);
    outline-offset:3px;
    border-radius:3px;
}

.qa-choice-block{
    display:flex;
    align-items:flex-start;
    gap:8px;
    margin-top:8px;
    max-width:100%;
}

.qa-choice-mark{
    flex:0 0 auto;
    width:28px;
    min-height:28px;
    border-radius:999px;
    display:flex;
    align-items:center;
    justify-content:center;
    background:var(--qa-main);
    color:#fff;
    font-size:13px;
    font-weight:700;
    line-height:1;
    margin-top:4px;
}

.qa-choice-list{
    display:flex;
    flex-wrap:wrap;
    gap:8px;
    max-width:100%;
}

.qa-choice-btn{
    border:1px solid transparent;
    background:var(--qa-choice-bg);
    color:var(--qa-main);
    padding:9px 13px;
    border-radius:999px;
    cursor:pointer;
    transition:background 0.2s, color 0.2s, border-color 0.2s, transform 0.1s;
    font-size:14px;
    line-height:1.4;
    text-align:left;
    min-height:44px;
    touch-action:manipulation;
}

.qa-choice-btn:hover{
    background:var(--qa-choice-hover);
    color:#fff;
}

.qa-choice-btn:focus-visible{
    background:var(--qa-choice-hover);
    color:#fff;
    outline:3px solid var(--qa-focus);
    outline-offset:2px;
}

.qa-choice-btn:active{
    transform:translateY(1px);
}

.qa-choice-btn:disabled{
    cursor:default;
    opacity:0.55;
}

.qa-choice-btn.qa-restart-btn{
    background:#fff2f2;
    color:var(--qa-danger);
    border-color:#f2c7c7;
}

.qa-choice-btn.qa-restart-btn:hover{
    background:var(--qa-danger);
    color:#fff;
}

.qa-choice-btn.qa-restart-btn:focus-visible{
    background:var(--qa-danger);
    color:#fff;
    outline:3px solid var(--qa-focus);
    outline-offset:2px;
}

.qa-typing .qa-bubble{
    color:var(--qa-sub);
}

.qa-dots::after{
    content:"";
    display:inline-block;
    width:1.4em;
    text-align:left;
    animation:qa-dots 1.2s steps(4,end) infinite;
}

@keyframes qa-dots{
    0%{content:"";}
    25%{content:".";}
    50%{content:"..";}
    75%,100%{content:"...";}
}

/* 単独ページ版 */
.qa-page-bg{
    background:var(--qa-bg);
    height:100vh;
    height:100dvh;
    overflow:hidden;
}

.qa-skip-link{
    position:fixed;
    top:8px;
    left:8px;
    z-index:2000;
    padding:10px 14px;
    border-radius:6px;
    background:#fff;
    color:#111827;
    font-weight:700;
    transform:translateY(-150%);
}

.qa-skip-link:focus{
    transform:translateY(0);
    outline:3px solid var(--qa-focus);
    outline-offset:2px;
}

.qa-noscript{
    width:min(700px, calc(100% - 24px));
    margin:24px auto;
    padding:16px;
    border:2px solid var(--qa-danger);
    background:#fff2f2;
    color:#6f120c;
}

.qa-single-wrap{
    width:min(700px, calc(100% - 24px));
    height:min(85vh, 760px);
    height:min(85dvh, 760px);
    min-height:0;
    max-height:calc(100vh - 48px);
    max-height:calc(100dvh - 48px);
    margin:24px auto;
}

/* 埋め込み版 */
.qa-embed-page{
    background:#fff;
}

.qa-content{
    width:min(960px, calc(100% - 32px));
    margin:32px auto;
    line-height:1.8;
}

.qa-embedded-wrap{
    width:100%;
    height:620px;
    margin:24px 0;
}

/* 右下フローティング版 */
.qa-floating-page{
    min-height:100vh;
    background:linear-gradient(180deg,#f8fafc,#eef2f7);
}

.qa-floating-demo-content{
    width:min(960px, calc(100% - 32px));
    margin:48px auto;
    line-height:1.8;
}

.qa-floating-launcher{
    position:fixed;
    right:24px;
    bottom:24px;
    z-index:1000;
    border:none;
    border-radius:999px;
    padding:14px 18px;
    background:var(--qa-main);
    color:#fff;
    font-weight:700;
    cursor:pointer;
    box-shadow:0 10px 28px rgba(23,39,63,0.24);
    min-height:44px;
    touch-action:manipulation;
}

.qa-floating-launcher:hover{
    background:var(--qa-main-dark);
}

.qa-floating-launcher:focus-visible{
    background:var(--qa-main-dark);
    outline:3px solid var(--qa-focus);
    outline-offset:2px;
}

/*
 フローティング版は、あらかじめチャット枠の縦横サイズを固定します。
 メッセージが増えてもパネル自体は伸びず、履歴部分だけがスクロールします。
*/
.qa-floating-panel{
    position:fixed;
    right:24px;
    bottom:88px;
    z-index:1000;
    width:380px;
    height:560px;
    max-width:calc(100vw - 32px);
    max-height:calc(100vh - 120px);
    max-height:calc(100svh - 120px);
    overflow:hidden;
    transform:translateY(22px) scale(0.98);
    opacity:0;
    pointer-events:none;
    transition:transform 0.24s ease, opacity 0.24s ease;
}

.qa-floating-panel.is-open{
    transform:translateY(0) scale(1);
    opacity:1;
    pointer-events:auto;
}

.qa-floating-panel #qaChat,
.qa-floating-panel .qa-chat-wrap{
    width:100%;
    height:100%;
    max-height:100%;
    min-height:0;
}

.qa-floating-panel .qa-chat-wrap{
    display:flex;
    flex-direction:column;
    overflow:hidden;
}

.qa-floating-panel .qa-chat-header{
    flex:0 0 auto;
}

.qa-floating-panel .qa-chat-title{
    font-size:17px;
}

.qa-floating-panel .qa-chat-body{
    flex:1 1 auto;
    min-height:0;
    overflow-y:auto;
    overscroll-behavior:contain;
    -webkit-overflow-scrolling:touch;
}

@media (max-width:520px){
    .qa-single-wrap{
        width:100%;
        height:100vh;
        height:100dvh;
        min-height:0;
        max-height:none;
        margin:0;
        border-radius:0;
    }

    .qa-chat-header{
        flex-wrap:wrap;
        gap:8px;
        padding:12px;
    }

    .qa-chat-title{
        flex:1 1 100%;
        font-size:18px;
    }

    .qa-header-actions{
        display:grid;
        grid-template-columns:minmax(0, 1fr) auto;
        width:100%;
    }

    .qa-header-button{
        padding:8px 10px;
    }

    .qa-chat-body{
        padding:16px 12px;
    }

    .qa-message-content{
        max-width:82%;
    }

    .qa-choice-block{
        align-items:flex-start;
    }

    .qa-choice-list{
        flex-direction:column;
        align-items:stretch;
        flex:1;
    }

    .qa-choice-btn{
        width:100%;
    }

    .qa-floating-launcher{
        right:16px;
        bottom:16px;
    }

    .qa-floating-panel{
        right:12px;
        bottom:76px;
        width:calc(100vw - 24px);
        height:520px;
        max-height:calc(100vh - 100px);
        max-height:calc(100svh - 100px);
    }
}

@media (prefers-reduced-motion:reduce){
    *,
    *::before,
    *::after{
        animation-duration:0.01ms !important;
        animation-iteration-count:1 !important;
        transition-duration:0.01ms !important;
    }

    .qa-dots::after{
        animation:none;
        content:"...";
    }
}

@media (forced-colors:active){
    .qa-header-button,
    .qa-choice-btn,
    .qa-bubble,
    .qa-avatar{
        border:1px solid ButtonText;
    }

    .qa-choice-btn:focus-visible,
    .qa-header-button:focus-visible,
    .qa-bubble a:focus-visible,
    .qa-message-content:focus{
        outline:3px solid Highlight;
    }
}

/* アイコン画像なしパターン */
.qa-no-avatar .qa-avatar{
    display:none;
}

.qa-no-avatar .qa-message{
    gap:0;
}

.qa-no-avatar .qa-message-content{
    max-width:86%;
}

/* 選択肢を画面下部に固定 */
.qa-fixed-choice .qa-chat-wrap{
    position:relative;
}

.qa-fixed-choice .qa-chat-body{
    padding-bottom:96px;
}

.qa-fixed-choice .qa-choice-block{
    position:sticky;
    bottom:0;
    z-index:5;
}

.qa-fixed-choice-area{
    flex:0 0 auto;
    border-top:none;
	box-shadow:0 -8px 18px rgba(103,58,183,0.06);
    background:#fff;
}

.qa-choice-bottom-mode .qa-fixed-choice-area{
    padding:6px 12px 12px;
    max-height:min(42dvh, 340px);
    overflow-y:auto;
    overscroll-behavior:contain;
    -webkit-overflow-scrolling:touch;
}

.qa-choice-bottom-mode .qa-fixed-choice-area .qa-choice-block{
    position:static;
}
