/* ==========================================================================
   Repure AI Chatbot Front Styles (Theme Independent & Auto-height)
   ========================================================================== */

/* ★ 強制リセット：テーマの干渉をすべてブロックします */
.rai-wrapper, .rai-wrapper * { 
    box-sizing: border-box !important; 
}
.rai-wrapper { 
    font-family: 'Noto Sans JP', sans-serif; 
}

/* Inline Container */
.rai-inline-container { 
    max-width: 400px; 
    margin: 20px auto; 
    border: 1px solid #e2e8f0; 
    border-radius: 12px; 
    overflow: hidden; 
    box-shadow: 0 10px 25px rgba(0,0,0,0.05); 
    background: #fff !important; 
    display: flex;
    flex-direction: column;
    /* 高さは中身に依存させる（同意画面ではぴったりに） */
}

/* Floating Container */
.rai-floating-container { 
    position: fixed; 
    bottom: 90px; 
    right: 20px; 
    z-index: 2147483647; 
    width: 360px; 
    max-width: calc(100% - 40px); 
    border-radius: 16px; 
    overflow: hidden; 
    box-shadow: 0 10px 40px rgba(0,0,0,0.2); 
    background: #fff !important; 
    display: none; 
    opacity: 0; 
    transform: translateY(20px); 
    transition: all 0.3s ease; 
    flex-direction: column;
}
.rai-floating-container.show { 
    display: flex !important; 
    opacity: 1; 
    transform: translateY(0); 
}

/* Toggle Button */
.rai-toggle-btn { 
    position: fixed; 
    bottom: 20px; 
    right: 20px; 
    z-index: 2147483647; 
    background: var(--repure-ai-main) !important; 
    border: none; 
    cursor: pointer; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.2); 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    color: #fff !important; 
    transition: 0.3s; 
    gap: 8px; 
    padding: 0;
}
.rai-toggle-btn:hover { transform: scale(1.05); }
.rai-toggle-btn.is-icon-only { width: 60px; height: 60px; border-radius: 50%; font-size: 30px; }
.rai-toggle-btn.is-text { height: 50px; padding: 0 20px 0 15px; border-radius: 25px; font-size: 15px; font-weight: bold; }
.rai-toggle-icon { display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; font-size: 20px; }
.rai-toggle-btn.is-icon-only .rai-toggle-icon { width: 40px; height: 40px; }

