/* A안 기술 문서형: GitHub 계열 색. 다크 모드는 OS 설정을 따른다. */
:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --fg: #1f2328;
  --muted: #59636e;
  --line: #d0d7de;
  --line-soft: #eaeef2;
  --accent: #0969da;
  --note: #0969da;   --note-bg: #ddf4ff;
  --tip: #1a7f37;    --tip-bg: #dafbe1;
  --important: #8250df; --important-bg: #fbefff;
  --warning: #9a6700; --warning-bg: #fff8c5;
  --caution: #cf222e; --caution-bg: #ffebe9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-soft: #151b23;
    --fg: #e6edf3;
    --muted: #9198a1;
    --line: #3d444d;
    --line-soft: #262c36;
    --accent: #4493f8;
    --note: #4493f8;   --note-bg: #121d2f;
    --tip: #3fb950;    --tip-bg: #0f2318;
    --important: #ab7df8; --important-bg: #1e1730;
    --warning: #d29922; --warning-bg: #272115;
    --caution: #f85149; --caution-bg: #2c1517;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.7 -apple-system, "Segoe UI", "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* 상단 바 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 20px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: baseline;
  color: var(--fg); font-size: 22px; font-weight: 800; letter-spacing: -0.04em;
}
.brand:hover { text-decoration: none; }
.brand-dot { color: var(--accent); }
.brand-sub {
  margin-left: 10px; padding-left: 10px; border-left: 1px solid var(--line);
  color: var(--muted); font-size: 13px; font-weight: 500; letter-spacing: 0;
}
@media (max-width: 768px) { .brand-sub { display: none; } }
.search { margin-left: auto; }
.search input {
  width: 240px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg-soft); color: var(--fg); font: inherit; font-size: 14px;
}
.account { display: flex; align-items: center; gap: 12px; font-size: 14px; white-space: nowrap; }
.account form { margin: 0; }
.account .who { color: var(--muted); }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
button.link:hover { text-decoration: underline; }
@media (max-width: 768px) { .account .who { display: none; } }
.admin-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.admin-table th, .admin-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.admin-table th { color: var(--muted); font-weight: 600; }
/* 관리자 편집기 */
.main.wide { grid-column: 2 / -1; max-width: none; }
@media (max-width: 768px) { .main.wide { grid-column: auto; } }
.btn {
  display: inline-block; padding: 6px 14px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg-soft); color: var(--fg); font: inherit; font-size: 14px; cursor: pointer;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn.danger { color: #cf222e; margin-top: 24px; }
.form-error { padding: 8px 12px; border: 1px solid #cf222e; border-radius: 6px; color: #cf222e; }
.editor-fields { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.editor-fields label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.editor input, .editor textarea {
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--fg); font: inherit; font-size: 15px;
}
.editor-panes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.editor textarea {
  min-height: 70vh; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 14px; line-height: 1.6;
}
.preview { min-height: 70vh; max-height: 80vh; overflow: auto; padding: 0 16px; border: 1px solid var(--line); border-radius: 6px; }
.upload-status { margin: 8px 0 0; color: #cf222e; font-size: 14px; }
.upload-status:empty { display: none; }
.editor-actions { display: flex; align-items: center; gap: 16px; margin-top: 12px; }
@media (max-width: 768px) {
  .editor-fields, .editor-panes { grid-template-columns: 1fr; }
  .editor textarea, .preview { min-height: 40vh; }
}
/* 버전 비교 */
.diff {
  border: 1px solid var(--line); border-radius: 6px; overflow-x: auto;
  font-family: ui-monospace, Consolas, monospace; font-size: 13px; line-height: 1.6;
}
.diff > div { white-space: pre-wrap; padding: 0 12px; }
.diff-added, .diff-added-sample { background: rgba(46, 160, 67, 0.18); }
.diff-removed, .diff-removed-sample { background: rgba(248, 81, 73, 0.18); }
.diff-same { color: var(--muted); }
.editor-actions form { margin: 0; }
.editor-actions .btn.danger { margin-top: 0; }
/* 댓글 */
.comments { margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--line); }
.comments h2 { font-size: 20px; margin: 0 0 16px; }
.comment { padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.comment-head { display: flex; gap: 8px; align-items: baseline; }
.comment-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0; }
.comment-actions { display: flex; gap: 12px; align-items: flex-start; font-size: 13px; }
.comment-actions form { margin: 0; }
.comment-actions summary { color: var(--accent); cursor: pointer; }
.comments textarea {
  display: block; width: 100%; min-height: 90px; margin: 8px 0; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); font: inherit; font-size: 15px;
}
.comment-form { margin-top: 16px; }
.menu { display: none; background: none; border: 1px solid var(--line); border-radius: 6px; color: var(--fg); font-size: 18px; padding: 2px 10px; cursor: pointer; }

/* 3단 배치: 주제 트리 | 본문 | 목차 */
.page {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 220px;
  min-height: calc(100vh - 56px);
}
.side {
  position: sticky; top: 56px; align-self: start;
  max-height: calc(100vh - 56px); overflow-y: auto;
  padding: 20px 16px; background: var(--bg-soft); border-right: 1px solid var(--line-soft);
  min-height: calc(100vh - 56px);
}
.side .cat {
  margin: 18px 0 6px; font-size: 12px; font-weight: 600;
  letter-spacing: .04em; color: var(--muted); text-transform: uppercase;
}
.side section:first-child .cat { margin-top: 0; }
.side a { display: block; padding: 4px 10px; border-left: 2px solid transparent; color: var(--fg); font-size: 14px; }
.side a:hover { background: var(--line-soft); text-decoration: none; }
.side a.on { border-left-color: var(--accent); color: var(--accent); font-weight: 600; }

.main { padding: 32px 48px 80px; max-width: 900px; width: 100%; }
.main h1 { margin: 0 0 4px; font-size: 32px; line-height: 1.3; }
.meta { color: var(--muted); font-size: 14px; }
.empty { color: var(--muted); }

.toc { position: sticky; top: 56px; align-self: start; padding: 32px 16px; font-size: 13px; border-left: 1px solid var(--line-soft); min-height: 200px; }
.toc nav:empty { display: none; }
.toc .toc-title { font-weight: 600; margin-bottom: 8px; }
.toc a { display: block; padding: 2px 0; color: var(--muted); }
.toc a.h3 { padding-left: 12px; }
.toc a:hover { color: var(--accent); }

/* 목록 화면 */
.list { list-style: none; padding: 0; margin: 24px 0; }
.list li { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.list li a { font-weight: 600; }

/* 노트 본문 */
.markdown { margin-top: 24px; }
.markdown h2 { margin: 40px 0 12px; padding-bottom: 6px; font-size: 24px; border-bottom: 1px solid var(--line-soft); }
.markdown h3 { margin: 28px 0 8px; font-size: 19px; }
.markdown h2, .markdown h3 { scroll-margin-top: 72px; }
.markdown code { padding: .15em .4em; border-radius: 6px; background: var(--bg-soft); font: 85% "JetBrains Mono", "D2Coding", Consolas, monospace; }
.markdown pre { position: relative; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-soft); overflow-x: auto; }
.markdown pre code { padding: 0; background: none; font-size: 13.5px; line-height: 1.55; }
.markdown pre code.hljs { background: none; padding: 0; }
.markdown table { border-collapse: collapse; margin: 16px 0; display: block; overflow-x: auto; }
.markdown th, .markdown td { padding: 6px 13px; border: 1px solid var(--line); }
.markdown th { background: var(--bg-soft); }
.markdown blockquote { margin: 16px 0; padding: 0 16px; color: var(--muted); border-left: 4px solid var(--line); }
.markdown img { max-width: 100%; }
.markdown ul:has(> li > input[type=checkbox]) { list-style: none; padding-left: 4px; }
.markdown li > input[type=checkbox] { margin-right: 6px; }

.copy-btn {
  position: absolute; top: 8px; right: 8px;
  padding: 2px 8px; font-size: 12px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--muted); cursor: pointer; opacity: 0;
  transition: opacity .15s;
}
.markdown pre:hover .copy-btn, .copy-btn:focus { opacity: 1; }

