/* ---------------------------------------------------------------
   상담 채팅 위젯
   팔레트: 먹(ink) + 쪽빛(indigo) — 파랑/노랑 일색인 상담 위젯 사이에서
   구분되면서도 오래 봐도 피로하지 않은 저채도 계열로 잡았습니다.
   --------------------------------------------------------------- */

/* 리셋.
   주의: `#chatw *` 처럼 ID 를 낀 선택자는 우선순위가 (1,0,0) 이라
   `.chatw-bubble` 같은 클래스 규칙(0,1,0)을 통째로 이깁니다.
   여기에 margin/padding 을 몰아넣으면 아래에서 지정한 여백이 전부 무효가 됩니다.
   그래서 box-sizing 만 전역으로 걸고, 여백 초기화는 필요한 태그에만 겁니다. */
#chatw,
#chatw *,
#chatw *::before,
#chatw *::after {
  box-sizing: border-box;
}

#chatw p,
#chatw h3,
#chatw label,
#chatw button,
#chatw input,
#chatw textarea,
#chatw a {
  margin: 0;
}

#chatw button,
#chatw input,
#chatw textarea {
  font-family: inherit;
}

#chatw {
  --ink: #15171c;
  --ink-60: #5c6270;
  --ink-40: #8b909c;
  --indigo: #2e3a6b;
  --indigo-hover: #3b4a86;
  --indigo-mist: #eceef6;
  --paper: #ffffff;
  --mist: #f4f5f7;
  --line: #e2e4e9;
  --alert: #c0453a;
  --ok: #2f8f5b;

  --radius: 14px;
  --shadow: 0 18px 48px -12px rgba(21, 23, 28, 0.28),
            0 2px 6px rgba(21, 23, 28, 0.06);

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483000;
  font-family: 'Pretendard Variable', Pretendard, -apple-system,
               'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ── 실행 버튼 ───────────────────────────────────────────────
   동그란 말풍선 대신, 상태 표시등을 품은 가로 알약 형태.
   "지금 사람이 있는가"가 누르기 전에 보이는 게 이 위젯의 요점입니다. */
#chatw-launcher {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 54px;
  padding: 0 24px 0 19px;
  border: 0;
  border-radius: 27px;
  /* 단색보다 미세한 그라데이션이 흰 배경에서 훨씬 또렷하게 읽힙니다 */
  background: linear-gradient(135deg, #3b4a86 0%, var(--indigo) 60%);
  color: #fff;
  font: inherit;
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: 0 10px 26px -6px rgba(46, 58, 107, 0.55),
              0 2px 6px rgba(21, 23, 28, 0.12);
  transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}
#chatw-launcher:hover {
  background: linear-gradient(135deg, #46579b 0%, var(--indigo-hover) 60%);
  transform: translateY(-2px);
  box-shadow: 0 14px 32px -6px rgba(46, 58, 107, 0.6),
              0 2px 8px rgba(21, 23, 28, 0.14);
}
#chatw-launcher:active { transform: translateY(0); }
#chatw-launcher:focus-visible { outline: 3px solid var(--indigo); outline-offset: 3px; }

#chatw-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #7d859e;
  flex: none;
}
#chatw-dot.is-online {
  background: #6fd39b;
  box-shadow: 0 0 0 0 rgba(111, 211, 155, 0.7);
  animation: chatw-pulse 2.4s ease-out infinite;
}
@keyframes chatw-pulse {
  70%  { box-shadow: 0 0 0 8px rgba(111, 211, 155, 0); }
  100% { box-shadow: 0 0 0 0 rgba(111, 211, 155, 0); }
}

#chatw-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--alert);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

/* ── 패널 ───────────────────────────────────────────────────── */
#chatw-panel {
  position: absolute;
  right: 0;
  bottom: 66px;
  width: 372px;
  height: 560px;
  max-height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform-origin: bottom right;
  animation: chatw-in 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes chatw-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
}

/* [hidden] 은 브라우저 기본이 display:none 이지만, display 를 명시한 요소
   (#chatw-panel, #chatw-form, #chatw-phone-row) 앞에서는 무력합니다.
   위젯 내부로만 한정해 눌러둡니다 — 전역으로 걸면 붙는 사이트를 망가뜨립니다. */
#chatw[hidden],
#chatw [hidden] { display: none !important; }

