/* ============================================================
   AvalAI Docs — Global Element Polish (A3)
   ------------------------------------------------------------
   Token-driven, CSS-only refinements applied project-wide over
   the existing docsify DOM. No markdown changes. Loaded AFTER
   the theme/component CSS so these rules win where intended,
   while staying conservative (no !important unless required to
   override docsify defaults).

   Covers: tables, code blocks, sidebar active state, heading
   anchors, neutral blockquotes, and focus rings. Dark mode + RTL
   + responsive included.
   ============================================================ */

/* ---------- Tables: rounded container, sticky head, zebra ---------- */
.markdown-section table {
  display: table;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1.2rem 0;
  border: 1px solid var(--border-subtle, #e1e4e8);
  border-radius: var(--radius-md, 10px);
  overflow: hidden;
  font-size: 0.92rem;
}

.markdown-section table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background-color: var(--surface-3, #f6f8fa);
  color: var(--text-1, #1f2328);
  font-weight: 700;
  text-align: inherit;
  border-bottom: 1px solid var(--border-strong, #d0d7de);
}

.markdown-section table th,
.markdown-section table td {
  padding: 0.6rem 0.85rem;
  border: none;
  border-bottom: 1px solid var(--border-subtle, #e1e4e8);
}

.markdown-section table tbody tr:last-child td {
  border-bottom: none;
}

/* Zebra striping (override docsify's default even-row tint) */
.markdown-section table tbody tr:nth-child(2n) {
  background-color: var(--surface-2, #f9fafb);
}
.markdown-section table tbody tr {
  background-color: transparent;
}
.markdown-section table tbody tr:hover {
  background-color: var(--surface-hover, rgba(9, 105, 218, 0.06));
}

/* Mobile: horizontal scroll affordance via a wrapper that docsify lacks,
   so we make the table itself scroll within the content column. */
@media (max-width: 768px) {
  .markdown-section table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .markdown-section table thead th {
    position: static;
  }
}

/* ---------- Code blocks: unified radius/border ---------- */
.markdown-section pre {
  border-radius: var(--radius-md, 10px);
  border: 1px solid var(--border-subtle, #e1e4e8);
}

/* ---------- Neutral (non-callout) blockquotes ---------- */
.markdown-section blockquote:not(.callout) {
  border-left: 4px solid var(--border-strong, #d0d7de);
  background-color: var(--surface-3, #f6f8fa);
  color: var(--text-2, #57606a);
  border-radius: 0 var(--radius-sm, 6px) var(--radius-sm, 6px) 0;
  padding: 0.6rem 1rem;
}
html[dir="rtl"] .markdown-section blockquote:not(.callout) {
  border-left: none;
  border-right: 4px solid var(--border-strong, #d0d7de);
  border-radius: var(--radius-sm, 6px) 0 0 var(--radius-sm, 6px);
}

/* ---------- Sidebar active item emphasis ---------- */
.sidebar ul li.active > a {
  color: var(--accent, #0969da);
  font-weight: 700;
  background-color: var(--accent-soft, rgba(9, 105, 218, 0.08));
  border-radius: var(--radius-sm, 6px);
}
.sidebar ul li > a {
  border-radius: var(--radius-sm, 6px);
  transition: background-color var(--transition-fast, 0.15s ease),
    color var(--transition-fast, 0.15s ease);
}
.sidebar ul li > a:hover {
  background-color: var(--surface-hover, rgba(9, 105, 218, 0.06));
}

/* ---------- Heading anchors: hover # affordance + scroll offset ---------- */
.markdown-section h1,
.markdown-section h2,
.markdown-section h3,
.markdown-section h4 {
  scroll-margin-top: 70px;
}

/* NOTE: docsify wraps the entire heading TEXT inside `a.anchor`, so we must
   never hide the anchor (that would hide the heading text — which previously
   broke dark mode). Instead, reveal a subtle "#" affordance on hover via a
   pseudo-element, leaving the heading text fully visible at all times. */
.markdown-section h2 > .anchor,
.markdown-section h3 > .anchor,
.markdown-section h4 > .anchor {
  position: relative;
}
.markdown-section h2 > .anchor::before,
.markdown-section h3 > .anchor::before,
.markdown-section h4 > .anchor::before {
  content: "#";
  position: absolute;
  right: 100%;
  margin-right: 0.3rem;
  color: var(--accent, #0969da);
  opacity: 0;
  transition: opacity var(--transition-fast, 0.15s ease);
}
html[dir="rtl"] .markdown-section h2 > .anchor::before,
html[dir="rtl"] .markdown-section h3 > .anchor::before,
html[dir="rtl"] .markdown-section h4 > .anchor::before {
  right: auto;
  left: 100%;
  margin-right: 0;
  margin-left: 0.3rem;
}
.markdown-section h2:hover > .anchor::before,
.markdown-section h3:hover > .anchor::before,
.markdown-section h4:hover > .anchor::before {
  opacity: 0.6;
}

/* ---------- Accessible focus rings ---------- */
a:focus-visible,
button:focus-visible,
summary:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--border-focus, #0969da);
  outline-offset: 2px;
  border-radius: var(--radius-sm, 6px);
}

/* ---------- Reduced motion safety ---------- */
@media (prefers-reduced-motion: reduce) {
  .sidebar ul li > a,
  .markdown-section h2 > .anchor::before,
  .markdown-section h3 > .anchor::before,
  .markdown-section h4 > .anchor::before {
    transition: none;
  }
}

/* ============================================================
   Reading Aids (A4) — injected by js/plugins/docsify-reading-aids.js
   ============================================================ */

/* ---- Scroll progress bar ---- */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--reading-progress-height, 3px);
  background: transparent;
  z-index: 1200;
  pointer-events: none;
}
.reading-progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(
    90deg,
    var(--accent, #0969da),
    var(--info, #3b82f6)
  );
  transition: width 0.1s linear;
}
html[dir="rtl"] .reading-progress-fill {
  margin-left: auto;
}

/* ---- Back to top ---- */
.back-to-top {
  position: fixed;
  bottom: 1.75rem;
  right: 1.75rem;
  width: 2.85rem;
  height: 2.85rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill, 999px);
  border: 1px solid var(--border-subtle, #e1e4e8);
  background-color: var(--surface-2, #ffffff);
  color: var(--accent, #0969da);
  box-shadow: var(--shadow-md, 0 4px 14px rgba(9, 105, 218, 0.1));
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.92);
  transition: opacity var(--transition-fast, 0.15s ease),
    transform var(--transition-fast, 0.15s ease),
    visibility var(--transition-fast, 0.15s ease),
    border-color var(--transition-fast, 0.15s ease),
    background-color var(--transition-fast, 0.15s ease);
  z-index: 1100;
  -webkit-tap-highlight-color: transparent;
}
.back-to-top svg {
  display: block;
  width: 20px;
  height: 20px;
}
.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}
.back-to-top:hover {
  border-color: var(--accent, #0969da);
  background-color: var(--accent, #0969da);
  color: var(--accent-contrast, #ffffff);
  box-shadow: var(--shadow-lg, 0 10px 40px rgba(0, 0, 0, 0.12));
}
.back-to-top:active {
  transform: translateY(0) scale(0.94);
}
html[dir="rtl"] .back-to-top {
  right: auto;
  left: 1.75rem;
}

@media (prefers-reduced-motion: reduce) {
  .back-to-top,
  .reading-progress-fill {
    transition: none;
  }
}

/* ============================================================
   Motion & A11y Polish (A6)
   Subtle entrance for content + components on route change.
   Motion only runs when the user has NOT requested reduced motion.
   ============================================================ */
@media (prefers-reduced-motion: no-preference) {
  @keyframes doc-fade-in {
    from {
      opacity: 0;
      transform: translateY(6px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .markdown-section > .doc-hero,
  .markdown-section > .doc-card-grid,
  .markdown-section .pkg-grid,
  .markdown-section blockquote.callout,
  .markdown-section .responses-equivalent {
    animation: doc-fade-in 0.32s cubic-bezier(0.16, 1, 0.3, 1) both;
  }
}

/* ---------- Lead paragraph + at-a-glance card (A5 primitives) ---------- */
.doc-lead {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text-2, #57606a);
  margin: 0.25rem 0 1.5rem;
  padding-left: 1rem;
  border-left: 3px solid var(--accent, #0969da);
}
html[dir="rtl"] .doc-lead {
  border-left: none;
  border-right: 3px solid var(--accent, #0969da);
  padding-left: 0;
  padding-right: 1rem;
  font-family: var(--font-family-persian, "IRANSansX", "PT Sans", sans-serif);
}

.doc-at-a-glance {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0 1.75rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border-subtle, #e1e4e8);
  border-radius: var(--radius-md, 10px);
  background-color: var(--surface-2, #f9fafb);
}
.doc-at-a-glance .glance-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.doc-at-a-glance .glance-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-3, #8b949e);
}
.doc-at-a-glance .glance-value {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-1, #1f2328);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  word-break: break-word;
}
html[dir="rtl"] .doc-at-a-glance {
  font-family: var(--font-family-persian, "IRANSansX", "PT Sans", sans-serif);
}
