/* =============================================================================
   Docs assistant overlay
   NOTE: Bottom-right public widget. Tokens come from landing.css so the
   overlay matches the docs site and the marketing pages without a second
   palette. z-index sits under the app chat (10000+) and above the navbar.
   ============================================================================= */

.docs-agent-root {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 8500;
    font-family: var(--font-sans, Inter, sans-serif);
    color: var(--color-text, #fff);
}

.docs-agent-toggle {
    width: 56px;
    height: 56px;
    border: 1px solid var(--color-border, rgba(255, 255, 255, 0.08));
    border-radius: var(--radius-full, 9999px);
    background: var(--color-bg-elevated, #111113);
    color: var(--color-primary, #39ff14);
    box-shadow: var(--shadow-lg, 0 8px 24px rgba(0, 0, 0, 0.6)), 0 0 24px var(--color-primary-glow, rgba(57, 255, 20, 0.3));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast, 150ms ease), box-shadow var(--transition-fast, 150ms ease);
}

.docs-agent-toggle:hover,
.docs-agent-toggle:focus-visible {
    transform: translateY(-1px);
    outline: 2px solid var(--color-primary, #39ff14);
    outline-offset: 2px;
}

.docs-agent-toggle[aria-expanded="true"] {
    box-shadow: var(--shadow-md, 0 4px 12px rgba(0, 0, 0, 0.5));
}

.docs-agent-toggle svg {
    width: 26px;
    height: 26px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.docs-agent-panel {
    position: absolute;
    right: 0;
    bottom: 68px;
    width: min(400px, calc(100vw - 24px));
    height: min(560px, calc(100vh - 120px));
    display: none;
    flex-direction: column;
    background: var(--color-bg-card, #161618);
    border: 1px solid var(--color-border, rgba(255, 255, 255, 0.08));
    border-radius: var(--radius-lg, 16px);
    box-shadow: var(--shadow-lg, 0 8px 24px rgba(0, 0, 0, 0.6));
    overflow: hidden;
}

.docs-agent-panel.is-open {
    display: flex;
}

.docs-agent-header {
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--color-border, rgba(255, 255, 255, 0.08));
    background: var(--color-bg-elevated, #111113);
}

.docs-agent-header h2 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
}

.docs-agent-header p {
    margin: 4px 0 0;
    font-size: 0.75rem;
    color: var(--color-text-muted, #71717a);
}

.docs-agent-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: var(--radius-sm, 6px);
    background: transparent;
    color: var(--color-text-secondary, #a1a1aa);
    cursor: pointer;
    font-size: 1.1rem;
}

.docs-agent-close:hover,
.docs-agent-close:focus-visible {
    color: var(--color-text, #fff);
    background: var(--color-glass-hover, rgba(255, 255, 255, 0.06));
}

.docs-agent-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.docs-agent-msg {
    max-width: 92%;
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.45;
}

.docs-agent-msg a {
    color: var(--color-primary, #39ff14);
    text-decoration: underline;
}

.docs-agent-msg.user {
    align-self: flex-end;
    background: var(--color-primary-dim, rgba(57, 255, 20, 0.1));
    border: 1px solid rgba(57, 255, 20, 0.25);
}

.docs-agent-msg.assistant {
    align-self: flex-start;
    background: var(--color-glass, rgba(255, 255, 255, 0.03));
    border: 1px solid var(--color-border, rgba(255, 255, 255, 0.08));
}

.docs-agent-msg.assistant p {
    margin: 0 0 0.6em;
}

.docs-agent-msg.assistant p:last-child,
.docs-agent-md > *:last-child {
    margin-bottom: 0;
}

.docs-agent-msg.assistant ul,
.docs-agent-msg.assistant ol {
    margin: 0.4em 0 0.6em;
    padding-left: 1.15em;
}

/* NOTE: Shared ChatMarkdown output - headings, code, and tables that used
   to leak as raw pipes because the overlay only knew paragraphs. */
.docs-agent-md {
    overflow-wrap: anywhere;
}

.docs-agent-md h2,
.docs-agent-md h3,
.docs-agent-md h4 {
    margin: 0.85em 0 0.4em;
    font-size: 0.92rem;
    font-weight: 650;
    line-height: 1.3;
    color: var(--color-text, #fff);
}

.docs-agent-md h2:first-child,
.docs-agent-md h3:first-child,
.docs-agent-md h4:first-child {
    margin-top: 0;
}

.docs-agent-md code {
    font-family: var(--font-mono, "JetBrains Mono", ui-monospace, monospace);
    font-size: 0.8em;
    background: var(--color-bg, #0a0a0b);
    padding: 1px 5px;
    border-radius: 4px;
}

.docs-agent-md pre {
    overflow-x: auto;
    margin: 0.6em 0;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--color-bg, #0a0a0b);
    border: 1px solid var(--color-border, rgba(255, 255, 255, 0.08));
}

.docs-agent-md pre code {
    padding: 0;
    background: transparent;
}

.docs-agent-md .chat-md-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0.7em 0;
    max-width: 100%;
    border: 1px solid var(--color-border, rgba(255, 255, 255, 0.08));
    border-radius: 10px;
}

.docs-agent-md table {
    width: 100%;
    min-width: 16rem;
    border-collapse: collapse;
    font-size: 0.78rem;
    line-height: 1.35;
}

.docs-agent-md th,
.docs-agent-md td {
    padding: 7px 8px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--color-border, rgba(255, 255, 255, 0.08));
    word-break: break-word;
}

.docs-agent-md th {
    color: var(--color-primary, #39ff14);
    background: var(--color-bg-elevated, #111113);
    font-weight: 600;
    white-space: nowrap;
}

.docs-agent-md td:first-child {
    color: var(--color-text, #fff);
    font-weight: 500;
}

.docs-agent-md tbody tr:last-child th,
.docs-agent-md tbody tr:last-child td {
    border-bottom: 0;
}

.docs-agent-msg.muted {
    align-self: center;
    max-width: 100%;
    background: transparent;
    border: 0;
    color: var(--color-text-muted, #71717a);
    font-size: 0.8rem;
    text-align: center;
}

.docs-agent-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 10px;
}

.docs-agent-chip {
    border: 1px solid var(--color-border, rgba(255, 255, 255, 0.08));
    background: var(--color-bg-elevated, #111113);
    color: var(--color-text-secondary, #a1a1aa);
    border-radius: var(--radius-full, 9999px);
    padding: 6px 10px;
    font-size: 0.75rem;
    cursor: pointer;
}

.docs-agent-chip:hover,
.docs-agent-chip:focus-visible {
    color: var(--color-text, #fff);
    border-color: var(--color-primary, #39ff14);
}

.docs-agent-form {
    display: flex;
    gap: 8px;
    padding: 12px 16px 14px;
    border-top: 1px solid var(--color-border, rgba(255, 255, 255, 0.08));
    background: var(--color-bg-elevated, #111113);
}

.docs-agent-form input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--color-border, rgba(255, 255, 255, 0.08));
    border-radius: var(--radius-md, 10px);
    background: var(--color-bg, #0a0a0b);
    color: var(--color-text, #fff);
    padding: 10px 12px;
    font-size: 0.875rem;
}

.docs-agent-form input:focus {
    outline: 2px solid var(--color-primary, #39ff14);
    outline-offset: 1px;
}

.docs-agent-form button[type="submit"] {
    border: 0;
    border-radius: var(--radius-md, 10px);
    background: var(--color-primary, #39ff14);
    color: #041204;
    font-weight: 600;
    padding: 0 14px;
    cursor: pointer;
}

.docs-agent-form button[type="submit"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.docs-agent-citations {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.docs-agent-citations a {
    font-size: 0.72rem;
    padding: 3px 7px;
    border-radius: var(--radius-full, 9999px);
    background: var(--color-primary-dim, rgba(57, 255, 20, 0.1));
    color: var(--color-primary, #39ff14);
    text-decoration: none;
}

@media (max-width: 520px) {
    .docs-agent-root {
        right: 12px;
        bottom: 12px;
    }

    .docs-agent-panel {
        width: calc(100vw - 24px);
        height: min(70vh, 560px);
    }
}
