/* B6B — Credi public (GUEST) launcher + chat panel — clients box.
 *
 * Ported from the marketing launcher styles (credicorp.co.uk
 * resources/css/components/credi-launcher.css). Self-contained: every custom
 * property has an inline fallback literal so the launcher renders correctly on the
 * clients guest pages (/apply, /login, /register) whether or not a token sheet is
 * present. Deployed standalone to public/assets/css/credi-launcher.css and loaded
 * by layouts/document.php on the guest surfaces (the launcher partial self-guards
 * on GUEST, the dock on AUTH, so exactly one renders per request).
 *
 * CSP-safe: pure stylesheet, no inline style, no @import of remote origins.
 */

/* ── Wrap: always fixed in the viewport corner (bottom-right) ─────────────── */
.ccfs-credi-wrap {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 900;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

/* Scroll-aware suppression: slide the launcher off the bottom edge while reading and
   scrolling down; credi-launcher.js brings it back on scroll-up or once scrolling stops,
   and never hides it while the chat panel is open. */
.ccfs-credi-wrap.is-scroll-hidden {
    transform: translateY(160%);
    opacity: 0;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    .ccfs-credi-wrap { transition: none; }
}

/* ── Launcher pill (FAB) ─────────────────────────────────────────────────── */
.ccfs-credi-fab {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 1.25rem 0.75rem 0.875rem;
    background: var(--c-navy, #003366);
    background-image: linear-gradient(155deg,
        var(--c-navy-light, #1e6b47) 0%,
        var(--c-navy, #003366) 55%,
        var(--c-navy-dark, #08231a) 100%);
    color: var(--c-white, #ffffff);
    border: none;
    border-radius: var(--r-full, 999px);
    font: 600 0.9375rem var(--font-sans, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
    cursor: pointer;
    box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.18) inset, 0 12px 28px -8px rgba(0, 0, 0, 0.42);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    letter-spacing: -0.01em;
}

.ccfs-credi-fab:hover {
    background-color: var(--c-navy-dark, #08231a);
    background-image: linear-gradient(155deg,
        var(--c-navy, #003366) 0%,
        var(--c-navy-dark, #08231a) 60%,
        var(--c-navy-dark, #08231a) 100%);
    transform: translateY(-3px);
    box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.22) inset, 0 18px 36px -8px rgba(0, 0, 0, 0.48);
}

.ccfs-credi-fab:focus-visible {
    outline: 2px solid var(--c-green, #90cb22);
    outline-offset: 3px;
}

.ccfs-credi-fab-avatar {
    flex: 0 0 auto;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: var(--r-full, 999px);
    background: var(--c-green, #90cb22);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.ccfs-credi-fab-label {
    color: var(--c-white, #ffffff);
    line-height: 1;
}

/* ── Panel ───────────────────────────────────────────────────────────────── */
.ccfs-credi-panel {
    position: absolute;
    bottom: calc(100% + 0.875rem);
    right: 0;
    width: 384px;
    max-height: min(560px, calc(100svh - 7rem));
    overscroll-behavior: contain;
    background: var(--c-bg-elevated, #ffffff);
    border-radius: var(--r-lg, 12px);
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.28),
                0 0 0 1px rgba(0, 51, 102, 0.07);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.25s ease, transform 0.25s ease;
    transform-origin: bottom right;
}

.ccfs-credi-panel[aria-hidden="true"] {
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px) scale(0.96);
}

.ccfs-credi-panel[aria-hidden="false"] {
    opacity: 1;
    transform: none;
}

/* ── Panel header ────────────────────────────────────────────────────────── */
.ccfs-credi-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem 0.875rem 0.875rem;
    background: var(--c-navy, #003366);
    color: var(--c-white, #ffffff);
    flex-shrink: 0;
    box-shadow: inset 0 -3px 0 0 var(--c-green, #90cb22);
}

.ccfs-credi-header-avatar {
    flex: 0 0 auto;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--r-full, 999px);
    background: var(--c-green, #90cb22);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.ccfs-credi-header-text {
    flex: 1;
    min-width: 0;
}

.ccfs-credi-title {
    display: block;
    font-weight: 700;
    font-size: 0.9375rem;
    line-height: 1.2;
    color: var(--c-white, #ffffff);
}

.ccfs-credi-subtitle {
    display: block;
    font-size: 0.71875rem;
    line-height: 1.35;
    color: rgba(255, 255, 255, 0.65);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ccfs-credi-close {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--r-full, 999px);
    color: var(--c-white, #ffffff);
    cursor: pointer;
    padding: 0;
    width: 1.875rem;
    height: 1.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.ccfs-credi-close:hover { background: rgba(255, 255, 255, 0.22); }
.ccfs-credi-close:focus-visible {
    outline: 2px solid var(--c-green, #90cb22);
    outline-offset: 2px;
}

/* ── Feed ────────────────────────────────────────────────────────────────── */
.ccfs-credi-feed {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    scroll-behavior: smooth;
    background: var(--c-bg-alt, #f8f9fb);
}

/* ── Bubbles ─────────────────────────────────────────────────────────────── */
.ccfs-credi-bubble {
    max-width: 90%;
    border-radius: var(--r-md, 8px);
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    line-height: 1.5;
}

.ccfs-credi-bubble p { margin: 0 0 0.375rem; }
.ccfs-credi-bubble p:last-child { margin-bottom: 0; }

.ccfs-credi-bubble.credi {
    background: var(--c-bg-elevated, #ffffff);
    color: var(--c-navy, #003366);
    align-self: flex-start;
    border-bottom-left-radius: var(--r-sm, 4px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.ccfs-credi-bubble.visitor {
    background: var(--c-navy, #003366);
    color: var(--c-white, #ffffff);
    align-self: flex-end;
    border-bottom-right-radius: var(--r-sm, 4px);
}

.ccfs-credi-bubble.is-error { border-left: 3px solid var(--c-error, #b3261e); }
.ccfs-credi-bubble.thinking { opacity: 0.6; font-style: italic; }

/* Welcome bubble — sign-in link uses navy (AA-safe). */
.ccfs-credi-bubble.is-welcome a {
    color: var(--c-navy, #003366);
    font-weight: 600;
    text-decoration: underline;
}

/* Answer links inherit the navy treatment so KB answer links stay legible. */
.ccfs-credi-bubble.credi a {
    color: var(--c-navy, #003366);
    font-weight: 600;
}

/* ── Suggestion chips ────────────────────────────────────────────────────── */
.ccfs-credi-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0 1rem 0.25rem;
}

.ccfs-credi-chips[hidden] { display: none; }

.ccfs-credi-chips--followup {
    margin-top: 0.25rem;
    padding-top: 0.625rem;
    border-top: 1px solid var(--c-border, #dee2e6);
}

.ccfs-credi-chips--followup::before {
    content: "You might also ask";
    flex-basis: 100%;
    margin-bottom: 0.125rem;
    color: var(--c-ink-subtle, #6b7280);
    font: 600 0.6875rem var(--font-sans, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.ccfs-credi-chip {
    border: 1px solid var(--c-border, #dee2e6);
    background: var(--c-bg-elevated, #ffffff);
    color: var(--c-navy, #003366);
    font: 600 0.8125rem var(--font-sans, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
    line-height: 1.2;
    padding: 0.5rem 0.8125rem;
    min-height: 40px;
    border-radius: var(--r-full, 999px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.ccfs-credi-chip:hover {
    background: var(--c-green, #90cb22);
    border-color: var(--c-green, #90cb22);
    color: var(--c-navy, #003366);
}
.ccfs-credi-chip:focus-visible {
    outline: 2px solid var(--c-navy, #003366);
    outline-offset: 2px;
}

/* ── Compose bar ─────────────────────────────────────────────────────────── */
.ccfs-credi-compose {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0.875rem;
    border-top: 1px solid var(--c-border, #dee2e6);
    flex-shrink: 0;
    background: var(--c-bg-elevated, #ffffff);
}

.ccfs-credi-input {
    flex: 1;
    min-height: 44px;
    border: 1px solid var(--c-border, #dee2e6);
    border-radius: var(--r-full, 999px);
    padding: 0.5rem 0.875rem;
    font: inherit;
    /* 16px stops iOS/Safari auto-zooming the viewport on focus. */
    font-size: 16px;
    color: var(--c-navy, #003366);
    background: var(--c-bg-alt, #f8f9fb);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08);
    box-sizing: border-box;
}

.ccfs-credi-input:focus-visible {
    outline: 2px solid var(--c-navy, #003366);
    outline-offset: 1px;
}

.ccfs-credi-counter {
    font-size: 0.75rem;
    color: var(--c-ink-subtle, #6b7280);
    min-width: 2.5ch;
    text-align: right;
}

.ccfs-credi-counter.is-low { color: var(--c-warn-text, #a15c00); }

.ccfs-credi-send {
    background: var(--c-green, #90cb22);
    border: none;
    border-radius: var(--r-full, 999px);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--c-navy, #003366);
    flex-shrink: 0;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.ccfs-credi-send:hover { background: var(--c-green-dark, #5f8a16); color: var(--c-navy, #003366); }
.ccfs-credi-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* sr-only helper for the compose label (in case the page's base sheet is absent). */
.ccfs-credi-compose .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Mobile: compact circular launcher + full-screen chat sheet ───────────── */
@media (max-width: 480px) {
    .ccfs-credi-wrap {
        bottom: 1rem;
        right: 1rem;
    }
    .ccfs-credi-panel {
        position: fixed;
        inset: 0 0 auto 0;
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        right: auto;
        bottom: auto;
        border-radius: 0;
        transform-origin: center;
    }
    .ccfs-credi-panel[aria-hidden="true"] {
        transform: translateY(8px) scale(0.99);
    }
    .ccfs-credi-feed { flex: 1 1 auto; }
    .ccfs-credi-fab {
        gap: 0;
        padding: 0;
        width: 3.5rem;
        height: 3.5rem;
        justify-content: center;
        border-radius: var(--r-full, 999px);
    }
    .ccfs-credi-fab-label { display: none; }
    .ccfs-credi-fab-avatar { width: 2rem; height: 2rem; }
}
