/* =====================================================================
   chat.css — キャベまるくん（LP AI チャット）Phase 3 UI
   モック: update/lp-chatbot/mock/phase3_ui_mock.html（v1.4）を移植
   - 単一テーマ固定（ホワイト／ベージュ + キーカラーのグリーン。ダークモード分岐なし）
   - PC（1200px 以上）= 右ドック 400px ／ スマホ = ボトムシート 90dvh（半開／全開）
   - クラスは stc- 接頭辞（style.css の旧チャット CSS と衝突させない）
   - FAB（.st-chat-fab）は style.css のまま
   ===================================================================== */

#st-chat-panel, #st-chat-scrim {
  color-scheme: light only;
  --ground: #fbf6ef; --paper: #ffffff; --paper-2: #f7f5f2; --ink: #2b211b; --ink-2: #6b6058; --line: #e6ddd0;
  --leaf: #3cb554; --leaf-deep: #22893f; --leaf-light: #8fdf6e; --leaf-pale: #e8f7e6; --cream: #ffe6cf;
  --order: #ff6b35; --order-2: #ff9a56;
  --ok: #3cb554; --maybe: #e0961f; --ng: #d14b43;
  --user-bubble: #e4f6df; --bot-bubble: #ffffff;
  --dock-head: linear-gradient(135deg, #2eab52, #4dcb6e);
  --card-pad: 14px; --card-r: 14px; --card-gap: 10px;
  --stc-font: 'Noto Sans JP', system-ui, -apple-system, 'Hiragino Sans', sans-serif;
  --stc-dot: 'DotGothic16', 'Noto Sans JP', monospace;
}

/* ---------- 外枠（スマホ = ボトムシート） ---------- */
#st-chat-scrim {
  position: fixed; inset: 0; z-index: 10001;
  background: rgba(43, 33, 27, .28);
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
#st-chat-scrim.is-on { opacity: 1; pointer-events: auto; }

#st-chat-panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10002;
  height: 90vh; height: 90dvh;
  background: var(--dock-head) no-repeat top / 100% 140px, var(--paper);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -6px 30px rgba(0, 0, 0, .18);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  transform: translateY(100%);
  visibility: hidden;
  transition: transform .32s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .32s;
  font-family: var(--stc-font); font-size: 14px; line-height: 1.7; color: var(--ink);
  text-align: left;
  -webkit-font-smoothing: antialiased;
}
#st-chat-panel[data-sheet="half"],
#st-chat-panel[data-sheet="full"] { visibility: visible; transition-delay: 0s; }
#st-chat-panel[data-sheet="half"] { transform: translateY(42%); }
#st-chat-panel[data-sheet="full"] { transform: translateY(0); }
#st-chat-panel.is-dragging { transition: none; will-change: transform; }
#st-chat-panel * { box-sizing: border-box; }
#st-chat-panel button { font-family: inherit; -webkit-tap-highlight-color: transparent; }
#st-chat-panel button:focus-visible,
#st-chat-panel a:focus-visible,
#st-chat-panel textarea:focus-visible,
#st-chat-panel [tabindex]:focus-visible { outline: 2px solid var(--leaf); outline-offset: 2px; }
#st-chat-panel .stc__head button:focus-visible { outline-color: #fff; }

.stc-handle {
  height: 22px; flex: none; display: flex; align-items: center; justify-content: center;
  cursor: grab; touch-action: none;
}
.stc-handle::before { content: ""; width: 40px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .7); }

/* 開いている間は FAB を隠す（シート／ドックの下に潜るため） */
body.stc-open .st-chat-fab { opacity: 0; pointer-events: none; transition: opacity .2s; }
body.stc-lock { overflow: hidden; }

/* ---------- チャット本体（共通） ---------- */
.stc { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.stc__head {
  background: transparent; color: #fff; padding: 4px 14px 10px;
  display: flex; align-items: center; gap: 10px; flex: none;
}
.stc__avatar-wrap { display: block; width: 40px; height: 40px; flex: none; }
.stc__avatar { width: 40px; height: 40px; image-rendering: pixelated; overflow: visible; display: block; }
.stc__title { min-width: 0; }
.stc__name { font-family: var(--stc-dot); font-size: 16px; line-height: 1.1; }
.stc__state { font-size: 11px; opacity: .92; line-height: 1.3; margin-top: 2px; font-family: var(--stc-dot); letter-spacing: .04em; }
.stc__head-btns { margin-left: auto; display: flex; gap: 6px; }
.stc__hb {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .55);
  background: rgba(255, 255, 255, .16); color: #fff; cursor: pointer; font-size: 14px;
  display: grid; place-items: center; padding: 0; line-height: 1;
}
.stc__hb:hover { background: rgba(255, 255, 255, .28); }
.stc__hb--text { width: auto; border-radius: 999px; padding: 0 10px; font-size: 11px; font-weight: 700; }

