:root {
  --bg: #ffffff;
  --bg-alt: #f7f7f5;
  --border: #e6e6e0;
  --text: #1f1f1c;
  --text-dim: #6b6b63;
  --accent: #d99a00;
  --accent-soft: #fef3d4;
  --sidebar-w: 300px;
  --topbar-h: 56px;
  --code-bg: #f4f4f0;
  --max-read: 820px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  font-size: 16px;
  line-height: 1.7;
}

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}
.brand-logo { font-size: 22px; }
.brand-name { font-size: 16px; }

.search-wrap {
  position: relative;
  margin-left: auto;
  width: min(360px, 45vw);
}
#search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--bg-alt);
  outline: none;
}
#search:focus { border-color: var(--accent); background: #fff; }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  max-height: 60vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.1);
  z-index: 200;
}
.search-results .sr-item {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--bg-alt);
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
}
.search-results .sr-item:last-child { border-bottom: none; }
.search-results .sr-item:hover,
.search-results .sr-item.active { background: var(--accent-soft); }
.sr-cat { font-size: 11px; color: var(--accent); font-weight: 600; }
.sr-title { font-size: 14px; font-weight: 600; }
.sr-snippet { font-size: 12px; color: var(--text-dim); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-empty { padding: 14px; color: var(--text-dim); font-size: 14px; }
.sr-item mark { background: var(--accent-soft); color: inherit; }

/* ---------- Layout ---------- */
.layout { display: flex; padding-top: var(--topbar-h); }

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg-alt);
  padding: 18px 0 40px;
  transition: transform .22s ease;
}
.nav-cat { margin-bottom: 6px; }
.nav-cat-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--text-dim);
  text-transform: uppercase;
  padding: 14px 20px 6px;
}
.nav-link {
  display: block;
  padding: 7px 20px 7px 24px;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  border-left: 3px solid transparent;
}
.nav-link:hover { background: #efefe9; }
.nav-link.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  font-weight: 600;
}
.nav-link .nav-id { color: var(--text-dim); font-size: 12px; margin-right: 6px; }

.overlay {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgba(0,0,0,.35);
  z-index: 90;
}

.content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  padding: 36px 48px 120px;
}
.article { max-width: var(--max-read); margin: 0 auto; }

/* ---------- Home ---------- */
.home-hero {
  background: linear-gradient(135deg, #fff8e6, #fef3d4);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  margin-bottom: 36px;
}
.home-hero h1 { margin: 0 0 10px; font-size: 30px; }
.home-hero p { margin: 0; color: var(--text-dim); font-size: 16px; }
.home-stats { display: flex; gap: 28px; margin-top: 22px; flex-wrap: wrap; }
.home-stat .num { font-size: 26px; font-weight: 700; color: var(--accent); }
.home-stat .lbl { font-size: 13px; color: var(--text-dim); }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.cat-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  background: #fff;
}
.cat-card h3 { margin: 0 0 10px; font-size: 16px; }
.cat-card ul { margin: 0; padding: 0; list-style: none; }
.cat-card li { margin: 4px 0; }
.cat-card a { color: var(--text); text-decoration: none; font-size: 14px; }
.cat-card a:hover { color: var(--accent); text-decoration: underline; }
.cat-card .c-id { color: var(--text-dim); font-size: 12px; margin-right: 6px; }

/* ---------- Article markdown ---------- */
.doc-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.doc-badge {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}
.doc-source { font-size: 13px; color: var(--text-dim); word-break: break-all; }
.doc-source a { color: var(--text-dim); }

