/* ============================================================
 * Docs / Setup page styles
 * Sidebar + content area for rendered markdown
 * ============================================================ */

.docs-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 0;
  min-height: calc(100vh - 64px);
}

/* ========== Sidebar ========== */
.docs-sidebar {
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  overflow-y: auto;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 24px 0;
}
.docs-sidebar-section {
  padding: 0 20px;
  margin-bottom: 24px;
}
.docs-sidebar h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 600;
  margin: 0 0 8px;
  padding: 0 12px;
}
.docs-sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.docs-sidebar a {
  display: block;
  padding: 7px 12px;
  font-size: 0.9rem;
  color: var(--text-muted);
  border-radius: 6px;
  transition: all 0.15s var(--ease);
  line-height: 1.4;
}
.docs-sidebar a:hover {
  background: var(--bg-elevated);
  color: var(--text);
}
.docs-sidebar a.active {
  background: var(--brand-50);
  color: var(--brand-700);
  font-weight: 500;
}
html[data-theme="dark"] .docs-sidebar a.active {
  background: rgba(99, 102, 241, 0.12);
  color: var(--brand-300);
}
.docs-sidebar-search {
  margin-bottom: 24px;
  padding: 0 20px;
}
.docs-sidebar-search input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s var(--ease);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%2394a3b8'%3E%3Cpath d='M11.7 10.3l3 3-1.4 1.4-3-3a6 6 0 1 1 1.4-1.4zM7 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 14px;
}
.docs-sidebar-search input:focus {
  border-color: var(--brand-400);
}
.docs-sidebar-search input::placeholder { color: var(--text-faint); }

/* ========== Mobile sidebar toggle ========== */
.docs-mobile-toggle {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 80;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--brand-600);
  color: #fff;
  display: none;
  place-items: center;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}

/* ========== Content area ========== */
.docs-content {
  padding: 48px 56px;
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}
.docs-loading,
.docs-error {
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
}
.docs-loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--brand-500);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Markdown article styling ========== */
.markdown { font-size: 16px; line-height: 1.7; color: var(--text); }
.markdown > *:first-child { margin-top: 0; }

.markdown h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  margin: 0 0 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  line-height: 1.2;
}
.markdown h2 {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 56px 0 20px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-soft);
  line-height: 1.3;
  scroll-margin-top: 80px;
}
.markdown h3 {
  font-size: 1.3rem;
  font-weight: 600;
  margin: 36px 0 16px;
  letter-spacing: -0.01em;
  scroll-margin-top: 80px;
}
.markdown h4 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 28px 0 12px;
  scroll-margin-top: 80px;
}
.markdown p { margin: 0 0 16px; }
.markdown a {
  color: var(--brand-600);
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s var(--ease);
}
.markdown a:hover { border-color: currentColor; }
html[data-theme="dark"] .markdown a { color: var(--brand-400); }

.markdown ul, .markdown ol { margin: 0 0 16px 0; padding-left: 28px; }
.markdown li { margin-bottom: 6px; }
.markdown li > p { margin-bottom: 8px; }

.markdown blockquote {
  margin: 20px 0;
  padding: 14px 20px;
  border-left: 4px solid var(--brand-400);
  background: var(--brand-50);
  border-radius: 0 8px 8px 0;
  color: var(--text);
}
html[data-theme="dark"] .markdown blockquote {
  background: rgba(99, 102, 241, 0.08);
  border-left-color: var(--brand-500);
}
.markdown blockquote p { margin: 0; }
.markdown blockquote p + p { margin-top: 8px; }

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

/* Inline code */
.markdown :not(pre) > code {
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  color: var(--brand-700);
}
html[data-theme="dark"] .markdown :not(pre) > code { color: var(--brand-300); }

/* Code blocks (highlight.js takes care of token colors) */
.markdown pre {
  margin: 20px 0;
  padding: 18px 22px;
  background: #0f172a;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.55;
}
html[data-theme="dark"] .markdown pre {
  background: #060a17;
  border: 1px solid var(--border-soft);
}
.markdown pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: #e2e8f0;
  font-size: inherit;
}

/* Mermaid */
.markdown pre.mermaid {
  background: var(--bg-soft);
  text-align: center;
  padding: 24px;
}
html[data-theme="dark"] .markdown pre.mermaid {
  background: var(--surface);
}
.markdown pre.mermaid svg { max-width: 100%; height: auto; margin: 0 auto; }

/* Tables */
.markdown table {
  border-collapse: collapse;
  width: 100%;
  margin: 24px 0;
  font-size: 0.92rem;
  display: block;
  overflow-x: auto;
  white-space: nowrap;
}
@media (min-width: 720px) {
  .markdown table { display: table; white-space: normal; }
}
.markdown th, .markdown td {
  border: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
}
.markdown th {
  background: var(--bg-soft);
  font-weight: 600;
  color: var(--text);
}
.markdown tr:nth-child(even) td { background: var(--bg-soft); }
html[data-theme="dark"] .markdown tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }

