/* =================================================================
 * chatbot.css — floating chat assistant ("Ken").
 *
 * Mounts a launcher pill in the bottom-right corner. Tapping it slides
 * the chat panel up with a spring; tapping the launcher again or the
 * chevron in the panel header closes it back down.
 *
 * All elements are scoped under .kg-chat — no class clashes with site CSS.
 * ================================================================= */

:root {
    --kg-chat-accent: hsl(var(--hue-color, 230), 80%, 60%);
    --kg-chat-accent-2: hsl(calc(var(--hue-color, 230) - 20), 90%, 65%);
    --kg-chat-bg: hsla(var(--hue-color, 230), 28%, 9%, 0.92);
    --kg-chat-edge: hsla(var(--hue-color, 230), 95%, 80%, 0.14);
}

/* Launcher (floating action button) */
.kg-chat-launcher {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    z-index: 1500;
    background:
        linear-gradient(135deg, var(--kg-chat-accent), var(--kg-chat-accent-2)),
        var(--kg-chat-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 14px 30px -10px hsla(var(--hue-color, 230), 90%, 50%, 0.6),
        0 6px 14px -4px rgba(0, 0, 0, 0.5);
    transition:
        transform 0.25s cubic-bezier(.2,.8,.2,1),
        box-shadow 0.3s ease,
        opacity 0.25s ease;
    /* Pulse moved to ::before pseudo-element below — scales transform+opacity
       on the GPU instead of the previous main-thread box-shadow animation. */
}

.kg-chat-launcher:hover {
    transform: translateY(-2px) scale(1.04);
}

.kg-chat-launcher:active {
    transform: scale(0.96);
}

.kg-chat-launcher i,
.kg-chat-launcher .kg-icon {
    font-size: 1.6rem;
    width: 1.6rem;
    height: 1.6rem;
}

/* Ken's face fills the entire launcher button when chat is closed.
   The button itself is a 60×60 circle so we crop the image to fit
   with object-fit: cover and pull the focal point up to keep Ken's
   eyes/face centered in the visible disc. */
.kg-chat-launcher img.kg-chat-launcher-open {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 30%;
    border-radius: 50%;
    display: block;
    pointer-events: none;
}

/* Inline-SVG icon defaults — replaces what `<i class="ri-…">` got from
   the remixicon font (currentColor inherit, baseline alignment).
   Per-context width/height overrides come from the parent rule. */
.kg-icon {
    display: inline-flex;
    flex-shrink: 0;
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
}
.kg-chat-close .kg-icon {
    width: 1.4rem;
    height: 1.4rem;
}
.kg-chat-input button .kg-icon {
    width: 1.1rem;
    height: 1.1rem;
}
.kg-chat-redirect .kg-icon {
    width: 1rem;
    height: 1rem;
}
.kg-prefill-banner > .kg-icon {
    width: 1.3rem;
    height: 1.3rem;
    color: var(--kg-chat-accent);
    flex-shrink: 0;
}
.kg-prefill-banner button .kg-icon {
    width: 1rem;
    height: 1rem;
}

.kg-chat-launcher .kg-chat-launcher-close {
    display: none;
}

.kg-chat--open .kg-chat-launcher {
    transform: rotate(180deg);
    animation: none;
}
/* Stop the pulse pseudo-element when the chat is open. */
.kg-chat--open .kg-chat-launcher::before {
    animation: none;
    opacity: 0;
}

.kg-chat--open .kg-chat-launcher .kg-chat-launcher-open {
    display: none;
}

.kg-chat--open .kg-chat-launcher .kg-chat-launcher-close {
    display: inline-flex;
}

/* Unread bubble */
.kg-chat-launcher-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ff6b6b;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 0 0 2px hsl(var(--hue-color, 230), 28%, 9%);
    transform: scale(0);
    transition: transform 0.25s cubic-bezier(.2,.8,.2,1);
}

.kg-chat-launcher-badge.is-visible {
    transform: scale(1);
}

/* Old pulse animated `box-shadow` which is a non-composited property
   and the trace flagged it as a CLS contributor with
   TARGET_HAS_INVALID_COMPOSITING_STATE / UNSUPPORTED_CSS_PROPERTY.
   Replaced with a ::before pseudo-element that scales + fades —
   transform + opacity are GPU-accelerated and don't trigger reflow. */
.kg-chat-launcher::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: hsla(var(--hue-color, 230), 90%, 60%, 0.45);
    z-index: -1;
    pointer-events: none;
    animation: kg-chat-pulse 3.2s ease-in-out infinite;
    will-change: transform, opacity;
}

@keyframes kg-chat-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.45;
    }
    50% {
        transform: scale(1.4);
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .kg-chat-launcher::before { animation: none; opacity: 0; }
}

