/* ===============================================================
   1. Global Settings & Resets
   グローバル設定とリセット
   =============================================================== */
:root {
  /* --- カラーパレット --- */
  --primary-color: #00748A;
  --primary-dark: #005f70;
  --primary-gradient-start: #61b265;
  --primary-gradient-end: #007f87;
  --secondary-color: #00848C;
  --body-bg: #8297ac;
  --chat-container-bg: #ffffff;
  --chat-messages-bg: #efede0;
  --bot-message-bg: #ffffff;
  --user-message-bg: var(--secondary-color);
  --text-color-light: #ffffff;
  --text-color-dark: #212121;
  --text-color-medium: #555;
  --text-color-default: #111111;
  --choice-button-text: #007387;
  --choice-button-border: #007387;
  --choice-button-bg: #ffffff;
  --choice-button-hover-bg: #e5f1f4;
  --disabled-bg: #f0f0f0;
  --disabled-text: #aaa;
  --disabled-border: #ddd;
  --error-color: red;
  --link-color: #007bff;
  --link-hover-color: #0056b3;
  --icon-placeholder-bg: #ddd;
}

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

html, body {
  height: 100%;
  overflow: auto; 
  font-family: 'Noto Sans JP', sans-serif;
  color: var(--text-color-default);
}

body {
  background-color: var(--body-bg);
  display: flex;
  justify-content: center;
  align-items: center;
  overscroll-behavior-y: contain;
}

/* ===============================================================
   2. Layout Styles
   主要なレイアウト
   =============================================================== */
.chat-container {
  width: 100%;
  max-width: 560px;
  height: 100%;
  background-color: var(--chat-container-bg);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px 1px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden; 
}
@media (max-width: 560px) {
  .chat-container {
    border-radius: 0;
    box-shadow: none;
    max-width: 100%;
  }
}

.chat-header {
  background: linear-gradient(135deg, var(--primary-gradient-start) 0%, var(--primary-gradient-end) 60%);
  color: var(--text-color-light);
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  text-align: center;
  font-size: 1.1em;
  font-weight: 500;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px 1px rgba(0,0,0,0.15);
}

.chat-header-title {
  margin-bottom: 5px;
}
.progress-bar-container {
  width: 100%; 
  height: 8px;
  background-color: var(--primary-dark);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar {
  width: 0%;
  height: 100%;
  background-color: var(--text-color-light);
  border-radius: 4px;
  transition: width 0.3s ease-in-out;
}

.chat-messages {
  flex-grow: 1;
  padding: 16px 20px 50px;
  overflow-y: auto; 
  background-color: var(--chat-messages-bg);
  display: flex;
  flex-direction: column;
  gap: 13px; 
  -webkit-overflow-scrolling: touch; 
  scroll-behavior: smooth;
}

/* ===============================================================
   3. Component: Banner
   バナー画像
   =============================================================== */
.banner-image-wrapper {
  margin-bottom: 5px;
}

.chat-banner-image {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 0;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);  
}

/* ===============================================================
   4. Component: Messages
   メッセージフキダシ
   =============================================================== */
.message-wrapper {
  display: flex;
  width: 100%;
  align-items: flex-end; 
}

.bot-message-wrapper {
  justify-content: flex-start;
}

.user-message-wrapper {
  justify-content: flex-end;
}

.bot-icon {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  margin-right: 5px;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  background-color: var(--icon-placeholder-bg); 
}

