/* =====================================================================
   APEX INSTITUTE - Chat assistant widget
   Uses the brand tokens declared at the top of style.css.
   Sits above the sticky header (60) and nav backdrop (55), but below the
   gallery lightbox (200) so a photo still opens over everything.
   ===================================================================== */

.chatbot {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 150;
    font-family: var(--font-body);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

.chatbot .visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------------------------- Launcher ----------------------------- */
.cb-launcher {
    order: 2;                      /* keeps the button under the panel */
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 13px 20px 13px 16px;
    border: 0;
    border-radius: 999px;
    background: var(--apex-gradient);
    color: #fff;
    font-family: var(--font-head);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: .01em;
    cursor: pointer;
    box-shadow: 0 6px 14px rgba(12, 107, 36, .24), 0 16px 34px rgba(12, 107, 36, .20);
    transition: transform .18s ease, box-shadow .18s ease;
}

.cb-launcher:hover  { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(12,107,36,.28), 0 22px 44px rgba(12,107,36,.24); }
.cb-launcher:active { transform: translateY(0); }
.cb-launcher:focus-visible { outline: 3px solid var(--apex-bright); outline-offset: 3px; }

.cb-launcher svg { width: 22px; height: 22px; flex: none; }
.cb-launcher .cb-ico-close { display: none; }

/* Open state: collapse to a round close button. */
.chatbot.is-open .cb-launcher          { padding: 13px; }
.chatbot.is-open .cb-launcher-label,
.chatbot.is-open .cb-ico-chat          { display: none; }
.chatbot.is-open .cb-ico-close         { display: block; }

/* Unread nudge on the launcher. */
.cb-dot {
    position: absolute;
    top: 6px; right: 8px;
    width: 11px; height: 11px;
    border-radius: 50%;
    background: var(--apex-gold);
    border: 2px solid #fff;
}
.cb-launcher { position: relative; }

/* ------------------------------ Panel ------------------------------ */
.cb-panel {
    order: 1;
    width: min(384px, calc(100vw - 32px));
    height: min(560px, calc(100vh - 140px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow-lift);
    transform-origin: bottom right;
    animation: cb-pop .22s ease-out;
}

.cb-panel[hidden] { display: none; }

@keyframes cb-pop {
    from { opacity: 0; transform: translateY(14px) scale(.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1);   }
}

/* ------------------------------ Header ----------------------------- */
.cb-head {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 14px 14px 14px 16px;
    background: var(--apex-gradient);
    color: #fff;
}

.cb-avatar {
    width: 38px; height: 38px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: rgba(255, 255, 255, .18);
    border: 1px solid rgba(255, 255, 255, .28);
    font-family: var(--font-head);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .04em;
}

.cb-head-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.cb-head-text strong { font-family: var(--font-head); font-size: 15px; }
.cb-status { font-size: 11.5px; opacity: .88; }

.cb-min {
    margin-left: auto;
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border: 0;
    border-radius: 9px;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    cursor: pointer;
}
.cb-min:hover { background: rgba(255, 255, 255, .26); }
.cb-min svg   { width: 17px; height: 17px; }

/* ---------------------------- Transcript --------------------------- */
.cb-log {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px 14px 6px;
    background: var(--page);
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 14.5px;
    line-height: 1.6;
    color: var(--ink-soft);
}

.cb-msg {
    max-width: 88%;
    padding: 10px 13px;
    border-radius: 14px;
    animation: cb-in .18s ease-out;
}

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

.cb-msg.bot {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--line);
    border-bottom-left-radius: 5px;
}

.cb-msg.user {
    align-self: flex-end;
    background: var(--apex-deep);
    color: #fff;
    border-bottom-right-radius: 5px;
}

.cb-msg p        { margin: 0 0 8px; }
.cb-msg p:last-child { margin-bottom: 0; }
.cb-msg strong   { color: var(--ink); font-weight: 650; }
.cb-msg.user strong { color: #fff; }
.cb-msg a        { color: var(--apex-dark); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.cb-msg a:hover  { color: var(--apex-deep); }

/* Typing indicator */
.cb-typing { display: inline-flex; gap: 4px; padding: 3px 0; }
.cb-typing i {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--apex-mid);
    animation: cb-bounce 1.1s infinite ease-in-out;
}
.cb-typing i:nth-child(2) { animation-delay: .15s; }
.cb-typing i:nth-child(3) { animation-delay: .3s;  }

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

/* --------------------- Rich content inside replies ------------------ */
.cb-list, .cb-steps {
    margin: 6px 0 8px;
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.cb-list { list-style: none; padding-left: 0; }
.cb-list li { position: relative; padding-left: 16px; }
.cb-list li::before {
    content: "";
    position: absolute;
    left: 2px; top: .62em;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--apex-mid);
}
.cb-list em, .cb-more { font-style: normal; color: var(--muted); font-size: 13px; }
.cb-more { margin: 4px 0 0; }
.cb-steps li { padding-left: 2px; }

.cb-card {
    margin: 8px 0 4px;
    padding: 12px 13px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--apex-gradient-soft);
}
.cb-card > strong { display: block; font-family: var(--font-head); color: var(--ink); font-size: 14.5px; }
.cb-code {
    display: inline-block;
    margin: 3px 0 8px;
    padding: 1px 7px;
    border-radius: 999px;
    background: rgba(12, 107, 36, .10);
    color: var(--apex-deep);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
}

.cb-facts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
.cb-facts li { display: flex; gap: 8px; align-items: baseline; }
.cb-facts li span {
    flex: 0 0 82px;
    color: var(--muted);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 700;
}
.cb-facts-wide li span { flex-basis: 66px; }

.cb-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }

.cb-btn {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--apex-gradient);
    color: #fff !important;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none !important;
    line-height: 1.3;
}
.cb-btn:hover { filter: brightness(1.06); }

.cb-btn-ghost {
    background: var(--surface);
    color: var(--apex-deep) !important;
    border: 1px solid var(--apex-mid);
}

/* ---------------------------- Quick chips --------------------------- */
.cb-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 10px 14px;
    background: var(--page);
    border-top: 1px solid var(--line);
}
.cb-chips:empty { display: none; }

.cb-chip {
    padding: 7px 13px;
    border: 1px solid var(--apex-lime);
    border-radius: 999px;
    background: var(--surface);
    color: var(--apex-deep);
    font-family: var(--font-body);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.cb-chip:hover { background: var(--apex-deep); color: #fff; border-color: var(--apex-deep); }
.cb-chip:focus-visible { outline: 2px solid var(--apex-green); outline-offset: 2px; }

/* ----------------------------- Composer ----------------------------- */
.cb-compose {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 11px 12px;
    background: var(--surface);
    border-top: 1px solid var(--line);
}

.cb-compose input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--ink);
}
.cb-compose input::placeholder { color: var(--muted); }
.cb-compose input:focus {
    outline: none;
    border-color: var(--apex-mid);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(87, 185, 44, .16);
}

.cb-send {
    flex: none;
    width: 42px; height: 42px;
    display: grid; place-items: center;
    border: 0;
    border-radius: 50%;
    background: var(--apex-gradient);
    color: #fff;
    cursor: pointer;
}
.cb-send:hover    { filter: brightness(1.07); }
.cb-send:disabled { opacity: .5; cursor: not-allowed; }
.cb-send svg      { width: 19px; height: 19px; }

.cb-foot {
    margin: 0;
    padding: 0 14px 11px;
    background: var(--surface);
    color: var(--muted);
    font-size: 11px;
    line-height: 1.45;
    text-align: center;
}

/* Inline validation message during the enquiry hand-off. */
.cb-error {
    align-self: flex-start;
    max-width: 88%;
    padding: 8px 12px;
    border-radius: 12px;
    background: var(--err-bg);
    color: var(--err-fg);
    font-size: 13.5px;
}

/* ------------------------------ Mobile ------------------------------ */
@media (max-width: 560px) {
    .chatbot { right: 14px; bottom: 14px; left: 14px; align-items: flex-end; }
    .cb-panel {
        width: 100%;
        height: min(76vh, calc(100vh - 110px));
    }
    .cb-launcher-label { display: none; }
    .cb-launcher       { padding: 14px; }
}

/* Printing a programme page should not carry the widget onto paper. */
@media print { .chatbot { display: none !important; } }

@media (prefers-reduced-motion: reduce) {
    .cb-panel, .cb-msg { animation: none; }
    .cb-launcher:hover { transform: none; }
    .cb-typing i       { animation: none; opacity: .6; }
}