/* ── 헤더 ───────────────────────────────────────────────────── */
#chatw-head {
  flex: none;
  padding: 16px 16px 14px;
  background: var(--indigo);
  color: #fff;
}
#chatw-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
#chatw-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
#chatw-status {
  margin-top: 3px;
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.72);
}
#chatw-close {
  flex: none;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
#chatw-close:hover { background: rgba(255, 255, 255, 0.22); }
#chatw-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ── 본문 ───────────────────────────────────────────────────── */
#chatw-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px;
  background: var(--mist);
  scrollbar-width: thin;
}

.chatw-msg {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin-bottom: 12px;
  min-width: 0;
}
.chatw-msg.is-guest { justify-content: flex-end; }

.chatw-bubble {
  max-width: 76%;
  min-width: 0;
  padding: 9px 14px;
  border-radius: 14px;
  font-size: 14.5px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.is-agent .chatw-bubble {
  background: var(--paper);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
}
.is-guest .chatw-bubble {
  background: var(--indigo);
  color: #fff;
  border-top-right-radius: 4px;
}
.is-guest .chatw-bubble a { color: #cdd6f7; }
.chatw-bubble a { color: var(--indigo); }

.chatw-who {
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-60);
}
.chatw-time {
  flex: none;
  font-size: 11px;
  color: var(--ink-40);
  white-space: nowrap;
}
.chatw-msg.is-pending .chatw-bubble { opacity: 0.55; }

/* 시스템 안내 — 말풍선이 아니라 가로 구분선으로 처리해
   대화가 아니라 '상태 변화'임을 형태로 구분합니다. */
.chatw-sys {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  font-size: 12px;
  color: var(--ink-40);
}
.chatw-sys::before,
.chatw-sys::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* ── 사전 입력 폼 (비회원) ──────────────────────────────────── */
#chatw-intro { padding: 22px 18px; background: var(--paper); }
#chatw-intro h3 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
#chatw-intro p {
  font-size: 13.5px;
  color: var(--ink-60);
  margin-bottom: 18px;
}
.chatw-field { margin-bottom: 13px; }
.chatw-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-60);
}
.chatw-field input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  font: inherit;
  font-size: 14.5px;
  color: var(--ink);
}
.chatw-field input:focus {
  outline: 0;
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px var(--indigo-mist);
}
.chatw-hint { font-size: 12px; color: var(--ink-40); margin-top: 6px; }

.chatw-btn {
  width: 100%;
  height: 46px;
  border: 0;
  border-radius: 10px;
  background: var(--indigo);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.16s ease;
}
.chatw-btn:hover { background: var(--indigo-hover); }
.chatw-btn:disabled { background: var(--ink-40); cursor: default; }
.chatw-btn:focus-visible { outline: 3px solid var(--indigo); outline-offset: 2px; }

/* ── 입력부 ─────────────────────────────────────────────────── */
#chatw-foot {
  flex: none;
  border-top: 1px solid var(--line);
  background: var(--paper);
}
#chatw-notice {
  padding: 9px 16px;
  background: var(--indigo-mist);
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--indigo);
}
#chatw-form {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 11px 12px;
}
#chatw-input {
  flex: 1 1 auto;
  max-height: 108px;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--mist);
  font: inherit;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink);
  resize: none;
}
#chatw-input:focus {
  outline: 0;
  border-color: var(--indigo);
  background: var(--paper);
  box-shadow: 0 0 0 3px var(--indigo-mist);
}
#chatw-send {
  flex: none;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 11px;
  background: var(--indigo);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
}
#chatw-send:disabled { background: #c3c7d1; cursor: default; }
#chatw-send:focus-visible { outline: 3px solid var(--indigo); outline-offset: 2px; }
#chatw-send svg { width: 18px; height: 18px; }

#chatw-error {
  padding: 9px 16px;
  background: #fdeceb;
  color: var(--alert);
  font-size: 12.5px;
  border-top: 1px solid #f6d5d2;
}

