/* ═══════════════════════════════════════════════════════════════
   Jarvis — floating assistant widget
   Reuses the site tokens from style.css, so the palette follows the
   brand automatically. Everything is namespaced .kb-* to keep it
   isolated from the rest of the design system.
═══════════════════════════════════════════════════════════════ */

.kb-chat {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 150;
    font-family: var(--font-body);
}

.kb-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- Launcher orb ---------- */
.kb-orb {
    position: relative;
    display: grid;
    place-items: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--grad);
    color: var(--brand-ink);
    box-shadow: var(--shadow-brand), 0 10px 30px -10px rgba(0, 0, 0, .8);
    transition: transform .35s var(--ease), box-shadow .35s var(--ease);
}

.kb-orb:hover { transform: translateY(-3px) scale(1.05); }
.kb-orb:active { transform: scale(.96); }

.kb-orb-core,
.kb-orb-close {
    grid-area: 1 / 1;
    display: grid;
    place-items: center;
    transition: opacity .25s var(--ease), transform .35s var(--ease);
}

.kb-orb-close { opacity: 0; transform: rotate(-90deg) scale(.6); }

.kb-chat.is-open .kb-orb-core { opacity: 0; transform: rotate(90deg) scale(.6); }
.kb-chat.is-open .kb-orb-close { opacity: 1; transform: none; }

/* Two expanding rings — the "listening" pulse. */
.kb-orb-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 1.5px solid var(--brand);
    opacity: 0;
    animation: kb-ping 3s var(--ease) infinite;
    pointer-events: none;
}

.kb-orb-ring-2 { animation-delay: 1.4s; }
.kb-chat.is-open .kb-orb-ring { animation: none; }

@keyframes kb-ping {
    0%   { transform: scale(1);   opacity: .55; }
    70%  { transform: scale(1.9); opacity: 0; }
    100% { transform: scale(1.9); opacity: 0; }
}

/* Unread / attention dot */
.kb-orb-dot {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #FF5D5D;
    border: 2px solid var(--bg);
    opacity: 0;
    transform: scale(.4);
    transition: opacity .3s var(--ease), transform .3s var(--ease);
}

.kb-chat.has-unread .kb-orb-dot { opacity: 1; transform: none; }

/* ---------- Idle nudge bubble ---------- */
.kb-nudge {
    position: absolute;
    right: 74px;
    bottom: 16px;
    padding: 9px 15px;
    border-radius: var(--r-pill);
    background: var(--panel-2);
    border: 1px solid var(--line-brand);
    color: var(--ink);
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: var(--shadow-1);
    opacity: 0;
    transform: translateX(10px);
    pointer-events: none;
    transition: opacity .4s var(--ease), transform .4s var(--ease);
}

.kb-chat.show-nudge .kb-nudge { opacity: 1; transform: none; }
.kb-chat.is-open .kb-nudge { opacity: 0; }

/* ---------- Panel ---------- */
.kb-panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    display: flex;
    flex-direction: column;
    width: min(392px, calc(100vw - 32px));
    height: min(608px, calc(100vh - 132px));
    overflow: hidden;
    border-radius: var(--r-lg);
    border: 1px solid var(--line-2);
    background: linear-gradient(180deg, rgba(16, 27, 22, .96), rgba(8, 17, 13, .98));
    backdrop-filter: blur(22px) saturate(140%);
    -webkit-backdrop-filter: blur(22px) saturate(140%);
    box-shadow: var(--shadow-2), 0 0 0 1px rgba(52, 211, 153, .07) inset;
    opacity: 0;
    transform: translateY(18px) scale(.96);
    transform-origin: bottom right;
    transition: opacity .3s var(--ease), transform .35s var(--ease);
}

.kb-panel[hidden] { display: none; }
.kb-chat.is-open .kb-panel { opacity: 1; transform: none; }

/* Aurora smear behind the glass */
.kb-panel-glow {
    position: absolute;
    top: -45%;
    left: -25%;
    width: 150%;
    height: 90%;
    background: radial-gradient(closest-side, rgba(52, 211, 153, .22), transparent 72%);
    filter: blur(12px);
    animation: kb-drift 14s ease-in-out infinite alternate;
    pointer-events: none;
}

