/* つだ建材 チャットボット ウィジェット
   既存テーマの影響を受けないよう、すべて .tsc- 接頭辞 + 明示指定で閉じています */

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

.tsc-root {
  --tsc-brand: #802726;
  --tsc-brand-dark: #7e1313;
  --tsc-ink: #333;
  --tsc-muted: #6d6d6d;
  --tsc-line: #e3ddd9;
  --tsc-bg: #fff;
  --tsc-bot-bg: #f5f1ee;
  --tsc-radius: 14px;
  --tsc-shadow: 0 8px 32px rgba(0, 0, 0, .18);

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99990;
  font-family: "Yu Gothic", "游ゴシック", YuGothic, "游ゴシック体",
               "ヒラギノ角ゴ Pro W3", "メイリオ", sans-serif;
  font-size: 15px;
  line-height: 1.7;
  color: var(--tsc-ink);
}

/* ---------- 起動ボタン ---------- */

.tsc-launcher {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 22px 13px 18px;
  border: none;
  border-radius: 999px;
  background: var(--tsc-brand);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
  box-shadow: var(--tsc-shadow);
  transition: transform .2s ease, background-color .2s ease;
}

.tsc-launcher:hover { background: var(--tsc-brand-dark); transform: translateY(-2px); }
.tsc-launcher:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.tsc-launcher svg { width: 22px; height: 22px; flex: none; }

.tsc-root[data-open="true"] .tsc-launcher { display: none; }

/* 未読バッジ */
.tsc-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #d64545;
  color: #fff;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
}

/* ---------- パネル ---------- */

.tsc-panel {
  display: none;
  flex-direction: column;
  width: min(390px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 96px));
  border-radius: var(--tsc-radius);
  background: var(--tsc-bg);
  box-shadow: var(--tsc-shadow);
  overflow: hidden;
}

.tsc-root[data-open="true"] .tsc-panel {
  display: flex;
  animation: tsc-in .24s cubic-bezier(.2, .8, .3, 1);
}

@keyframes tsc-in {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tsc-root[data-open="true"] .tsc-panel { animation: none; }
  .tsc-launcher { transition: none; }
}

/* ---------- ヘッダ ---------- */

.tsc-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--tsc-brand);
  color: #fff;
  flex: none;
}

.tsc-header-title { font-size: 15px; font-weight: 700; margin: 0; line-height: 1.4; }
.tsc-header-sub   { font-size: 11.5px; opacity: .85; margin: 0; line-height: 1.4; }
.tsc-header-text  { flex: 1 1 auto; min-width: 0; }

.tsc-close {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  cursor: pointer;
}
.tsc-close:hover { background: rgba(255, 255, 255, .28); }
.tsc-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.tsc-close svg { width: 16px; height: 16px; }

/* ---------- メッセージ ---------- */

.tsc-log {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 8px;
  background: #fbf9f8;
}

.tsc-msg { display: flex; margin-bottom: 14px; }
.tsc-msg-bot  { justify-content: flex-start; }
.tsc-msg-user { justify-content: flex-end; }

.tsc-bubble {
  max-width: 84%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14.5px;
  word-break: break-word;
}

.tsc-msg-bot .tsc-bubble {
  background: var(--tsc-bot-bg);
  border-top-left-radius: 4px;
}
.tsc-msg-user .tsc-bubble {
  background: var(--tsc-brand);
  color: #fff;
  border-top-right-radius: 4px;
}

.tsc-bubble small { display: inline-block; margin-top: 4px; font-size: 12.5px; color: var(--tsc-muted); }
.tsc-msg-user .tsc-bubble small { color: rgba(255, 255, 255, .8); }
.tsc-bubble a { color: inherit; text-decoration: underline; }
.tsc-msg-bot .tsc-bubble a { color: var(--tsc-brand-dark); }

.tsc-error .tsc-bubble { background: #fdecec; color: #a12626; }

/* 入力中インジケータ */
.tsc-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.tsc-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #b3a9a3;
  animation: tsc-blink 1.2s infinite ease-in-out;
}
.tsc-typing span:nth-child(2) { animation-delay: .18s; }
.tsc-typing span:nth-child(3) { animation-delay: .36s; }

