/* ========================================
   カラー変数
   ======================================== */
:root {
  --key-color: #000080;
  --key-color-light: #1a1a99;
  --key-color-dark: #000066;
  --accent-color: #4040bf;
  --bg-light: #f0f2f8;
  --text-dark: #333;
  --text-light: #666;
  --border-color: #dde1e8;
}

/* ========================================
   チャット本体
   ======================================== */
.chat-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 340px;
  max-height: 700px;
  background: #fff;
  border: none;
  border-radius: 16px;
  display: none;
  flex-direction: column;
  z-index: 9999;
  padding: 0;
  box-shadow: 0 8px 32px rgba(0, 0, 128, 0.25), 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

.chat-container h1 {
  text-align: center;
  font-size: 1.1rem;
  color: #fff;
  margin: 0;
  padding: 12px;
  background: rgba(0, 0, 0, 0.1);
}

/* ========================================
   チャットヘッダー
   ======================================== */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  background: linear-gradient(135deg, var(--key-color) 0%, var(--key-color-light) 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-header > span {
  font-size: 15px;
  letter-spacing: 0.3px;
}

.chat-header > div {
  display: flex;
  gap: 6px;
  font-size: 11px;
  flex-shrink: 0;
}

.chat-header span {
  cursor: pointer;
  transition: all 0.2s;
}

/* ヘッダーボタン共通スタイル */
.chat-header #restart-chat-button,
.chat-header #close-chat-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  background: transparent;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  transition: background 0.2s;
}

.chat-header #restart-chat-button:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* 閉じるボタン - シンプルモダン */
.chat-header #close-chat-button {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  color: rgba(0, 0, 0, 0.5);
  font-size: 14px;
  font-weight: 300;
  line-height: 1;
}

.chat-header #close-chat-button:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

/* ========================================
   進捗バー
   ======================================== */
.progress-container {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(0, 0, 0, 0.05);
}

.progress-bar {
  flex: 1;
  height: 5px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #fff;
  border-radius: 3px;
  transition: width 0.5s ease;
  width: 0%;
}

.progress-text {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  min-width: 80px;
  text-align: right;
}

/* ========================================
   チャットログ
   ======================================== */
#chat-log,
.chat-log {
  position: relative;
  flex: 1;
  min-height: 350px;
  max-height: 480px;
  overflow-y: auto;
  padding: 16px;
  border: none;
  border-radius: 0;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#chat-log::-webkit-scrollbar,
.chat-log::-webkit-scrollbar {
  width: 4px;
}

#chat-log::-webkit-scrollbar-track,
.chat-log::-webkit-scrollbar-track {
  background: transparent;
}

#chat-log::-webkit-scrollbar-thumb,
.chat-log::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 128, 0.2);
  border-radius: 2px;
}

/* ========================================
   吹き出し
   ======================================== */
.chat-message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.5;
  position: relative;
  word-wrap: break-word;
  font-size: 14px;
}

.chat-message.bot.intro {
  max-width: 100%;
}

/* ユーザー発言 */
.chat-message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--key-color) 0%, var(--key-color-light) 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0, 0, 128, 0.2);
}

/* クリック可能なユーザー回答 */
.chat-message.user.editable {
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.chat-message.user.editable:hover {
  background: linear-gradient(135deg, var(--key-color-light) 0%, var(--accent-color) 100%);
  box-shadow: 0 4px 12px rgba(0, 0, 128, 0.3);
  transform: translateY(-1px);
}

.chat-message.user.editable::after {
  content: "✎";
  position: absolute;
  top: -6px;
  right: -6px;
  background: #fff;
  color: var(--key-color);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.chat-message.user.editable:hover::after {
  opacity: 1;
}

/* Bot発言 */
.chat-wrapper-bot {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  align-self: flex-start;
}

.chat-wrapper-bot img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.chat-message.bot {
  background-color: var(--bg-light);
  color: var(--text-dark);
  border-bottom-left-radius: 4px;
  font-weight: 500;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

/* ========================================
   タイピングインジケーター
   ======================================== */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  background: var(--bg-light);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--key-color);
  border-radius: 50%;
  opacity: 0.4;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0s; }

@keyframes typing-bounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ========================================
   入力フォーム
   ======================================== */
#chat-form {
  display: flex;
  gap: 10px;
  padding: 12px 16px 16px;
  background: #fff;
  border-top: 1px solid var(--border-color);
}

#user-input {
  flex: 1;
  padding: 12px 14px;
  border: 2px solid var(--border-color);
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  transition: all 0.3s ease;
  background-color: #fafbfc;
}

#user-input.active {
  border-color: var(--key-color);
  background-color: #fff;
  box-shadow: 0 0 0 3px rgba(0, 0, 128, 0.1);
}

#user-input.active:focus {
  border-color: var(--key-color);
  box-shadow: 0 0 0 4px rgba(0, 0, 128, 0.15);
}

