/**
 * styles/chatbot.css — RAG 챗봇 페이지 (Hotfix #121)
 *
 * 레이아웃: 좌 대화 목록 280px + 우 메시지/입력 (모바일은 1열).
 */

.chatbot-page {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: calc(100vh - 60px);
  min-height: 500px;
}

/* #196 v2 Part A: 단일 컬럼 (좌측 이력 패널 제거) */
.chatbot-page--single {
  display: flex;
  flex-direction: column;
  grid-template-columns: none;
  max-width: 1024px;
  margin: 0 auto;
  padding: 16px 20px 0;
  box-sizing: border-box;
  width: 100%;
}

/* #196 v3 Part A: v2 의 .chatbot-header* 룰 폐기 — HTML 에서 헤더 제거됨.
   (CSS 정의 자체는 무해. 미래 안전을 위해 남겨두지만 셀렉터 매치 0건.) */

/* #196 v3 Part A: 검색 범위 줄의 필터 + 새 대화 버튼 그룹 (사장님 명시 — 맨 오른쪽) */
.chat-input-filter__left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.chat-input-filter__actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: auto;
}

.chatbot-filter-btn,
.chatbot-new-chat-btn {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chatbot-filter-btn {
  background: #FFFFFF;
  border: 1px solid #D1D5DB;
  color: #374151;
}
.chatbot-filter-btn:hover {
  background: #F9FAFB;
  border-color: #9CA3AF;
}
.chatbot-filter-btn[aria-expanded="true"] {
  background: #FEF3C7;
  border-color: #C9A961;
  color: #92400E;
}

.chatbot-filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #0F1E3D;
  color: #FFFFFF;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}
.chatbot-filter-badge.hidden {
  display: none;
}

.chatbot-new-chat-btn {
  background: #0F1E3D;       /* 사장님 브랜드 네이비 */
  color: #FFFFFF;
  border: 1px solid #0F1E3D;
}
.chatbot-new-chat-btn:hover {
  background: #1e3055;
  border-color: #1e3055;
}

/* #196 v3 Part C: 팝업 필터 패널 (전체 기록 패턴) */
.chatbot-filter-panel {
  margin-top: 8px;
  padding: 12px 14px;
  background: #FFFFFF;
  border: 1px solid #E5E7EB;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chatbot-filter-panel.hidden {
  display: none;
}
.chatbot-filter-panel__row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chatbot-filter-panel__row label {
  font-size: 12px;
  font-weight: 600;
  color: #4B5563;
}
.chatbot-filter-input {
  padding: 8px 10px;
  border: 1px solid #D1D5DB;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: #FFFFFF;
  color: #111827;
}
.chatbot-filter-input:focus {
  outline: none;
  border-color: #0F1E3D;
  box-shadow: 0 0 0 3px rgba(15, 30, 61, 0.08);
}
.chatbot-filter-hint {
  margin: 0;
  font-size: 11px;
  color: #9CA3AF;
  line-height: 1.4;
}
.chatbot-filter-panel__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.chatbot-filter-reset,
.chatbot-filter-apply {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
}
.chatbot-filter-reset {
  background: #FFFFFF;
  border: 1px solid #D1D5DB;
  color: #374151;
}
.chatbot-filter-reset:hover {
  background: #F3F4F6;
}
.chatbot-filter-apply {
  background: #0F1E3D;
  border: 1px solid #0F1E3D;
  color: #FFFFFF;
}
.chatbot-filter-apply:hover {
  background: #1e3055;
}

/* ── 사이드바 ── */
.chatbot-sidebar {
  border-right: 1px solid #e5e7eb;
  background: #f9fafb;
  padding: 16px;
  overflow-y: auto;
}

.chatbot-sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.chatbot-sidebar__header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #0F1E3D;
}
.chatbot-new-btn {
  background: #0F1E3D;
  color: white;
  border: 0;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.chatbot-new-btn:hover { background: #1e3055; }

.conv-list { display: flex; flex-direction: column; gap: 4px; }
.conv-empty {
  font-size: 12px;
  color: #9ca3af;
  text-align: center;
  padding: 16px 8px;
}
.conv-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  color: inherit;
}
.conv-item:hover { background: #f3f4f6; }
.conv-item.active { background: #e0e7ff; }
.conv-title { font-weight: 500; font-size: 13px; color: #111827; }
.conv-date { font-size: 11px; color: #6b7280; margin-top: 2px; }

/* ── 메인 ── */
.chatbot-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-welcome {
  text-align: center;
  padding: 40px 20px;
  color: #4b5563;
}
.chat-welcome h2 { margin: 0 0 8px; font-size: 18px; color: #0F1E3D; }
.chat-welcome p { margin: 0 0 16px; font-size: 13px; }
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 600px;
  margin: 0 auto;
}
.chat-suggestion {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 16px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  color: #374151;
}
.chat-suggestion:hover { background: #e0e7ff; border-color: #0F1E3D; }

/* #194-5 (Phase 5): welcome 활용법 박스 */
.chat-welcome__tips {
  background: #F9FAFB;
  border: 1px solid #E5E7EB;
  border-radius: 10px;
  padding: 14px 18px;
  margin: 16px auto 20px;
  max-width: 640px;
  text-align: left;
}
.chat-welcome__tips h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: #0F1E3D;
}
.chat-welcome__tips ul {
  margin: 0;
  padding-left: 18px;
  list-style: disc;
  font-size: 12px;
  color: #4B5563;
  line-height: 1.7;
}
.chat-welcome__tips li {
  margin-bottom: 2px;
}
.chat-welcome__tips strong {
  color: #0F1E3D;
}

.chat-msg {
  display: flex;
  gap: 10px;
  max-width: 80%;
}
.chat-msg--user {
  flex-direction: row-reverse;
  align-self: flex-end;
}
.chat-msg--bot {
  align-self: flex-start;
}
.chat-msg__avatar { font-size: 22px; flex-shrink: 0; }
.chat-msg__bubble {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px 12px 12px 4px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.55;
  /* #194-1: 한국어 단어 단위 줄바꿈 — 어색한 자모 분리 방지 */
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.chat-msg--user .chat-msg__bubble {
  background: #0F1E3D;
  color: white;
  border-color: #0F1E3D;
  border-radius: 12px 12px 4px 12px;
}
.chat-msg--loading .chat-msg__bubble {
  background: #f9fafb;
  color: #6b7280;
  font-style: italic;
}
.chat-loading { font-size: 13px; }

/* #194-4 (Phase 4): 다중 회의 통합 정리 모드 배지 */
.chat-msg__mode-badge {
  display: inline-block;
  margin-bottom: 8px;
  padding: 4px 10px;
  border-radius: 12px;
  background: #FEF3C7;     /* amber-100 */
  color: #92400E;           /* amber-800 */
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* ── 참조 자료 카드 ── */
.chat-sources {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed #e5e7eb;
}
.chat-sources__title {
  font-size: 12px;
  color: #6b7280;
  font-weight: 600;
  margin-bottom: 8px;
}
.chat-source {
  background: #f9fafb;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 4px;
  font-size: 12px;
}
.chat-source__head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.chat-source__num {
  font-weight: 600;
  color: #0F1E3D;
}
.chat-source__title {
  color: #0F1E3D;
  text-decoration: none;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-source__title:hover { text-decoration: underline; }
.chat-source__date,
.chat-source__sim {
  color: #6b7280;
  font-size: 11px;
}

/* #194-3 (Phase 3): chunk_source 배지 — 원본 STT vs 정리된 회의록 식별 */
.chat-source__type {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  line-height: 1.4;
}
.chat-source__type--raw {
  background: #FEF3C7;  /* amber-100 — 원본 STT */
  color: #92400E;        /* amber-800 */
}
.chat-source__type--formatted {
  background: #DBEAFE;  /* blue-100 — 정리된 회의록 */
  color: #1E40AF;        /* blue-800 */
}
.chat-source__excerpt {
  color: #4b5563;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ── 입력창 ── */
/* #194-1: position sticky 로 화면 하단 고정 — flex 컨테이너 안에서
   chat-messages 가 flex:1 로 늘어나며 입력창은 항상 보이게 됨 (모바일 키보드 친화) */
.chat-input-area {
  border-top: 1px solid #e5e7eb;
  padding: 14px 20px;
  background: white;
  position: sticky;
  bottom: 0;
  z-index: 5;
}
.chat-input-filter {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 13px;
  flex-wrap: wrap;
}
.chat-input-filter__label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #4b5563;
}
.chat-input-filter__label select {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  background: white;
}
.chat-input-filter__hint {
  color: #9ca3af;
  font-size: 11px;
}
.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.chat-input-row textarea {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  line-height: 1.4;
}
.chat-input-row textarea:focus {
  outline: none;
  border-color: #0F1E3D;
  box-shadow: 0 0 0 2px rgba(15, 30, 61, 0.1);
}
.chat-send-btn {
  background: #0F1E3D;
  color: white;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.chat-send-btn:hover:not(:disabled) { background: #1e3055; }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* #194-1: AI 답변 참고용 안내 — 입력창 아래 항상 노출 */
.chat-disclaimer {
  margin: 8px 0 0;
  font-size: 11px;
  color: #9ca3af;
  text-align: center;
  line-height: 1.4;
}

/* ── 모바일 ── */
@media (max-width: 768px) {
  .chatbot-page { grid-template-columns: 1fr; }
  .chatbot-sidebar { display: none; }

  /* #196 v2 Part A: 단일 컬럼 모바일 — 좌우 padding 축소 */
  .chatbot-page--single {
    padding: 12px 12px 0;
  }
  .chatbot-header__title {
    font-size: 16px;
  }
  .chatbot-clear-btn {
    font-size: 11px;
    padding: 5px 10px;
  }

  /* #194-1: 모바일 메시지 폭 확장 — 짧은 텍스트 4줄 잘림 방지 */
  .chat-msg { max-width: 95%; }
  .chat-msg__bubble {
    padding: 10px 12px;
    font-size: 15px;  /* iOS 자동 zoom 방지 (16px 미만이지만 bubble 은 OK) */
  }

  /* #194-1: 메시지 영역 패딩 축소 (모바일에서 화면 활용도 ↑) */
  .chat-messages { padding: 14px 12px; }

  /* #194-1: 빠른 질문 — 가로 스크롤 chip (모바일 표준 패턴) */
  .chat-suggestions {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    padding: 4px 12px 12px;
    margin: 0 -12px;  /* welcome 좌우 padding 상쇄 → 화면 끝까지 스크롤 영역 */
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;  /* Firefox */
  }
  .chat-suggestions::-webkit-scrollbar { display: none; }
  .chat-suggestion {
    flex-shrink: 0;
    white-space: nowrap;
    scroll-snap-align: start;
    font-size: 13px;
    padding: 8px 14px;
  }

  /* #194-1: 입력창 모바일 — 패딩 축소 + textarea 한 줄 시작 */
  .chat-input-area { padding: 10px 12px; }
  .chat-input-row textarea {
    padding: 10px 12px;
    font-size: 16px;  /* iOS 입력창 자동 zoom 방지 핵심 */
  }
  /* #194-4: 모바일 필터 세로 배치 — 검색 범위 + 기간 드롭다운 한 줄씩 */
  .chat-input-filter {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 12px;
  }
  .chat-input-filter__label {
    width: 100%;
  }
  .chat-input-filter__label select {
    flex: 1;
    width: 100%;
    font-size: 14px;  /* iOS 자동 zoom 방지 */
    min-height: 32px;
  }
  .chat-input-filter__hint { font-size: 10px; }
  .chat-send-btn { padding: 0 14px; font-size: 13px; }
}