/* Panel */
.kg-chat-panel {
    position: fixed;
    bottom: 6rem;
    right: 1.25rem;
    width: min(380px, calc(100vw - 2rem));
    height: min(560px, calc(100vh - 8rem));
    background: var(--kg-chat-bg);
    backdrop-filter: saturate(160%) blur(28px);
    -webkit-backdrop-filter: saturate(160%) blur(28px);
    border: 1px solid var(--kg-chat-edge);
    border-radius: 1.25rem;
    box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.7);
    z-index: 1499;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #f5f7ff;
    /* Open/close animation: scale + fade + translate */
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    pointer-events: none;
    transition:
        opacity 0.3s cubic-bezier(.2,.8,.2,1),
        transform 0.35s cubic-bezier(.2,.8,.2,1);
}

.kg-chat--open .kg-chat-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.kg-chat-panel-header {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.85rem 1rem;
    background:
        linear-gradient(135deg,
            hsla(var(--hue-color, 230), 80%, 60%, 0.45),
            hsla(calc(var(--hue-color, 230) - 20), 90%, 65%, 0.30)
        );
    border-bottom: 1px solid var(--kg-chat-edge);
}

.kg-chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--kg-chat-accent), var(--kg-chat-accent-2));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: 0 0 0 2px hsla(255, 100%, 100%, 0.18);
    flex-shrink: 0;
    object-fit: cover;
    object-position: center top;
}

.kg-chat-title-block { flex: 1; min-width: 0; }
.kg-chat-title { font-weight: 600; font-size: 0.95rem; letter-spacing: 0.01em; }
.kg-chat-status {
    font-size: 0.72rem;
    color: hsla(255, 100%, 100%, 0.7);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.kg-chat-status::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #2ecc71;
    box-shadow: 0 0 6px #2ecc71;
}

.kg-chat-close {
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 1.4rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.2s ease;
}
.kg-chat-close:hover {
    background-color: hsla(255, 100%, 100%, 0.12);
    transform: rotate(90deg);
}

/* Messages */
.kg-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    scroll-behavior: smooth;
}

.kg-chat-messages::-webkit-scrollbar { width: 6px; }
.kg-chat-messages::-webkit-scrollbar-thumb {
    background: hsla(var(--hue-color, 230), 60%, 60%, 0.35);
    border-radius: 999px;
}

.kg-msg {
    max-width: 85%;
    padding: 0.6rem 0.85rem;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.4;
    animation: kg-msg-in 0.28s cubic-bezier(.2,.8,.2,1) both;
    word-wrap: break-word;
}

@keyframes kg-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.kg-msg--bot {
    background: hsla(var(--hue-color, 230), 28%, 18%, 0.7);
    border: 1px solid var(--kg-chat-edge);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.kg-msg--user {
    background: linear-gradient(135deg, var(--kg-chat-accent), var(--kg-chat-accent-2));
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 6px 14px -6px hsla(var(--hue-color, 230), 90%, 50%, 0.45);
}

.kg-msg--system {
    background: transparent;
    border: 1px dashed var(--kg-chat-edge);
    color: hsla(255, 100%, 100%, 0.6);
    font-size: 0.78rem;
    font-style: italic;
    align-self: center;
    text-align: center;
    padding: 0.5rem 0.75rem;
}

/* Quick suggestion chips */
.kg-chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.25rem;
    align-self: flex-start;
    max-width: 100%;
}

.kg-chip {
    min-height: 44px;
    padding: 0.6rem 1rem;
    border-radius: 999px;
    background: hsla(var(--hue-color, 230), 80%, 60%, 0.12);
    border: 1px solid hsla(var(--hue-color, 230), 95%, 80%, 0.25);
    color: #f5f7ff;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    line-height: 1.2;
}

.kg-chip:hover {
    background: hsla(var(--hue-color, 230), 80%, 60%, 0.25);
    transform: translateY(-1px);
}

.kg-chip:active {
    transform: scale(0.97);
}

/* Booking summary card */
.kg-chat-summary {
    background: hsla(var(--hue-color, 230), 28%, 16%, 0.7);
    border: 1px solid var(--kg-chat-edge);
    border-left: 3px solid var(--kg-chat-accent);
    border-radius: 12px;
    padding: 0.75rem 0.85rem;
    align-self: flex-start;
    width: 100%;
    font-size: 0.85rem;
    animation: kg-msg-in 0.28s cubic-bezier(.2,.8,.2,1) both;
}

.kg-chat-summary h4 {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
    color: #fff;
}

.kg-chat-summary dl {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 0.6rem;
}

.kg-chat-summary dt {
    color: hsla(255, 100%, 100%, 0.55);
    font-size: 0.78rem;
}

.kg-chat-summary dd {
    margin: 0;
    color: #f5f7ff;
    font-size: 0.85rem;
    overflow-wrap: anywhere;
}

.kg-chat-summary .kg-chat-redirect {
    margin-top: 0.75rem;
    width: 100%;
    padding: 0.6rem 0.9rem;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--kg-chat-accent), var(--kg-chat-accent-2));
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.25s ease;
    font-family: inherit;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.kg-chat-summary .kg-chat-redirect:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 18px -6px hsla(var(--hue-color, 230), 90%, 55%, 0.6);
}