#user-input.inactive {
  background-color: #f0f0f0;
  border-color: #ddd;
  color: #999;
  cursor: not-allowed;
}

#user-input::placeholder {
  color: #aaa;
  font-size: 13px;
}

#user-input.active::placeholder {
  color: #888;
}

#user-input.error {
  border-color: #e53935;
  background-color: #fff8f8;
}

#user-input.error:focus {
  box-shadow: 0 0 0 3px rgba(229, 57, 53, 0.12);
}

#chat-form button {
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--key-color) 0%, var(--key-color-light) 100%);
  color: #fff;
  border: none;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 128, 0.2);
}

#chat-form button:hover {
  background: linear-gradient(135deg, var(--key-color-light) 0%, var(--accent-color) 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 128, 0.25);
}

#chat-form button:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.input-error {
  color: #e53935;
  font-size: 12px;
  margin-top: 6px;
  padding: 6px 12px;
  background: #ffebee;
  border-radius: 8px;
  display: none;
}

/* ========================================
   選択肢ボタン
   ======================================== */
.option-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  padding-left: 46px;
}

.option-buttons button {
  padding: 10px 16px;
  background-color: #fff;
  border: 2px solid var(--border-color);
  border-radius: 20px;
  color: var(--text-dark);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.option-buttons button:hover:not(.disabled) {
  border-color: var(--key-color);
  background-color: var(--key-color);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 128, 0.2);
}

.option-buttons button.disabled {
  opacity: 0.5;
  cursor: default;
  background-color: #f5f5f5;
  border-color: #e0e0e0;
}

.option-buttons button.selected {
  background-color: var(--key-color);
  color: #fff;
  border-color: var(--key-color);
}

/* ========================================
   チャットランチャー
   ======================================== */
#chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: transparent;
  padding: 0;
  border: none;
  border-radius: 0;
  cursor: pointer;
  z-index: 9998;
  display: flex;
  align-items: center;
  transition: all 0.3s ease;
}

#chat-launcher:hover {
  transform: translateY(-2px);
}

#chat-launcher img {
  width: 220px;
  height: auto;
  margin: 0 !important;
  cursor: pointer;
}

#chat-launcher.is-close {
  background-color: #fff !important;
  color: var(--key-color) !important;
  border: 1px solid #999;
  font-size: 16px;
  padding: 8px 16px !important;
  border-radius: 50px;
}

.launcher-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.4;
}

.chat-float {
  animation: float-bob 3s ease-in-out infinite;
}

@keyframes float-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.chat-float.no-float {
  animation: none !important;
}

.chat-caption-inline {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  font-weight: normal;
  margin-top: 4px;
  line-height: 1.3;
}

.chat-label {
  font-weight: 600;
  font-size: 14px;
  color: #fff;
}

/* ========================================
   ローディング画面
   ======================================== */
#full-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 16px;
}

.loading-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #eee;
  border-top: 4px solid var(--key-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  margin-top: 20px;
  font-size: 16px;
  color: var(--key-color);
  font-weight: 600;
}

.loading-subtext {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-light);
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ========================================
   結果画面
   ======================================== */
.final-screen {
  padding: 32px 24px;
  text-align: center;
  background: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 400px;
}

.final-subtitle {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.final-title {
  font-size: 22px;
  color: var(--key-color);
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.4;
}

.final-description {
  font-size: 15px;
  color: var(--text-dark);
  margin-bottom: 8px;
}

.final-monthly {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 16px;
}

.simulation-id {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 24px;
  padding: 8px 12px;
  background: var(--bg-light);
  border-radius: 6px;
  display: inline-block;
}

.simulation-id strong {
  color: var(--key-color);
  font-family: 'Courier New', monospace;
  letter-spacing: 1px;
}

.red-text {
  color: #d32f2f;
  font-weight: 700;
  font-size: 1.3em;
}

.final-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.final-button {
  padding: 14px 24px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 28px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.final-button .btn-icon {
  margin-right: 8px;
  font-size: 16px;
}

.final-button.primary-button {
  background: linear-gradient(135deg, var(--key-color) 0%, var(--key-color-light) 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 128, 0.25);
}

.final-button.primary-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 128, 0.35);
}

.final-button.secondary-button {
  background: #fff;
  color: var(--key-color);
  border: 2px solid var(--key-color);
}

.final-button.secondary-button:hover {
  background: var(--key-color);
  color: #fff;
}

/* 注釈テキスト */
.final-disclaimer {
  margin-top: 20px;
  padding: 12px 16px;
  background: var(--bg-light);
  border-radius: 8px;
  font-size: 11px;
  color: var(--text-light);
  line-height: 1.6;
  text-align: left;
}

.retry-link {
  margin-top: 16px;
  text-align: center;
}

.retry-link a {
  color: var(--text-light);
  font-size: 13px;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: all 0.2s;
}

