/* AI 안내 챗봇 위젯 — 모든 규칙은 .cb 아래에 둔다. 새 색은 만들지 않고 기존 토큰만 쓴다.
   z-index: 런처·말풍선 52, 팝업 59 (헤더 40 < 글쓰기 버튼 51 < 런처 52 < 팝업 59 < 프로필 패널 60 < 토스트 90) */
.cb { --cb-launcher: 60px; --cb-gap: 12px; }
.cb[hidden] { display: none; }
.cb * { box-sizing: border-box; }
.cb button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.cb p, .cb h2, .cb ul, .cb ol { margin: 0; padding: 0; }
.cb ul, .cb ol { list-style: none; }
.cb .cb-ico { width: 20px; height: 20px; display: block; }
.cb button:focus-visible, .cb a:focus-visible, .cb textarea:focus-visible, .cb .cb-log:focus-visible {
  outline: 2px solid var(--c-accent); outline-offset: 2px; border-radius: var(--r-md);
}

/* ---------- 런처: 오른쪽 아래, 글쓰기 버튼 위에 쌓는다 ---------- */
/* PC 글쓰기 버튼: bottom 28 + 높이 48 = 76 → 간격 12 → 88 */
.cb .cb-dock { position: fixed; right: 28px; bottom: 88px; z-index: 52; display: flex; align-items: center; animation: cb-float 3.4s ease-in-out infinite; }
.cb[data-fab="none"] .cb-dock { bottom: 28px; }
.cb--open .cb-dock { animation: none; }
.cb .cb-launcher { position: relative; width: var(--cb-launcher); height: var(--cb-launcher); border-radius: 50%; background: var(--c-bg); border: 2px solid var(--c-accent); box-shadow: var(--shadow-3); overflow: hidden; display: block; transition: transform var(--m-base) var(--ease-press); }
.cb .cb-launcher:hover { transform: scale(1.06); }
.cb .cb-launcher:active { transform: scale(.94); }
.cb .cb-launcher:focus-visible { outline-offset: 3px; border-radius: 50%; }
.cb .cb-launcher-face { display: block; width: 100%; height: 100%; }
.cb .cb-launcher .cb-img { width: 100%; height: 100%; object-fit: cover; display: block; animation: cb-nod 3.4s ease-in-out infinite; transform-origin: 50% 80%; }
.cb--open .cb-launcher .cb-img { animation: none; }
.cb .cb-fallback { width: 100%; height: 100%; padding: 22%; color: var(--c-logo); display: block; }

/* 말풍선 안내 팁 */
.cb .cb-tip { position: absolute; right: calc(100% + 10px); top: 50%; transform: translateY(-50%); display: flex; align-items: center; background: var(--c-bg); border: 1px solid var(--c-line-2); border-radius: var(--r-lg); box-shadow: var(--shadow-3); white-space: nowrap; }
.cb .cb-tip[hidden] { display: none; }
.cb .cb-tip::after { content: ""; position: absolute; right: -6px; top: 50%; width: 10px; height: 10px; background: var(--c-bg); border-top: 1px solid var(--c-line-2); border-right: 1px solid var(--c-line-2); transform: translateY(-50%) rotate(45deg); }
.cb .cb-tip-text { padding: 0 4px 0 14px; min-height: 44px; font-size: var(--t-sm); font-weight: 600; color: var(--c-ink); }
.cb .cb-tip-x { width: 44px; height: 44px; display: grid; place-items: center; color: var(--c-muted); }
.cb .cb-tip-x .cb-ico { width: 16px; height: 16px; }
.cb .cb-tip-x:hover { color: var(--c-ink); }

@keyframes cb-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes cb-nod { 0%, 100% { transform: rotate(0); } 35% { transform: rotate(-5deg); } 70% { transform: rotate(4deg); } }

/* ---------- 팝업 ---------- */
.cb .cb-overlay { position: fixed; inset: 0; z-index: 59; background: rgba(25, 31, 40, .45); display: grid; place-items: center; overscroll-behavior: contain; }
.cb .cb-overlay[hidden] { display: none; }
.cb .cb-dialog { width: min(960px, 94vw); height: min(680px, 88vh); display: grid; grid-template-columns: 280px minmax(0, 1fr); background: var(--c-bg); border-radius: var(--r-lg); overflow: hidden; box-shadow: 0 12px 40px rgba(0, 0, 0, .22); color: var(--c-ink); font-family: var(--f-body); font-size: var(--t-sm); line-height: 1.5; }