.kg-chat-summary .kg-chat-redirect:active {
    transform: scale(0.97);
}

/* Typing indicator */
.kg-chat-typing {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.65rem 0.85rem;
}

.kg-chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: hsl(var(--hue-color, 230), 95%, 80%);
    opacity: 0.4;
    animation: kg-chat-typing 1.2s infinite ease-in-out;
}

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

@keyframes kg-chat-typing {
    0%, 60%, 100% { opacity: 0.4; transform: scale(0.85); }
    30%           { opacity: 1;   transform: scale(1.1);  }
}

/* Input row */
.kg-chat-input {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--kg-chat-edge);
    background: hsla(var(--hue-color, 230), 28%, 5%, 0.55);
}

.kg-chat-input input {
    flex: 1;
    padding: 0.65rem 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--kg-chat-edge);
    background: hsla(var(--hue-color, 230), 28%, 12%, 0.65);
    color: #f5f7ff;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.kg-chat-input input:focus {
    border-color: var(--kg-chat-accent);
    box-shadow: 0 0 0 4px hsla(var(--hue-color, 230), 90%, 60%, 0.2);
}

.kg-chat-input button {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--kg-chat-accent), var(--kg-chat-accent-2));
    color: #fff;
    cursor: pointer;
    transition: transform 0.18s ease, opacity 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.kg-chat-input button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.kg-chat-input button:hover:not(:disabled) {
    transform: scale(1.07);
}

.kg-chat-input button:active:not(:disabled) {
    transform: scale(0.93);
}

/* Pre-fill banner on booking pages (mounted by chatbot.js) */
.kg-prefill-banner {
    position: relative;
    margin: 1rem auto 0;
    max-width: 800px;
    width: 90%;
    padding: 0.85rem 1rem 0.85rem 1.1rem;
    border-radius: 12px;
    background: hsla(var(--hue-color, 230), 80%, 60%, 0.10);
    border: 1px solid hsla(var(--hue-color, 230), 95%, 80%, 0.25);
    border-left: 3px solid var(--kg-chat-accent);
    color: var(--title-color, #fff);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    animation: kg-msg-in 0.35s cubic-bezier(.2,.8,.2,1) both;
}

.kg-prefill-banner i {
    font-size: 1.3rem;
    color: var(--kg-chat-accent);
    flex-shrink: 0;
}

.kg-prefill-banner-text { flex: 1; }

.kg-prefill-banner button {
    background: transparent;
    border: 0;
    color: hsla(255, 100%, 100%, 0.55);
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}
.kg-prefill-banner button:hover {
    background-color: hsla(255, 100%, 100%, 0.12);
    color: #fff;
}

/* Honour reduced motion */
@media (prefers-reduced-motion: reduce) {
    .kg-chat-launcher,
    .kg-chat-panel,
    .kg-msg,
    .kg-chat-summary,
    .kg-prefill-banner {
        animation: none !important;
        transition: none !important;
    }
}

/* Mobile tweaks */
@media screen and (max-width: 480px) {
    .kg-chat-launcher {
        bottom: 1rem;
        right: 1rem;
        width: 54px;
        height: 54px;
    }
    .kg-chat-panel {
        bottom: 5rem;
        right: 0.75rem;
        width: calc(100vw - 1.5rem);
        height: calc(100vh - 6.5rem);
        max-height: 640px;
    }
}

/* Hide on the admin pages — admins don't need a customer-facing chatbot. */
body.is-admin-page .kg-chat-launcher,
body.is-admin-page .kg-chat-panel {
    display: none !important;
}

/* ---- Keyboard accessibility: unified focus-visible rings on every
   interactive element inside the chat. The native :focus outline was
   suppressed earlier for visual reasons; this restores keyboard
   discoverability without affecting mouse users. */
.kg-chat-launcher:focus-visible,
.kg-chat-close:focus-visible,
.kg-chip:focus-visible,
.kg-chat-summary .kg-chat-redirect:focus-visible,
.kg-prefill-banner button:focus-visible {
    outline: none;
    box-shadow:
        0 0 0 3px hsla(var(--hue-color, 230), 95%, 70%, 0.55),
        0 8px 22px -8px hsla(var(--hue-color, 230), 90%, 50%, 0.55);
}

.kg-chat-input button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px hsla(var(--hue-color, 230), 95%, 70%, 0.6);
}

.kg-chat-input input:focus-visible {
    border-color: var(--kg-chat-accent);
    box-shadow:
        0 0 0 4px hsla(var(--hue-color, 230), 90%, 60%, 0.28);
}

/* Clearer send-button disabled state — opacity alone reads as "loading"
   to some users; combine with desaturation so it's unmistakably inert. */
.kg-chat-input button:disabled {
    background: hsla(var(--hue-color, 230), 15%, 35%, 0.6);
    filter: grayscale(0.4);
}
