/* ============================================================
   Chat Widget — 제17차 GEMS 워크숍 안내 챗봇
   ------------------------------------------------------------
   디자인 토큰만 사용 (tokens.css). 별도 컬러 도입 금지.
   ============================================================ */

.chat-fab {
  position: fixed;
  right: max(var(--sp-6), env(safe-area-inset-right));
  bottom: max(var(--sp-6), env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: var(--radius-pill);
  border: none;
  background: var(--color-primary);
  color: var(--color-text-invert);
  box-shadow: 0 8px 24px rgba(11, 27, 43, 0.18), 0 2px 6px rgba(11, 27, 43, 0.12);
  cursor: pointer;
  z-index: 9000;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.chat-fab:hover  { background: var(--color-primary-dark); transform: translateY(-2px); }
.chat-fab:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
}
.chat-fab svg { width: 26px; height: 26px; }
.chat-fab[hidden] { display: none; }

.chat-panel {
  position: fixed;
  right: max(var(--sp-6), env(safe-area-inset-right));
  bottom: max(var(--sp-6), env(safe-area-inset-bottom));
  width: 360px;
  height: min(560px, calc(100dvh - var(--sp-8)));
  background: var(--color-bg-alt);
  color: var(--color-text);
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 60px rgba(11, 27, 43, 0.28), 0 6px 18px rgba(11, 27, 43, 0.14);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  z-index: 9100;
  border: 1px solid var(--color-border);
}
.chat-panel[hidden] { display: none; }

@media (max-width: 640px) {
  .chat-panel {
    inset: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: none;
  }
}

.chat-panel__header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4);
  background: var(--color-primary);
  color: var(--color-text-invert);
}
.chat-panel__title { font-size: var(--fs-16); font-weight: 600; margin: 0; line-height: var(--lh-snug); }
.chat-panel__sub   { font-size: var(--fs-12); color: var(--color-text-invert-muted); margin: 0; }
.chat-panel__badge {
  font-size: var(--fs-12);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: rgba(248, 250, 252, 0.18);
  color: var(--color-text-invert);
  margin-left: auto;
}
.chat-panel__badge--demo { background: var(--color-warning); color: #1F2937; }
.chat-panel__close {
  background: transparent;
  color: var(--color-text-invert);
  border: none;
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  cursor: pointer;
}
.chat-panel__close:hover { background: rgba(248, 250, 252, 0.14); }
.chat-panel__close:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.chat-body {
  padding: var(--sp-4);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  background: var(--color-bg-soft);
}

/* 메시지 묶음 — sender label + bubble 한 쌍 */
.chat-row {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  max-width: 90%;
}
.chat-row--bot  { align-self: flex-start; align-items: flex-start; }
.chat-row--user { align-self: flex-end;   align-items: flex-end; }

.chat-msg__sender {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-12);
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.01em;
  padding-left: 4px;
}
.chat-msg__sender img {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-pill);
  display: block;
  background: var(--color-bg-soft);
  padding: 2px;
  box-shadow: 0 1px 2px rgba(11, 27, 43, 0.08);
}

.chat-msg {
  max-width: 100%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg);
  font-size: var(--fs-14);
  line-height: var(--lh-normal);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-msg--bot {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-bottom-left-radius: var(--radius-sm);
}
.chat-msg--user {
  background: #E4ECF6;
  border: 1px solid #C9D8E9;
  color: #06325C;
  border-bottom-right-radius: var(--radius-sm);
}
.chat-msg a {
  color: var(--color-primary);
  font-weight: 600;
  text-decoration: underline;
}
.chat-msg--user a { color: var(--color-primary-dark); }

.chat-msg__typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.chat-msg__typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: chat-typing 1.2s infinite ease-in-out both;
}
.chat-msg__typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-msg__typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-typing {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-1);
  align-self: flex-start;
  max-width: 90%;
}
.chat-chip {
  border: 1px solid var(--color-border-strong);
  background: var(--color-bg-alt);
  color: var(--color-primary);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-12);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.chat-chip:hover         { background: var(--color-primary-soft); border-color: var(--color-primary); }
.chat-chip:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-bg-alt);
  border-top: 1px solid var(--color-border);
}
.chat-input {
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: var(--fs-14);
  font-family: inherit;
  resize: none;
  min-height: 42px;
  max-height: 96px;
  line-height: var(--lh-snug);
  color: var(--color-text);
  background: var(--color-bg-alt);
  overflow-y: auto;
}
.chat-input:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
  border-color: var(--color-primary);
}
.chat-input:disabled { background: var(--color-bg-soft); }

.chat-send {
  background: var(--color-primary);
  color: var(--color-text-invert);
  border: none;
  border-radius: var(--radius-md);
  width: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chat-send:hover:not(:disabled) { background: var(--color-primary-dark); }
.chat-send:disabled             { opacity: 0.5; cursor: not-allowed; }
.chat-send:focus-visible        { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.chat-send svg { width: 18px; height: 18px; }

.chat-foot {
  font-size: var(--fs-12);
  color: var(--color-text-muted);
  padding: 0 var(--sp-4) var(--sp-3);
  background: var(--color-bg-alt);
}

@media (prefers-reduced-motion: reduce) {
  .chat-fab, .chat-msg__typing span { transition: none; animation: none; }
}
