﻿/* ================================
   Dify Chat – Tonmana Theme (老舗呉服店向け上品デザイン)
   Version: 2.0.0
   ・老舗呉服店のHPに調和する和の雰囲気
   ・体系的なカラーパレット（CSS変数）
   ・繊細な影とグラデーション
   ・滑らかなアニメーション（cubic-bezier）
   ・モバイルキーボード対応
   ・音声入力ボタンとアニメーション
   ================================ */

/* ---- Base / font / manual position (JSで上書き可) ---- */
#dify-chatbot-container.theme-tonmana{
  position: relative;
  z-index: 2147483647;
  font-family: "Yu Mincho","游明朝体","YuMincho","Hiragino Mincho ProN","Noto Serif JP",serif;

  /* 位置設定 */
  --launcher-right: 24px;
  --launcher-bottom: 88px;
  --window-right: 24px;
  --window-bottom: 96px;

  /* 角丸（より優しく上品な印象に） */
  --r-window: 12px;
  --r-bubble: 12px;
  --r-chip:   8px;
  --r-input:  8px;
  --r-btn:    8px;

  /* ヒット領域 */
  --close-hit: 40px;  /* 52px → 40px に縮小（ヘルプボタンと干渉しないように） */
  --close-size: 28px;
  --menu-hit: 56px;

  /* カラーパレット（老舗呉服店らしい上品な配色） */
  --color-primary: #2b9aa1;           /* メインティール */
  --color-primary-light: #4db3b9;     /* 明るいティール */
  --color-primary-dark: #1e7278;      /* 濃いティール */
  --color-primary-pale: #d4eff1;      /* 淡いティール */
  --color-primary-soft: #e8f7f8;      /* とても淡いティール */
  
  --color-accent: #ff6b7a;            /* アクセント（柔らかいコーラルピンク） */
  --color-accent-light: #ffadb6;      /* 淡いアクセント */
  
  --color-bg-main: #ffffff;           /* メイン背景 */
  --color-bg-secondary: #f8fafb;      /* セカンダリ背景 */
  --color-bg-tertiary: #f0f4f6;       /* ターシャリ背景 */
  
  --color-text-primary: #2b2b2b;      /* メインテキスト */
  --color-text-secondary: #5a5a5a;    /* セカンダリテキスト */
  --color-text-muted: #8b9299;        /* 控えめなテキスト */
  
  --color-border: #e6ecef;            /* 通常のボーダー */
  --color-border-light: #f1f5f7;      /* 淡いボーダー */
  
  /* 影（より繊細で上品に） */
  --shadow-sm: 0 1px 3px rgba(43, 154, 161, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(43, 154, 161, 0.10), 0 2px 6px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 28px rgba(43, 154, 161, 0.12), 0 6px 12px rgba(0, 0, 0, 0.08);
  --shadow-xl: 0 20px 40px rgba(43, 154, 161, 0.14), 0 12px 20px rgba(0, 0, 0, 0.10);
}

/* ---- Overlay ---- */
#chat-overlay[hidden]{ display:none; }
#chat-overlay{
  position:fixed; inset:0;
  background:rgba(0,0,0,.2);
  opacity:0; transition:opacity .18s ease;
  z-index:9998;
}
#chat-overlay[data-anim="out"]{ opacity:0; }
#chat-overlay:not([hidden]){ opacity:1; }

