/* ------------------------------------------------------------------------
 * Tabs — the underline nav for page navigation and the setup guide.
 *
 * The drawing (approved export, Tabs section): a row of labels on a 1px
 * --kl-border rule, no track; the selected label carries a 2px --kl-text bar
 * under it, as wide as the word. Values are the export's measured ones:
 *
 *   nav     gap 30 · tab 54 high on a pointer; 50 / 24 on an iPad-sized touch
 *           screen; 46 / 22 on a phone
 *   tab     15 / 500, --kl-muted; hover and selected --kl-text, 600 selected
 *   rule    2px, radius 2, bottom -1px so it lands on the nav's own 1px rule
 *
 * The export keys its three drawings off [data-device], which this package does
 * not have. Touch is one drawing here, so its iPad step is the coarse pointer
 * at a tablet width — the same rule ChatInput uses for its iPad radius.
 * ------------------------------------------------------------------------ */
.ktabs {
  display: flex;
  gap: var(--ktabs-gap, 30px);
  box-sizing: border-box;
  width: 100%;
  border-bottom: 1px solid var(--kl-border);
  /* More tabs than fit (a phone, a long label) scroll inside the nav, the
   * way a wide segmented track does, instead of being clipped away: every
   * tab stays reachable by touch and by keyboard. The 1px click overshoot of
   * the selected rule is clipped vertically, as the drawing clips it, so no
   * scrollbar appears and the divider on the nav's own border box — outside
   * the scroll box — stays visible at every scroll offset. */
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
}
.ktab {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  height: var(--ktabs-tab-h, 54px);
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-family: inherit;
  font-style: normal;
  font-size: 15px;
  font-weight: 500;
  line-height: normal;
  letter-spacing: normal;
  text-transform: none;
  white-space: nowrap;
  color: var(--kl-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ktab:hover,
.ktab[data-state="selected"] { color: var(--kl-text); }
.ktab[data-state="selected"] { font-weight: 600; }
/* The nav clips the rule's 1px overshoot, so the ring sits inside the tab:
 * an outside ring would be cut at the nav's top edge. */
.ktab:focus-visible { outline: 2px solid var(--kl-accent); outline-offset: -2px; }
/* The rule: a pseudo-element, so the tab's markup is its label. Same ink
 * as the text (`currentColor`), which is what the export draws. */
.ktab::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: transparent;
}
.ktab[data-state="selected"]::after { background: currentColor; }

.ktabs-panel { margin-top: 16px; }
.ktabs-panel:focus-visible { outline: 2px solid var(--kl-accent); outline-offset: 2px; }

@media (any-pointer: coarse) {
  .ktabs { --ktabs-gap: 22px; --ktabs-tab-h: 46px; }
}
/* The drawing's iPad step sits between the pointer and phone ones. */
@media (any-pointer: coarse) and (min-width: 700px) {
  .ktabs { --ktabs-gap: 24px; --ktabs-tab-h: 50px; }
}
  /* TabNav — the same row of labels, as page navigation (real links), with the
   * selected pill of the segmented control instead of the underline.
   *
   * --ktabnav-h is the link's tap box and the bar's drawn height (a host may
   * pin its own; 44px is the HIG floor). The pill is that height minus 12px, so
   * the fill keeps an equal 6px gap to both edges of its box and never touches
   * a rule above or below it — the box is the target, the pill is the drawing. */
.ktabnav {
  --ktabnav-pill: calc(var(--ktabnav-h, 44px) - 12px);
  display: flex;
  align-items: center;
  height: var(--ktabnav-h, 44px);
  min-height: var(--ktabnav-h, 44px);
  border-bottom: 0;
  gap: 0 var(--ktabs-gap, 30px);
}
.ktabnav .ktab {
  /* Own stacking context, so the pill can sit behind the label: an absolutely
   * positioned pseudo-element paints above in-flow text otherwise, and a solid
   * fill would erase the selected label. */
  isolation: isolate;
  height: var(--ktabnav-h, 44px);
  /* The pill's horizontal padding: the fill is wider than the word by 12px
   * each side, and the link's hit box grows with it. */
  padding: 0 12px;
  color: var(--kl-muted);
}
/* The pill: an inner box, so it can be shorter than the link without the tap
 * target shrinking. It spans the link's padding box, so the fill is the word
 * plus 12px either side. */
.ktabnav .ktab::before {
  content: "";
  position: absolute;
  inset: 50% 0 auto;
  height: var(--ktabnav-pill);
  border: 1px solid transparent;
  border-radius: 6px;
  transform: translateY(-50%);
  z-index: -1; /* behind the label; inside the link's own context */
  pointer-events: none;
}
/* No underline in this drawing: the pill is the only indicator. */
.ktabnav .ktab::after { content: none; }
.ktabnav .ktab:hover::before { background: var(--kl-sunken); }
.ktabnav .ktab[data-state="selected"] { font-weight: 600; }
.ktabnav .ktab[data-state="selected"]::before {
  background: var(--kl-raised);
  border-color: var(--kl-border-strong);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.12);
}
/* The ring follows the pill, not the 44px box: an inset ring on the box would
 * draw on top of the bar's rule. */
