/* =========================
   ベース（色・影・フォント）
   ========================= */
:root{
  --c-bg:#ffffff;
  --c-surface:#ffffff;
  --c-border:#e5e7eb;
  --c-muted:#94a3b8;
  --c-primary:#2563eb;
  --c-primary-weak:#eff6ff;
  --c-accent:#4f8cff;
  --c-user:#dcfce7;
  --shadow:0 18px 40px rgba(0,0,0,.25);
  --radius:12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP",
          "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", "Meiryo", sans-serif;
}
*{ box-sizing: border-box; }
body{ font-family: var(--font); margin:0; background:#f8fafc; }

/* =========================
   右下の起動ボタン
   ========================= */
/* ランチャー本体：位置は右下のまま、影くっきり */
#chat-launcher{
  position: fixed; 
  right: 20px; 
  bottom: 20px; 
  z-index: 9999;
  padding: 8px 12px;
  border: 0;
  border-radius: 14px;
  background: var(--c-accent);
  color:#fff;
  font-weight: 400;
  font-size: 16px;
  line-height: 1.35;
  text-align: center;
  white-space: pre-line;
  box-shadow: 0 2px 4px rgba(0,0,0,0.50);
  cursor: pointer;
}

/* 尻尾：三角（border方式）。1px“食い込ませ”て境目を消す＋影を小さめに */
#chat-launcher::after{
  content:"";
  position:absolute;
  right: 14px;             /* 右端からの位置は好みで微調整 */
  bottom: -7px;            /* ← 1px 食い込ませて境目ゼロに（-8pxだと段差が出やすい） */
  width: 0; height: 0;
  border-style: solid;
  border-width: 8px 8px 0 8px;            /* 上向き三角 */
  border-color: var(--c-accent) transparent transparent transparent;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.35));   /* 三角にも控えめな影 */
}

/* =========================
   ウィジェット本体
   ========================= */
#chat-widget{
  position: fixed;
  right: 20px;
  bottom: 92px;
  z-index: 9999;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border:1px solid var(--c-border);
}

/* =========================
   open 状態のとき
   ========================= */
#chat-widget.open {
  top: 20px;
  bottom: 20px;
  height: auto;      /* height は使わない */
  max-height: none;
}

/* =========================
   ヘッダー
   ========================= */
/* ヘッダー：左右をやや詰めて、右端ボタンぶんの避難スペースは維持 */
.chat-header{
  display:flex;
  align-items:center;
  justify-content:flex-start;
  position: relative;
  padding: 8px 10px;      /* ← 高さを下げる: 12px→8px, 右余白も14→10px */
  padding-right: 80px;    /* ← ⟳/×の重なり回避。少し増やして安全側に */
  background: var(--c-primary);
  color:#fff;
  font-weight:700;
}

/* 左の画像アイコンをやや小さく＆左端寄りに見せる */
.chat-icon{
  width: 20px;            /* ← 24px→20px で高さもスリムに */
  height: 20px;
  object-fit: contain;
  margin-right: 6px;      /* タイトルとの間隔は維持 */
}

/* タイトルは左寄せのまま */
.chat-title{
  display:flex;
  align-items:center;
  font-size: 16px;
  font-weight: 400;       /* ← 見出しの太さ 500/400 */
  margin-left: 0;         /* ← 余白はアイコン側で持つ */
}

/* 右端の × ボタン */
#chat-close{
  position:absolute;
  right: 10px;             /* ← 12px→8px で端寄せ */
  top: 50%;
  transform: translateY(-50%);
  font-size: 26px;
  font-weight: normal;
  color:#fff;
  cursor:pointer;
  line-height:1;
  background: transparent;
  border: none;
  padding: 0;
}

/* リセットは × の少し左。間隔は 36〜40px 程度がバランス良い */
.reset-btn{
  position:absolute;
  right: 22px;            /* ← 22px→28px（×との差を広げる） */
  top:50%;
  transform: translateY(-50%);
  font-size: 20px;
  background: transparent;
  border: 0;
  color:#fff;
  cursor:pointer;
  line-height:1;
}
.reset-btn:hover{ opacity:.8; }

/* =========================
   注意文
   ========================= */
