/* =============================================================================
   UnlimitedModel.com — Documentation portal (/docs)
   Light-first developer docs: three-pane layout (sidebar / content / on-this-page),
   copyable code blocks with language tabs, integration guides, live model list.
   Loads after tokens.css + app-shell.css + base.css + components.css.
   ============================================================================= */

/* ===========================================
   1. Shell layout
   =========================================== */
.docs-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
  background: var(--bg-primary);
  color: var(--text-primary);
  /* Sidebar labels, breadcrumbs, and code-block captions are informational
     text: the global --text-muted (#98a2b3) fails WCAG AA at those sizes, so
     the docs portal raises the muted tone to the secondary shade. */
  --text-muted: var(--text-secondary);
}
.docs-shell.sidebar-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.docs-shell.sidebar-collapsed .docs-sidebar { transform: translateX(-100%); }

/* ===========================================
   2. Sidebar
   =========================================== */
.docs-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  z-index: var(--z-sticky, 100);
  transition: transform var(--transition-base, 180ms ease);
}
.docs-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: var(--z-fixed, 200);
}
.docs-sidebar-overlay.open { display: block; }

.sidebar-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: var(--space-4) var(--space-4) var(--space-3);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--text-primary);
  font-weight: var(--font-bold);
  font-size: var(--text-md);
  margin-bottom: var(--space-3);
}
.sidebar-logo-img { border-radius: var(--radius-sm); }
.sidebar-logo-text { letter-spacing: -0.01em; }
.sidebar-logo-badge {
  margin-left: auto;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--accent);
  background: var(--accent-light);
  border-radius: var(--radius-full);
  padding: 2px 8px;
}

.sidebar-search { position: relative; }
.sidebar-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  display: flex;
  pointer-events: none;
}
.sidebar-search-icon svg { width: 15px; height: 15px; }
.sidebar-search input {
  width: 100%;
  height: 36px;
  padding: 0 10px 0 32px;
  font-size: var(--text-sm);
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
}
.sidebar-search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.search-results {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  max-height: 340px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg, 0 12px 28px rgba(15, 23, 42, 0.14));
  z-index: var(--z-dropdown, 300);
}
.search-results.active { display: block; }
.search-result-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
}
.search-result-item:last-child { border-bottom: 0; }
.search-result-item:hover { background: var(--bg-hover); }
.result-icon { color: var(--text-muted); display: flex; padding-top: 2px; }
.result-icon svg { width: 14px; height: 14px; }
.result-title { font-size: var(--text-sm); font-weight: var(--font-medium); color: var(--text-primary); }
.result-category { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.search-no-results { padding: 12px; font-size: var(--text-sm); color: var(--text-muted); }

.sidebar-nav { padding: var(--space-3) var(--space-3) var(--space-5); flex: 1; }
.sidebar-nav-section { margin-bottom: var(--space-2); }
.sidebar-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px var(--space-2);
  background: none;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}
.sidebar-category-header:hover { color: var(--text-secondary); background: var(--bg-hover); }
.category-icon { display: flex; align-items: center; gap: 6px; }
.category-icon svg { width: 13px; height: 13px; }
.collapse-icon { display: flex; transition: transform var(--transition-fast, 120ms ease); }
.collapse-icon svg { width: 14px; height: 14px; }
.sidebar-category-header.collapsed .collapse-icon { transform: rotate(-90deg); }
.sidebar-category-items { display: flex; flex-direction: column; gap: 1px; padding: 2px 0 6px; }
.sidebar-category-items.collapsed { display: none; }

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 7px var(--space-2) 7px var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
}
.sidebar-nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: var(--font-semibold);
  border-left-color: var(--accent);
}
.nav-icon { display: flex; color: currentColor; opacity: 0.85; }
.nav-icon svg { width: 14px; height: 14px; }
.nav-label { flex: 1; min-width: 0; }

