/* @kira/components — standalone styles.
 *
 * Every colour is read from the inherited --kl-* roles, so a host that
 * already defines them keeps its palette. The :where() fallbacks below
 * have zero specificity: anything a host sets on :root, body or .dark
 * wins, in any import order.
 *
 * Theme: [data-kira-theme="light"|"dark"] on <html> or any ancestor.
 * With no attribute the light defaults apply at :root and inherit down.
 * Order matters here and only here -- dark before explicit light, so a
 * light subtree can re-enter inside a dark one.
 *
 * Font: never set here. Buttons and segments use font-family: inherit, so
 * they render in the host's face. The count/code badge reads --kl-font-mono
 * with the same stack Kira uses, so a host that loads IBM Plex Mono (as Kira
 * does) gets the design's figures; one that does not gets its platform mono.
 * Nothing is downloaded by this file either way.
 * No @font-face, no @import, so importing this file downloads nothing.
 *
 * Sizes follow the host's pointer: touch-capable devices get 44px targets.
 * The query is `any-pointer: coarse`, not `pointer: coarse`, so an iPad with
 * a trackpad or Pencil attached (fine primary, coarse available) still gets
 * the touch floor. A pure mouse/trackpad desktop stays at the drawing's
 * pointer sizes; a touch laptop gains 44px targets, which is the floor the
 * HIG asks for and the deliberate cost of not sniffing the UA. The old
 * [data-device] showcase hook stays absent.
 */

/* Dark first, explicit light last, so a light subtree re-enters inside dark.
 * The :root default skips a dark <html>, so it never fights the dark rule. */
