/* ============================================
   AI Agent Tutorial - Modern Documentation Style
   ============================================ */

/* ---------- CSS Variables (Light Theme) ---------- */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fb;
  --bg-sidebar: #f8f9fb;
  --bg-code: #f6f8fa;
  --bg-code-block: #1e1e2e;
  --bg-hover: #eef0f4;
  --bg-active: #e8e5ff;
  --bg-card: #ffffff;
  --bg-blockquote: #f0f0ff;
  --bg-table-header: #f3f4f6;
  --bg-table-stripe: #f9fafb;
  --bg-badge: #eef2ff;

  --text-primary: #1a1a2e;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --text-code: #e06c75;
  --text-link: #6366f1;
  --text-link-hover: #4f46e5;
  --text-sidebar: #374151;
  --text-sidebar-active: #6366f1;
  --text-blockquote: #4338ca;
  --text-badge: #4338ca;

  --border-color: #e5e7eb;
  --border-active: #6366f1;

  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-bg: #eef2ff;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.08);

  --sidebar-width: 280px;
  --toc-width: 240px;
  --content-max-width: 820px;
  --radius: 8px;
  --transition: 0.2s ease;
}

/* ---------- Dark Theme ---------- */
[data-theme="dark"] {
  --bg-primary: #0f0f23;
  --bg-secondary: #161630;
  --bg-sidebar: #13132b;
  --bg-code: #1e1e3a;
  --bg-code-block: #1a1a35;
  --bg-hover: #1e1e3a;
  --bg-active: #2d2b55;
  --bg-card: #1a1a35;
  --bg-blockquote: #1a1a40;
  --bg-table-header: #1e1e3a;
  --bg-table-stripe: #161630;
  --bg-badge: #2d2b55;

  --text-primary: #e2e8f0;
  --text-secondary: #a0aec0;
  --text-muted: #64748b;
  --text-code: #f78c6c;
  --text-link: #818cf8;
  --text-link-hover: #a5b4fc;
  --text-sidebar: #cbd5e1;
  --text-sidebar-active: #a5b4fc;
  --text-blockquote: #a5b4fc;
  --text-badge: #a5b4fc;

  --border-color: #2d2b55;
  --border-active: #818cf8;

  --accent: #818cf8;
  --accent-light: #a5b4fc;
  --accent-bg: #2d2b55;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.5);
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans SC', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.75;
  display: flex;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ---------- Sidebar (Left Nav) ---------- */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  padding: 0;
  z-index: 100;
  transition: transform 0.3s ease, background var(--transition);
}

.sidebar-header {
  padding: 20px 24px 16px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  background: var(--bg-sidebar);
  z-index: 1;
}

.sidebar-header .logo {
  font-size: 1.3rem;
}

.sidebar-group {
  padding: 12px 0 4px;
}

.sidebar-group-title {
  padding: 4px 24px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.sidebar-link {
  display: block;
  padding: 6px 24px 6px 28px;
  font-size: 0.88rem;
  color: var(--text-sidebar);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all var(--transition);
  line-height: 1.5;
}

.sidebar-link:hover {
  background: var(--bg-hover);
  color: var(--text-link);
}

.sidebar-link.active {
  background: var(--bg-active);
  color: var(--text-sidebar-active);
  border-left-color: var(--border-active);
  font-weight: 600;
}

/* ---------- Main Content ---------- */
.content {
  margin-left: var(--sidebar-width);
  margin-right: var(--toc-width);
  flex: 1;
  min-width: 0;
  padding: 40px 56px 80px;
  max-width: calc(var(--content-max-width) + 112px);
}

.content article {
  max-width: var(--content-max-width);
  margin: 0 auto;
}

/* ---------- Right TOC ---------- */
.toc {
  position: fixed;
  top: 0; right: 0;
  width: var(--toc-width);
  height: 100vh;
  overflow-y: auto;
  padding: 40px 20px 40px 0;
  border-left: 1px solid var(--border-color);
  background: var(--bg-primary);
  transition: background var(--transition);
}

.toc-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 16px 12px;
}

.toc ul {
  list-style: none;
  padding: 0;
}

.toc li {
  margin: 0;
}

.toc a {
  display: block;
  padding: 4px 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all var(--transition);
  line-height: 1.5;
}

.toc a:hover {
  color: var(--text-link);
}

.toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
}

.toc a.toc-h3 {
  padding-left: 28px;
  font-size: 0.78rem;
}

/* ---------- Theme Toggle ---------- */
.theme-toggle {
  position: fixed;
  top: 16px; right: calc(var(--toc-width) + 16px);
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all var(--transition);
  z-index: 200;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--shadow-md);
}

/* ---------- Mobile Menu ---------- */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  align-items: center;
  gap: 12px;
  z-index: 200;
}

