/* ---------------------------------------------------------------------
   Responsive / zoom fixes
   Targets WCAG 2.1 SC 1.4.4 Resize Text and SC 1.4.10 Reflow.

   The application must retain all content and functionality when the
   viewport becomes narrow as a result of browser zoom or resizing.
------------------------------------------------------------------------ */

.site-header { overflow: visible; }

.doc-content,
.content-col,
.breadcrumbs,
.page-nav,
.toc-col {
  min-width: 0;
  max-width: 100%;
}

.doc-content img,
.doc-content video,
.doc-content iframe,
.doc-content canvas,
.doc-content svg,
.doc-content audio {
  max-width: 100%;
}

.doc-content pre {
  max-width: 100%;
  overflow-x: auto;
}

.doc-content p,
.doc-content li,
.doc-content td,
.doc-content th,
.doc-content a,
.doc-content code,
.doc-content pre {
  overflow-wrap: anywhere;
  word-break: normal;
}

.header-search.search-box { min-width: 0; }

.search-results {
  max-width: min(36rem, calc(100vw - 1rem));
  max-height: min(60vh, 28rem);
  overflow-x: hidden;
  overflow-y: auto;
}

/* ---------------------------------------------------------------------
   Interactive control borders

   All buttons and input fields use a border color with at least 3:1
   contrast against the adjacent surface in both light and dark themes.
------------------------------------------------------------------------ */

button,
input,
select,
textarea,
.search-input,
.icon-btn,
.tree-toggle {
  border: 1px solid var(--control-border);
}

/* ---------------------------------------------------------------------
   Brand logo
------------------------------------------------------------------------ */

.brand-logo {
  display: block;
  width: 112px;
  height: 45px;
  max-width: 100%;
  object-fit: contain;
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------
   Narrow viewport / high zoom layout
------------------------------------------------------------------------ */

@media (max-width: 700px) {
  :root { --header-h: 96px; }

  .site-header {
    height: var(--header-h);
    min-height: var(--header-h);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: minmax(40px, auto) minmax(36px, auto);
    align-items: center;
    gap: 0.35rem 0.5rem;
    padding: 0.5rem 0.75rem;
    overflow: visible;
  }

  .nav-toggle { display: inline-flex; grid-column: 1; grid-row: 1; }

  .brand {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    width: auto;
    max-width: 100%;
    white-space: normal;
    line-height: 1.15;
    overflow: visible;
  }

  .brand > span:not(.brand-mark) {
    display: block;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .header-actions {
    grid-column: 3;
    grid-row: 1;
    margin-left: 0;
  }

  .header-search {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    max-width: none;
    min-width: 0;
    margin: 0;
  }

  .search-input { width: 100%; min-width: 0; }
  .search-results { left: 0; right: 0; width: 100%; max-width: none; }

  .brand-logo {
    width: 96px;
    height: 38px;
  }

  .content-col {
    width: 100%;
    padding: 1.25rem 1rem 4rem;
    overflow: visible;
  }

  .doc-content { width: 100%; max-width: none; }
  .page-nav { width: 100%; }
  .page-nav a { min-width: 0; max-width: 100%; }
}

@media (max-width: 360px) {
  :root { --header-h: 96px; }

  .site-header { padding: 0.45rem 0.5rem; gap: 0.3rem 0.35rem; }
  .brand { gap: 0.35rem; font-size: var(--step--1); }
  .brand-mark { width: 24px; height: 24px; font-size: 0.68rem; }
  .brand-logo { width: 82px; height: 34px; }
  .icon-btn { padding: 0.3rem 0.4rem; }
  .content-col { padding: 1rem 0.75rem 3rem; }
  .breadcrumbs { width: 100%; }
  .doc-content h1 { max-width: 100%; }
  .doc-content ul, .doc-content ol { padding-left: 1.2rem; }
  .page-nav { flex-direction: column; gap: 0.75rem; }
  .page-nav a { width: 100%; }
}

/* ---------------------------------------------------------------------
   High-zoom / narrow layout

   router.js moves the TOC into #doc-content immediately after the H1.
   Keeping the TOC in the document flow here gives the user this order:
   Breadcrumbs -> H1 -> On this page -> page content.
------------------------------------------------------------------------ */
@media (max-width: 1100px) {
  .site-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .toc-col {
    display: block;
    position: static;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: none;
    overflow: visible;
    margin: 0 0 2rem;
    padding: 1.25rem 0 1.5rem;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }

  .toc-col ul { max-width: 100%; }
}

@media (max-width: 820px) {
  .sidebar { width: min(85vw, 320px); max-width: 100vw; }
  .toc-col { padding: 1rem 0 1.5rem; }
}

@media (max-width: 360px) {
  .toc-col { padding: 1rem 0 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
