/**
 * THE CHROME ENGINE — one header, one footer, every site.
 *
 * Single source of truth for the frame around my.maibot.io (Next.js) and
 * brain.maibot.io (static generator). Both import THIS file; neither carries
 * its own copy of these rules. The markup contract is the class names below —
 * the portal renders them from React, the docs site from chrome.mjs — and each
 * site supplies its OWN menu items; the engine only owns how they look.
 *
 * Everything is written on the token layer (--bg-panel, --accent, --human…),
 * so the chrome re-skins with whatever token set the page defines. Assets are
 * expected at /brand-mark.png and /brand/{sb-lockup.png,mh-lockup.png,
 * maibot.svg} on BOTH origins.
 */

/* ── header ────────────────────────────────────────────────────────────────── */
.ui-header {
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-panel);
  position: sticky;
  top: 0;
  z-index: 20;
}
/* Glass: the page scrolls through a frosted header. Solid stays the fallback
   for engines without backdrop-filter, so text never floats over raw content. */
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .ui-header {
    background: color-mix(in srgb, var(--bg-panel) 72%, transparent);
    -webkit-backdrop-filter: blur(14px) saturate(1.15);
    backdrop-filter: blur(14px) saturate(1.15);
  }
}
.ui-header-inner {
  max-width: var(--page-max, 72rem);
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ui-wordmark {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  white-space: nowrap;
  text-decoration: none;
}
.ui-wordmark:hover {
  text-decoration: none;
}
.ui-wordmark-ai {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.88em;
  letter-spacing: 0.02em;
  color: var(--accent);
}
/* The circuit-tree mark: a white alpha mask filled with the accent, so every
   skin re-tints it without a second asset. */
.ui-brand-mark {
  display: inline-block;
  width: 1.25em;
  height: 1.25em;
  flex: none;
  vertical-align: -0.28em;
  margin-right: 0.45em;
  background: var(--accent);
  -webkit-mask-image: url(/brand-mark.png);
  mask-image: url(/brand-mark.png);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

/* The push: lets the burger sit at the header's far edge on string sites that
   have no layout system of their own. The portal defines the same class. */
.ui-spacer { flex: 1; }

/* Each site's OWN menu rides here — the engine styles it, never fills it. */
.ui-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
  flex: 1;
}
.ui-nav-link {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  white-space: nowrap;
  text-decoration: none;
  transition: color 0.25s var(--ease), background 0.25s var(--ease);
}
.ui-nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
  text-decoration: none;
}
.ui-nav-link[aria-current="page"],
.ui-nav-link.active {
  color: var(--accent-text);
  background: var(--accent-muted);
}

/* The header's one call-to-action pill (Distributors on the portal, Portal on
   the docs site) — self-contained so sites without a button system can use it. */
.ui-chrome-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border-default);
  background: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.25s var(--ease), color 0.25s var(--ease);
}
.ui-chrome-btn:hover {
  border-color: var(--accent-ring);
  color: var(--text-primary);
  text-decoration: none;
}

/* F1 (legacy, non-rail sites): on phones the nav becomes ONE scrollable chip
   row under the brand line. Rail sites (body.has-rail) replace this with the
   drawer below. F5: targets grow to thumb size at the same breakpoint. */
@media (max-width: 640px) {
  .ui-header-inner {
    flex-wrap: wrap;
    row-gap: 0.25rem;
    gap: 0.5rem;
  }
  body:not(.has-rail) .ui-nav {
    order: 10;
    flex: 1 1 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    margin: 0 -1rem;
    padding: 0 1rem 0.25rem;
  }
  body:not(.has-rail) .ui-nav::-webkit-scrollbar { display: none; }
  .ui-nav-link {
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
  }
  .ui-chrome-btn {
    padding: 0.5rem 0.85rem;
  }
  /* the toggle and the two selects ride in the brand row — same thumb rule */
  .ui-header-inner button,
  .ui-header-inner select {
    min-height: 2.5rem;
  }
}

/* ── the rail: the winner layout, promoted to chrome ───────────────────────────
 * Ruled 2026-08-09: vertical rail menus — the Community layout, the one every
 * winner shipped application uses — are the portal's direction. Desktop nav is
 * a fixed left rail: wordmark on top, the site's own menu as full-width rows,
 * the CTA pill and the site's tools on the floor. The header stays as MOBILE
 * chrome only, where a hamburger opens the drawer. A site opts in by putting
 * class="has-rail" on <body> and a .ui-rail in its markup — sites without it
 * keep the classic header untouched.
 */
