/* ═══════════════════════════════════════════════════════
   로컬 LLM 채팅
   ══════════════════════════════════════════════════════ */

.llm-layout {
  display: flex;
  gap: 0;
  height: calc(100vh - var(--sw) - 80px);
  min-height: 560px;
  border: 1px solid var(--bd);
  border-radius: var(--r);
  overflow: hidden;
  background: var(--s1);
}

/* ── 왼쪽 사이드바 ──────────────────────────────────── */
.llm-sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--s2);
  border-right: 1px solid var(--bd);
  display: flex;
  flex-direction: column;
}

.llm-sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--bd);
}

.llm-sidebar-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--t1);
}

.llm-session-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.llm-session-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--t2);
  transition: all var(--tr);
  margin-bottom: 2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.llm-session-item:hover {
  background: var(--s3);
  color: var(--t1);
}

.llm-session-item.active {
  background: var(--ag);
  color: var(--a);
}

.llm-session-item .llm-sess-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.llm-session-item .llm-sess-del {
  opacity: 0;
  color: var(--red);
  font-size: 14px;
  transition: opacity var(--tr);
  flex-shrink: 0;
}

.llm-session-item:hover .llm-sess-del {
  opacity: 1;
}

.llm-sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--bd);
}

.llm-empty {
  padding: 20px 12px;
  font-size: 11px;
  color: var(--t2);
  text-align: center;
  line-height: 1.6;
}

/* ── 메인 영역 ──────────────────────────────────────── */
.llm-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* 상단 바 */
.llm-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 10px 14px;
  border-bottom: 1px solid var(--bd);
  background: var(--s2);
  gap: 10px;
}

.llm-header-left,
.llm-header-right {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.llm-conn-dot {
  font-size: 12px;
  color: var(--t2);
  padding-bottom: 6px;
}

.llm-conn-dot.connected {
  color: var(--grn);
}

.llm-conn-dot.error {
  color: var(--red);
}

.llm-header-left .ck {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: var(--t1);
  white-space: nowrap;
  user-select: none;
}
.llm-header-left .ck input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

/* 설정 패널 */
.llm-settings {
  background: var(--s3);
  border-bottom: 1px solid var(--bd);
  padding: 12px 14px;
}

/* 메시지 영역 */
.llm-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.llm-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--t2);
  gap: 8px;
}

.llm-welcome-icon {
  font-size: 40px;
  opacity: 0.3;
}

.llm-welcome-text {
  font-size: 14px;
  font-weight: 600;
}

.llm-welcome-hint {
  font-size: 12px;
}

/* 메시지 버블 */
.llm-msg {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: llm-fade-in 0.2s ease;
}

@keyframes llm-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.llm-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.llm-msg.assistant {
  align-self: flex-start;
}

.llm-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.llm-msg.user .llm-msg-avatar {
  background: var(--a);
  color: #fff;
}

.llm-msg.assistant .llm-msg-avatar {
  background: var(--s4);
  color: var(--t1);
}

.llm-msg-bubble {
  padding: 10px 14px;
  border-radius: var(--r);
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.llm-msg.user .llm-msg-bubble {
  background: var(--a);
  color: #fff;
  border-bottom-right-radius: 2px;
}

.llm-msg.assistant .llm-msg-bubble {
  background: var(--s3);
  color: var(--t0);
  border: 1px solid var(--bd);
  border-bottom-left-radius: 2px;
}

.llm-msg-bubble code {
  background: rgba(0,0,0,0.3);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--fm);
  font-size: 12px;
}

.llm-msg-bubble pre {
  background: rgba(0,0,0,0.4);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
  font-family: var(--fm);
  font-size: 12px;
  line-height: 1.5;
}

.llm-msg-bubble pre code {
  background: none;
  padding: 0;
}

/* 타이핑 인디케이터 */
.llm-typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.llm-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--t2);
  animation: llm-bounce 1.2s infinite;
}

.llm-typing span:nth-child(2) { animation-delay: 0.2s; }
.llm-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes llm-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── 입력 영역 ──────────────────────────────────────── */
.llm-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--bd);
  background: var(--s2);
}

.llm-input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.llm-textarea {
  flex: 1;
  background: var(--s3);
  border: 1px solid var(--bd);
  border-radius: var(--r);
  padding: 10px 14px;
  color: var(--t0);
  font-family: var(--ff);
  font-size: 13px;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 150px;
  transition: border-color var(--tr);
}

.llm-textarea:focus {
  border-color: var(--a);
}

.llm-textarea::placeholder {
  color: var(--t2);
}

.llm-input-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ── 반응형 ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .llm-sidebar { display: none; }
  .llm-layout { height: calc(100vh - var(--sw) - 120px); }
}

/* ═══════════════════════════════════════════════════════
   Phase 5 — 채팅 통합 (툴 카드 / KB 인용 / 표 / 추천 칩)
   ══════════════════════════════════════════════════════ */

/* 툴 카드 컨테이너 — assistant 메시지 버블 위 */
.llm-tool-cards {
  display: flex; flex-direction: column; gap: 6px;
  margin: 4px 0 8px 0;
}