.diagram { position: relative; margin: 16px 0; padding: 16px; border: 1px solid var(--line-soft); border-radius: 8px; overflow-x: auto; }
.diagram:hover .copy-btn { opacity: 1; }
.mermaid { text-align: center; }
.diagram-error { margin-top: -8px; color: #cf222e; font-size: 13px; }
.diagram-dialog .copy-btn { opacity: 1; }
.diagram-dialog { box-sizing: border-box; overflow: hidden; width: 95vw; max-width: none; height: 90vh; padding: 40px 16px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.diagram-dialog::backdrop { background: rgb(0 0 0 / .5); }
.diagram-dialog svg { width: 100%; height: 100%; max-width: none !important; }

/* 강조 박스: > [!TIP] 등 */
.markdown-alert { margin: 16px 0; padding: 8px 16px; border-left: 4px solid; border-radius: 6px; }
.markdown-alert > :last-child { margin-bottom: 8px; }
.markdown-alert-title { margin: 8px 0 4px; font-weight: 600; }
.markdown-alert-note { border-color: var(--note); background: var(--note-bg); }
.markdown-alert-note .markdown-alert-title { color: var(--note); }
.markdown-alert-note .markdown-alert-title::before { content: "ℹ️ "; }
.markdown-alert-tip { border-color: var(--tip); background: var(--tip-bg); }
.markdown-alert-tip .markdown-alert-title { color: var(--tip); }
.markdown-alert-tip .markdown-alert-title::before { content: "💡 "; }
.markdown-alert-important { border-color: var(--important); background: var(--important-bg); }
.markdown-alert-important .markdown-alert-title { color: var(--important); }
.markdown-alert-important .markdown-alert-title::before { content: "❗ "; }
.markdown-alert-warning { border-color: var(--warning); background: var(--warning-bg); }
.markdown-alert-warning .markdown-alert-title { color: var(--warning); }
.markdown-alert-warning .markdown-alert-title::before { content: "⚠️ "; }
.markdown-alert-caution { border-color: var(--caution); background: var(--caution-bg); }
.markdown-alert-caution .markdown-alert-title { color: var(--caution); }
.markdown-alert-caution .markdown-alert-title::before { content: "🛑 "; }

/* 좁은 화면: 목차 숨김, 사이드바는 ☰ 버튼으로 */
@media (max-width: 1100px) {
  .page { grid-template-columns: 240px minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 768px) {
  .menu { display: block; }
  .search input { width: 140px; }
  .page { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; position: fixed; top: 56px; left: 0; right: 0; bottom: 0; z-index: 9; max-height: none; }
  body.side-open .side { display: block; }
  .main { padding: 20px 16px 60px; }
  .main h1 { font-size: 26px; }
  .list li { flex-direction: column; gap: 2px; }
}
