/* BookSesh CS Agent — Public chat widget
   Shares Aura gradient palette: blue #1535E8 · purple #7B5CF0 · terracotta #C4714A
   Scoped to .bksesh-cs-* — zero global leakage. */

@keyframes cs-flow {
    0%   { background-position: 0% 50%;   }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%;   }
}
@keyframes cs-pulse {
    0%   { box-shadow: 0 4px 16px rgba(21,53,232,.30), 0 0 0 0   rgba(21,53,232,.22); }
    65%  { box-shadow: 0 4px 16px rgba(21,53,232,.30), 0 0 0 10px rgba(21,53,232,0);  }
    100% { box-shadow: 0 4px 16px rgba(21,53,232,.30), 0 0 0 0   rgba(21,53,232,0);  }
}
@keyframes cs-icon-breathe {
    0%         { opacity: 1; transform: scale(1);   }
    17%, 50%   { opacity: 0; transform: scale(.82); }
    67%, 100%  { opacity: 1; transform: scale(1);   }
}
@keyframes cs-text-breathe {
    0%         { opacity: 0; transform: scale(.82); }
    17%, 50%   { opacity: 1; transform: scale(1);   }
    67%, 100%  { opacity: 0; transform: scale(.82); }
}
@keyframes cs-msg-in {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0);   }
}
@keyframes cs-bounce {
    0%,60%,100% { transform: translateY(0);    }
    30%          { transform: translateY(-5px); }
}

