/*
 * Ciras ご案内アシスタント スタイル — meta.ai 風（カラフルなグラデーション）
 * エアリーな余白・少ない罫線・大きな丸い入力欄＋丸い送信ボタン・吹き出しを弱めた
 * 見せ方・象徴グラデーションのオーブ。色は tokens.css の CSS 変数のみ参照。
 */

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

:root {
  font-size: 100%; /* 16px 基準。サイズは rem で文字拡大に追従 */
}

html,
body {
  margin: 0;
  height: 100dvh;
  /* ページ自体はスクロールさせず、下部の入力欄を固定する。
     スマホでスクロール（引き上げ・端でのラバーバンド）しても入力欄が動かないようにする。 */
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background-color: var(--color-bg-page);
  background-image: var(--glow);
  background-attachment: fixed;
  background-repeat: no-repeat;
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  font-weight: 400;
  font-size: 1.0625rem; /* 17px */
  line-height: 1.7;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── レイアウト（中央 768px・エアリー） ───────────── */
.app {
  --app-pad: 16px;
  display: flex;
  flex-direction: column;
  max-width: 768px;
  height: 100dvh;
  margin: 0 auto;
  padding: 0 var(--app-pad);
  /* ログだけをスクロールさせ、下部の入力・リンクは固定する。 */
  overflow: hidden;
}

/* ── ヘッダー（ミニマル・罫線なし） ─────────────── */
.app__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 4px 12px;
}

.brand__mark {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--color-divider);
  object-fit: contain;
  padding: 4px;
  box-shadow: var(--shadow-bubble);
}

.brand__name {
  margin: 0;
  font-size: 1.5rem; /* 24px */
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.brand__tagline {
  margin: 2px 0 0;
  font-size: 0.8125rem; /* 13px */
  color: var(--color-text-sub);
  line-height: 1.4;
}

/* ブランド名が長くても、右端のメニューボタンを押し出さないようにする。 */
.brand__text {
  min-width: 0;
}

/* 右上メニューの開閉ボタン（ハンバーガー）。 */
.menu-toggle {
  flex: 0 0 auto;
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: 14px;
  box-shadow: var(--shadow-bubble);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}

.menu-toggle:hover {
  background: var(--color-tint);
}

.menu-toggle__icon {
  width: 22px;
  height: 22px;
  display: block;
}

/* ── チャットログ ─────────────────────────────── */
.log {
  flex: 1 1 auto;
  /* flex 子が内容より縮んでスクロールできるようにする（固定フッターの前提）。 */
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 14px 4px 20px;
  overflow-y: auto;
  overflow-x: hidden;
  /* ログの端まで来ても、ページ側へスクロールを伝播させない（入力欄が動くのを防ぐ）。 */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

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

/* ボット：グラデーションのオーブ＋地の文に近い見せ方 */
.msg-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  max-width: 96%;
  align-self: flex-start;
  animation: msgIn 0.28s ease-out;
}

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--color-divider);
  object-fit: contain;
  padding: 3px;
  box-shadow: var(--shadow-bubble);
}

.msg {
  max-width: 100%;
  font-size: 1.0625rem; /* 17px */
  line-height: 1.75;
  word-wrap: break-word;
  word-break: break-word;
}

.msg a {
  color: var(--color-accent-text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* AI 返答はライトグレーの吹き出しで囲む */
.msg--bot {
  padding: 12px 16px;
  background: var(--color-ai-bubble);
  color: var(--color-text);
  border-radius: 22px;
  border-bottom-left-radius: 8px;
}

/* ユーザー発言だけ控えめな囲み */
.msg--user {
  align-self: flex-end;
  max-width: 80%;
  padding: 12px 16px;
  background: var(--color-user-bubble);
  color: var(--color-text);
  border-radius: 22px;
  border-bottom-right-radius: 8px;
  animation: msgIn 0.28s ease-out;
}

.msg--user a {
  color: var(--color-accent-text);
}

.msg--error {
  align-self: flex-start;
  max-width: 96%;
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--color-error-bg);
  color: var(--color-error);
  border: 1px solid var(--color-error-border);
  border-radius: 18px;
  animation: msgIn 0.28s ease-out;
}

/* 相談回数の上限などのやわらかい案内（エラーではないので赤くしない）。 */
.msg--limit {
  align-self: flex-start;
  max-width: 96%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  background: var(--color-tint);
  color: var(--color-text);
  border: 1px solid var(--color-divider);
  border-radius: 18px;
  line-height: 1.6;
  animation: msgIn 0.28s ease-out;
}

.msg-limit__cta {
  align-self: flex-start;
  font-weight: 700;
  color: var(--color-accent-text);
  text-decoration: none;
}

.msg-limit__cta:hover {
  text-decoration: underline;
}

/* 応答待ちインジケータ */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
}