/* 좌측 안내 */
.cb .cb-aside { background: var(--c-milk-2); padding: var(--s-8) var(--s-5); display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-3); overflow-y: auto; min-height: 0; }
.cb .cb-avatar { width: 112px; height: 112px; border-radius: 50%; overflow: hidden; background: var(--c-bg); border: 3px solid var(--c-bg); box-shadow: var(--shadow-3); flex: none; display: block; }
.cb .cb-avatar .cb-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cb .cb-brand-name { font-size: var(--t-lg); font-weight: 800; color: var(--c-ink); }
.cb .cb-brand-sub { font-size: var(--t-xs); color: var(--c-muted); }
.cb .cb-title { font-size: var(--t-md); font-weight: 700; color: var(--c-berry); margin-top: var(--s-2); }
.cb .cb-suggests { display: flex; flex-direction: column; gap: var(--s-2); width: 100%; margin-top: var(--s-2); }
.cb .cb-suggest { min-height: 44px; padding: 10px 14px; background: var(--c-bg); border: 1px solid var(--c-line-2); border-radius: var(--r-lg); font-size: var(--t-sm); font-weight: 600; color: var(--c-ink); text-align: left; line-height: 1.4; transition: border-color var(--m-fast), background var(--m-fast); }
.cb .cb-suggest:hover { border-color: var(--c-accent); background: var(--c-surface-2); }
.cb .cb-suggest:disabled { opacity: .6; cursor: default; }
.cb--busy .cb-suggest { opacity: .6; pointer-events: none; }

/* 우측 대화 */
.cb .cb-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.cb .cb-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: 0 var(--s-3) 0 var(--s-5); min-height: 56px; border-bottom: 1px solid var(--c-line); flex: none; }
.cb .cb-head-text { font-weight: 700; color: var(--c-ink); }
.cb .cb-actions { display: flex; align-items: center; gap: var(--s-1); flex: none; }
.cb .cb-clear { min-height: 44px; padding: 0 12px; font-size: var(--t-sm); font-weight: 600; color: var(--c-muted); border-radius: var(--r-md); }
.cb .cb-clear:hover { color: var(--c-ink); background: var(--c-surface-2); }
.cb .cb-close { width: 44px; height: 44px; display: grid; place-items: center; color: var(--c-ink); border-radius: var(--r-md); }
.cb .cb-close:hover { background: var(--c-surface-2); }

.cb .cb-log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--s-5); display: flex; flex-direction: column; gap: var(--s-4); background: var(--c-bg); }
.cb .cb-row { display: flex; gap: var(--s-2); align-items: flex-start; max-width: 100%; }
.cb .cb-row--user { justify-content: flex-end; }
.cb .cb-mini { width: 32px; height: 32px; border-radius: 50%; overflow: hidden; flex: none; background: var(--c-milk-2); display: block; }
.cb .cb-mini .cb-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cb .cb-col { display: flex; flex-direction: column; gap: 4px; min-width: 0; max-width: min(78%, 560px); }
.cb .cb-row--user .cb-col { align-items: flex-end; }
.cb .cb-bubble { padding: 10px 14px; border-radius: var(--r-lg); overflow-wrap: anywhere; word-break: break-word; font-size: var(--t-sm); line-height: 1.6; }
.cb .cb-bubble--bot { background: var(--c-milk); color: var(--c-ink); border-top-left-radius: var(--r-sm); }
.cb .cb-bubble--user { background: var(--c-accent); color: #fff; border-top-right-radius: var(--r-sm); white-space: pre-wrap; }
.cb .cb-bubble--err { background: var(--c-danger-bg); color: var(--c-danger); }
.cb .cb-p + .cb-p, .cb .cb-p + .cb-list, .cb .cb-list + .cb-p, .cb .cb-list + .cb-list { margin-top: var(--s-2); }
.cb .cb-list { padding-left: 1.3em; }
.cb .cb-list li { list-style: inherit; }
.cb ul.cb-list { list-style: disc; }
.cb ol.cb-list { list-style: decimal; }
.cb .cb-inline-link { color: var(--c-berry); text-decoration: underline; font-weight: 600; }
.cb .cb-time { font-size: var(--t-xs); color: var(--c-muted); }
.cb .cb-links { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.cb .cb-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 1px solid var(--c-accent); border-radius: var(--r-pill); color: var(--c-berry); font-weight: 700; font-size: var(--t-sm); background: var(--c-bg); text-decoration: none; transition: background var(--m-fast), color var(--m-fast); }
.cb .cb-link:hover { background: var(--c-accent); color: #fff; }

/* 입력 중 점 */
.cb .cb-typing { display: flex; gap: 5px; align-items: center; min-height: 40px; }
.cb .cb-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c-muted); animation: cb-blink 1.2s ease-in-out infinite; }
.cb .cb-dot:nth-child(2) { animation-delay: .18s; }
.cb .cb-dot:nth-child(3) { animation-delay: .36s; }
@keyframes cb-blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* CTA 카드 */
.cb .cb-cta { display: flex; gap: var(--s-2); padding: var(--s-3) var(--s-5); border-top: 1px solid var(--c-line); background: var(--c-surface-2); flex: none; }
.cb .cb-cta-card { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: space-between; gap: var(--s-2); padding: var(--s-3); background: var(--c-bg); border: 1px solid var(--c-line-2); border-radius: var(--r-lg); }
.cb .cb-cta-title { font-size: var(--t-sm); font-weight: 700; color: var(--c-ink); overflow-wrap: anywhere; }
.cb .cb-cta-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 12px; background: var(--c-accent); color: #fff; border-radius: var(--r-btn); font-weight: 700; font-size: var(--t-sm); text-decoration: none; text-align: center; }
.cb .cb-cta-btn:hover { background: var(--c-accent-2); }