/* Sidebar footer: community help + collapse */
.sidebar-help {
  margin: 0 var(--space-3) var(--space-3);
  padding: var(--space-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}
.sidebar-help-title {
  margin: 0 0 6px;
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.sidebar-discord {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--accent);
  text-decoration: none;
}
.sidebar-discord:hover { color: var(--accent-hover); text-decoration: underline; }
.sidebar-discord svg { width: 15px; height: 15px; }
.sidebar-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 var(--space-3) var(--space-3);
  padding: 8px var(--space-3);
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
}
.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-hover); }
.sidebar-toggle svg { width: 14px; height: 14px; }

/* ===========================================
   3. Main column + header
   =========================================== */
.docs-main { display: flex; flex-direction: column; min-width: 0; }
.docs-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky, 100);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 60px;
  padding: 0 var(--space-6);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}
.breadcrumbs { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); min-width: 0; }
.breadcrumb-item {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  text-decoration: none;
}
.breadcrumb-item:hover { color: var(--text-primary); }
.breadcrumb-item svg, .breadcrumb-separator svg { width: 14px; height: 14px; }
.breadcrumb-separator { display: flex; color: var(--text-subtle); }
.breadcrumb-current { color: var(--text-primary); font-weight: var(--font-medium); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.docs-header-actions { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; flex-shrink: 0; }
.docs-header-actions .btn { text-decoration: none; }

#mobile-menu-btn { display: none; }
#mobile-sidebar-toggle { display: none; }
#mobile-menu-btn.is-mobile { display: inline-flex; }

/* ===========================================
   4. Content + page panels
   =========================================== */
/* Prose links are distinguishable without relying on colour alone
   (WCAG 1.4.1): underline them inside the reading column only, so nav and
   card links keep their current treatment. */
.docs-page-panel p a,
.docs-page-panel li a,
.docs-page-lede a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.docs-content { flex: 1; min-width: 0; }
.docs-content-inner {
  display: grid;
  /* reading column + on-this-page rail, 32px apart, centred in the viewport */
  grid-template-columns: minmax(0, 760px) 200px;
  gap: var(--space-8, 32px);
  max-width: 1056px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-16, 64px);
}
.docs-pages { min-width: 0; }
.docs-page-panel { display: none; }
.docs-page-panel.active { display: block; animation: none; }

/* Typography */
.docs-page-title {
  font-family: var(--font-display);
  font-size: var(--text-4xl, 28px);
  font-weight: var(--font-bold);
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin: 0 0 var(--space-3);
}
.docs-page-lede {
  font-size: var(--text-lg, 16px);
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0 0 var(--space-6);
  max-width: 68ch;
}
.docs-page-panel h2 {
  font-size: var(--text-2xl, 20px);
  font-weight: var(--font-bold);
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin: var(--space-10, 40px) 0 var(--space-3);
  padding-top: var(--space-2);
  scroll-margin-top: 80px;
}
.docs-page-panel h3 {
  font-size: var(--text-lg, 16px);
  font-weight: var(--font-semibold);
  line-height: 1.35;
  color: var(--text-primary);
  margin: var(--space-6) 0 var(--space-2);
  scroll-margin-top: 80px;
}
.docs-page-panel p, .docs-page-panel li { font-size: var(--text-base, 14px); line-height: 1.7; color: var(--text-secondary); }
.docs-page-panel p { margin: 0 0 var(--space-4); max-width: 74ch; }
.docs-page-panel ul, .docs-page-panel ol { margin: 0 0 var(--space-4); padding-left: 22px; max-width: 74ch; }
.docs-page-panel li { margin-bottom: 6px; }
.docs-page-panel strong { color: var(--text-primary); font-weight: var(--font-semibold); }
.docs-page-panel a { color: var(--accent); text-decoration: none; }
.docs-page-panel a:hover { text-decoration: underline; }
.docs-inline-code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  color: var(--text-primary);
  white-space: nowrap;
}
.docs-page-panel hr { border: 0; border-top: 1px solid var(--border-subtle); margin: var(--space-8) 0; }

/* ===========================================
   5. Callouts, steps, cards
   =========================================== */