.typing__dots {
  display: inline-flex;
  gap: 6px;
}

.typing__dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b9b3e8;
  animation: typing-bounce 0.9s ease-in-out infinite;
}

.typing__dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing__dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.typing__text {
  font-size: 0.9375rem;
  color: var(--color-text-sub);
}

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

/* ── 提案チップ（タップで相談を始める入口） ─────── */
.starters {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-self: stretch;
  padding: 6px 0 2px;
}

.starters__heading {
  margin: 0 0 2px;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-accent-text);
}

/* 選択肢ボタンの下に添える「文章で書いてもよい」案内（淡色・小さめ・控えめ）。 */
.starters__note {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--color-text-sub);
}

.starter {
  padding: 13px 18px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  line-height: 1.45;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: 18px;
  box-shadow: var(--shadow-bubble);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s, background 0.15s;
}

.starter:hover {
  border-color: transparent;
  background: var(--color-tint);
  box-shadow: 0 6px 20px rgba(110, 92, 246, 0.16);
}

.starter:active {
  transform: scale(0.99);
}

/* ── 入力バー（浮遊する丸いピル＋丸い送信ボタン） ── */
/* ── 下部ドック（入力欄＋出口リンク＋新しい会話。ここは固定し、上のログだけスクロール） ── */
.dock {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* 画面幅いっぱいの帯にして、上のログとの区切りを出す。 */
  margin: 0 calc(-1 * var(--app-pad));
  padding: 10px var(--app-pad) calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--color-bg-page);
  border-top: 1px solid var(--color-divider);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0;
  padding: 8px 8px 8px 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: 28px;
  box-shadow: var(--shadow-pill);
}

.composer:focus-within {
  border-color: transparent;
  box-shadow: var(--shadow-pill), 0 0 0 2px #fff,
    0 0 0 4px var(--ring);
}

.composer__input {
  flex: 1 1 auto;
  min-height: 28px;
  max-height: 168px;
  resize: none;
  padding: 9px 0;
  font-family: inherit;
  font-size: 1.0625rem;
  line-height: 1.55;
  color: var(--color-text);
  background: transparent;
  border: 0;
}

.composer__input:focus,
.composer__input:focus-visible {
  outline: none;
}

.composer__input::placeholder {
  color: var(--color-text-sub);
}

.composer__send {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--grad-accent);
  color: var(--color-on-primary);
  box-shadow: 0 4px 14px rgba(123, 92, 255, 0.4);
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s, opacity 0.15s;
}

.composer__send:hover {
  filter: brightness(1.06);
}

.composer__send:active {
  transform: scale(0.94);
}

.composer__send:disabled {
  background: var(--color-disabled-bg);
  color: var(--color-disabled-text);
  box-shadow: none;
  cursor: default;
}

.composer__send-icon {
  width: 20px;
  height: 20px;
  display: block;
}

/* ── 右上メニュー（クリックで開閉するドロップダウン） ───────── */
.menu[hidden] {
  display: none;
}

.menu {
  position: fixed;
  inset: 0;
  z-index: 150;
}

/* 画面外クリックを拾う透明レイヤー（面は暗くしない＝ドロップダウンらしく軽く）。 */
.menu__overlay {
  position: absolute;
  inset: 0;
}

/* メニュー本体。トグルの真下・右端に JS で位置を合わせる（top/right は控えの初期値）。 */
.menu__panel {
  position: absolute;
  top: 64px;
  right: 12px;
  width: min(260px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  padding: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  animation: menuIn 0.14s ease-out;
}

@keyframes menuIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.menu__exits {
  display: flex;
  flex-direction: column;
}

/* メニュー項目（出口リンク・新しい会話・ログアウト）を同じ行体裁に揃える。 */
.menu__exits a,
.menu__item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: left;
  color: var(--color-text);
  text-decoration: none;
  background: none;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}