/* 입력 */
.cb .cb-form { display: flex; align-items: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-5) 0; flex: none; }
.cb .cb-input { flex: 1; min-width: 0; min-height: 44px; max-height: 120px; resize: none; padding: 10px 14px; border: 1px solid var(--c-line-2); border-radius: var(--r-lg); font: inherit; font-size: var(--t-sm); line-height: 1.5; color: var(--c-ink); background: var(--c-bg); }
.cb .cb-input::placeholder { color: var(--c-muted); }
.cb .cb-input:focus { border-color: var(--c-accent); }
.cb .cb-send { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--c-accent); color: #fff; transition: background var(--m-fast); }
.cb .cb-send:hover:not(:disabled) { background: var(--c-accent-2); }
.cb .cb-send:disabled { background: var(--c-line-2); color: var(--c-muted); cursor: default; }
.cb .cb-hint { min-height: 20px; padding: 2px var(--s-5) 0; font-size: var(--t-xs); color: var(--c-danger); flex: none; }
.cb .cb-notice { padding: 0 var(--s-5) var(--s-3); font-size: var(--t-xs); color: var(--c-muted); line-height: 1.5; flex: none; overflow-wrap: anywhere; }

/* ---------- 모바일: 전체 화면 시트 ---------- */
@media (max-width: 1024px) and (min-width: 769px) {
  .cb .cb-dialog { grid-template-columns: 240px minmax(0, 1fr); }
}
@media (max-width: 768px) {
  .cb { --cb-launcher: 56px; }
  /* 글쓰기 버튼(56px)은 탭바(80px) 위, 그 위 12px 간격 */
  .cb .cb-dock { right: 16px; bottom: calc(80px + 56px + var(--cb-gap) + env(safe-area-inset-bottom)); }
  .cb[data-fab="none"] .cb-dock { bottom: calc(88px + env(safe-area-inset-bottom)); }
  .cb .cb-tip { max-width: calc(100vw - 16px - 56px - 16px - 10px); }
  .cb .cb-tip-text { overflow: hidden; text-overflow: ellipsis; }

  .cb .cb-overlay { display: block; background: var(--c-bg); }
  .cb .cb-overlay { top: var(--cb-top, 0); bottom: auto; height: var(--cb-vh, 100dvh); }
  .cb .cb-dialog { width: 100%; height: 100%; border-radius: 0; box-shadow: none; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); position: relative; }
  .cb .cb-aside { flex-direction: row; flex-wrap: wrap; align-items: center; text-align: left; gap: var(--s-2) var(--s-3); padding: 8px var(--s-3) 10px var(--s-4); overflow: visible; }
  .cb .cb-avatar { width: 40px; height: 40px; border-width: 2px; box-shadow: none; }
  .cb .cb-brand { flex: 1 1 0; min-width: 0; padding-right: 120px; }
  .cb .cb-brand-name { font-size: var(--t-md); }
  .cb .cb-title { display: none; }
  .cb .cb-suggests { flex: 0 0 100%; flex-direction: row; overflow-x: auto; margin: 0; padding-bottom: 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .cb .cb-suggests::-webkit-scrollbar { display: none; }
  .cb .cb-suggest { flex: none; white-space: nowrap; border-radius: var(--r-pill); min-height: 44px; }
  .cb .cb-head { position: absolute; top: 0; right: 0; z-index: 1; min-height: 56px; padding: 0 4px; border: 0; background: transparent; }
  .cb .cb-head-text { display: none; }
  .cb .cb-log { padding: var(--s-4); }
  .cb .cb-col { max-width: calc(100% - 40px); }
  .cb .cb-row--user .cb-col { max-width: 86%; }
  .cb .cb-cta { overflow-x: auto; padding: var(--s-2) var(--s-4); scrollbar-width: none; }
  .cb .cb-cta::-webkit-scrollbar { display: none; }
  .cb .cb-cta-card { flex: 0 0 220px; }
  .cb .cb-form { padding: var(--s-2) var(--s-4) 0; }
  .cb .cb-input { font-size: 16px; } /* iOS 자동 확대 방지 */
  .cb .cb-hint { padding: 2px var(--s-4) 0; }
  .cb .cb-notice { padding: 0 var(--s-4) calc(var(--s-2) + env(safe-area-inset-bottom)); }
}

/* 움직임 줄이기 */
@media (prefers-reduced-motion: reduce) {
  .cb .cb-dock, .cb .cb-launcher .cb-img, .cb .cb-dot { animation: none; }
  .cb .cb-launcher, .cb .cb-link, .cb .cb-suggest, .cb .cb-send { transition: none; }
}