@keyframes tsc-blink {
  0%, 60%, 100% { opacity: .28; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

/* ---------- 選択肢 ---------- */

.tsc-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 12px;
  background: #fbf9f8;

  /* 既定の flex-shrink:1 のままだと、選択肢が多いときに縦に潰されて
     最後のボタンが見切れる。潰さず、あふれる分はここでスクロールさせる。 */
  flex: 0 0 auto;
  max-height: 45%;
  overflow-y: auto;
}

.tsc-option {
  padding: 9px 16px;
  border: 1.5px solid var(--tsc-brand);
  border-radius: 999px;
  background: #fff;
  color: var(--tsc-brand);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.tsc-option:hover { background: var(--tsc-brand); color: #fff; }
.tsc-option:focus-visible { outline: 2px solid var(--tsc-brand-dark); outline-offset: 2px; }

/* ---------- 写真アップロード ---------- */

.tsc-photo { width: 100%; }

.tsc-photo-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 20px 16px;
  border: 2px dashed var(--tsc-brand);
  border-radius: 12px;
  background: #fff;
  color: var(--tsc-brand);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  transition: background-color .15s ease;
}
.tsc-photo-drop:hover { background: #fdf7f6; }
.tsc-photo-drop svg { width: 26px; height: 26px; }
.tsc-photo-drop small { font-size: 11.5px; font-weight: 400; color: var(--tsc-muted); }

/* 送信した画像。大きいと後続のやり取りが画面外へ押し出されるので控えめに。 */
.tsc-thumb {
  display: block;
  width: 116px;
  height: 78px;
  object-fit: cover;
  border-radius: 8px;
}

/* 写真からの見立て（1枚のカードにまとめる） */
.tsc-verdict {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.tsc-vhead {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--tsc-brand);
}
.tsc-vmain {
  font-size: 16px;
  line-height: 1.5;
}
.tsc-vbody { font-size: 13.5px; }
.tsc-vnote {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--tsc-line);
  font-size: 11.5px;
  color: var(--tsc-muted);
}

/* PDFなど、サムネイルを出せないファイル */
.tsc-file {
  display: inline-block;
  max-width: 100%;
  padding: 2px 0;
  font-size: 13.5px;
  word-break: break-all;
}
.tsc-file::before {
  content: "📄";
  margin-right: 6px;
}

/* ---------- 書類の読み取り結果の確認 ---------- */

.tsc-confirm {
  width: 100%;
  margin-bottom: 6px;
  padding: 16px;
  border: 1px solid var(--tsc-line);
  border-radius: 12px;
  background: #fff;
}

.tsc-ctable {
  border: 1px solid var(--tsc-line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 14px;
}

.tsc-crow {
  display: grid;
  grid-template-columns: 6.5em 1fr;
  gap: 10px;
  padding: 9px 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--tsc-line);
}
.tsc-crow:last-child { border-bottom: none; }
.tsc-crow:nth-child(odd) { background: var(--tsc-bot-bg); }

.tsc-clabel { color: var(--tsc-muted); font-size: 13px; }
.tsc-cvalue { font-weight: 700; }
.tsc-cvalue small {
  display: block;
  margin-top: 2px;
  font-weight: 400;
  font-size: 11.5px;
  color: var(--tsc-muted);
}

.tsc-cdeny {
  display: block;
  width: 100%;
  margin-top: 8px;
  text-align: center;
}

/* ---------- 連絡先フォーム（会話の最後） ---------- */

.tsc-contact {
  width: 100%;
  margin-bottom: 6px;
  padding: 16px;
  border: 1px solid var(--tsc-line);
  border-radius: 12px;
  background: #fff;
}

.tsc-field { margin-bottom: 12px; }

.tsc-field label {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 700;
  color: var(--tsc-ink);
}

.tsc-req {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--tsc-brand);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  vertical-align: 1px;
}

.tsc-field input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--tsc-line);
  border-radius: 8px;
  background: #fff;
  font-family: inherit;
  font-size: 16px;   /* iOS の自動ズーム防止 */
  color: var(--tsc-ink);
}
.tsc-field input:focus { outline: none; border-color: var(--tsc-brand); }

.tsc-consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 14px 0;
  font-size: 13px;
  line-height: 1.6;
  cursor: pointer;
}
.tsc-consent input { margin-top: 4px; flex: none; }
.tsc-consent a { color: var(--tsc-brand-dark); }