.menu__exits a:hover,
.menu__item:hover {
  background: var(--color-tint);
}

/* 外部リンク（別タブで開く）には、右寄せで控えめな目印を添える。 */
.menu__exits a::after {
  content: "↗";
  margin-left: auto;
  font-size: 0.85em;
  color: var(--color-accent-text);
  opacity: 0.85;
}

/* 「新しい会話」と出口リンクの間に、細い区切りを入れて整理する。 */
.menu__exits + .menu__item {
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--color-divider);
}

/* ログアウトは副次的な操作なので、控えめな色にする。 */
.menu__item--muted {
  color: var(--color-text-sub);
  font-weight: 600;
}

/* hidden 属性を確実に効かせる（未契約時はログアウトを隠す）。 */
.menu__item[hidden] {
  display: none;
}

/* ── 出口の説明カード（リンクを押すと挟む） ─────── */
.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 18, 40, 0.5);
  backdrop-filter: blur(2px);
}

.modal__card {
  position: relative;
  width: 100%;
  max-width: 440px;
  padding: 28px 24px;
  text-align: center;
  background: var(--color-surface);
  border-radius: 24px;
  box-shadow: var(--shadow-card);
}

.modal__title {
  margin: 0 0 8px;
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.modal__desc {
  margin: 0 0 16px;
  font-size: 1.0625rem;
  line-height: 1.7;
  text-align: left;
  color: var(--color-text);
}

.modal__note {
  margin: 0 0 22px;
  font-size: 0.8125rem;
  color: var(--color-text-sub);
}

.modal__open {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 0 24px;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--color-on-primary);
  background: var(--grad-cta);
  border-radius: 999px;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(90, 68, 232, 0.3);
  transition: filter 0.15s, transform 0.1s;
}

.modal__open:hover {
  filter: brightness(1.05);
}

.modal__open:active {
  transform: scale(0.99);
}

.modal__back {
  margin-top: 14px;
  min-height: 40px;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-text-sub);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}

/* ── 入口（契約者ゲート：選択画面＋会社ID入力） ──── */
.entry[hidden] {
  display: none;
}

.entry {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
  background-color: var(--color-bg-page);
  background-image: var(--glow);
  overflow-y: auto;
}

.entry__card {
  width: 100%;
  max-width: 440px;
  padding: 28px 24px 22px;
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: 24px;
  box-shadow: var(--shadow-card);
}

.entry__mark {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--color-divider);
  object-fit: contain;
  padding: 6px;
  box-shadow: var(--shadow-bubble);
}

.entry__title {
  margin: 14px 0 6px;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.entry__lead {
  margin: 0 0 18px;
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--color-text-sub);
}

.entry__choice {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  margin-top: 12px;
  /* 右側は「›」の分だけ広めに空ける。 */
  padding: 15px 44px 15px 18px;
  text-align: left;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  /* 枠をはっきり見せて「押せるカード」だと分かるようにする。 */
  border: 1.5px solid var(--color-border);
  border-radius: 18px;
  box-shadow: var(--shadow-bubble);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s, background 0.15s;
}

/* 押せる入口ボタンには右端に「›」を添え、タップできることを明確にする。 */
.entry__choice:not(:disabled)::after {
  content: "›";
  position: absolute;
  top: 50%;
  right: 18px;
  transform: translateY(-50%);
  font-size: 1.5rem;
  line-height: 1;
  color: var(--color-text-sub);
  transition: color 0.15s, transform 0.15s;
}

/* ホバー時は枠をブランド色にし、面を淡く色づけ・少し持ち上げて、反応をはっきり示す。 */
.entry__choice:not(:disabled):hover {
  border-color: var(--color-primary);
  background: var(--color-tint);
  box-shadow: 0 8px 22px rgba(110, 92, 246, 0.2);
  transform: translateY(-1px);
}

.entry__choice:not(:disabled):hover::after {
  color: var(--color-primary);
  transform: translateY(-50%) translateX(3px);
}

