*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.chat-wrapper {
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 480px;
  height: 720px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ヘッダー */
.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.header-avatar {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.header-info {
  color: #ffffff;
}

.header-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.header-status {
  font-size: 13px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* メッセージエリア */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #e2e8f0;
  border-radius: 4px;
}

/* メッセージバブル */
.message {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.bot {
  flex-direction: row;
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #667eea, #764ba2);
}

.message.user .message-avatar {
  background: linear-gradient(135deg, #f093fb, #f5576c);
}

.message-bubble {
  max-width: 72%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.6;
  word-break: break-word;
}

.message.bot .message-bubble {
  background: #f1f5f9;
  color: #1e293b;
  border-bottom-left-radius: 4px;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

/* 検索結果バブル */
.message.bot .message-bubble.search-bubble {
  max-width: 85%;
}

.search-results {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.search-results li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-results li a {
  flex: 1;
  color: #667eea;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.search-results li a::before {
  content: "→";
  flex-shrink: 0;
  color: #94a3b8;
}

.search-results li a:hover {
  text-decoration: underline;
  color: #5a67d8;
}

.search-no-results {
  color: #64748b;
  font-size: 13.5px;
}

/* ローディングスピナー */
.loading-spinner-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* タイピングインジケーター */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: #94a3b8;
  border-radius: 50%;
  animation: typing 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* 戻るナビゲーション（インライン） */
.inline-nav-row {
  display: flex;
  gap: 16px;
  justify-content: flex-end;
}
.back-nav-btn {
  background: none;
  border: none;
  font-size: 13px;
  color: #94a3b8;
  cursor: pointer;
  padding: 4px 0;
  font-family: inherit;
  transition: color 0.15s;
}
.back-nav-btn:hover {
  color: #667eea;
}

/* インライン選択肢 */
.inline-choices {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  animation: fadeInUp 0.3s ease;
}

.choice-btn {
  max-width: 80%;
  padding: 10px 16px;
  background: #ffffff;
  border: 1.5px solid #667eea;
  border-radius: 18px;
  border-bottom-right-radius: 4px;
  font-size: 14px;
  color: #667eea;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 10px;
}

.choice-btn:hover {
  background: #f8fafc;
  border-color: #667eea;
  color: #667eea;
}

.choice-btn:active {
  background: #eff6ff;
}

.choice-btn .choice-icon {
  font-size: 16px;
  flex-shrink: 0;
}

/* テキスト入力エリア */
.chat-input-area {
  padding: 10px 16px 14px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-label {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 500;
}

.input-caution {
  font-size: 11px;
  color: #f87171;
  font-weight: 400;
  margin-left: 8px;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 24px;
  font-size: 14px;
  font-family: inherit;
  color: #1e293b;
  background: #ffffff;
  outline: none;
  transition: border-color 0.15s;
}

.chat-input:focus {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-input::placeholder {
  color: #cbd5e1;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #ffffff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.send-btn:hover {
  opacity: 0.85;
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 完了メッセージ */
.message-bubble.end-message {
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  color: #065f46;
  border: 1px solid #6ee7b7;
}

/* レスポンシブ */
@media (max-width: 520px) {
  body {
    padding: 0;
    align-items: flex-end;
  }

  .chat-wrapper {
    border-radius: 20px 20px 0 0;
    height: 95vh;
    max-width: 100%;
  }
}