.stc__body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 14px 12px 10px; display: flex; flex-direction: column; gap: 10px;
  background: var(--ground); min-height: 0;
}

/* メッセージ */
.stc-msg { display: flex; gap: 8px; align-items: flex-end; max-width: 92%; animation: stc-rise .16s ease-out both; }
.stc-msg--user { align-self: flex-end; flex-direction: row-reverse; }
.stc-msg__av { width: 28px; height: 28px; image-rendering: pixelated; overflow: visible; flex: none; }
.stc-bubble {
  background: var(--bot-bubble); border-radius: 14px 14px 14px 4px; padding: 9px 12px; line-height: 1.65;
  box-shadow: 0 1px 2px rgba(43, 33, 27, .08); word-break: break-word; overflow-wrap: anywhere; min-width: 0;
}
.stc-msg--user .stc-bubble { background: var(--user-bubble); border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.stc-bubble p { margin: 0; }
.stc-bubble p + p { margin-top: 6px; }
.stc-bubble ul, .stc-bubble ol { margin: 4px 0 0; padding-left: 18px; }
.stc-bubble li { margin: 0; }
.stc-bubble h1, .stc-bubble h2, .stc-bubble h3 { font-size: 14px; font-weight: 700; margin: 6px 0 2px; }
.stc-bubble a { color: var(--leaf-deep); }
.stc-bubble code { font-family: var(--stc-dot); font-size: 13px; background: var(--paper-2); padding: 0 4px; border-radius: 4px; }
.stc-bubble strong { font-weight: 700; }
.stc-w { display: inline; animation: stc-fadein .18s ease-out both; white-space: pre-wrap; }
.stc-w--still { animation: none; }
.stc-caret { display: inline-block; width: 7px; height: 1em; background: var(--leaf); vertical-align: -2px; margin-left: 2px; animation: stc-blink 1s steps(1) infinite; }

/* 状態行（考え中／ツール実行中） */
.stc-status { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 12px; padding: 2px 0 0 36px; animation: stc-fadein .2s ease-out both; }
.stc-dots i { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--leaf); margin-right: 3px; animation: stc-dot 1.2s infinite; }
.stc-dots i:nth-child(2) { animation-delay: .2s; }
.stc-dots i:nth-child(3) { animation-delay: .4s; }
.stc-status--tool { font-family: var(--stc-dot); color: var(--leaf-deep); }
.stc-status--tool::before { content: "▶"; font-size: 9px; }

/* クイックリプライ */
.stc-replies { display: flex; flex-wrap: wrap; gap: 6px; padding-left: 36px; animation: stc-fadein .2s ease-out both; }
.stc-reply {
  font: inherit; font-size: 12.5px; padding: 6px 12px; border-radius: 999px; border: 1.5px solid var(--leaf);
  background: var(--paper); color: var(--leaf-deep); cursor: pointer; min-height: 36px; line-height: 1.4; text-align: left;
}
.stc-reply:hover { background: var(--leaf-pale); }
.stc-reply--first { border-style: dashed; }

/* 入力 */
.stc__foot { flex: none; border-top: 1px solid var(--line); background: var(--paper); padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px)); }
.stc-input { display: flex; gap: 8px; align-items: flex-end; }
.stc-input textarea {
  flex: 1; font-family: inherit; font-size: 16px; resize: none; border: 1.5px solid var(--line); border-radius: 14px;
  padding: 9px 12px; background: var(--paper-2); color: var(--ink); min-height: 44px; max-height: 104px; line-height: 1.5;
  outline: none; -webkit-appearance: none; appearance: none; margin: 0; width: auto; box-shadow: none;
}
.stc-input textarea:focus { border-color: var(--leaf); }
.stc-input textarea::placeholder { color: #a39a91; }
.stc-send {
  width: 44px; height: 44px; border-radius: 50%; border: none; background: var(--leaf); color: #fff; font-size: 18px;
  cursor: pointer; flex: none; display: grid; place-items: center; padding: 0; line-height: 1;
}
.stc-send:disabled { opacity: .5; cursor: default; }
.stc-send--stop { background: var(--ink-2); }
.stc-meta { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--ink-2); padding: 4px 6px 0; font-variant-numeric: tabular-nums; }
.stc-meta .stc-over { color: var(--ng); font-weight: 700; }