/* ── Launcher ────────────────────────────────────────────────────────────── */
button#bksesh-cs-launcher.bksesh-cs-launcher,
.bksesh-cs-launcher {
    position: fixed !important;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    right: 20px !important;
    z-index: 99990 !important;
    width: 56px !important;
    height: 56px !important;
    min-width: 56px !important;
    min-height: 56px !important;
    max-width: 56px !important;
    max-height: 56px !important;
    border-radius: 50% !important;
    border: none !important;
    cursor: pointer !important;
    padding: 12px !important;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: linear-gradient(135deg, #1535E8 0%, #7B5CF0 45%, #C4714A 100%) !important;
    background-size: 240% 240% !important;
    animation: cs-flow 7.5s ease-in-out infinite, cs-pulse 3s ease-in-out 2s infinite !important;
    color: #fff !important;
    transition: filter .12s, transform .08s !important;
    -webkit-tap-highlight-color: transparent !important;
    overflow: hidden !important;
    line-height: 1 !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    font-size: inherit !important;
}
.bksesh-cs-launcher:hover  { filter: brightness(.92); }
.bksesh-cs-launcher:active { filter: brightness(.84); transform: translateY(1px); }
.bksesh-cs-launcher.open   { animation: cs-flow 7.5s ease-in-out infinite; border-radius: 50% !important; }

.bksesh-cs-launcher .icon-sparkle,
.bksesh-cs-launcher .icon-text,
.bksesh-cs-launcher .icon-close {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bksesh-cs-launcher .icon-sparkle {
    transition: opacity .25s, transform .25s;
    animation: cs-icon-breathe 7.5s ease-in-out 1.5s infinite;
}
.bksesh-cs-launcher .icon-text {
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    text-align: center;
    line-height: 1.25;
    letter-spacing: .03em;
    opacity: 0;
    transition: opacity .25s;
    animation: cs-text-breathe 7.5s ease-in-out 1.5s infinite;
    pointer-events: none;
    user-select: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.bksesh-cs-launcher .icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(.7);
    transition: opacity .18s, transform .18s;
}
.bksesh-cs-launcher.open .icon-sparkle { opacity: 0; transform: rotate(90deg) scale(.7); animation: none; }
.bksesh-cs-launcher.open .icon-text    { opacity: 0; animation: none; }
.bksesh-cs-launcher.open .icon-close   { opacity: 1; transform: rotate(0) scale(1); }

/* ── Panel ───────────────────────────────────────────────────────────────── */
.bksesh-cs-panel {
    position: fixed;
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    right: 20px;
    z-index: 99989;
    width: min(360px, calc(100vw - 32px));
    max-height: min(520px, 70vh);
    display: flex;
    flex-direction: column;
    background: #FFFCF9;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(28,42,58,.18), 0 4px 16px rgba(28,42,58,.09);
    overflow: hidden;
    pointer-events: none;
    opacity: 0;
    transform: translateY(14px) scale(.97);
    transition: opacity .24s cubic-bezier(.16,1,.3,1), transform .24s cubic-bezier(.16,1,.3,1);
}
.bksesh-cs-panel.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: all; }

/* ── Header ──────────────────────────────────────────────────────────────── */
.bksesh-cs-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px 12px;
    background: linear-gradient(180deg, rgba(21,53,232,.06) 0%, transparent 100%);
    flex-shrink: 0;
}
.bksesh-cs-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1535E8 0%, #7B5CF0 55%, #C4714A 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.bksesh-cs-name   { flex: 0 0 auto; font-size: 14px; font-weight: 700; color: #1C2A3A; letter-spacing: .01em; }
.bksesh-cs-status { display: flex; align-items: center; gap: 5px; font-size: 11px; color: #72697A; }
.bksesh-cs-status-dot {
    width: 6px; height: 6px; border-radius: 50%; background: #22c55e;
    animation: cs-pulse 2.5s ease-in-out infinite;
}
.bksesh-cs-header-close {
    width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
    background: none; border: none; border-radius: 8px; color: #9E97A6;
    font-size: 16px; cursor: pointer; transition: background .12s, color .12s;
    margin: -8px; padding: 8px;
}
.bksesh-cs-header-close:hover { background: rgba(0,0,0,.06); color: #1C2A3A; }

.bksesh-cs-header-book {
    flex-shrink: 0;
    margin-right: auto;
    padding: 5px 11px;
    background: linear-gradient(135deg, #1535E8 0%, #7B5CF0 100%);
    color: #fff !important;
    font-size: 11px;
    font-weight: 600;
    font-family: inherit;
    border: none !important;
    border-radius: 20px !important;
    cursor: pointer;
    white-space: nowrap;
    transition: filter .12s, transform .08s;
    -webkit-tap-highlight-color: transparent;
    letter-spacing: .01em;
}
.bksesh-cs-header-book:hover  { filter: brightness(.92); }
.bksesh-cs-header-book:active { transform: translateY(1px); filter: brightness(.84); }

/* ── Messages ─────────────────────────────────────────────────────────────── */
.bksesh-cs-messages {
    flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column;
    gap: 12px; scroll-behavior: smooth; min-height: 80px;
}
.bksesh-cs-messages::-webkit-scrollbar       { width: 4px; }
.bksesh-cs-messages::-webkit-scrollbar-track { background: transparent; }
.bksesh-cs-messages::-webkit-scrollbar-thumb { background: rgba(28,42,58,.12); border-radius: 2px; }

.bksesh-cs-msg {
    max-width: 86%; font-size: 14px; line-height: 1.6; padding: 10px 13px;
    border-radius: 14px; animation: cs-msg-in .2s ease both;
}
.bksesh-cs-msg.aura {
    white-space: pre-wrap; /* renders \n and \n\n as visual line/paragraph breaks */
    line-height: 1.65;
    word-spacing: .01em;
}
@keyframes cs-cursor-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}
.bksesh-cs-msg.aura.streaming::after {
    content: '|';
    display: inline;
    color: #7B5CF0;
    font-weight: 300;
    animation: cs-cursor-blink .6s step-end infinite;
    margin-left: 1px;
}

/* ── Book CTA button (appears after Aura message when intent score ≥ 5) ── */
.bksesh-cs-book-btn {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    background: linear-gradient(135deg, #1535E8 0%, #7B5CF0 100%);
    color: #fff !important;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    border: none !important;
    border-radius: 20px !important;
    cursor: pointer;
    animation: cs-msg-in .2s ease both;
    transition: filter .12s, transform .08s;
    text-decoration: none;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.bksesh-cs-book-btn:hover  { filter: brightness(.92); }
.bksesh-cs-book-btn:active { transform: translateY(1px); filter: brightness(.84); }
.bksesh-cs-msg.aura  { align-self: flex-start; background: #F0F3FF; color: #1C2A3A; border-bottom-left-radius: 3px; }
.bksesh-cs-msg.user  { align-self: flex-end; background: linear-gradient(135deg, #1535E8 0%, #7B5CF0 100%); color: #fff; border-bottom-right-radius: 3px; max-width: 78%; }
.bksesh-cs-msg.error { align-self: flex-start; background: #FEF2F2; color: #991B1B; font-size: 13px; border-bottom-left-radius: 3px; }

/* ── Typing indicator ─────────────────────────────────────────────────────── */
.bksesh-cs-typing {
    align-self: flex-start; display: flex; gap: 3px; align-items: center;
    padding: 11px 14px; background: #F0F3FF; border-radius: 14px; border-bottom-left-radius: 3px;
}
.bksesh-cs-typing span { width: 5px; height: 5px; background: #7B5CF0; border-radius: 50%; animation: cs-bounce 1.3s ease-in-out infinite; }
.bksesh-cs-typing span:nth-child(2) { animation-delay: .18s; }
.bksesh-cs-typing span:nth-child(3) { animation-delay: .36s; }

/* ── Input area ───────────────────────────────────────────────────────────── */
.bksesh-cs-input-row {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 10px 14px 14px; border-top: 1px solid rgba(28,42,58,.07);
    background: #FFFCF9; flex-shrink: 0;
}
.bksesh-cs-input {
    flex: 1; font-size: 14px; font-family: inherit; padding: 10px 12px;
    border: 1.5px solid transparent; border-radius: 14px; background: #F3F1EF;
    color: #1C2A3A; resize: none; line-height: 1.45; max-height: 80px;
    overflow-y: auto; outline: none; transition: border-color .15s, background .15s, box-shadow .15s;
}
.bksesh-cs-input:focus { border-color: #1535E8; background: #fff; box-shadow: 0 0 0 3px rgba(21,53,232,.08); }
.bksesh-cs-input::placeholder { color: #9E97A6; }
.bksesh-cs-input:disabled { opacity: .5; }
.bksesh-cs-send {
    flex-shrink: 0; width: 38px; height: 38px; border: none; border-radius: 12px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1535E8 0%, #7B5CF0 100%);
    background-size: 200% 200%; animation: cs-flow 7.5s ease-in-out infinite;
    color: #fff; transition: filter .12s, transform .08s; margin-bottom: 1px;
}
.bksesh-cs-send:hover  { filter: brightness(.92); }
.bksesh-cs-send:active { transform: translateY(1px); filter: brightness(.84); }
.bksesh-cs-send:disabled { opacity: .4; cursor: not-allowed; animation: none; background: #9E97A6; }

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .bksesh-cs-launcher { bottom: calc(8px + env(safe-area-inset-bottom, 0px)); right: 12px; }
    .bksesh-cs-panel { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); right: 12px; width: calc(100vw - 24px); max-height: 65vh; border-radius: 18px; }
}

/* ── Reduced motion ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .bksesh-cs-launcher, .bksesh-cs-send { animation: none; }
    .bksesh-cs-launcher .icon-sparkle, .bksesh-cs-launcher .icon-text { animation: none; }
    .bksesh-cs-status-dot { animation: none; }
    .bksesh-cs-typing span { animation: none; opacity: .6; }
    .bksesh-cs-msg { animation: none; }
    .bksesh-cs-panel { transition: opacity .15s; }
}
