/* ==========================================================================
   Contexa Documentation Layout
   Sidebar Navigation, Documentation Content, Table of Contents
   ========================================================================== */

/* ── Docs Page Layout ── */
.docs-layout {
  display: flex;
  max-width: var(--max-width-wide);
  margin: 0 auto;
  min-height: calc(100vh - var(--header-height));
}

/* ── Sidebar ── */
.docs-sidebar {
  position: sticky;
  top: var(--header-height);
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-6) 0;
  z-index: 10;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
}

.docs-sidebar::-webkit-scrollbar {
  width: 4px;
}

.docs-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.docs-sidebar::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: var(--radius-full);
}

.sidebar-section {
  margin-bottom: var(--space-2);
  width: 100%;
}

.sidebar-section-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px var(--space-4);
  font-size: 0.8rem;
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  letter-spacing: 0.01em;
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast), background-color var(--transition-fast);
  border-radius: 0;
}

.sidebar-section-title:hover {
  color: var(--brand-primary);
  background-color: rgba(37, 99, 235, 0.04);
}

.sidebar-section-title .chevron {
  width: 12px;
  height: 12px;
  transition: transform 200ms ease;
  opacity: 0.35;
}

.sidebar-section.collapsed .chevron {
  transform: rotate(-90deg);
}

.sidebar-section.collapsed .sidebar-links {
  max-height: 0 !important;
  opacity: 0;
  overflow: hidden;
}

/* Section with active link gets a subtle accent */
.sidebar-section.has-active > .sidebar-section-title {
  color: var(--brand-primary);
}

.sidebar-links {
  list-style: none;
  padding: 0 !important;
  padding-left: 0 !important;
  margin: 0 0 var(--space-2) 0;
  overflow: hidden;
  transition: max-height 300ms cubic-bezier(0.4, 0, 0.2, 1), opacity 200ms ease;
  text-align: center;
}

.sidebar-links li {
  margin: 0;
}

.sidebar-link {
  display: block;
  padding: 7px var(--space-4);
  font-size: 0.82rem;
  font-weight: var(--weight-regular);
  color: var(--text-tertiary);
  text-decoration: none;
  text-align: center;
  transition: color 150ms ease, background-color 150ms ease;
  border-radius: var(--radius-sm);
  line-height: 1.5;
  margin: 0 var(--space-3);
}

.sidebar-link:hover {
  color: var(--text-primary);
  background-color: rgba(0, 0, 0, 0.025);
}

.sidebar-link.active {
  color: var(--brand-primary);
  font-weight: var(--weight-medium);
  background-color: rgba(37, 99, 235, 0.06);
}

/* Nested sidebar links */
.sidebar-links .sidebar-links {
  margin: 0;
}

.sidebar-links .sidebar-links .sidebar-link {
  font-size: var(--text-xs);
}

/* ── Docs Content ── */
.docs-content {
  flex: 1;
  min-width: 0;
  transition: opacity 150ms ease;
}

.docs-content-inner {
  max-width: var(--docs-content-max-width);
  padding: var(--space-10) var(--space-8) var(--space-16);
  margin: 0 auto;
  overflow-x: auto;
}

/* ── Docs Page Title ── */
.docs-page-header {
  margin-bottom: var(--space-10);
  padding-bottom: var(--space-8);
  border-bottom: 1px solid var(--border-light);
}

.docs-page-header h1 {
  font-size: var(--text-4xl);
  margin-bottom: var(--space-3);
}

.docs-page-header .lead {
  margin-bottom: 0;
  max-width: 640px;
}

.docs-module-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

/* ── Docs Content Typography ── */
.docs-content h2 {
  margin-top: var(--space-12);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-light);
}

.docs-content h2:first-of-type {
  border-top: none;
  padding-top: 0;
}

.docs-content h3 {
  margin-top: var(--space-8);
}

/* ── API Signature Block ── */
.api-signature {
  margin: var(--space-6) 0;
  padding: var(--space-4) var(--space-5);
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  overflow-x: auto;
}