.entry__choice:not(:disabled):active {
  transform: translateY(0) scale(0.99);
}

/* キーボード操作でも分かるよう、フォーカス時も枠を強調する。 */
.entry__choice:not(:disabled):focus-visible {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-tint), 0 8px 22px rgba(110, 92, 246, 0.2);
}

/* 調整中で押せない入口ボタン（面をグレーにして「押せない」ことを示し、ホバー効果は消す）。 */
.entry__choice:disabled,
.entry__choice--disabled {
  opacity: 0.7;
  cursor: not-allowed;
  color: var(--color-text-sub);
  background: var(--color-ai-bubble);
  border-color: var(--color-divider);
  box-shadow: none;
}
.entry__choice:disabled:hover,
.entry__choice--disabled:hover {
  border-color: var(--color-divider);
  background: var(--color-ai-bubble);
  box-shadow: none;
  transform: none;
}
.entry__choice:disabled:active,
.entry__choice--disabled:active {
  transform: none;
}

.entry__choice-title {
  font-size: 1.0625rem;
  font-weight: 700;
}

/* 「調整中」バッジ（見出しの右に小さく添える）。 */
.entry__badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  font-size: 0.6875rem;
  font-weight: 700;
  vertical-align: middle;
  border-radius: 999px;
  background: var(--color-ai-bubble);
  color: var(--color-text-sub);
}

.entry__choice-sub {
  font-size: 0.8125rem;
  color: var(--color-text-sub);
  line-height: 1.5;
}

.entry__gate[hidden] {
  display: none;
}

.entry__input {
  width: 100%;
  margin: 4px 0 6px;
  padding: 13px 16px;
  font-family: inherit;
  font-size: 1.0625rem;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
}

.entry__input:focus,
.entry__input:focus-visible {
  outline: none;
  border-color: transparent;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ring);
}

.entry__error {
  margin: 0 0 10px;
  font-size: 0.875rem;
  color: var(--color-error);
  text-align: left;
}

.entry__error[hidden] {
  display: none;
}

.entry__submit {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  margin-top: 6px;
  padding: 0 24px;
  font-family: inherit;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--color-on-primary);
  background: var(--grad-cta);
  border: 0;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(90, 68, 232, 0.3);
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s, opacity 0.15s;
}

.entry__submit:hover {
  filter: brightness(1.05);
}

.entry__submit:active {
  transform: scale(0.99);
}

.entry__submit:disabled {
  opacity: 0.6;
  cursor: default;
}

.entry__back {
  margin-top: 12px;
  min-height: 40px;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-text-sub);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}

/* 注意書き。文言はスマートに整え、アクセントの紫で少し目立たせる。 */
.entry__note {
  margin: 18px 0 0;
  font-size: 0.8125rem;
  line-height: 1.6;
  font-weight: 500;
  color: var(--color-accent-text);
}

/* リード文・注意書きを「文の切れ目」で2行に固定する。
   各文をひとまとまり（inline-block）にして、途中で不自然に折り返さないようにする。
   端末幅で改行位置がばらつく違和感を防ぐため、PC・スマホ共通で <br> の位置で改行する。 */
.entry__nb {
  display: inline-block;
}

/* ── フォーカス可視化（消去禁止） ───────────────── */
a:focus-visible,
button:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--color-accent-text);
  outline-offset: 2px;
}

/* 入力ピルはフォーカス時に :focus-within のリングで示すため二重枠を避ける */
.composer__input:focus-visible {
  outline: none;
}

/* ── レスポンシブ ─────────────────────────────── */
@media (max-width: 600px) {
  body {
    font-size: 1rem;
  }
  .app {
    --app-pad: 12px;
  }
  .brand__name {
    /* 右上のメニューボタンと同居できるよう、スマホでは1行に収まる大きさにする。 */
    font-size: 1.1875rem;
  }
  .msg {
    font-size: 1rem;
  }
  .composer {
    padding-left: 18px;
    border-radius: 26px;
  }
}

@media (max-width: 380px) {
  .brand__tagline {
    display: none;
  }
  .starter {
    font-size: 0.9375rem;
    padding: 12px 16px;
  }
  .composer__send {
    width: 42px;
    height: 42px;
  }
}

/* ── モーション設定 ───────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