/* ---- Launcher bubble ---- */
#open-chat{
  position:fixed;
  right: var(--launcher-right);
  bottom: calc(var(--launcher-bottom) + env(safe-area-inset-bottom, 0px));
  width:64px; height:64px; border-radius:50%;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color:#fff; border:none;
  box-shadow: var(--shadow-lg);
  cursor:pointer;
  transition: transform .25s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow .25s cubic-bezier(0.4, 0, 0.2, 1),
              bottom .15s ease;
}
#open-chat:hover{
  transform: translateY(-4px) scale(1.05);
  box-shadow: var(--shadow-xl);
}
#open-chat::after{
  content: attr(data-label);
  position:absolute; right:68px; top:50%; transform:translateY(-50%);
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color:#fff;
  padding:10px 16px;
  border-radius:999px;
  font-weight:600;
  font-size:13px;
  white-space:nowrap;
  opacity:.96;
  box-shadow: var(--shadow-md);
  pointer-events:none;
  letter-spacing: 0.03em;
}
/* モバイルではラベルをアイコンの上側・中央に表示する */
@media (max-width:767px){
  #open-chat::after{
    display:block;
    font-size:12px;
    left:auto;
    right:0;
    top:auto;
    bottom: calc(100% + 10px);
    transform:none;
    max-width: calc(100vw - 24px); /* 画面端での見切れ防止。padding相当の余白を確保 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
  }
}

/* ランチャー内のアイコン&AIバッジ（内側固定） */
#open-chat .launcher-icon{
  position:absolute; left:50%; top:50%;
  transform:translate(-50%,-50%);
  width:28px; height:28px; color:#fff;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}
#open-chat .launcher-icon svg{ width:100%; height:100%; display:block; }
#open-chat .launcher-badge{
  position:absolute; right:2px; bottom:2px;
  background:#fff;
  color: var(--color-primary-dark);
  border:2px solid #fff;
  border-radius:999px;
  padding:3px 6px;
  font-weight:700;
  font-size:10px;
  line-height:1;
  box-shadow: var(--shadow-sm);
  letter-spacing: 0.02em;
}

/* ---- Window ---- */
#chat-window[hidden]{ display:none; }
#chat-window{
  position:fixed;
  right: var(--window-right);
  bottom: calc(var(--window-bottom) + env(safe-area-inset-bottom, 0px));
  width:400px;
  max-height:70vh;
  display:flex;
  flex-direction:column;
  background: var(--color-bg-main);
  color: var(--color-text-primary);
  border:1px solid var(--color-border);
  border-radius: var(--r-window);
  box-shadow: var(--shadow-xl);
  overflow:hidden;
  transform: translateY(16px) scale(.96);
  opacity:0;
  transition: transform .3s cubic-bezier(0.4, 0, 0.2, 1),
              opacity .3s cubic-bezier(0.4, 0, 0.2, 1),
              bottom .15s ease;
  z-index:9999;

  --header-h-pc: 64px;
  --header-h-sp: 56px;
  --title-size-pc: 17px;
  --title-size-sp: 16px;

  --kb: 0px;
}
#chat-window[data-anim="in"]{
  transform:translateY(0) scale(1);
  opacity:1;
}
#chat-window[data-anim="out"]{
  transform:translateY(16px) scale(.96);
  opacity:0;
}

/* ---- Header ---- */
#chat-header{
  position: relative;
  flex: 0 0 var(--header-h-pc);
  height: var(--header-h-pc);
  min-height: var(--header-h-pc);
  box-sizing: border-box;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 0 16px;
  background: linear-gradient(180deg, var(--color-bg-secondary) 0%, var(--color-bg-main) 100%);
  border-bottom:1px solid var(--color-border);
  line-height:1;
  z-index:10000;
  overflow:visible; /* エラートースト表示のため */
}
#chat-header::before{
  content: attr(data-title);
  display:block;
  font-weight:600;
  letter-spacing:.04em;
  color: var(--color-text-primary);
  font-size: var(--title-size-pc);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* ヘルプボタンと閉じるボタンのスペースを確保 */
  max-width: calc(100% - var(--close-hit) - 56px);
  padding: 0 10px;
}
#chat-header .title{ display:none !important; }

/* 右の×（大きいまま右端寄せ表示） */
#close-chat{
  position:absolute; right:0; top:50%; transform:translateY(-50%);
  width: var(--close-hit) !important; height: var(--close-hit) !important;
  display:inline-flex; align-items:center; justify-content:flex-end;
  padding-right: 14px;
  background:transparent !important; border:none !important; box-shadow:none !important;
  color: var(--color-text-secondary);
  font-size: var(--close-size);
  line-height:1;
  cursor:pointer;
  -webkit-tap-highlight-color:transparent;
  touch-action:manipulation;
  transition: color .2s ease, transform .15s ease;
}
#close-chat::before, #close-chat::after{ content:none !important; }
#close-chat:hover{
  color: var(--color-text-primary);
}
#close-chat:active{
  transform:translateY(-50%) scale(.95);
}