.ktabnav .ktab:focus-visible { outline: none; }
.ktabnav .ktab:focus-visible::before {
  outline: 2px solid var(--kl-accent);
  outline-offset: 2px;
}

/* ---- host glue (not the drawing) ---- */

/* Section nav — the site's one persistent wayfinding bar.
 *
 * The drawing is the package's: <TabNav> from @kira/components, rendered to
 * static HTML at publish time. This file is only the glue that puts that nav on
 * the site's page:
 *
 *   - the sticky box, its z-index and the rule under it;
 *   - the content gutter, so the labels line up with the hero below them;
 *   - the palette, because the catalogue paints its shell from literals while
 *     the package reads --kl-* roles. Mapping the host's own colours onto those
 *     roles is the point: the bar is the design system's component, drawn in the
 *     palette the page is already in, from the first frame.
 *
 * Nothing here draws a pill, an underline, a gap or a colour of its own. If the
 * bar looks wrong, the fix belongs in packages/react/styles.css, not here.
 *
 * Geometry: 44px of nav + 1px rule, as a direct child of <body>, before the
 * page. Every route therefore starts 45px lower than it would without a bar —
 * that is the initial layout, not a shift, and it is the same height everywhere.
 */

/* The bar's own height, named once. The renderer sets --ktabnav-h on the nav
 * (the package reads it); this is the box's view of the same number, for the
 * sticky offsets the catalogue's own header and skeleton need. */
:root {
  --sn-h: 44px;
}

/* The package's palette for the two host shells. The light values are the
 * approved export's own :root roles; the dark values are its `.dark` roles, so
 * the bar resolves every colour it draws from the same values the page uses.
 *
 * Every selector here is scoped away from a document that carries
 * data-kira-theme: the kit page sets that attribute and keeps the package's own
 * tokens, so this file can never repaint the kit. */
html:not([data-kira-theme]) {
  --kl-sunken: #f5f5f3;
  --kl-raised: #ffffff;
  --kl-selected: #ececea;
  --kl-border: #e6e6e3;
  --kl-border-strong: #d9d8d4;
  --kl-text: #37352f;
  --kl-text-2: #585753;
  --kl-muted: #6a6967;
  --kl-accent: #1a66b3;
  /* The bar takes the page's own chrome colour, so the strip is part of the
   * page rather than a lighter band on it. */
  --sn-bg: #f3f2ef;
}
html[data-host-theme="dark"] {
  --kl-sunken: #1e1e1e;
  --kl-raised: #202020;
  --kl-selected: #2a2a2a;
  --kl-border: #2e2e2e;
  --kl-border-strong: #3a3a3a;
  --kl-text: #e6e6e4;
  --kl-text-2: #a8a7a2;
  --kl-muted: #93928d;
  --kl-accent: #5aa3d4;
  --sn-bg: #191919;
}
@media (prefers-color-scheme: dark) {
  html[data-host-theme="dark"],
  html:not([data-kira-theme]):not([data-host-theme]) {
    --kl-sunken: #1e1e1e;
    --kl-raised: #202020;
    --kl-selected: #2a2a2a;
    --kl-border: #2e2e2e;
    --kl-border-strong: #3a3a3a;
    --kl-text: #e6e6e4;
    --kl-text-2: #a8a7a2;
    --kl-muted: #93928d;
    --kl-accent: #5aa3d4;
    --sn-bg: #191919;
  }
}

