/**
 * AI 학습 도우미 — 플로팅 채팅 위젯
 * 경로: /learner/inc/ai-chat-widget.css
 *
 * Tailwind 임의값(bg-[color:var(--t-*)])이 JIT 빌드에서 인식되지 않아
 * 페이지 전용 CSS 로 분리. 모든 색상은 --t-* 변수만 사용.
 */

/* ─── 위젯 컨테이너 ─── */
#ai-chat-widget {
  position: fixed;
  bottom: 5rem;
  right: 1rem;
  z-index: var(--t-z-widget);
  width: 22rem;
  max-height: 32rem;
  display: flex;
  flex-direction: column;
  background: var(--t-paper);
  border: 1px solid var(--t-line);
  border-radius: 1rem;
  box-shadow: var(--t-shadow-xl, 0 20px 25px -5px rgba(0,0,0,.12), 0 8px 10px -6px rgba(0,0,0,.08));
  overflow: hidden;
}

/* ─── 헤더 ─── */
.ai-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: linear-gradient(to right, var(--t-clay-500), var(--t-clay-600));
  color: var(--t-paper);
}

.ai-chat__brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}

.ai-chat__brand-img {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  padding: 0.125rem;
  flex-shrink: 0;
}

.ai-chat__brand-name {
  display: block;
  font-size: var(--t-fs-sm);
  font-weight: 600;
  line-height: 1.15;
}

.ai-chat__brand-sub {
  display: block;
  font-size: 11px;
  opacity: 0.85;
}

.ai-chat__actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.ai-chat__action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem;
  border: 0;
  background: transparent;
  border-radius: 0.5rem;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.ai-chat__action-btn:hover { background: rgba(255,255,255,0.18); }
.ai-chat__action-btn .material-symbols-outlined { font-size: 20px; }

/* ─── 세션 목록 오버레이 ─── */
.ai-chat__sessions {
  position: absolute;
  inset: 52px 0 0 0;
  background: var(--t-paper);
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.ai-chat__sessions-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--t-line);
  font-size: var(--t-fs-sm);
  font-weight: 600;
  color: var(--t-ink);
}

.ai-chat__sessions-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  border: 0;
  background: transparent;
  border-radius: 0.375rem;
  color: var(--t-muted);
  cursor: pointer;
}
.ai-chat__sessions-close:hover { background: var(--t-bg); color: var(--t-ink); }
.ai-chat__sessions-close .material-symbols-outlined { font-size: 20px; }

.ai-chat__sessions-list {
  flex: 1;
  overflow-y: auto;
}

.ai-chat__sessions-loading,
.ai-chat__sessions-empty {
  padding: 2rem 1rem;
  text-align: center;
  font-size: var(--t-fs-sm);
  color: var(--t-muted);
}

/* ─── 세션 아이템 (JS 동적) ─── */
.ai-chat__session-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--t-line);
  cursor: pointer;
  transition: background 0.15s;
}
.ai-chat__session-item:hover { background: var(--t-bg); }
.ai-chat__session-item.active { background: var(--t-clay-100); }

