/*
 * Oveja Negra (Aarón) — mobile navbar and its drawer.
 *
 * Loaded last in the head, on top of the export. The export styles everything
 * inline, so anything competing with an inline declaration needs `!important`.
 * That is the cost of correcting a generated artifact from the outside, and it
 * beats editing the export by hand — the next publish re-extracts the folder
 * and would silently drop the edit.
 *
 * Structure of the nav, verified in the rendered DOM:
 *
 *   nav                      sticky, display:flex, flex-wrap:wrap
 *     > img                  the wordmark, with margin-right:auto
 *     > button               "Quién soy"   ┐ rendered by <sc-for>
 *     > button               "Mi chamba"   ┘
 *     > div.sc-host-x        display:contents — so the <a> inside it is the
 *         > a                real flex item, and the selector still has to go
 *                            through the wrapper
 *
 * The problem: the row needs 459px at 390px wide (logo 49 + tabs 117/122 + CTA
 * 120, plus gaps and padding), so it wraps — and because the logo carries
 * `margin-right:auto`, what lands on the second row is the CTA, alone, flush
 * left, looking like a mistake. At 320px it broke a third time and took
 * "Mi chamba" with it. Fitting all four in one row means 11px caps with the
 * tracking squeezed out and a tap target under 40px, which is worse.
 *
 * So below 600px the nav keeps only the wordmark and the three controls move
 * into a drawer. `demo.js` supplies the button and the <dialog>.
 */

/* ---- the hamburger ------------------------------------------------------ */

/* Hidden by default so the desktop row, which is untouched, never shows it —
   and so the button is invisible if demo.js fails to load rather than sitting
   there doing nothing. */
.demo-nav-toggle {
  display: none;
}

@media (max-width: 599px) {
  .demo-nav-toggle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    /* Fixed, over the sticky nav, which is z-index 60. */
    position: fixed;
    top: 5px;
    right: 8px;
    z-index: 70;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .demo-nav-toggle span {
    display: block;
    width: 22px;
    height: 2.5px;
    border-radius: 2px;
    background: var(--on-navy, #072d6b);
  }

  .demo-nav-toggle:focus-visible {
    outline: 2px solid var(--on-orange, #ff7c36);
    outline-offset: 2px;
  }

  /* The bar keeps the wordmark only. Right padding clears the 44px button so a
     long wordmark cannot slide under it. */
  nav {
    flex-wrap: nowrap !important;
    gap: 0 !important;
    padding: 8px 60px 8px clamp(12px, 4vw, 20px) !important;
  }

  nav > button,
  nav > .sc-host-x > a {
    display: none !important;
  }
}

/* ---- the drawer --------------------------------------------------------- */

/* A modal <dialog> is painted in the top layer, above every z-index on the
   page — which is why the hamburger cannot double as the close control: it
   sits under the backdrop, unreachable. The drawer carries its own. */
.demo-drawer {
  position: fixed;
  /* Pinned to the right edge, full height, instead of the centred box a dialog
     is by default. */
  inset: 0 0 0 auto;
  margin: 0;
  width: min(84vw, 320px);
  max-width: 100%;
  /* The UA stylesheet sizes a dialog to `fit-content`, which beats `inset: 0`
     on the block axis — without this the panel is only as tall as its items
     (270px against an 844px screen) and reads as a dropdown, not a drawer.
     dvh so the phone's collapsing address bar cannot leave a gap. */
  height: 100%;
  height: 100dvh;
  max-height: 100%;
  padding: 0;
  border: none;
  background: var(--on-white, #fff);
  color: var(--on-navy, #072d6b);
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: -18px 0 44px rgba(4, 25, 61, 0.22);
  /* Off-canvas until demo.js adds `is-in` on the frame after showModal(). The
     class is what animates, rather than @starting-style, so the transition does
     not depend on discrete-property animation support. */
  transform: translateX(100%);
  transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.demo-drawer.is-in {
  transform: translateX(0);
}

.demo-drawer::backdrop {
  background: rgba(4, 25, 61, 0);
  transition: background 260ms linear;
}

.demo-drawer.is-in::backdrop {
  background: rgba(4, 25, 61, 0.55);
}

.demo-drawer__head {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 8px 10px;
  border-bottom: 2px solid var(--on-navy-100, #dce6f6);
}

.demo-drawer__close {
  position: relative;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.demo-drawer__close span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 2.5px;
  margin: -1.25px 0 0 -11px;
  border-radius: 2px;
  background: var(--on-navy, #072d6b);
}

.demo-drawer__close span:nth-child(1) {
  transform: rotate(45deg);
}

.demo-drawer__close span:nth-child(2) {
  transform: rotate(-45deg);
}

.demo-drawer__close:focus-visible,
.demo-drawer__items > *:focus-visible {
  outline: 2px solid var(--on-orange, #ff7c36);
  outline-offset: 2px;
}

.demo-drawer__items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
}

/* The clones keep the export's inline styling, which is what carries the active
   tab's colours — only the box is restated here.

   `box-sizing` is not cosmetic: the design system's Button is `content-box`, a
   browser default the <button> tabs get and an <a> does not. Left alone,
   `width:100%` puts its 18px padding and 2px border *outside* the 100%, so the
   CTA renders wider than its column and hangs off the edge. */
.demo-drawer__items > button,
.demo-drawer__items > a {
  display: flex !important;
  box-sizing: border-box !important;
  align-items: center;
  justify-content: center;
  width: 100% !important;
  height: 48px !important;
}

@media (prefers-reduced-motion: reduce) {
  .demo-drawer,
  .demo-drawer::backdrop {
    transition: none;
  }
}

/* The page behind a modal dialog is inert but still scrollable. */
.demo-nav-open,
.demo-nav-open body {
  overflow: hidden;
}