/* The band: sticky, full-bleed, opaque, one hairline under it. The nav inside
 * it is the drawing; this box only owns the page (position, paint, the rule).
 *
 * Two elements on purpose. A sticky bar must span the viewport for its fill to
 * reach both edges, while its labels must sit in the page's content box; one
 * element can only do both with percentage padding, which resolves against the
 * containing block (the body's content width, not the viewport) and lands 24px
 * off beside a padded or negatively-margined parent. So: full-bleed band,
 * centred content box inside it. */
.sn {
  position: sticky;
  top: 0;
  z-index: 30; /* above the catalogue header's 20 and its trays */
  height: calc(var(--ktabnav-h) + 1px);
  box-sizing: border-box;
  background: var(--sn-bg, var(--kl-surface));
  border-bottom: 1px solid var(--kl-border);
}

/* The content box: the catalogue's own 1384px border-box (1320 of content plus
 * 32 padding a side), centred. 60px of gutter at 1440, 32px on a phone — the
 * same edge the hero and the header use. */
body > .sn.ktabs,
.sn {
  display: block;
}
.sn > .ktabnav {
  width: 100%;
  max-width: 1384px;
  margin: 0 auto;
  /* The gutter minus the link's own pill padding: the first *label* lands on
   * the hero's edge while the pill hangs 12px into the gutter, which is what the
   * selected pill needs to look like a pill rather than a box. */
  padding-inline: 20px; /* 32px gutter - 12px pill padding */
  box-sizing: border-box;
  height: var(--ktabnav-h, 44px);
  font-family: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  /* The band owns the rule and the fill; the drawing's own 1px divider would
   * double it and sit one row up from the bar's bottom edge. */
  border-bottom: 0;
}

/* The catalogue's page-level rules are hostile to a host element: it paints
 * every [data-kl-root] anchor one ink and gives every element its own
 * border-color, which would flatten the pill's edge and the labels' muted/hover
 * inks. Two restores, scoped to the bar, so the drawing keeps its own values.
 * Specificity beats `[data-kl-root] a` (0,1,1) because body > .sn .ktab is
 * (0,2,1); nothing else on the page is touched. */
body > .sn .ktab { color: var(--kl-muted); }
/* The bar's labels are not document links and the drawing never underlines a
 * tab. The catalogue's own `a { text-decoration: inherit }` used to say so on
 * the routes that load catalogue.css; `/`, `/kit/` and `/devices/` do not, so
 * the UA's underline landed on them alone — visible on the current link, whose
 * 44px box sits in the bar's rule. One rule here, for the pages no sheet covers. */
body > .sn .ktab,
body > .sn .ktab:hover,
body > .sn .ktab:focus,
body > .sn .ktab[data-state="selected"] { text-decoration: none; }
body > .sn .ktab:hover,
body > .sn .ktab[data-state="selected"] { color: var(--kl-text); }
body > .sn .ktab::before { border-color: transparent; }
body > .sn .ktab:hover::before { border-color: transparent; }
body > .sn .ktab[data-state="selected"]::before {
  border-color: var(--kl-border-strong);
}