:where([data-kira-theme="dark"]) {
  --kl-surface: #191919;
  --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;
  --kl-running: #d9a445;
  --kl-blocked: #ef8c55;
  --kl-done: #57c398;
  --kl-failed: #ef6f68;
  --kl-queued: #97a0b0;
  --kl-purple: #b9a6ff;
  --kl-font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

:where(:root:not([data-kira-theme="dark"])) {
  --kl-surface: #fbfbfa;
  --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;
  --kl-running: #85600f;
  --kl-blocked: #a84a12;
  --kl-done: #3a7454;
  --kl-failed: #bc3b37;
  --kl-queued: #5a6372;
  --kl-purple: #6b4fc4;
  --kl-font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

:where([data-kira-theme="light"]) {
  --kl-surface: #fbfbfa;
  --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;
  --kl-running: #85600f;
  --kl-blocked: #a84a12;
  --kl-done: #3a7454;
  --kl-failed: #bc3b37;
  --kl-queued: #5a6372;
  --kl-purple: #6b4fc4;
  --kl-font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

/* Button — 36 high, radius 6, 15/600 pointer; 44 high, radius 10 touch. */
@layer components {
  .kbtn {
    --kbtn-h: 36px;
    --kbtn-w: auto;
    --kbtn-px: 16px;
    --kbtn-r: 6px;
    --kbtn-fs: 15px;
    --kbtn-fw: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-sizing: border-box;
    margin: 0;
    border: 1px solid transparent;
    font-family: inherit;
    font-style: normal;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    /* A label that cannot fit its container wraps instead of pushing the page
     * sideways (iOS/iPadOS never scroll the page horizontally). Short labels
     * never reach this path: an auto-width flex item still sizes to max-content. */
    white-space: normal;
    max-width: 100%;
    overflow-wrap: anywhere;
    cursor: pointer;
    min-height: var(--kbtn-h);
    width: var(--kbtn-w);
    padding: 0 var(--kbtn-px);
    border-radius: var(--kbtn-r);
    font-size: var(--kbtn-fs);
    font-weight: var(--kbtn-fw);
    -webkit-tap-highlight-color: transparent;
  }

  .kbtn-sm { --kbtn-h: 32px; --kbtn-px: 12px; --kbtn-fs: 13px; --kbtn-fw: 550; }
  .kbtn-lg { --kbtn-h: 40px; --kbtn-px: 24px; --kbtn-r: 10px; }
  .kbtn-icon { --kbtn-w: 36px; --kbtn-px: 0px; }
  .kbtn-pill { --kbtn-px: 16px; --kbtn-r: 999px; --kbtn-fs: 13px; --kbtn-fw: 550; }
  .kbtn-icon-sm { --kbtn-h: 32px; --kbtn-w: 32px; --kbtn-px: 0px; }

  @media (any-pointer: coarse) {
    .kbtn { --kbtn-h: 44px; --kbtn-r: 10px; }
    .kbtn.kbtn-sm { --kbtn-h: 36px; --kbtn-r: 6px; }
    .kbtn.kbtn-lg { --kbtn-h: 48px; }
    .kbtn.kbtn-icon { --kbtn-w: 44px; }
    .kbtn.kbtn-pill { --kbtn-r: 999px; }
    .kbtn.kbtn-icon-sm { --kbtn-h: 36px; --kbtn-w: 36px; --kbtn-r: 6px; }

    /* sm and icon-sm keep their visual box and sit in a 44px hit area. */
    .kbtn.kbtn-sm,
    .kbtn.kbtn-icon-sm { position: relative; }
    .kbtn.kbtn-sm::after,
    .kbtn.kbtn-icon-sm::after {
      content: "";
      position: absolute;
      inset: calc((var(--kbtn-h) - 44px) / 2);
    }
  }

  .kbtn-default { background: var(--kl-text); color: var(--kl-surface); border-color: var(--kl-text); }
  .kbtn-secondary { background: var(--kl-raised); color: var(--kl-text); border-color: var(--kl-border); }
  .kbtn-outline { background: transparent; color: var(--kl-text); border-color: var(--kl-border); }
  .kbtn-ghost { background: transparent; color: var(--kl-text-2); border-color: transparent; }
  .kbtn-destructive { background: var(--kl-failed); color: var(--kl-surface); border-color: var(--kl-failed); }
  .kbtn-link {
    background: transparent;
    color: var(--kl-accent);
    border-color: transparent;
    text-decoration: underline;
    text-underline-offset: 3px;
    padding: 0;
  }

  .kbtn:hover:not(:disabled, [aria-busy="true"]) { filter: brightness(0.96); }
  .kbtn:active:not(:disabled, [aria-busy="true"]) { transform: translateY(1px); filter: brightness(0.94); }
  .kbtn:focus-visible { outline: 2px solid var(--kl-accent); outline-offset: 2px; }
  .kbtn:disabled { opacity: 0.5; cursor: not-allowed; }
  .kbtn[aria-busy="true"] { opacity: 0.9; }
  .kbtn [data-kbtn-spinner] {
    width: 14px;
    height: 14px;
    box-sizing: border-box;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    display: inline-block;
  }
  .kbtn svg { pointer-events: none; flex-shrink: 0; }
}

/* Badge — status pill 12/600, tag 13/550, count mono 12, code mono 13 x 44. */
@layer components {
  .kbadge {
    --kbadge-fs: 12px;
    --kbadge-fw: 600;
    --kbadge-pad: 4px 12px;
    --kbadge-r: 999px;
    --kbadge-mono: inherit;
    display: inline-block;
    box-sizing: border-box;
    margin: 0;
    border: 0;
    padding: var(--kbadge-pad);
    border-radius: var(--kbadge-r);
    font-family: var(--kbadge-mono);
    font-size: var(--kbadge-fs);
    font-weight: var(--kbadge-fw);
    font-variant-numeric: tabular-nums;
    font-style: normal;
    line-height: normal;
    letter-spacing: normal;
    text-transform: none;
    text-align: left;
    white-space: nowrap;
    vertical-align: baseline;
    background: transparent;
    color: inherit;
  }

  .kbadge-tag { --kbadge-fs: 13px; --kbadge-fw: 550; font-variant-numeric: normal; }
  .kbadge-count {
    --kbadge-fs: 12px;
    --kbadge-fw: 400;
    --kbadge-pad: 0;
    --kbadge-r: 0;
    --kbadge-mono: var(--kl-font-mono);
    font-variant-numeric: normal;
    background: transparent;
  }
  .kbadge-code {
    --kbadge-fs: 13px;
    --kbadge-fw: 400;
    --kbadge-pad: 4px 0;
    --kbadge-r: 6px;
    --kbadge-mono: var(--kl-font-mono);
    min-width: 44px;
    text-align: center;
    font-variant-numeric: normal;
    background: var(--kl-selected);
  }

  /* The drawing's touch size for the two device-sized kinds. An explicit
   * size class has higher specificity, so a pinned size is never overridden. */
  @media (any-pointer: coarse) {
    .kbadge.kbadge-status,
    .kbadge.kbadge-count { --kbadge-fs: 12.5px; }
  }

  .kbadge.kbadge-sm { --kbadge-fs: 12px; }
  .kbadge.kbadge-md { --kbadge-fs: 12.5px; }
  .kbadge.kbadge-xl { --kbadge-fs: 13px; }

  /* A tone tints the pill only; count and code keep their own finish. */
  .kbadge.kbadge-count { background: transparent; }
  .kbadge.kbadge-code { background: var(--kl-selected); }

  /* Toned pills: the neutral tint first (parses everywhere), then the OKLCH
   * mix. Safari below 16.4 rejects `color-mix(in oklch, …)` and keeps the
   * neutral tint, so a toned badge is never a bare transparent box there.
   * The tone still lives in the text colour in both cases. */
  .kbadge-default { color: var(--kl-muted); background: var(--kl-selected); }
  .kbadge-secondary { color: var(--kl-text-2); background: var(--kl-selected); }
  .kbadge-success { color: var(--kl-done); background: var(--kl-selected); background: color-mix(in oklch, var(--kl-done) 12%, transparent); }
  .kbadge-warning { color: var(--kl-running); background: var(--kl-selected); background: color-mix(in oklch, var(--kl-running) 12%, transparent); }
  .kbadge-danger,
  .kbadge-destructive { color: var(--kl-failed); background: var(--kl-selected); background: color-mix(in oklch, var(--kl-failed) 12%, transparent); }
  .kbadge-info { color: var(--kl-queued); background: var(--kl-selected); background: color-mix(in oklch, var(--kl-queued) 12%, transparent); }
  .kbadge-purple { color: var(--kl-purple); background: var(--kl-selected); background: color-mix(in oklch, var(--kl-purple) 12%, transparent); }
  .kbadge-outline {
    color: var(--kl-text-2);
    background: transparent;
    box-shadow: inset 0 0 0 1px var(--kl-border);
  }

  .kbadge-code { background: var(--kl-selected); }
}

/* Segmented control — track on --sunken, raised selected chip. */
@layer components {
  .kseg-track {
    display: flex;
    gap: 2px;
    padding: 2px;
    /* border-box so max-width: 100% bounds the drawn track, not just its
     * content; content-box let the 2px padding + 1px border overshoot. */
    box-sizing: border-box;
    width: fit-content;
    /* Fit the viewport, then scroll the track itself rather than the page:
     * the contained-scroller pattern iPhone/iPad use for wide segmented bars. */
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    background: var(--kl-sunken);
    border: 1px solid var(--kl-border);
    border-radius: 10px;
  }
  .kseg-seg {
    --kseg-h: 32px;
    min-height: var(--kseg-h);
    padding: 0 12px;
    box-sizing: border-box;
    margin: 0;
    border: 1px solid transparent;
    border-radius: 6px;
    font-family: inherit;
    font-style: normal;
    font-size: 15px;
    font-weight: 500;
    line-height: normal;
    letter-spacing: normal;
    text-transform: none;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    cursor: pointer;
    background: transparent;
    color: var(--kl-text-2);
    box-shadow: none;
    -webkit-tap-highlight-color: transparent;
  }
  .kseg-seg[data-state="selected"] {
    font-weight: 600;
    background: var(--kl-raised);
    border-color: var(--kl-border-strong);
    color: var(--kl-text);
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.12);
  }

  /* Same focus treatment as .kbtn: 2px accent ring at 2px offset. The UA
   * default (1px auto, no offset) is invisible against the track tint. */
  .kseg-seg:focus-visible { outline: 2px solid var(--kl-accent); outline-offset: 2px; }

  .kseg-track-sm { border-radius: 8px; }
  .kseg-seg-sm { --kseg-h: 28px; padding: 0 8px; font-size: 13px; }
  .kseg-seg-icon { display: inline-flex; align-items: center; gap: 6px; }

  @media (any-pointer: coarse) {
    .kseg-seg { --kseg-h: 44px; }
    .kseg-seg-sm { --kseg-h: 44px; }
  }
}

/* ------------------------------------------------------------------------
 * Chip — the board's filter chip, the search's scope chip and the chat
 * header's project chip. Radius 10, 1px --kl-border, label ink --kl-text-2
 * (--kl-text for project).
 *
 *   filter   44 high · 15 / 550 · 0 16 0 12 · gap 8
 *   scope    30 high · 13 / 550 · 0 11    · gap 4
 *   project  34 high · 15 / 550 · 0 8 0 12 · gap 8
 *
 * The scope chip is the only one whose box follows the pointer: 36 high with
 * 8 of padding on touch, as the design's phone column draws it.
 *
 * A chip is a label, not a control: the design draws no hover, pressed or
 * disabled state, so none is invented here. `selected` and `focus` are the two
 * states it does draw.
 * ------------------------------------------------------------------------ */
@layer components {
  .kchip {
    --kchip-h: 44px;
    --kchip-px: 12px;
    --kchip-px-end: 16px;
    --kchip-gap: 8px;
    --kchip-fs: 15px;
    display: inline-flex;
    align-items: center;
    box-sizing: border-box;
    gap: var(--kchip-gap);
    margin: 0;
    min-height: var(--kchip-h);
    padding: 0 var(--kchip-px-end) 0 var(--kchip-px);
    border: 1px solid var(--kl-border);
    border-radius: 10px;
    font-family: inherit;
    font-style: normal;
    font-size: var(--kchip-fs);
    font-weight: 550;
    /* The design leaves the line box natural (20px at 15/550); line-height: 1
     * would shrink the drawn box. */
    line-height: normal;
    letter-spacing: normal;
    text-transform: none;
    white-space: nowrap;
    background: transparent;
    color: var(--kl-text-2);
  }

  .kchip-scope {
    --kchip-h: 30px;
    --kchip-px: 11px;
    --kchip-px-end: 11px;
    --kchip-gap: 4px;
    --kchip-fs: 13px;
  }
  /* 36 high on touch so the phone column's drawing holds; the 44px tap area
   * belongs to whatever button holds the chip. */
  @media (any-pointer: coarse) {
    .kchip-scope { --kchip-h: 36px; --kchip-px: 8px; --kchip-px-end: 8px; }
  }

  .kchip-project {
    --kchip-h: 34px;
    --kchip-px: 12px;
    --kchip-px-end: 8px;
    color: var(--kl-text);
  }

  .kchip-selected {
    color: var(--kl-surface);
    background: var(--kl-text);
    border-color: var(--kl-text);
  }
  .kchip-focus {
    outline: 2px solid var(--kl-accent);
    outline-offset: 2px;
  }
}

/* ------------------------------------------------------------------------
 * Avatar — one box per kind, no sizes: the round person chip is 24 and the
 * square project tile 22, both 13 / 650 on --kl-selected inside a 1px
 * --kl-border ring. Person uses --kl-text, project the second ink.
 *
 * Hover, focus and pressed belong to the button that holds the avatar, so
 * none is drawn here.
 * ------------------------------------------------------------------------ */
@layer components {
  .kavatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    flex-shrink: 0;
    user-select: none;
    border: 1px solid var(--kl-border);
    background: var(--kl-selected);
    font-size: 13px;
    font-weight: 650;
    /* Natural line box (17px at 13/650), as the design draws it. */
    line-height: normal;
    color: var(--kl-text);
  }
  .kavatar-person { width: 24px; height: 24px; border-radius: 50%; }
  .kavatar-project { width: 22px; height: 22px; border-radius: 6px; color: var(--kl-text-2); }
}

/* ------------------------------------------------------------------------
 * Dialog — Kira's confirm card, as a real modal <dialog>.
 *
 * Isolated block: nothing below is referenced by Button/Badge/SegmentedControl
 * and nothing above is modified for it. Every value is the live, approved
 * Kira modal (frontend .kdialog + .kdialog-title + .kdialog-actions), which
 * the doc's Dialog spec restates with older numbers (radius 18/padding 20/
 * title 17) — the rendered card wins, as asked.
 *
 *   card     width min(440px, 100% − 40px) · radius 22 · padding 24
 *            1px --kl-border · --kl-raised · 0 24 70 rgb(15 15 15 / .25)
 *   title    18 / 650, line-height normal
 *   body     15 / 1.55, --kl-text-2
 *   actions  flex gap 8 · each 46 high · radius 14 · 15 / 550 (600 destructive)
 *   scrim    rgb(15 15 15 / .32) light, rgb(0 0 0 / .55) dark
 *
 * Why <dialog> and not a div: showModal() puts the card in the top layer,
 * makes the rest of the document inert, gives Escape for free and keeps the
 * closed element display:none — so a closed dialog costs no layout, no paint
 * and no listeners. There is no scroll lock to write: the document is inert.
 * ------------------------------------------------------------------------ */
@layer components {
  .kdialog {
    /* :where() so a host's own dialog rules still win at equal specificity. */
    box-sizing: border-box;
    width: min(440px, 100% - 40px);
    max-width: 440px;
    max-height: calc(100dvh - 48px);
    /* The UA centres with margin:auto; keep that, drop its padding/border. */
    margin: auto;
    padding: 24px;
    overflow: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--kl-border);
    border-radius: 22px;
    background: var(--kl-raised);
    box-shadow: 0 24px 70px rgb(15 15 15 / 0.25);
    color: var(--kl-text);
    font-family: inherit;
    font-size: 15px;
    font-weight: 400;
    /* normal, as the live card: the doc's 1.55 is the body copy's, below. */
    line-height: normal;
    letter-spacing: normal;
    text-align: left;
  }

  .kdialog::backdrop {
    background: rgb(15 15 15 / 0.32);
  }
  /* Dark is declared second so it wins over the light default above. */
  :where([data-kira-theme="dark"]) .kdialog::backdrop {
    background: rgb(0 0 0 / 0.55);
  }

  .kdialog-title {
    margin: 0;
    padding: 0;
    font-size: 18px;
    font-weight: 650;
    line-height: normal;
    letter-spacing: normal;
    color: var(--kl-text);
  }

  .kdialog-desc {
    margin: 8px 0 0;
    padding: 0;
    font-size: 15px;
    font-weight: 400;
    line-height: 1.55;
    color: var(--kl-text-2);
  }

  .kdialog-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
  }

  .kdialog-action {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 14px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 550;
    line-height: normal;
    letter-spacing: normal;
    color: var(--kl-text);
    background: var(--kl-selected);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .kdialog-action:hover { filter: brightness(0.96); }
  .kdialog-action:active { filter: brightness(0.92); }
  .kdialog-action:focus-visible,
  .kdialog:focus-visible { outline: 2px solid var(--kl-accent); outline-offset: 2px; }
  .kdialog-action:disabled { opacity: 0.5; cursor: not-allowed; }
  .kdialog-action-destructive {
    font-weight: 600;
    /* Same ink rule as .kbtn-destructive: --kl-surface, not #fff. In light the
     * two are visually identical (#fbfbfa); in dark --kl-surface is the dark
     * ink, which is what keeps white-on-#ef6f68 from failing at ~2.5:1. */
    color: var(--kl-surface);
    background: var(--kl-failed);
  }

  /* One small entrance, transform + opacity only, as the library's motion
   * rule asks. @starting-style is what makes an appearing <dialog> animate at
   * all; browsers without it simply appear. Reduced motion gets no motion. */
  @media (prefers-reduced-motion: no-preference) {
    .kdialog[open] {
      animation: kdialog-in 160ms cubic-bezier(0.32, 0.72, 0, 1);
    }
    @starting-style {
      .kdialog[open] { opacity: 0; transform: translateY(8px) scale(0.98); }
    }
    @keyframes kdialog-in {
      from { opacity: 0; transform: translateY(8px) scale(0.98); }
    }
  }

  /* A 44px touch floor for the action row, matching .kbtn's own rule. */
  @media (any-pointer: coarse) {
    .kdialog-action { min-height: 48px; }
  }
}

