/* ── BeatRoute Chat Widget ───────────────────────────────────────────── */

#brc-widget {
    position: fixed;
    z-index: 99999;
    font-family: var(--brc-font-family, -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif);
    font-size: var(--brc-font-size, 14px);
}

/* Desktop positioning */
#brc-widget.brc-position-bottom-right { bottom: 24px; right: 24px; display: flex; flex-direction: column; align-items: flex-end; }
#brc-widget.brc-position-bottom-left  { bottom: 24px; left: 24px;  display: flex; flex-direction: column; align-items: flex-start; }

/* ── Greeting bubble ─────────────────────────────────────────────────── */
#brc-greeting-bubble {
    background: #fff;
    border-radius: 14px 14px 4px 14px;
    padding: 10px 32px 10px 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    border: 1px solid #f0f0f0;
    max-width: 240px;
    margin-bottom: 10px;
    font-size: 13px;
    font-weight: 500;
    color: #111827;
    line-height: 1.4;
    position: relative;
    cursor: pointer;
    white-space: nowrap;
}
#brc-greeting-bubble span {
    display: block;
    font-size: 11.5px;
    font-weight: 400;
    color: #6b7280;
    margin-top: 2px;
}
#brc-greeting-bubble.brc-bubble-visible {
    animation: brc-bubble-in 0.35s cubic-bezier(0.34, 1.26, 0.64, 1);
}
@keyframes brc-bubble-in {
    from { opacity: 0; transform: translateY(8px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
#brc-greeting-bubble.brc-bubble-hiding {
    animation: brc-bubble-out 0.18s ease forwards;
}
@keyframes brc-bubble-out {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(5px); }
}
#brc-greeting-dismiss {
    position: absolute;
    top: 7px; right: 9px;
    background: none; border: none;
    color: #9ca3af; cursor: pointer;
    font-size: 15px; line-height: 1;
    padding: 1px 3px;
}
#brc-greeting-dismiss:hover { color: #374151; }

/* ── Launcher circle FAB ─────────────────────────────────────────────── */
#brc-launcher {
    width: 52px; height: 52px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--brc-gradient);
    color: var(--brc-text-color, #fff);
    /* colored glow shadow set dynamically in JS */
    box-shadow: 0 4px 18px rgba(0,0,0,0.22);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-family: inherit;
}
#brc-launcher:hover { transform: scale(1.07); }
#brc-widget.brc-open #brc-launcher { display: none; }

.brc-custom-icon-img { width: 26px; height: 26px; object-fit: contain; border-radius: 50%; }
#brc-launcher svg { width: 22px; height: 22px; fill: currentColor; }

/* ── Chat window — Desktop ───────────────────────────────────────────── */
#brc-window {
    display: none;
    flex-direction: column;
    width: 380px;
    height: 580px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.14), 0 1px 4px rgba(0,0,0,0.08);
    border: 1px solid rgba(0,0,0,0.07);
    overflow: hidden;
    margin-bottom: 12px;
    font-family: inherit;
    font-size: inherit;
}
#brc-widget.brc-open #brc-window {
    display: flex;
    animation: brc-slide-up 0.22s cubic-bezier(0.34, 1.26, 0.64, 1);
}
@keyframes brc-slide-up {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── MOBILE: Full-screen takeover ────────────────────────────────────── */
@media (max-width: 480px) {

    #brc-widget,
    #brc-widget.brc-position-bottom-right,
    #brc-widget.brc-position-bottom-left {
        top: 0; left: 0; right: 0; bottom: 0;
        width: 100%; height: 100%;
        pointer-events: none;
        display: block;
        align-items: unset;
    }

    #brc-launcher {
        position: fixed;
        bottom: 20px; right: 20px;
        pointer-events: auto;
        z-index: 100000;
    }
    #brc-widget.brc-position-bottom-left #brc-launcher { right: auto; left: 20px; }

    /* Pin the greeting bubble fixed, just above the launcher, matching its alignment */
    #brc-greeting-bubble {
        position: fixed;
        bottom: 82px;   /* launcher height (52) + gap (10) + launcher bottom (20) */
        right: 20px;
        left: auto;
        max-width: calc(100vw - 40px);
        font-size: 13px;
        pointer-events: auto;
        white-space: normal;
    }
    #brc-widget.brc-position-bottom-left #brc-greeting-bubble { right: auto; left: 20px; }

    #brc-widget.brc-open #brc-window {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        width: 100%; height: 100%; height: 100dvh;
        max-width: 100%; max-height: 100%;
        border-radius: 0;
        margin-bottom: 0;
        box-shadow: none;
        border: none;
        pointer-events: auto;
        animation: brc-mobile-up 0.28s ease;
    }

    @keyframes brc-mobile-up {
        from { opacity: 0; transform: translateY(100%); }
        to   { opacity: 1; transform: translateY(0); }
    }

    #brc-header { padding: max(18px, env(safe-area-inset-top)) 16px 16px; }
    #brc-messages { flex: 1; padding: 16px 14px; }
    .brc-message { max-width: 90%; }
    #brc-input-area {
        padding: 10px 14px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    #brc-suggestions {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 8px 14px;
    }
    #brc-suggestions::-webkit-scrollbar { display: none; }
}