.ui-rail { display: none; }

@media (min-width: 981px) {
  body.has-rail { padding-left: 14.5rem; }
  /* The rail IS the chrome here — two nav homes would be noise. */
  body.has-rail .ui-header { display: none; }

  .ui-rail {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 14.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1.1rem 0.85rem 1rem;
    border-right: 1px solid var(--border-subtle);
    background: var(--bg-panel);
    overflow-y: auto;
    z-index: 20;
  }
  /* Same glass as the header it replaces: the page scrolls through it. */
  @supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .ui-rail {
      background: color-mix(in srgb, var(--bg-panel) 72%, transparent);
      -webkit-backdrop-filter: blur(14px) saturate(1.15);
      backdrop-filter: blur(14px) saturate(1.15);
    }
  }
  .ui-rail .ui-wordmark {
    font-size: 1.1rem;
    padding: 0.15rem 0.65rem 0.85rem;
  }
  .ui-rail .ui-nav {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 0.15rem;
    flex: 0 0 auto;
  }
  .ui-rail .ui-nav-link {
    display: flex;
    align-items: center;
    font-size: 0.95rem;
    padding: 0.55rem 0.9rem;
  }
}

/* ── collapse: the rail folds away on request ─────────────────────────────────
 * The chevron reveals itself when the pointer is already on the rail (or via
 * keyboard focus); collapsing slides the rail off-canvas, hands the page the
 * full width, and leaves one floating pill to bring it back. The choice rides
 * html[data-rail] so the pre-paint boot script can apply it before first
 * paint — same trick as the skin. Desktop-only: mobile has the drawer.
 */
.ui-rail-collapse {
  position: absolute;
  top: 0.9rem;
  right: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0.2rem 0.5rem;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.25s var(--ease), background 0.25s var(--ease), color 0.25s var(--ease);
}
.ui-rail-collapse:hover { background: var(--bg-hover); color: var(--text-primary); }
.ui-rail:hover .ui-rail-collapse,
.ui-rail-collapse:focus-visible {
  opacity: 1;
}
.ui-rail-expand { display: none; }

@media (min-width: 981px) {
  html[data-rail="collapsed"] body.has-rail { padding-left: 0; }
  html[data-rail="collapsed"] .ui-rail {
    transform: translateX(-100%);
    visibility: hidden;
  }
  html[data-rail="collapsed"] .ui-rail-expand {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    /* UNDER the rail (20): while the peek is out, the rail covers the pill and
       the pointer is already on the rail, which is what keeps the peek open. */
    z-index: 19;
    min-width: 2.5rem;
    min-height: 2.5rem;
    padding: 0.25rem 0.6rem;
    border: 1px solid var(--border-default);
    border-radius: 999px;
    background: var(--bg-panel);
    color: var(--text-secondary);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.25s var(--ease), color 0.25s var(--ease);
  }
  html[data-rail="collapsed"] .ui-rail-expand:hover {
    border-color: var(--accent-ring);
    color: var(--text-primary);
  }
  /* The peek: hovering (or focusing) the pill slides the rail back in OVER the
     content — the page keeps its full width — and the rail's own hover holds
     it while the visitor navigates. Leaving lets it fold again; clicking the
     pill still pins it open. Collapsed is a posture, not a dead end. */
  html[data-rail="collapsed"] body:has(.ui-rail-expand:hover) .ui-rail,
  html[data-rail="collapsed"] body:has(.ui-rail-expand:focus-visible) .ui-rail,
  html[data-rail="collapsed"] .ui-rail:hover,
  html[data-rail="collapsed"] .ui-rail:focus-within {
    transform: none;
    visibility: visible;
    box-shadow: 0 12px 40px rgb(0 0 0 / 0.35);
  }
  @media (prefers-reduced-motion: no-preference) {
    .ui-rail {
      transition: transform 0.25s var(--ease), visibility 0.25s var(--ease);
    }
    body.has-rail { transition: padding-left 0.25s var(--ease); }
  }
}