.message {
  padding: 10px 14px;
  border-radius: 18px;
  word-wrap: break-word;
  font-size: 0.95em;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.bot-message-wrapper .message { 
  max-width: 80%;
  background-color: var(--bot-message-bg);
  color: var(--text-color-dark);
  border-bottom-left-radius: 4px;
}
.bot-message-wrapper .message.error-text {
  color: var(--error-color);
}
.bot-message-wrapper .message a { 
  color: var(--link-color); 
  text-decoration: underline;
}
.bot-message-wrapper .message a:hover {
  color: var(--link-hover-color);
}

.user-message-wrapper .message {
  background-color: var(--user-message-bg);
  color: var(--text-color-light);
  border-bottom-right-radius: 4px;
}

/* ★修正: ebookボタン用のスタイルを追加 */
.ebook-button-message-content {
  padding: 0 !important; 
  background-color: transparent !important; 
  box-shadow: none !important; 
  width: 100%; 
  max-width: 100% !important; 
}
.ebook-button-link {
  display: flex; 
  align-items: center; 
  justify-content: center; 
  width: 100%; 
  padding: 12px 15px;
  background-color: var(--primary-color); 
  color: var(--text-color-light) !important; 
  border: none;
  border-radius: 8px; 
  font-size: 1em;
  font-weight: 500;
  text-align: center;
  text-decoration: none !important; 
  cursor: pointer;
  transition: background-color 0.2s;
  box-sizing: border-box;
}
.ebook-button-link:hover {
  background-color: var(--primary-dark); 
}
.ebook-button-link svg { 
  width: 20px; 
  height: 20px;
  margin-right: 8px; 
  stroke: var(--text-color-light); 
}

/* ===============================================================
   5. Component: Input Area & Elements
   各種入力フォームと要素
   =============================================================== */
.input-container-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 10px;  
  box-sizing: border-box;
}
.input-container-wrapper.inputs-disabled {
  opacity: 0.6;
  pointer-events: none;
}

/* --- 5a. Choice Buttons (選択肢ボタン) --- */
.choices-container {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 480px;
  box-sizing: border-box;
}

