/* The assistant widget. It takes every colour from the docs theme variables, so light and dark follow
   the reader's choice without a rule of their own. */

#kd-assistant {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    z-index: 1200;
    font-family: var(--docs-font-sans);
}

#kd-assistant svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.kda-launcher {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 0;
    border-radius: 999px;
    padding: 11px 18px 11px 14px;
    background: var(--docs-accent);
    color: var(--docs-accent-contrast);
    font: 600 14px var(--docs-font-sans);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.22);
    cursor: pointer;
}

.kda-launcher:hover {
    background: var(--docs-accent-strong);
}

.kda-panel {
    display: flex;
    flex-direction: column;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 40px);
    background: var(--docs-surface);
    color: var(--docs-text);
    border: 1px solid var(--docs-border);
    border-radius: var(--docs-radius-lg);
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.24);
    overflow: hidden;
}

.kda-panel[hidden],
.kda-launcher[hidden] {
    display: none;
}

.kda-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 10px 12px 16px;
    background: var(--docs-accent);
    color: var(--docs-accent-contrast);
}

.kda-title {
    flex: 1;
    min-width: 0;
    line-height: 1.25;
}

.kda-title strong {
    display: block;
    font-size: 15px;
}

.kda-title span {
    display: block;
    font-size: 12px;
    opacity: 0.85;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kda-icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: var(--docs-radius);
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.kda-icon:hover {
    background: rgba(255, 255, 255, 0.16);
}

.kda-notice {
    margin: 0;
    padding: 6px 12px;
    font-size: 11px;
    text-align: center;
    color: var(--docs-text-muted);
    border-bottom: 1px solid var(--docs-border);
}

.kda-log {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.kda-msg {
    max-width: 88%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.kda-msg p {
    margin: 0;
}

.kda-msg p + p,
.kda-msg ol {
    margin-top: 6px;
}

.kda-msg ol {
    margin-bottom: 0;
    padding-left: 20px;
}

.kda-agent {
    align-self: flex-start;
    background: var(--docs-bg);
    border-bottom-left-radius: 4px;
}

.kda-agent a {
    color: var(--docs-accent);
    font-weight: 500;
}

.kda-user {
    align-self: flex-end;
    background: var(--docs-accent);
    color: var(--docs-accent-contrast);
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.kda-note {
    align-self: center;
    max-width: 100%;
    font-size: 12px;
    color: var(--docs-text-muted);
    text-align: center;
    background: transparent;
}

.kda-typing {
    align-self: flex-start;
    display: inline-flex;
    gap: 4px;
    padding: 12px 14px;
    background: var(--docs-bg);
    border-radius: 14px;
}

.kda-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--docs-text-faint);
    animation: kda-blink 1.2s infinite ease-in-out;
}

.kda-typing span:nth-child(2) { animation-delay: 0.15s; }
.kda-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes kda-blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

.kda-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--docs-border);
}

.kda-input {
    flex: 1;
    min-width: 0;
    resize: none;
    max-height: 140px;
    border: 1px solid var(--docs-border-strong);
    border-radius: 18px;
    padding: 8px 14px;
    background: var(--docs-surface);
    color: var(--docs-text);
    font: 14px/1.4 var(--docs-font-sans);
}

.kda-input:focus {
    outline: none;
    border-color: var(--docs-accent);
    box-shadow: 0 0 0 3px var(--docs-focus);
}

.kda-send {
    display: grid;
    place-items: center;
    flex: none;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: var(--docs-accent);
    color: var(--docs-accent-contrast);
    cursor: pointer;
}

.kda-busy .kda-send {
    opacity: 0.5;
    cursor: progress;
}

#kd-assistant :focus-visible {
    outline: 2px solid var(--docs-accent);
    outline-offset: 2px;
}

@media (max-width: 640px) {
    #kd-assistant:has(.kda-panel:not([hidden])) {
        inset: 0;
    }

    #kd-assistant .kda-panel {
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border: 0;
        border-radius: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .kda-typing span {
        animation: none;
    }
}