.hamburger {
  width: 36px; height: 36px;
  border: none;
  background: none;
  color: var(--text-primary);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

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

.mobile-header .title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

.overlay.active { display: block; }

/* ---------- Typography ---------- */
h1 {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.25;
  margin: 0 0 8px;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

h1 + blockquote {
  margin-top: 8px;
  margin-bottom: 32px;
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 48px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

h3 {
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.4;
  margin: 36px 0 12px;
  color: var(--text-primary);
}

h4 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--text-secondary);
}

p { margin: 0 0 16px; }

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--transition);
}

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

strong { font-weight: 650; }

hr {
  border: none;
  height: 1px;
  background: var(--border-color);
  margin: 32px 0;
}

/* ---------- Blockquote ---------- */
blockquote {
  background: var(--bg-blockquote);
  border-left: 4px solid var(--accent);
  padding: 12px 20px;
  margin: 0 0 16px;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-blockquote);
  font-size: 0.95rem;
}

blockquote p { margin: 0; }
blockquote p + p { margin-top: 8px; }

/* ---------- Lists ---------- */
ul, ol {
  padding-left: 24px;
  margin: 0 0 16px;
}

li {
  margin: 4px 0;
}

li > ul, li > ol {
  margin: 4px 0 4px;
}

/* ---------- Code ---------- */
code {
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', monospace;
  font-size: 0.88em;
  background: var(--bg-code);
  color: var(--text-code);
  padding: 2px 6px;
  border-radius: 4px;
}

pre {
  background: var(--bg-code-block);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 0 0 20px;
  overflow-x: auto;
  position: relative;
  border: 1px solid var(--border-color);
}

pre code {
  background: none;
  color: #abb2bf;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.6;
}

.copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  padding: 4px 10px;
  font-size: 0.72rem;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 5px;
  background: rgba(255,255,255,0.08);
  color: #94a3b8;
  cursor: pointer;
  opacity: 0;
  transition: all var(--transition);
}

pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: rgba(255,255,255,0.15); color: #e2e8f0; }
.copy-btn.copied { color: #4ade80; border-color: #4ade80; }

/* ---------- Tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 20px;
  font-size: 0.9rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border-color);
}

thead {
  background: var(--bg-table-header);
}

th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-color);
}

td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}

tbody tr:nth-child(even) {
  background: var(--bg-table-stripe);
}

tbody tr:hover {
  background: var(--bg-hover);
}

/* ---------- Chapter Navigation ---------- */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 64px;
  padding-top: 32px;
  border-top: 1px solid var(--border-color);
  gap: 16px;
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  text-decoration: none;
  transition: all var(--transition);
  min-width: 0;
  flex: 1;
  max-width: 48%;
}

.chapter-nav a:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}

.chapter-nav a .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.chapter-nav a .title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* ---------- Index Page ---------- */
.index-hero {
  text-align: center;
  padding: 60px 20px 40px;
}

.index-hero h1 {
  font-size: 2.4rem;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.index-hero .subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto 32px;
}

.index-badges {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--bg-badge);
  color: var(--text-badge);
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  margin: 32px 0;
}

.section-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 24px;
  background: var(--bg-card);
  transition: all var(--transition);
}

.section-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.section-card .section-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.section-card h3 {
  font-size: 1.1rem;
  margin: 0 0 8px;
}

.section-card p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin: 0 0 16px;
}

.section-card .chapters {
  list-style: none;
  padding: 0;
  margin: 0;
}

.section-card .chapters li {
  margin: 0;
}

.section-card .chapters a {
  display: block;
  padding: 5px 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.section-card .chapters a:hover {
  color: var(--accent);
  text-decoration: none;
}

.section-card .chapters li:last-child a {
  border-bottom: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .toc { display: none; }
  .content { margin-right: 0; }
  .theme-toggle { right: 16px; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 300px;
    z-index: 300;
  }
  .sidebar.open { transform: translateX(0); }

  .mobile-header { display: flex; }
  .content {
    margin-left: 0;
    padding: 72px 20px 60px;
  }
  .theme-toggle {
    top: 10px;
    right: 12px;
    width: 36px; height: 36px;
    font-size: 1rem;
  }

  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.3rem; }

  .chapter-nav { flex-direction: column; }
  .chapter-nav a { max-width: 100%; }

  .index-hero h1 { font-size: 1.8rem; }
  .section-grid { grid-template-columns: 1fr; }

  table { font-size: 0.8rem; }
  th, td { padding: 8px 10px; }
}

/* ---------- Scrollbar ---------- */
.sidebar::-webkit-scrollbar,
.toc::-webkit-scrollbar {
  width: 4px;
}

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

/* ---------- Selection ---------- */
::selection {
  background: var(--accent-bg);
  color: var(--accent);
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .toc, .theme-toggle, .mobile-header, .chapter-nav, .copy-btn { display: none !important; }
  .content { margin: 0; padding: 20px; max-width: 100%; }
}