.chat-notice{
  padding: 10px 12px;
  font-size: 12px;
  color: var(--c-muted);
  border-bottom:1px solid var(--c-border);
  background: #fafafa;
}
.chat-notice a{ color: var(--c-primary); text-decoration: underline; }

/* =========================
   ログ（メッセージ一覧）
   ========================= */
.chat-log{
  flex: 1;
  min-height: 0;      /* ← ★余った高さを使う部分 */
  overflow-y: auto;
  padding: 12px;
  background:#f8fafc;
  display: flex;
  flex-direction: column;   /* 縦に積む */
}

/* =========================
   吹き出し共通
   ========================= */
.msg{
  width: fit-content;          /* 短文はコンパクト */
  max-width: 75%;              /* 長文でも横幅は65%まで */
  margin: 4px 0;
  padding: 8px 12px;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 14px;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;          /* 尻尾用 */
}

/* Bot吹き出しが連続する場合は間隔を広げる */
.msg.bot + .msg.bot{ 
  margin-top: 14px;  /* ← 20px → 10px に縮める */
}

/* =========================
   ユーザー（右寄せ・尻尾つき）
   ========================= */
.msg.user{
  align-self: flex-end;        /* 右寄せ */
  max-width: 70%;     /* ← 質問は少し狭め（例：70%） */
  background: var(--c-user);
  border: 1px solid var(--c-border);
}
/* 尻尾（右側） */
.msg.user::before{             /* 枠線 */
  content:"";
  position:absolute;
  right:-9px; top:12px;
  border-width:8px 0 8px 8px;
  border-style:solid;
  border-color:transparent transparent transparent var(--c-border);
}
.msg.user::after{              /* 背景 */
  content:"";
  position:absolute;
  right:-8px; top:12px;
  border-width:8px 0 8px 8px;
  border-style:solid;
  border-color:transparent transparent transparent var(--c-user);
}

/* =========================
   Bot（左寄せ・尻尾つき）
   ========================= */
.msg.bot{
  align-self: flex-start;      /* 左寄せ */
  max-width: 80%;     /* ← 回答は広め（例：80%） */
  background:#fff;
  border:1px solid var(--c-border);
}
/* 尻尾（左側） */
.msg.bot::before{              /* 枠線 */
  content:"";
  position:absolute;
  left:-9px; top:12px;
  border-width:8px 8px 8px 0;
  border-style:solid;
  border-color:transparent var(--c-border) transparent transparent;
}
.msg.bot::after{               /* 背景 */
  content:"";
  position:absolute;
  left:-8px; top:12px;
  border-width:8px 8px 8px 0;
  border-style:solid;
  border-color:transparent #fff transparent transparent;
}

/* =========================
   入力欄
   ========================= */
.chat-form{
  display:flex;
  gap:8px;
  padding:10px;
  border-top:1px solid var(--c-border);
  background:#fff;
}
#chat-input{
  flex:1;
  padding:10px;
  border:1px solid #cbd5e1;
  border-radius:8px;
  outline: none;
}
#chat-input:focus{
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-weak);
}
#chat-send.primary{
  padding:10px 14px;
  border:0;
  border-radius:8px;
  background: var(--c-primary);
  color:#fff;
  font-weight:600;
  cursor:pointer;
}
#chat-send.primary:hover{ filter: brightness(1.05); }

/* =========================
   軽微な見た目調整 2026/1/6 追加　不要なら削除する
   ========================= */
.msg .meta{
  margin-top: 6px;
  font-size: 12px;
  opacity: 0.85;
}
.msg .meta.type{
  opacity: 0.6;
}

/* =========================
   モバイル対応
   ========================= */