@keyframes kb-drift {
    from { transform: translate3d(-6%, 0, 0) scale(1); }
    to   { transform: translate3d(12%, 6%, 0) scale(1.15); }
}

/* Faint circuit grid */
.kb-grid-bg {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(52, 211, 153, .05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(52, 211, 153, .05) 1px, transparent 1px);
    background-size: 34px 34px;
    mask-image: radial-gradient(closest-side at 50% 0%, #000, transparent 85%);
    -webkit-mask-image: radial-gradient(closest-side at 50% 0%, #000, transparent 85%);
    pointer-events: none;
}

/* ---------- Header ---------- */
.kb-head {
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 14px 14px 13px 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .015);
}

.kb-avatar {
    position: relative;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: none;
    border-radius: 50%;
    background: var(--grad);
    color: var(--brand-ink);
}

.kb-avatar-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 1px solid var(--brand);
    opacity: .35;
    animation: kb-breathe 2.8s ease-in-out infinite;
}

@keyframes kb-breathe {
    0%, 100% { transform: scale(1);    opacity: .35; }
    50%      { transform: scale(1.12); opacity: .05; }
}

.kb-head-text { display: flex; flex-direction: column; line-height: 1.25; margin-right: auto; }
.kb-head-text strong {
    font-family: var(--font-display);
    font-size: 15.5px;
    font-weight: 600;
    letter-spacing: .01em;
    color: var(--ink);
}

.kb-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: var(--muted);
}

.kb-status i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--brand);
    box-shadow: 0 0 0 0 var(--brand-glow);
    animation: kb-blink 2.2s ease-in-out infinite;
}

@keyframes kb-blink {
    0%, 100% { box-shadow: 0 0 0 0 var(--brand-glow); }
    50%      { box-shadow: 0 0 0 5px rgba(52, 211, 153, 0); }
}

.kb-icon-btn {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: var(--r-sm);
    color: var(--muted);
    transition: color .2s var(--ease), background .2s var(--ease);
}

.kb-icon-btn:hover { color: var(--ink); background: rgba(255, 255, 255, .06); }

/* ---------- Log ---------- */
.kb-log {
    position: relative;
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 18px 16px 6px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .16) transparent;
}

.kb-log::-webkit-scrollbar { width: 6px; }
.kb-log::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .14); border-radius: 99px; }

.kb-msg {
    max-width: 84%;
    padding: 11px 14px;
    font-size: 14.5px;
    line-height: 1.6;
    border-radius: 16px;
    animation: kb-rise .35s var(--ease) both;
    overflow-wrap: anywhere;
}

@keyframes kb-rise {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

.kb-msg-bot {
    align-self: flex-start;
    border-bottom-left-radius: 5px;
    background: var(--panel-3);
    border: 1px solid var(--line);
    color: var(--ink-2);
}

.kb-msg-user {
    align-self: flex-end;
    border-bottom-right-radius: 5px;
    background: var(--grad);
    color: var(--brand-ink);
    font-weight: 500;
    box-shadow: var(--shadow-brand);
}

.kb-msg a { color: var(--brand-2); text-decoration: underline; text-underline-offset: 2px; }
.kb-msg-user a { color: var(--brand-ink); }
.kb-msg strong { color: var(--ink); font-weight: 600; }
.kb-msg-user strong { color: inherit; }
.kb-msg ul { margin: 6px 0 0; padding-left: 16px; list-style: disc; }
.kb-msg li { margin: 2px 0; }
.kb-msg p + p { margin-top: 8px; }

/* Delivery confirmation line */
.kb-note {
    align-self: center;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 13px;
    border-radius: var(--r-pill);
    background: var(--brand-soft);
    border: 1px solid var(--line-brand);
    color: var(--brand-2);
    font-size: 12px;
    animation: kb-rise .35s var(--ease) both;
}

/* Caret that trails the streaming reply */
.kb-caret {
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 2px;
    vertical-align: -2px;
    border-radius: 1px;
    background: var(--brand);
    animation: kb-blink .9s steps(1) infinite;
}

@keyframes kb-blink {
    0%, 49%  { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* A bubble that types itself out must not re-run the slide-up entrance on
   every repaint — it just fades in once and then grows with the text. */
.kb-msg-streaming { animation: kb-fade .22s var(--ease) both; }

@keyframes kb-fade {
    from { opacity: .001; }
    to   { opacity: 1; }
}

/* Typing indicator */
.kb-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 13px 15px;
    border-radius: 16px 16px 16px 5px;
    background: var(--panel-3);
    border: 1px solid var(--line);
}

.kb-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--brand);
    animation: kb-bounce 1.3s ease-in-out infinite;
}

