/*
 * JCode chat widget.
 *
 * This runs inside somebody else's theme, so every rule is namespaced under
 * .jcode-chat and nothing is set on a bare element. Sizes are in rem but the
 * root font size is not touched — a theme that has scaled its own is entitled
 * to scale this too.
 */

.jcode-chat {
    --jcode-accent: #2563eb;
    --jcode-surface: #ffffff;
    --jcode-ink: #1f2937;
    --jcode-muted: #6b7280;
    --jcode-line: #e5e7eb;

    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

/* ---- bubble ---------------------------------------------------------- */

.jcode-chat__bubble {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3.5rem;
    height: 3.5rem;
    margin-left: auto;
    border: 0;
    border-radius: 50%;
    background: var(--jcode-accent);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
    transition: transform 0.15s ease;
}

.jcode-chat__bubble:hover { transform: scale(1.05); }
.jcode-chat__bubble:focus-visible { outline: 3px solid var(--jcode-accent); outline-offset: 3px; }
.jcode-chat__bubble-icon { font-size: 1.5rem; line-height: 1; }

/* ---- panel ----------------------------------------------------------- */

.jcode-chat__panel {
    display: flex;
    flex-direction: column;
    width: 22rem;
    max-width: calc(100vw - 2.5rem);
    height: 30rem;
    max-height: calc(100vh - 7rem);
    margin-bottom: 0.75rem;
    overflow: hidden;
    background: var(--jcode-surface);
    border: 1px solid var(--jcode-line);
    border-radius: 0.85rem;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
}

.jcode-chat__panel[hidden] { display: none; }

.jcode-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    background: var(--jcode-accent);
    color: #fff;
}

.jcode-chat__title { font-weight: 600; }

.jcode-chat__close {
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.25rem;
}

/* ---- log ------------------------------------------------------------- */

.jcode-chat__log {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: #f9fafb;
}

.jcode-chat__msg {
    max-width: 85%;
    padding: 0.55rem 0.8rem;
    border-radius: 0.85rem;
    color: var(--jcode-ink);
    /* Long URLs in an answer must not widen the panel. */
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.jcode-chat__msg--agent {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--jcode-line);
    border-bottom-left-radius: 0.25rem;
}

.jcode-chat__msg--visitor {
    align-self: flex-end;
    background: var(--jcode-accent);
    color: #fff;
    border-bottom-right-radius: 0.25rem;
}

/* ---- error ----------------------------------------------------------- */

.jcode-chat__error {
    padding: 0.6rem 1rem;
    background: #fef2f2;
    border-top: 1px solid #fecaca;
    color: #b91c1c;
    font-size: 0.85rem;
}

.jcode-chat__error[hidden] { display: none; }

/* ---- composer -------------------------------------------------------- */

.jcode-chat__form {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--jcode-line);
    background: var(--jcode-surface);
}

.jcode-chat__input {
    flex: 1;
    min-width: 0;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--jcode-line);
    border-radius: 0.5rem;
    font: inherit;
    color: var(--jcode-ink);
    background: #fff;
}

.jcode-chat__input:focus {
    outline: none;
    border-color: var(--jcode-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.jcode-chat__send {
    padding: 0.55rem 1rem;
    border: 0;
    border-radius: 0.5rem;
    background: var(--jcode-accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.jcode-chat__send:disabled { opacity: 0.6; cursor: default; }

/* ---- small screens --------------------------------------------------- */

@media (max-width: 480px) {
    .jcode-chat { right: 0.75rem; bottom: 0.75rem; }

    .jcode-chat__panel {
        width: calc(100vw - 1.5rem);
        height: calc(100vh - 6rem);
    }
}

/* A theme with a dark palette gets a dark panel rather than a white slab. */
@media (prefers-color-scheme: dark) {
    .jcode-chat {
        --jcode-surface: #111827;
        --jcode-ink: #f3f4f6;
        --jcode-muted: #9ca3af;
        --jcode-line: #374151;
    }

    .jcode-chat__log { background: #0b1220; }
    .jcode-chat__msg--agent { background: #1f2937; }
    .jcode-chat__input { background: #1f2937; color: var(--jcode-ink); }
    .jcode-chat__error { background: #3f1d1d; border-top-color: #7f1d1d; color: #fca5a5; }
}
