/* ═══════════════════════════════════════════════════════ */
/* Crowny Finance — 대화식 챗 인터페이스 (chat.css)             */
/* crowny.org 사용자 표준: 베이지 base + 골드 #C9A961 액센트    */
/* Pretendard · TOAU ◇/⬡ · light/dark (style.css :root 상속)   */
/* 모바일 우선 · 단일 컬럼 · 100dvh 3행 그리드                  */
/* ═══════════════════════════════════════════════════════ */

/* style.css :root 토큰(--bg/--surface/--accent/--font 등)을 그대로 상속 */

.chat-body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── 셸: 100dvh 3행 그리드 ── */
.chat-shell {
  display: grid;
  grid-template-rows: 56px auto 1fr auto;
  grid-template-areas:
    "header"
    "dots"
    "stream"
    "input";
  height: 100vh;
  height: 100dvh;
  max-width: 100%;
  position: relative;
}

/* ─── (1) 헤더 ─── */
.chat-header {
  grid-area: header;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  height: 56px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.ch-logo {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: var(--text);
}
.ch-mark {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; border-radius: 9px;
  font-size: 16px; line-height: 1;
}
.ch-name { font-size: 16px; font-weight: 600; letter-spacing: -0.2px; white-space: nowrap; }
.ch-name b { font-weight: 800; color: var(--accent2); }
.ch-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

/* 좁은 화면: 헤더 패딩·간격 축소 + "서비스 소개" 라벨 축약 */
@media (max-width: 400px) {
  .chat-header { padding: 0 12px; }
  .ch-actions { gap: 6px; }
  #btnAbout { font-size: 0; padding: 0 12px; }
  #btnAbout::after { content: '소개'; font-size: 13px; font-weight: 600; }
}
.ch-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px; padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  font-size: 13px; font-weight: 600;
  font-family: var(--font);
  cursor: pointer; text-decoration: none;
  transition: border-color .15s, background .15s;
}
.ch-btn:hover { border-color: var(--accent); }
.ch-btn.ghost { background: transparent; }
.ch-btn.icon {
  width: 44px; min-width: 44px; padding: 0;
  background: var(--surface2); font-size: 15px;
}
.ic-moon { display: none; }
.ic-light { display: inline; }
.ic-dark { display: none; }
:root.dark .ic-light { display: none; }
:root.dark .ic-dark { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not(.light) .ic-light { display: none; }
  :root:not(.light) .ic-dark { display: inline; }
}

/* ─── 8단계 진행 도트 ─── */
.flow-dots {
  grid-area: dots;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 16px 4px;
  background: var(--bg);
}
.flow-dots .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--border2);
  transition: background .25s, transform .25s, width .25s;
}
.flow-dots .dot.done { background: var(--accent); }
.flow-dots .dot.active {
  background: var(--accent);
  width: 18px; border-radius: 999px;
}

/* ─── (2) 메시지 스트림 ─── */
.chat-stream {
  grid-area: stream;
  overflow-y: auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}
.stream-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 24px;
  display: flex; flex-direction: column; gap: 14px;
}

/* ── 메시지 행 ── */
.msg {
  display: flex; gap: 8px; align-items: flex-start;
  animation: fadeSlideUp 220ms cubic-bezier(.2,.7,.3,1);
}
.msg-bot { justify-content: flex-start; }
.msg-user { justify-content: flex-end; }

.avatar {
  flex: 0 0 28px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; line-height: 1;
  margin-top: 2px;
}

.bubble {
  max-width: calc(100% - 40px);
  padding: 11px 14px;
  border-radius: 18px;
  font-size: 15px; line-height: 1.55;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  word-break: break-word;
}
.bubble.bot {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
  color: var(--text);
}
.bubble.user {
  background: var(--accent-soft);
  border: 1px solid var(--accent-ring);
  border-bottom-right-radius: 6px;
  color: var(--text);
}
.bubble p { margin: 0; }
.bubble p + p { margin-top: 6px; }
.bubble .bubble-sub { color: var(--text2); font-size: 13.5px; }
.bubble b, .bubble strong { color: var(--accent2); font-weight: 700; }

/* ── 타이핑 인디케이터 ── */
.bubble.typing {
  display: inline-flex; gap: 4px; align-items: center;
  padding: 14px;
}
.bubble.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text3);
  animation: blink 1.2s infinite ease-in-out;
}
.bubble.typing span:nth-child(2) { animation-delay: .2s; }
.bubble.typing span:nth-child(3) { animation-delay: .4s; }

