:root {
  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #5486f1;
  --text: #1a1a1a;
  --text-muted: #555;
  --border: #e5e7eb;
  --code-bg: #f1f1f1d5;
  --code-text: #1e1e1e;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #f59e0b;
  --nav-bg: #ffffff;
  --card-bg: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --sidebar-width: 280px;
  --topbar-height: 52px;
  --radius: 8px;
  --overlay: rgba(0,0,0,0.35);
}

[data-theme="dark"] {
  --bg: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --text: #e5e5e5;
  --text-muted: #a3a3a3;
  --border: #2a2a2a;
  --code-bg: #161616;
  --code-text: #e5e5e5;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --accent: #fbbf24;
  --nav-bg: #141414;
  --card-bg: #1a1a1a;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --overlay: rgba(0,0,0,0.55);
}

*{
  scroll-behavior: smooth; scrollbar-width: thin;
  scrollbar-color: var(--primary-hover) transparent;
  margin: 0; padding: 0; box-sizing: border-box; outline: none;
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background 0.25s, color 0.25s;
  width: 100vw;
}

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

/* ─── Top bar ─── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--topbar-height);
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--nav-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.topbar-brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
}
.topbar-brand:hover { text-decoration: none; color: var(--text); }
.topbar-brand span { color: var(--primary); }

.icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover {
  background: var(--bg-secondary);
  border-color: var(--border);
}

/* ─── Layout ─── */
.layout {
  display: flex;
  position: relative;
}

/* ─── Sidebar ─── */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  padding: 1.25rem 0 2rem;
  border-right: 1px solid var(--border);
  background: var(--nav-bg);
  z-index: 50;
  transform: translateX(0);
  transition: transform 0.28s ease, box-shadow 0.28s ease;
}

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

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--topbar-height);
  background: var(--overlay);
  z-index: 45;
  opacity: 0;
  transition: opacity 0.28s ease;
  pointer-events: none;
}
.sidebar-overlay.visible {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding: 0 1rem;
}

.logo-placeholder {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 12px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.logo-text {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  line-height: 1.2;
}
.logo-text span { color: var(--primary); }
.logo-text small {
  display: block;
  font-weight: 500;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.search-box {
  margin: 0 1rem 1.25rem;
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 0.5rem 0.85rem 0.5rem 2.15rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}
.search-box input:focus { border-color: var(--primary); }
.search-box svg {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}
#search-results {
  display: none;
  position: absolute;
  top: 110%;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 260px;
  overflow: auto;
  z-index: 30;
  box-shadow: var(--shadow);
}
.search-item {
  display: block;
  padding: 0.55rem 0.85rem;
  color: var(--text);
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover {
  background: var(--bg-secondary);
  text-decoration: none;
  color: var(--primary);
}

.nav-section { margin-bottom: 1.15rem; }
.nav-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding: 0 1rem;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.nav-link {
  display: block;
  padding: 0.4rem 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  color: var(--text);
  background: rgba(88, 166, 255, 0.247);
  text-decoration: none;
}

.nav-link.active {
  color: var(--primary);
  background: rgba(88, 166, 255, 0.178);
  border-left-color: var(--primary-hover);
  font-weight: 500;
}


/* ─── Main content ─── */
.main {
  flex: 1;
  margin-left: var(--sidebar-width );
  padding: 1rem 2rem;
  transition: margin-left 0.28s ease;
}
body.sidebar-collapsed .main {
  margin-left: 0;
  max-width: 960px;
}

.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }

h1 {
  font-size: 2.05rem;
  font-weight: 800;
  margin-bottom: 0.65rem;
  line-height: 1.25;
  letter-spacing: -0.02em;
}
h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 2.4rem 0 0.9rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}
h3 {
  font-size: 1.12rem;
  font-weight: 600;
  margin: 1.75rem 0 0.65rem;
  color: var(--primary);
}
h4 { font-size: 1.02rem; font-weight: 600; margin: 1.4rem 0 0.5rem; }

