/* ポータル相談ウィジェット（顧客フロント）— モーダル内に全幅で収まる前提 */
.cw {
  --cw-ink: #15202b;
  --cw-sub: #5b6b7a;
  --cw-line: #e3e8ee;
  --cw-bg: #ffffff;
  --cw-soft: #f5f8fb;
  --cw-brand: #0b5cff;
  --cw-brand-ink: #ffffff;
  --cw-ok: #1a9e6a;
  --cw-warn: #b26a00;
  --cw-danger: #c0392b;
  font-family: "Noto Sans JP", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--cw-ink);
  background: var(--cw-bg);
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  position: relative;   /* 用語ツールチップの基準 */
}
.cw * { box-sizing: border-box; }

/* 専門用語ツールチップ */
.cw-term { border-bottom: 1px dotted var(--cw-brand); cursor: help; }
.cw-tip {
  position: absolute; z-index: 60; max-width: 260px;
  background: #15202b; color: #fff; font-size: 12px; line-height: 1.55;
  padding: 8px 11px; border-radius: 9px; box-shadow: 0 8px 24px rgba(20,32,43,.28);
  pointer-events: none;
}

/* ヘッダ：相談対象の文脈チップ */
.cw-head { padding: 16px 18px 12px; border-bottom: 1px solid var(--cw-line); }
.cw-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 700; color: var(--cw-brand);
  background: #eaf1ff; border: 1px solid #d4e1ff; border-radius: 999px;
  padding: 5px 12px; margin-bottom: 9px; max-width: 100%;
}
.cw-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--cw-brand); }
.cw-title { font-size: 18px; font-weight: 700; margin: 0; }
/* 在席ステータスを“はっきり分かる”バッジに（不在＝アンバー／在席＝グリーン） */
.cw-status {
  font-size: 14px; font-weight: 700; margin-top: 10px; line-height: 1.4;
  display: flex; align-items: center; gap: 8px; padding: 9px 13px; border-radius: 10px;
  color: #8a6320; background: #fff7ea; border: 1px solid #ffdfa6;
}
.cw-status .led { width: 11px; height: 11px; border-radius: 50%; background: #d39b34; flex: none; }
.cw-status.online { color: var(--cw-ok); background: #e7f7f0; border-color: #bfe7d6; }
.cw-status.online .led { background: var(--cw-ok); box-shadow: 0 0 0 3px rgba(26,158,106,.18); }

/* 本体スクロール域 */
.cw-body { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px 18px; background: var(--cw-soft); }

/* 入口カード */
.cw-cards { display: flex; flex-direction: column; gap: 10px; }
.cw-card {
  width: 100%; text-align: left; cursor: pointer;
  background: var(--cw-bg); border: 1px solid var(--cw-line); border-radius: 12px;
  padding: 14px 16px; display: flex; align-items: center; gap: 14px;
  transition: border-color .12s, box-shadow .12s, transform .04s;
}
.cw-card:hover { border-color: #c2d2ff; box-shadow: 0 2px 10px rgba(11,92,255,.08); }
.cw-card:active { transform: translateY(1px); }
.cw-card[disabled] { opacity: .5; cursor: not-allowed; }
.cw-card.primary { background: var(--cw-brand); border-color: var(--cw-brand); }
.cw-card.primary .cw-card-t, .cw-card.primary .cw-card-s { color: var(--cw-brand-ink); }
.cw-card.primary .cw-ico { background: rgba(255,255,255,.18); }
.cw-ico {
  width: 46px; height: 46px; flex: none; border-radius: 11px; background: #eef3fb;
  display: grid; place-items: center; font-size: 23px;
}
.cw-card-main { flex: 1; min-width: 0; }
.cw-card-t { font-size: 16px; font-weight: 700; margin: 0; }
.cw-card-s { font-size: 13.5px; color: var(--cw-sub); margin: 3px 0 0; line-height: 1.5; }
.cw-card-go { font-size: 20px; color: inherit; opacity: .6; }

/* 不在案内画面（担当者とチャットを不在時に選んだとき） */
.cw-offline { text-align: center; padding: 18px 10px 4px; }
.cw-offline-ic { font-size: 38px; line-height: 1; }
.cw-offline-t { font-size: 19px; font-weight: 800; margin: 12px 0 8px; color: var(--cw-ink); }
.cw-offline-s { font-size: 14px; color: var(--cw-sub); line-height: 1.75; margin: 0; }
.cw-offline-s b { color: var(--cw-warn); font-size: 15px; font-weight: 800; }
.cw-offline-opts {
  margin-top: 16px; border: 1px solid var(--cw-line); border-radius: 14px;
  background: #fff; padding: 12px; display: flex; flex-direction: column; gap: 10px;
}
.cw-offline-opts-t { font-size: 13px; font-weight: 700; color: var(--cw-sub); text-align: center; margin: 2px 0 2px; }

/* オフライン帯 */
.cw-banner {
  background: #fff7ea; border: 1px solid #ffe2b0; color: #8a5a10;
  border-radius: 10px; padding: 12px 14px; font-size: 14px; font-weight: 700;
  margin-bottom: 14px; line-height: 1.6;
}

/* 画面ヘッダ（戻る＋タイトル・スクロールしても上部に残る） */
.cw-shead {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px;
  background: var(--cw-bg); padding: 6px 0 10px; margin: -14px -16px 10px; padding-left: 12px; padding-right: 16px;
  border-bottom: 1px solid var(--cw-line);
}
.cw-back {
  background: none; border: none; color: var(--cw-sub); font-size: 22px; line-height: 1;
  cursor: pointer; padding: 2px 8px; border-radius: 8px;
}
.cw-back:hover { background: var(--cw-soft); color: var(--cw-ink); }
.cw-shead-t { font-size: 15px; font-weight: 700; }
.cw-end {
  margin-left: auto; display: inline-flex; align-items: center; gap: 5px;
  background: #fdecea; border: 1px solid #f0c3bd; color: var(--cw-danger);
  font-size: 12.5px; font-weight: 700; line-height: 1; padding: 7px 12px;
  border-radius: 999px; cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.cw-end .cw-end-x { font-size: 11px; font-weight: 700; }
.cw-end:hover { background: var(--cw-danger); border-color: var(--cw-danger); color: #fff; }
.cw-end:active { transform: translateY(1px); }
.cw-end:focus-visible { outline: 2px solid var(--cw-danger); outline-offset: 2px; }

/* 終了の確認バー（誤タップ防止） */
.cw-endconfirm {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #fdecea; border: 1px solid #f0c3bd; border-radius: 10px;
  padding: 9px 12px; margin: 0 0 10px;
}
.cw-endconfirm-q { font-size: 13px; font-weight: 700; color: var(--cw-danger); margin-right: auto; }
.cw-endconfirm-yes {
  background: var(--cw-danger); border: 1px solid var(--cw-danger); color: #fff;
  font-size: 12.5px; font-weight: 700; padding: 6px 14px; border-radius: 8px; cursor: pointer;
}
.cw-endconfirm-no {
  background: #fff; border: 1px solid var(--cw-line); color: var(--cw-sub);
  font-size: 12.5px; font-weight: 700; padding: 6px 14px; border-radius: 8px; cursor: pointer;
}
.cw-endconfirm-yes:hover { background: #a32d2d; border-color: #a32d2d; }
.cw-endconfirm-no:hover { background: var(--cw-soft); color: var(--cw-ink); }

/* 自動退避時のフォーム導線カード */
.cw-evac {
  background: var(--cw-soft); border: 1px solid var(--cw-line); border-radius: 12px;
  padding: 13px 15px; margin-top: 10px;
}
.cw-evac-t { font-size: 14px; font-weight: 700; color: var(--cw-ink); margin-bottom: 4px; }
.cw-evac-s { font-size: 12.5px; color: var(--cw-sub); line-height: 1.6; margin: 0 0 10px; }
.cw-evac-btn {
  background: var(--cw-brand); border: none; color: var(--cw-brand-ink);
  font-size: 13px; font-weight: 700; padding: 9px 16px; border-radius: 9px; cursor: pointer; width: 100%;
}
.cw-evac-btn:hover { filter: brightness(.95); }

/* 用語ヒント */
.cw-hint { font-size: 11.5px; color: var(--cw-sub); background: var(--cw-soft); border: 1px solid var(--cw-line); border-radius: 9px; padding: 7px 11px; margin-top: 8px; text-align: center; }

/* チャットスレッド */
.cw-thread { display: flex; flex-direction: column; gap: 8px; padding-bottom: 6px; }
.cw-msg { max-width: 84%; padding: 9px 12px; border-radius: 14px; font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.cw-msg.in { align-self: flex-start; background: #fff; border: 1px solid var(--cw-line); border-bottom-left-radius: 4px; }
.cw-msg.out { align-self: flex-end; background: var(--cw-brand); color: #fff; border-bottom-right-radius: 4px; }
/* AI/担当者メッセージはMarkdownをHTML整形して表示（pre-wrapを解除） */
.cw-msg.in { white-space: normal; }
.cw-msg.in h4, .cw-msg.in h5, .cw-msg.in h6 { margin: 11px 0 5px; font-weight: 900; line-height: 1.4; color: #241546; }
.cw-msg.in h4:first-child, .cw-msg.in h5:first-child, .cw-msg.in h6:first-child { margin-top: 2px; }
.cw-msg.in h4 { font-size: 15.5px; } .cw-msg.in h5 { font-size: 14.5px; } .cw-msg.in h6 { font-size: 14px; color: #52606f; }
.cw-msg.in p { margin: 0 0 8px; } .cw-msg.in p:last-child { margin-bottom: 0; }
.cw-msg.in strong { font-weight: 900; }
.cw-msg.in code { background: #eef0f5; border-radius: 4px; padding: 1px 5px; font-size: .92em; font-family: ui-monospace, Menlo, monospace; }
.cw-msg.in hr { border: 0; border-top: 1px solid #e3e8ee; margin: 10px 0; }
.cw-msg.in .cw-md-ul, .cw-msg.in .cw-md-ol { margin: 4px 0 8px; padding-left: 20px; }
.cw-msg.in .cw-md-ul li, .cw-msg.in .cw-md-ol li { margin: 3px 0; }
.cw-msg.in .cw-md-tw { overflow-x: auto; margin: 6px 0 10px; }
.cw-msg.in .cw-md-table { border-collapse: collapse; font-size: 13px; width: 100%; }
.cw-msg.in .cw-md-table th, .cw-msg.in .cw-md-table td { border: 1px solid #dfe4ec; padding: 6px 9px; text-align: left; vertical-align: top; }
.cw-msg.in .cw-md-table th { background: #f4f2fb; font-weight: 800; color: #241546; }
.cw-meta { font-size: 10.5px; color: var(--cw-sub); align-self: center; margin: 4px 0; }

/* 入力フォーム類 */
.cw-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.cw-field label { font-size: 12px; font-weight: 600; color: var(--cw-sub); }
.cw-input, .cw-area {
  width: 100%; border: 1px solid var(--cw-line); border-radius: 10px; padding: 10px 12px;
  font-size: 13.5px; font-family: inherit; color: var(--cw-ink); background: #fff;
}
.cw-area { min-height: 92px; resize: vertical; }
.cw-input:focus, .cw-area:focus { outline: none; border-color: var(--cw-brand); box-shadow: 0 0 0 3px rgba(11,92,255,.12); }
.cw-note { font-size: 11.5px; color: var(--cw-sub); line-height: 1.5; margin: 0 0 12px; }
.cw-err { color: var(--cw-danger); font-size: 12px; margin: 0 0 10px; min-height: 14px; }
.cw-req { color: var(--cw-danger); font-size: 11px; font-weight: 700; margin-left: 5px; }

/* 問い合わせフォーム：来訪文脈チップ */
.cw-formctx {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  font-size: 12px; font-weight: 700; color: var(--cw-brand);
  background: #eaf1ff; border: 1px solid #d4e1ff; border-radius: 999px;
  padding: 5px 12px; margin: 0 0 14px;
}
.cw-formctx .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--cw-brand); flex: none; }
.cw-formctx span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 問い合わせフォーム：カテゴリ選択チップ */
.cw-cats { display: flex; flex-wrap: wrap; gap: 7px; }
.cw-cat {
  border: 1px solid var(--cw-line); background: #fff; color: var(--cw-sub);
  font-size: 12.5px; font-weight: 600; padding: 7px 13px; border-radius: 999px; cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.cw-cat:hover { border-color: var(--cw-brand); color: var(--cw-brand); }
.cw-cat.on { background: var(--cw-brand); border-color: var(--cw-brand); color: #fff; }

/* 完了画面：受付番号・戻る */
.cw-receipt { font-size: 13px; color: var(--cw-ink); margin: 12px 0 0; }
.cw-receipt b { letter-spacing: .08em; }
.cw-done .cw-btn { margin-top: 18px; }

/* 送信バー（チャット下部固定） — 入力欄をはっきり見せる */
.cw-foot {
  border-top: 1px solid var(--cw-line); background: var(--cw-soft);
  padding: 12px; display: flex; gap: 8px; align-items: flex-end;
  box-shadow: 0 -4px 12px rgba(20,32,43,.05);
}
.cw-foot .cw-area {
  min-height: 46px; max-height: 120px; padding: 12px 14px;
  font-size: 15px; background: #fff; border: 1.5px solid #b9c6d4; border-radius: 12px;
}
.cw-foot .cw-area::placeholder { color: #8a98a6; }
.cw-foot .cw-area:focus { border-color: var(--cw-brand); box-shadow: 0 0 0 3px rgba(11,92,255,.14); }
.cw-send {
  flex: none; border: none; background: var(--cw-brand); color: #fff; font-weight: 800;
  border-radius: 12px; padding: 0 18px; height: 46px; cursor: pointer; font-size: 15px;
}
.cw-send:disabled { opacity: .45; cursor: default; }

/* 大ボタン（フォーム送信・チャット開始） */
.cw-btn {
  width: 100%; border: none; background: var(--cw-brand); color: #fff; font-weight: 700;
  border-radius: 11px; padding: 13px; font-size: 14.5px; cursor: pointer;
}
.cw-btn:disabled { opacity: .5; cursor: default; }
.cw-btn.ghost { background: #eef3fb; color: var(--cw-brand); }

/* 完了・状態表示 */
.cw-done { text-align: center; padding: 22px 8px; }
.cw-done .ok { font-size: 40px; }
.cw-done h4 { margin: 8px 0 4px; font-size: 16px; }
.cw-done p { margin: 0; font-size: 13px; color: var(--cw-sub); line-height: 1.6; }
.cw-disc { font-size: 11px; color: var(--cw-sub); line-height: 1.5; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--cw-line); }
.cw-typing { font-size: 12px; color: var(--cw-sub); padding: 4px 2px; }

/* 個別相談CTA（担当者が案内→顧客が本格クロージングへ遷移） */
.cw-consult { margin: 10px 0 4px; border: 1px solid var(--cw-brand); border-radius: 12px; padding: 12px 14px; background: #eef4ff; }
.cw-consult-t { font-size: 13.5px; font-weight: 700; color: var(--cw-brand); display: flex; align-items: center; gap: 6px; }
.cw-consult-t::before { content: "📩"; }
.cw-consult-s { font-size: 12px; color: var(--cw-sub); margin: 5px 0 10px; line-height: 1.55; }
.cw-consult-btn { width: 100%; border: none; background: var(--cw-brand); color: #fff; font-weight: 700; border-radius: 10px; padding: 12px; font-size: 14.5px; cursor: pointer; }
.cw-consult-btn:hover { filter: brightness(1.05); }

/* AIに聞く：人チャット(青)と区別するため紫系の配色＋導入文 */
.cw.cw-ai-mode { --cw-brand: #6d4ad8; }
.cw-ai-mode .cw-msg.in { background: #f7f4ff; border-color: #e0d7f7; }
.cw-ai-mode .cw-foot .cw-area:focus { box-shadow: 0 0 0 3px rgba(109,74,216,.16); }
.cw-ai-mode .cw-consult { background: #f3eefe; border-color: #6d4ad8; }
.cw-ai-intro { font-size: 12px; color: #5b4a8a; background: #f3eefe; border: 1px solid #e2d8fb; border-radius: 10px; padding: 9px 12px; margin-bottom: 10px; line-height: 1.5; }

/* モバイル最適化（スマホは全画面想定・タッチ余白を広げる） */
@media (max-width: 480px) {
  .cw-card { padding: 15px 16px; }
  .cw-card-t { font-size: 15px; }
  .cw-msg { font-size: 14.5px; max-width: 88%; }
  .cw-send { height: 46px; padding: 0 18px; }
  .cw-foot .cw-area { min-height: 44px; }
  .cw-consult-btn, .cw-btn { padding: 14px; font-size: 15px; }
  .cw-tip { max-width: 75vw; }
}
.hidden { display: none !important; }
