/* 사내 업무 도우미 — 공통 스타일
   위계 3단계(제목/본문/보조), 본문 대비 4.5:1 이상, 강조 총량 10% 이하.
   09_ 데모 앱들과 같은 네이비를 쓴다. */

:root {
  --navy: #0f3d6e;
  --navy-dark: #0b2e53;
  --ink: #1c2733;
  --muted: #5a6b7c;
  --line: #dfe5ec;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --amber: #9a5b06;
  --amber-bg: #fdf6e9;
  --amber-line: #e7c98d;
  --green: #1d6b3f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 32, 48, 0.09);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic",
    "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── 헤더 ─────────────────────────────────────────── */
.top {
  height: 48px;
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  flex-shrink: 0;
}
.top h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.top .sub {
  font-size: 12.5px;
  color: #a9c6e4;
  margin-left: 2px;
}
.top .spacer { flex: 1; }
.top a {
  color: #cfe0f0;
  font-size: 13px;
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.22);
}
.top a:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }

/* ── 채팅 레이아웃 ────────────────────────────────── */
.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
#log {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 8px;
}
.thread {
  max-width: 760px;
  margin: 0 auto;
}

/* 첫 화면 안내 */
.intro {
  padding: 8px 4px 4px;
}
.intro h2 {
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.intro p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 14.5px;
}

/* 말풍선 */
.turn { margin: 18px 0; }
.turn.me { display: flex; justify-content: flex-end; }
.bubble-me {
  background: var(--navy);
  color: #fff;
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
  max-width: 78%;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15.5px;
}