.api-signature .keyword {
  color: var(--brand-primary);
  font-weight: var(--weight-medium);
}

.api-signature .type {
  color: var(--brand-secondary);
}

.api-signature .param {
  color: var(--text-primary);
}

.api-signature .annotation {
  color: #D97706;
}

/* ── Method / Property Listing ── */
.api-method {
  margin: var(--space-8) 0;
  padding: var(--space-6);
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
}

.api-method-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.api-method-name {
  font-family: var(--font-mono);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.api-method-return {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--brand-secondary);
  background: var(--brand-secondary-light);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.api-method-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
  margin-bottom: var(--space-4);
}

.api-method-params {
  margin-top: var(--space-4);
}

.api-method-params h5 {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  margin-bottom: var(--space-2);
  margin-top: 0;
}

.api-param {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border-light);
}

.api-param:last-child {
  border-bottom: none;
}

.api-param-name {
  font-family: var(--font-mono);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  white-space: nowrap;
  min-width: 120px;
}

.api-param-type {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--brand-secondary);
  white-space: nowrap;
  min-width: 100px;
}

.api-param-desc {
  color: var(--text-secondary);
  flex: 1;
}

/* ── Enum Values Table ── */
.enum-table {
  width: 100%;
  margin: var(--space-4) 0;
}

.enum-table td:first-child {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  width: 200px;
}

/* ── Related Links / See Also ── */
.related-links {
  margin-top: var(--space-10);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-light);
}

.related-links h4 {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  margin-bottom: var(--space-4);
  margin-top: 0;
}

.related-links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-3);
}

.related-link-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  text-decoration: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.related-link-card h3 {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  margin: 0;
}

.related-link-card p {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin: 0;
}

.related-link-card:hover {
  border-color: var(--border-brand);
  box-shadow: var(--shadow-sm);
}

.related-link-card-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}

.related-link-card-desc {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.related-link-card svg {
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

/* ── Docs Navigation (Prev/Next) ── */
.docs-nav-footer {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-12);
  padding-top: var(--space-8);
  border-top: 1px solid var(--border-light);
}

.docs-nav-link {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-6);
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  text-decoration: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  flex: 1;
  max-width: 50%;
}

.docs-nav-link:hover {
  border-color: var(--border-brand);
  box-shadow: var(--shadow-sm);
}

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

.docs-nav-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
}

.docs-nav-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--brand-primary);
}

/* ── Mobile Sidebar Toggle ── */
.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  width: 48px;
  height: 48px;
  align-items: center;
  justify-content: center;
  background: var(--brand-gradient);
  color: var(--text-inverse);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-overlay);
}

.sidebar-toggle svg {
  width: 20px;
  height: 20px;
}

/* ── Sidebar Mobile Overlay ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 9;
}

/* ── Sidebar Search ── */
.sidebar-search {
  position: relative;
  padding: 0 var(--space-4) var(--space-4);
  flex-shrink: 0;
}

