/* ════════════════════════════════════════════════════════════════════════
   khio-page.css — Khio, the one chat: #view-khio in the study shell.
   2026-10-12. Logic: public/js/shared/khio-page.js.

   The view has no navigation of its own (James: "we already have this, so
   use this"). The shell's sidebar is the navigation: on a computer the rail
   and the panel beside the chat, on a phone the same panel opened as a drawer
   (.kp-sb-open, the Phone drawer section below; the panel's rows wear
   study-rail.css's rules). Sizes follow Ask AI's chat (#view-deeptutor in
   study-deeptutor-glass.css): 15px text, an 820px reading column, a slim
   composer. The one thing of its own on a computer is the Agents sidebar
   on the left (Section: agents, 2026-10-18).

   Pure white in light, black in dark. Your messages blue (#0071e3, white text
   at 4.7:1), Khio's neutral grey. No orange anywhere.
   ════════════════════════════════════════════════════════════════════════ */

/* ── Section: tokens ───────────────────────────────────────────────────── */
/* The view, and the Agents sidebar the shell shares (#kpSide, outside it). */
#view-khio, .kp-side {
    --bg: #ffffff;
    --raised: #ffffff;
    --ink: #111114;
    --ink-2: rgba(17, 17, 20, .62);
    --ink-3: rgba(17, 17, 20, .45);
    --line: rgba(17, 17, 20, .09);
    --line-2: rgba(17, 17, 20, .15);
    --hover: rgba(17, 17, 20, .045);
    --hover-2: rgba(17, 17, 20, .07);
    --blue: #0071e3;
    --blue-press: #0062c4;
    --blue-ring: rgba(0, 113, 227, .2);
    --me-bg: var(--blue);
    --khio-bg: #f0f0f3;
    --on-ink: #ffffff;
    --good: #1f8f47;
    --bad: #d93025;
    --shadow-sm: 0 1px 2px rgba(17, 17, 20, .04), 0 2px 8px rgba(17, 17, 20, .04);
    --shadow: 0 1px 2px rgba(17, 17, 20, .05), 0 6px 20px rgba(17, 17, 20, .07);
    --ease: cubic-bezier(.22, 1, .36, 1);
    --read: 820px;
    --compose: 960px;
    --gutter: 16px;
    --work: #d97757;
    --wait: #b45309;
}
html[data-theme="dark"] #view-khio, html[data-theme="dark"] .kp-side {
    --bg: #000000;
    --raised: #141416;
    --ink: #f4f4f5;
    --ink-2: rgba(244, 244, 245, .66);
    --ink-3: rgba(244, 244, 245, .45);
    --line: rgba(255, 255, 255, .09);
    --line-2: rgba(255, 255, 255, .16);
    --hover: rgba(255, 255, 255, .06);
    --hover-2: rgba(255, 255, 255, .1);
    --blue-ring: rgba(64, 156, 255, .32);
    --khio-bg: #262629;
    --on-ink: #000000;
    --good: #30d158;
    --bad: #ff5c5c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow: 0 8px 24px rgba(0, 0, 0, .5);
    --work: #f4f4f5;
    --wait: #f4f4f5;
}

/* ── Section: the view ─────────────────────────────────────────────────── */
#view-khio {
    position: relative; flex: 1; min-height: 0; min-width: 0; height: 100%; flex-direction: row;
    background: var(--bg); color: var(--ink);
    font: 400 15px/1.5 var(--k-sans, 'Inter', system-ui, sans-serif); -webkit-font-smoothing: antialiased;
}
#view-khio.active { display: flex !important; }
/* The chat and the thread scroll inside themselves; the view never does.
   (The panel waiting below the opening screen made it scrollable, which
   showed as a white scrollbar strip down the right of the picture.) */
#view-khio.study-view { overflow: hidden !important; }
/* The chat runs to the bottom of the screen: no .study-view padding, and no
   room kept for the mobile tab bar the other views use. */
