:root { --primary-color: #0084ff; --primary-color-light: #e7f3ff; }

html, body { height: 100%; margin: 0; background: transparent; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }

/* ウィジェット全体のルート。埋め込み先ページの上に浮かせるため、
   バブル/パネル以外の領域はクリックを透過させる（pointer-events:none）。
   埋め込み側はこのiframe自体を position:fixed で画面隅に固定して使うことを想定 */
.widget-root { position: fixed; inset: 0; pointer-events: none; }

.chat-bubble {
    position: fixed;
    width: 60px; height: 60px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    pointer-events: auto;
    z-index: 2;
}
.chat-bubble svg { width: 28px; height: 28px; }
.chat-bubble.hidden { display: none; }

.chat-panel {
    position: fixed;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 110px);
    display: none;
    pointer-events: auto;
    z-index: 3;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
    overflow: hidden;
}
.chat-panel.open { display: block; }

.chat-container { width: 100%; height: 100%; background: white; display: flex; flex-direction: column; }
.chat-header { padding: 15px; background: var(--primary-color); color: white; font-weight: bold; display: flex; align-items: center; justify-content: space-between; }
.chat-close-btn { background: none; border: none; color: white; font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }
.chat-box { flex: 1; padding: 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.message { max-width: 75%; padding: 10px 15px; border-radius: 15px; font-size: 15px; line-height: 1.4; white-space: pre-wrap; }
.user { align-self: flex-end; background: var(--primary-color); color: white; border-bottom-right-radius: 2px; }
.bot { align-self: flex-start; background: #e4e6eb; color: black; border-bottom-left-radius: 2px; }
.error { align-self: center; background: #ffeef0; color: #ff3b30; font-size: 13px; border-radius: 5px; }
.bot a { color: var(--primary-color); }
.error a { color: #ff3b30; text-decoration: underline; }
.loading { align-self: flex-start; background: #f0f2f5; color: #8e8e93; font-style: italic; }
.suggestions-area { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
.suggestion-chip { background: var(--primary-color-light); color: var(--primary-color); border: 1px solid var(--primary-color); padding: 6px 12px; border-radius: 20px; font-size: 13px; cursor: pointer; transition: all 0.2s; }
.suggestion-chip:hover { background: var(--primary-color); color: white; }
.input-area { padding: 15px; border-top: 1px solid #e4e6eb; display: flex; gap: 10px; }
input { flex: 1; padding: 10px; border: 1px solid #ccd0d5; border-radius: 20px; outline: none; font-size: 15px; }
button { background: var(--primary-color); color: white; border: none; padding: 0 20px; border-radius: 20px; cursor: pointer; font-weight: bold; }
button:disabled { background: #b0cbd6; cursor: not-allowed; }

/* PC表示スタイル（pc_style。JS側で pc-style-0/1/2 をwidget-rootに付与する） */
/* 0: 右下バブル */
.pc-style-0 .chat-bubble { right: 20px; bottom: 20px; }
.pc-style-0 .chat-panel { right: 20px; bottom: 90px; }
/* 1: 左下バブル */
.pc-style-1 .chat-bubble { left: 20px; bottom: 20px; }
.pc-style-1 .chat-panel { left: 20px; bottom: 90px; }
/* 2: 右側フルハイトパネル */
.pc-style-2 .chat-bubble { right: 20px; bottom: 20px; }
.pc-style-2 .chat-panel { right: 0; top: 0; bottom: 0; height: 100vh; max-height: 100vh; width: 400px; border-radius: 0; }

/* SP表示スタイル（sp_style）。モバイル幅でのみ pc-style-* を上書きする */
@media (max-width: 768px) {
    .chat-panel { width: calc(100vw - 20px); }

    /* 0: 下部バブル（右下） */
    .sp-style-0 .chat-bubble { right: 16px; bottom: 16px; }
    .sp-style-0 .chat-panel { right: 10px; bottom: 84px; }
    /* 1: 上部バブル（右上） */
    .sp-style-1 .chat-bubble { right: 16px; bottom: auto; top: 16px; }
    .sp-style-1 .chat-panel { right: 10px; bottom: auto; top: 76px; height: calc(100vh - 100px); }
    /* 2: フルスクリーン */
    .sp-style-2 .chat-bubble { right: 16px; bottom: 16px; }
    .sp-style-2 .chat-panel { top: 0; left: 0; right: 0; bottom: 0; width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh; border-radius: 0; }
}

/* ダイレクトモード（/{タグ値}/card または /{タグ値} で直接アクセスした場合）。
   バブルは使わず常にパネル全体を表示する。埋め込みオーバーレイではなく単独ページとして
   表示するため、widget-rootの固定オーバーレイ設定を無効化し、bodyを通常のページにする */
body.mode-direct-full,
body.mode-direct-card {
    background: #f0f2f5;
}
body.mode-direct-full .widget-root,
body.mode-direct-card .widget-root {
    position: static;
    pointer-events: auto;
}
body.mode-direct-full .chat-close-btn,
body.mode-direct-card .chat-close-btn {
    display: none;
}

/* フルスクリーン: 画面いっぱいに表示 */
body.mode-direct-full .chat-panel {
    position: fixed; inset: 0;
    width: 100vw; height: 100vh;
    max-width: 100vw; max-height: 100vh;
    border-radius: 0;
}

/* カード: 中央寄せのカードとして表示（埋め込み前の元デザインに近いレイアウト） */
body.mode-direct-card {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}
body.mode-direct-card .chat-panel {
    position: relative;
    width: 100%;
    max-width: 600px;
    height: 80vh;
    max-height: 80vh;
}