/* The rail's floor: CTA above tools, pinned to the bottom like the community
   user chip. Reused inside the drawer, where the flow order does the pinning. */
.ui-rail-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.6rem;
  padding: 0.6rem 0.65rem 0;
}
.ui-rail-foot .ui-chrome-btn { justify-content: center; }
.ui-rail-tools {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── the hamburger and the drawer: mobile nav for rail sites ────────────────── */
.ui-burger {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0.25rem 0.6rem;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--text-secondary);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.25s var(--ease), color 0.25s var(--ease);
}
.ui-burger:hover { background: var(--bg-hover); color: var(--text-primary); }

.ui-drawer-back {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.45);
  border: 0;
  padding: 0;
  z-index: 29;
}
.ui-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(19rem, 85vw);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.9rem 0.85rem 1.1rem;
  border-left: 1px solid var(--border-subtle);
  background: var(--bg-panel);
  overflow-y: auto;
  z-index: 30;
}
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .ui-drawer {
    background: color-mix(in srgb, var(--bg-panel) 88%, transparent);
    -webkit-backdrop-filter: blur(18px) saturate(1.15);
    backdrop-filter: blur(18px) saturate(1.15);
  }
}
@media (prefers-reduced-motion: no-preference) {
  .ui-drawer { animation: ui-drawer-in 0.22s var(--ease); }
  @keyframes ui-drawer-in {
    from { transform: translateX(1.5rem); opacity: 0; }
    to { transform: none; opacity: 1; }
  }
}
/* The drawer's own top row: a close affordance where the thumb already is. */
.ui-drawer-top {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 2.5rem;
}
.ui-drawer .ui-nav {
  flex-direction: column;
  align-items: stretch;
  flex-wrap: nowrap;
  gap: 0.15rem;
  flex: 0 0 auto;
}
.ui-drawer .ui-nav-link {
  display: flex;
  align-items: center;
  font-size: 1rem;
  padding: 0.7rem 0.9rem;
}
.ui-drawer[hidden], .ui-drawer-back[hidden] { display: none; }

@media (max-width: 980px) {
  /* Rail sites: the header slims to wordmark + burger; nav lives in the drawer. */
  body.has-rail .ui-header .ui-nav { display: none; }
  body.has-rail .ui-burger { display: inline-flex; }
}
@media (min-width: 981px) {
  /* A drawer left open across a resize must not haunt the desktop. */
  .ui-drawer, .ui-drawer-back { display: none; }
}

/* ── footer ────────────────────────────────────────────────────────────────── */
.ui-footer {
  border-top: 1px solid var(--border-subtle);
  padding: 1.5rem 1rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-faint);
}
.ui-footer-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1.25rem;
}
.ui-footer-nav a {
  color: var(--text-muted);
  text-decoration: none;
}
.ui-footer-nav a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* The three houses: product, series, company — one ink, masked artwork. */
.ui-footer-brands {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-subtle);
}
.ui-lockup {
  display: inline-block;
  background: var(--text-secondary);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}
/* Product and series artwork is 4:1; the company mark is 3.5:1. */
.ui-lockup--sb { height: 2.1rem; width: 8.4rem; -webkit-mask-image: url(/brand/sb-lockup.png); mask-image: url(/brand/sb-lockup.png); }
.ui-lockup--mh { height: 2.1rem; width: 8.4rem; -webkit-mask-image: url(/brand/mh-lockup.png); mask-image: url(/brand/mh-lockup.png); }
.ui-lockup--maibot { height: 1.8rem; width: 6.3rem; -webkit-mask-image: url(/brand/maibot.svg); mask-image: url(/brand/maibot.svg); }

.ui-footer-legal {
  margin-top: 0.75rem;
}
.ui-footer-legal p {
  margin: 0.2rem 0;
}

/* The long read ends with a hand back to the start. */
.ui-totop {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  margin-top: 1.25rem;
  padding: 0.5rem 1.15rem;
  border-radius: 999px;
  border: 1px solid var(--border-default);
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.25s var(--ease), color 0.25s var(--ease), transform 0.25s var(--ease);
}
.ui-totop::before {
  content: "↑";
  color: var(--accent);
}
.ui-totop:hover {
  border-color: var(--accent-ring);
  color: var(--text-primary);
  transform: translateY(-2px);
}