p { margin-bottom: 0.8rem; }
.lead {
  font-size: 1.12rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
}

ul, ol { margin: 0 0 1.2rem 1.4rem; }
li { margin-bottom: 0.35rem; }
strong { font-weight: 600; }

/* Inline code */
:not(pre) > code {
  font-family: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: var(--bg-secondary);
  padding: 0.12em 0.38em;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--text);
}

/* Code blocks + copy button */
.pre-wrap {
  position: relative;
  margin: 1rem 0 1.3rem;
}
.pre-wrap pre {
  margin: 0 !important;
}
.copy-btn {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  z-index: 5;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.28rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  font-family: inherit;
  line-height: 1.2;
}
.pre-wrap:hover .copy-btn,
.copy-btn:focus {
  opacity: 1;
}
.copy-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.copy-btn.copied {
  opacity: 1;
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}

pre {
  background: var(--code-bg) !important;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 1.1rem 1.2rem !important;
  overflow-x: auto;
  margin: 1.2rem 0 1.6rem;
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--code-text);
}
pre code {
  background: none !important;
  padding: 0 !important;
  border: none !important;
  color: inherit;
  font-size: inherit;
  font-family: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0 1.6rem;
  font-size: 0.9rem;
}
th, td {
  border: 1px solid var(--border);
  padding: 0.6rem 0.9rem;
  text-align: left;
}
th {
  background: var(--bg-secondary);
  font-weight: 600;
}
td { color: var(--text-muted); }
tr:hover td { background: var(--bg-secondary); color: var(--text); }

/* Callouts / notes */
.callout, .note {
  border-left: 4px solid var(--primary);
  background: var(--bg-secondary);
  padding: 0.95rem 1.15rem;
  margin: 1.4rem 0;
  border-radius: 0 8px 8px 0;
}
.callout.warning, .note.warning { border-left-color: var(--accent); }
.callout.danger { border-left-color: #ef4444; }
.callout.success { border-left-color: #16a34a; }
.callout-title {
  font-weight: 600;
  display: block;
  margin-bottom: 0.3rem;
}

/* Badges */
.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.12em 0.45em;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-sync { background: rgba(22,163,74,0.15); color: #16a34a; }
.badge-async { background: rgba(37,99,235,0.15); color: var(--primary); }

/* Method signature */
.method-sig {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88rem;
  margin: 0.9rem 0 1.1rem;
  overflow-x: auto;
}
.method-sig .name { color: var(--primary); font-weight: 600; }
.method-sig .param { color: var(--accent); }
.method-sig .type { color: #a855f7; }
.method-sig .return { color: #16a34a; }

/* Theme toggle (floating) */
.theme-toggle {
  position: fixed;
  bottom: 1.4rem;
  right: 1.4rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  z-index: 100;
  transition: transform 0.2s;
}
.theme-toggle:hover { transform: scale(1.08); }

/* Footer nav */
.page-footer {
  margin-top: 3.5rem;
  padding-top: 1.35rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--text-muted);
  gap: 1rem;
  flex-wrap: wrap;
}
.page-footer a {
  color: var(--primary);
  font-weight: 500;
}

/* Feature cards (home) */
.features {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.9rem;
  margin: 1.75rem 0;
}
.feature-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.05rem;
  box-shadow: var(--shadow);
}
.feature-card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.98rem;
  color: var(--primary);
}
.feature-card p {
  font-size: 0.88rem;
  margin: 0;
  color: var(--text-muted);
}

/* Highlight.js dark-ish code always (readable on both themes) */
.hljs { background: var(--code-bg) !important; color: var(--code-text); }

/* Responsive */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.18);
  }
  .main {
    margin-left: 0 !important;
    padding: 1.35rem 1.15rem 3.5rem;
    max-width: 100%;
  }
  body.sidebar-collapsed .main { margin-left: 0; }
  h1 { font-size: 1.7rem; }
}
