/* ========================================
   VARIABLE BRIDGE
   Maps guides internal vars → main.css system
   ======================================== */
:root {
  --nav-height: 64px;
  --radius: 0.5rem;
  --radius-lg: 1rem;
  --transition: 0.2s ease;
  --font-body: inherit;
  --font-mono: 'Courier New', Courier, monospace;

  /* Light theme mappings */
  --bg-base:     var(--bg-light);
  --bg-card:     var(--bg-light);
  --bg-surface:  var(--bg-light-secondary);
  --border:      var(--border-light);
  --border-accent: rgba(37, 99, 235, 0.4);
  --text-primary:   #0f172a;
  --text-secondary: #334155;
  --text-muted:     #64748b;
  --accent-dim:     rgba(37, 99, 235, 0.08);
  --accent2:        #6d28d9;
  --orange:         #ea580c;
  --green:          #059669;
}

html.dark {
  --bg-base:     var(--bg-dark);
  --bg-card:     var(--bg-dark-secondary);
  --bg-surface:  #111827;
  --border:      var(--border-dark);
  --border-accent: rgba(37, 99, 235, 0.4);
  --text-primary:   var(--text-dark);
  --text-secondary: var(--text-dark-secondary);
  --text-muted:     #64748b;
  --accent-dim:     rgba(37, 99, 235, 0.12);
  --accent2:        #a78bfa;
  --orange:         #fb923c;
  --green:          #34d399;
}

/* ========================================
   PAGE LAYOUT
   ======================================== */
#main-content {
  padding-top: 2.5rem;
  padding-bottom: 5rem;
  min-height: calc(100vh - var(--nav-height));
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.knowledge-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 900px) {
  /* Stack sidebar above article */
  .knowledge-layout {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  /* Sidebar: normal block, no sticky, no fixed */
  .knowledge-sidebar {
    position: static !important;
    transform: none !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* Let the list show fully */
  .sidebar-list {
    max-height: 260px;
    overflow-y: auto;
  }

  /* Page adjustments */
  #main-content {
    padding-top: 1rem;
  }

  .page-header {
    margin-bottom: 1rem;
  }

  .page-header h1 {
    font-size: 1.4rem;
  }

  .article-body {
    padding: 1.25rem 1rem;
  }

  .article-topbar {
    padding: 0.75rem 1rem;
  }

  .container {
    padding: 0 0.875rem;
  }

  /* Hide desktop-only nav counter */
  .nav-center-counter {
    display: none;
  }

  /* Prev/next buttons */
  .article-nav-footer {
    grid-template-columns: 1fr 1fr;
    padding: 0.875rem 1rem;
  }

  .article-nav-btn.next {
    margin-left: 0;
  }

  .nav-btn-title {
    max-width: 120px;
  }
}

/* ========================================
   PAGE HEADER
   ======================================== */
.page-header {
  margin-bottom: 2rem;
}

.page-header-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--border-accent);
  border-radius: 2rem;
  padding: 0.3rem 0.875rem;
  margin-bottom: 0.75rem;
}

.page-header h1 {
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 0.5rem;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ========================================
   SIDEBAR
   ======================================== */
/* Sidebar - desktop only positioning */
@media (min-width: 901px) {
  .knowledge-sidebar {
    position: sticky;
    top: calc(var(--nav-height) + 1.5rem);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
  }

  html:not(.dark) .knowledge-sidebar {
    border-color: #cbd5e1;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  }
}

/* Sidebar base - shared between desktop and mobile drawer */
.knowledge-sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.sidebar-head {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
}

html:not(.dark) .sidebar-head {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.sidebar-head-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.sidebar-article-count {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--accent-dim);
  border: 1px solid var(--border-accent);
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
}

/* Sidebar search */
.sidebar-search-wrap {
  padding: 0.875rem;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.sidebar-search-wrap input {
  width: 100%;
  padding: 0.55rem 0.875rem 0.55rem 2.25rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text-primary);
  font-size: 0.8rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  box-sizing: border-box;
}

.sidebar-search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.sidebar-search-wrap input::placeholder {
  color: var(--text-muted);
}

.sidebar-search-icon {
  position: absolute;
  left: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  display: flex;
  pointer-events: none;
}

.sidebar-search-icon svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-list {
  list-style: none;
  padding: 0.5rem;
  margin: 0;
  max-height: calc(100vh - var(--nav-height) - 12rem);
  overflow-y: auto;
}

.sidebar-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem;
  border-radius: 0.625rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 0.125rem;
  position: relative;
}

.sidebar-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 3px;
  height: 60%;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  transition: transform var(--transition);
}

