/*
  App_RAG 화면 스타일 (라이트 테마, 운영 프로그램형 레이아웃)
  [사용 모델·기술·라이브러리]
  - AI 모델: 사용 안 함 (스타일 파일)
  - 기술: CSS3 (CSS 변수, Grid/Flexbox, 반응형 미디어 쿼리), Markdown 뷰어 타이포그래피
  - 라이브러리: 사용 안 함
*/
:root {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --subtle: #F7F8FA;
  --hover: #F0F4F9;
  --border: #E1E4E8;
  --border-strong: #C8CDD3;
  --fg: #1F2328;
  --fg2: #57606A;
  --fg3: #8C959F;
  --accent: #0F6CBD;
  --accent-h: #115EA3;
  --accent-bg: #EBF3FC;
  --accent-bd: #B4D6FA;
  --ok: #107C10;   --ok-bg: #DFF6DD;
  --warn: #8A5300; --warn-bg: #FFF4CE;
  --err: #C50F1F;  --err-bg: #FDE7E9;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --font: "Segoe UI Variable", "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", Pretendard, sans-serif;
  --mono: Consolas, "D2Coding", "SF Mono", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; min-height: 100vh;
}
button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--fg3); }

/* ---------- 최상단 모델·기술 표시 ---------- */
.stackbar { background: #1F2328; color: #E6EDF3; font-size: 12px; position: sticky; top: 0; z-index: 30; }
.stackbar-in {
  max-width: 1440px; margin: 0 auto; padding: 6px 24px;
  display: flex; flex-wrap: wrap; gap: 4px 20px; align-items: center;
}
.sb-group { display: inline-flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.sb-label {
  font-size: 11px; font-weight: 600; color: #1F2328; background: #9CD0FF;
  border-radius: 3px; padding: 0 6px; line-height: 18px;
}
.sb-item b { color: #9CD0FF; font-weight: 600; margin-right: 2px; }
.sb-item em { font-style: normal; color: #9BA6B2; }

/* ---------- 앱 바 ---------- */
.appbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.appbar-in {
  max-width: 1440px; margin: 0 auto; padding: 0 24px; height: 56px;
  display: flex; align-items: center; gap: 10px;
}
.crumb-home { display: inline-flex; align-items: center; gap: 8px; color: var(--fg2); text-decoration: none; font-weight: 600; }
.crumb-home:hover { color: var(--accent); }
.logo {
  width: 26px; height: 26px; border-radius: 6px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.crumb-sep { color: var(--fg3); }
.app-title { font-size: 16px; font-weight: 600; margin: 0; }
.chips { margin-left: auto; display: flex; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--fg2);
  border: 1px solid var(--border); border-radius: 12px; padding: 2px 10px; background: var(--subtle);
  white-space: nowrap;
}
.chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--fg3); }
.chip.ok i { background: var(--ok); }
.chip.warn i { background: #D29200; animation: pulse 1.2s infinite; }
.chip.err i { background: var(--err); }
.chip.err { color: var(--err); border-color: #F1BBBC; background: var(--err-bg); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- 레이아웃 ---------- */
.layout {
  flex: 1; width: 100%; max-width: 1440px; margin: 0 auto; padding: 20px 24px 24px;
  display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 20px; align-items: start;
}
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 0;
}
.panel-h {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.panel-h h2 { margin: 0; font-size: 15px; font-weight: 600; }

/* ---------- 문서 패널 ---------- */
.docs { min-height: 0; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 14px 18px 0; }
.kpi { background: var(--subtle); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; }
.kpi span { display: block; font-size: 11px; color: var(--fg2); }
.kpi b { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }

.drop {
  margin: 14px 18px 0; border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  padding: 18px 12px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  text-align: center; color: var(--fg2); cursor: pointer; transition: background .15s, border-color .15s;
}
.drop svg { color: var(--accent); }
.drop strong { color: var(--fg); font-size: 13px; font-weight: 600; }
.drop span { font-size: 12px; color: var(--fg3); }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-bg); }
.drop.busy { pointer-events: none; opacity: .6; }

.upload-log { list-style: none; margin: 8px 18px 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.upload-log li {
  font-size: 12px; border-radius: 4px; padding: 6px 8px; display: flex; gap: 8px; align-items: baseline;
  background: var(--subtle); border: 1px solid var(--border);
}
.upload-log li b { font-weight: 600; flex: none; }
.upload-log li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.upload-log li.indexed { background: var(--ok-bg); border-color: #B7E1B5; } .upload-log li.indexed b { color: var(--ok); }
.upload-log li.duplicate { background: var(--warn-bg); border-color: #F3D98B; } .upload-log li.duplicate b { color: var(--warn); }
.upload-log li.error { background: var(--err-bg); border-color: #F1BBBC; } .upload-log li.error b { color: var(--err); }
.upload-log li.pending b { color: var(--accent); }

.list-h {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 16px 18px 6px; font-size: 12px; font-weight: 600; color: var(--fg2);
}
.list-h .muted { font-weight: 400; font-size: 11px; }
.doc-list { list-style: none; margin: 0; padding: 0 10px 12px; overflow-y: auto; flex: 1; min-height: 80px; }
.doc {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 8px; border-radius: 6px; border: 1px solid transparent;
}
.doc:hover { background: var(--hover); }
.doc.sel { background: var(--accent-bg); border-color: var(--accent-bd); }
.doc input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.doc-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 11px; color: var(--fg3); }
.doc-del {
  border: 0; background: transparent; color: var(--fg3); width: 28px; height: 28px; border-radius: 4px;
  display: grid; place-items: center;
}
.doc-del:hover { background: var(--err-bg); color: var(--err); }
.doc-empty { color: var(--fg3); font-size: 13px; text-align: center; padding: 24px 8px; }

/* ---------- 채팅 패널 ---------- */
.chat { min-height: 0; }
/* 데스크톱: 화면 높이에 맞춘 앱 셸 — 패널 내부만 스크롤 */
@media (min-width: 1001px) {
  body { height: 100vh; overflow: hidden; }
  .layout { min-height: 0; grid-template-rows: minmax(0, 1fr); align-items: stretch; }
  .docs, .chat { height: 100%; }
  .thread { min-height: 0; }
}
.chat-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.scope {
  font-size: 12px; color: var(--accent); background: var(--accent-bg); border: 1px solid var(--accent-bd);
  border-radius: 12px; padding: 1px 10px;
}
.sel { font-size: 12px; color: var(--fg2); display: inline-flex; gap: 6px; align-items: center; }
.sel select {
  font: inherit; border: 1px solid var(--border-strong); border-radius: 4px; padding: 3px 6px; background: var(--surface);
}
.btn-text { border: 0; background: transparent; color: var(--accent); font-size: 12px; font-weight: 600; padding: 4px 6px; border-radius: 4px; }
.btn-text:hover:not(:disabled) { background: var(--accent-bg); }
.btn-text.danger { color: var(--err); }
.btn-text.danger:hover:not(:disabled) { background: var(--err-bg); }

.thread { position: relative; flex: 1; padding: 20px 24px; display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }
.thread > * { flex-shrink: 0; }
.welcome { margin: auto; max-width: 520px; text-align: center; color: var(--fg2); padding: 32px 0; }
.welcome-ico {
  width: 52px; height: 52px; border-radius: 12px; background: var(--accent-bg); color: var(--accent);
  display: grid; place-items: center; margin: 0 auto 12px;
}
.welcome h3 { color: var(--fg); margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.welcome p { margin: 0 0 16px; font-size: 13px; }
.welcome code { font-family: var(--mono); background: var(--subtle); padding: 0 4px; border-radius: 3px; }
.samples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.samples button {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--fg); border-radius: 16px;
  padding: 6px 12px; font-size: 12px;
}
.samples button:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }

.msg-q { align-self: flex-end; max-width: 78%; }
.msg-q .bubble {
  background: var(--accent); color: #fff; padding: 10px 14px; border-radius: 12px 12px 2px 12px;
  white-space: pre-wrap; word-break: break-word;
}
.msg-q .when { text-align: right; font-size: 11px; color: var(--fg3); margin-top: 4px; }

.msg-a {
  align-self: stretch; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  overflow: hidden;
}
.msg-a-h {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: var(--subtle);
  border-bottom: 1px solid var(--border); font-size: 12px; color: var(--fg2);
}
.msg-a-h .ai {
  width: 20px; height: 20px; border-radius: 5px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
  display: grid; place-items: center;
}
.msg-a-h strong { color: var(--fg); font-weight: 600; }
.msg-a-h .meta { margin-left: auto; font-variant-numeric: tabular-nums; }
.msg-a-h .copy { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 4px; font-size: 11px; padding: 1px 8px; color: var(--fg2); }
.msg-a-h .copy:hover { color: var(--accent); border-color: var(--accent); }
.msg-a-b { padding: 16px 20px; }
.msg-a.error .msg-a-b { background: var(--err-bg); color: var(--err); }

.loading { display: flex; align-items: center; gap: 10px; color: var(--fg2); font-size: 13px; }
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--accent-bd); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Markdown 뷰어 ---------- */
.md { font-size: 14.5px; line-height: 1.75; color: var(--fg); word-break: keep-all; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.35; font-weight: 600; margin: 1.3em 0 .5em; }
.md h1 { font-size: 1.4em; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.md h2 { font-size: 1.22em; padding-bottom: .25em; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 1.08em; color: var(--accent-h); }
.md h4 { font-size: 1em; }
.md p { margin: .6em 0; }
.md ul, .md ol { padding-left: 1.5em; margin: .5em 0; }
.md li { margin: .25em 0; }
.md li::marker { color: var(--accent); }
.md strong { font-weight: 700; color: #0B3B66; background: linear-gradient(transparent 62%, #DCEBFB 62%); }
.md a { color: var(--accent); }
.md blockquote {
  margin: .8em 0; padding: .6em 1em; border-left: 3px solid var(--accent); background: var(--accent-bg);
  color: var(--fg2); border-radius: 0 6px 6px 0;
}
.md blockquote > :first-child { margin-top: 0; } .md blockquote > :last-child { margin-bottom: 0; }
.md code { font-family: var(--mono); font-size: .88em; background: #EFF1F3; padding: .12em .4em; border-radius: 4px; }
.md pre { background: #F6F8FA; border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: .85em; }
.md table { border-collapse: collapse; width: 100%; margin: .8em 0; font-size: .92em; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; vertical-align: top; }
.md th { background: var(--subtle); font-weight: 600; white-space: nowrap; }
.md tr:nth-child(even) td { background: #FBFBFC; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }
.md .cite {
  display: inline-block; min-width: 18px; padding: 0 4px; margin: 0 1px; font-size: 10.5px; font-weight: 700;
  line-height: 16px; text-align: center; vertical-align: 2px; color: var(--accent); background: var(--accent-bg);
  border: 1px solid var(--accent-bd); border-radius: 4px; cursor: pointer; text-decoration: none;
}
.md .cite:hover { background: var(--accent); color: #fff; }

/* ---------- 근거 문서 ---------- */
.sources { border-top: 1px solid var(--border); }
.sources > summary {
  list-style: none; cursor: pointer; padding: 10px 20px; font-size: 12px; font-weight: 600; color: var(--fg2);
  display: flex; align-items: center; gap: 6px; user-select: none;
}
.sources > summary::-webkit-details-marker { display: none; }
.sources > summary::before { content: "▸"; color: var(--fg3); transition: transform .15s; }
.sources[open] > summary::before { transform: rotate(90deg); }
.src-list { list-style: none; margin: 0; padding: 0 20px 14px; display: flex; flex-direction: column; gap: 8px; }
.src { border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; background: var(--subtle); transition: box-shadow .2s, border-color .2s; }
.src.flash { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.src-h { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.src-n {
  font-weight: 700; color: #fff; background: var(--accent); border-radius: 4px; min-width: 20px; text-align: center; font-size: 11px; padding: 0 4px;
}
.src-f { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.src-p { color: var(--fg3); flex: none; }
.kw {
  flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 11px; color: var(--ok); background: var(--ok-bg); border-radius: 3px; padding: 0 6px;
}
.score { margin-left: auto; flex: none; display: inline-flex; align-items: center; gap: 6px; color: var(--fg2); font-variant-numeric: tabular-nums; }
.score-bar { width: 54px; height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.score-bar i { display: block; height: 100%; background: var(--accent); }
.src-t {
  margin: 6px 0 0; font-size: 12.5px; color: var(--fg2); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.src.open .src-t { -webkit-line-clamp: unset; display: block; }
.src-more { border: 0; background: none; color: var(--accent); font-size: 11px; padding: 2px 0 0; }

/* ---------- 입력창 ---------- */
.composer {
  display: flex; gap: 10px; align-items: flex-end; padding: 14px 18px; border-top: 1px solid var(--border);
  background: var(--surface); border-radius: 0 0 var(--radius) var(--radius);
}
.composer textarea {
  flex: 1; resize: none; font: inherit; border: 1px solid var(--border-strong); border-radius: 6px;
  padding: 9px 12px; min-height: 40px; max-height: 160px; line-height: 1.5; color: var(--fg);
}
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.btn-primary {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 16px; border-radius: 6px;
  border: 1px solid var(--accent); background: var(--accent); color: #fff; font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-h); }
.btn-sec { height: 34px; padding: 0 14px; border-radius: 4px; border: 1px solid var(--border-strong); background: var(--surface); }
.btn-sec:hover { background: var(--subtle); }
.btn-danger { height: 34px; padding: 0 14px; border-radius: 4px; border: 1px solid var(--err); background: var(--err); color: #fff; font-weight: 600; }

/* ---------- 모달·토스트 ---------- */
.modal { position: fixed; inset: 0; background: rgba(31,35,40,.35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 400px; padding: 20px; box-shadow: 0 12px 40px rgba(0,0,0,.18); }
.modal-box h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.modal-box p { margin: 0 0 20px; color: var(--fg2); word-break: break-all; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: #1F2328; color: #fff; padding: 10px 14px; border-radius: 6px; font-size: 13px; max-width: 360px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: tin .2s ease-out;
}
.toast.err { background: var(--err); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* ---------- 반응형 ---------- */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .doc-list { max-height: 320px; }
  .chat { height: 78vh; }
  .stackbar { position: static; }
}
@media (max-width: 600px) {
  .stackbar-in, .appbar-in { padding-left: 16px; padding-right: 16px; }
  .stackbar { font-size: 11px; line-height: 1.45; }
  .stackbar-in { gap: 3px 12px; padding-top: 5px; padding-bottom: 5px; }
  .chips { gap: 4px; flex: none; }
  .chip { font-size: 11px; gap: 4px; }
  .layout { padding: 12px 16px 16px; gap: 12px; }
  .crumb-home { font-size: 0; gap: 0; }
  .chips .chip { padding: 2px 7px; }
  .app-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .thread { padding: 16px 14px; }
  .msg-q { max-width: 92%; }
  .msg-a-b { padding: 14px; }
  .msg-a-h .meta { display: none; }
  .chat-tools { justify-content: flex-start; }
  .panel-h { flex-wrap: wrap; }
}