/* ---------- カード（6 種共通ルール） ----------
   すべてのカードは同じ内側余白（--card-pad）と角丸（--card-r）を共有する。
   見出し・本文・フッターの左端が 1 本の線に揃う。 */
.stc-cardwrap { padding-left: 36px; display: flex; flex-direction: column; gap: var(--card-gap); }
.stc-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--card-r); overflow: hidden;
  animation: stc-pop .2s ease-out both; box-shadow: 0 1px 2px rgba(43, 33, 27, .05);
}
.stc-card__body { padding: var(--card-pad); }
.stc-card__eyebrow { font-family: var(--stc-dot); font-size: 11.5px; letter-spacing: .06em; color: var(--leaf-deep); line-height: 1.4; }
.stc-card__title { font-weight: 700; font-size: 15px; line-height: 1.45; margin: 2px 0 0; text-wrap: balance; }
.stc-card__sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.stc-card__note { font-size: 12.5px; color: var(--ink-2); margin-top: 8px; line-height: 1.6; }
.stc-card__cta { margin-top: 12px; }
.stc-card__actions { display: flex; gap: 8px; margin-top: 12px; }
.stc-card__actions .stc-cta { flex: 1 1 0; min-width: 0; padding-left: 8px; padding-right: 8px; }
.stc-card__foot { padding: 12px var(--card-pad) var(--card-pad); border-top: 1px solid var(--line); display: flex; gap: 8px; }
.stc-card__foot .stc-cta { flex: 1 1 0; min-width: 0; padding-left: 8px; padding-right: 8px; }
.stc-cta {
  display: block; width: 100%; font: inherit; font-weight: 700; font-size: 13.5px; padding: 11px 14px; border-radius: 999px;
  border: none; background: linear-gradient(135deg, var(--order-2), var(--order)); color: #fff; cursor: pointer;
  min-height: 44px; line-height: 1.3; text-align: center; text-decoration: none;
}
.stc-cta:hover { filter: brightness(1.05); }
.stc-cta--ghost { background: var(--paper); color: var(--leaf-deep); border: 1.5px solid var(--leaf); font-weight: 500; }
.stc-cta--ghost:hover { background: var(--leaf-pale); filter: none; }