.sidebar-search-input {
  width: 100%;
  padding: 8px 32px 8px 34px;
  font-size: 0.8125rem;
  font-family: inherit;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

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

.sidebar-search-icon {
  position: absolute;
  left: calc(var(--space-4) + 10px);
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.sidebar-search-icon svg {
  width: 100%;
  height: 100%;
}

.sidebar-search-clear {
  position: absolute;
  right: calc(var(--space-4) + 8px);
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.sidebar-search-clear:hover {
  color: var(--text-primary);
  background: var(--bg-secondary);
}

/* ── On This Page TOC ── */
/* ── Right-side TOC Sidebar ── */
.docs-toc-sidebar {
  width: 220px;
  min-width: 220px;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  padding: var(--space-6) var(--space-3) var(--space-6) 0;
  border-left: 1px solid var(--border-light);
}

.docs-toc-sidebar::-webkit-scrollbar { width: 3px; }
.docs-toc-sidebar::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

.docs-toc {
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
}

.docs-toc-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.docs-toc-toggle {
  width: 12px;
  height: 12px;
  transition: transform 0.2s;
  margin-left: auto;
}

.docs-toc.collapsed .docs-toc-toggle {
  transform: rotate(-90deg);
}

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

.docs-toc.collapsed .docs-toc-list {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  margin: 0;
}

.docs-toc-item {
  margin: 0;
}

.docs-toc-item.docs-toc-sub {
  padding-left: var(--space-4);
}

.docs-toc-link {
  display: block;
  padding: 4px 8px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-radius: 0 4px 4px 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  line-height: 1.4;
}

.docs-toc-link:hover {
  color: var(--text-primary);
  background: rgba(37, 99, 235, 0.05);
}

.docs-toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* Desktop: 3+ headings, expanded by default */
@media (min-width: 769px) {
  .docs-toc-toggle {
    display: none;
  }
  .docs-toc-title {
    cursor: default;
  }
}

/* ==========================================================================
   Architecture Diagram System
   CSS-based visual diagrams replacing ASCII text diagrams
   ========================================================================== */

/* ── Diagram Container ── */
.diagram-container {
  margin: var(--space-6) 0;
  padding: var(--space-6);
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  overflow-x: auto;
}

.diagram-container.diagram-compact {
  padding: var(--space-4);
}

.diagram-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  margin-bottom: var(--space-4);
  text-align: center;
}

/* ── Horizontal Flow ── */
.diagram-flow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  flex-wrap: nowrap;
  min-width: max-content;
}

.diagram-flow.diagram-flow-wrap {
  flex-wrap: wrap;
  gap: var(--space-3);
}

/* ── Vertical Flow ── */
.diagram-flow-vertical {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

/* ── Diagram Box (Component) ── */
.diagram-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-primary);
  border: 2px solid var(--border-light);
  border-radius: var(--radius-lg);
  min-width: 120px;
  text-align: center;
  flex-shrink: 0;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.diagram-box:hover {
  border-color: var(--brand-primary);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.1);
}

.diagram-box-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  line-height: 1.3;
}

.diagram-box-desc {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
  line-height: 1.3;
}

.diagram-box-code {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--brand-secondary);
  margin-top: 4px;
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

/* Box Variants */
.diagram-box.diagram-highlight {
  border-color: var(--brand-primary);
  background: rgba(37, 99, 235, 0.04);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.diagram-box.diagram-accent {
  border-color: var(--brand-secondary);
  background: rgba(124, 58, 237, 0.04);
}

.diagram-box.diagram-success {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.04);
}

.diagram-box.diagram-warning {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.04);
}

.diagram-box.diagram-danger {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.04);
}

.diagram-box.diagram-muted {
  border-color: var(--border-light);
  background: var(--bg-secondary);
  opacity: 0.7;
}

.diagram-box.diagram-large {
  min-width: 160px;
  padding: var(--space-4) var(--space-5);
}

.diagram-box.diagram-small {
  min-width: 80px;
  padding: var(--space-2) var(--space-3);
}

.diagram-box.diagram-small .diagram-box-name {
  font-size: var(--text-xs);
}

/* ── Horizontal Arrow ── */
.diagram-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 0 var(--space-2);
  flex-shrink: 0;
  position: relative;
  min-width: 40px;
}

.diagram-arrow::before {
  content: '';
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text-tertiary);
}

.diagram-arrow::after {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 8px solid var(--text-tertiary);
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
}

.diagram-arrow.diagram-arrow-long::before {
  width: 48px;
}

.diagram-arrow.diagram-arrow-long {
  min-width: 64px;
}

.diagram-arrow.diagram-arrow-long::after {
  right: 4px;
}

/* ── Vertical Arrow ── */
.diagram-arrow-down {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-1) 0;
  flex-shrink: 0;
  position: relative;
  min-height: 28px;
}