/* Header & Close */
.rai-close-header { 
    background: var(--repure-ai-main) !important; 
    color: #fff !important; 
    padding: 12px 15px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    font-weight: bold; 
    font-size: 14px; 
    flex-shrink: 0; 
}
.rai-close-btn { background: none; border: none; color: #fff !important; font-size: 20px; cursor: pointer; line-height: 1; padding: 0; margin: 0; }

/* Screens */
.rai-consent-screen { 
    padding: 30px 20px; 
    text-align: center; 
    background: #f8fafc !important; 
    display: flex; 
    flex-direction: column; 
    justify-content: center; 
}
.rai-consent-icon { font-size: 40px; width: 60px; height: 60px; margin: 0 auto 15px; border-radius: 50%; background: #fff !important; box-shadow: 0 4px 10px rgba(0,0,0,0.05); display: flex; align-items: center; justify-content: center; }
.rai-consent-title { margin: 0 0 15px 0; color: #0f172a; font-weight: 900; }
.rai-consent-text { font-size: 13px; color: #475569; text-align: left; line-height: 1.6; margin-bottom: 20px; }

/* ★ 修正：チャット画面展開時にだけ高さを押し広げる */
.rai-chatbox-screen { 
    display: flex;
    flex-direction: column; 
    background: #f8fafc !important; 
    width: 100%;
}
.rai-inline-container .rai-chatbox-screen {
    height: 500px;
    max-height: 70vh;
}
.rai-floating-container .rai-chatbox-screen {
    height: 450px;
    max-height: calc(100vh - 160px);
}

.rai-history { 
    flex: 1; 
    padding: 20px; 
    overflow-y: auto; 
    font-size: 14px; 
    line-height: 1.6; 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    position: relative; 
    min-height: 0; 
}

/* Messages */
.rai-msg-row { display: flex; gap: 10px; align-items: flex-start; margin-right: 30px; }
.rai-msg-user-row { justify-content: flex-end; margin-left: 30px; margin-right: 0; }
.rai-msg-icon { width: 30px; height: 30px; border-radius: 50%; background: var(--repure-ai-main) !important; color: #fff !important; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.rai-msg-icon.loading-icon { background: #cbd5e1 !important; }
.rai-msg-bubble { background: #fff !important; padding: 12px 16px; border-radius: 0 12px 12px 12px; border: 1px solid #e2e8f0; color: #334155; box-shadow: 0 2px 4px rgba(0,0,0,0.02); width: 100%; overflow-x: auto; }
.rai-msg-user { background: var(--repure-ai-main) !important; color: #fff !important; padding: 10px 16px; border-radius: 12px 0 12px 12px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); text-align: left; width: auto; border: none; }

/* Suggests & Inputs */
.rai-suggestions-wrapper { padding: 0 15px 10px; background: #fff !important; display: flex; flex-wrap: wrap; gap: 8px; flex-shrink: 0; }
.rai-input-wrapper { padding: 15px; background: #fff !important; border-top: 1px solid #e2e8f0; display: flex; flex-shrink: 0; align-items: center; }
.rai-input { flex: 1; padding: 10px 15px; border: 1px solid #cbd5e1; border-radius: 50px; font-size: 16px; outline: none; margin: 0; height: 44px; line-height: 1.4; }

/* Markdown Formatting */
.rai-history h3 { font-size: 15px; margin: 15px 0 5px; color: #0f172a; border-bottom: 1px solid #e2e8f0; padding-bottom: 3px; }
.rai-history p { margin: 0 0 10px; }
.rai-history ul, .rai-history ol { padding-left: 20px; margin: 0 0 10px; }
.rai-history strong { color: var(--repure-ai-main); }
.rai-history table { width: 100%; border-collapse: collapse; margin-bottom: 15px; font-size: 12px; }
.rai-history th, .rai-history td { border: 1px solid #cbd5e1; padding: 6px; text-align: left; }
.rai-history th { background: #f1f5f9 !important; font-weight: bold; }

/* Buttons */
.rai-btn { background: var(--repure-ai-main) !important; color: #fff !important; border: none; border-radius: 50px; cursor: pointer; font-weight: bold; transition: 0.2s; }
.rai-btn-start { padding: 15px 20px; width: 100%; font-size: 15px; }
.rai-send-btn { padding: 0 20px; margin-left: 10px; height: 44px; display: flex; align-items: center; justify-content: center; }
.rai-btn:hover { opacity: 0.85; transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,0.15); }
.rai-btn:disabled { background: #94a3b8 !important; cursor: not-allowed; transform: none; box-shadow: none; }

.rai-suggest { background: #f1f5f9 !important; color: var(--repure-ai-main) !important; border: 1px solid var(--repure-ai-main); padding: 5px 12px; border-radius: 20px; font-size: 12px; cursor: pointer; transition: 0.2s; white-space: nowrap; margin-bottom: 5px; }
.rai-suggest:hover { background: var(--repure-ai-main) !important; color: #fff !important; }

/* Escalation Box */
.esc-box { background: #f1f5f9 !important; padding: 15px; border-radius: 8px; border: 1px solid #cbd5e1; margin-bottom: 15px; text-align: center; width: 100%; }
.esc-box p { margin: 0 0 10px; font-size: 13px; color: #334155; font-weight: bold; }
.esc-box-btns { display: flex; justify-content: center; gap: 10px; }
.esc-btn-yes { background: #fff !important; border: 1px solid var(--repure-ai-main); color: var(--repure-ai-main) !important; padding: 6px 15px; border-radius: 20px; cursor: pointer; font-size: 12px; font-weight: bold; }
.esc-btn-no { background: var(--repure-ai-main) !important; border: none; color: #fff !important; padding: 6px 15px; border-radius: 20px; cursor: pointer; font-size: 12px; font-weight: bold; }
.esc-btn-link { background: var(--repure-ai-main) !important; color: #fff !important; text-decoration: none; padding: 6px 15px; border-radius: 20px; font-size: 12px; font-weight: bold; display:inline-block; }
.esc-btn-continue { background: #fff !important; border: 1px solid #cbd5e1; color: #64748b !important; padding: 6px 15px; border-radius: 20px; cursor: pointer; font-size: 12px; }

/* =========================================================
   スマホ用調整（ボトムメニューとの被り回避）
   ========================================================= */
@media screen and (max-width: 768px) {
    /* 起動ボタンを、下から 80px の位置に持ち上げる（Cocoonのモバイルボタン回避） */
    .rai-toggle-btn {
        bottom: 60px !important;
    }
}