/* [CODE] /public/chat.css */
/* aas-chat-app — Button Trigger Morphing UI */

:root {
  /* --- Dimensions --- */
  /* ボタン状態のサイズ */
  --dock-height-min: 56px;
  --dock-width-min: 160px;
  
  /* PCでの展開サイズ */
  --dock-height-pc: 550px;
  --dock-width-expanded: min(92vw, 420px);
  
  /* Mobileでの展開サイズ (1/3強〜1/2程度) */
  --dock-height-mobile-partial: 40vh; 
  --dock-height-mobile-full: 90vh;
  
  /* --- Design --- */
  --bg-glass: rgba(255, 255, 255, 0.85);
  --bg-glass-dark: rgba(20, 20, 25, 0.85);
  --border-glass: rgba(255, 255, 255, 0.4);
  --shadow-dock: 0 12px 40px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.2) inset;
  
  --accent: #007aff;
  --text-main: #1d1d1f;
  --text-sub: #86868b;
  
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* =========================================
   Container (The Button/Dock)
   ========================================= */
#aas-chat-app {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 99999;

  /* 初期状態: ボタンサイズ */
  width: var(--dock-width-min);
  height: var(--dock-height-min);
  
  /* レイアウト */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  /* Glass Design */
  background: var(--bg-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  
  border-radius: 30px; /* 丸っこいボタン */
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-dock);
  
  overflow: hidden;
  box-sizing: border-box;
  font-family: var(--font-ui);
  color: var(--text-main);
  cursor: pointer; /* ボタンであることを示す */

  /* Morphing Animation */
  transition: 
    width 0.4s cubic-bezier(0.19, 1, 0.22, 1),
    height 0.4s cubic-bezier(0.19, 1, 0.22, 1),
    border-radius 0.4s cubic-bezier(0.19, 1, 0.22, 1),
    bottom 0.3s ease;
}

/* =========================================
   Trigger Label (閉じてる時だけ表示)
   ========================================= */
#aas-trigger-content {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  pointer-events: none; /* クリックは親が受け取る */
  opacity: 1;
  transition: opacity 0.2s;
}

/* アイコン */
#aas-trigger-icon {
  font-size: 18px;
}

/* =========================================
   Expanded State (開いた時)
   ========================================= */
#aas-chat-app.is-expanded {
  width: var(--dock-width-expanded);
  height: var(--dock-height-pc);
  border-radius: 20px;
  justify-content: flex-start; /* 上詰め */
  background: rgba(255, 255, 255, 0.95);
  cursor: default;
}

/* 開いたらトリガー文字は消す */
#aas-chat-app.is-expanded #aas-trigger-content {
  display: none;
  opacity: 0;
}

/* Maximized State (全画面) */
#aas-chat-app.is-expanded.is-maximized {
  height: 85vh;
  width: min(98vw, 900px);
}

/* =========================================
   Inner UI (開いた時だけ表示)
   ========================================= */
#aas-chat-app .toolbar,
#aas-chat-app .chat,
#aas-chat-app .input,
#aas-chat-app .status {
  display: none; /* 初期は非表示 */
  opacity: 0;
}

#aas-chat-app.is-expanded .toolbar,
#aas-chat-app.is-expanded .chat,
#aas-chat-app.is-expanded .input,
#aas-chat-app.is-expanded .status {
  display: flex; /* 必要に応じてflex/block */
  opacity: 1;
  animation: fadeIn 0.4s ease 0.1s forwards;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* =========================================
   Component Styles
   ========================================= */

/* --- Toolbar --- */
#aas-chat-app .toolbar {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 12px 16px;
  box-sizing: border-box;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  background: rgba(245,245,247,0.5);
}
#phase-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  margin-right: auto;
}
/* Toolbar Buttons */
.tool-btn {
  background: transparent;
  border: none;
  width: 32px; height: 32px;
  border-radius: 8px;
  font-size: 18px;
  color: var(--text-sub);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  margin-left: 4px;
}
.tool-btn:hover { background: rgba(0,0,0,0.05); color: var(--text-main); }

/* --- Chat Area --- */
#aas-chat-app .chat {
  display: block !important; /* scrollさせるため */
  flex: 1;
  width: 100%;
  overflow-y: auto;
  padding: 10px 16px;
  scroll-behavior: smooth;
  box-sizing: border-box;
}

/* --- Input Area --- */
#aas-chat-app .input {
  width: 100%;
  padding: 12px;
  box-sizing: border-box;
  background: #fff;
  border-top: 1px solid rgba(0,0,0,0.05);
  gap: 8px;
}
#aas-chat-app .input input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid rgba(0,0,0,0.1);
  font-size: 15px;
  outline: none;
  background: #f2f2f7;
  color: #000;
}
#aas-chat-app .input input:focus {
  background: #fff;
  border-color: var(--accent);
}
#btn-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: bold;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* --- Messages (Same as before) --- */
.row { display: flex; gap: 10px; margin-bottom: 14px; align-items: flex-end; }
.row.me { justify-content: flex-end; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: #eee; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.bubble { max-width: 82%; padding: 10px 14px; border-radius: 18px; font-size: 14px; line-height: 1.5; word-break: break-word; }
.bubble.ai { background: #f2f2f7; color: #000; border-bottom-left-radius: 4px; }
.bubble.me { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.quick-wrap { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #fff; border: 1px solid #ddd; border-radius: 12px; padding: 6px 10px; font-size: 12px; cursor: pointer; }

/* Status Line */
.status { width:100%; font-size: 9px; color: #aaa; text-align: center; padding: 2px 0; }


/* =========================================
   Mobile Optimization (1/3 Height)
   ========================================= */
@media (max-width: 640px) {
  #aas-chat-app {
    width: 140px; /* スマホではボタン少し小さく */
    height: 48px;
    bottom: 20px;
  }
  
  /* スマホ展開時：画面の40% (約1/3〜1/2) */
  #aas-chat-app.is-expanded {
    width: 100vw;
    height: var(--dock-height-mobile-partial) !important;
    bottom: 0;
    border-radius: 24px 24px 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom, 20px);
  }
  
  /* スマホ全画面 */
  #aas-chat-app.is-expanded.is-maximized {
    height: var(--dock-height-mobile-full) !important;
  }
}

/* =========================================
   Game Switch Context Override
   ========================================= */
.sheet-body #aas-chat-app {
    position: relative !important;
    bottom: auto !important; left: auto !important; transform: none !important;
    width: 100% !important; height: 100% !important; min-height: 400px;
    background: transparent !important; box-shadow: none !important; border: none !important;
}
.sheet-body #aas-chat-app #aas-trigger-content { display: none !important; }
.sheet-body #aas-chat-app .toolbar,
.sheet-body #aas-chat-app .chat,
.sheet-body #aas-chat-app .input { display: flex !important; opacity: 1 !important; }