/* JOYCAR AI 상담 위젯 (renewal.css 토큰 사용) */
.aichat-fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 900;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 18px 0 14px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--c-primary-2), var(--c-primary));
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 14px 32px rgba(43, 99, 246, 0.4);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.aichat-fab:hover { transform: translateY(-2px); }
.aichat-fab.is-open { box-shadow: none; opacity: 0.85; }

.aichat-fab__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c-gold-2);
  box-shadow: 0 0 0 4px rgba(240, 207, 138, 0.25);
}

.aichat-panel[hidden] { display: none !important; }
.aichat-panel {
  position: fixed;
  right: 16px;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  z-index: 901;
  width: min(400px, calc(100vw - 32px));
  max-height: min(680px, calc(100vh - 110px));
  display: flex;
  flex-direction: column;
  border-radius: var(--r-lg);
  border: 1px solid var(--c-line-strong);
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

.aichat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--c-line);
  background: var(--c-surface-2);
}

.aichat-title { display: grid; gap: 2px; }
.aichat-title strong { font-size: 15px; }
.aichat-title span { font-size: 12px; color: var(--c-text-2); }

.aichat-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--c-text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.aichat-body {
  flex: 1 1 auto;
  min-height: 220px;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 16px;
}

.aichat-msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: keep-all;
}

.aichat-msg--user {
  justify-self: end;
  background: var(--c-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.aichat-msg--bot {
  justify-self: start;
  background: var(--c-surface-2);
  border-bottom-left-radius: 4px;
}

.aichat-typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.aichat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-text-2);
  animation: aichat-bounce 1s infinite;
}
.aichat-typing span:nth-child(2) { animation-delay: 0.15s; }
.aichat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes aichat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.aichat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 12px;
}

.aichat-chip {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--c-line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--c-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.aichat-chip:hover { background: rgba(255, 255, 255, 0.09); }

.aichat-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--c-line);
  background: var(--c-surface-2);
}

.aichat-input {
  flex: 1 1 auto;
  min-height: 44px !important;
  max-height: 120px;
  padding: 11px 14px !important;
  resize: none;
  font-size: 14px;
}

.aichat-send {
  flex: none;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--c-primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.aichat-send:disabled { opacity: 0.5; cursor: default; }

.aichat-foot {
  margin: 0;
  padding: 8px 16px 12px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--c-text-2);
  background: var(--c-surface-2);
}

@media (max-width: 640px) {
  .aichat-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: 92vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: 0;
  }
  .aichat-fab { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  body.aichat-open .aichat-fab { display: none; }
}

.aichat-chips[hidden] { display: none; }

/* 답변 색 강조: 굵은 글씨=금색, 금액=민트, 날짜·시간=하늘색 */
.aichat-msg--bot strong { color: #f3d28a; font-weight: 800; }
.aichat-msg--bot .aichat-price { color: #7ee0a8; font-weight: 800; }
.aichat-msg--bot .aichat-when { color: #8ec5ff; font-weight: 700; }
/* 답변 기다리는 동안: 자동차가 달리며 거품이 터지는 로딩 */
.aichat-typing { display: inline-flex; align-items: center; gap: 10px; padding: 10px 14px; }
.aichat-typing span:not(.aichat-road) { display: none; }
.aichat-typing em { font-style: normal; font-size: 13px; color: #aeb9cc; }
.aichat-typing .aichat-road { border-radius: 0; position: relative; display: inline-block; width: 74px; height: 26px; border-bottom: 2px dashed rgba(209,163,77,.5); overflow: hidden; animation: none !important; background: none !important; }
.aichat-road i { position: absolute; font-style: normal; line-height: 1; }
.aichat-car { bottom: 1px; font-size: 20px; transform: scaleX(-1); animation: aiCarDrive 1.6s ease-in-out infinite; }
.aichat-bub { top: 2px; font-size: 11px; opacity: 0; animation: aiBubPop 1.6s ease-in-out infinite; }
.aichat-bub.b1 { left: 8px; animation-delay: .1s; } .aichat-bub.b2 { left: 30px; animation-delay: .5s; } .aichat-bub.b3 { left: 54px; animation-delay: .9s; }
@keyframes aiCarDrive { 0% { left: -22px; } 100% { left: 78px; } }
@keyframes aiBubPop { 0%,100% { opacity: 0; transform: translateY(6px) scale(.6); } 50% { opacity: 1; transform: translateY(-2px) scale(1.1); } }

/* AI 상담 버튼: 귀여운 캐릭터가 통통 튀며 눌러 달라고 손짓 + 빛 반짝임 */
.aichat-fab { overflow: visible; animation: aiFabBob 3.2s ease-in-out infinite; }
.aichat-fab.is-open { animation: none; }
.aichat-fab__face { display: inline-block; font-size: 24px; line-height: 1; transform-origin: 50% 90%; animation: aiFaceWave 3.2s ease-in-out infinite; filter: drop-shadow(0 2px 3px rgba(0,0,0,.25)); }
.aichat-fab::after { content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(110deg, transparent 35%, rgba(255,255,255,.55) 50%, transparent 65%); background-size: 250% 100%; background-position: 160% 0; animation: aiFabShine 3.2s ease-in-out infinite; }
.aichat-fab::before { content: '✨'; position: absolute; right: -6px; top: -10px; font-size: 16px; animation: aiSpark 3.2s ease-in-out infinite; pointer-events: none; }
.aichat-fab.is-open::before, .aichat-fab.is-open::after { display: none; }
.aichat-tip { position: fixed; right: 18px; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); z-index: 901; padding: 10px 14px; border-radius: 14px 14px 4px 14px;
  background: #fff; color: #172036; font-size: 14px; font-weight: 800; box-shadow: 0 10px 28px rgba(0,0,0,.28); cursor: pointer; animation: aiTipIn .4s ease-out, aiTipFloat 2.4s ease-in-out .4s infinite; }
.aichat-tip[hidden] { display: none; }
@keyframes aiFabBob { 0%, 55%, 100% { transform: translateY(0); } 62% { transform: translateY(-9px); } 70% { transform: translateY(0); } 76% { transform: translateY(-4px); } 82% { transform: translateY(0); } }
@keyframes aiFaceWave { 0%, 58%, 100% { transform: rotate(0); } 64% { transform: rotate(-14deg) scale(1.12); } 72% { transform: rotate(12deg) scale(1.12); } 80% { transform: rotate(-6deg); } }
@keyframes aiFabShine { 0%, 50% { background-position: 160% 0; } 75%, 100% { background-position: -60% 0; } }
@keyframes aiSpark { 0%, 55%, 100% { opacity: 0; transform: scale(.4) rotate(0); } 68% { opacity: 1; transform: scale(1.2) rotate(20deg); } 85% { opacity: 0; transform: scale(.6) rotate(40deg); } }
@keyframes aiTipIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes aiTipFloat { 50% { transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) { .aichat-fab, .aichat-fab__face, .aichat-fab::after, .aichat-fab::before, .aichat-tip { animation: none !important; } }