/* 左のハンバーガー */
#dify-menu-toggle{
  position:absolute; left:0; top:50%; transform:translateY(-50%);
  width: var(--menu-hit); height: var(--menu-hit);
  display:inline-flex; align-items:center; justify-content:flex-start;
  padding-left:14px;
  background:transparent;
  border:none;
  cursor:pointer;
  -webkit-tap-highlight-color:transparent;
  touch-action:manipulation;
  transition: opacity .2s ease;
}
#dify-menu-toggle:hover{ opacity: 0.7; }
#dify-menu-toggle .dify-bars{ position:relative; width:24px; height:18px; }
#dify-menu-toggle .dify-bar{
  position:absolute;
  left:0; right:0;
  height:2.5px;
  background: var(--color-text-secondary);
  border-radius:2px;
  transition: background .2s ease;
}
#dify-menu-toggle:hover .dify-bar{ background: var(--color-primary); }
#dify-menu-toggle .dify-bar:nth-child(1){ top:0; }
#dify-menu-toggle .dify-bar:nth-child(2){ top:8px; }
#dify-menu-toggle .dify-bar:nth-child(3){ bottom:0; }

/* ドロップダウン */
#dify-menu-dropdown{
  position:absolute;
  left:10px;
  top: calc(100% + 8px);
  min-width: 200px;
  background: var(--color-bg-main);
  border:1px solid var(--color-border);
  border-radius: var(--r-chip);
  box-shadow: var(--shadow-lg);
  padding:8px;
  z-index: 10001;
  transform-origin: 12px top;
  transform: scale(.96) translateY(-8px);
  opacity:0;
  pointer-events:none;
  transition: transform .25s cubic-bezier(0.4, 0, 0.2, 1),
              opacity .25s cubic-bezier(0.4, 0, 0.2, 1);
}
#dify-menu-dropdown[data-open="true"]{
  transform: scale(1) translateY(0);
  opacity:1;
  pointer-events:auto;
}
.dify-menu-item{
  width:100%;
  text-align:left;
  background: var(--color-bg-main);
  border:none;
  border-radius: var(--r-chip);
  padding:12px 14px;
  cursor:pointer;
  font-weight:600;
  color: var(--color-text-primary);
  transition: background .2s ease, transform .15s ease;
}
.dify-menu-item:hover{
  background: var(--color-bg-secondary);
}
.dify-menu-item:active{
  transform:scale(.98);
}

/* ---- Messages ---- */
#chat-messages{
  position: relative;
  flex:1;
  padding:16px;
  overflow:auto;
  background: var(--color-bg-secondary);
  line-height:1.75;
  display:flex;
  flex-direction:column;
  gap:14px;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

