/* ============================================
   JACK — JC FITNESS FAQ ASSISTANT
   Floating chat widget styles.
   Reuses index.php's existing design tokens
   (--red, --ink, --border, --r-*, --sh-*, --ff-*)
   defined in that page's <style> block, so this
   file must be loaded AFTER index.php's inline
   <style> tag.
   ============================================ */

#jack-launcher {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 60px;
    height: 60px;
    border-radius: 0;
    background: transparent;
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: var(--sh-lg, 0 12px 28px rgba(0, 0, 0, .22));
    z-index: 9998;
    transition: transform .2s var(--ease, ease), box-shadow .2s var(--ease, ease);
}

#jack-launcher:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: var(--sh-xl, 0 18px 36px rgba(0, 0, 0, .28));
}

#jack-launcher img {
    width: 100%;
    height: 100%;
    border-radius: 0;
    object-fit: contain;
}

#jack-launcher .jack-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #2ecc71;
    border: 2px solid #fff;
}

#jack-panel {
    position: fixed;
    right: 24px;
    bottom: 96px;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: var(--r-lg, 18px);
    box-shadow: var(--sh-xl, 0 20px 50px rgba(0, 0, 0, .3));
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    font-family: var(--ff-body, 'Outfit', sans-serif);
    border: 1px solid var(--border, #e4e4e4);
}

#jack-panel.jack-open {
    display: flex;
    animation: jackSlideUp .22s var(--ease, ease) both;
}

@keyframes jackSlideUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.jack-header {
    background: var(--ink, #171717);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.jack-header .jack-avatar {
    width: 36px;
    height: 36px;
    border-radius: 0;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    position: relative;
}

.jack-header .jack-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 0;
    object-fit: contain;
}

.jack-header .jack-avatar::after {
    content: '';
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #2ecc71;
    border: 2px solid var(--ink, #171717);
}

.jack-header .jack-title {
    flex: 1;
    min-width: 0;
}

.jack-header .jack-name {
    font-weight: 600;
    font-size: .95rem;
    line-height: 1.2;
}

.jack-header .jack-subtitle {
    font-size: .72rem;
    color: rgba(255, 255, 255, .65);
    line-height: 1.2;
}

.jack-header .jack-close {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, .8);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
}

.jack-header .jack-close:hover {
    background: rgba(255, 255, 255, .12);
    color: #fff;
}

.jack-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--surface, #f8f8f8);
    scroll-behavior: smooth;
}

.jack-msg {
    max-width: 86%;
    padding: 9px 12px;
    border-radius: var(--r-md, 12px);
    font-size: .86rem;
    line-height: 1.42;
    word-wrap: break-word;
    white-space: pre-line;
}

/* Fade/slide-in for newly-appended messages and suggestion groups —
   applied via JS (playEnterAnimation) right after the node is inserted. */
.jack-enter {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .28s var(--ease, ease), transform .28s var(--ease, ease);
}

.jack-enter.jack-enter-active {
    opacity: 1;
    transform: translateY(0);
}

.jack-msg.jack-bot.jack-typewriting {
    cursor: pointer;
}

.jack-msg.jack-bot.jack-typewriting::after {
    content: '';
    display: inline-block;
    width: 2px;
    height: .9em;
    margin-left: 2px;
    vertical-align: -2px;
    background: var(--muted-lt, #a0a0a0);
    animation: jackCaret .8s step-end infinite;
}

@keyframes jackCaret {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.jack-msg.jack-bot {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--border, #e4e4e4);
    color: var(--ink, #171717);
    border-bottom-left-radius: 4px;
}

.jack-msg.jack-user {
    align-self: flex-end;
    background: var(--red, #dc3545);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.jack-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-self: stretch;
}

.jack-suggestions .jack-hint {
    font-size: .74rem;
    color: var(--muted, #6e6e6e);
    margin: 2px 0 2px 2px;
}

.jack-chip {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--red, #dc3545);
    color: var(--red, #dc3545);
    font-family: inherit;
    font-size: .82rem;
    font-weight: 500;
    padding: 7px 12px;
    border-radius: 999px;
    cursor: pointer;
    text-align: left;
    transition: background .15s, color .15s;
}

.jack-chip:hover,
.jack-chip:focus-visible {
    background: var(--red, #dc3545);
    color: #fff;
    outline: none;
}

/* "Not found" handoff — visually distinct (solid, not outline) from the
   FAQ chips so it reads as the primary action, not another suggestion. */
.jack-inquiry-btn {
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--red, #dc3545);
    border: none;
    color: #fff;
    font-family: inherit;
    font-size: .84rem;
    font-weight: 600;
    padding: 10px 14px;
    border-radius: 999px;
    cursor: pointer;
    transition: background .15s, transform .15s;
}

.jack-inquiry-btn:hover,
.jack-inquiry-btn:focus-visible {
    background: var(--red-dark, #c82333);
    outline: none;
}

.jack-inquiry-btn:active {
    transform: scale(.98);
}

.jack-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 10px 13px;
    background: #fff;
    border: 1px solid var(--border, #e4e4e4);
    border-radius: var(--r-md, 12px);
    border-bottom-left-radius: 4px;
}

.jack-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted-lt, #a0a0a0);
    animation: jackBounce 1.2s infinite ease-in-out;
}

.jack-typing span:nth-child(2) { animation-delay: .15s; }
.jack-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes jackBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.jack-inputbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border, #e4e4e4);
    background: #fff;
}

.jack-inputbar input {
    flex: 1;
    border: 1px solid var(--border, #e4e4e4);
    border-radius: 999px;
    padding: 9px 14px;
    font-size: .86rem;
    font-family: inherit;
    outline: none;
    min-width: 0;
}

.jack-inputbar input:focus {
    border-color: var(--red, #dc3545);
}

.jack-inputbar button {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    border: none;
    background: var(--red, #dc3545);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .95rem;
    transition: background .15s;
}

.jack-inputbar button:hover {
    background: var(--red-dark, #c82333);
}

.jack-inputbar button:disabled {
    opacity: .5;
    cursor: default;
}

@media (max-width: 480px) {
    #jack-panel {
        right: 12px;
        left: 12px;
        bottom: 88px;
        width: auto;
        max-width: none;
        height: calc(100vh - 160px);
    }

    #jack-launcher {
        right: 16px;
        bottom: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #jack-launcher,
    #jack-launcher:hover,
    .jack-chip,
    .jack-inquiry-btn {
        transition: none;
    }

    #jack-panel.jack-open {
        animation: none;
    }

    .jack-body {
        scroll-behavior: auto;
    }

    .jack-enter {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .jack-typing span {
        animation: none;
        opacity: .8;
    }

    .jack-msg.jack-bot.jack-typewriting::after {
        animation: none;
    }
}