/* ------------------------------------------------------------------------
 * Input — the library's Input section, as a real <input>.
 *
 * Numbers are the approved standalone's (sha 1a62d561…), LIB_PX + LIB_SPECS:
 *
 *   search   100% · 54 tall (52 phone) · pad 0 14 (pad-right 8 phone) · radius 14
 *            · gap 12 · 18px muted icon
 *   field    max 260 · 36 tall (44 touch) · pad 0 12 · radius 10 · gap 8
 *   state    36 tall (44 touch) · pad 0 12 · radius 10
 *   text     15px, 16px on touch (the iOS zoom floor the section states)
 *   box      --kl-raised, 1px --kl-border; placeholder --kl-muted, value --kl-text
 *
 * One deliberate delta from the drawing: the drawing's focus is "caret only,
 * outline none" and its spec table flags that as undecided. A real field keeps
 * the caret and adds the same 2px accent ring .kbtn/.kseg use, so keyboard
 * focus stays visible.
 * ------------------------------------------------------------------------ */
@layer components {
  .kinput-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
  }

  .kinput-label {
    font-family: inherit;
    font-size: 13px;
    font-weight: 550;
    line-height: normal;
    color: var(--kl-text-2);
  }

  .kinput-error {
    margin: 0;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
    color: var(--kl-failed);
  }

  .kinput {
    display: flex;
    align-items: center;
    box-sizing: border-box;
    width: 100%;
    background: var(--kl-raised);
    border: 1px solid var(--kl-border);
  }
  .kinput-invalid { border-color: var(--kl-failed); }

  .kinput-search {
    gap: 12px;
    height: 54px;
    padding: 0 14px;
    border-radius: 14px;
  }
  .kinput-field {
    gap: 8px;
    max-width: 260px;
    height: 36px;
    padding: 0 12px;
    border-radius: 10px;
  }
  .kinput-state {
    gap: 8px;
    height: 36px;
    padding: 0 12px;
    border-radius: 10px;
  }
  .kinput-icon { flex: none; color: var(--kl-muted); }

  /* The drawing's `$` and `per month`: 15px value ink, 13.5px unit. */
  .kinput-affix {
    flex: none;
    font-family: inherit;
    font-size: 15px;
    line-height: normal;
    white-space: nowrap;
    color: var(--kl-text);
  }
  .kinput-suffix { font-size: 13.5px; color: var(--kl-muted); }

  /* The input itself: no box of its own, the wrapper draws it. The 16px
   * font on touch is the zoom floor, not a style choice. */
  .kinput-text {
    flex: 1;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    font-family: inherit;
    font-size: 15px;
    line-height: normal;
    color: var(--kl-text);
    appearance: none;
  }
  .kinput-text::placeholder { color: var(--kl-muted); opacity: 1; }
  .kinput-text:focus { outline: none; }
  .kinput-text:focus-visible { outline: 2px solid var(--kl-accent); outline-offset: 2px; }
  .kinput-text:disabled { color: var(--kl-muted); cursor: not-allowed; }
  .kinput:has(.kinput-text:disabled) { opacity: 0.6; }

  @media (any-pointer: coarse) {
    .kinput-field,
    .kinput-state { height: 44px; }
    .kinput-text { font-size: 16px; }
  }
  /* The drawing's phone search is 52 tall with an 8px right pad; iPad keeps
   * 54/14. The split is by viewport, as ChatInput's iPad radius is, because
   * `any-pointer: coarse` alone cannot tell an iPad from an iPhone. */
  @media (any-pointer: coarse) and (max-width: 699px) {
    .kinput-search { height: 52px; padding-right: 8px; }
  }
}