/* ── 퀵리플라이 칩 (스트림 인라인) ── */
.chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-left: 36px;
  max-width: calc(100% - 36px);
  margin-top: -4px;
}
.msg-user + .chips { margin-left: 0; justify-content: flex-end; }

.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 38px; padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 999px;
  font-size: 13.5px; font-weight: 600;
  font-family: var(--font);
  color: var(--text);
  cursor: pointer; text-decoration: none;
  transition: border-color .15s, background .15s, transform .1s;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.chip:active { transform: scale(.97); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); }
.chip.link { color: var(--accent2); }

/* ─── 카드 (스트림 인라인 임베드) ─── */
.card {
  max-width: 82%;
  margin-left: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: fadeSlideUp 220ms cubic-bezier(.2,.7,.3,1);
}

/* 진행 타임라인 카드 */
.timeline-card { padding: 16px; }
.tc-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px;
  margin-bottom: 14px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.tc-id {
  font-weight: 800; color: var(--accent2);
  background: var(--accent-soft); border: 1px solid var(--accent-ring);
  padding: 2px 8px; border-radius: 999px; font-size: 13px;
}
.tc-name { font-weight: 700; font-size: 14px; }
.tc-cat { color: var(--text2); font-size: 13px; }
.tc-steps { list-style: none; margin: 0; padding: 0; }
.tc-step {
  position: relative;
  display: grid; grid-template-columns: 28px 1fr;
  gap: 10px; padding-bottom: 14px;
}
.tc-node {
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  background: var(--surface2); color: var(--text3);
  border: 1px solid var(--border2);
  z-index: 1;
}
.tc-line {
  position: absolute; left: 11.5px; top: 24px; bottom: -2px;
  width: 1.5px; background: var(--border2);
}
.tc-step:last-child .tc-line { display: none; }
.tc-step.done .tc-node { background: var(--t-color); color: #fff; border-color: var(--t-color); }
.tc-step.done .tc-line { background: var(--t-color); }
.tc-step.current .tc-node { background: var(--accent); color: #fff; border-color: var(--accent); animation: pulse 1.6s infinite; }
.tc-info { display: flex; flex-direction: column; gap: 2px; }
.tc-info b { font-size: 14px; }
.tc-desc { color: var(--text2); font-size: 12.5px; }
.tc-info time { color: var(--text3); font-size: 11.5px; }

/* 상품 추천 카드 */
.reco-card { padding: 16px; }
.reco-code {
  display: inline-block;
  font-size: 11px; font-weight: 700; letter-spacing: .5px;
  color: var(--accent2); background: var(--accent-soft);
  border: 1px solid var(--accent-ring);
  padding: 3px 9px; border-radius: 999px;
}
.reco-name { font-size: 17px; font-weight: 800; margin: 10px 0 4px; letter-spacing: -0.2px; }
.reco-price { font-size: 22px; font-weight: 800; color: var(--text); }
.reco-price span { font-size: 13px; font-weight: 600; color: var(--text2); margin-left: 2px; }
.reco-desc { color: var(--text2); font-size: 13.5px; line-height: 1.55; margin: 8px 0 14px; }
.reco-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* 추천 캐러셀 (여러 개 가로 스와이프) */
.reco-carousel {
  display: flex; gap: 12px; overflow-x: auto;
  margin-left: 36px; max-width: calc(100% - 36px);
  padding-bottom: 4px; scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.reco-carousel .card { margin-left: 0; flex: 0 0 86%; max-width: 86%; scroll-snap-align: start; }

/* 주주 대시보드 카드 */
.shareholder-card { padding: 16px; border-color: var(--accent-ring); }
.sh-head {
  display: flex; flex-direction: column; gap: 2px;
  font-size: 15px; font-weight: 800; margin-bottom: 14px;
}
.sh-head .sh-mark { color: var(--u-color); margin-right: 6px; }
.sh-head small { font-weight: 500; color: var(--text2); font-size: 12px; }
.sh-bars { display: flex; gap: 8px; margin-bottom: 14px; }
.sh-bar {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px; font-size: 12px; color: var(--text2);
}
.sh-bar b { font-size: 20px; font-weight: 800; color: var(--text); }
.sh-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.sh-dot.t { background: var(--t-color); }
.sh-dot.o { background: var(--o-color); }
.sh-dot.a { background: var(--a-color); }
.sh-lines { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.sh-lines li { font-size: 13px; color: var(--text2); }
.sh-lines li b { color: var(--accent2); font-weight: 700; }
.shareholder-card .chips { margin-left: 0; }

/* 소개 카드 (referral) */
.referral-card { padding: 16px; }
.rf-code {
  font-size: 19px; font-weight: 800; letter-spacing: 1px;
  color: var(--accent2); background: var(--accent-soft);
  border: 1px dashed var(--accent-ring);
  padding: 10px 14px; border-radius: 12px;
  text-align: center; margin: 6px 0 12px;
  user-select: all;
}
.rf-stats { display: flex; gap: 8px; margin-bottom: 12px; }
.rf-stat {
  flex: 1; text-align: center;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px; font-size: 11.5px; color: var(--text2);
}
.rf-stat b { display: block; font-size: 18px; font-weight: 800; color: var(--text); }

/* ── 인라인 미니 폼 (접수) ── */
.mini-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.mini-form input {
  width: 100%;
  min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--border2); border-radius: 10px;
  background: var(--bg); color: var(--text);
  font-size: 15px; font-family: var(--font);
}
.mini-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* 버튼 (카드/폼 내부) */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; border: none; border-radius: 12px;
  font-size: 14px; font-weight: 700; font-family: var(--font);
  cursor: pointer; transition: filter .15s, transform .1s;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:active { transform: scale(.98); }

/* ─── (3) 입력영역 ─── */
.chat-input-wrap {
  grid-area: input;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
}
.chip-tray {
  display: flex; gap: 8px;
  max-width: 720px; margin: 0 auto 8px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-wrap: nowrap;
}
.chip-tray::-webkit-scrollbar { display: none; }
.chip-tray:empty { display: none; }
.chip-tray .chip { flex: 0 0 auto; }

.chat-input-bar {
  display: flex; align-items: flex-end; gap: 8px;
  max-width: 720px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 24px;
  padding: 6px 6px 6px 16px;
  transition: border-color .15s, box-shadow .15s;
}
.chat-input-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
#chatInput {
  flex: 1;
  border: none; background: transparent; resize: none;
  font-size: 15px; font-family: var(--font); color: var(--text);
  line-height: 1.4; max-height: 96px;
  padding: 9px 0;
}
#chatInput:focus { outline: none; }
#chatInput::placeholder { color: var(--text3); }
.send-btn {
  flex: 0 0 40px;
  width: 40px; height: 40px; min-width: 40px;
  border: none; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; font-size: 18px; line-height: 1;
  cursor: pointer; transition: filter .15s, transform .1s;
}
.send-btn:hover { filter: brightness(1.05); }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { opacity: .45; cursor: default; }

/* ─── 인라인 칩 앵커 (잔여 폴리시: 최신 봇 메시지 바로 아래) ─── */
.inline-chips {
  margin-top: 2px;
}

/* ═══ 초대 바이럴 (전화번호부 동기화 / 보상 / 가입 알림) ═══ */

/* 초대 카드(챗 인라인) */
.invite-card { padding: 16px; border-color: var(--accent-ring); }
.invite-card-desc { font-size: 13px; color: var(--text2); line-height: 1.6; margin: 4px 0 12px; }
.invite-card-desc b { color: var(--accent2); font-weight: 700; }
.invite-self { margin: 0 0 12px; padding: 11px 12px; border: 1px solid var(--border2); border-radius: var(--radius-sm); background: var(--surface2); }
.invite-self-label { display: block; font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 7px; }
.invite-self-label small { font-weight: 500; color: var(--text2); }
.invite-self input {
  width: 100%; box-sizing: border-box; min-height: 42px; padding: 10px 11px;
  border: 1px solid var(--border2); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px;
}
.invite-self input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.invite-self-note { font-size: 12px; color: var(--text2); line-height: 1.6; margin: 8px 0 0; }
.invite-self-note b { color: var(--accent2); font-weight: 700; }
.invite-self-warn { font-size: 12px; color: #c0392b; line-height: 1.5; margin: 8px 0 0; font-weight: 600; }

.invite-mini { display: flex; gap: 7px; }
.invite-mi-name { flex: 0 0 32%; min-width: 0; }
.invite-mi-phone { flex: 1; min-width: 0; }
.invite-mini input {
  min-height: 42px; padding: 10px 11px;
  border: 1px solid var(--border2); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px;
}
.invite-mini input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.invite-mi-add {
  flex: 0 0 auto; border: none; border-radius: var(--radius-sm); padding: 0 14px;
  background: var(--accent-soft); color: var(--accent2);
  font-family: var(--font); font-weight: 700; font-size: 13px; cursor: pointer;
  transition: background .15s;
}
.invite-mi-add:hover { background: var(--accent-ring); }
.invite-mini-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.invite-chip {
  font-size: 12px; color: var(--text);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px;
}
.invite-chip.rejected { color: var(--a-color); border-color: var(--a-color); text-decoration: line-through; }

/* 1맘 보상 카운터 카드 */
.invite-reward-card { padding: 18px 16px; border-color: var(--accent-ring); background: var(--hero-grad); }
.irw-main { display: flex; align-items: baseline; gap: 6px; margin-top: 2px; }
.irw-mom { font-size: 40px; font-weight: 800; letter-spacing: -1px; color: var(--text); font-variant-numeric: tabular-nums; line-height: 1; }
.irw-unit { font-size: 17px; font-weight: 700; color: var(--accent2); }
.irw-krw { margin-top: 6px; font-size: 14px; color: var(--text2); }
.irw-krw b { color: var(--accent2); font-weight: 800; font-variant-numeric: tabular-nums; }
.irw-rate { font-size: 11.5px; color: var(--text3); }
.irw-stats {
  display: flex; align-items: center; margin-top: 16px; padding: 12px 0;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.irw-stat { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.irw-stat b { font-size: 20px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.irw-stat span { font-size: 11.5px; color: var(--text3); }
.irw-sep { width: 1px; height: 32px; background: var(--border2); }

/* 가입 알림 토스트 (body 직속, 화면 하단 중앙) */
.inv-toast-stack {
  position: fixed; left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1200;
  display: flex; flex-direction: column; gap: 10px;
  width: min(420px, calc(100vw - 28px));
  pointer-events: none;
}
.inv-toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  padding: 13px 15px;
  border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--accent-ring); box-shadow: var(--shadow-lg);
  animation: invToastIn .35s cubic-bezier(.2,.8,.2,1);
}
.inv-toast.out { animation: invToastOut .3s forwards; }
.inv-toast-ic {
  width: 36px; height: 36px; flex: 0 0 auto; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; font-weight: 800; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.inv-toast-tx { flex: 1; font-size: 13.5px; line-height: 1.45; color: var(--text); }
.inv-toast-rw {
  flex: 0 0 auto; font-size: 11.5px; font-weight: 700; color: var(--t-color);
  background: color-mix(in srgb, var(--t-color) 12%, transparent);
  border-radius: 999px; padding: 3px 9px;
}
@keyframes invToastIn { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes invToastOut { to { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ─── 애니메이션 ─── */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes blink {
  0%, 80%, 100% { opacity: .3; transform: scale(.8); }
  40% { opacity: 1; transform: scale(1); }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-ring); }
  50% { box-shadow: 0 0 0 5px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .msg, .card { animation: none; }
  .bubble.typing span, .tc-step.current .tc-node { animation: none; }
  .inv-toast { animation: none; }
  .chat-stream { scroll-behavior: auto; }
}

/* ─── 태블릿+ ─── */
@media (min-width: 768px) {
  .bubble { max-width: 70%; }
  .card { max-width: 460px; }
}

/* 바이럴 환영 — 초대받은 가입자에게 보상 전달 안내 */
.invite-welcome{margin:0 0 8px;padding:9px 12px;border-radius:10px;
  background:linear-gradient(135deg,rgba(201,161,97,.16),rgba(201,161,97,.06));
  border:1px solid rgba(201,161,97,.35);color:var(--text,#2b2620);font-weight:600;font-size:.92rem;line-height:1.45}
.invite-welcome b{color:var(--gold,#C9A961)}

/* 전화번호부 일괄 동기화 */
.invite-bulk{margin-top:10px;font-size:.88rem}
.invite-bulk summary{cursor:pointer;color:var(--gold,#C9A961);font-weight:600;padding:4px 0;list-style:none}
.invite-bulk summary::-webkit-details-marker{display:none}
.invite-bulk summary::before{content:"＋ ";font-weight:700}
.invite-bulk[open] summary::before{content:"－ "}
.invite-bulk-ta{width:100%;margin-top:6px;padding:8px;border:1px solid var(--line,#e6e0d8);border-radius:8px;
  font:inherit;font-size:.86rem;resize:vertical;background:var(--surface,#fff);color:var(--text,#2b2620);box-sizing:border-box}
.invite-bulk-add{margin-top:6px;min-height:40px;padding:0 14px;border:0;border-radius:8px;
  background:var(--gold,#C9A961);color:#1c1813;font-weight:700;cursor:pointer}
.invite-bulk-add:disabled{opacity:.55;cursor:default}
.invite-bulk-stat{margin:6px 0 0;font-size:.84rem;color:var(--muted,#7a7166)}