/* ── 모바일 ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #chatw { right: 14px; bottom: 14px; }
  #chatw-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  /* 패널이 전체화면이 되므로 실행 버튼이 남아 있으면 전송 버튼을 덮습니다.
     닫기는 헤더의 X 로 합니다. */
  #chatw.is-open #chatw-launcher,
  #chatw.is-open #chatw-nudge { display: none !important; }

  /* 아이폰 홈 인디케이터에 입력창이 가리지 않도록 */
  #chatw-form { padding-bottom: calc(11px + env(safe-area-inset-bottom, 0px)); }
  #chatw-head { padding-top: calc(16px + env(safe-area-inset-top, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  #chatw *,
  #chatw *::before,
  #chatw *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ── 문자 알림 ────────────────────────────────────────────────
   대화 흐름을 끊지 않도록 헤더 바로 아래 얇은 띠로 붙입니다.
   본문(mist)과 헤더(indigo) 사이의 중간 톤이라 시선을 뺏지 않습니다. */
#chatw-notify {
  flex: none;
  padding: 10px 16px;
  background: var(--indigo-mist);
  border-bottom: 1px solid var(--line);
}

.chatw-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--indigo);
  cursor: pointer;
}
.chatw-check input {
  flex: none;
  width: 15px;
  height: 15px;
  margin-top: 2px;
  accent-color: var(--indigo);
  cursor: pointer;
}
.chatw-check:focus-within { outline: 2px solid var(--indigo); outline-offset: 3px; border-radius: 4px; }

/* 사전 입력 폼 안에서는 배경 없이 */
#chatw-optin-wrap {
  margin: 4px 0 16px;
  color: var(--ink60);
}

#chatw-phone-row {
  display: flex;
  gap: 7px;
  margin-top: 9px;
}
#chatw-phone {
  flex: 1;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  font: inherit;
  font-size: 13.5px;
}
#chatw-phone:focus { outline: 0; border-color: var(--indigo); }
#chatw-phone-save {
  flex: none;
  height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--indigo);
  color: #fff;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
#chatw-phone-save:hover { background: var(--indigo-hover); }

/* ── 상담 종료 ────────────────────────────────────────────────
   입력창을 잠그는 대신 통째로 교체합니다. 비활성 입력창을 남겨두면
   왜 안 써지는지 몰라 한참 두드리게 됩니다. */
#chatw-ended {
  padding: 16px;
  text-align: center;
}
#chatw-ended p {
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--ink60);
}


/* ── 시선 끌기 ────────────────────────────────────────────────
   무한 반복은 금방 피로해집니다. 몇 번만 튕기고 멈추게 했습니다. */

@keyframes chatw-attn {
  0%, 100% { transform: translateY(0)      scale(1); }
  15%      { transform: translateY(-7px)   scale(1.04); }
  30%      { transform: translateY(0)      scale(0.99); }
  45%      { transform: translateY(-4px)   scale(1.02); }
  60%      { transform: translateY(0)      scale(1); }
}

/* 버튼에서 퍼져 나가는 파동 */
@keyframes chatw-ring {
  0%   { opacity: 0.5; transform: scale(1); }
  100% { opacity: 0;   transform: scale(1.45); }
}

#chatw-launcher.is-attn { animation: chatw-attn 1.1s ease-in-out; }

#chatw-launcher.is-attn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--indigo);
  animation: chatw-ring 1.1s ease-out;
  z-index: -1;
  pointer-events: none;
}
#chatw-launcher { position: relative; z-index: 1; }

/* 말풍선 힌트 — 버튼 위에 잠깐 떴다 사라집니다 */
#chatw-nudge {
  position: absolute;
  right: 0;
  bottom: 70px;
  display: flex;
  align-items: center;
  gap: 10px;
  /* #chatw 는 버튼 너비만큼만 차지합니다. max-content 가 없으면
     말풍선이 그 폭에 갇혀 글자가 세로로 쪼개집니다. */
  width: max-content;
  max-width: 250px;
  padding: 11px 12px 11px 15px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px 14px 4px 14px;
  box-shadow: 0 10px 26px -8px rgba(21, 23, 28, 0.3);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  animation: chatw-nudge-in 0.36s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes chatw-nudge-in {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
}
#chatw-nudge-text { white-space: nowrap; }

#chatw-nudge-x {
  flex: none;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 6px;
  background: var(--mist);
  color: var(--ink40);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}
#chatw-nudge-x:hover { background: var(--line); color: var(--ink); }

@media (max-width: 480px) {
  #chatw-nudge { max-width: calc(100vw - 48px); }
  #chatw-nudge-text { white-space: normal; }
}