/* 390: eight labels do not fit. The package's nav already scrolls its own
 * overflow (never the document) and hides the scrollbar; the gutter above keeps
 * the first and last label on the page's edge, so the scroll starts and ends
 * flush with the hero. The generator sets the offset to the current pill before
 * the first paint.
 *
 * The offset it sets assumes 32px of gutter, so the first label still lands on
 * the hero's edge — hence the same 20px here as above (32 - 12). */
/* Landing on an anchor with the bar present. The catalogue's targets carry their
 * own scroll-margin (inline on `#rule-book`, injected per-specimen by
 * catalog-nav.js), so adjusting them here would mean fighting two sources of
 * truth. `scroll-padding-top` on the scrollport is the other half of the same
 * mechanism: the browser adds it to every scrollIntoView/fragment landing, so the
 * target clears the bar no matter which margin the target itself carries. */
html:has(> body > .sn) {
  scroll-padding-top: var(--sn-h, 44px);
}

/* The catalogue's own sticky header parks 45px lower, under the bar, so its
 * device/theme tray stays reachable while the page is scrolled. Scoped to a
 * document that really owns a bar: inside the /devices/ frame there is none, and
 * the framed catalogue must keep its own top. */
body:has(> .sn) [data-lib] > div:first-child {
  top: var(--sn-h, 44px) !important;
}

/* The pre-mount skeleton is an absolutely positioned sibling of #root at the top
 * of the page, so without this it would paint its header 45px above the real one
 * and the cross-fade would show the bar jumping. It starts below the nav, exactly
 * where the catalogue's own header does — the two layers stay pixel-identical. */
body:has(> .sn) > .catalog-skel {
  top: calc(var(--sn-h, 44px) + 1px);
}

/* Tap targets, 390, without touching a painted pixel.
 *
 * The pills are 32px tall in a tray that has no vertical neighbour, so the hit
 * box grows 6px above and below its own box; the button itself is unchanged.
 * Horizontally the narrowest pill is 41px and the tray gaps it 4px from the next
 * one, so growing sideways would overlap a neighbour — worse than a small box.
 * A pseudo-element on the button receives the click as the button's own. */
[data-lib] > div:first-child button {
  position: relative;
}
[data-lib] > div:first-child button::after {
  content: "";
  position: absolute;
  inset-block: -6px;
  inset-inline: 0;
}

/* The intro link row (20px of text) is the third way to a section, next to the
 * bar. It cannot reach 44px: its rows are 8px apart, so anything past ±4px
 * collides with the row above. 28px is the most it can have. */
body:has(> .sn) [data-lib] a {
  position: relative;
}
body:has(> .sn) [data-lib] a::after {
  content: "";
  position: absolute;
  inset-block: -4px;
  inset-inline: 0;
}

/* Home's own header links are 27px of text at 390, in two rows 12px apart. A
 * 44px hit box needs 8.5px above and below, so the two rows need 17px between
 * them or the boxes overlap — and an overlapping target is worse than a small
 * one, because the tap lands on whichever box is painted last. The row gap is
 * therefore widened to 18px (spacing only: the header's own drawing, type and
 * colours are untouched), which buys the 1px of clearance the boxes need.
 * Above 599 the header is one row with room, so the gap stays as designed. */
body:has(> .sn) > main > header a {
  position: relative;
}
body:has(> .sn) > main > header .wordmark {
  display: inline-flex;
  align-items: center;
}
@media (max-width: 599px) {
  body:has(> .sn) > main > header {
    row-gap: 18px;
  }
  body:has(> .sn) > main > header a::after {
    content: "";
    position: absolute;
    inset-block: -8.5px;
    inset-inline: -8px;
  }
  body:has(> .sn) > main > header .wordmark {
    min-height: 44px;
    margin-block: -7px;
  }
}
/* Above 599 the header is one row with 12px of padding above and below it, so a
 * hit box can grow into that padding without meeting another target. */
@media (min-width: 600px) {
  body:has(> .sn) > main > header a::after {
    content: "";
    position: absolute;
    inset-block: -12px;
    inset-inline: -6px;
  }
}