.tsc-submit {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--tsc-brand);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.tsc-submit:hover { background: var(--tsc-brand-dark); }
.tsc-submit:focus-visible { outline: 2px solid var(--tsc-brand-dark); outline-offset: 2px; }

/* ---------- 入力欄 ---------- */

.tsc-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--tsc-line);
  background: #fff;
  flex: none;
}

.tsc-input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 110px;
  padding: 10px 13px;
  border: 1px solid var(--tsc-line);
  border-radius: 10px;
  background: #fff;
  font-family: inherit;
  font-size: 16px; /* iOS の自動ズーム防止 */
  line-height: 1.5;
  color: var(--tsc-ink);
  resize: none;
}
.tsc-input:focus { outline: none; border-color: var(--tsc-brand); }
.tsc-input::placeholder { color: #a8a09b; }

.tsc-send {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 10px;
  background: var(--tsc-brand);
  color: #fff;
  cursor: pointer;
}
.tsc-send:hover:not(:disabled) { background: var(--tsc-brand-dark); }
.tsc-send:disabled { background: #ccc3bd; cursor: not-allowed; }
.tsc-send:focus-visible { outline: 2px solid var(--tsc-brand-dark); outline-offset: 2px; }
.tsc-send svg { width: 18px; height: 18px; }

.tsc-foot {
  padding: 0 12px 10px;
  background: #fff;
  font-size: 11px;
  color: var(--tsc-muted);
  text-align: center;
  flex: none;
}
.tsc-foot a { color: var(--tsc-muted); }

/* ---------- スマホ ---------- */

@media (max-width: 600px) {
  .tsc-root { right: 12px; bottom: 12px; left: 12px; }
  .tsc-launcher { margin-left: auto; }
  .tsc-panel {
    width: 100%;
    height: min(560px, calc(100vh - 80px));
  }
  .tsc-root[data-open="true"] {
    right: 0; bottom: 0; left: 0; top: 0;
  }
  .tsc-root[data-open="true"] .tsc-panel {
    width: 100%; height: 100%; border-radius: 0;
  }
}

/* ---------- アイコンで選ぶ設問（建物の種類・階数・構造など） ----------

   つだ建材様のご指摘どおり、建物は「絵を見れば直感的に選べる」ため、
   専門用語が分からない施主様でも迷わず答えられるようグリッド表示にしています。
   1行あたりの枚数は幅に応じて自動で変わります（狭い画面でも2列は確保）。 */

.tsc-options--grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
  align-content: start;
  max-height: 58%;
}

.tsc-option--icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding: 12px 6px 10px;
  border-radius: var(--tsc-radius);
  border: 1.5px solid var(--tsc-line);
  background: #fff;
  color: var(--tsc-brand);
  text-align: center;
  min-height: 92px;
}

.tsc-option--icon:hover,
.tsc-option--icon:focus-visible {
  border-color: var(--tsc-brand);
  background: #fff;
  color: var(--tsc-brand);
  box-shadow: 0 2px 10px rgba(128, 39, 38, .14);
}

.tsc-option--icon:active {
  background: var(--tsc-bot-bg);
}

.tsc-option-fig {
  display: block;
  width: 44px;
  height: 44px;
  flex: none;
  color: var(--tsc-brand);
}

.tsc-option-fig svg {
  display: block;
  width: 100%;
  height: 100%;
}

.tsc-option-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--tsc-ink);
  word-break: auto-phrase;
}

/* 端末の設定で「視差効果を減らす」が有効な場合はホバーの動きを止める */
@media (prefers-reduced-motion: reduce) {
  .tsc-option--icon { transition: none; }
  .tsc-option--icon:hover { box-shadow: none; }
}

/* 画面の縦が短い端末（小型スマホ・横向き）では、選択肢が会話ログを押し出して
   直前の質問文が見えなくなる。アイコンを一回り小さくして質問文の居場所を残す。 */
@media (max-height: 700px) {
  .tsc-options--grid { max-height: 44%; }
  .tsc-option--icon  { min-height: 74px; padding: 8px 4px 7px; gap: 4px; }
  .tsc-option-fig    { width: 34px; height: 34px; }
  .tsc-option-label  { font-size: 11px; }
}
