/*
 * Fase L — header + layout shell + content frame.
 *
 * Stripe-style top header (sticky, backdrop blur, subtle border) with
 * brand on the left, search trigger pill in the middle/right, locale +
 * theme toggles on the right. Mobile collapses search trigger and
 * surfaces a hamburger toggle for the sidebar.
 *
 * The shell is a grid `var(--sidebar-width) 1fr`. Below 768px the
 * sidebar becomes a slide-in panel (positioning kept here so the
 * old layout-functional.css can be removed in commit 6).
 */

/* ---------- Skip link (WCAG 2.4.1) ---------- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: var(--space-2) var(--space-4);
  background: var(--color-text);
  color: var(--color-bg);
  text-decoration: none;
  border-radius: 0 0 var(--radius-md) 0;
  z-index: 100;
  font-weight: var(--weight-medium);
}

.skip-link:focus {
  left: 0;
}

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: hsl(0 0% 100% / 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
  min-height: var(--header-height);
}

[data-theme="dark"] .site-header {
  background: hsl(228 16% 7% / 0.85);
}

.site-brand {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  text-decoration: none;
  color: var(--color-text);
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.site-brand:hover {
  color: var(--color-link);
}

/* Wordmark completo "Veriko" con franja azul + badge "Docs" al lado.
   El logo.svg fuente tiene el texto en blanco (para fondo oscuro); en el
   header claro usamos la variante de tinta oscura, y en modo oscuro
   volvemos al blanco original. La franja azul (#2f4f99) es igual en ambas. */
.site-wordmark {
  display: block;
  height: 1.4rem;
  aspect-ratio: 7017 / 2228; /* viewBox del logo */
  background: url("/assets/img/logo-wordmark-light.svg") no-repeat center / contain;
}

[data-theme="dark"] .site-wordmark {
  background-image: url("/assets/img/logo.svg");
}

.docs-badge {
  font-family: var(--font-display);
  font-size: 0.6875rem; /* 11px — más pequeño que --text-xs */
  font-weight: var(--weight-medium);
  letter-spacing: 0.02em;
  color: var(--color-text-muted);
  background: var(--color-bg-subtle);
  padding: 1px var(--space-1-5, 6px);
  border-radius: var(--radius-pill);
  line-height: 1.4;
}

/* Empuja los controles (idioma/tema/menú) al extremo derecho. */
.header-spacer {
  flex: 1;
}