/* 献立 */
.stc-mtabs { display: flex; gap: 4px; padding: 12px var(--card-pad) 0; overflow-x: auto; scrollbar-width: none; }
.stc-mtabs::-webkit-scrollbar { display: none; }
.stc-mtab {
  font: inherit; font-size: 11.5px; min-width: 32px; padding: 4px 6px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--paper); color: var(--ink-2); cursor: pointer; flex: none; line-height: 1.5;
}
.stc-mtab[aria-selected="true"] { background: var(--leaf); color: #fff; border-color: var(--leaf); }
.stc-mhead { padding: 12px var(--card-pad) 0; }
.stc-mrow {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px var(--card-pad) 12px; scroll-padding-left: var(--card-pad);
  scroll-snap-type: x mandatory; scrollbar-width: thin;
}
.stc-mcard { flex: 0 0 150px; scroll-snap-align: start; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--paper); }
.stc-mcard__img { height: 90px; background: linear-gradient(150deg, #f0d9b5, #c9b48a); display: grid; place-items: center; color: rgba(43, 33, 27, .55); font-size: 11px; overflow: hidden; }
.stc-mcard__img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.stc-mcard__b { padding: 8px 10px 10px; }
.stc-mcard__d { font-size: 10.5px; color: var(--leaf-deep); font-family: var(--stc-dot); letter-spacing: .04em; }
.stc-mcard__t { font-size: 12.5px; font-weight: 700; line-height: 1.4; margin: 2px 0 1px; }
.stc-mcard__s { font-size: 11px; color: var(--ink-2); line-height: 1.4; }

/* 価格 */
.stc-ptabs { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin-top: 12px; background: var(--paper-2); }
.stc-ptab { flex: 1; font: inherit; font-size: 12.5px; padding: 6px 0; border: none; background: transparent; color: var(--ink-2); cursor: pointer; min-height: 34px; }
.stc-ptab[aria-selected="true"] { background: var(--leaf); color: #fff; }
.stc-pcard__amount { display: flex; align-items: baseline; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.stc-pcard__price { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; letter-spacing: -.01em; }
.stc-pcard__price small { font-size: 12px; font-weight: 400; color: var(--ink-2); margin-left: 4px; }
.stc-pcard__base { font-size: 12px; color: var(--ink-2); text-decoration: line-through; font-variant-numeric: tabular-nums; }
.stc-pcard__disc { display: inline-block; margin-top: 8px; font-size: 11.5px; background: var(--cream); color: var(--ink); padding: 3px 10px; border-radius: 6px; line-height: 1.5; }

/* 配達エリア */
.stc-acard__head { display: flex; align-items: center; gap: 10px; }
.stc-acard__ico { width: 28px; height: 28px; border-radius: 50%; background: var(--ok); color: #fff; display: grid; place-items: center; font-size: 14px; font-weight: 700; flex: none; }
.stc-acard--maybe .stc-acard__ico { background: var(--maybe); }
.stc-acard--ng .stc-acard__ico { background: var(--ng); }
.stc-acard__txt { display: flex; flex-direction: column; min-width: 0; }
.stc-acard__label { font-size: 14px; font-weight: 700; line-height: 1.4; color: var(--leaf-deep); }
.stc-acard--maybe .stc-acard__label { color: #9a6510; }
.stc-acard--ng .stc-acard__label { color: var(--ng); }
.stc-acard__zip { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; line-height: 1.4; }
.stc-acard__msg { font-size: 12.5px; color: var(--ink); margin-top: 10px; line-height: 1.6; }

/* 連絡先 */
.stc-ccard__tel { display: block; font-size: 24px; font-weight: 700; color: var(--leaf-deep); text-decoration: none; font-variant-numeric: tabular-nums; margin: 6px 0 0; line-height: 1.2; letter-spacing: .01em; }
.stc-ccard__h { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.stc-ccard__links { display: flex; gap: 8px; margin-top: 12px; }
.stc-ccard__links a { font-size: 12.5px; padding: 9px 10px; border-radius: 999px; border: 1.5px solid var(--leaf); color: var(--leaf-deep); text-decoration: none; flex: 1; text-align: center; min-height: 40px; line-height: 1.4; }
.stc-ccard__links a.stc-ccard__line { background: #06c755; color: #fff; border-color: #06c755; }

/* クーポン */
.stc-kcard .stc-card__body { background: repeating-linear-gradient(-45deg, var(--paper) 0 8px, var(--leaf-pale) 8px 16px); }
.stc-kcard__row { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.stc-kcard__code { font-family: var(--stc-dot); font-size: 22px; letter-spacing: .12em; background: var(--paper); padding: 7px 14px; border-radius: 8px; display: inline-block; border: 1.5px dashed var(--leaf); line-height: 1.2; user-select: all; }
.stc-kcard__copy { font: inherit; font-size: 12.5px; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--leaf); background: var(--paper); color: var(--leaf-deep); cursor: pointer; min-height: 40px; }

/* クイズ */
.stc-qcard__q { font-weight: 700; font-size: 15px; line-height: 1.45; margin-top: 2px; }
.stc-qcard__opts { display: grid; gap: 8px; margin-top: 12px; }
.stc-qopt { font: inherit; font-size: 13px; text-align: left; padding: 10px 14px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--paper); color: var(--ink); cursor: pointer; min-height: 44px; line-height: 1.5; }
.stc-qopt:hover { border-color: var(--leaf); }
.stc-qopt:disabled { cursor: default; opacity: .55; }
.stc-qopt.is-picked { opacity: 1; border-color: var(--leaf); background: var(--leaf-pale); font-weight: 700; }
/* エラー／上限／注文へ */
.stc-err { padding: 10px 12px; border-radius: 12px; background: #fff1ef; color: #8d2c25; font-size: 13px; display: flex; flex-direction: column; gap: 8px; margin-left: 36px; animation: stc-rise .16s ease-out both; }
.stc-err button { font: inherit; font-size: 12.5px; align-self: flex-start; padding: 6px 14px; border-radius: 999px; border: 1.5px solid currentColor; background: transparent; color: inherit; cursor: pointer; min-height: 36px; }
.stc-err--soft { background: var(--cream); color: var(--ink); }
.stc-progress { margin: 0 0 0 36px; padding: 10px 12px; border-radius: 12px; background: var(--leaf-pale); color: var(--leaf-deep); font-size: 13px; display: flex; align-items: center; gap: 10px; }
.stc-progress .stc-bar { flex: 1; height: 6px; border-radius: 3px; background: var(--paper); overflow: hidden; }
.stc-progress .stc-bar i { display: block; height: 100%; width: 60%; background: var(--leaf); animation: stc-grow 1.4s ease-out forwards; }

/* ---------- スプライト（4 表情） ---------- */
.stc-av .av-body { transform-box: fill-box; transform-origin: center bottom; animation: stc-bounce 1s steps(2) infinite; }
.stc-av .av-ll { transform-box: fill-box; transform-origin: right bottom; animation: stc-leafl 1.3s steps(2) infinite; }
.stc-av .av-lr { transform-box: fill-box; transform-origin: left bottom; animation: stc-leafr 1.3s steps(2) infinite; }
.stc-av .av-lt { transform-box: fill-box; transform-origin: center bottom; animation: stc-leaft 1.1s steps(2) infinite; }
.stc-av.is-think .av-body { animation: stc-tilt .9s steps(2) infinite; }
.stc-av.is-think .av-eyes { transform-box: fill-box; animation: stc-look 1.2s steps(2) infinite; }
.stc-av.is-happy .av-body { animation: stc-hop .6s steps(2) infinite; }
.stc-av.is-sad .av-body, .stc-av.is-sad .av-ll, .stc-av.is-sad .av-lr, .stc-av.is-sad .av-lt { animation: none; transform: translateY(1px); }
.stc-av.is-sad .av-lt { transform: translateY(2px); }
/* 吹き出し脇の小アバターは静止（本文の読みやすさ優先） */
.stc-msg__av .av-body, .stc-msg__av .av-ll, .stc-msg__av .av-lr, .stc-msg__av .av-lt, .stc-msg__av .av-eyes { animation: none; }

@keyframes stc-bounce { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(.96); } }
@keyframes stc-hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }
@keyframes stc-tilt { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes stc-look { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(1px); } }
@keyframes stc-leafl { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-6deg); } }
@keyframes stc-leafr { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(6deg); } }
@keyframes stc-leaft { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(.92); } }
@keyframes stc-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes stc-fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes stc-pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes stc-blink { 50% { opacity: 0; } }
@keyframes stc-dot { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-3px); opacity: 1; } }
@keyframes stc-grow { from { width: 10%; } to { width: 92%; } }