#view-khio.study-view { padding: 0 !important; margin: 0 !important; }
#app:has(> #view-khio.active) { padding-bottom: 0 !important; }
.kp-side { color: var(--ink); font: 400 15px/1.5 var(--k-sans, 'Inter', system-ui, sans-serif); -webkit-font-smoothing: antialiased; }
#view-khio *, #view-khio *::before, #view-khio *::after, .kp-side *, .kp-side *::before, .kp-side *::after { box-sizing: border-box; }
:where(#view-khio, .kp-side) button { font: inherit; color: inherit; }
#view-khio [hidden], .kp-side [hidden] { display: none !important; }
#view-khio :focus-visible, .kp-side :focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.kp-svg, #view-khio .kp-iconbtn svg, #view-khio .kp-send svg, #view-khio .kp-stop svg, #view-khio .kp-tobottom svg {
    display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.kp-iconbtn {
    flex: none; width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-2);
    display: inline-flex; align-items: center; justify-content: center; position: relative; cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.kp-iconbtn svg { width: 18px; height: 18px; }
@media (hover: hover) { .kp-iconbtn:hover { background: var(--hover); color: var(--ink); } }
.kp-iconbtn:active { background: var(--hover-2); }

/* ── Section: no side panel on a computer ─────────────────────────────── */
/* James 2026-10-16: "we don't need this". While the Khio chat is up on a
   computer the shell's panel (Earlier chats, the account) is hidden, and
   since 2026-10-19 the icon rail too: the Agents sidebar (Section: agents)
   is the only left sidebar here, with Keeps, Spaces and Settings in it.
   Other views keep the rail. */
@media (min-width: 1024px) {
    .study-layout:has(#view-khio.active) #studySidebar,
    .study-layout:has(#view-khio.active) .khio-rail,
    html[data-khio-pre-view="khio"] #studySidebar,
    html[data-khio-pre-view="khio"] .khio-rail { display: none !important; }
}

/* ── Section: the chat column ──────────────────────────────────────────── */
.kp-chat { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.kp-chat.is-drop::after { content: 'Drop to attach'; position: absolute; inset: 10px; display: flex; align-items: center; justify-content: center; border: 2px dashed var(--blue); border-radius: 16px; color: var(--blue); font-weight: 600; pointer-events: none; z-index: 20; background: color-mix(in srgb, var(--blue) 5%, transparent); }

/* No header (James: "remove the chat header bar entirely"). On a phone two
   small floating buttons: the drawer on the left, Khio's card on the right. */
.kp-fab {
    position: absolute; z-index: 7; top: calc(env(safe-area-inset-top) + 8px); width: 38px; height: 38px;
    border: 1px solid var(--line); border-radius: 50%; padding: 0; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; color: var(--ink);
    background: color-mix(in srgb, var(--raised) 86%, transparent); box-shadow: var(--shadow-sm);
    -webkit-backdrop-filter: blur(14px) saturate(1.6); backdrop-filter: blur(14px) saturate(1.6);
}
.kp-fab svg { width: 17px; height: 17px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
/* Messages fade out under the two buttons instead of running into them. */
.kp-chat::before {
    content: ''; position: absolute; z-index: 6; top: 0; left: 0; right: 0; height: calc(env(safe-area-inset-top) + 58px); pointer-events: none;
    background: linear-gradient(to bottom, var(--bg) 55%, color-mix(in srgb, var(--bg) 0%, transparent));
}
.kp-menu-btn { left: max(10px, env(safe-area-inset-left)); }
.kp-card-btn { right: max(10px, env(safe-area-inset-right)); }
.kp-install-btn {
    right: calc(max(10px, env(safe-area-inset-right)) + 46px); width: auto; gap: 6px; padding: 0 14px 0 11px;
    border-radius: 999px; font-size: 13.5px; font-weight: 500;
}
@media (hover: hover) { .kp-install-btn:hover { border-color: var(--line-2); } }

.kp-dot { position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 2px var(--bg); }

.kp-scroll {
    flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    padding: calc(env(safe-area-inset-top) + 56px) max(var(--gutter), calc((100% - var(--read)) / 2)) calc(var(--kp-composer-h, 96px) + 12px);
    scrollbar-width: none;
}
.kp-scroll::-webkit-scrollbar, .kp-thread-scroll::-webkit-scrollbar { display: none; }
.kp-transcript { min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }

.kp-datesep { align-self: center; margin: 20px 0 6px; font-size: 11.5px; font-weight: 600; color: var(--ink-3); letter-spacing: .02em; }
.kp-datesep:first-child { margin-top: 6px; }
.kp-sys { align-self: center; margin: 10px 0; padding: 6px 12px; border-radius: 999px; background: var(--hover); font-size: 12.5px; color: var(--ink-2); text-align: center; }

/* ── Section: the opening screen (computer only) ───────────────────────── */
/* Libron (SIL OFL 1.1, Nico Verbruggen; public/fonts/Libron-OFL.txt), the
   headline face from James's Arrow site, sets the opening screen's question. */
@font-face { font-family: "Libron"; src: url(/fonts/Libron-Regular.woff2) format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@media (max-width: 1023px) { .kp-front { display: none !important; } }
/* A greeting over one of James's six Real BG pictures (the dots at the
   bottom switch them, khio-page.js remembers the pick) with the composer
   centred under it; the chat itself waits underneath (khio-page.js
   setFront). #1-3 are dark with light words; #4-6 are pale paper, and
   khio-page.js marks the chat .is-front-light so the words and the box
   turn dark-on-light for them. */
.kp-front {
    position: absolute; inset: 0; z-index: 4;
    --kp-front-img: url(/images/khio/front-real-1.webp); --kp-front-shade: rgba(0, 0, 0, .35);
    background: radial-gradient(ellipse 60% 42% at 50% 46%, var(--kp-front-shade), rgba(0, 0, 0, 0) 70%), #050505 var(--kp-front-img) center / cover no-repeat;
    animation: kp-front-in .4s ease both;
}
.kp-front[hidden] { display: none; }
/* A plain white or black page instead of a picture, when they asked Khio for
   one (users.metadata.khio_backdrop). Only Khio can put the picture back, so
   the picker steps aside. */
.kp-front[data-backdrop="white"] { background: #fff; }
.kp-front[data-backdrop="black"] { background: #000; }
.kp-front[data-backdrop] .kp-front-bgs { display: none; }
@keyframes kp-front-in { from { opacity: 0; } }
/* After James's mockup (2026-10-18): a small grey greeting, a big serif
   question, a tall dark box, and "Resume last chat" under it. The head and
   the link sit off the composer's measured height (--kp-composer-h). */
.kp-front-head {
    position: absolute; left: var(--gutter); right: var(--gutter); bottom: calc(50% + var(--kp-composer-h, 150px) / 2 + 10px);
    text-align: center; text-shadow: 0 2px 24px rgba(0, 0, 0, .5);
}
.kp-front-kicker { margin: 0 0 10px; color: rgba(255, 255, 255, .62); font: 400 17px/1.3 var(--k-sans, 'Inter', system-ui, sans-serif); }
.kp-front-title { margin: 0; color: #fff; font: 400 56px/1.08 "Libron", var(--k-display, Georgia, serif); letter-spacing: -.015em; text-wrap: balance; }
.kp-front-history {
    position: absolute; left: 50%; top: calc(50% + var(--kp-composer-h, 150px) / 2 + 4px); transform: translateX(-50%);
    display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px; border: 0; border-radius: 8px;
    background: none; color: rgba(255, 255, 255, .78); font-size: 13px; font-weight: 500; cursor: pointer; transition: color .15s ease;
}
.kp-front-history kbd {
    padding: 1px 6px; border: 1px solid currentColor; border-radius: 6px; opacity: .7;
    font: 500 11px/1.5 var(--k-sans, 'Inter', system-ui, sans-serif); color: inherit; background: none;
}
@media (hover: hover) { .kp-front-history:hover { color: #fff; } }
/* The composer while the opening screen is up: a tall dark glass box, the
   words on top, + on the left and the mic and a white send on the right. */
.kp-chat.is-front #kpComposer > :not(.kp-tobottom) { max-width: 768px; }
.kp-chat.is-front #kpComposer .kp-field {
    flex-wrap: wrap; align-items: center; min-height: 140px; padding: 16px 14px 12px; border-radius: 22px;
    /* Raised glass: a lit top edge, a darker base, and a two-step drop
       shadow so the box sits up off the picture. */
    background: linear-gradient(180deg, rgba(44, 44, 48, .78), rgba(14, 14, 16, .86));
    border: 1px solid rgba(255, 255, 255, .14);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .16), inset 0 -1px 0 rgba(0, 0, 0, .5),
        0 2px 4px rgba(0, 0, 0, .3), 0 18px 50px -8px rgba(0, 0, 0, .65);
    -webkit-backdrop-filter: blur(18px) saturate(1.3); backdrop-filter: blur(18px) saturate(1.3);
    transition: box-shadow .25s ease, border-color .25s ease;
}
.kp-chat.is-front #kpComposer .kp-field:focus-within {
    border-color: rgba(255, 255, 255, .24);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2), inset 0 -1px 0 rgba(0, 0, 0, .5), 0 0 0 4px rgba(255, 255, 255, .06),
        0 2px 4px rgba(0, 0, 0, .3), 0 24px 60px -8px rgba(0, 0, 0, .7);
}
html body .kp-chat.is-front #kpComposer .kp-field textarea { order: -1; flex: 1 0 100%; align-self: stretch; min-height: 64px !important; padding: 2px 10px !important; color: #fff !important; -webkit-text-fill-color: #fff !important; font-size: 16px; }
.kp-chat.is-front #kpComposer .kp-field textarea::placeholder { color: rgba(255, 255, 255, .5); -webkit-text-fill-color: rgba(255, 255, 255, .5); }
/* Buttons with depth: a top highlight, a darker base and a drop shadow;
   they lift on hover and press in on click. */
.kp-chat.is-front .kp-attach, .kp-chat.is-front .kp-mic {
    width: 38px; height: 38px; border-radius: 12px; color: rgba(255, 255, 255, .88);
    background: linear-gradient(180deg, rgba(255, 255, 255, .12), rgba(255, 255, 255, .04));
    border: 1px solid rgba(255, 255, 255, .1);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14), 0 1px 2px rgba(0, 0, 0, .4);
    transition: transform .15s ease, background .15s ease, box-shadow .15s ease, color .15s ease;
}
.kp-chat.is-front .kp-attach { margin-right: auto; }
.kp-chat.is-front .kp-attach:active, .kp-chat.is-front .kp-mic:active, .kp-chat.is-front .kp-send:active { transform: translateY(1px) scale(.96); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .35); }
#view-khio .kp-chat.is-front .kp-mic[hidden], #view-khio .kp-chat.is-front .kp-send[hidden] { display: inline-flex !important; }
.kp-chat.is-front .kp-callbtn { display: none; }
.kp-chat.is-front .kp-send {
    width: 40px; height: 38px; margin-left: 8px; border-radius: 12px; color: #111114;
    background: linear-gradient(180deg, #ffffff, #e6e6ea); border: 1px solid rgba(255, 255, 255, .9);
    box-shadow: inset 0 1px 0 #fff, inset 0 -2px 0 rgba(0, 0, 0, .1), 0 2px 6px rgba(0, 0, 0, .45), 0 0 0 1px rgba(0, 0, 0, .25);
    transition: transform .15s ease, box-shadow .15s ease;
}
@media (hover: hover) {
    .kp-chat.is-front .kp-attach:hover, .kp-chat.is-front .kp-mic:hover { transform: translateY(-1px); color: #fff; background: linear-gradient(180deg, rgba(255, 255, 255, .18), rgba(255, 255, 255, .07)); }
    .kp-chat.is-front .kp-send:hover { transform: translateY(-1px); box-shadow: inset 0 1px 0 #fff, inset 0 -2px 0 rgba(0, 0, 0, .1), 0 6px 14px rgba(0, 0, 0, .5), 0 0 0 1px rgba(0, 0, 0, .25); }
}
.kp-front[data-bg="2"] { --kp-front-img: url(/images/khio/front-real-2.webp); }
.kp-front[data-bg="3"] { --kp-front-img: url(/images/khio/front-real-3.webp); }
.kp-front[data-bg="4"] { --kp-front-img: url(/images/khio/front-real-4.webp); }
.kp-front[data-bg="5"] { --kp-front-img: url(/images/khio/front-real-5.webp); }
.kp-front[data-bg="6"] { --kp-front-img: url(/images/khio/front-real-6.webp); }
.kp-chat.is-front-light .kp-front { --kp-front-shade: rgba(250, 248, 244, .55); background-color: #efece6; }
.kp-front-bgs { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; }
.kp-front-bg {
    width: 30px; height: 30px; padding: 0; border: 2px solid rgba(255, 255, 255, .35); border-radius: 50%; cursor: pointer;
    background: center / cover no-repeat; transition: border-color .15s ease, transform .15s ease;
}
.kp-front-bg[data-bg="1"] { background-image: url(/images/khio/front-real-1.webp); }
.kp-front-bg[data-bg="2"] { background-image: url(/images/khio/front-real-2.webp); }
.kp-front-bg[data-bg="3"] { background-image: url(/images/khio/front-real-3.webp); }
.kp-front-bg[data-bg="4"] { background-image: url(/images/khio/front-real-4.webp); }
.kp-front-bg[data-bg="5"] { background-image: url(/images/khio/front-real-5.webp); }
.kp-front-bg[data-bg="6"] { background-image: url(/images/khio/front-real-6.webp); }
.kp-front-bg[aria-checked="true"] { border-color: #fff; }
@media (hover: hover) { .kp-front-bg:hover { transform: scale(1.08); } }
/* Dark on light, for the pale pictures (#4-6). */
.kp-chat.is-front-light .kp-front-head { text-shadow: 0 0 28px rgba(250, 248, 244, .9); }
.kp-chat.is-front-light .kp-front-kicker { color: rgba(17, 17, 20, .6); }
.kp-chat.is-front-light .kp-front-title { color: #111114; }
.kp-chat.is-front-light .kp-front-history { color: rgba(17, 17, 20, .72); }
.kp-chat.is-front-light .kp-front-bg { border-color: rgba(17, 17, 20, .22); }
.kp-chat.is-front-light .kp-front-bg[aria-checked="true"] { border-color: #111114; }
.kp-chat.is-front.is-front-light #kpComposer .kp-field {
    background: linear-gradient(180deg, rgba(255, 255, 255, .96), rgba(244, 242, 238, .92)); border-color: rgba(17, 17, 20, .1);
    box-shadow: inset 0 1px 0 #fff, inset 0 -1px 0 rgba(17, 17, 20, .06), 0 1px 2px rgba(17, 17, 20, .08), 0 18px 50px -10px rgba(17, 17, 20, .28);
}
.kp-chat.is-front.is-front-light #kpComposer .kp-field:focus-within {
    border-color: rgba(17, 17, 20, .18);
    box-shadow: inset 0 1px 0 #fff, 0 0 0 4px rgba(17, 17, 20, .05), 0 1px 2px rgba(17, 17, 20, .08), 0 24px 60px -10px rgba(17, 17, 20, .32);
}
html body .kp-chat.is-front.is-front-light #kpComposer .kp-field textarea { color: #111114 !important; -webkit-text-fill-color: #111114 !important; }
.kp-chat.is-front.is-front-light #kpComposer .kp-field textarea::placeholder { color: rgba(17, 17, 20, .45); -webkit-text-fill-color: rgba(17, 17, 20, .45); }
.kp-chat.is-front.is-front-light .kp-attach, .kp-chat.is-front.is-front-light .kp-mic {
    color: rgba(17, 17, 20, .75); background: linear-gradient(180deg, #fff, #f0eeea); border-color: rgba(17, 17, 20, .1);
    box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(17, 17, 20, .12);
}
.kp-chat.is-front.is-front-light .kp-send {
    color: #fff; background: linear-gradient(180deg, #3a3a40, #111114); border-color: #111114;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 2px 6px rgba(17, 17, 20, .3);
}
@media (hover: hover) {
    .kp-chat.is-front-light .kp-front-history:hover { color: #111114; }
    .kp-chat.is-front.is-front-light .kp-attach:hover, .kp-chat.is-front.is-front-light .kp-mic:hover { color: #111114; background: linear-gradient(180deg, #fff, #e9e6e1); }
    .kp-chat.is-front.is-front-light .kp-send:hover { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 6px 14px rgba(17, 17, 20, .35); }
}
.kp-chat.is-front::before, .kp-chat.is-front .kp-scroll, .kp-chat.is-front .kp-tobottom { visibility: hidden; }
.kp-chat.is-front #kpComposer { bottom: calc(50% - var(--kp-composer-h, 64px) / 2); }
.kp-front-edge { display: none; }
/* Resuming the chat (khio-page.js setFront): the picture drifts forward and
   blurs away, the greeting lifts off, the box glides down to its place and
   the latest messages rise in one after another. */
.kp-front.is-leaving { animation: kp-front-out .7s cubic-bezier(.4, 0, .2, 1) forwards; pointer-events: none; }
.kp-front.is-leaving .kp-front-head { animation: kp-front-lift .45s cubic-bezier(.4, 0, .2, 1) forwards; }
.kp-front.is-leaving .kp-front-history, .kp-front.is-leaving .kp-front-bgs { animation: kp-front-fade .25s ease forwards; }
@keyframes kp-front-out { 40% { opacity: 1; } to { opacity: 0; transform: scale(1.08); filter: blur(12px); } }
@keyframes kp-front-lift { to { opacity: 0; transform: translateY(-36px); filter: blur(4px); } }
@keyframes kp-front-fade { to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .kp-front, .kp-front.is-leaving, .kp-front.is-leaving * { animation: none; } }

/* ── Section: a brand-new chat ─────────────────────────────────────────── */
.kp-hello { margin: auto 0; padding: 20px 4px 24px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.kp-hello-ava { display: none; }
.kp-hello-title { margin: 0 0 8px; font: 500 28px/1.1 var(--k-display, Georgia, serif); letter-spacing: -.02em; text-wrap: balance; }
.kp-hello p { margin: 0 0 18px; max-width: 420px; color: var(--ink-2); font-size: 14.5px; line-height: 1.5; text-wrap: pretty; }
.kp-suggest { display: grid; grid-template-columns: 1fr; gap: 8px; width: 100%; max-width: 520px; }
.kp-suggest-btn {
    min-height: 44px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--raised);
    text-align: left; font-size: 14px; font-weight: 500; cursor: pointer; transition: border-color .15s ease, background .15s ease;
}
@media (hover: hover) { .kp-suggest-btn:hover { border-color: var(--line-2); background: var(--hover); } }
@media (min-width: 560px) { .kp-suggest { grid-template-columns: 1fr 1fr; } }

/* ── Section: messages ─────────────────────────────────────────────────── */
/* A run from one side tightens to 2px, its joined corners tuck in, and only
   the last bubble of the run gets a tail. */
.kp-row { position: relative; display: flex; flex-wrap: wrap; align-items: flex-end; margin-top: 2px; }
.kp-row.is-start { margin-top: 12px; }
.kp-row.is-me { justify-content: flex-end; }
.kp-row.is-new { animation: kp-in .26s var(--ease) both; }
@keyframes kp-in { from { opacity: 0; transform: translateY(6px); } }

.kp-b {
    position: relative; max-width: min(78%, 620px); padding: 8px 13px; border-radius: 18px;
    font-size: 15px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere;
}
.kp-row.is-me .kp-b { background: var(--me-bg); color: #fff; }
.kp-row.is-khio .kp-b { background: var(--khio-bg); color: var(--ink); }
.kp-row.is-me:not(.is-end) > .kp-b { border-bottom-right-radius: 5px; }
.kp-row.is-me:not(.is-start) > .kp-b { border-top-right-radius: 5px; }
.kp-row.is-khio:not(.is-end) > .kp-b { border-bottom-left-radius: 5px; }
.kp-row.is-khio:not(.is-start) > .kp-b { border-top-left-radius: 5px; }
.kp-row.is-end > .kp-b:not(.kp-b-img):not(.kp-b-file):not(.kp-typing)::before,
.kp-row.is-end > .kp-b:not(.kp-b-img):not(.kp-b-file):not(.kp-typing)::after { content: ''; position: absolute; bottom: 0; height: 16px; pointer-events: none; }
.kp-row.is-me.is-end > .kp-b::before { right: -6px; width: 18px; background: var(--me-bg); border-bottom-left-radius: 14px 12px; }
.kp-row.is-me.is-end > .kp-b::after { right: -24px; width: 24px; background: var(--bg); border-bottom-left-radius: 9px; }
.kp-row.is-khio.is-end > .kp-b::before { left: -6px; width: 18px; background: var(--khio-bg); border-bottom-right-radius: 14px 12px; }
.kp-row.is-khio.is-end > .kp-b::after { left: -24px; width: 24px; background: var(--bg); border-bottom-right-radius: 9px; }
.kp-b a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* The time: beside the bubble on hover on a computer (from a zero-width box
   so it takes no room), under it after a tap on a phone. */
.kp-time { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--ink-3); white-space: nowrap; pointer-events: none; }
@media (hover: hover) {
    .kp-time { flex: none; align-self: center; display: flex; width: 0; padding-left: 10px; opacity: 0; transition: opacity .15s ease; }
    .kp-row.is-me > .kp-time { order: -1; justify-content: flex-end; padding: 0 10px 0 0; }
    .kp-row:hover > .kp-time, .kp-row.show-time > .kp-time { opacity: 1; }
}
@media (hover: none) {
    .kp-time { display: none; flex-basis: 100%; margin: 3px 6px 0; }
    .kp-row.is-me > .kp-time { text-align: right; }
    .kp-row.show-time > .kp-time { display: block; }
}

.kp-row .kp-b.kp-b-img { padding: 0; background: none; overflow: hidden; border-radius: 16px; }
.kp-b-img img { display: block; max-width: min(240px, 66vw); max-height: 300px; border-radius: 16px; box-shadow: 0 0 0 1px var(--line); }
.kp-row .kp-b.kp-b-file { display: inline-flex; align-items: center; gap: 9px; padding: 6px 12px 6px 6px; text-decoration: none; white-space: nowrap; }
.kp-file-ic { flex: none; width: 30px; height: 30px; border-radius: 8px; background: color-mix(in srgb, currentColor 14%, transparent); display: inline-flex; align-items: center; justify-content: center; }
.kp-file-ic svg { width: 15px; height: 15px; }
.kp-file-name { overflow: hidden; text-overflow: ellipsis; max-width: 200px; font-size: 14px; font-weight: 500; }
.kp-row .b.khiocard { max-width: min(352px, calc(100vw - 40px)); }

.kp-typing { display: inline-flex; align-items: center; gap: 4px; padding: 12px 14px; }
.kp-typing span, .kp-thinking span { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: kp-wave 1.2s infinite ease-in-out; }
.kp-typing span:nth-child(2), .kp-thinking span:nth-child(2) { animation-delay: .15s; }
.kp-typing span:nth-child(3), .kp-thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes kp-wave { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-3px); opacity: 1; } }

/* ── Section: thread cards in the chat ─────────────────────────────────── */
/* One bordered row, as in the Claude app's chat (James 2026-10-16): a
   mark, the title, then its status in a word, and how long it has been
   working while it is. A soft fill on hover. */
.kp-tcard {
    display: flex; align-items: center; gap: 12px; align-self: flex-start; max-width: 100%; min-height: 46px;
    margin: 4px 0; padding: 8px 18px 8px 14px; border: 1px solid var(--line-2); border-radius: 14px; background: var(--bg);
    text-align: left; cursor: pointer; transition: background .15s ease;
}
@media (hover: hover) { .kp-tcard:hover { background: var(--hover); } }
.kp-tcard:active { background: var(--hover-2); }
.kp-tc-title { min-width: 0; font-size: 15px; font-weight: 500; color: var(--ink); letter-spacing: -.005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kp-tcard[data-status="done"] .kp-tc-title, .kp-tcard[data-status="stopped"] .kp-tc-title { color: var(--ink-2); }
.kp-tc-sub { flex: none; font-size: 14px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* The row's mark: four dots taking turns while working, a filled check
   when done, a red mark on a failure, a dashed ring when stopped. */
.kp-rm { flex: none; width: 18px; height: 18px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.kp-rm svg { width: 10px; height: 10px; stroke-width: 3.2; }
.kp-rm.is-working { display: grid; grid-template-columns: 4px 4px; gap: 4px; place-content: center; border-radius: 0; }
.kp-rm.is-working i { width: 4px; height: 4px; border-radius: 50%; background: var(--work); animation: kp-dots 1.2s ease-in-out infinite; }
.kp-rm.is-working i:nth-child(2) { animation-delay: .3s; }
.kp-rm.is-working i:nth-child(4) { animation-delay: .6s; }
.kp-rm.is-working i:nth-child(3) { animation-delay: .9s; }
@keyframes kp-dots { 0%, 100% { opacity: .25; transform: scale(.75); } 35% { opacity: 1; transform: scale(1); } }
.kp-rm.is-done { background: var(--ink); color: var(--bg); }
.kp-rm.is-failed { background: var(--bad); color: #fff; }
html[data-theme="dark"] #view-khio .kp-rm.is-failed { color: #000; }
/* Waiting on them: a ring in the waiting colour (amber; ink in dark, which has no orange). */
.kp-rm.is-waiting { width: 14px; height: 14px; border: 2px solid var(--wait); }
.kp-rm.is-stopped { width: 16px; height: 16px; border: 1.5px dashed var(--ink-3); }
.kp-rm.is-chat { color: var(--ink-3); }
.kp-rm.is-chat svg { width: 15px; height: 15px; stroke-width: 1.8; }

/* Under Khio's answer: back into the thread it came from. */
.kp-tlink {
    display: inline-flex; align-items: center; gap: 2px; min-height: 30px; margin: 4px 0 0 2px; padding: 0 6px 0 10px;
    border: 1px solid var(--line); border-radius: 999px; background: var(--raised); color: var(--ink-2);
    font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.kp-tlink svg { width: 14px; height: 14px; }
@media (hover: hover) { .kp-tlink:hover { border-color: var(--line-2); color: var(--ink); } }

.kp-st { position: absolute; right: -3px; bottom: -3px; width: 14px; height: 14px; box-shadow: 0 0 0 2px var(--raised); }
.kp-st { flex: none; width: 16px; height: 16px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--raised); }
.kp-st svg { width: 9px; height: 9px; stroke-width: 3.4; }
.kp-st.is-working { border: 1.5px solid color-mix(in srgb, var(--blue) 25%, transparent); border-top-color: var(--blue); animation: kp-spin .8s linear infinite; }
.kp-st.is-done { background: var(--good); color: #fff; }
.kp-st.is-failed { background: var(--bad); color: #fff; }
html[data-theme="dark"] #view-khio .kp-st.is-done, html[data-theme="dark"] #view-khio .kp-st.is-failed { color: #000; }
.kp-st.is-waiting { border: 2px solid var(--wait); }
.kp-st.is-stopped { border: 1.5px solid var(--ink-3); }
.kp-st.is-stopped::after { content: ''; width: 5px; height: 5px; border-radius: 1px; background: var(--ink-3); }
.kp-st.is-chat { background: var(--hover-2); color: var(--ink-2); }
@keyframes kp-spin { to { transform: rotate(360deg); } }

/* ── Section: composer ─────────────────────────────────────────────────── */
/* Ask AI's: a slim field in the reading column. */
.kp-composer {
    position: relative; flex: none;
    padding: 8px max(var(--gutter), calc((100% - var(--read)) / 2)) calc(env(safe-area-inset-bottom) + 16px);
    background: transparent;
}
/* The chat's own composer floats over the messages, which scroll on under
   it instead of stopping at a band above it (James 2026-10-16). Only what
   is in it takes clicks; the clear space around the field passes them on.
   khio-page.js keeps --kp-composer-h at its height. */
#kpComposer { position: absolute; z-index: 5; left: 0; right: 0; bottom: 0; pointer-events: none; }
/* Longer than the reading column and slim (James 2026-10-16). A max width,
   not percentage padding: padding percentages measure the whole chat, so
   with the side panel taking the right they shrank the field. */
#kpComposer { padding-left: var(--gutter); padding-right: var(--gutter); }
#kpComposer > :not(.kp-tobottom) { max-width: var(--compose); margin-left: auto; margin-right: auto; }
#kpComposer .kp-field { min-height: 44px; padding: 4px 6px 4px 8px; border-radius: 14px; }
#kpComposer .kp-field textarea { padding: 5px 6px; }
/* The mic while it records (red, breathing) and while the words come back. */
.kp-mic.is-recording { background: var(--bad); color: #fff; animation: kp-rec 1.4s ease-in-out infinite; }
.kp-mic.is-busy { opacity: .45; pointer-events: none; }
@keyframes kp-rec { 50% { opacity: .7; } }
#kpComposer > * { pointer-events: auto; }
.kp-allowance { margin: 0 0 6px; text-align: center; font-size: 12px; color: var(--ink-3); }
.kp-pending { display: flex; gap: 8px; overflow-x: auto; padding: 6px 2px 2px; scrollbar-width: none; }
.kp-pending::-webkit-scrollbar { display: none; }
.kp-pending:not(:empty) { margin-bottom: 6px; }
.kp-chip { position: relative; flex: none; display: inline-flex; align-items: center; gap: 8px; height: 48px; max-width: 220px; padding: 0 26px 0 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--raised); }
.kp-chip.is-image { width: 48px; padding: 0; }
.kp-chip.is-image img { width: 48px; height: 48px; object-fit: cover; border-radius: 11px; display: block; }
.kp-chip-ext { flex: none; width: 34px; height: 34px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--blue) 10%, transparent); color: var(--blue); font-size: 9.5px; font-weight: 700; letter-spacing: .03em; }
.kp-chip-tx { display: flex; flex-direction: column; min-width: 0; }
.kp-chip-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kp-chip-size { font-size: 11.5px; color: var(--ink-3); }
.kp-chip-x { position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--bg); background: var(--ink); color: var(--on-ink); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.kp-chip-x svg { width: 9px; height: 9px; stroke-width: 3; }

.kp-field {
    display: flex; align-items: flex-end; gap: 2px; min-height: 54px; padding: 8px 8px 8px 10px;
    background: var(--raised); border: 1px solid var(--line-2); border-radius: 16px;
    box-shadow: 0 1px 2px rgba(17, 17, 20, .04), 0 8px 28px rgba(17, 17, 20, .06);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.kp-field:focus-within { border-color: var(--line-2); }
.kp-field textarea {
    flex: 1; min-width: 0; align-self: center; resize: none; border: 0; outline: none; background: none !important; color: var(--ink);
    font: 400 15px/1.45 var(--k-sans, 'Inter', system-ui, sans-serif); padding: 7px 6px; max-height: 160px;
}
#view-khio .kp-field textarea:focus-visible { outline: none; }
/* The shell styles every textarea (a border, a grey fill, a focus ring);
   here the field around it is the visible surface. */
html body #view-khio .kp-field textarea { border: 0 !important; background: none !important; box-shadow: none !important; border-radius: 0 !important; margin: 0 !important; min-height: 0 !important; }
/* The words typed take this page's own ink, not the site's light-scheme
   input grey (#2d2f31), which is unreadable when the chat is dark. */
html body #view-khio .kp-field textarea { color: var(--ink) !important; -webkit-text-fill-color: var(--ink) !important; }
.kp-field textarea::placeholder { color: var(--ink-3); }
.kp-send {
    flex: none; width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--blue); color: #fff;
    display: inline-flex; align-items: center; justify-content: center; cursor: pointer; transition: background .15s ease, transform .15s ease;
}
.kp-send svg { width: 17px; height: 17px; stroke-width: 2.4; }
@media (hover: hover) { .kp-send:hover { background: var(--blue-press); } }
.kp-send:active { transform: scale(.92); }
.kp-send:disabled { background: var(--hover-2); color: var(--ink-3); cursor: default; transform: none; }

.kp-tobottom {
    position: absolute; z-index: 6; left: 50%; bottom: calc(100% + 6px); width: 36px; height: 36px; margin-left: -18px;
    border: 1px solid var(--line-2); border-radius: 50%; background: var(--raised); color: var(--ink); box-shadow: var(--shadow);
    display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
    opacity: 0; transform: translateY(6px); pointer-events: none; transition: opacity .18s ease, transform .2s var(--ease);
}
.kp-tobottom svg { width: 17px; height: 17px; }
.kp-tobottom.is-on { opacity: 1; transform: none; pointer-events: auto; }
.kp-unread { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--blue); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }

/* ── Section: full-screen states (link your phone, can't reach) ─────────── */
.kp-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px 28px 48px; text-align: center; }
.kp-state-title { margin: 0; font: 500 28px/1.1 var(--k-display, Georgia, serif); letter-spacing: -.02em; text-wrap: balance; }
.kp-state-copy { margin: 0 0 6px; max-width: 360px; color: var(--ink-2); font-size: 14.5px; line-height: 1.5; }

.kp-toast {
    position: fixed; z-index: 1200; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px);
    padding: 9px 16px; border-radius: 999px; background: var(--ink); color: var(--on-ink); font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow);
    transform: translate(-50%, 10px); opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .25s var(--ease);
    max-width: calc(100vw - 32px); text-align: center;
}
.kp-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ── Section: the thread (phone: a full screen over the chat) ─────────── */
.kp-thread {
    position: fixed; z-index: 1100; inset: 0;
    display: flex; flex-direction: column; background: var(--bg);
    transform: translateX(100%); transition: transform .32s var(--ease);
    --dt-ink: var(--ink); --dt-muted: var(--ink-2); --dt-line: var(--line); --dt-soft: var(--hover); --dt-glass-bg-color: var(--bg);
}
.kp-thread.is-open { transform: none; }
.kp-thread-top {
    flex: none; display: flex; align-items: center; gap: 6px; min-height: 52px;
    padding: calc(env(safe-area-inset-top) + 6px) 10px 6px 6px; box-shadow: 0 1px 0 var(--line);
}
.kp-thread-ic { display: none; }
.kp-thread-id { flex: 1; min-width: 0; }
.kp-thread-title { font-size: 15px; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kp-thread-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); }
.kp-pill { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; color: var(--ink-2); }
.kp-pill[data-status="working"] { color: var(--blue); }
.kp-pill[data-status="done"] { color: var(--good); }
.kp-pill[data-status="failed"] { color: var(--bad); }
.kp-pill .kp-st { width: 12px; height: 12px; background: transparent; }
.kp-pill .kp-st.is-done { background: var(--good); }
.kp-pill .kp-st.is-failed { background: var(--bad); }
.kp-pill .kp-st svg { width: 7px; height: 7px; color: var(--bg); }
.kp-pill .kp-st.is-chat { display: none; }
.kp-thread-close { display: none; }
.kp-stop {
    flex: none; display: inline-flex; align-items: center; gap: 5px; height: 32px; padding: 0 12px 0 10px;
    border: 1px solid var(--line-2); border-radius: 10px; background: var(--raised); cursor: pointer; font-size: 13px; font-weight: 600;
}
.kp-stop svg { width: 12px; height: 12px; fill: currentColor; stroke: none; }
@media (hover: hover) { .kp-stop:hover { background: var(--hover); } }

.kp-thread-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px var(--gutter) 12px; scrollbar-width: none; }
.kp-thread-body { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.kp-thread-composer { padding-left: var(--gutter); padding-right: var(--gutter); }
.kp-thread-composer .kp-field, .kp-thread-composer .kp-pending { max-width: 720px; margin-left: auto; margin-right: auto; }
.kp-thread-composer .kp-field { padding-left: 12px; }
.kp-thread-composer .kp-field:has(> .kp-attach:not([hidden])) { padding-left: 4px; }

.kp-tmsg.is-me { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.kp-tmsg.is-me .kp-b { background: var(--me-bg); color: #fff; }
.kp-tmsg.is-me .kp-b.kp-b-file { background: var(--khio-bg); color: var(--ink); display: inline-flex; align-items: center; gap: 9px; padding: 6px 12px 6px 6px; }
.kp-tmsg-img { max-width: 200px; border-radius: 14px; box-shadow: 0 0 0 1px var(--line); display: block; }
.kp-tmsg.is-khio { min-width: 0; }
.kp-thinking { display: inline-flex; align-items: center; gap: 4px; padding: 6px 2px; }
.kp-thinking em { margin-left: 8px; font-style: normal; font-size: 13px; color: var(--ink-3); }
.kp-thinking.is-center { align-self: center; margin-top: 28px; }
.kp-terr { margin: 6px 0 0; padding: 9px 12px; border-radius: 10px; background: color-mix(in srgb, var(--bad) 9%, transparent); font-size: 14px; color: var(--bad); }

/* Answers are markdown, cleaned by DOMPurify, set like Ask AI's answers. */
.kp-md { font-size: 15px; line-height: 1.72; overflow-wrap: anywhere; }
.kp-md > :first-child { margin-top: 0; }
.kp-md > :last-child { margin-bottom: 0; }
.kp-md p { margin: .65em 0; }
.kp-md strong { font-weight: 650; }
.kp-md h1, .kp-md h2, .kp-md h3, .kp-md h4 { margin: 1.3em 0 .45em; line-height: 1.3; letter-spacing: -.012em; font-weight: 650; }
.kp-md h1 { font-size: 1.35em; } .kp-md h2 { font-size: 1.2em; } .kp-md h3 { font-size: 1.07em; } .kp-md h4 { font-size: 1em; }
.kp-md ul, .kp-md ol { margin: .6em 0; padding-left: 1.35em; }
.kp-md li { margin: .25em 0; }
.kp-md a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }
.kp-md code { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--hover-2); padding: 1px 5px; border-radius: 5px; }
.kp-md pre { background: var(--hover); border: 1px solid var(--line); padding: 12px 14px; border-radius: 12px; overflow-x: auto; }
.kp-md pre code { background: none; padding: 0; }
.kp-md blockquote { margin: .9em 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--line-2); color: var(--ink-2); }
.kp-md hr { border: 0; border-top: 1px solid var(--line); margin: 1.3em 0; }
.kp-md table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; display: block; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.kp-md th, .kp-md td { text-align: left; padding: 8px 11px; border-bottom: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
.kp-md tr:last-child td { border-bottom: 0; }
.kp-md th { font-weight: 600; font-size: 12.5px; color: var(--ink-2); background: var(--hover); }
.kp-md img { max-width: 100%; border-radius: 10px; }

.kp-files { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.kp-out { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 7px 10px; border-radius: 12px; color: inherit; text-decoration: none; border: 1px solid var(--line); background: var(--raised); }
@media (hover: hover) { .kp-out:hover { border-color: var(--line-2); } }
.kp-out-ic { flex: none; width: 32px; height: 32px; border-radius: 9px; background: color-mix(in srgb, var(--blue) 9%, transparent); color: var(--blue); display: inline-flex; align-items: center; justify-content: center; }
.kp-out-ic svg { width: 16px; height: 16px; }
.kp-out-tx { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.kp-out-title { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kp-out-sub { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kp-pic { display: block; max-width: 400px; border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 1px var(--line); }
.kp-pic.is-receipt { max-width: 280px; }
.kp-pic img { display: block; width: 100%; height: auto; }
.kp-sources { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.kp-sources-h { width: 100%; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); }
.kp-source { display: inline-flex; align-items: center; gap: 6px; max-width: 220px; min-height: 28px; padding: 0 10px 0 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); text-decoration: none; font-size: 12px; }
.kp-source img { width: 13px; height: 13px; border-radius: 3px; flex: none; }
.kp-source span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kp-watch { align-self: flex-start; display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--raised); cursor: pointer; font-size: 13.5px; font-weight: 600; }
.kp-watch svg { width: 16px; height: 16px; color: var(--blue); }

/* ── Section: computer (1024px and up) ─────────────────────────────────── */
/* The shell's rail and panel are the navigation; the chat sits centred at
   Ask AI's reading width, and a thread opens as a panel on its right. */
@media (min-width: 1024px) {
    #view-khio { --gutter: 28px; }
    .kp-chat::before { display: none; }
    .kp-menu-btn { display: none; }
    /* Install app is in the rail on a computer (khio-page.js). */
    .kp-install-btn { display: none; }
    /* The first message lines up with the top of the side cards. */
    .kp-scroll { padding-top: 12px; }
    .kp-datesep:first-child { margin-top: 0; }
    .kp-thread {
        position: relative; z-index: auto; inset: auto; flex: 0 0 min(460px, 42%);
        border-left: 1px solid var(--line); transform: none; opacity: 0; transition: opacity .2s ease;
    }
    .kp-thread.is-open { opacity: 1; }
    .kp-thread-top { padding: 10px 10px 10px 16px; }
    .kp-thread-back { display: none; }
    .kp-thread-close { display: inline-flex; }
    .kp-thread-scroll { padding: 18px 20px 12px; }
    .kp-toast { bottom: 36px; }
}

/* ── Section: Khio's panel ─────────────────────────────────────────────── */
/* After the Claude app's side panel (James 2026-10-16): tabs along the top,
   a welcome, then the threads under grey group headers. A phone opens it as
   a sheet from the top-right button; 1180px and up pins it on the right. */
.kp-card {
    position: fixed; z-index: 1160; top: calc(env(safe-area-inset-top) + 54px); right: max(10px, env(safe-area-inset-right));
    width: min(400px, calc(100vw - 20px)); max-height: calc(100dvh - env(safe-area-inset-top) - 70px); overflow-y: auto; overscroll-behavior: contain;
    display: flex; flex-direction: column; border: 1px solid var(--line-2); border-radius: 16px; background: var(--bg); box-shadow: var(--shadow);
    font-size: 14.5px; line-height: 1.35; scrollbar-width: none;
    opacity: 0; transform: translateY(-6px) scale(.98); transform-origin: top right; pointer-events: none; visibility: hidden;
    transition: opacity .16s ease, transform .2s var(--ease), visibility 0s linear .2s;
}
.kp-card::-webkit-scrollbar { display: none; }
.kp-card.is-open { opacity: 1; transform: none; pointer-events: auto; visibility: visible; transition: opacity .16s ease, transform .2s var(--ease), visibility 0s; }
.kp-card-scrim { position: fixed; inset: 0; z-index: 1155; background: transparent; }

/* The top bar, held at the top while the panel scrolls: the tabs (the open
   one a grey pill with its name, the others an icon; Threads carries a blue
   count of what is waiting on them), New thread, then Search, Filter, Expand and
   Close on the right. Search opens a field under it, Filter a small menu. */
.kp-head { position: sticky; top: 0; z-index: 2; padding: 10px 8px 4px 10px; background: var(--bg); }
.kp-tabs { display: flex; align-items: center; gap: 2px; }
.kp-tablist { display: flex; align-items: center; gap: 2px; min-width: 0; }
.kp-tab {
    flex: none; display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 8px; border: 0; border-radius: 8px;
    background: none; color: var(--ink-3); font-size: 14px; font-weight: 500; cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.kp-tab svg { width: 17px; height: 17px; flex: none; display: block; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.kp-tab span { display: none; }
.kp-tab.is-on { flex: 0 1 auto; min-width: 0; padding-right: 10px; background: var(--hover-2); color: var(--ink); }
.kp-tab.is-on span { display: inline; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (hover: hover) { .kp-tab:not(.is-on):hover { background: var(--hover); color: var(--ink-2); } }
.kp-tab-n {
    flex: none; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 5px; background: var(--blue); color: #fff;
    font-size: 11.5px; font-weight: 600; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums;
}
.kp-tools { display: flex; align-items: center; margin-left: auto; }
.kp-tool {
    flex: none; width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; padding: 0;
    border: 0; border-radius: 8px; background: none; color: var(--ink-2); cursor: pointer; transition: background .15s ease, color .15s ease;
}
.kp-tool svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) { .kp-tool:hover { background: var(--hover); color: var(--ink); } }
.kp-tool[aria-expanded="true"], .kp-tool.is-on { background: var(--hover-2); color: var(--ink); }
/* Expand only means something where the panel is pinned (below). */
.kp-tool-size { display: none; }
.kp-tool-size .kp-ico-shrink, .kp-tool-size[aria-pressed="true"] .kp-ico-grow { display: none; }
.kp-tool-size[aria-pressed="true"] .kp-ico-shrink { display: block; }
.kp-search {
    display: flex; align-items: center; gap: 8px; height: 36px; margin: 8px 2px 2px 0; padding: 0 12px;
    border: 1px solid transparent; border-radius: 10px; background: var(--hover); color: var(--ink-3); cursor: text;
    transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.kp-search:focus-within { background: var(--raised); border-color: var(--line-2); box-shadow: 0 0 0 3px var(--hover); color: var(--ink-2); }
.kp-search svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.kp-search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--ink); font: inherit; font-size: 14px; }
/* The shell gives every input a border, a fill and a round focus ring; in
   here the rounded box around it is the field (the "weird circles"). */
html body #view-khio .kp-search input, html body #kpSide .kp-search input {
    border: 0 !important; border-radius: 0 !important; background: none !important; box-shadow: none !important; outline: none !important;
    padding: 0 !important; margin: 0 !important; height: 100% !important; min-height: 0 !important; -webkit-appearance: none; appearance: none;
}
#view-khio .kp-search input::-webkit-search-cancel-button, .kp-side .kp-search input::-webkit-search-cancel-button { display: none; }
.kp-filter {
    position: absolute; z-index: 3; top: 46px; right: 8px; min-width: 210px; padding: 6px;
    border: 1px solid var(--line-2); border-radius: 12px; background: var(--raised); box-shadow: var(--shadow);
}
.kp-filter-opt { display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 8px; border-radius: 8px; font-size: 14px; color: var(--ink); cursor: pointer; }
.kp-filter-opt input { width: 15px; height: 15px; margin: 0; accent-color: var(--blue); }
@media (hover: hover) { .kp-filter-opt:hover { background: var(--hover); } }

.kp-pane { padding: 0 10px 14px; }
/* The panel's contents rise in one after another each time a tab shows,
   and again whenever the panel itself comes up (the name changes, so the
   animation starts over). The sparkline draws itself in. */
.kp-pane > * { animation: kp-pane-in .5s cubic-bezier(.2, .8, .2, 1) both; }
#kpChat:not(.is-front) ~ .kp-card .kp-pane > *,
#kpChat.is-front ~ .kp-front-edge:hover ~ .kp-card .kp-pane > *,
#kpChat.is-front ~ .kp-card:hover .kp-pane > * { animation-name: kp-pane-rise; }
.kp-pane > :nth-child(2) { animation-delay: .05s; }
.kp-pane > :nth-child(3) { animation-delay: .1s; }
.kp-pane > :nth-child(4) { animation-delay: .15s; }
.kp-pane > :nth-child(5) { animation-delay: .2s; }
.kp-pane > :nth-child(n+6) { animation-delay: .25s; }
@keyframes kp-pane-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes kp-pane-rise { from { opacity: 0; transform: translateY(14px); } }
.kp-spark-line { stroke-dasharray: 260; animation: kp-spark-draw 1.1s .2s cubic-bezier(.4, 0, .2, 1) both; }
.kp-spark-dot, .kp-spark-halo { animation: kp-pane-in .4s 1.1s ease both; }
@keyframes kp-spark-draw { from { stroke-dashoffset: 260; } to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .kp-pane > *, .kp-spark-line, .kp-spark-dot, .kp-spark-halo { animation: none !important; } }

/* Welcome back, in the landing's serif, with the last two weeks beside it. */
.kp-welcome { display: flex; align-items: center; gap: 12px; padding: 18px 10px 16px; }
.kp-welcome-tx { flex: 1; min-width: 0; }
.kp-welcome-title { margin: 0; font: 500 23px/1.15 var(--k-display, Georgia, serif); letter-spacing: -.02em; color: var(--ink); text-wrap: balance; }
.kp-welcome-sub { margin: 5px 0 0; font-size: 13.5px; color: var(--ink-3); }
.kp-spark { flex: none; width: 108px; height: 40px; overflow: visible; }
.kp-spark pattern circle { fill: var(--ink); opacity: .32; }
.kp-spark-line { fill: none; stroke: var(--good); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.kp-spark-dot { fill: var(--good); }
.kp-spark-halo { fill: var(--good); opacity: .16; }

.kp-acts { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 10px 16px; }
.kp-acts:has(> #kpText[hidden]) { display: none; }
.kp-act {
    display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px 0 10px; border: 1px solid var(--line-2); border-radius: 999px;
    background: var(--bg); color: var(--ink); font-size: 13.5px; font-weight: 500; text-decoration: none; cursor: pointer; transition: background .15s ease;
}
.kp-act svg { width: 15px; height: 15px; flex: none; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) { .kp-act:hover { background: var(--hover); } }

/* A group: a grey header with its count, its rows lined up under the name,
   or one quiet line saying what would be there. */
.kp-grp + .kp-grp { margin-top: 8px; }
.kp-grp-head {
    display: flex; align-items: center; gap: 8px; width: 100%; min-height: 36px; padding: 0 12px 0 10px; border: 0; border-radius: 8px;
    background: var(--hover); color: var(--ink); font-size: 14.5px; font-weight: 500; text-align: left;
}
button.kp-grp-head { cursor: pointer; }
.kp-grp-chev { width: 15px; height: 15px; flex: none; display: block; fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s var(--ease); }
.kp-grp.is-empty .kp-grp-chev { visibility: hidden; }
.kp-grp.is-shut .kp-grp-chev { transform: rotate(-90deg); }
.kp-grp-n { color: var(--ink-3); font-weight: 400; font-variant-numeric: tabular-nums; }
.kp-grp-list { display: flex; flex-direction: column; padding-top: 4px; }
.kp-grp-list:empty, .kp-grp.is-shut .kp-grp-list, .kp-grp.is-shut .kp-card-more { display: none; }
.kp-grp .kp-card-row { padding-left: 33px; }
.kp-grp .kp-card-more { margin-left: 27px; }
.kp-grp-empty { margin: 0; padding: 12px 12px 6px 33px; font-size: 13.5px; line-height: 1.45; color: var(--ink-3); }
.kp-grp:not(.is-empty) .kp-grp-empty, .kp-grp.is-shut .kp-grp-empty { display: none; }

.kp-card-list { display: flex; flex-direction: column; }
.kp-card-row {
    display: flex; align-items: center; gap: 12px; width: 100%; min-height: 38px; padding: 6px 12px 6px 8px; border: 0; border-radius: 8px;
    background: transparent; color: var(--ink); text-align: left; text-decoration: none; font-size: 14.5px; cursor: pointer;
    transition: background .15s ease;
}
@media (hover: hover) { .kp-card-row:hover { background: var(--hover); } }
.kp-card-row:active, .kp-card-row.is-open { background: var(--hover-2); }
.kp-card-row-tx { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* A thread row's two lines: the title, then how it ended and its summary. */
.kp-row-tx { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.kp-row-sub { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kp-row-state { font-weight: inherit; color: var(--ink-2); }
.kp-row-state[data-status="failed"] { color: var(--bad); }
.kp-row-state[data-status="waiting"] { color: var(--wait); }
.kp-row-meta { flex: none; margin-left: auto; font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.kp-ci { flex: none; width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); }
.kp-ci svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.kp-card-more { margin: 2px 0; padding: 5px 6px; border: 0; background: none; color: var(--ink-2); font-size: 13.5px; font-weight: 500; cursor: pointer; border-radius: 7px; }
@media (hover: hover) { .kp-card-more:hover { color: var(--ink); background: var(--hover); } }
[data-pane="outputs"] .kp-card-list { padding-top: 10px; }

/* Scheduled tasks: the routine in their words, then when it runs. */
.kp-sched { display: flex; align-items: flex-start; gap: 12px; padding: 10px 8px; }
.kp-sched:first-child { margin-top: 6px; }
.kp-sched .kp-ci { margin-top: 1px; }
.kp-sched-tx { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.kp-sched-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--ink); }
.kp-sched-meta { font-size: 13px; color: var(--ink-3); }

/* An empty tab: an icon and one line, in the middle of the panel. */
.kp-pane.is-empty { flex: 1 0 auto; display: flex; flex-direction: column; }
.kp-pane-empty {
    display: flex; flex-direction: column; align-items: center; gap: 14px; margin: auto 0; padding: 72px 28px;
    text-align: center; font-size: 14px; line-height: 1.5; color: var(--ink-2); text-wrap: balance;
}
.kp-pane-empty svg { width: 26px; height: 26px; display: block; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.kp-pane:not(.is-empty) .kp-pane-empty { display: none; }

/* Wide screens: the panel runs down the right of the chat, and the chat
   keeps clear of it. Expand widens it; Close hides it and the top-right
   button brings it back. While a thread is open the thread panel takes the
   right instead. */
@media (min-width: 1180px) {
    #view-khio { --kp-panel-w: 400px; }
    #view-khio.kp-panel-wide { --kp-panel-w: min(640px, 46vw); }
    .kp-card-btn { display: none; }
    .kp-card, .kp-card.is-open {
        position: absolute; z-index: 6; top: 12px; right: 12px; bottom: 12px; width: var(--kp-panel-w); max-height: none;
        box-shadow: none; opacity: 1; transform: none; pointer-events: auto; visibility: visible;
    }
    .kp-card-scrim { display: none !important; }
    .kp-tool-size { display: inline-flex; }
    /* The chat keeps clear of the panel on both sides (Section: agents). */
    #view-khio { --kp-right: calc(var(--kp-panel-w) + 24px); }
    /* The opening screen has the whole width: the panel slides down out of
       sight and comes back up when the chat opens (James 2026-10-18). */
    .kp-card { transition: transform .45s cubic-bezier(.2, .8, .2, 1), opacity .3s ease; }
    #kpChat.is-front ~ .kp-card { transform: translateY(calc(100% + 24px)); opacity: 0; pointer-events: none; }
    /* ...and comes up while the pointer is at the right edge or on it. */
    #kpChat.is-front ~ .kp-front-edge { display: block; position: fixed; z-index: 6; top: 0; right: 0; bottom: 0; width: 22px; }
    #kpChat.is-front ~ .kp-front-edge:hover ~ .kp-card, #kpChat.is-front ~ .kp-card:hover { transform: none; opacity: 1; pointer-events: auto; }
    #view-khio.kp-panel-off .kp-card { display: none; }
    #view-khio.kp-panel-off, body.kp-thread-on #view-khio { --kp-right: 0px; }
    #view-khio.kp-panel-off .kp-card-btn { display: inline-flex; top: 12px; }
    body.kp-thread-on .kp-card { display: none; }
}
@media (min-width: 1024px) and (max-width: 1179px) {
    .kp-card-btn { top: 12px; }
}

/* ── Section: agents ───────────────────────────────────────────────────── */
/* James 2026-10-18: a sidebar of agents down the left of a computer, after
   the agent lists in chat apps: Khio first, then the agents the person made,
   each a round coloured avatar, its name, its last line and when. The chat
   column is centred where it fits and clears each side (--kp-left here,
   --kp-right from the pinned panel). An open agent's chat is the thread view
   taking the middle (.kp-thread.is-agent). A phone has no sidebar.
   Since 2026-10-19 Keeps and Spaces wear it too, in place of the rail and
   the shell's panel: it is one copy outside the views (study.html #kpSide),
   and khio-page.js paintSide says where it shows with classes on <html>:
     kp-side-on     shown here (/khio, Keeps, Spaces on the one-thread web)
     kp-side-page   on Keeps or Spaces, where it takes the rail's place
     kp-side-front  /khio's opening screen is up, so it waits off the left
     kp-side-off    closed by the person (remembered on this browser) */
.kp-agents, .kp-agents-open, .kp-dlg-scrim { display: none; }
@media (min-width: 1024px) {
    html { --kp-agents-w: 288px; }
    #view-khio { --kp-left: calc(var(--kp-agents-w) + 24px); --kp-clear: max(var(--kp-left), var(--kp-right, 0px)); }
    /* Closed: the chat takes the left too (khio-page.js setAgentsOpen). */
    html.kp-side-off #view-khio { --kp-left: 0px; }
    html.kp-side-off .kp-agents { transform: translateX(calc(-100% - 24px)); opacity: 0; pointer-events: none; visibility: hidden; transition: transform .4s cubic-bezier(.2, .8, .2, 1), opacity .25s ease, visibility 0s linear .4s; }
    /* Keeps and Spaces: no rail and no panel, and the page clears the
       sidebar (or, closed, the button that brings it back). */
    html.kp-side-on.kp-side-page .khio-rail,
    html.kp-side-on.kp-side-page #studySidebar { display: none !important; }
    html.kp-side-on.kp-side-page #app { margin-left: calc(var(--kp-agents-w) + 24px); transition: margin-left .4s cubic-bezier(.2, .8, .2, 1); }
    html.kp-side-on.kp-side-page.kp-side-off #app { margin-left: 0; }
    .kp-agents-open {
        position: fixed; z-index: 61; top: 12px; left: 12px; width: 36px; height: 36px; padding: 0;
        display: none; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 10px;
        background: var(--bg); color: var(--ink-2); cursor: pointer; transition: background .15s ease, color .15s ease;
    }
    .kp-agents-open svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
    @media (hover: hover) { .kp-agents-open:hover { background: var(--hover); color: var(--ink); } }
    html.kp-side-on.kp-side-off:not(.kp-side-front) .kp-agents-open { display: inline-flex; }
    /* Each side clears only what is on it, so opening the Threads panel does
       not squeeze the chat from the left as well (Lake 2026-10-19). */
    #view-khio .kp-scroll { padding-left: max(var(--gutter), calc((100% - var(--read)) / 2), var(--kp-left)); padding-right: max(var(--gutter), calc((100% - var(--read)) / 2), var(--kp-right, 0px)); }
    /* The box sits under the messages, the same width and place. */
    #kpComposer { left: max(var(--gutter), calc((100% - var(--read)) / 2), var(--kp-left)); right: max(var(--gutter), calc((100% - var(--read)) / 2), var(--kp-right, 0px)); }
    #kpChat.is-front #kpComposer { left: 0; right: 0; }
    /* A task thread open on the right: the chat keeps clear of the sidebar only. */
    body.kp-thread-on #view-khio .kp-scroll { padding-left: max(var(--kp-left), calc((100% - var(--read)) / 2)); padding-right: max(var(--gutter), calc((100% - var(--read)) / 2)); }
    body.kp-thread-on #kpComposer { left: var(--kp-left); right: 0; }

    html.kp-side-on .kp-agents { display: flex; }
    .kp-agents {
        position: fixed; z-index: 60; top: 12px; left: 12px; bottom: 12px; width: var(--kp-agents-w);
        flex-direction: column; border: 1px solid var(--line); border-radius: 16px; background: var(--bg);
        font-size: 14.5px; line-height: 1.35;
        transition: transform .5s cubic-bezier(.2, .8, .2, 1), opacity .3s ease;
    }
    /* Away while the opening screen is up; it slides in with the chat. */
    html.kp-side-front .kp-agents { transform: translateX(calc(-100% - 24px)); opacity: 0; pointer-events: none; }
    .kp-agents-head { display: flex; align-items: center; gap: 6px; padding: 12px 8px 2px 16px; }
    .kp-agents-title { flex: 1; margin: 0; font: 500 21px/1.2 var(--k-display, Georgia, serif); letter-spacing: -.02em; color: var(--ink); }
    .kp-agents-search { margin: 8px 10px 6px; }
    .kp-agents-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 2px 8px 10px; scrollbar-width: none; }
    .kp-agents-list::-webkit-scrollbar { display: none; }

    /* A row: the avatar, the name and its time, the last line under them.
       The rows rise in one after another when the sidebar comes in. */
    .kp-agent { position: relative; animation: kp-agent-in .45s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(min(var(--i, 0), 10) * 35ms); }
    html:not(.kp-side-front) .kp-agents .kp-agent { animation-name: kp-agent-rise; }
    @keyframes kp-agent-in { from { opacity: 0; transform: translateX(-8px); } }
    @keyframes kp-agent-rise { from { opacity: 0; transform: translateX(-12px); } }
    .kp-agent-row {
        display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 10px; border: 0; border-radius: 10px;
        background: transparent; color: var(--ink); text-align: left; cursor: pointer; transition: background .15s ease;
    }
    @media (hover: hover) { .kp-agent-row:hover { background: var(--hover); } }
    .kp-agent-row.is-on { background: var(--hover-2); }
    .kp-agent-tx { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
    .kp-agent-top { display: flex; align-items: baseline; gap: 8px; }
    .kp-agent-name { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 600; letter-spacing: -.005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .kp-agent-when { flex: none; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
    /* Something new since it was last open. */
    .kp-agent-dot { flex: none; align-self: center; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); }
    .kp-agent-row.is-unread .kp-agent-prev { color: var(--ink-2); }
    .kp-agent-prev { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    /* When it runs on its own ("Weekdays 8:00 AM"), under the name. */
    .kp-agent-sched { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .kp-agent-sched svg { flex: none; width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
    /* The three dots: in place of the time, on hover or focus. */
    .kp-agent-more {
        position: absolute; top: 7px; right: 6px; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 7px;
        display: inline-flex; align-items: center; justify-content: center; background: transparent; color: var(--ink-2); cursor: pointer;
        opacity: 0; transition: opacity .15s ease, background .15s ease;
    }
    .kp-agent-more svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
    .kp-agent:hover .kp-agent-more, .kp-agent-more:focus-visible { opacity: 1; }
    .kp-agent:hover .kp-agent-when, .kp-agent:focus-within .kp-agent-when { visibility: hidden; }
    @media (hover: hover) { .kp-agent-more:hover { background: var(--hover-2); color: var(--ink); } }
    .kp-agent-menu {
        position: absolute; z-index: 8; min-width: 150px; padding: 5px;
        border: 1px solid var(--line-2); border-radius: 12px; background: var(--raised); box-shadow: var(--shadow);
    }
    .kp-agent-menu button { display: block; width: 100%; height: 34px; padding: 0 10px; border: 0; border-radius: 8px; background: none; text-align: left; font-size: 14px; color: var(--ink); cursor: pointer; }
    .kp-agent-menu button.is-bad { color: var(--bad); }
    @media (hover: hover) { .kp-agent-menu button:hover { background: var(--hover); } }

    /* Keeps and Spaces under the search, Settings at the foot: the same
       quiet rows. */
    .kp-agents-nav { display: flex; flex-direction: column; padding: 0 8px 6px; margin-bottom: 4px; }
    .kp-agents-link {
        display: flex; align-items: center; gap: 11px; height: 36px; padding: 0 10px; border-radius: 10px;
        color: var(--ink); text-decoration: none; font-size: 14.5px; font-weight: 500; transition: background .15s ease;
    }
    .kp-agents-link svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--ink-2); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
    @media (hover: hover) { .kp-agents-link:hover { background: var(--hover); } }
    /* The section showing, on Keeps or Spaces (khio-page.js paintSide). */
    .kp-agents-link.is-on { background: var(--hover-2); }
    /* The foot: Download on desktop, New agent under it, then Settings. */
    .kp-agents-foot { display: flex; flex-direction: column; gap: 8px; padding: 10px 10px 10px; }
    .kp-agents-btn {
        display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: 10px;
        background: var(--bg); color: var(--ink); font-size: 14px; font-weight: 500; cursor: pointer; transition: background .15s ease;
    }
    .kp-agents-btn svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
    @media (hover: hover) { .kp-agents-btn:hover { background: var(--hover); } }
    .kp-agents-btn.is-primary { border-color: transparent; background: var(--ink); color: var(--on-ink); }
    @media (hover: hover) { .kp-agents-btn.is-primary:hover { background: color-mix(in srgb, var(--ink) 86%, transparent); } }
    .kp-agents-settings { margin-top: -2px; }

    /* An agent's chat, in the middle of the page between the two sides, over
       the one chat (and its floating composer, which comes before it). */
    .kp-thread.is-agent {
        position: absolute; z-index: 5; inset: 0; flex: none; border-left: 0;
        --kp-agent-side: max(var(--gutter), calc((100% - var(--read)) / 2), var(--kp-clear));
        opacity: 0; transform: translateY(8px); transition: opacity .22s ease, transform .35s var(--ease);
    }
    .kp-thread.is-agent.is-open { opacity: 1; transform: none; }
    .kp-thread.is-agent .kp-thread-top { padding: 14px var(--kp-agent-side) 10px; box-shadow: none; }
    .kp-thread.is-agent .kp-thread-scroll { padding: 12px var(--kp-agent-side) 12px; }
    .kp-thread.is-agent .kp-thread-composer { padding-left: var(--kp-agent-side); padding-right: var(--kp-agent-side); }
    .kp-thread.is-agent .kp-thread-body, .kp-thread.is-agent .kp-thread-composer .kp-field, .kp-thread.is-agent .kp-thread-composer .kp-pending { max-width: none; }
    .kp-thread.is-agent .kp-thread-title { font: 500 19px/1.25 var(--k-display, Georgia, serif); letter-spacing: -.015em; }
}
@media (min-width: 1440px) { html { --kp-agents-w: 316px; } }
/* Too narrow for the sidebar, the chat and a task thread at once: the
   sidebar steps aside while the thread is open. */
@media (min-width: 1024px) and (max-width: 1279px) {
    html:not(.kp-side-page) body.kp-thread-on .kp-agents { display: none; }
    body.kp-thread-on #view-khio { --kp-left: var(--gutter); }
}

/* A round coloured avatar with the agent's initials; Khio's is its mark. */
.kp-ava {
    flex: none; width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    background: var(--ava, var(--blue)); color: #fff; font-size: 13.5px; font-weight: 600; letter-spacing: .02em; overflow: hidden;
}
.kp-ava.is-khio { background: #0b0b0d; box-shadow: inset 0 0 0 1px var(--line); }
.kp-ava.is-khio img { width: 100%; height: 100%; object-fit: cover; }
.kp-ava.is-mascot img { width: 100%; height: 100%; object-fit: cover; }
.kp-thread-ava { width: 34px; height: 34px; font-size: 12.5px; margin-right: 4px; }
.kp-thread-job { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* An agent with no messages yet: who it is and what it is for. */
.kp-agent-intro { display: flex; flex-direction: column; align-items: center; text-align: center; margin: 12vh auto 0; max-width: 440px; animation: kp-pane-in .5s cubic-bezier(.2, .8, .2, 1) both; }
.kp-agent-intro .kp-ava { width: 64px; height: 64px; font-size: 22px; margin-bottom: 14px; }
.kp-agent-intro-name { margin: 0 0 8px; font: 500 28px/1.1 var(--k-display, Georgia, serif); letter-spacing: -.02em; }
.kp-agent-intro-job { margin: 0 0 10px; font-size: 14.5px; line-height: 1.5; color: var(--ink-2); white-space: pre-line; text-wrap: pretty; }
.kp-agent-intro-hint { margin: 0; font-size: 13px; color: var(--ink-3); }

/* New agent and Edit: a small card over a soft scrim. */
@media (min-width: 1024px) { .kp-dlg-scrim:not([hidden]) { display: flex; } }
.kp-dlg-scrim {
    position: fixed; z-index: 1200; inset: 0; align-items: center; justify-content: center; padding: 24px;
    background: rgba(17, 17, 20, .22); opacity: 0; transition: opacity .18s ease;
}
html[data-theme="dark"] .kp-dlg-scrim { background: rgba(0, 0, 0, .55); }
.kp-dlg-scrim.is-open { opacity: 1; }
.kp-dlg {
    width: min(440px, 100%); padding: 20px 20px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--raised); box-shadow: 0 18px 48px rgba(17, 17, 20, .18);
    transform: translateY(8px) scale(.98); transition: transform .25s var(--ease);
}
.kp-dlg-scrim.is-open .kp-dlg { transform: none; }
.kp-dlg-title { margin: 0 0 16px; font: 500 23px/1.15 var(--k-display, Georgia, serif); letter-spacing: -.02em; }
.kp-dlg-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.kp-dlg-field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
html body #kpSide .kp-dlg-field input, html body #kpSide .kp-dlg-field textarea, html body #kpSide .kp-dlg-field select {
    width: 100%; margin: 0; padding: 9px 12px; border: 1px solid var(--line-2) !important; border-radius: 10px !important;
    background: var(--bg) !important; color: var(--ink); font: 400 14.5px/1.45 var(--k-sans, 'Inter', system-ui, sans-serif); box-shadow: none !important; outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
html body #kpSide .kp-dlg-field textarea { resize: vertical; min-height: 96px; }
html body #kpSide .kp-dlg-field input:focus, html body #kpSide .kp-dlg-field textarea:focus, html body #kpSide .kp-dlg-field select:focus { border-color: var(--blue) !important; box-shadow: 0 0 0 3px var(--blue-ring) !important; }
/* Runs: how often, then the day (weekly) and the time, in one row. */
.kp-dlg-runs { display: flex; gap: 8px; }
.kp-dlg-runs > * { flex: 1; min-width: 0; }
.kp-dlg-colors { display: flex; flex-wrap: wrap; gap: 8px; }
.kp-dlg-color {
    width: 26px; height: 26px; padding: 0; border: 0; border-radius: 50%; background: var(--ava); cursor: pointer;
    box-shadow: 0 0 0 2px var(--raised), 0 0 0 2px transparent; transition: box-shadow .15s ease, transform .15s ease;
}
.kp-dlg-color[aria-checked="true"] { box-shadow: 0 0 0 2px var(--raised), 0 0 0 4px var(--ava); }
@media (hover: hover) { .kp-dlg-color:hover { transform: scale(1.08); } }
.kp-dlg-err { margin: -4px 0 12px; font-size: 13px; color: var(--bad); }
.kp-dlg-acts { display: flex; justify-content: flex-end; gap: 8px; }
.kp-dlg-btn {
    height: 36px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--bg); color: var(--ink);
    font-size: 14px; font-weight: 500; cursor: pointer; transition: background .15s ease;
}
@media (hover: hover) { .kp-dlg-btn:hover { background: var(--hover); } }
.kp-dlg-btn.is-primary { border-color: transparent; background: var(--ink); color: var(--on-ink); }
@media (hover: hover) { .kp-dlg-btn.is-primary:hover { background: color-mix(in srgb, var(--ink) 85%, transparent); } }
.kp-dlg-btn:disabled { opacity: .5; cursor: default; }

/* ── Section: the panel's thread rows (study-deeptutor.js) ─────────────── */
/* A working thread's row icon: a small spinner in the panel's icon slot. */
.khio-panel-row-icon.kp-pst.is-working::before {
    content: ''; width: 11px; height: 11px; border-radius: 50%;
    border: 1.5px solid rgba(0, 113, 227, .25); border-top-color: #0071e3; animation: kp-spin .8s linear infinite;
}
.dt2-recents-row[data-status="done"] .khio-panel-row-icon { color: #1f8f47; }
.dt2-recents-row[data-status="failed"] .khio-panel-row-icon { color: #d93025; }
html[data-theme="dark"] .dt2-recents-row[data-status="done"] .khio-panel-row-icon { color: #30d158; }
html[data-theme="dark"] .dt2-recents-row[data-status="failed"] .khio-panel-row-icon { color: #ff5c5c; }
html[data-theme="dark"] .khio-panel-row-icon.kp-pst.is-working::before { border-color: rgba(64, 156, 255, .3); border-top-color: #409cff; }
/* The current place among Khio, Keeps and Spaces, lit like a chosen row. */
html body #navKhioAI > .khio-panel-new.is-here { background: rgba(17, 17, 20, .06) !important; }
html[data-theme="dark"] body #navKhioAI > .khio-panel-new.is-here { background: rgba(255, 255, 255, .08) !important; }
/* The three rows sit together; the New Keep row's gap comes after the last. */
html body .study-layout #navKhioAI > .khio-panel-new.khio-panel-new.khio-panel-new.khio-panel-new[data-panel-act="khio"],
html body .study-layout #navKhioAI > .khio-panel-new.khio-panel-new.khio-panel-new.khio-panel-new[data-panel-act="keeps"] { margin-bottom: 0 !important; }

/* ── Section: Phone drawer ─────────────────────────────────────────────── */
/* Below 1024px the shell's .study-layout.kp-sb-open shows .study-sidebar
   (switcher, the Khio panel, account row) as a card over the page, the way a
   computer shows it beside the chat. */
@media (max-width: 1023px) {
    html body .study-layout.kp-sb-open .study-sidebar {
        display: flex !important; flex-direction: column !important;
        position: fixed !important; z-index: 1150 !important; top: calc(env(safe-area-inset-top) + 8px) !important; bottom: calc(env(safe-area-inset-bottom) + 8px) !important; left: 8px !important;
        width: min(300px, calc(100vw - 56px)) !important; height: auto !important; max-width: none !important;
        border: 1px solid rgba(17, 17, 20, .09) !important; border-radius: 16px !important;
        background: #ffffff !important; box-shadow: 0 18px 48px rgba(17, 17, 20, .18) !important;
        transform: translateX(-110%); transition: transform .3s cubic-bezier(.22, 1, .36, 1) !important; overflow: hidden !important;
    }
    html body .study-layout.kp-sb-open.kp-sb-in .study-sidebar { transform: none; }
    /* The phone's own nav-link sizing is taller; the drawer keeps the panel's. */
    html body .study-layout.kp-sb-open #navKhioAI > .khio-panel-new.khio-panel-new { min-height: 38px !important; padding-top: 8px !important; padding-bottom: 8px !important; }
    html[data-theme="dark"] body .study-layout.kp-sb-open .study-sidebar { background: #141416 !important; border-color: rgba(255, 255, 255, .09) !important; box-shadow: 0 18px 48px rgba(0, 0, 0, .6) !important; }
}
.kp-sb-scrim { position: fixed; inset: 0; z-index: 1140; background: rgba(17, 17, 20, .22); opacity: 0; pointer-events: none; transition: opacity .25s ease; }
.kp-sb-scrim.open { opacity: 1; pointer-events: auto; }
html[data-theme="dark"] .kp-sb-scrim { background: rgba(0, 0, 0, .55); }

/* ── Section: reduced motion ───────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .kp-thread, .kp-tobottom, .kp-toast, .kp-sb-scrim, .study-layout.kp-sb-open .study-sidebar, .kp-agents, .kp-dlg-scrim, .kp-dlg { transition: none !important; }
    .kp-row.is-new, .kp-agent, .kp-agent-intro { animation: none !important; }
    .kp-rm.is-working i { animation-duration: 2.4s; }
    .kp-st.is-working, .khio-panel-row-icon.kp-pst.is-working::before, .kp-typing span, .kp-thinking span { animation-duration: 2.4s; }
}