/* ------------------------------------------------------------------------
 * 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.
 * ------------------------------------------------------------------------ */
@layer components {
  .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; }
  }
}

/* Menu — a 300px popover, radius 14, padding 8; rows 38/44 with a 12 gap.
 *
 * The design draws the phone variant as a Sheet. This ships the popover at
 * every width instead: it is clamped to the viewport, so a narrow screen gets
 * the same menu, inset rather than resized into a sheet the package does not
 * have. The 52px phone row belongs to the sheet and is not applied here. */
@layer components {
  .kmenu { display: inline-flex; }

  /* Fixed, because the surface is placed from the trigger's measured box so
   * it can flip above the trigger and stay inside a narrow viewport. */
  .kmenu-popover {
    position: fixed;
    inset: auto;
    z-index: 60;
    box-sizing: border-box;
    width: 300px;
    /* The design's 300, clamped to the viewport: on a 320 screen it insets
     * instead of overflowing. */
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    overflow: auto;
    padding: 8px;
    margin: 0;
    border: 1px solid var(--kl-border);
    border-radius: 14px;
    background: var(--kl-raised);
    color: var(--kl-text);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
    font-family: inherit;
  }
  .kmenu-popover[data-anchor-position] {
    /* Keep the design's right alignment, then clamp to the viewport edges. */
    left: clamp(8px, var(--kmenu-left, calc(anchor(right) - min(300px, 100vw - 16px))), max(8px, 100vw - 308px));
    top: max(8px, calc(anchor(bottom) + 6px));
    position-try-fallbacks: --kmenu-above, --kmenu-fit;
  }

  @position-try --kmenu-above {
    top: auto;
    bottom: max(8px, calc(anchor(top) + 6px));
  }
  @position-try --kmenu-fit {
    top: 8px;
  }

  .kmenu-row {
    --kmenu-row-h: 38px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    width: 100%;
    min-height: var(--kmenu-row-h);
    margin: 0;
    padding: 0 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--kl-text);
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    text-align: left;
    line-height: normal;
    white-space: normal;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .kmenu-row:hover:not(:disabled),
  .kmenu-row:focus-visible { background: var(--kl-selected); }
  .kmenu-row:focus-visible { outline: 2px solid var(--kl-accent); outline-offset: -2px; }
  .kmenu-row:disabled,
  .kmenu-row[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

  /* The leading glyph: the design's 17px box, secondary ink, never shrinks. */
  .kmenu-icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    color: var(--kl-text-2);
  }

  .kmenu-label { flex: 1; min-width: 0; font-weight: 400; }
  .kmenu-row[data-current] .kmenu-label { font-weight: 600; }
  .kmenu-note { flex: none; font-size: 13px; color: var(--kl-muted); }

  /* The HIG's 44px floor for a finger, on the query the rest of the file uses. */
  @media (any-pointer: coarse) {
    .kmenu-row { --kmenu-row-h: 44px; }
  }
}