.sidebar-item:hover {
  background: var(--accent-dim);
}

.sidebar-item.active {
  background: var(--accent-dim);
}

.sidebar-item.active::before {
  transform: translateY(-50%) scaleY(1);
}

.sidebar-num {
  font-size: 0.62rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-weight: 600;
  padding-top: 0.175rem;
  min-width: 1.25rem;
  flex-shrink: 0;
  transition: color var(--transition);
}

.sidebar-item.active .sidebar-num {
  color: var(--accent);
}

.sidebar-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.45;
  font-weight: 500;
  transition: color var(--transition);
}

html:not(.dark) .sidebar-label {
  color: #334155;
}

.sidebar-item:hover .sidebar-label,
.sidebar-item.active .sidebar-label {
  color: var(--text-primary);
  font-weight: 600;
}

html:not(.dark) .sidebar-item:hover .sidebar-label,
html:not(.dark) .sidebar-item.active .sidebar-label {
  color: #1d4ed8;
}

.sidebar-item.hidden {
  display: none;
}

/* ========================================
   ARTICLE AREA
   ======================================== */
.knowledge-content {
  min-width: 0;
}

.article-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 420px;
  text-align: center;
  gap: 1rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  background: var(--bg-card);
}

.article-placeholder .placeholder-icon {
  font-size: 2.5rem;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  border-radius: 1rem;
  border: 1px solid var(--border-accent);
}

.article-placeholder h3 {
  font-size: 1.05rem;
  color: var(--text-secondary);
  font-weight: 600;
  margin: 0;
}

.article-placeholder p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