.diagram-arrow-down::before {
  content: '';
  display: block;
  width: 2px;
  height: 16px;
  background: var(--text-tertiary);
}

.diagram-arrow-down::after {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 8px solid var(--text-tertiary);
}

.diagram-arrow-down.diagram-arrow-long::before {
  height: 28px;
}

/* ── Arrow Labels ── */
.diagram-label {
  font-size: 0.65rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
}

.diagram-arrow-down .diagram-label {
  top: auto;
  left: calc(100% + 6px);
  transform: none;
  top: 50%;
  transform: translateY(-50%);
}

/* ── Vertical Line (no arrowhead) ── */
.diagram-line-down {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.diagram-line-down::before {
  content: '';
  display: block;
  width: 2px;
  height: 8px;
  background: var(--text-tertiary);
}

/* ── Diagram Group (Cluster) ── */
.diagram-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: var(--space-4);
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-xl);
  background: rgba(0, 0, 0, 0.01);
}

.diagram-group-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-3);
}

/* ── Diagram Grid (Side-by-side boxes) ── */
.diagram-grid {
  display: grid;
  gap: var(--space-3);
  justify-items: center;
}

.diagram-grid-2 { grid-template-columns: 1fr 1fr; }
.diagram-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.diagram-grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.diagram-grid-5 { grid-template-columns: repeat(5, 1fr); }

/* ── Branching (Fork/Join) ── */
.diagram-branch {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
}

.diagram-branch-line {
  width: 2px;
  background: var(--text-tertiary);
  align-self: stretch;
  margin: 0 var(--space-3);
  position: relative;
}

/* ── Step Indicator ── */
.diagram-step {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  width: 100%;
}

.diagram-step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: var(--radius-full);
  background: var(--brand-primary);
  color: white;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
}

.diagram-step-content {
  flex: 1;
}

.diagram-step-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.diagram-step-desc {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}

.diagram-step.diagram-step-active {
  border-color: var(--brand-primary);
  background: rgba(37, 99, 235, 0.03);
}

.diagram-step.diagram-step-complete .diagram-step-number {
  background: #10b981;
}

/* ── Comparison / vs Layout ── */
.diagram-compare {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}

.diagram-compare-vs {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  border: 2px solid var(--border-light);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--text-tertiary);
  align-self: center;
}

.diagram-compare-side {
  padding: var(--space-4);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--bg-primary);
  min-width: 0;
  overflow-x: auto;
}

.diagram-compare-side .code-block {
  margin: var(--space-3) 0;
}

.diagram-compare-side .code-block pre {
  overflow-x: auto;
  font-size: var(--text-xs);
}

.diagram-compare-side h4 {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  margin: 0 0 var(--space-3);
}

/* ── Responsive: stack on mobile ── */
@media (max-width: 768px) {
  .diagram-flow {
    flex-direction: column;
  }
  .diagram-arrow {
    transform: rotate(90deg);
    padding: var(--space-1) 0;
    min-width: auto;
    min-height: 28px;
  }
  .diagram-arrow.diagram-arrow-long {
    min-width: auto;
  }
  .diagram-grid-3,
  .diagram-grid-4,
  .diagram-grid-5 {
    grid-template-columns: 1fr 1fr;
  }
  .diagram-compare {
    grid-template-columns: 1fr;
  }
  .diagram-compare-vs {
    justify-self: center;
  }
  .diagram-branch {
    flex-direction: column;
  }
}

/* ==========================================================================
   Vertical Flow Diagrams — Premium Architecture Visualization
   ========================================================================== */

.arch-vertical-flow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: var(--space-8) var(--space-6);
  margin: var(--space-6) 0;
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  position: relative;
  overflow: hidden;
}

.arch-vertical-flow::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 2px;
  height: 100%;
  background: linear-gradient(to bottom, transparent 0%, var(--border-light) 10%, var(--border-light) 90%, transparent 100%);
  transform: translateX(-50%);
  z-index: 0;
}