/* 削除: 最新の2メッセージ用ラッパー（不要） */
.chat-row{
  display:flex;
  align-items:flex-end;
  gap:10px;
  animation: fadeInUp .3s ease;
}
@keyframes fadeInUp{
  from{ opacity:0; transform:translateY(8px); }
  to{ opacity:1; transform:translateY(0); }
}
.chat-row.bot{ flex-direction: row; }
.chat-row.me { flex-direction: row; justify-content:flex-end; }
.avatar{
  width:42px;
  height:42px;
  aspect-ratio:1/1;
  border-radius:50% !important;
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:22px;
  border:2px solid var(--color-bg-main);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.chat-row.me .avatar{
  background: var(--color-primary-pale);
  border-color: var(--color-bg-main);
}
.bubble{
  max-width:85%;
  padding:14px 16px;
  border-radius: var(--r-bubble) !important;
  background: var(--color-bg-main);
  border:1px solid var(--color-border-light);
  box-shadow: var(--shadow-sm);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
}
.chat-row.me .bubble{
  background: var(--color-primary-soft);
  border-color: var(--color-primary-pale);
}

/* --- 追加：アバター画像の自動トリミング＆丸型フィット --- */
.avatar img.avatar-img{
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: 50% !important;
}

/* ---- Quick actions ---- */
.quick-actions{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:8px;
}
.quick-actions button{
  padding:10px 14px !important;
  border-radius: var(--r-chip) !important;
  border:1px solid var(--color-primary-pale);
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  font-weight:600;
  cursor:pointer;
  transition: all .2s ease;
  box-shadow: var(--shadow-sm);
  /* モバイル対応: タップ領域を確保 */
  min-height: 44px;
  -webkit-tap-highlight-color: rgba(43, 154, 161, 0.1);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.quick-actions button:hover{
  background: var(--color-primary-pale);
  border-color: var(--color-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* モバイル対応: ボタンサイズとフォントを調整 */
@media (max-width:767px){
  .quick-actions button{
    padding:12px 16px !important;
    font-size:15px;
    min-height:48px;
  }
}

/* ---- Input ---- */
#chat-input{
  display:flex;
  gap:10px;
  padding:14px 16px;
  background: var(--color-bg-main);
  border-top:1px solid var(--color-border);
}
#user-input{
  flex:1;
  padding:12px 14px;
  border:2px solid var(--color-border);
  border-radius: var(--r-input) !important;
  outline:none;
  font-size:14px;
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  transition: border-color .2s ease, background .2s ease, box-shadow .2s ease;
  resize: none;
  overflow-y: auto;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.5;
  font-family: inherit;
}
#user-input:focus{
  border-color: var(--color-primary);
  background: var(--color-bg-main);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}
#user-input::placeholder{
  color: var(--color-text-muted);
}

/* ---- Voice Input Button ---- */
#voice-input-btn{
  padding:12px 16px;
  border-radius: var(--r-btn) !important;
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  border:2px solid var(--color-border);
  min-width: 52px;
  cursor:pointer;
  transition: all .2s ease;
  box-shadow: var(--shadow-sm);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  position:relative;
  /* モバイル対応: タップ操作の改善 */
  -webkit-tap-highlight-color: rgba(43, 154, 161, 0.1);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
#voice-input-btn:hover:not(:disabled){
  background: var(--color-primary-soft);
  color: var(--color-primary);
  border-color: var(--color-primary-pale);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
#voice-input-btn:active:not(:disabled){
  transform: translateY(0);
  background: var(--color-primary-pale);
}
#voice-input-btn:disabled{
  opacity: 0.4;
  cursor: not-allowed;
}
#voice-input-btn[hidden]{
  display:none;
}

/* マイクアイコン */
#voice-input-btn .mic-icon{
  width:20px;
  height:20px;
  display:block;
  /* モバイル対応: アイコンのクリックイベントを親に伝播 */
  pointer-events: none;
}
#voice-input-btn .mic-icon svg{
  width:100%;
  height:100%;
  display:block;
  pointer-events: none;
}

/* 録音中の状態 */
#voice-input-btn.recording{
  background: var(--color-accent);
  color:#fff;
  border-color: var(--color-accent);
  animation: voicePulse 1.5s ease-in-out infinite;
}
@keyframes voicePulse{
  0%, 100%{ box-shadow: 0 0 0 0 rgba(255, 107, 122, 0.4); }
  50%{ box-shadow: 0 0 0 8px rgba(255, 107, 122, 0); }
}

/* 録音中の波形アニメーション */
#voice-input-btn.recording::before{
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: var(--r-btn);
  border: 2px solid var(--color-accent-light);
  opacity: 0.6;
  animation: voiceRipple 1.5s ease-out infinite;
}
@keyframes voiceRipple{
  0%{ transform: scale(1); opacity: 0.6; }
  100%{ transform: scale(1.2); opacity: 0; }
}

/* LINEブラウザ等での制限警告 */
#voice-input-btn.voice-limited-browser{
  border-color: var(--color-accent-light);
  opacity: 0.9;
}
#voice-input-btn.voice-limited-browser .voice-warning-badge{
  animation: warningPulse 2s ease-in-out infinite;
}
@keyframes warningPulse{
  0%, 100%{ transform: scale(1); }
  50%{ transform: scale(1.1); }
}

