/*
    J.AI assistant widget styles.
    Uses the site's theme tokens (var(--surface), var(--accent), etc.) so it
    follows light/dark automatically. Two modes: floating (fab + panel) and inline.
*/

/* Floating launcher button, pinned bottom-right on every page. */
.jai-fab {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 1000;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.1rem;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font: 600 0.95rem/1 var(--font-sans);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: transform var(--transition-fast), background-color var(--transition-fast);
}
.jai-fab:hover { background: var(--accent-strong); transform: translateY(-1px); }

/* Slide-up chat panel for the floating mode (sits above the button). */
.jai-panel {
    position: fixed;
    right: 1.25rem;
    bottom: 5rem;
    z-index: 1000;
    width: min(400px, calc(100vw - 2rem));
    /* Capped so it reads as a compact card and always leaves clear space above it. */
    height: min(560px, 75vh);
    height: min(560px, 75dvh);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}
/* Two-class selector so it outranks .jai-chat's display: flex below. */
.jai-panel:not(.is-open) { display: none; }

/* Shared chat UI (used by both the floating panel and the inline container). */
/* No height here: .jai-panel and .jai-inline each set their own, and a height on this
   single-class rule would override .jai-panel's (same specificity, later in the file). */
.jai-chat { display: flex; flex-direction: column; min-height: 0; }
.jai-head { position: relative; padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); }
.jai-head h3 { margin: 0; font-size: 1rem; color: var(--text); }
.jai-log { flex: 1; min-height: 0; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.jai-msg { padding: 0.55rem 0.8rem; border-radius: var(--radius-sm); max-width: 88%; white-space: pre-wrap; line-height: 1.45; font-size: 0.9rem; }
.jai-user { align-self: flex-end; background: var(--accent); color: #fff; }
.jai-bot { align-self: flex-start; background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.jai-sources { margin-top: 0.4rem; font-size: 0.78rem; }
.jai-sources a { color: var(--accent-strong); display: block; }
.jai-bar { display: flex; gap: 0.5rem; padding: 0.7rem; border-top: 1px solid var(--border); }
.jai-bar input { flex: 1; padding: 0.55rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; }
.jai-bar button { padding: 0.55rem 0.9rem; border: 0; border-radius: var(--radius-sm); background: var(--accent); color: #fff; cursor: pointer; }
.jai-bar button:disabled { opacity: 0.5; cursor: default; }

/* Close button in the floating panel's header. */
.jai-close {
    position: absolute;
    top: 50%;
    right: 0.6rem;
    transform: translateY(-50%);
    width: 2.25rem;
    height: 2.25rem;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}
.jai-close:hover { background: var(--surface-alt); color: var(--text); }

/* Phones: icon-only launcher, full-screen panel sized to the visible viewport. */
@media (max-width: 600px) {
    .jai-fab { width: 3.25rem; height: 3.25rem; padding: 0; justify-content: center; }
    .jai-fab-label { display: none; }
    .jai-fab svg { width: 24px; height: 24px; }

    .jai-panel {
        top: var(--jai-vv-top, 0);
        right: 0;
        bottom: auto;
        left: 0;
        width: 100%;
        height: 100vh;
        height: var(--jai-vv-h, 100dvh);
        border: 0;
        border-radius: 0;
    }
    .jai-head { padding-top: calc(0.85rem + env(safe-area-inset-top)); }
    .jai-bar { padding-bottom: calc(0.7rem + env(safe-area-inset-bottom)); }
    /* 16px stops iOS Safari from zooming in when the input is focused. */
    .jai-bar input { font-size: 16px; }

    /* Stop the page behind the full-screen chat from scrolling. */
    body.jai-open { overflow: hidden; }
}

/* Inline mode: a bordered card that sits in the page flow (e.g. the RAG project page). */
.jai-inline {
    height: 520px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

/* Printing (e.g. the resume): the chat is interactive-only, so leave it off the page. */
@media print {
    .jai-fab,
    .jai-panel,
    .jai-inline {
        display: none !important;
    }
}