.arch-vf-node {
  position: relative;
  z-index: 1;
  background: var(--bg-primary);
  border: 2px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  text-align: center;
  min-width: 200px;
  max-width: 320px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s, box-shadow 0.2s;
}

.arch-vf-node:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.12);
}

.arch-vf-sub {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-normal);
  color: var(--text-tertiary);
  margin-top: 2px;
}

.arch-vf-success {
  border-color: var(--success);
  background: linear-gradient(135deg, var(--bg-primary) 0%, rgba(34, 197, 94, 0.04) 100%);
}

.arch-vf-warning {
  border-color: var(--warning);
  background: linear-gradient(135deg, var(--bg-primary) 0%, rgba(245, 158, 11, 0.04) 100%);
}

.arch-vf-error {
  border-color: var(--error);
  background: linear-gradient(135deg, var(--bg-primary) 0%, rgba(239, 68, 68, 0.04) 100%);
}

.arch-vf-decision {
  position: relative;
  z-index: 1;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.08) 0%, rgba(139, 92, 246, 0.08) 100%);
  border: 2px solid var(--primary);
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--primary);
  text-align: center;
  min-width: 180px;
  transform: rotate(0deg);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  aspect-ratio: 2 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.arch-vf-arrow {
  position: relative;
  z-index: 1;
  color: var(--text-tertiary);
  font-size: 1rem;
  line-height: 1;
  padding: var(--space-1) 0;
}

.arch-vf-branch {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
  width: 100%;
  max-width: 640px;
  margin-top: var(--space-2);
}

.arch-vf-branch-left,
.arch-vf-branch-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: var(--space-4);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] .arch-vf-branch-left,
[data-theme="dark"] .arch-vf-branch-right {
  background: rgba(30, 41, 59, 0.3);
}

.arch-vf-branch-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: 9999px;
  background: var(--bg-secondary);
}

.arch-vf-branch-left .arch-vf-branch-label {
  color: var(--success);
}

.arch-vf-branch-right .arch-vf-branch-label {
  color: var(--primary);
}

/* Sequence diagram (Client <-> Server) */
.arch-sequence {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: var(--space-4);
  padding: var(--space-6);
  margin: var(--space-6) 0;
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
}

.arch-seq-actor {
  text-align: center;
}

.arch-seq-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--primary);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--primary);
  margin-bottom: var(--space-4);
}

.arch-seq-steps {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.arch-seq-step {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-primary);
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.arch-seq-arrows {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: var(--space-4);
  color: var(--text-tertiary);
}

.arch-seq-arrow-right,
.arch-seq-arrow-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Split cards (Multi MFA, comparison panels) */
.arch-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin: var(--space-6) 0;
}

.arch-split-card {
  padding: var(--space-5);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  background: var(--bg-primary);
  border-top: 3px solid var(--primary);
}

.arch-split-card:nth-child(2) {
  border-top-color: #8b5cf6;
}

.arch-split-title {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  margin: 0 0 var(--space-3) 0;
}

.arch-split-card:first-child .arch-split-title { color: var(--primary); }
.arch-split-card:nth-child(2) .arch-split-title { color: #8b5cf6; }

.arch-split-meta {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}

.arch-split-meta code {
  font-size: var(--text-xs);
}

/* Result badges */
.arch-vf-result {
  display: inline-flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.arch-vf-badge {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  padding: var(--space-1) var(--space-3);
  border-radius: 9999px;
}

.arch-vf-badge-success {
  background: rgba(34, 197, 94, 0.1);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.arch-vf-badge-error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

@media (max-width: 768px) {
  .arch-vf-branch {
    grid-template-columns: 1fr;
  }
  .arch-split {
    grid-template-columns: 1fr;
  }
  .arch-sequence {
    grid-template-columns: 1fr;
  }
  .arch-vf-decision {
    clip-path: none;
    aspect-ratio: auto;
    border-radius: var(--radius-lg);
  }
}