/* ── Header ──────────────────────────────────────────────────────────── */
#brc-header {
    background: #ffffff;
    border-bottom: 1px solid #f0f1f3;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.brc-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brc-header-avatar {
    width: 40px; height: 40px;
    background: var(--brc-gradient);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    color: #fff;
}
.brc-header-avatar svg { width: 20px; height: 20px; fill: currentColor; }
.brc-header-avatar .brc-custom-icon-img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }

.brc-header-info { display: flex; flex-direction: column; gap: 1px; }
.brc-header-info strong { font-size: 15px; font-weight: 700; color: #111827; line-height: 1.2; }
.brc-header-info span   { font-size: 12px; color: #6b7280; display: flex; align-items: center; gap: 5px; }
.brc-status-dot {
    width: 7px; height: 7px;
    background: #22c55e;
    border-radius: 50%;
    animation: brc-pulse 2.5s infinite;
}
@keyframes brc-pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* ── Close button (always visible) ───────────────────────────────────── */
#brc-close {
    width: 32px; height: 32px;
    background: #f3f4f6;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: #6b7280;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
    padding: 0;
}
#brc-close:hover { background: #e5e7eb; color: #111827; }
#brc-close svg { display: block; }

/* ── Messages ────────────────────────────────────────────────────────── */
#brc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #ffffff;
}
#brc-messages::-webkit-scrollbar { width: 3px; }
#brc-messages::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 4px; }

.brc-message {
    display: flex;
    flex-direction: column;
    max-width: 84%;
    animation: brc-fade 0.2s ease;
}
@keyframes brc-fade { from{opacity:0;transform:translateY(5px)} to{opacity:1;transform:translateY(0)} }

.brc-message.brc-bot  { align-self: flex-start; align-items: flex-start; }
.brc-message.brc-user { align-self: flex-end;   align-items: flex-end; }

.brc-bubble {
    padding: 11px 15px;
    border-radius: 18px;
    font-size: inherit;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Bot bubble — light gray */
.brc-bot .brc-bubble {
    background: #f3f4f6;
    color: #111827;
    border-top-left-radius: 4px;
}

/* User bubble — primary color pill */
.brc-user .brc-bubble {
    background: var(--brc-gradient);
    color: var(--brc-text-color, #fff);
    border-top-right-radius: 4px;
}

/* Attribution line under bot messages */
.brc-attribution {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    padding-left: 2px;
    letter-spacing: 0.01em;
}

/* ── Clickable links in bot messages ─────────────────────────────────── */
.brc-bubble a.brc-link {
    color: var(--brc-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
    cursor: pointer;
    transition: opacity 0.15s;
    pointer-events: auto;
}
.brc-bubble a.brc-link:hover { opacity: 0.72; }

/* ── Typing ──────────────────────────────────────────────────────────── */
.brc-typing {
    display: flex; align-items: center; gap: 4px;
    padding: 14px 16px;
    background: #f3f4f6;
    border-radius: 18px;
    border-top-left-radius: 4px;
    width: fit-content;
}
.brc-typing span {
    width: 6px; height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: brc-bounce 1.2s infinite;
}
.brc-typing span:nth-child(2) { animation-delay: .18s; }
.brc-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes brc-bounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-5px)} }

/* ── Suggestion chips ────────────────────────────────────────────────── */
#brc-suggestions {
    display: flex; flex-wrap: wrap; gap: 6px;
    padding: 8px 16px;
    background: #fff;
    border-top: 1px solid #f0f1f3;
}
.brc-chip {
    font-size: var(--brc-chip-size, 12px); padding: 5px 13px;
    background: #f3f4f6; color: #374151;
    border: 1px solid #e5e7eb; border-radius: 20px;
    cursor: pointer; transition: background 0.15s, border-color 0.15s;
    white-space: nowrap; font-family: inherit;
}
.brc-chip:hover { background: #e9eaec; border-color: #d1d5db; }

/* ── Input area ──────────────────────────────────────────────────────── */
#brc-input-area {
    padding: 12px 14px 16px;
    background: #fff;
    border-top: 1px solid #f0f1f3;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

#brc-input {
    flex: 1;
    border: 1.5px solid #e5e7eb;
    border-radius: 22px;
    padding: 10px 16px;
    font-size: inherit;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 100px;
    min-height: 42px;
    line-height: 1.5;
    transition: border-color 0.2s;
    color: #111827;
    background: #fafafa;
    box-sizing: border-box;
}
#brc-input::placeholder { color: #9ca3af; }
#brc-input:focus { border-color: #d1d5db; background: #fff; }

#brc-send {
    width: 38px; height: 38px;
    background: var(--brc-gradient);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    color: var(--brc-text-color, #fff);
    transition: opacity 0.2s, transform 0.1s;
}
#brc-send:hover    { opacity: 0.88; transform: scale(1.06); }
#brc-send:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
#brc-send svg { width: 16px; height: 16px; fill: currentColor; }


/* ── Mobile: hide launcher when chat is open ─────────────────────────── */
@media (max-width: 480px) {
    #brc-widget.brc-open #brc-launcher { display: none; }
    #brc-header { position: relative; }
}