/* ---------- PC: 右ドック 400px ---------- */
@media (min-width: 1200px) {
  #st-chat-panel {
    left: auto; right: 0; top: 0; bottom: 0;
    width: 400px; height: 100vh; height: 100dvh;
    background: var(--paper); border-radius: 0; border-left: 1px solid var(--line);
    box-shadow: -8px 0 24px rgba(43, 33, 27, .08);
    transform: translateX(100%);
    transition: transform .28s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .28s;
  }
  #st-chat-panel[data-sheet="half"],
  #st-chat-panel[data-sheet="full"] { transform: translateX(0); }
  .stc-handle { display: none; }
  .stc__head { background: var(--dock-head); padding: 10px 14px; }
  .stc-input textarea { font-size: 14px; }
  .stc__foot { padding-bottom: 10px; }
  /* 十分に広い画面ではドック分だけ LP を左へ寄せる（狭い PC は重ねる） */
  body.stc-lock { overflow: auto; }
}
@media (min-width: 1620px) {
  body.stc-open { padding-right: 400px; transition: padding-right .28s cubic-bezier(.2, .8, .2, 1); }
}

/* ---------- 動きを減らす設定 ---------- */
@media (prefers-reduced-motion: reduce) {
  #st-chat-panel, #st-chat-scrim, body.stc-open { transition: none !important; }
  #st-chat-panel *, #st-chat-panel *::before, #st-chat-panel *::after { animation: none !important; transition: none !important; }
  .stc-caret { opacity: 1; }
  .stc-progress .stc-bar i { width: 92%; }
}