.docs-callout {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border-default);
  border-left-width: 3px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  margin: 0 0 var(--space-5);
  max-width: 74ch;
}
.docs-callout-icon { flex-shrink: 0; color: var(--text-muted); display: flex; padding-top: 1px; }
.docs-callout-icon svg { width: 16px; height: 16px; }
.docs-callout-title { font-size: var(--text-sm); font-weight: var(--font-semibold); color: var(--text-primary); margin: 0 0 2px; }
.docs-callout p { margin: 0; font-size: var(--text-sm); }
.docs-callout--info { border-left-color: var(--accent); }
.docs-callout--info .docs-callout-icon { color: var(--accent); }
.docs-callout--warning { border-left-color: #d97706; }
.docs-callout--warning .docs-callout-icon { color: #d97706; }
.docs-callout--success { border-left-color: var(--success, #059669); }
.docs-callout--success .docs-callout-icon { color: var(--success, #059669); }

.docs-steps { display: flex; flex-direction: column; gap: var(--space-5); margin: 0 0 var(--space-6); }
.docs-step { display: flex; gap: var(--space-4); }
.docs-step-number {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--accent-light);
  color: var(--accent);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  display: flex;
  align-items: center;
  justify-content: center;
}
.docs-step-body { min-width: 0; flex: 1; }
.docs-step-title { font-size: var(--text-md, 15px); font-weight: var(--font-semibold); color: var(--text-primary); margin: 2px 0 var(--space-2); }
.docs-step-body > p { margin: 0 0 var(--space-3); }

.docs-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
  margin: 0 0 var(--space-6);
}
.docs-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: var(--space-5);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  text-decoration: none;
  transition: border-color var(--transition-fast, 120ms ease), box-shadow var(--transition-fast, 120ms ease);
}
.docs-card:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.docs-card-icon { color: var(--accent); display: flex; margin-bottom: 2px; }
.docs-card-icon svg { width: 20px; height: 20px; }
.docs-card-title { font-size: var(--text-md, 15px); font-weight: var(--font-semibold); color: var(--text-primary); }
.docs-card-desc { font-size: var(--text-sm); line-height: 1.55; color: var(--text-secondary); }
.docs-card-cta { margin-top: auto; padding-top: 8px; font-size: var(--text-sm); font-weight: var(--font-medium); color: var(--accent); }

/* ===========================================
   6. Tables
   =========================================== */
.docs-table-wrap { overflow-x: auto; margin: 0 0 var(--space-5); border: 1px solid var(--border-default); border-radius: var(--radius-md); }
.docs-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.docs-table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}
.docs-table td { padding: 10px 14px; border-bottom: 1px solid var(--border-subtle); color: var(--text-secondary); vertical-align: top; }
.docs-table tr:last-child td { border-bottom: 0; }
.docs-table code { font-family: var(--font-mono); font-size: 0.9em; color: var(--text-primary); }
.docs-table td:first-child { white-space: nowrap; }

/* ===========================================
   7. Code blocks + language tabs
   =========================================== */
.code-block {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin: 0 0 var(--space-5);
}
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 7px var(--space-3) 7px var(--space-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}
.code-block-label {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.code-block-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  cursor: pointer;
}
.code-block-copy:hover { color: var(--text-primary); border-color: var(--border-strong); }
.code-block-copy.copied { color: var(--success, #059669); border-color: var(--success, #059669); }
.code-block-copy svg { width: 13px; height: 13px; }
.code-block-body { overflow-x: auto; }
.code-block-body pre { margin: 0; padding: var(--space-4); }
.code-block-body code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text-primary);
  white-space: pre;
}
.code-block-body .token.comment { color: var(--text-muted); }
.code-block-body .token.string { color: #0f766e; }
.code-block-body .token.keyword, .code-block-body .token.boolean { color: #7c3aed; }
.code-block-body .token.function, .code-block-body .token.class-name { color: #1d4ed8; }
.code-block-body .token.number { color: #b45309; }
.code-block-body .token.property, .code-block-body .token.attr-name { color: #0e7490; }
.code-block-body .token.operator, .code-block-body .token.punctuation { color: var(--text-secondary); }

.code-tabs { margin: 0 0 var(--space-5); }
.code-tabs-header {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  border-bottom: 1px solid var(--border-default);
  margin-bottom: 0;
}
.code-tab {
  padding: 8px 14px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-muted);
  cursor: pointer;
}
.code-tab:hover { color: var(--text-primary); }
.code-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.code-tab-panel { display: none; }
.code-tab-panel.active { display: block; }
.code-tab-panel .code-block { margin-top: var(--space-3); border-top-left-radius: var(--radius-sm); }

/* ===========================================
   8. Live model catalog
   =========================================== */
.model-live {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  margin: 0 0 var(--space-5);
}
.model-live-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.model-live-title { font-size: var(--text-sm); font-weight: var(--font-semibold); color: var(--text-primary); margin-right: auto; }
.model-live-body { padding: var(--space-3) var(--space-4); max-height: 320px; overflow-y: auto; }
.model-live-status { font-size: var(--text-sm); color: var(--text-muted); margin: 0; }
.model-live-status.error { color: var(--text-secondary); }
.model-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 7px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.model-row:last-child { border-bottom: 0; }
.model-row-id { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--text-primary); flex: 1; min-width: 0; overflow-wrap: anywhere; }
.model-row-copy {
  flex-shrink: 0;
  padding: 3px 9px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  cursor: pointer;
}
.model-row-copy:hover { color: var(--text-primary); border-color: var(--border-strong); }

/* ===========================================
   9. FAQ accordion
   =========================================== */
.faq-accordion { display: flex; flex-direction: column; gap: var(--space-2); max-width: 74ch; margin: 0 0 var(--space-6); }
.faq-item {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  overflow: hidden;
}
.faq-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-4);
  background: none;
  border: 0;
  font-family: inherit;
  font-size: var(--text-md, 15px);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
}
.faq-trigger:hover { background: var(--bg-hover); }
.faq-trigger svg { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; transition: transform var(--transition-fast, 120ms ease); }
.faq-item.open .faq-trigger svg { transform: rotate(180deg); }
.faq-content { max-height: 0; overflow: hidden; transition: max-height var(--transition-base, 180ms ease); }
.faq-content > p { padding: 0 var(--space-4) var(--space-4); margin: 0; }

/* ===========================================
   10. On this page (right rail)
   =========================================== */
.docs-toc { position: sticky; top: 84px; align-self: start; max-height: calc(100vh - 110px); overflow-y: auto; }
.docs-toc-title {
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}
.docs-toc-nav { display: flex; flex-direction: column; gap: 1px; }
.docs-toc-link {
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 4px 0 4px 12px;
  border-left: 2px solid var(--border-subtle);
}
.docs-toc-link:hover { color: var(--text-primary); }
.docs-toc-link.active { color: var(--accent); border-left-color: var(--accent); font-weight: var(--font-medium); }

/* ===========================================
   11. Responsive
   =========================================== */
@media (max-width: 1180px) {
  .docs-content-inner { grid-template-columns: minmax(0, 1fr); }
  .docs-toc { display: none; }
}
@media (max-width: 1023px) {
  .docs-shell { grid-template-columns: minmax(0, 1fr); }
  .docs-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl, 0 24px 48px rgba(15, 23, 42, 0.2));
  }
  .docs-sidebar.open { transform: translateX(0); }
  .docs-shell.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); }
  .docs-shell.sidebar-collapsed .docs-sidebar { transform: translateX(-100%); }
  .sidebar-toggle { display: none; }
  #mobile-sidebar-toggle { display: inline-flex; }
}
@media (max-width: 767px) {
  .docs-content-inner { padding: var(--space-5) var(--space-4) var(--space-12, 48px); }
  .docs-header { padding: 0 var(--space-4); }
  .docs-header-actions .btn-text { display: none; }
  .docs-page-title { font-size: var(--text-3xl, 24px); }
  .docs-card-grid { grid-template-columns: 1fr; }
}