#send-msg{
  padding:12px 20px;
  border-radius: var(--r-btn) !important;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color:#fff;
  border:none;
  font-weight:600;
  min-width: 88px;
  cursor:pointer;
  transition: transform .2s ease, box-shadow .2s ease;
  box-shadow: var(--shadow-sm);
}
#send-msg:hover{
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
#send-msg:active{
  transform: translateY(0);
}
#send-msg:disabled{
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Typing indicator ---- */
.bubble.typing{
  background: var(--color-bg-tertiary);
  border-style:dashed;
  border-color: var(--color-border);
}
.typing-box{
  display:flex;
  align-items:center;
  gap:10px;
}
.typing-text{
  color: var(--color-text-muted);
  font-size:13px;
}
.dots{
  display:inline-flex;
  gap:5px;
  align-items:center;
}
.dot{
  width:7px;
  height:7px;
  border-radius:50%;
  background: var(--color-primary);
  opacity:.6;
  animation:blink 1.4s infinite ease-in-out;
}
.dot:nth-child(2){ animation-delay:.2s; }
.dot:nth-child(3){ animation-delay:.4s; }
@keyframes blink{
  0%, 80%, 100%{ transform:translateY(0); opacity:.3; }
  40%{ transform:translateY(-3px); opacity:1; }
}

/* ---- SP fullscreen & keyboard ---- */
@media (max-width:767px){
  #chat-window{
    right:0; left:0; bottom:auto; top:0; width:100%;
    max-height:none;
    height:100svh; height:100dvh; height:calc(var(--vh, 1vh) * 100);
    border-radius:0; border:none;
    overscroll-behavior: contain;

    --close-hit: 44px;  /* 56px → 44px に縮小（モバイルでもヘルプボタンと干渉しないように） */
    --close-size: 32px;
    --menu-hit: 64px;
  }

  /* 削除: モバイルでの最新メッセージラッパー調整（不要） */
  #chat-header{
    flex-basis: var(--header-h-sp);
    height: var(--header-h-sp);
    min-height: var(--header-h-sp);
    padding: 0 12px;
  }
  #chat-header::before{ font-size: var(--title-size-sp); }
  
  /* モバイル入力エリアの調整（見切れ防止） */
  #chat-window #chat-input{
    position: sticky; bottom: 0; z-index: 2;
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }
  
  #chat-window #user-input{
    padding: 10px 12px;
    min-height: 44px;
    font-size: 16px; 
    line-height: 1.3;
    flex: 1;
    min-width: 0; /* flexアイテムの縮小を許可 */
  }
  
  /* マイクボタンのモバイル調整 */
  #chat-window #voice-input-btn{
    padding: 10px 12px;
    min-width: 44px;
    min-height: 44px;
    flex-shrink: 0; /* 縮小しない */
  }
  
  #chat-window #send-msg{
    padding: 10px 14px;
    min-height: 44px;
    min-width: 72px;
    font-size: 15px;
    flex-shrink: 0; /* 縮小しない */
  }
  
  #chat-window.kb-open #chat-messages{ padding-bottom: calc(14px + var(--kb, 0px)); }
  #chat-window.kb-open #chat-input{    margin-bottom: var(--kb, 0px); }
}
/* バブル内リンクの可読性向上 */
.bubble a{
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-color: var(--color-primary-pale);
  word-break: break-all;
  transition: color .2s ease, text-decoration-color .2s ease;
}
.bubble a:hover{
  color: var(--color-primary-dark);
  text-decoration-color: var(--color-primary);
}