.llm-tool-card {
  border: 1px solid var(--bd1);
  border-radius: var(--rm);
  background: var(--s1);
  font-size: 12px;
  overflow: hidden;
}
.llm-tool-card.running .llm-tool-icon { animation: spin 1.4s linear infinite; }
.llm-tool-card.ok      { border-color: #2a5a3a; }
.llm-tool-card.err     { border-color: #5a2a2a; }
.llm-tool-card.extending { border-color: #8a6a1f; background: rgba(180, 130, 30, 0.06); }
.llm-tool-card.extending .llm-tool-icon { animation: spin 0.7s linear infinite; }
.llm-tool-card.extending .llm-tool-status { color: #e9b94a; }

.llm-tool-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; cursor: pointer;
  background: var(--s2);
  user-select: none;
}
.llm-tool-head:hover { background: var(--s3, #2a2a2e); }
.llm-tool-icon { font-size: 13px; }
.llm-tool-name { font-weight: 600; color: var(--t0); }
.llm-tool-args {
  flex: 1; color: var(--t2); font-size: 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.llm-tool-status { font-size: 11px; color: var(--t2); flex-shrink: 0; }
.llm-tool-card.ok  .llm-tool-status { color: #6bd58b; }
.llm-tool-card.err .llm-tool-status { color: #f37070; }

.llm-tool-body { display: none; padding: 8px 10px; }
.llm-tool-card.open .llm-tool-body { display: block; }
.llm-tool-raw {
  margin: 0; padding: 6px 8px; max-height: 240px; overflow: auto;
  font-family: var(--ffm); font-size: 11px;
  background: var(--s0); border: 1px solid var(--bd1); border-radius: 4px;
  white-space: pre-wrap; word-break: break-all;
}
.llm-tool-err {
  color: #f37070; font-family: var(--ffm); font-size: 12px;
  padding: 6px 8px;
}
.llm-tool-more {
  font-size: 11px; color: var(--t2); margin-top: 4px; text-align: right;
}

/* 툴 결과 표 */
.llm-tool-tbl-wrap { max-height: 320px; overflow: auto; border: 1px solid var(--bd1); border-radius: 4px; }
.llm-tool-tbl {
  width: 100%; border-collapse: collapse; font-size: 11px; font-family: var(--ffm);
}
.llm-tool-tbl th, .llm-tool-tbl td {
  padding: 4px 8px; border-bottom: 1px solid var(--bd1);
  text-align: left; white-space: nowrap;
}
.llm-tool-tbl th {
  background: var(--s2); position: sticky; top: 0;
  font-weight: 600; color: var(--t1);
}

/* 대화 요약 배너 (Phase 7.2) */
.llm-summary-card {
  margin: 4px 0 12px 0; padding: 8px 12px;
  border: 1px dashed #4a5a7a; border-radius: 6px;
  background: rgba(80, 110, 160, 0.08);
  cursor: pointer; user-select: none;
}
.llm-summary-head { font-size: 12px; color: var(--t2); font-weight: 600; }
.llm-summary-body {
  display: none; margin-top: 8px; padding-top: 6px;
  border-top: 1px solid var(--bd1);
  font-size: 12px; color: var(--t1); line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.llm-summary-card.open .llm-summary-body { display: block; }

/* 시계열 스파클라인 (툴 카드 안) */
.llm-sparkline-box {
  margin-bottom: 8px; padding: 8px 10px;
  border: 1px solid var(--bd1); border-radius: 4px;
  background: var(--s0);
}
.llm-sparkline-label { font-size: 11px; color: var(--t2); margin-bottom: 4px; }
.llm-sparkline-chart { width: 100%; min-height: 90px; }
.llm-sparkline-chart .u-legend { display: none !important; }

/* KB 검색 결과 (search_kb 카드 안) */
.llm-kb-hits { display: flex; flex-direction: column; gap: 6px; }
.llm-kb-hit {
  padding: 6px 8px; background: var(--s0);
  border: 1px solid var(--bd1); border-radius: 4px;
}
.llm-kb-head { font-size: 12px; color: var(--t0); margin-bottom: 2px; }
.llm-kb-head .mono { color: var(--t2); margin-right: 6px; }
.llm-kb-snip { font-size: 11px; color: var(--t1); line-height: 1.4; }

/* KB 인용 링크 (본문 안) */
.kb-cite-link {
  color: var(--a); text-decoration: none;
  border-bottom: 1px dashed var(--a);
  padding-bottom: 1px;
}
.kb-cite-link:hover { color: #fff; border-bottom-style: solid; }

/* welcome 추천 질문 칩 */
.llm-chip-row {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; margin-top: 16px;
  max-width: 720px;
}
.llm-chip {
  padding: 6px 12px;
  background: var(--s2);
  border: 1px solid var(--bd1);
  border-radius: 16px;
  color: var(--t0);
  font-family: var(--ff);
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
}
.llm-chip:hover {
  background: var(--s3, var(--s2));
  border-color: var(--a);
  transform: translateY(-1px);
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