.article h1 { font-size: 28px; margin: 0 0 18px; line-height: 1.3; }
.article h2 { font-size: 22px; margin: 36px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.article h3 { font-size: 18px; margin: 26px 0 10px; }
.article h4 { font-size: 16px; margin: 20px 0 8px; }
.article p { margin: 12px 0; }
.article a { color: #b07d00; }
.article ul, .article ol { padding-left: 24px; }
.article li { margin: 4px 0; }
.article blockquote {
  margin: 16px 0;
  padding: 8px 16px;
  border-left: 4px solid var(--accent);
  background: var(--bg-alt);
  color: var(--text-dim);
  border-radius: 0 8px 8px 0;
}
.article hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }
.article code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.88em;
  font-family: "JetBrains Mono", "Consolas", monospace;
}
.article pre {
  background: #1f2430;
  color: #e6e6e6;
  padding: 16px 18px;
  border-radius: 10px;
  overflow-x: auto;
}
.article pre code { background: none; padding: 0; color: inherit; }
.article table {
  border-collapse: collapse;
  width: 100%;
  margin: 16px 0;
  font-size: 14px;
}
.article th, .article td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.article th { background: var(--bg-alt); font-weight: 700; }
.article tr:nth-child(even) td { background: #fafaf8; }

.doc-footer {
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.doc-footer a {
  flex: 1;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--text);
  transition: border-color .15s;
}
.doc-footer a:hover { border-color: var(--accent); }
.doc-footer .nav-dir { font-size: 12px; color: var(--text-dim); }
.doc-footer .nav-ttl { font-size: 14px; font-weight: 600; }
.doc-footer .next { text-align: right; }
.doc-footer .spacer { flex: 1; border: none; }

/* ---------- Chat ---------- */
:root { --chat-w: 400px; }

.chat-toggle {
  margin-left: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chat-toggle:hover { background: #c48b00; }

.chat-panel {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  width: var(--chat-w);
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 96;
  box-shadow: -4px 0 24px rgba(0,0,0,.06);
}
/* 챗 패널이 열리면 본문이 가려지지 않도록 여백 확보 + 본문을 왼쪽 정렬 */
body.chat-open .content { margin-right: var(--chat-w); }
body.chat-open .article { margin-left: 0; margin-right: 0; }

/* 화면이 아주 넓지 않으면, 챗봇을 열 때 왼쪽 사이드바를 접어 본문 공간 확보
   (☰ 버튼으로 다시 열 수 있음) */
@media (max-width: 1279px) {
  body.chat-open .sidebar { display: none; }
  body.chat-open .content { margin-left: 0; }
  body.chat-open .menu-toggle { display: block; }
  /* 접힌 사이드바를 ☰로 다시 열면 본문 위에 오버레이로 표시 */
  body.chat-open .sidebar.open {
    display: block;
    z-index: 97;
    box-shadow: 2px 0 18px rgba(0,0,0,.14);
  }
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}
.chat-title { font-weight: 700; font-size: 15px; }
.chat-header-btns { display: flex; gap: 4px; }
.chat-icon-btn {
  background: none; border: none; cursor: pointer;
  font-size: 15px; padding: 4px 6px; border-radius: 6px; line-height: 1;
}
.chat-icon-btn:hover { background: #ecec014d; background: #e6e6df; }

.chat-config {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: #fffdf6;
}
.chat-config-desc { font-size: 12px; color: var(--text-dim); margin: 0 0 12px; line-height: 1.5; }
.chat-field { display: block; margin-bottom: 10px; }
.chat-field span { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.chat-field input {
  width: 100%; padding: 8px 10px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 7px; background: #fff;
}
.chat-field input:focus { outline: none; border-color: var(--accent); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-empty {
  margin: auto 0;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.7;
  width: 100%;
}
.chat-greet {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 14px 14px 14px 4px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 16px;
  max-width: 92%;
}
.chat-suggests {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.suggest-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: #8a6a00;
  background: var(--accent-soft);
  border: 1px solid #f3dca0;
  border-radius: 14px 14px 4px 14px;
  padding: 11px 14px;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 600;
  transition: background .15s, transform .08s;
}
.suggest-bubble:hover { background: #fde4b0; }
.suggest-bubble:active { transform: scale(.98); }
.suggest-bubble .sg-icon { font-size: 17px; flex-shrink: 0; }
.suggest-bubble .sg-text { line-height: 1.4; }

.msg { max-width: 92%; }
.msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  padding: 9px 13px;
  border-radius: 14px 14px 4px 14px;
  font-size: 14px;
  white-space: pre-wrap;
}
.msg-bot {
  align-self: flex-start;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  padding: 11px 14px;
  border-radius: 14px 14px 14px 4px;
  font-size: 14px;
}
.msg-bot.error { background: #fdeaea; border-color: #f3c2c2; color: #a12; }
.msg-bot p:first-child { margin-top: 0; }
.msg-bot p:last-child { margin-bottom: 0; }
.msg-bot table { font-size: 13px; }
.msg-bot pre { font-size: 12px; }

.msg-sources {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.msg-sources a {
  font-size: 11px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--text-dim);
  text-decoration: none;
}
.msg-sources a:hover { border-color: var(--accent); color: var(--accent); }

.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-dim); opacity: .4;
  animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.25} 40%{opacity:.9} }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  max-height: 140px;
}
.chat-input:focus { outline: none; border-color: var(--accent); }
.chat-send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chat-send-btn:hover { background: #c48b00; }
.chat-send-btn:disabled { opacity: .5; cursor: default; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .menu-toggle { display: block; }
  .brand-name { display: none; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
    z-index: 95;
    width: 280px;
  }
  .sidebar.open { transform: translateX(0); }
  .content { margin-left: 0; padding: 24px 18px 100px; }
  .chat-toggle { padding: 8px 10px; font-size: 0; }
  .chat-toggle::before { content: "💬"; font-size: 18px; }
  .chat-panel { width: 100%; }
  body.chat-open .content { margin-right: 0; }
}