/* ---- Feedback Modal ---- */
.feedback-modal[hidden]{ display:none; }
.feedback-modal{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.5);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:2147483646; /* チャットウィンドウより下、overlayより上 */
  opacity:0;
  transition:opacity .3s ease;
}
.feedback-modal:not([hidden]){
  opacity:1;
}
.feedback-content{
  background: var(--color-bg-main);
  border-radius: var(--r-window);
  padding:32px 28px;
  max-width:400px;
  width:90%;
  box-shadow: var(--shadow-xl);
  animation: feedbackSlideIn .3s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes feedbackSlideIn{
  from{ transform:translateY(20px) scale(.95); opacity:0; }
  to{ transform:translateY(0) scale(1); opacity:1; }
}
.feedback-question{
  font-size:18px;
  font-weight:600;
  color: var(--color-text-primary);
  margin:0 0 20px 0;
  text-align:center;
  line-height:1.6;
}
.feedback-buttons{
  display:flex;
  gap:12px;
  justify-content:center;
}
.feedback-btn{
  padding:14px 24px;
  border-radius: var(--r-btn);
  font-weight:600;
  font-size:15px;
  cursor:pointer;
  transition: all .2s ease;
  border:2px solid transparent;
  min-width: 140px;
}
.feedback-btn-positive{
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color:#fff;
  box-shadow: var(--shadow-sm);
}
.feedback-btn-positive:hover{
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.feedback-btn-negative{
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  border-color: var(--color-border);
}
.feedback-btn-negative:hover{
  background: var(--color-bg-tertiary);
  border-color: var(--color-text-muted);
  transform: translateY(-2px);
}
.feedback-btn:active{
  transform: translateY(0) scale(.98);
}

/* モバイル対応 */
@media (max-width:767px){
  .feedback-content{
    padding:28px 24px;
  }
  .feedback-question{
    font-size:17px;
  }
  .feedback-buttons{
    flex-direction:column;
    gap:10px;
  }
  .feedback-btn{
    width:100%;
    min-width:auto;
  }
}

/* ---- Scroll to Message Top Button ---- */
.scroll-to-message-top{
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  z-index: 10;
  transition: all .2s ease;
  opacity: 0;
  animation: fadeInButton .3s ease forwards;
}
@keyframes fadeInButton{
  from{ opacity: 0; transform: scale(.8); }
  to{ opacity: 1; transform: scale(1); }
}
.scroll-to-message-top:hover{
  transform: translateY(-2px) scale(1.05);
  box-shadow: var(--shadow-lg);
}
.scroll-to-message-top:active{
  transform: translateY(0) scale(.95);
}
.scroll-to-message-top svg{
  width: 16px;
  height: 16px;
  display: block;
}

/* ---- Error Toast ---- */
.error-toast{
  position: absolute;
  top: calc(100% + 12px); /* ヘッダーの下に表示 */
  left: 50%;
  transform: translateX(-50%);
  background: #ff6b7a;
  color: #fff;
  padding: 14px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 10003 !important; /* ヘッダーやインプットエリアより上 */
  font-weight: 600;
  max-width: calc(100% - 24px);
  text-align: center;
  animation: errorToastSlideIn .3s ease forwards;
  white-space: pre-line; /* 改行を有効化 */
  line-height: 1.6;
  pointer-events: none; /* クリックイベントを貫通 */
}
@keyframes errorToastSlideIn{
  from{ opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to{ opacity: 1; transform: translateX(-50%) translateY(0); }
}
/* モバイル対応 */
@media (max-width:767px){
  .error-toast{
    top: calc(100% + 8px);
    padding: 12px 16px;
    font-size: 14px;
    max-width: calc(100% - 16px);
  }
}

/* ---- Message Feedback Buttons ---- */
.message-feedback{
  display: flex;
  gap: 6px;
  margin-top: 8px;
  opacity: 0.6;
  transition: opacity .2s ease;
}
.message-feedback:hover{
  opacity: 1;
}
.feedback-icon-btn{
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  color: var(--color-text-muted);
  transition: all .2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.feedback-icon-btn:hover{
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
}
.feedback-icon-btn:active{
  transform: scale(.95);
}
.feedback-icon-btn.selected{
  color: var(--color-primary);
  background: var(--color-primary-soft);
}
.feedback-icon-btn svg{
  width: 16px;
  height: 16px;
  display: block;
  pointer-events: none;
}
/* Goodボタンが選択されたとき */
.feedback-icon-btn.good.selected{
  color: var(--color-primary);
}
/* Badボタンが選択されたとき */
.feedback-icon-btn.bad.selected{
  color: var(--color-accent);
}
/* ---- Help Button in Header ---- */
#help-button{
  position: absolute;
  right: calc(var(--close-hit) + 8px); /* ����{�^���̍����ɔz�u */
  top: 50%;
  transform: translateY(-50%);
  width: 32px; height: 32px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  color: var(--color-primary);
  cursor: pointer;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  transition: all .2s ease;
  box-shadow: var(--shadow-sm);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  z-index: 10002;

}
#help-button:hover{
  background: var(--color-primary-soft);
  border-color: var(--color-primary-pale);
  transform: translateY(-50%) scale(1.05);
  box-shadow: var(--shadow-md);
}
#help-button:active{
  transform: translateY(-50%) scale(.95);
}
.help-icon{
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

/* ---- Help Modal ---- */
.help-modal[hidden]{ display: none; }
.help-modal{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2147483646; /* feedback-modal�Ɠ��� */
  opacity: 0;
  transition: opacity .3s ease;
}
.help-modal:not([hidden]){
  opacity: 1;
}
.help-modal-content{
  background: var(--color-bg-main);
  border-radius: var(--r-window);
  padding: 28px 32px 32px;
  max-width: 480px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: helpSlideIn .3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}
@keyframes helpSlideIn{
  from{ transform: translateY(20px) scale(.95); opacity: 0; }
  to{ transform: translateY(0) scale(1); opacity: 1; }
}
.help-modal-close{
  position: absolute;
  right: 16px;
  top: 16px;
  width: 36px;
  height: 36px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  color: var(--color-text-secondary);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s ease;
}
.help-modal-close:hover{
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  transform: scale(1.05);
}
.help-modal-close:active{
  transform: scale(.95);
}
.help-modal-title{
  font-size: 20px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0 0 24px 0;
  text-align: center;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--color-border-light);
  letter-spacing: 0.02em;
}
.help-modal-body{
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.help-section h4{
  font-size: 16px;
  font-weight: 600;
  color: var(--color-primary-dark);
  margin: 0 0 12px 0;
  letter-spacing: 0.02em;
}
.help-section ul{
  margin: 0;
  padding: 0 0 0 20px;
  list-style: none;
}
.help-section li{
  position: relative;
  padding-left: 12px;
  margin-bottom: 10px;
  color: var(--color-text-secondary);
  line-height: 1.7;
  font-size: 14px;
}
.help-section li::before{
  content: '';
  position: absolute;
  left: -8px;
  top: 10px;
  width: 6px;
  height: 6px;
  background: var(--color-primary);
  border-radius: 50%;
}

/* モバイル対応 */
@media (max-width:767px){
  #help-button{
    right: calc(var(--close-hit) + 4px);
    width: 28px; height: 28px;
  }
  .help-icon{
    font-size: 14px;
  }
  #chat-header::before{
    max-width: calc(100% - var(--close-hit) - 46px);
  }
  .help-modal-content{
    padding: 24px 20px 28px;
    width: 94%;
    max-height: 85vh;
  }
  .help-modal-title{
    font-size: 18px;
    margin-bottom: 20px;
    padding-bottom: 14px;
  }
  .help-section h4{
    font-size: 15px;
  }
  .help-section li{
    font-size: 13px;
    margin-bottom: 8px;
  }
}


