/* =========================
   Speed Reader AI — Docs UI
   Inspired by OpenAI Docs layout
   ========================= */

/* Base */
body.docs-body {
  margin: 0;
  background: #0f1117; /* deep neutral */
  color: #e5e7eb; /* light gray text */
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Ensure no horizontal overflow on small screens */
html, body.docs-body { max-width: 100%; overflow-x: hidden; }

/* Links */
.docs-body a {
  color: #8ab4ff;
  text-decoration: none;
}
.docs-body a:hover {
  text-decoration: underline;
}

/* Topbar */
.docs-topbar {
  position: fixed;      /* keep visible while scrolling */
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: 56px;
  background: #0f1117;
  border-bottom: 1px solid #1f2330;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
}
.docs-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: #e5e7eb;
}
.docs-brand__logo {
  display: inline-flex;
  width: 24px;
  height: 24px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: linear-gradient(135deg, #667eea, #764ba2);
}
.docs-topbar__link {
  color: #cbd5e1;
  padding: 6px 10px;
  border-radius: 8px;
}
.docs-topbar__link:hover {
  background: #1a1f2b;
  text-decoration: none;
}
.docs-topbar__left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.docs-topbar__right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.docs-topbar__toggle {
  display: none;
  background: #1a1f2b;
  color: #e5e7eb;
  border: 1px solid #2a3040;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

/* Layout */
.docs-layout {
  display: flex;
  min-height: calc(100vh - 56px);
  min-width: 0;           /* allow flex children to shrink */
  overflow-x: hidden;     /* prevent flex overflow from causing page scroll */
  padding-top: 56px;      /* account for fixed topbar */
}

/* Sidebar */
.data-sidebar {
  width: 280px;
  background: #0b0d12;
  border-right: 1px solid #1f2330;
  padding: 12px 12px 24px;
  position: sticky;
  top: 56px; /* beneath topbar */
  height: calc(100vh - 56px);
  overflow: auto;
}
.sidebar-search {
  position: sticky;
  top: 0;
  background: #0b0d12;
  padding-bottom: 8px;
  margin-bottom: 8px;
  z-index: 1;
}
.sidebar-search input {
  width: 100%;
  height: 36px;
  border-radius: 8px;
  border: 1px solid #293042;
  background: #0f1320;
  color: #e5e7eb;
  padding: 0 10px;
  outline: none;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sidebar-section__title {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
  margin: 8px 6px;
}
.sidebar-link {
  display: block;
  padding: 8px 10px;
  margin: 2px 0;
  border-radius: 8px;
  color: #cbd5e1;
  text-decoration: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.sidebar-link:hover {
  background: #111827;
  color: #e5e7eb;
}
.sidebar-link.active {
  background: linear-gradient(
    135deg,
    rgba(102, 126, 234, 0.25),
    rgba(118, 75, 162, 0.25)
  );
  border: 1px solid rgba(118, 75, 162, 0.35);
  color: #ffffff;
}

/* Main page body */
.page-body {
  flex: 1;
  padding: 24px 32px;
  min-width: 0;          /* critical for flex child to avoid overflow */
}
.page-body.full-width .docs-article {
  max-width: 960px;
  margin: 0 auto;
}
.page-body.flush {
  padding-left: 32px;
  padding-right: 32px;
}

/* Article content */
.docs-article {
  line-height: 1.65;
  /* Allow long URLs/terms to wrap on narrow screens to prevent horizontal scroll */
  word-break: break-word;
  overflow-wrap: anywhere;
}
.docs-article .lead {
  font-size: 1.05rem;
  color: #c7d2fe;
}
.docs-article h1 {
  font-size: 2rem;
  margin: 8px 0 12px 0;
}
.docs-article h2 {
  font-size: 1.4rem;
  margin: 28px 0 10px 0;
  color: #ffffff;
}
.docs-article h3,
.docs-article h4 {
  margin: 18px 0 8px 0;
  color: #e5e7eb;
}
.docs-article p,
.docs-article ul,
.docs-article ol {
  color: #d1d5db;
  margin: 8px 0 12px 0;
}
.docs-article ul,
.docs-article ol {
  padding-left: 20px;
}
.docs-article hr {
  border: none;
  border-top: 1px solid #23293a;
  margin: 28px 0;
}

/* Responsive media within article */
.docs-article img,
.docs-article video,
.docs-article iframe {
  max-width: 100%;
  height: auto;
  display: block;
}
/* Anchor offset for sticky topbar */
.docs-article [id] {
  scroll-margin-top: 72px;
}

/* Grid */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 900px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* Callouts and notes */
.callout {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 12px;
  border: 1px solid #2b3350;
  background: #0f1320;
  padding: 12px 14px;
  border-radius: 12px;
  color: #d1d5db;
}
.callout__icon {
  font-size: 18px;
  line-height: 28px;
}
/* Notes do not use a left icon column – render as a single column block */
.note {
  display: block;
  border: 1px dashed #2b3350;
  background: #0f1320;
  padding: 12px 14px;
  border-radius: 12px;
  color: #d1d5db;
  opacity: 0.95;
}

/* Code blocks */
pre.code,
pre > code {
  display: block;
  background: #0b1220;
  color: #e5e7eb;
  border: 1px solid #28314a;
  border-radius: 12px;
  padding: 14px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.5;
}

/* Tables */
.docs-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #0f1320;
  border: 1px solid #28314a;
  border-radius: 12px;
  overflow: hidden;
  margin: 12px 0 18px 0;
  font-size: 13px;
}
.docs-table thead th {
  text-align: left;
  background: #0b1220;
  color: #cbd5e1;
  padding: 10px 12px;
  border-bottom: 1px solid #28314a;
  font-weight: 600;
}
.docs-table tbody td {
  padding: 10px 12px;
  color: #d1d5db;
  border-top: 1px solid #1f2330;
  vertical-align: top;
}
.docs-table tbody tr:nth-child(odd) {
  background: #0f121d;
}
.docs-table code {
  background: transparent;
  color: #c7d2fe;
}
@media (max-width: 720px) {
  .docs-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* Footer */
.docs-footer {
  border-top: 1px solid #1f2330;
  margin-top: 40px;
  padding: 18px 0 40px;
  color: #9aa4b2;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.docs-footer__links a {
  margin-left: 10px;
}

/* Mobile sidebar behavior */
@media (max-width: 1080px) {
  .docs-topbar__toggle {
    display: inline-flex;
  }
  .data-sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    transform: translateX(-100%);      /* off‑canvas without extending page width */
    height: calc(100vh - 56px);
    width: min(80vw, 320px);
    max-width: 320px;
    transition: transform 0.25s ease;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    z-index: 1100;
    will-change: transform;
  }
  .data-sidebar.open {
    transform: translateX(0);
  }
  body.docs-body.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
  }
  .page-body {
    padding: 20px;
  }
}

/* Desktop: keep sidebar visible and shift content right */
@media (min-width: 1081px) {
  .data-sidebar {
    position: fixed;
    left: 0;
    top: 56px;
    bottom: 0;
    height: auto;
    overflow: auto;
  }
  .page-body {
    margin-left: 280px;   /* match sidebar width */
  }
}

/* Utility */
.hidden {
  display: none !important;
}

/* ===== Mobile / Thin layout tweaks ===== */

/* Compact typography and paddings on tablets */
@media (max-width: 900px) {
  .page-body {
    padding: 16px 18px;
  }
  .docs-article h1 { font-size: 1.8rem; margin: 6px 0 10px; }
  .docs-article h2 { font-size: 1.25rem; margin: 22px 0 8px; }
  .docs-article p,
  .docs-article ul,
  .docs-article ol { font-size: 0.97rem; }
  .callout, .note { padding: 10px 12px; }
  pre.code, pre > code { font-size: 12px; padding: 12px; }
  .docs-table { font-size: 12px; }
  .docs-footer { flex-direction: column; gap: 6px; }
}

/* Phone width optimizations */
@media (max-width: 600px) {
  /* Top bar compaction */
  .docs-topbar { padding: 0 8px; height: 52px; }
  .docs-topbar__left { gap: 6px; }
  .docs-topbar__right { gap: 4px; }
  .docs-topbar__link { padding: 4px 8px; font-size: 12px; }
  .docs-brand__logo { width: 22px; height: 22px; }
  .docs-brand__name { font-size: 14px; }

  /* Hide reference link on very small widths to avoid wrapping */
  .docs-topbar__right .docs-topbar__link:last-child { display: none; }

  .page-body { padding: 14px; }
  .docs-article { line-height: 1.55; }
  .docs-article .lead { font-size: 0.98rem; }
  .docs-article h1 { font-size: 1.6rem; }
  .docs-article h2 { font-size: 1.15rem; }
  .docs-article h3 { font-size: 1.0rem; }
  .docs-article ul, .docs-article ol { padding-left: 18px; }
  .grid-2 { grid-template-columns: 1fr; gap: 12px; }

  /* Callouts: tighter grid */
  .callout, .note {
    grid-template-columns: 22px 1fr;
    padding: 10px 12px;
    border-radius: 10px;
  }
  .callout__icon { font-size: 16px; line-height: 22px; }

  /* Tables already scroll; add softer padding on cells */
  .docs-table thead th, .docs-table tbody td { padding: 8px 10px; }

  /* Search suggestions sizing */
  .sidebar-search-results { top: 40px; }
}

/* Ultra-narrow phones */
@media (max-width: 420px) {
  /* Hide long brand text, keep logo only */
  .docs-brand__name { display: none; }

  .docs-topbar { padding: 0 6px; }
  .page-body { padding: 12px; }
  .docs-article h1 { font-size: 1.45rem; }
  .docs-article h2 { font-size: 1.08rem; }
  .docs-article p, .docs-article ul, .docs-article ol { font-size: 0.95rem; }
  .callout, .note { padding: 8px 10px; }
  pre.code, pre > code { font-size: 11.5px; padding: 10px; }
}

/* Search suggestions dropdown */
.sidebar-search {
  position: sticky; /* already sticky, ensures positioned ancestor */
}
.sidebar-search-results {
  display: none;
  position: absolute;
  top: 44px; /* below the input */
  left: 0;
  right: 0;
  background: #0f1320;
  border: 1px solid #293042;
  border-radius: 10px;
  box-shadow: 0 18px 40px rgba(0,0,0,.45);
  max-height: 50vh;
  overflow: auto;
  padding: 6px;
  z-index: 5;
}
.sidebar-search-results.visible {
  display: block;
}
.sidebar-search-results .result-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: #e5e7eb;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
  font-size: 13px;
}
.sidebar-search-results .result-item:hover {
  background: #111827;
}
.sidebar-search-results .result-item .result-section {
  font-size: 11px;
  color: #94a3b8;
  opacity: 0.85;
}

/* Target highlight when navigating via search/links */
.target-highlight {
  outline: 2px solid rgba(118,75,162,.6);
  background: linear-gradient(135deg, rgba(102,126,234,.10), rgba(118,75,162,.10));
  border-radius: 6px;
  animation: targetFlash 1.6s ease;
}
@keyframes targetFlash {
  0%   { box-shadow: 0 0 0 0 rgba(102,126,234,.0); }
  35%  { box-shadow: 0 0 0 8px rgba(102,126,234,.18); }
  100% { box-shadow: 0 0 0 0 rgba(102,126,234,.0); }
}