/* ---------- Locale + theme toggles ---------- */
.locale-toggle,
.theme-toggle,
.download-menu-trigger {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  background: var(--color-bg-subtle);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.locale-toggle:hover,
.theme-toggle:hover,
.download-menu-trigger:hover {
  border-color: var(--color-border-strong);
  background: var(--color-bg-hover);
  color: var(--color-text);
}

/* ---------- Download menu ---------- */
/* Built on native <details>: trigger is the <summary>, panel is the
   sibling <div>. The list-style override hides the default disclosure
   triangle since the trigger already says "Download". */
.download-menu {
  position: relative;
}

.download-menu-trigger {
  cursor: pointer;
  list-style: none;
}

.download-menu-trigger::-webkit-details-marker {
  display: none;
}

.download-menu-trigger::marker {
  content: '';
}

.download-menu-trigger:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

.download-menu-panel {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 30;
  min-width: 14rem;
  padding: var(--space-2);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.download-menu-item {
  display: block;
  padding: var(--space-2) var(--space-3);
  text-decoration: none;
  color: var(--color-text);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}

.download-menu-item:hover,
.download-menu-item:focus-visible {
  background: var(--color-bg-hover);
  outline: none;
}

/* Theme toggle: show one glyph per mode */
.theme-toggle-light,
.theme-toggle-dark {
  font-size: var(--text-base);
  line-height: 1;
}

.theme-toggle .theme-toggle-dark {
  display: none;
}

[data-theme="dark"] .theme-toggle .theme-toggle-light {
  display: none;
}

[data-theme="dark"] .theme-toggle .theme-toggle-dark {
  display: inline;
}

/* ---------- Mobile menu toggle ---------- */
.mobile-menu-toggle {
  display: none;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font: inherit;
}

.mobile-menu-toggle:hover {
  background: var(--color-bg-hover);
  border-color: var(--color-border-strong);
}

/* ---------- Layout shell ---------- */
.layout-shell {
  display: grid;
  /* `minmax(0, 1fr)` (not `1fr`) so the content column can shrink below
     its min-content width. A plain `1fr` track grows to the widest
     non-wrapping child (a long URL / inline `code`), pushing the page
     past the viewport on narrow screens and triggering a zoom-out. */
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 80vh;
}

/* Changelog y otras secciones sin nav de referencia: contenido a ancho completo. */
.layout-shell--no-sidebar {
  grid-template-columns: minmax(0, 1fr);
}

.layout-sidebar {
  background: var(--color-bg-sidebar);
  border-right: 1px solid var(--color-sidebar-divider);
  padding: var(--space-5) var(--space-3);
  overflow-y: auto;
  max-height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
  align-self: start;
}

.layout-main {
  padding: var(--space-8);
  max-width: var(--content-max-width);
  width: 100%;
  /* Grid item must be allowed to shrink below its content's min-content
     so wide children scroll/wrap inside it instead of widening the page. */
  min-width: 0;
  margin: 0 auto;
}

/* Concept pages opt into a tighter prose width for reading comfort */
.layout-main .prose-section,
.layout-main.is-prose {
  max-width: var(--content-max-width-prose);
}

/* ---------- Mobile (<=768px) ---------- */
@media (max-width: 768px) {
  .site-header {
    padding: var(--space-3) var(--space-4);
    gap: var(--space-2);
  }

  .layout-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .layout-sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    max-height: 100vh;
    background: var(--color-bg-sidebar);
    z-index: 20;
    box-shadow: var(--shadow-lg);
  }

  .layout-sidebar.open {
    display: block;
  }

  .mobile-menu-toggle {
    display: inline-flex;
    align-items: center;
  }

  .locale-toggle {
    margin-left: 0;
  }

  /* On phones the trigger keeps the arrow glyph but drops the
     "Download" word so the header doesn't wrap. */
  .download-menu-trigger-label {
    display: none;
  }

  .layout-main {
    padding: var(--space-4);
  }
}

/* ---------- Mobile sidebar: backdrop overlay + close header ---------- */
/* Desktop never shows these — the sidebar is a permanent column there. */
.sidebar-overlay,
.sidebar-mobile-header {
  display: none;
}

.sidebar-close {
  background: transparent;
  border: 0;
  color: var(--color-sidebar-text);
  font-size: 1.6rem;
  line-height: 1;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.sidebar-close:hover {
  color: var(--color-sidebar-text-active);
  background: var(--color-sidebar-item-hover);
}

@media (max-width: 768px) {
  /* Backdrop behind the slid-in panel; tapping it closes (JS). Sits just
     under the sidebar (z-index 20) and above the page content. */
  .sidebar-overlay:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 19;
  }

  /* Sticky header inside the dark panel with the close (X) on the right.
     Negative margins cancel the aside's padding so it spans full width
     and sits flush at the top. */
  .sidebar-mobile-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1;
    margin: calc(var(--space-5) * -1) calc(var(--space-3) * -1) var(--space-3);
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg-sidebar);
    border-bottom: 1px solid var(--color-sidebar-divider);
  }
}

/* ── Floating "back to top" control ───────────────────────────────────────
   Global FAB on every docs page (API + changelog). Hidden until the shell
   script adds .is-visible past the scroll threshold. */
.scroll-top {
  position: fixed;
  right: var(--space-5, 1.5rem);
  bottom: var(--space-5, 1.5rem);
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--color-link, #294385);
  color: #fff;
  box-shadow: var(--shadow-lg, 0 12px 32px rgba(0, 0, 0, 0.18));
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, background-color 0.15s ease;
}

.scroll-top.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.scroll-top:hover {
  background: var(--color-link-hover, #25386b);
}

.scroll-top:focus-visible {
  outline: 2px solid var(--color-link, #294385);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .scroll-top {
    transition: opacity 0.18s ease;
    transform: none;
  }
}