/* ------------------------------------------------------------------------
 * Toast — Kira's one-row confirmation, ported from the live .ktoast.
 *
 *   row      44 min · padding 0 8 0 16 · gap 12 · radius 14
 *            --kl-selected · 1px --kl-border · 0 14 40 rgb(0 0 0 / .55)
 *            15px --kl-text, one line, ellipsis
 *   mark     16px, decorative
 *   action   draws a .kbtn (size sm) at 32 high, --kl-text on --kl-raised
 *   dismiss  32 × 32 · radius 10 · --kl-muted, 14px X
 *   touch    the X sits in a 44px hit area, as .kbtn-icon-sm does
 *
 * The live drawing is dark only (delta §Toast): --kl-selected with that
 * shadow is right on a dark page and a grey slab on a light one, so light
 * takes the raised surface and a soft shadow. Same stacking rule as above:
 * dark first, explicit light last.
 * ------------------------------------------------------------------------ */
@layer components {
  .ktoast {
    display: flex;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    max-width: 100%;
    min-height: 44px;
    margin: 0;
    padding: 0 8px 0 16px;
    border: 1px solid var(--kl-border);
    border-radius: 14px;
    background: var(--kl-selected);
    box-shadow: 0 14px 40px rgb(0 0 0 / 0.55);
    color: var(--kl-text);
    font-family: inherit;
    font-size: 15px;
    font-weight: 400;
    line-height: normal;
    letter-spacing: normal;
    text-align: left;
  }
  :where(:root:not([data-kira-theme="dark"])) .ktoast,
  :where([data-kira-theme="light"]) .ktoast {
    background: var(--kl-raised);
    box-shadow: 0 1px 2px rgb(15 15 15 / 0.05), 0 14px 40px rgb(15 15 15 / 0.18);
  }

  .ktoast-mark {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    color: var(--kl-text);
  }

  .ktoast-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ktoast-action-slot { display: inline-flex; flex: none; }

  .ktoast-dismiss {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--kl-muted);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .ktoast-dismiss:hover { color: var(--kl-text); background: var(--kl-border); }
  .ktoast-dismiss:active { background: var(--kl-border-strong); }
  .ktoast-dismiss:focus-visible { outline: 2px solid var(--kl-accent); outline-offset: 2px; }

  /* Touch keeps the 32px drawing and puts a 44px hit area around it. */
  @media (any-pointer: coarse) {
    .ktoast-dismiss { position: relative; }
    .ktoast-dismiss::after {
      content: "";
      position: absolute;
      inset: -6px;
    }
  }

  /* One small entrance, transform + opacity only; reduced motion opts out. */
  @media (prefers-reduced-motion: no-preference) {
    .ktoast { animation: ktoast-in 220ms cubic-bezier(0.32, 0.72, 0, 1); }
    @keyframes ktoast-in {
      from { opacity: 0; transform: translateY(8px); }
    }
  }
}