/* ---- Manual Feedback Modal ---- */
.manual-feedback-modal[hidden]{ display: none; }
.manual-feedback-modal{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2147483646;
  opacity: 0;
  transition: opacity .3s ease;
}
.manual-feedback-modal:not([hidden]){
  opacity: 1;
}
.manual-feedback-content{
  background: var(--color-bg-main);
  border-radius: var(--r-window);
  padding: 28px 32px 32px;
  max-width: 540px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: manualFeedbackSlideIn .3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}
@keyframes manualFeedbackSlideIn{
  from{ transform: translateY(20px) scale(.95); opacity: 0; }
  to{ transform: translateY(0) scale(1); opacity: 1; }
}
.manual-feedback-close{
  position: absolute;
  right: 16px;
  top: 16px;
  width: 36px;
  height: 36px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  color: var(--color-text-secondary);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s ease;
}
.manual-feedback-close:hover{
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  transform: scale(1.05);
}
.manual-feedback-close:active{
  transform: scale(.95);
}
.manual-feedback-title{
  font-size: 20px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0 0 24px 0;
  text-align: center;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--color-border-light);
  letter-spacing: 0.02em;
}
.manual-feedback-body{
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.manual-feedback-field{
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.manual-feedback-field label{
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
  letter-spacing: 0.02em;
}
.manual-feedback-field textarea{
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--color-border);
  border-radius: var(--r-input);
  font-size: 14px;
  font-family: inherit;
  color: var(--color-text-primary);
  background: var(--color-bg-secondary);
  resize: vertical;
  min-height: 100px;
  transition: border-color .2s ease, background .2s ease, box-shadow .2s ease;
  line-height: 1.6;
}
.manual-feedback-field textarea:focus{
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-bg-main);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.manual-feedback-field textarea::placeholder{
  color: var(--color-text-muted);
}
.manual-feedback-buttons{
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 8px;
}
.manual-feedback-btn{
  padding: 12px 24px;
  border-radius: var(--r-btn);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: all .2s ease;
  border: 2px solid transparent;
  min-width: 120px;
}
.manual-feedback-btn-primary{
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.manual-feedback-btn-primary:hover:not(:disabled){
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.manual-feedback-btn-primary:disabled{
  opacity: 0.5;
  cursor: not-allowed;
}
.manual-feedback-btn-secondary{
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  border-color: var(--color-border);
}
.manual-feedback-btn-secondary:hover{
  background: var(--color-bg-tertiary);
  border-color: var(--color-text-muted);
  transform: translateY(-2px);
}
.manual-feedback-btn:active{
  transform: translateY(0) scale(.98);
}

/* モバイル対応 */
@media (max-width:767px){
  .manual-feedback-content{
    padding: 24px 20px 28px;
    width: 94%;
    max-height: 90vh;
  }
  .manual-feedback-title{
    font-size: 18px;
    margin-bottom: 20px;
    padding-bottom: 14px;
  }
  .manual-feedback-field label{
    font-size: 13px;
  }
  .manual-feedback-field textarea{
    font-size: 13px;
    padding: 10px 12px;
    min-height: 80px;
  }
  .manual-feedback-buttons{
    flex-direction: column;
    gap: 10px;
  }
  .manual-feedback-btn{
    width: 100%;
    min-width: auto;
  }
}

/* ---- Font Size Toggle (Accessibility) ---- */
/* フォントサイズ拡大モード適用時のスタイル */
#dify-chatbot-container.large-font .bubble{
  font-size: 18px;
  line-height: 1.8;
}
#dify-chatbot-container.large-font #user-input{
  font-size: 17px;
}
#dify-chatbot-container.large-font #send-msg{
  font-size: 16px;
}
#dify-chatbot-container.large-font .quick-actions button{
  font-size: 16px;
  padding: 11px 16px !important;
}
#dify-chatbot-container.large-font .typing-text{
  font-size: 15px;
}
#dify-chatbot-container.large-font #chat-header::before{
  font-size: 18px;
}
#dify-chatbot-container.large-font .help-section li{
  font-size: 16px;
}
#dify-chatbot-container.large-font .help-section h4{
  font-size: 18px;
}
#dify-chatbot-container.large-font .manual-feedback-field textarea{
  font-size: 16px;
}
#dify-chatbot-container.large-font .manual-feedback-field label{
  font-size: 16px;
}
#dify-chatbot-container.large-font .feedback-question{
  font-size: 20px;
}
#dify-chatbot-container.large-font .dify-menu-item{
  font-size: 16px;
}

/* モバイル対応 */
@media (max-width:767px){
  /* モバイルでのフォントサイズ拡大 */
  #dify-chatbot-container.large-font .bubble{
    font-size: 18px;
  }
  #dify-chatbot-container.large-font #user-input{
    font-size: 18px;
  }
  #dify-chatbot-container.large-font #chat-header::before{
    font-size: 17px;
  }
  #dify-chatbot-container.large-font .quick-actions button{
    font-size: 16px;
  }
}