.retry-link a:hover {
  color: var(--key-color);
  border-bottom-color: var(--key-color);
}

/* ========================================
   アニメーション
   ======================================== */
.fade-in {
  animation: fadeIn 0.35s ease-out;
}

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

/* ========================================
   その他
   ======================================== */
.restart-chat-btn {
  position: absolute;
  bottom: 8px;
  right: 50px;
  background: transparent;
  border: none;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
  padding: 0;
  line-height: 1.2;
  z-index: 10;
}

.close-chat-btn {
  position: absolute;
  bottom: 8px;
  right: 15px;
  background: transparent;
  border: none;
  font-size: 16px;
  font-weight: bold;
  color: #fff;
  cursor: pointer;
  padding: 0;
  line-height: 1.2;
  z-index: 10;
}

.restart-chat-btn:hover,
.close-chat-btn:hover {
  opacity: 0.8;
}

#reset-chat {
  padding: 8px 12px;
  background-color: #f0f0f0;
  color: var(--text-dark);
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

#reset-chat:hover {
  background-color: #e0e0e0;
}

.reset-wrapper {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
  padding-right: 4px;
}

#chat-popup {
  opacity: 0;
  visibility: hidden;
  position: fixed;
  bottom: 80px;
  right: 24px;
  width: 380px;
  height: 500px;
  border-radius: 16px;
  overflow: hidden;
  z-index: 9998;
  background-color: #fff;
  border: none;
  box-shadow: 0 8px 32px rgba(0, 0, 128, 0.2);
  transition: opacity 0.4s ease, visibility 0.4s ease;
  pointer-events: none;
}

#chat-popup.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#chat-popup.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#chat-popup iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.answer-summary {
  margin: 12px 0;
  font-size: 12px;
  color: var(--text-light);
  text-align: left;
  padding: 12px 16px;
  background: var(--bg-light);
  border-radius: 12px;
}

.answer-summary-title {
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--key-color);
  font-size: 14px;
}

.answer-list {
  list-style: disc inside;
  padding-left: 0;
  margin: 0;
}

.answer-list li {
  margin-bottom: 4px;
}

/* ========================================
   質問文のスタイリング
   ======================================== */
.chat-message.bot .q-icon {
  font-size: 1.1em;
  margin-right: 4px;
}

.chat-message.bot .q-strong {
  font-weight: 700;
  color: var(--key-color);
}

.chat-message.bot .q-note {
  font-size: 0.85em;
  color: var(--text-light);
  font-weight: 400;
}

/* ========================================
   スキップボタン
   ======================================== */
.skip-category-button {
  display: block;
  margin: 8px 0 4px 46px;
  padding: 8px 16px;
  background: transparent;
  border: 1px dashed var(--text-light);
  border-radius: 16px;
  color: var(--text-light);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.skip-category-button:hover:not(.disabled) {
  border-color: var(--key-color);
  color: var(--key-color);
  background: rgba(0, 0, 128, 0.05);
}

.skip-category-button.disabled {
  opacity: 0.5;
  cursor: default;
  border-style: solid;
  background: #f5f5f5;
}

/* ========================================
   自由入力ボタン（ハイブリッド入力用）
   ======================================== */
.free-input-button {
  display: block;
  margin: 8px 0 4px 46px;
  padding: 10px 18px;
  background: #fff;
  border: 2px solid var(--accent-color);
  border-radius: 20px;
  color: var(--accent-color);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.free-input-button:hover:not(.disabled) {
  background: var(--accent-color);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(64, 64, 191, 0.25);
}

.free-input-button.disabled {
  opacity: 0.5;
  cursor: default;
  background: #f5f5f5;
  border-color: #e0e0e0;
  color: var(--text-light);
}

.free-input-button.selected {
  background: var(--accent-color);
  color: #fff;
  border-color: var(--accent-color);
}

/* ========================================
   スマホ対応
   ======================================== */
@media (max-width: 500px) {
  .chat-container {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 100vh;
    border-radius: 0;
  }

  #chat-log,
  .chat-log {
    max-height: calc(100vh - 200px);
  }

  #chat-launcher {
    bottom: 8px !important;
    right: 8px !important;
    border-radius: 24px;
    font-size: 13px;
    padding: 14px 20px !important;
  }

  .chat-label {
    font-size: 13px;
  }

  .chat-caption-inline {
    font-size: 10px;
  }

  #chat-popup {
    right: 8px;
    left: 8px;
    width: auto;
    bottom: 70px;
    height: calc(100vh - 100px);
  }

  .option-buttons {
    padding-left: 0;
  }

  .option-buttons button {
    padding: 10px 14px;
    font-size: 13px;
  }

  .skip-category-button {
    margin-left: 0;
  }

  .free-input-button {
    margin-left: 0;
  }

  .final-screen {
    padding: 24px 20px;
  }

  .final-title {
    font-size: 20px;
  }

  #chat-launcher img {
    width: 180px;
  }
}