/* ChatInput — the Composer specimen's field and send disc: card hairline on
 * --kl-raised, radius 16/18/22, text 15px/16px, a 32px disc in a 36/44 target,
 * and the drawing's Off rim. Roles only. */
@layer components {
  .kchat {
    --kchat-r: 16px;
    --kchat-fs: 15px;
    --kchat-tap: 36px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    border: 1px solid var(--kl-border);
    border-radius: var(--kchat-r);
    background: var(--kl-raised);
    box-shadow: 0 2px 12px rgb(15 15 15 / 0.05);
    color: var(--kl-text);
    font-family: inherit;
  }
  .kchat:focus-within { border-color: var(--kl-border-strong); }
  .kchat:has(.kchat-field:focus-visible) {
    box-shadow: 0 2px 12px rgb(15 15 15 / 0.05), 0 0 0 2px var(--kl-accent);
  }
  /* Native textarea: Enter, IME, undo and autocorrect are the browser's. */
  .kchat-field {
    display: block;
    box-sizing: border-box;
    width: 100%;
    margin: 0;
    padding: 12px 16px 4px;
    /* Grows with the text to about four rows, then scrolls. field-sizing is
     * the browser's own sizing; where it is missing the field stays one row
     * and scrolls, which is the same thing at the other end of the range. */
    field-sizing: content;
    max-height: calc(var(--kchat-fs) * 1.4 * 4 + 16px);
    border: 0;
    outline: none;
    overflow-y: auto;
    resize: none;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: var(--kchat-fs);
    line-height: 1.4;
  }
  .kchat-field::placeholder { color: var(--kl-muted); }
  .kchat-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px 8px;
  }
  .kchat-lead { display: flex; align-items: center; gap: 4px; min-width: 0; }
  .kchat-tail { display: flex; align-items: center; gap: 4px; margin-left: auto; }
  /* A caller's model chip gets the drawing's 32/36px pill; its content is the
   * caller's, so only the box is ours. */
  .kchat-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    padding: 0 12px 0 8px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    color: var(--kl-text-2);
    white-space: nowrap;
  }
  /* The disc is the drawing; the button is the hit target. */
  .kchat-send {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: var(--kchat-tap);
    height: var(--kchat-tap);
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--kl-surface);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .kchat-send:disabled { cursor: default; }
  .kchat-send:focus-visible { outline: 2px solid var(--kl-accent); outline-offset: 2px; }
  .kchat-send[aria-busy="true"] { opacity: 0.55; }
  .kchat-disc {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--kl-selected);
    color: var(--kl-muted);
  }
  .kchat-send[data-ready] .kchat-disc,
  .kchat-send[data-stop] .kchat-disc { background: var(--kl-text); color: var(--kl-surface); }
  .kchat[data-off] { opacity: 0.7; }
  .kchat[data-off] .kchat-disc { background: transparent; border: 1.5px dashed var(--kl-muted); }

  @media (any-pointer: coarse) {
    .kchat { --kchat-fs: 16px; --kchat-tap: 44px; --kchat-r: 22px; }
    .kchat-chip { height: 36px; }
  }
  /* The drawing's iPad radius sits between the pointer and phone steps. */
  @media (any-pointer: coarse) and (min-width: 700px) {
    .kchat { --kchat-r: 18px; }
  }
}