.choice-button {
  background-color: var(--choice-button-bg);
  border: 1px solid var(--choice-button-border);
  color: var(--choice-button-text);
  padding: 12px 6px;
  font-size: 0.9em;
  border-radius: 20px;
  cursor: pointer;
  text-align: center;
  transition: background-color 0.2s, color 0.2s, box-shadow 0.2s;
  width: 100%;
  box-sizing: border-box;
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1.3;
  display: flex; 
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.choice-button:hover:not(:disabled) {
  background-color: var(--choice-button-hover-bg);
  box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px 1px rgba(0,0,0,0.15);
}
.choice-button:disabled {
  background-color: var(--disabled-bg);
  color: var(--disabled-text);
  border-color: var(--disabled-border);
  cursor: not-allowed;
}
.final-consent-submit-button {
  background-color: var(--primary-color); 
  color: var(--text-color-light);
  border-color: var(--primary-dark); 
  max-width: 480px;
  padding: 12px;
  font-size: 1em;
}
.final-consent-submit-button:hover:not(:disabled) {
  background-color: var(--primary-dark); 
}
.final-consent-submit-button svg { 
  margin-left: 8px; 
  stroke: var(--text-color-light); 
  width: 16px; 
  height: 16px;
}

/* --- 5b. Text Inputs (テキスト入力欄) --- */
.input-area,
.paired-input-container {
  display: flex;
  width: 100%; 
  max-width: 480px;
  background-color: var(--bot-message-bg);
  border-radius: 30px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
  padding: 15px;
}
.paired-input-container {
  flex-direction: column;
  gap: 7px; 
  border-radius: 16px;
}
.input-area {
  align-items: center;
}
.paired-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.paired-input-row label {
  font-size: 0.9em;
  color: var(--text-color-medium);
  flex-shrink: 0;
  width: 30px;
  text-align: center;
}
.input-icon-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px; 
  margin: 0 8px 0 5px;
}
.input-icon-container svg {
  width: 20px; 
  height: 20px;
  stroke: var(--text-color-medium); 
}
.input-area input,
.paired-input-row input {
  flex-grow: 1; 
  border: none;
  background-color: transparent; 
  outline: none; 
  padding: 8px;
  min-width: 0;
  font-size: 1em;  
}
.paired-input-row input {
  padding: 10px 15px;
  border: 1px solid #ccc;
  border-radius: 15px;
  font-size: 1em;
  background-color: var(--bot-message-bg);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.paired-input-row input:hover {
  border-color: #a0a0a0; 
}
.paired-input-row input:focus {
  border-color: var(--primary-color) !important; 
  box-shadow: 0 0 0 2px rgba(0, 116, 138, 0.2) !important; 
}
.input-area button,
.paired-input-row .paired-input-send-button {
  padding: 0; 
  width: 34px; 
  height: 34px; 
  background-color: #b0b0b0; 
  color: var(--text-color-light);
  border: none; 
  border-radius: 50%; 
  cursor: not-allowed; 
  display: flex;
  align-items: center; 
  justify-content: center; 
  transition: background-color 0.2s; 
  flex-shrink: 0;
}
.paired-input-row .paired-input-send-button {
  width: 40px;
  height: 40px;
}
.input-area button.enabled,
.paired-input-row .paired-input-send-button.enabled { 
  background-color: var(--primary-color) !important; 
  cursor: pointer; 
}
.input-area button.enabled:hover,
.paired-input-row .paired-input-send-button.enabled:hover { 
  background-color: var(--primary-dark) !important; 
}
.input-area button svg { 
  width: 18px; 
  height: 18px; 
}
.paired-input-row .paired-input-send-button svg { 
  width: 20px; 
  height: 20px; 
}
.paired-input-row .placeholder { 
  visibility: hidden; 
}

/* --- 5c. Calendar (カレンダー) --- */
.calendar-container {
  background-color: var(--bot-message-bg); 
  border-radius: 8px; 
  padding: 15px; 
  width: 100%;
  max-width: 480px;
  margin: 0 auto; 
  font-size: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3), 0 6px 10px 4px rgba(0,0,0,0.15);
}
.calendar-header {
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  margin-bottom: 5px; 
}
.calendar-month-year { 
  font-weight: 500; 
  font-size: 1.2em; 
  color: var(--text-color-dark); 
}
.calendar-nav-buttons button { 
  background: none; 
  border: 1px solid var(--primary-color); 
  color: var(--primary-color);
  cursor: pointer;
  padding: 5px 10px; 
  border-radius: 15px; 
  transition: background-color 0.2s, color 0.2s; 
  margin-left: 5px; 
}
.calendar-nav-buttons button:hover:not(:disabled) { 
  background-color: var(--primary-color); 
  color: var(--text-color-light); 
}
.calendar-nav-buttons button:disabled { 
  border-color: #BDBDBD; 
  color: #BDBDBD; 
  cursor: not-allowed; 
}
.calendar-grid { 
  display: grid; 
  grid-template-columns: repeat(7, 1fr); 
  gap: 4px; 
  text-align: center; 
}
.calendar-day-name {
  padding: 10px 0;
  font-size: 0.9em;
  font-weight: 500; 
  color: #757575; 
  border-bottom: 1px solid #E0E0E0; 
  margin-bottom: 5px;
}
.calendar-day-name-sun { color: #E57373 !important; } 
.calendar-day-name-sat { color: #64B5F6 !important; } 
.calendar-day {
  padding: 0;
  cursor: pointer; 
  border-radius: 50%;
  transition: background-color 0.2s, color 0.2s, transform 0.1s;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center; 
}
.calendar-day:hover:not(.disabled):not(.empty):not(.selected) { 
  background-color: var(--choice-button-hover-bg); 
  transform: scale(1.05); 
}
.calendar-day.selected { 
  background-color: var(--primary-color); 
  color: var(--text-color-light); 
  font-weight: 500; 
}
.calendar-day.today { 
  font-weight: 500; 
  border: 2px solid var(--primary-color); 
}
.calendar-day.disabled, .calendar-day.empty { 
  cursor: default; 
  color: #BDBDBD; 
  background-color: #FAFAFA; 
}
.calendar-day.empty { 
  background-color: transparent !important; 
}
.calendar-actions {
  display: flex; 
  justify-content: flex-end; 
  margin-top: 10px;
  padding-top: 10px; 
  border-top: 1px solid #E0E0E0;
}
.calendar-submit-button {
  background-color: #BDBDBD; 
  color: var(--text-color-light); 
  border: none;
  width: 40px; 
  height: 40px; 
  border-radius: 50%; 
  cursor: not-allowed; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  transition: background-color 0.2s;
}
.calendar-submit-button.enabled { 
  background-color: var(--primary-color); 
  cursor: pointer; 
}
.calendar-submit-button.enabled:hover { 
  background-color: var(--primary-dark); 
}
.calendar-submit-button svg { 
  width: 20px; 
  height: 20px; 
  stroke: var(--text-color-light); 
}

/* ===============================================================
   6. Component: Summary & Consent
   最終確認画面と同意文
   =============================================================== */
.summary-area-wrapper {
  background-color: var(--bot-message-bg);
  border-radius: 20px; 
  padding: 15px;
  overflow-y: auto;
  font-size: 0.9em;
  border: 1px solid #e0e0e0;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.summary-area-wrapper h3 {
  font-size: 1em;
  font-weight: 500;
  color: var(--primary-color);
  margin: 0 0 10px 0;
}
.summary-area-wrapper ul {
  list-style: none;
}
.summary-area-wrapper li {
  margin-bottom: 6px;
  line-height: 1.4;
}
.summary-item-label {
  font-weight: 500;
  color: var(--text-color-medium);
}
.summary-item-value {
  color: #222;
  word-break: break-all; 
}

.summary-adjacent-consent-text { 
  font-size: 0.7em;
  color: var(--text-color-medium);
  text-align: left; 
  padding: 0 0 0 48px; 
  max-width: calc(100% - 48px); 
  word-wrap: break-word; 
}
.summary-adjacent-consent-text a {
  color: var(--link-color);
  text-decoration: underline;
}
.summary-adjacent-consent-text a:hover {
  color: var(--link-hover-color);
}

/* ===============================================================
   7. Component: Modal
   モーダルウィンドウ
   =============================================================== */
.modal-overlay {
  position: fixed; 
  top: 0; 
  left: 0; 
  width: 100%; 
  height: 100%;
  background-color: rgba(0,0,0,0.6); 
  display: none;
  justify-content: center; 
  align-items: center; 
  z-index: 1000;
}
.modal-content {
  background-color: var(--bot-message-bg); 
  padding: 25px; 
  border-radius: 8px;
  width: 90%; 
  max-width: 500px; 
  max-height: 80vh; 
  overflow-y: auto;
  position: relative;
  box-shadow: 0 2px 3px rgba(0,0,0,0.3), 0 8px 12px 6px rgba(0,0,0,0.15);
}
.modal-close-button {
  position: sticky; 
  top: 10px; 
  float: right; 
  margin: -10px -10px 0 0;
  font-size: 1.8em;
  font-weight: bold;
  cursor: pointer;
  border: none;
  background: none;
  color: #888;
  z-index: 1001; 
}
.modal-close-button:hover { 
  color: #000; 
}
#modalBody h3 {
  font-size: 1.1em;
  text-align: center;
  font-weight: bold;
  margin-bottom: 1em;
}
#modalBody h4 {
  font-size: 1em;
  font-weight: bold;
  margin-top: 1.5em;
  margin-bottom: 0.8em;
  border-left: 4px solid var(--primary-color);
  padding-left: 8px;
}
#modalBody p, #modalBody ul {
  font-size: 0.8em;
  line-height: 1.6;
}
#modalBody ul {
  padding-left: 20px;
  list-style-type: disc;
}
#modalBody li {
  margin-bottom: 0.5em;
}

/* ===============================================================
   8. Animations
   アニメーション（ローディングなど）
   =============================================================== */
.loading-dots span {
  display: inline-block;
  width: 5px; 
  height: 5px;
  background-color: currentColor; 
  border-radius: 50%;
  margin-left: 2px;
  animation: loadingDots 1.4s infinite ease-in-out both;
}
.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
.loading-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes loadingDots {
  0%, 80%, 100% {
    transform: scale(0);
  } 40% {
    transform: scale(1.0);
  }
}