/* Doc page banner */
.docs-banner {
  position: relative;
  padding: 48px 56px;
  background: linear-gradient(135deg, var(--brand-600), var(--brand-800));
  color: #fff;
  margin-bottom: 0;
}
.docs-banner::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 50%, rgba(255,255,255,0.1), transparent 50%),
    radial-gradient(circle at 80% 50%, rgba(245, 158, 11, 0.15), transparent 50%);
  pointer-events: none;
}
.docs-banner-inner {
  position: relative;
  max-width: 920px;
  margin: 0 auto;
}
.docs-banner h1 {
  font-size: 2.2rem;
  font-weight: 800;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}
.docs-banner p {
  font-size: 1.05rem;
  opacity: 0.9;
  margin: 0;
}

.docs-toc-floating {
  position: sticky;
  top: 88px;
  align-self: start;
  font-size: 0.85rem;
  padding: 16px;
}
.docs-toc-floating h4 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 600;
  margin: 0 0 8px;
}
.docs-toc-floating ul { list-style: none; padding: 0; margin: 0; }
.docs-toc-floating a {
  display: block;
  padding: 4px 8px;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  transition: all 0.15s var(--ease);
  font-size: 0.85rem;
}
.docs-toc-floating a.active,
.docs-toc-floating a:hover {
  color: var(--brand-600);
  border-left-color: var(--brand-500);
}

/* ========== Docs index tiles ========== */
.doc-index-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.doc-index-tile {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s var(--ease);
  position: relative;
  overflow: hidden;
}
.doc-index-tile:hover {
  border-color: var(--brand-300);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  color: var(--text);
}
.doc-index-tile::after {
  content: "→";
  position: absolute;
  top: 24px;
  right: 24px;
  color: var(--text-faint);
  transition: all 0.15s var(--ease);
}
.doc-index-tile:hover::after {
  color: var(--brand-500);
  transform: translateX(4px);
}
.doc-index-num {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--brand-600);
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
html[data-theme="dark"] .doc-index-num { color: var(--brand-400); }
.doc-index-tile h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.doc-index-tile p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Responsive sidebar */
@media (max-width: 880px) {
  .docs-shell { grid-template-columns: 1fr; }
  .docs-sidebar {
    position: fixed;
    top: 64px;
    left: -100%;
    width: 280px;
    z-index: 70;
    transition: left 0.25s var(--ease);
    border-right: 1px solid var(--border);
  }
  .docs-sidebar.open { left: 0; }
  .docs-content { padding: 32px 24px; }
  .docs-banner { padding: 32px 24px; }
  .docs-banner h1 { font-size: 1.7rem; }
  .docs-mobile-toggle { display: grid; }
}

/* Phone-sized viewports — shrink typography and lock down anything that can
   overflow horizontally. Long code blocks, wide tables, mermaid SVGs, and
   inline code with long URLs are the usual culprits. */
@media (max-width: 640px) {
  .docs-content {
    padding: 24px 16px;
    /* Don't let the article exceed the viewport — code blocks and tables get
       their own internal scroll, but the article itself stays put. */
    max-width: 100%;
    overflow-x: hidden;
  }
  .docs-banner { padding: 24px 16px; }
  .docs-banner h1 { font-size: 1.4rem; }
  .docs-banner p { font-size: 0.95rem; }

  .markdown { font-size: 15px; line-height: 1.65; }
  .markdown h1 { font-size: 1.7rem; padding-bottom: 12px; }
  .markdown h2 { font-size: 1.3rem; margin: 36px 0 14px; padding-bottom: 6px; }
  .markdown h3 { font-size: 1.1rem; margin: 26px 0 10px; }
  .markdown h4 { font-size: 1rem; margin: 22px 0 8px; }

  /* Pre blocks scroll horizontally inside their own container instead of pushing
     the page sideways. The line-height stays comfortable for code reading. */
  .markdown pre {
    margin: 16px 0;
    padding: 14px 16px;
    font-size: 0.78rem;
    line-height: 1.5;
    max-width: 100%;
  }

  /* Inline code with long values (URLs, file paths) — wrap so they don't break
     out of the column on phones. */
  .markdown :not(pre) > code {
    word-break: break-word;
    overflow-wrap: anywhere;
    font-size: 0.82em;
  }

  /* Tables — the parent already has overflow-x: auto for horizontal scroll;
     just ensure the cell padding shrinks so most tables fit without scroll. */
  .markdown table {
    font-size: 0.84rem;
    /* Reset the desktop @media rule that says display: table so we get the
       inner-scroll behavior again. */
    display: block;
    white-space: nowrap;
  }
  .markdown th, .markdown td { padding: 8px 10px; }

  /* Long text — break very long URLs / words / code identifiers so they don't
     force horizontal scroll. */
  .markdown p,
  .markdown li,
  .markdown blockquote { overflow-wrap: anywhere; word-break: break-word; }

  /* Mermaid diagrams — keep them within the viewport, scroll if larger. */
  .markdown pre.mermaid {
    overflow-x: auto;
    padding: 16px;
  }
}

/* Very small phones (≤ 380px) — tighten further */
@media (max-width: 380px) {
  .markdown { font-size: 14px; }
  .markdown h1 { font-size: 1.5rem; }
  .markdown h2 { font-size: 1.2rem; }
  .docs-content { padding: 20px 12px; }
}