.article-frame {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

html:not(.dark) .article-frame {
  border-color: #cbd5e1;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.article-frame.visible {
  display: block;
  animation: fadeSlideIn 0.25s ease;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Article topbar */
.article-topbar {
  padding: 0.875rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--bg-surface);
}

html:not(.dark) .article-topbar {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.article-breadcrumb {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.article-breadcrumb a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: opacity var(--transition);
}

.article-breadcrumb a:hover {
  opacity: 0.75;
}

.article-breadcrumb .sep {
  color: var(--border);
}

/* Article body */
.article-body {
  padding: 2.25rem 2.5rem;
}

@media (max-width: 640px) {
  .article-body {
    padding: 1.5rem 1.25rem;
  }
}

/* ========================================
   ARTICLE CONTENT TYPOGRAPHY
   ======================================== */
.article-content .tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
}

.article-content .tag {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.65rem;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.article-content .tag.blue   { background: rgba(56,189,248,0.12); color: #38bdf8; border: 1px solid rgba(56,189,248,0.25); }
.article-content .tag.purple { background: rgba(167,139,250,0.12); color: #a78bfa; border: 1px solid rgba(167,139,250,0.25); }
.article-content .tag.green  { background: rgba(52,211,153,0.12); color: #34d399; border: 1px solid rgba(52,211,153,0.25); }

.article-content h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.25;
  margin-bottom: 1rem;
}

.article-content h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 2.5rem;
  margin-bottom: 0.875rem;
  padding-bottom: 0.625rem;
  border-bottom: 1px solid var(--border);
}

.article-content h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-top: 1.75rem;
  margin-bottom: 0.625rem;
  color: var(--accent);
}

.article-content p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.85;
  margin-bottom: 1rem;
}

html:not(.dark) .article-content p {
  color: #1e293b;
}

.article-content ul,
.article-content ol {
  padding-left: 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.article-content li {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

html:not(.dark) .article-content li {
  color: #1e293b;
}

.article-content ul li::marker { color: var(--accent); }
.article-content ol li::marker { color: var(--accent); font-weight: 700; }

.article-content strong { color: var(--text-primary); font-weight: 600; }
.article-content em { color: var(--accent2); font-style: italic; }

.article-content pre {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.125rem 1.25rem;
  overflow-x: auto;
  margin: 1.125rem 0 1.375rem;
  font-size: 0.8rem;
  line-height: 1.75;
  position: relative;
}

html:not(.dark) .article-content pre {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.article-content pre::before {
  content: attr(data-lang);
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.article-content code { color: var(--accent); font-family: var(--font-mono); }
.article-content pre code { color: var(--green); }

html:not(.dark) .article-content pre code { color: #065f46; }

.article-content p code,
.article-content li code {
  background: var(--accent-dim);
  border: 1px solid var(--border-accent);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.8em;
  color: var(--accent);
  font-family: var(--font-mono);
}

html:not(.dark) .article-content p code,
html:not(.dark) .article-content li code {
  background: rgba(37, 99, 235, 0.07);
  border-color: rgba(37, 99, 235, 0.25);
  color: #1d4ed8;
}

/* Info & warn boxes */
.info-box {
  background: var(--accent-dim);
  border: 1px solid var(--border-accent);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.875rem 1.125rem;
  margin: 1.25rem 0;
}

.info-box p { margin: 0; font-size: 0.855rem; }

html:not(.dark) .info-box {
  background: rgba(37, 99, 235, 0.06);
  border-color: rgba(37, 99, 235, 0.3);
}

html:not(.dark) .info-box p { color: #1e3a8a; }

.warn-box {
  background: rgba(249, 115, 22, 0.07);
  border: 1px solid rgba(249, 115, 22, 0.2);
  border-left: 3px solid var(--orange);
  border-radius: var(--radius);
  padding: 0.875rem 1.125rem;
  margin: 1.25rem 0;
}

.warn-box p { margin: 0; font-size: 0.855rem; }

html:not(.dark) .warn-box {
  background: rgba(234, 88, 12, 0.06);
  border-color: rgba(234, 88, 12, 0.3);
}

html:not(.dark) .warn-box p { color: #7c2d12; }

/* Loader */
.loader {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ========================================
   ARTICLE NAV FOOTER (prev/next)
   ======================================== */
.article-nav-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-surface);
}

html:not(.dark) .article-nav-footer {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.article-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all var(--transition);
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
}

.article-nav-btn:hover:not(.disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.article-nav-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
}

.article-nav-btn.prev {
  justify-content: flex-start;
}

.article-nav-btn.next {
  justify-content: flex-end;
  margin-left: auto;
}

.nav-btn-label {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  text-align: left;
}

.nav-btn-label.right {
  text-align: right;
}

.nav-btn-direction {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  line-height: 1;
}

.article-nav-btn:hover:not(.disabled) .nav-btn-direction {
  color: var(--accent);
  opacity: 0.7;
}

.nav-btn-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.3;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html:not(.dark) .nav-btn-title {
  color: #334155;
}

.article-nav-btn:hover:not(.disabled) .nav-btn-title {
  color: var(--accent);
}

.nav-center-counter {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  text-align: center;
}

@media (max-width: 640px) {
  .article-nav-footer {
    grid-template-columns: 1fr 1fr;
    padding: 0.875rem 1rem;
  }
  .nav-center-counter { display: none; }
  .article-nav-btn.next { margin-left: 0; }
  .nav-btn-title { max-width: 120px; }
}

/* ========================================
   ARTICLE INLINE LINKS
   (only inside paragraphs/list items - keeps
   .btn / .related-guide-card untouched)
   ======================================== */
.article-content p a,
.article-content li a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid var(--border-accent);
  transition: opacity var(--transition);
}

.article-content p a:hover,
.article-content li a:hover {
  opacity: 0.7;
}

/* ========================================
   VIDEO EMBED
   ======================================== */
.video-embed-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.625rem;
}

.video-embed {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 */
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin: 0 0 1.5rem;
  border: 1px solid var(--border);
  background: var(--bg-base);
}

html:not(.dark) .video-embed {
  border-color: #cbd5e1;
}

.video-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* ========================================
   TOOL CTA
   (callout box with a button to the tool)
   ======================================== */
.tool-cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.25rem;
  background: var(--accent-dim);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin: 1.25rem 0 1.5rem;
}

.tool-cta-text {
  flex: 1 1 220px;
  min-width: 0;
}

.tool-cta-text strong {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
  color: var(--text-primary);
}

.tool-cta-text span {
  display: block;
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--text-muted);
}

.tool-cta .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

/* ========================================
   RELATED GUIDES
   (cross-links to other articles, placed
   inside .article-content)
   ======================================== */
.related-guides {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.875rem;
  margin: 1.25rem 0 0.5rem;
}

.article-content a.related-guide-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.95rem 1.1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 400;
  color: inherit;
  transition: all var(--transition);
}

html:not(.dark) .article-content a.related-guide-card {
  border-color: #cbd5e1;
}

.article-content a.related-guide-card:hover {
  opacity: 1;
  border-color: var(--accent);
  background: var(--accent-dim);
  transform: translateX(2px);
}

.related-guide-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 0.5rem;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 700;
  transition: all var(--transition);
}

.article-content a.related-guide-card:hover .related-guide-icon {
  background: var(--accent);
  color: #fff;
}

.related-guide-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.related-guide-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.related-guide-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}