/* ------------------------------------------------------------------------
 * Sheet — Kira's bottom sheet, as a real modal <dialog>.
 *
 * Isolated block: nothing above is modified and nothing below is referenced by
 * the other components. Numbers are the drawn ones from the standalone design
 * of record (LIB:538-541, LIB:1357): 22/22/0/0 corners, elev.sheet, grabber
 * 38 x 5, pinned header with a 44 x 44 close around a 30px chip, padding
 * 0 12, bottom max(16px, safe area), 84% cap at content height.
 *
 * Why <dialog> and not a portal div: showModal() gives the top layer, an inert
 * document, Escape via `cancel`, focus restoration and display:none while
 * closed — the same platform Dialog already uses, with no global state and no
 * scroll-lock bookkeeping. The panel is bottom-anchored with the UA's own
 * margin box overridden, so there is no extra wrapper element.
 * ------------------------------------------------------------------------ */
@layer components {
  .ksheet {
    /* The UA centres a modal dialog; pin it to the bottom edge instead and let
     * the block margins collapse to nothing above it. */
    position: fixed;
    inset: auto 0 0;
    margin: 0 auto;
    width: 100%;
    max-width: 560px;
    /* 84% of the viewport: the dialog is fixed, so % is the viewport and no
     * viewport unit is needed (no whole-document re-resolve on open). */
    max-height: 84%;
    box-sizing: border-box;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 22px 22px 0 0;
    background: var(--kl-raised);
    box-shadow: 0 -14px 44px rgb(15 15 15 / 0.22);
    color: var(--kl-text);
    font-family: inherit;
    font-size: 15px;
    font-weight: 400;
    line-height: normal;
    text-align: left;
    /* Only a drag writes transform; this is its per-frame consequence. */
    --ksheet-scrim: 1;
    will-change: transform;
  }
  .ksheet::backdrop {
    background: rgb(15 15 15 / 0.32);
    opacity: var(--ksheet-scrim, 1);
  }
  :where([data-kira-theme="dark"]) .ksheet::backdrop {
    background: rgb(0 0 0 / 0.55);
  }

  /* The panel is the dialog's content box; the body flexes inside the cap and
   * is the only scroller, so the header stays put. */
  /* [open] so the UA's `dialog:not([open]) { display: none }` still stands:
   * a closed sheet keeps costing no box, no paint and no listeners. */
  .ksheet[open] {
    display: flex;
    flex-direction: column;
  }
  .ksheet-surface {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    padding: 0 12px max(16px, env(safe-area-inset-bottom));
    box-sizing: border-box;
  }

  .ksheet-grabber-row {
    display: flex;
    flex: none;
    justify-content: center;
    padding: 8px 0 4px;
    cursor: grab;
    touch-action: none;
  }
  .ksheet-grabber {
    display: block;
    width: 38px;
    height: 5px;
    border-radius: 2px;
    background: var(--kl-border);
  }

  .ksheet-header {
    display: flex;
    flex: none;
    align-items: center;
    padding: 4px 4px 8px 12px;
    touch-action: none;
  }
  .ksheet-title {
    flex: 1;
    min-width: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-size: 18px;
    font-weight: 650;
    line-height: normal;
    letter-spacing: normal;
    color: var(--kl-text);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ksheet-close {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 22px;
    background: transparent;
    color: var(--kl-muted);
    font: inherit;
    cursor: pointer;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
  }
  .ksheet-close-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 14px;
    background: var(--kl-selected);
  }
  .ksheet-close:focus-visible,
  .ksheet:focus-visible { outline: 2px solid var(--kl-accent); outline-offset: 2px; }

  /* The scroller: a long list scrolls inside the 84% cap. */
  .ksheet-body {
    min-height: 0;
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* One entrance, transform + opacity only, as the library's motion rule asks.
   * @starting-style is what lets an appearing <dialog> animate at all; without
   * it (or with reduced motion) the sheet simply appears in place. */
  @media (prefers-reduced-motion: no-preference) {
    .ksheet[open] {
      animation: ksheet-in 420ms cubic-bezier(0.32, 0.72, 0, 1);
    }
    @starting-style {
      .ksheet[open] { opacity: 0; transform: translate3d(0, 100%, 0); }
    }
    @keyframes ksheet-in {
      from { opacity: 0; transform: translate3d(0, 100%, 0); }
    }
  }
}

/* ------------------------------------------------------------------------
 * Popover — a non-modal anchored panel.
 *
 * The box is the design's floating surface: a --kl-raised card, 1px
 * --kl-border, radius 14, an 8px inset, and the same soft shadow family as the
 * dialog one size down. Position comes from the component (fixed left/top);
 * everything else from here. max-height is the viewport minus the 8px edge the
 * positioner reserves on both sides, so a tall panel scrolls inside itself
 * rather than running off the screen; overscroll containment keeps a scroll
 * inside the panel from moving the page behind it.
 *
 * Non-modal, so no scrim and no focus trap: the page behind stays usable.
 * ------------------------------------------------------------------------ */
@layer components {
  .kpop {
    box-sizing: border-box;
    position: fixed;
    /* The design's panel width; a host overrides with its own style prop. */
    width: max-content;
    min-width: 220px;
    max-width: min(360px, calc(100vw - 16px));
    max-height: calc(100dvh - 16px);
    overflow: auto;
    overscroll-behavior: contain;
    padding: 8px;
    border: 1px solid var(--kl-border);
    border-radius: 14px;
    background: var(--kl-raised);
    box-shadow: 0 16px 44px rgb(15 15 15 / 0.2);
    color: var(--kl-text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.4;
    letter-spacing: normal;
    text-align: left;
    /* The UA's [popover] rule sets inset:0 + margin:auto; the position comes
     * from the component instead, in both the promoted and the plain path. */
    inset: auto;
    margin: 0;
    /* Touch: never let a hold-and-drag on the panel text-select behind it. */
    -webkit-tap-highlight-color: transparent;
  }

  /* A touch floor for the panel's own rows, as every other control gets. */
  @media (any-pointer: coarse) {
    .kpop { font-size: 15px; }
  }

  /* One small entrance, transform + opacity only, as the library's motion rule
   * asks; reduced motion gets none. Keyed off the open state the component
   * renders, so the fallback and the top layer animate the same way. */
  @media (prefers-reduced-motion: no-preference) {
    .kpop {
      animation: kpop-in 140ms cubic-bezier(0.32, 0.72, 0, 1);
    }
    @keyframes kpop-in {
      from { opacity: 0; transform: translateY(-4px) scale(0.98); }
    }
  }
}
