/* ========== CSS Variables ========== */
:root {
  --bg: #ffffff;
  --bg-secondary: #f7f8fa;
  --bg-sidebar: #f9fafb;
  --bg-hover: #f0f2f5;
  --bg-active: #e8f0fe;
  --bg-code: #f4f5f7;
  --bg-callout-tip: #e8f5e9;
  --bg-callout-warning: #fff8e1;
  --bg-callout-tool: #e3f2fd;
  --bg-callout-info: #f3e8fd;
  --text: #1a1a2e;
  --text-secondary: #5f6368;
  --text-muted: #9aa0a6;
  --text-sidebar: #3c4043;
  --text-active: #1a73e8;
  --border: #e0e3e8;
  --border-light: #eef0f4;
  --accent: #1a73e8;
  --accent-hover: #1557b0;
  --accent-light: #d2e3fc;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --topbar-height: 56px;
  --sidebar-width: 280px;
  --content-max: 860px;
  --radius: 8px;
  --radius-sm: 4px;
  --transition: 0.2s ease;
  --font-sans: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

[data-theme="dark"] {
  --bg: #1a1b1e;
  --bg-secondary: #25262b;
  --bg-sidebar: #1e1f23;
  --bg-hover: #2c2e33;
  --bg-active: #1e3a5f;
  --bg-code: #2d2e33;
  --bg-callout-tip: #1b3a2a;
  --bg-callout-warning: #3a3020;
  --bg-callout-tool: #1a2d40;
  --bg-callout-info: #2a1d3e;
  --text: #e4e5e7;
  --text-secondary: #a1a5ab;
  --text-muted: #6b7075;
  --text-sidebar: #c1c4c9;
  --text-active: #8ab4f8;
  --border: #383a3f;
  --border-light: #2e3035;
  --accent: #8ab4f8;
  --accent-hover: #aecbfa;
  --accent-light: #1e3a5f;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
}

/* ========== Reset & Base ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}

/* ========== Topbar ========== */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  transition: background var(--transition), border-color var(--transition);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  transition: color var(--transition);
}

.logo-icon {
  font-size: 20px;
}

/* ========== Hamburger ========== */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.hamburger:hover {
  background: var(--bg-hover);
}

.hamburger span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 2px;
  transition: transform var(--transition), opacity var(--transition);
}

body.sidebar-open .hamburger span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}
body.sidebar-open .hamburger span:nth-child(2) {
  opacity: 0;
}
body.sidebar-open .hamburger span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* ========== Search ========== */
.search-wrapper {
  position: relative;
}

#search-input {
  width: 220px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition), background var(--transition), width var(--transition);
}

#search-input:focus {
  border-color: var(--accent);
  width: 300px;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 380px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 200;
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}

.search-result-item:hover {
  background: var(--bg-hover);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 2px;
}

.search-result-snippet {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.search-result-empty {
  padding: 20px 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ========== Theme Toggle ========== */
.theme-toggle {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background var(--transition);
  color: var(--text-secondary);
}

.theme-toggle:hover {
  background: var(--bg-hover);
}

.icon-moon { display: none; }

[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: inline; }

/* ========== Backdrop ========== */
.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 49;
}

/* ========== Sidebar ========== */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 50;
  transition: transform var(--transition), background var(--transition), border-color var(--transition);
}

.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Sidebar nav items */
.nav-part {
  margin-bottom: 8px;
}

.nav-part-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: color var(--transition);
}

.nav-part-title:hover {
  color: var(--text-secondary);
}

.nav-part-title .arrow {
  font-size: 10px;
  transition: transform var(--transition);
  display: inline-block;
}

.nav-part.collapsed .arrow {
  transform: rotate(-90deg);
}

.nav-part.collapsed .nav-chapters {
  display: none;
}

.nav-chapter {
  display: block;
}

.nav-chapter-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 20px 6px 28px;
  font-size: 13.5px;
  color: var(--text-sidebar);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
  line-height: 1.4;
}

.nav-chapter-link:hover {
  background: var(--bg-hover);
}

.nav-chapter-link.active {
  background: var(--bg-active);
  color: var(--text-active);
  border-left-color: var(--accent);
  font-weight: 500;
}

.nav-chapter-link .check {
  font-size: 12px;
  opacity: 0;
  transition: opacity var(--transition);
  flex-shrink: 0;
}

.nav-chapter-link.completed .check {
  opacity: 1;
  color: #34a853;
}

.nav-sections {
  overflow: hidden;
}

.nav-section-link {
  display: block;
  padding: 4px 20px 4px 44px;
  font-size: 12.5px;
  color: var(--text-muted);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}

.nav-section-link:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.nav-section-link.active {
  color: var(--text-active);
  font-weight: 500;
}

/* ========== Content ========== */
.content {
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
  transition: margin-left var(--transition);
  position: relative;
}

.progress-bar {
  position: sticky;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  width: 0%;
  transition: width 0.1s linear;
  z-index: 10;
}