.ai-chat__session-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.ai-chat__session-title {
  font-size: var(--t-fs-sm);
  color: var(--t-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-chat__session-meta {
  font-size: var(--t-fs-2xs);
  color: var(--t-muted);
}

.ai-chat__session-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.625rem;
  height: 1.625rem;
  border: 0;
  background: transparent;
  border-radius: 0.375rem;
  color: var(--t-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}
.ai-chat__session-item:hover .ai-chat__session-del { opacity: 1; }
.ai-chat__session-del:hover { background: var(--t-paper); color: var(--t-danger, #c44); }
.ai-chat__session-del .material-symbols-outlined { font-size: 18px; }

/* ─── 메시지 영역 ─── */
.ai-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  background: var(--t-paper);
}

/* ─── 환영 화면 ─── */
.ai-chat__welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1.5rem 0;
}

.ai-chat__welcome-img {
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  margin-bottom: 0.75rem;
}

.ai-chat__welcome-title {
  font-size: var(--t-fs-base);
  font-weight: 700;
  color: var(--t-ink);
  margin-bottom: 0.25rem;
}

.ai-chat__welcome-desc {
  font-size: var(--t-fs-sm);
  color: var(--t-muted);
  line-height: 1.55;
  margin-bottom: 1rem;
}

.ai-chat__suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.375rem;
}

.ai-chat__chip,
.ai-chat__suggest-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.375rem 0.75rem;
  font-size: var(--t-fs-2xs);
  background: var(--t-clay-50);
  color: var(--t-clay-700);
  border: 1px solid var(--t-clay-100);
  border-radius: 9999px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.ai-chat__chip:hover,
.ai-chat__suggest-btn:hover { opacity: 0.85; }

/* ─── 메시지 버블 (JS 동적) ─── */
.ai-chat__msg {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.625rem;
  align-items: flex-end;
}
.ai-chat__msg--user { justify-content: flex-end; }

.ai-chat__msg-avatar {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  overflow: hidden;
  background: var(--t-clay-100);
}
.ai-chat__msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ai-chat__bubble {
  max-width: 78%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.875rem;
  font-size: var(--t-fs-sm);
  line-height: 1.55;
  word-break: break-word;
}
.ai-chat__msg--assistant .ai-chat__bubble {
  background: var(--t-bg);
  color: var(--t-ink);
  border-bottom-left-radius: 0.25rem;
}
.ai-chat__msg--user .ai-chat__bubble {
  background: var(--t-clay-500);
  color: var(--t-paper);
  border-bottom-right-radius: 0.25rem;
}
.ai-chat__msg--system .ai-chat__bubble {
  background: var(--t-warning-soft, color-mix(in srgb, var(--t-mustard-500) 14%, transparent));
  color: var(--t-mustard-700);
  font-size: var(--t-fs-xs);
}

.ai-chat__bubble code {
  background: color-mix(in srgb, var(--t-ink) 8%, transparent);
  padding: 0.0625rem 0.25rem;
  border-radius: 0.25rem;
  font-size: 0.92em;
}
.ai-chat__msg--user .ai-chat__bubble code {
  background: color-mix(in srgb, var(--t-paper) 25%, transparent);
}
.ai-chat__bubble strong { font-weight: 700; }
.ai-chat__bubble em { font-style: italic; }

.ai-chat__system-text {
  font-size: var(--t-fs-xs);
  color: var(--t-mustard-700);
}

/* ─── 타이핑 인디케이터 ─── */
.ai-chat__typing {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  margin-bottom: 0.625rem;
}

.ai-chat__dots {
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: var(--t-bg);
  border-radius: 0.875rem;
  border-bottom-left-radius: 0.25rem;
}
.ai-chat__dots span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--t-muted);
  animation: ai-chat-typing 1.2s infinite ease-in-out;
}
.ai-chat__dots span:nth-child(2) { animation-delay: 0.15s; }
.ai-chat__dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-chat-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ─── 입력 바 ─── */
.ai-chat__input-bar {
  padding: 0.625rem 0.75rem;
  border-top: 1px solid var(--t-line);
  background: var(--t-bg);
}

.ai-chat__input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ai-chat__input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  font-size: var(--t-fs-sm);
  background: var(--t-paper);
  border: 1px solid var(--t-line);
  border-radius: 0.75rem;
  color: var(--t-ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ai-chat__input::placeholder { color: var(--t-muted); }
.ai-chat__input:focus {
  border-color: var(--t-clay-300);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--t-clay-300) 50%, transparent);
}

.ai-chat__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border: 0;
  background: var(--t-clay-500);
  color: var(--t-paper);
  border-radius: 0.75rem;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.ai-chat__send:hover:not(:disabled) { background: var(--t-clay-600); }
.ai-chat__send:disabled { opacity: 0.4; cursor: not-allowed; }
.ai-chat__send .material-symbols-outlined { font-size: 20px; }

.ai-chat__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.375rem;
  font-size: 11px;
  color: var(--t-muted);
}

.ai-chat__open-full {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  color: var(--t-clay-600);
  text-decoration: none;
  transition: opacity 0.15s;
}
.ai-chat__open-full:hover { opacity: 0.8; }
.ai-chat__open-full .material-symbols-outlined { font-size: 12px; }
