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

#brc-widget {
    position: fixed;
    z-index: 99999;
    font-family: var(--brc-font-family, 'Segoe 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; }

/* ── Launcher pill ───────────────────────────────────────────────────── */
#brc-launcher {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 0 12px;
    height: 52px;
    border-radius: 100px;
    border: none;
    cursor: pointer;
    background: var(--brc-gradient);
    color: var(--brc-text-color, #fff);
    box-shadow: 0 4px 22px rgba(0,0,0,0.22);
    transition: transform 0.2s, box-shadow 0.2s;
    white-space: nowrap;
    max-width: 320px;
    font-family: inherit;
}
#brc-launcher:hover { transform: translateY(-2px); box-shadow: 0 7px 28px rgba(0,0,0,0.28); }

.brc-launcher-content { display: inline-flex; align-items: center; gap: 10px; }
.brc-icon-close { display: none !important; }
#brc-widget.brc-open .brc-icon-open  { display: none !important; }
#brc-widget.brc-open .brc-icon-close { display: inline-flex !important; }

.brc-launcher-icon-wrap {
    width: 32px; height: 32px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.brc-launcher-icon-wrap svg { width: 18px; height: 18px; fill: currentColor; }
.brc-custom-icon-img { width: 22px; height: 22px; object-fit: contain; border-radius: 4px; }
.brc-launcher-label { font-size: 13.5px; font-weight: 600; font-family: inherit; }

/* ── Chat window — Desktop ───────────────────────────────────────────── */
#brc-window {
    display: none;
    flex-direction: column;
    width: 360px;
    height: 540px;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 16px 50px rgba(0,0,0,0.2);
    overflow: hidden;
    margin-bottom: 12px;
    font-family: inherit;
    font-size: inherit;
}
#brc-widget.brc-open #brc-window {
    display: flex;
    animation: brc-slide-up 0.25s ease;
}
@keyframes brc-slide-up {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

    /* Widget anchors to all four corners — launcher stays bottom-right */
    #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%;
        /* Keep widget itself non-blocking until open */
        pointer-events: none;
        display: block;
        align-items: unset;
    }

    /* Launcher stays in its corner, re-enable pointer events */
    #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;
    }

    /* Chat window fills entire screen — no gaps, no rounded corners */
    #brc-widget.brc-open #brc-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        /* Use dvh (dynamic viewport height) so mobile browser chrome is accounted for */
        height: 100dvh;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        margin-bottom: 0;
        box-shadow: none;
        pointer-events: auto;
        /* Slide in from bottom on mobile */
        animation: brc-mobile-up 0.28s ease;
    }

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

    /* Header — slightly taller on mobile for easier tap */
    #brc-header {
        padding: 18px 16px;
        padding-top: max(18px, env(safe-area-inset-top)); /* iPhone notch */
    }

    /* Messages area fills available space */
    #brc-messages {
        flex: 1;
        padding: 14px 12px;
    }

    /* Bubbles can be wider on mobile */
    .brc-message { max-width: 92%; }

    /* Input area — respect iPhone home bar */
    #brc-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    /* Suggestion chips scrollable horizontally on mobile */
    #brc-suggestions {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 8px 12px;
    }
    #brc-suggestions::-webkit-scrollbar { display: none; }
}

/* ── Header ──────────────────────────────────────────────────────────── */
#brc-header {
    background: var(--brc-gradient);
    color: var(--brc-text-color, #fff);
    padding: 16px 18px;
    display: flex; align-items: center; gap: 12px;
    flex-shrink: 0;
}
.brc-header-avatar {
    width: 38px; height: 38px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.brc-header-avatar svg { width: 20px; height: 20px; fill: currentColor; }
.brc-header-avatar .brc-custom-icon-img { width: 26px; height: 26px; border-radius: 4px; }
.brc-header-info { display: flex; flex-direction: column; }
.brc-header-info strong { font-size: 15px; font-weight: 700; }
.brc-header-info span   { font-size: 12px; opacity: 0.85; margin-top: 2px; display: flex; align-items: center; gap: 5px; }
.brc-status-dot { width: 7px; height: 7px; background: #4ade80; border-radius: 50%; animation: brc-pulse 2s infinite; }
@keyframes brc-pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }


/* ── Close button (mobile only) ──────────────────────────────────────── */
#brc-close {
    display: none; /* hidden on desktop */
    position: absolute;
    top: 50%;
    right: 14px;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--brc-text-color, #fff);
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
    padding: 0;
}
#brc-close:hover { background: rgba(255,255,255,0.35); }
#brc-close svg   { display: block; fill: currentColor; }

@media (max-width: 480px) {
    #brc-close {
        display: flex; /* show on mobile */
    }
    /* Make header position:relative so absolute close btn works */
    #brc-header {
        position: relative;
        /* Leave room on right for the close button */
        padding-right: 56px;
    }
}
/* ── Messages ────────────────────────────────────────────────────────── */
#brc-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 10px;
    background: #f8f9fb;
}
#brc-messages::-webkit-scrollbar { width: 4px; }
#brc-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

.brc-message { display: flex; align-items: flex-end; gap: 7px; max-width: 88%; animation: brc-fade 0.25s ease; }
@keyframes brc-fade { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:translateY(0)} }
.brc-message.brc-bot  { align-self: flex-start; }
.brc-message.brc-user { align-self: flex-end; flex-direction: row-reverse; }

.brc-bubble {
    padding: 10px 14px; border-radius: 16px;
    font-size: inherit; line-height: 1.55;
    white-space: pre-wrap; word-break: break-word;
}
.brc-bot  .brc-bubble { background: #fff; color: #1f2937; border-bottom-left-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.brc-user .brc-bubble { background: var(--brc-gradient); color: var(--brc-text-color,#fff); border-bottom-right-radius: 4px; }

.brc-bot-icon {
    width: 26px; height: 26px;
    background: var(--brc-gradient);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; color: #fff;
}
.brc-bot-icon svg { width: 13px; height: 13px; fill: currentColor; }

/* ── 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;
    /* Ensure links aren't blocked by any parent pointer-events */
    pointer-events: auto;
}
.brc-bubble a.brc-link:hover { opacity: 0.72; }
.brc-bubble a.brc-link:visited { color: var(--brc-secondary); }

/* ── Typing ──────────────────────────────────────────────────────────── */
.brc-typing { display:flex; align-items:center; gap:4px; padding:10px 14px; background:#fff; border-radius:16px; border-bottom-left-radius:4px; box-shadow:0 1px 3px rgba(0,0,0,.08); }
.brc-typing span { width:7px; height:7px; background:var(--brc-primary); border-radius:50%; animation:brc-bounce 1.2s infinite; }
.brc-typing span:nth-child(2){animation-delay:.2s} .brc-typing span:nth-child(3){animation-delay:.4s}
@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 14px; background:#fff; border-top:1px solid #f0f0f0; }
.brc-chip {
    font-size: 12px; padding: 5px 12px;
    background: #f0f0ff; color: var(--brc-primary);
    border: 1px solid #d4d4ff; border-radius: 20px;
    cursor: pointer; transition: background 0.15s;
    white-space: nowrap;
}
.brc-chip:hover { background: #e0e0ff; }

/* ── Input area ──────────────────────────────────────────────────────── */
#brc-input-area {
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
    align-items: stretch;
    flex-shrink: 0;
}
#brc-input {
    flex: 1;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: inherit;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 90px;
    min-height: 40px;
    line-height: 1.45;
    transition: border-color 0.2s;
    color: #1f2937;
    box-sizing: border-box;
}
#brc-input:focus { border-color: var(--brc-primary); }

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

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