@media (max-width: 480px){

  body{
    overflow-x: hidden;
  }

  #chat-launcher{
    right: 12px;
    bottom: 12px;
    font-size: 14px;
    padding: 8px 10px;
    border-radius: 12px;
  }

  #chat-widget{
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100vw;
    max-width: 100vw;
    height: 88vh;
    border-radius: 14px 14px 0 0;
  }

  #chat-widget.open{
    top: 0;
    bottom: 0;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .chat-header{
    padding: 10px 12px;
    padding-right: 76px;
  }

  .chat-title{
    font-size: 15px;
  }

  .chat-notice{
    padding: 8px 10px;
    font-size: 11px;
    line-height: 1.45;
  }

  .chat-log{
    padding: 10px;
  }

  .msg{
    max-width: 88%;
    font-size: 14px;
    line-height: 1.55;
    padding: 8px 10px;
  }

  .msg.user{
    max-width: 82%;
  }

  .msg.bot{
    max-width: 90%;
  }

  .chat-form{
    gap: 6px;
    padding: 8px;
  }

  #chat-input{
    font-size: 16px; /* iPhoneの入力時ズーム防止 */
    padding: 10px;
  }

  #chat-send.primary{
    padding: 10px 12px;
    font-size: 14px;
    white-space: nowrap;
  }
}

/* =========================
   回答評価　2026/5/29
   ========================= */
.feedback-box{
  margin-top: 8px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

/* アイコン */
.feedback-icon{
  appearance: none;
  -webkit-appearance: none;
  border: none;
  outline: none;
  background: transparent;
  box-shadow: none;
  padding: 0 2px;
  margin: 0;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: .55;
}

.feedback-icon:hover{
  opacity: 1;
  transform: scale(1.08);
}

.feedback-good:hover{
  color: #2563eb;
}

.feedback-bad:hover{
  color: #dc2626;
}

.feedback-bad-area{
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  margin-top: 6px;
}

.feedback-select{
  width: 100%;
}

.feedback-detail{
  width: 100%;
  min-width: 0;
}

.feedback-send{
  border: 0;
  background: var(--c-primary);
  color: #fff;
  padding: 0 12px;
  cursor: pointer;

  display: flex;
  align-items: center;
  justify-content: center;

  align-self: flex-end;
}

.feedback-select,
.feedback-detail,
.feedback-send{
  height: 30px;
  font-size: 12px;
  border-radius: 6px;
}

.feedback-select,
.feedback-detail{
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
  padding: 0 8px;
}

.feedback-send:hover{
  filter: brightness(1.05);
}

.feedback-done{
  font-size: 12px;
  color: var(--c-muted);
}

.feedback-send{
  min-width: 32px;
}

/* =========================
   考え中表示　2026/6/4
   ========================= */
.thinking-row{
  align-self: flex-start;
  margin: 6px 0 4px;
}

.thinking-indicator{
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 10px;
  border: 1px solid var(--c-border);
  border-radius: 999px;
  background: #fff;
  color: var(--c-muted);
  font-size: 12px;
}

.thinking-indicator span{
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--c-muted);
  opacity: .35;
  animation: thinkingDot 1.2s infinite ease-in-out;
}

.thinking-indicator span:nth-child(2){
  animation-delay: .15s;
}

.thinking-indicator span:nth-child(3){
  animation-delay: .3s;
}

.thinking-indicator em{
  font-style: normal;
  margin-left: 4px;
}

@keyframes thinkingDot{
  0%, 80%, 100%{
    opacity: .25;
    transform: translateY(0);
  }
  40%{
    opacity: 1;
    transform: translateY(-2px);
  }
}

/* =========================
   300文字対応　2026/6/10
   ========================= */
.input-warning{
  align-self: center;
  max-width: 90%;
  margin: 8px 0;
  padding: 8px 12px;
  border: 1px solid #facc15;
  border-radius: 999px;
  background: #fefce8;
  color: #854d0e;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;

  white-space: nowrap;
}

/* =========================
   埋め込みモード
   ========================= */
body.embed-mode {
  background: transparent;
}

/* 右下ボタン */
body.embed-mode #chat-launcher {
  font-size: 18px;
  bottom: 18px;
}

/* チャット画面 */
body.embed-mode #chat-widget.open {
  top: 8px;
  right: 8px;
  bottom: 12px;
  left: 8px;

  width: auto;
  max-width: none;
  height: auto;

  border-radius: 12px;
  overflow: hidden;

  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.16);
}

/* チャット画面上部の注意事項文字サイズ */
body.embed-mode .chat-notice {
  font-size: 12px;
}

/* iframe時：質問入力欄 */
body.embed-mode #chat-input {
  font-size: 14px;
}

/* iframe時：送信ボタン */
body.embed-mode #chat-send {
  min-width: 62px;
  padding-left: 9px;
  padding-right: 9px;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: 4px;
}