.answer {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 12px;
}
/* 답변 본문과 근거 원문 패널은 같은 포매터를 쓰므로 같은 규칙을 공유한다 */
.answer .body,
.src-text {
  font-size: 15.5px;
  line-height: 1.72;
  word-break: break-word;
}
.answer .body p,
.src-text p { margin: 0 0 10px; }
.answer .body p:last-child,
.src-text p:last-child { margin-bottom: 0; }
.answer .body ul,
.src-text ul { margin: 4px 0 10px; padding-left: 20px; }
.answer .body li,
.src-text li { margin: 3px 0; }
.answer .body strong,
.src-text strong { font-weight: 650; }
.answer .body .subh,
.src-text .subh {
  font-weight: 650;
  margin: 12px 0 4px;
  color: #23425f;
}
.answer .body .subh:first-child,
.src-text .subh:first-child { margin-top: 0; }
.tscroll { overflow-x: auto; margin: 8px 0 12px; }
.answer .body table,
.src-text table {
  border-collapse: collapse;
  font-size: 14.5px;
  width: 100%;
  min-width: 320px;
}
.answer .body th, .answer .body td,
.src-text th, .src-text td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
}
.answer .body th,
.src-text th { background: #eef2f7; font-weight: 600; }

/* 근거 칩 */
.cites {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.cite {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: #eef3f8;
  border: 1px solid #d4e0ec;
  color: #23425f;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.5;
  text-align: left;
}
.cite:hover { background: #e2ebf4; border-color: #b9cee2; }
.cite .n { font-weight: 700; font-size: 12px; }
.cite .rev { color: #63798e; font-size: 12px; }

/* 인라인 인용 번호 */
.ref {
  font-size: 11.5px;
  vertical-align: super;
  color: var(--navy);
  background: #eaf1f8;
  border-radius: 4px;
  padding: 0 4px;
  margin-left: 1px;
  cursor: pointer;
  font-weight: 700;
}
.ref:hover { background: #d7e5f3; }

/* 답변 하단 도구 */
.tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.tools .spacer { flex: 1; }
.tools button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: inherit;
}
.tools button:hover { border-color: #b9c6d4; color: var(--ink); }
.tools button[aria-pressed="true"] {
  border-color: var(--navy);
  color: var(--navy);
  background: #eef3f8;
  font-weight: 600;
}

/* 고지·경고 */
.note {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  margin: 8px 0;
  border: 1px solid var(--line);
  background: #eef2f6;
  color: #3d5064;
}
.note.warn {
  background: var(--amber-bg);
  border-color: var(--amber-line);
  color: var(--amber);
}
.note.mask {
  background: #edf5ef;
  border-color: #bcdcc7;
  color: var(--green);
}

/* 에스컬레이션 카드 */
.escalate {
  border: 1px solid var(--amber-line);
  background: var(--amber-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.escalate .body { font-size: 15px; line-height: 1.7; }
.escalate .row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.escalate input {
  flex: 1;
  min-width: 180px;
  padding: 8px 11px;
  border: 1px solid var(--amber-line);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.btn-amber {
  background: var(--amber);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 9px 15px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-amber:hover { background: #7d4905; }
.btn-amber:disabled { opacity: 0.5; cursor: default; }

/* 타이핑 표시 */
.typing span {
  display: inline-block;
  width: 6px; height: 6px;
  margin-right: 3px;
  border-radius: 50%;
  background: #9aa9b8;
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* ── 입력 영역 ────────────────────────────────────── */
.composer-wrap {
  border-top: 1px solid var(--line);
  background: #fff;
  flex-shrink: 0;
}
.composer {
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 16px 14px;
}
.samples {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 9px;
}
.samples button {
  background: #f1f4f8;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  color: #3d5064;
  cursor: pointer;
  font-family: inherit;
}
.samples button:hover { background: #e6ecf3; color: var(--ink); }
form.ask { display: flex; gap: 8px; }
form.ask input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid #c3ced9;
  border-radius: 10px;
  font-size: 15.5px;
  font-family: inherit;
  color: var(--ink);
}
form.ask input:focus {
  outline: 2px solid #a9c6e4;
  outline-offset: -1px;
  border-color: var(--navy);
}
form.ask button {
  padding: 12px 20px;
  border: 0;
  border-radius: 10px;
  background: var(--navy);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
form.ask button:hover { background: var(--navy-dark); }
form.ask button:disabled { opacity: 0.45; cursor: default; }

/* ── 근거 패널 ────────────────────────────────────── */
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 420px;
  max-width: 92vw;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 24px rgba(16, 32, 48, 0.12);
  transform: translateX(100%);
  transition: transform 0.18s ease-out;
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.drawer.open { transform: translateX(0); }
.drawer header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.drawer header h3 { margin: 0; font-size: 15px; font-weight: 650; flex: 1; }
.drawer header button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  width: 28px; height: 28px;
  font-size: 16px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}
.drawer .content { overflow-y: auto; padding: 16px; }
.src-meta {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.7;
}
.src-meta b { color: var(--ink); font-weight: 600; }
.src-text {
  font-size: 14.5px;
  background: #f7f9fb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(16, 32, 48, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
  z-index: 15;
}
.scrim.on { opacity: 1; pointer-events: auto; }

/* ── 관리자 화면 ──────────────────────────────────── */
.admin-wrap { max-width: 1080px; margin: 0 auto; padding: 20px 20px 60px; }
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}
.tabs button {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  font-size: 14.5px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}
.tabs button[aria-selected="true"] {
  color: var(--navy);
  border-bottom-color: var(--navy);
  font-weight: 650;
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
}
.stat .k { font-size: 12.5px; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin-top: 3px; }
.stat .v small { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 3px; }

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel h3 {
  margin: 0;
  padding: 13px 16px;
  font-size: 14.5px;
  font-weight: 650;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th, table.grid td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid #eef1f5;
  vertical-align: top;
}
table.grid th {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: #f8fafc;
  white-space: nowrap;
}
table.grid tr:last-child td { border-bottom: 0; }
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef3f8;
  color: #23425f;
  border: 1px solid #d4e0ec;
}
.tag.open { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-line); }
.tag.answered { background: #edf5ef; color: var(--green); border-color: #bcdcc7; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.muted { color: var(--muted); font-size: 13px; }
.samples-list { margin: 5px 0 0; padding-left: 17px; color: var(--muted); font-size: 13px; }
.samples-list li { margin: 2px 0; }
.rowbtn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  white-space: nowrap;
}
.rowbtn:hover { border-color: #b9c6d4; }

/* ── 반응형 ───────────────────────────────────────── */
@media (max-width: 640px) {
  .top { padding: 0 14px; }
  .top .sub { display: none; }
  #log { padding: 14px 12px 4px; }
  .composer { padding: 8px 12px 12px; }
  .bubble-me { max-width: 88%; }
  .answer { padding: 14px 15px 10px; }
  .drawer { width: 100%; }
  .admin-wrap { padding: 14px 12px 50px; }
  .tabs { overflow-x: auto; }
  table.grid { font-size: 13px; }
  table.grid th, table.grid td { padding: 8px 10px; }
}