.content-body {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 40px 48px 60px;
}

/* ========== Content Typography ========== */
.content-body h1 {
  font-size: 2em;
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.3;
  color: var(--text);
}

.content-body .subtitle {
  font-size: 1.1em;
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-weight: 300;
}

.content-body h2 {
  font-size: 1.5em;
  font-weight: 600;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
}

.content-body h3 {
  font-size: 1.2em;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
  color: var(--text);
}

.content-body p {
  margin-bottom: 16px;
  color: var(--text);
}

.content-body ul, .content-body ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

.content-body li {
  margin-bottom: 6px;
}

.content-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}

.content-body a:hover {
  border-bottom-color: var(--accent);
}

.content-body strong {
  font-weight: 600;
}

.content-body img {
  max-width: 100%;
  border-radius: var(--radius);
  margin: 16px 0;
}

.content-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 40px 0;
}

.content-body blockquote {
  border-left: 4px solid var(--accent);
  padding: 12px 20px;
  margin: 16px 0;
  background: var(--bg-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.content-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
}

.content-body th, .content-body td {
  padding: 10px 14px;
  border: 1px solid var(--border);
  text-align: left;
}

.content-body th {
  background: var(--bg-secondary);
  font-weight: 600;
}

/* ========== Code Blocks ========== */
.content-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-code);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: background var(--transition);
}

.content-body pre {
  background: var(--bg-code);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 16px 0;
  overflow-x: auto;
  position: relative;
  border: 1px solid var(--border-light);
}

.content-body pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.6;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
}

.content-body pre:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background: var(--bg-hover);
}

/* ========== Callouts ========== */
.callout {
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 20px 0;
  border-left: 4px solid;
  font-size: 14px;
}

.callout-title {
  font-weight: 600;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.callout-tip {
  background: var(--bg-callout-tip);
  border-color: #34a853;
}

.callout-warning {
  background: var(--bg-callout-warning);
  border-color: #f9ab00;
}

.callout-tool {
  background: var(--bg-callout-tool);
  border-color: #1a73e8;
}

.callout-info {
  background: var(--bg-callout-info);
  border-color: #9334e6;
}

/* ========== Tool Badge ========== */
.tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent);
}

/* ========== Diagram / Architecture ========== */
.arch-diagram {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.arch-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  transition: transform var(--transition), box-shadow var(--transition);
}

.arch-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.arch-card-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.arch-card-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.arch-card-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

.arch-label {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.arch-arrow {
  text-align: center;
  font-size: 24px;
  color: var(--text-muted);
  margin: 8px 0;
}

/* ========== Steps ========== */
.steps {
  counter-reset: step;
  margin: 20px 0;
}

.step {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  position: relative;
}

.step::before {
  counter-increment: step;
  content: counter(step);
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
}

.step-content h4 {
  font-weight: 600;
  margin-bottom: 4px;
}

.step-content p {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ========== Page Nav (Prev/Next) ========== */
.page-nav {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 48px 48px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.page-nav a {
  display: block;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  flex: 1;
  max-width: 48%;
}

.page-nav a:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.page-nav-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.page-nav-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
}

.page-nav .next {
  text-align: right;
  margin-left: auto;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .hamburger {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .backdrop {
    display: block;
  }

  .content {
    margin-left: 0;
  }

  .content-body {
    padding: 24px 20px 48px;
  }

  .page-nav {
    padding: 0 20px 32px;
    flex-direction: column;
  }

  .page-nav a {
    max-width: 100%;
  }

  #search-input {
    width: 140px;
  }

  #search-input:focus {
    width: 200px;
  }

  .search-results {
    width: 300px;
    right: -40px;
  }

  .logo-text {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .logo-text {
    display: none;
  }

  .content-body h1 {
    font-size: 1.5em;
  }
}

/* ========== Loading ========== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-muted);
}

.loading::after {
  content: '';
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========== Checklist ========== */
.checklist {
  list-style: none;
  padding-left: 0;
}

.checklist li {
  padding: 6px 0;
  padding-left: 28px;
  position: relative;
}

.checklist li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 10px;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ========== Tag ========== */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 4px;
}

.tag-core { background: #e8f5e9; color: #2e7d32; }
.tag-support { background: #e3f2fd; color: #1565c0; }
.tag-advanced { background: #f3e5f5; color: #7b1fa2; }
.tag-output { background: #fff3e0; color: #e65100; }

[data-theme="dark"] .tag-core { background: #1b3a2a; color: #81c784; }
[data-theme="dark"] .tag-support { background: #1a2d40; color: #64b5f6; }
[data-theme="dark"] .tag-advanced { background: #2a1d3e; color: #ce93d8; }
[data-theme="dark"] .tag-output { background: #3a2a1a; color: #ffb74d; }

/* ========== Workflow Diagram ========== */
.workflow {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 20px 0;
  padding: 20px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
}

.workflow-step {
  padding: 8px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}

.workflow-arrow {
  color: var(--text-muted);
  font-size: 18px;
}