.kb-typing span:nth-child(2) { animation-delay: .16s; }
.kb-typing span:nth-child(3) { animation-delay: .32s; }

@keyframes kb-bounce {
    0%, 60%, 100% { transform: none;             opacity: .35; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Quick chips ---------- */
.kb-chips {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 10px 16px 4px;
}

.kb-chips:empty,
.kb-chips[hidden] { display: none; }

.kb-chip {
    padding: 7px 13px;
    border-radius: var(--r-pill);
    border: 1px solid var(--line-2);
    background: rgba(255, 255, 255, .03);
    color: var(--ink-2);
    font-size: 12.5px;
    transition: border-color .2s var(--ease), color .2s var(--ease), transform .2s var(--ease);
}

.kb-chip:hover {
    border-color: var(--brand);
    color: var(--brand-2);
    transform: translateY(-1px);
}

/* ---------- Composer ---------- */
.kb-composer {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 9px;
    margin: 10px 12px 0;
    padding: 8px 8px 8px 14px;
    border-radius: var(--r-md);
    border: 1px solid var(--line-2);
    background: rgba(255, 255, 255, .025);
    transition: border-color .25s var(--ease), box-shadow .25s var(--ease);
}

.kb-composer:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(52, 211, 153, .12);
}

.kb-composer textarea {
    flex: 1;
    min-width: 0;
    /* One line, always: a safety floor so the box can never collapse and
       leave the placeholder hanging below it before JS has measured it. */
    min-height: 22px;
    max-height: 116px;
    padding: 7px 0;
    border: none;
    outline: none;
    resize: none;
    background: none;
    color: var(--ink);
    font-size: 14.5px;
    line-height: 1.5;
    /* JS flips this to auto only once the text really outgrows max-height,
       so a one-line box never shows a native scrollbar. */
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .16) transparent;
}

.kb-composer textarea::-webkit-scrollbar { width: 6px; }
.kb-composer textarea::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .14);
    border-radius: 99px;
}

/* Keep the hint on one line — it gets clipped, never wrapped. */
.kb-composer textarea::placeholder {
    color: var(--muted);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.kb-send {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: none;
    border-radius: var(--r-sm);
    background: var(--grad);
    color: var(--brand-ink);
    transition: transform .2s var(--ease), opacity .2s var(--ease);
}

.kb-send:hover { transform: translateY(-1px); }
.kb-send:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.kb-foot {
    position: relative;
    padding: 9px 16px 12px;
    font-size: 10.5px;
    line-height: 1.5;
    color: var(--muted);
    text-align: center;
}

.kb-foot a { color: var(--ink-2); text-decoration: underline; text-underline-offset: 2px; }

/* The scroll-to-top button shares this corner — stack it above the orb. */
.scroll-top { bottom: 96px; }

/* ---------- Small screens ---------- */
@media (max-width: 520px) {
    .kb-chat { right: 14px; bottom: 14px; }
    .kb-panel {
        width: calc(100vw - 20px);
        height: min(76vh, calc(100vh - 108px));
        right: -2px;
    }
    .kb-nudge { display: none; }
    .scroll-top { bottom: 86px; }
}

@media print {
    .kb-chat { display: none !important; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .kb-orb-ring,
    .kb-avatar-pulse,
    .kb-status i,
    .kb-panel-glow { animation: none; }
    .kb-msg, .kb-note, .kb-panel, .kb-nudge { animation: none; transition: none; }
    .kb-caret { animation: none; opacity: 1; }
}
