/* ── ランチャーボタン ── */
#lab-chat-launcher {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-teal));
  color: var(--bg-0);
  box-shadow: 0 8px 24px rgba(75,169,255,0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 9998;
}
#lab-chat-launcher:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 10px 30px rgba(75,169,255,0.45); }
#lab-chat-launcher svg { width: 26px; height: 26px; }

.lab-chat-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-teal);
  opacity: 0;
  transition: opacity 0.2s ease;
}
#lab-chat-launcher.has-unread .lab-chat-dot {
  opacity: 1;
  animation: lab-chat-pulse 1.6s ease-in-out infinite;
}
@keyframes lab-chat-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(30,235,192,0.55); }
  50% { box-shadow: 0 0 0 6px rgba(30,235,192,0); }
}

/* ── パネル ── */
#lab-chat-panel {
  position: fixed;
  right: 22px;
  bottom: 92px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 140px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 9999;
}
#lab-chat-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.lab-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(120deg, rgba(75,169,255,0.12), rgba(30,235,192,0.08));
  border-bottom: 1px solid var(--border);
}
.lab-chat-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-0);
  margin: 0;
}
.lab-chat-sub {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--accent-teal);
  margin: 2px 0 0;
}
.lab-chat-close {
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  display: flex;
}
.lab-chat-close:hover { background: rgba(255,255,255,0.06); color: var(--text-0); }
.lab-chat-close svg { width: 18px; height: 18px; }

.lab-chat-notice {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  line-height: 1.6;
  color: var(--text-2);
  padding: 8px 18px;
  border-bottom: 1px solid var(--border);
  margin: 0;
}

/* ── メッセージ一覧 ── */
.lab-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.lab-chat-bubble {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 0.84rem;
  line-height: 1.65;
  word-break: break-word;
  animation: lab-chat-fade-in 0.18s ease;
}
@keyframes lab-chat-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.lab-chat-bubble[data-sender="user"] {
  align-self: flex-end;
  background: linear-gradient(120deg, var(--accent-blue), var(--accent-teal));
  color: var(--bg-0);
  border-bottom-right-radius: 4px;
}
.lab-chat-bubble[data-sender="bot"] {
  align-self: flex-start;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  color: var(--text-1);
  border-bottom-left-radius: 4px;
}
.lab-chat-bubble[data-sender="developer"] {
  align-self: flex-start;
  background: rgba(30,235,192,0.12);
  border: 1px solid rgba(30,235,192,0.3);
  color: var(--text-0);
  border-bottom-left-radius: 4px;
}

.lab-chat-bubble-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.55rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 3px;
  opacity: 0.65;
}

/* ── 応答待ちインジケータ ── */
.lab-chat-bubble[data-sender="thinking"] {
  align-self: flex-start;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom-left-radius: 4px;
}
.lab-chat-bubble[data-sender="thinking"] .lab-chat-bubble-label {
  margin-bottom: 0;
}
.lab-chat-bubble[data-sender="thinking"] .lab-chat-thinking-dots {
  display: flex;
  gap: 4px;
}
.lab-chat-bubble[data-sender="thinking"] .lab-chat-thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-2);
  animation: lab-chat-bounce 1.1s ease-in-out infinite;
}
.lab-chat-bubble[data-sender="thinking"] .lab-chat-thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.lab-chat-bubble[data-sender="thinking"] .lab-chat-thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes lab-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-3px); opacity: 1; }
}

.lab-chat-bubble a {
  color: var(--accent-blue);
  text-decoration: underline;
  word-break: break-all;
}

/* ── フッター(呼び出しボタン・入力欄) ── */
.lab-chat-footer {
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lab-chat-call-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(255,194,92,0.1);
  border: 1px solid rgba(255,194,92,0.3);
  color: var(--accent-amber, #ffc25c);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 7px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.lab-chat-call-btn:hover { background: rgba(255,194,92,0.18); }
.lab-chat-call-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.lab-chat-call-btn svg { width: 14px; height: 14px; }

.lab-chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.lab-chat-input {
  flex: 1;
  resize: none;
  max-height: 90px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 12px;
  color: var(--text-0);
  font-size: 0.83rem;
  outline: none;
  font-family: inherit;
}
.lab-chat-input:focus { border-color: var(--accent-blue); }

.lab-chat-send-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-teal));
  color: var(--bg-0);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}
.lab-chat-send-btn:hover { transform: scale(1.06); }
.lab-chat-send-btn svg { width: 16px; height: 16px; }

@media (max-width: 480px) {
  #lab-chat-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 78px;
    height: auto;
    max-height: calc(100vh - 100px);
    max-height: calc(100dvh - 100px);
  }
  #lab-chat-launcher {
    right: 14px;
    bottom: 14px;
    width: 52px;
    height: 52px;
  }
  .lab-chat-header { padding: 14px 14px; }
  .lab-chat-messages { padding: 12px 10px; }
  .lab-chat-bubble { max-width: 88%; font-size: 0.86rem; }
  .lab-chat-footer { padding: 8px 10px 10px; }
  .lab-chat-input { font-size: 16px; } /* iOSでの自動ズームを防止 */
}

@media (max-width: 480px) and (max-height: 640px) {
  /* 画面が低い端末(横向き含む)では、パネルをほぼ全画面化して入力欄を確保する */
  #lab-chat-panel {
    bottom: 70px;
    max-height: calc(100vh - 84px);
    max-height: calc(100dvh - 84px);
  }
}
