/* ===================================================================
 *  BPC Chatbot Widget — Styles
 *  Version: 1.0.0
 * =================================================================== */

/* ── Variables ───────────────────────────────────────────────────── */
:root {
    --bpc-chat-primary: #4f46e5;
    --bpc-chat-primary-hover: #4338ca;
    --bpc-chat-primary-light: #eef2ff;
    --bpc-chat-bg: #ffffff;
    --bpc-chat-bg-alt: #f8fafc;
    --bpc-chat-text: #1e293b;
    --bpc-chat-text-muted: #64748b;
    --bpc-chat-border: #e2e8f0;
    --bpc-chat-user-bg: #4f46e5;
    --bpc-chat-user-text: #ffffff;
    --bpc-chat-bot-bg: #f1f5f9;
    --bpc-chat-bot-text: #1e293b;
    --bpc-chat-radius: 16px;
    --bpc-chat-shadow: 0 20px 60px rgba(0,0,0,.15), 0 4px 16px rgba(0,0,0,.08);
    --bpc-chat-bubble-size: 60px;
    --bpc-chat-width: 400px;
    --bpc-chat-height: 580px;
    --bpc-chat-z: 99999;
}

/* ── Bubble trigger ──────────────────────────────────────────────── */
.bpc-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: var(--bpc-chat-bubble-size);
    height: var(--bpc-chat-bubble-size);
    border-radius: 50%;
    background: var(--bpc-chat-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(79,70,229,.4);
    z-index: var(--bpc-chat-z);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease, box-shadow .2s ease;
    padding: 0;
    outline: none;
}
.bpc-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(79,70,229,.5);
}
.bpc-chat-bubble svg {
    width: 28px;
    height: 28px;
    fill: #fff;
    transition: opacity .2s ease, transform .2s ease;
}
.bpc-chat-bubble .bpc-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}
.bpc-chat-bubble.is-open .bpc-icon-chat {
    opacity: 0;
    transform: rotate(90deg);
}
.bpc-chat-bubble.is-open .bpc-icon-close {
    opacity: 1;
    transform: rotate(0);
}

/* Unread badge */
.bpc-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0);
    transition: all .2s ease;
}
.bpc-chat-badge.visible {
    opacity: 1;
    transform: scale(1);
}

/* ── Window container ────────────────────────────────────────────── */
.bpc-chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: var(--bpc-chat-width);
    height: var(--bpc-chat-height);
    max-height: calc(100vh - 130px);
    background: var(--bpc-chat-bg);
    border-radius: var(--bpc-chat-radius);
    box-shadow: var(--bpc-chat-shadow);
    z-index: var(--bpc-chat-z);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(.95);
    pointer-events: none;
    transition: opacity .25s ease, transform .25s ease;
}
.bpc-chat-window.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Header ──────────────────────────────────────────────────────── */
.bpc-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    background: var(--bpc-chat-primary);
    color: #fff;
    flex-shrink: 0;
}
.bpc-chat-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.bpc-chat-header-avatar svg {
    width: 22px;
    height: 22px;
    fill: #fff;
}
.bpc-chat-header-info {
    flex: 1;
    min-width: 0;
}
.bpc-chat-header-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
}
.bpc-chat-header-subtitle {
    font-size: 12px;
    opacity: .8;
    line-height: 1.3;
}

/* ── Messages area ───────────────────────────────────────────────── */
.bpc-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bpc-chat-bg-alt);
    scroll-behavior: smooth;
}
.bpc-chat-messages::-webkit-scrollbar {
    width: 5px;
}
.bpc-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.bpc-chat-messages::-webkit-scrollbar-thumb {
    background: var(--bpc-chat-border);
    border-radius: 3px;
}

/* ── Single message ──────────────────────────────────────────────── */
.bpc-chat-msg {
    max-width: 85%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: bpcMsgIn .25s ease;
}
@keyframes bpcMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.bpc-chat-msg.is-user {
    align-self: flex-end;
}
.bpc-chat-msg.is-bot {
    align-self: flex-start;
}

.bpc-chat-msg-body {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}
.bpc-chat-msg.is-user .bpc-chat-msg-body {
    background: var(--bpc-chat-user-bg);
    color: var(--bpc-chat-user-text);
    border-bottom-right-radius: 4px;
}
.bpc-chat-msg.is-bot .bpc-chat-msg-body {
    background: var(--bpc-chat-bot-bg);
    color: var(--bpc-chat-bot-text);
    border-bottom-left-radius: 4px;
}

/* Markdown in bot messages */
.bpc-chat-msg.is-bot .bpc-chat-msg-body p {
    margin: 0 0 8px;
}
.bpc-chat-msg.is-bot .bpc-chat-msg-body p:last-child {
    margin-bottom: 0;
}
.bpc-chat-msg.is-bot .bpc-chat-msg-body strong {
    font-weight: 600;
}
.bpc-chat-msg.is-bot .bpc-chat-msg-body ul,
.bpc-chat-msg.is-bot .bpc-chat-msg-body ol {
    margin: 6px 0;
    padding-left: 20px;
}
.bpc-chat-msg.is-bot .bpc-chat-msg-body li {
    margin-bottom: 3px;
}
.bpc-chat-msg.is-bot .bpc-chat-msg-body a {
    color: var(--bpc-chat-primary);
    text-decoration: underline;
}
.bpc-chat-msg.is-bot .bpc-chat-msg-body code {
    background: rgba(0,0,0,.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
}

/* ── Feedback row ────────────────────────────────────────────────── */
.bpc-chat-feedback {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
}
.bpc-chat-feedback button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 6px;
    font-size: 16px;
    opacity: .5;
    transition: opacity .15s, background .15s;
    line-height: 1;
}
.bpc-chat-feedback button:hover {
    opacity: 1;
    background: rgba(0,0,0,.05);
}
.bpc-chat-feedback button.is-active {
    opacity: 1;
}
.bpc-chat-feedback button.is-active.thumb-up {
    color: #16a34a;
}
.bpc-chat-feedback button.is-active.thumb-down {
    color: #dc2626;
}

/* ── Login hint banner ───────────────────────────────────────────── */
.bpc-chat-login-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 14px;
    margin: 6px 0;
    background: linear-gradient(135deg, #f0f4ff 0%, #e8f0fe 100%);
    border: 1px solid #c7d2fe;
    border-radius: 12px;
    font-size: 13px;
    color: #4338ca;
    line-height: 1.4;
}
.bpc-chat-login-hint .bpc-login-link {
    display: inline-block;
    padding: 4px 12px;
    background: var(--bpc-chat-primary, #4f46e5);
    color: #fff !important;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s;
    white-space: nowrap;
}
.bpc-chat-login-hint .bpc-login-link:hover {
    background: var(--bpc-chat-primary-hover, #4338ca);
}

/* ── Typing indicator ────────────────────────────────────────────── */
.bpc-chat-typing {
    align-self: flex-start;
    display: none;
    gap: 5px;
    padding: 12px 18px;
    background: var(--bpc-chat-bot-bg);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
.bpc-chat-typing.visible {
    display: flex;
}
.bpc-chat-typing span {
    width: 8px;
    height: 8px;
    background: var(--bpc-chat-text-muted);
    border-radius: 50%;
    animation: bpcTyping 1.2s infinite ease-in-out;
}
.bpc-chat-typing span:nth-child(2) { animation-delay: .15s; }
.bpc-chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bpcTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: .4; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* ── Suggestions chips ───────────────────────────────────────────── */
.bpc-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 12px;
    background: var(--bpc-chat-bg-alt);
}
.bpc-chat-chip {
    display: inline-block;
    padding: 6px 12px;
    font-size: 13px;
    background: var(--bpc-chat-bg);
    border: 1px solid var(--bpc-chat-border);
    border-radius: 20px;
    color: var(--bpc-chat-text);
    cursor: pointer;
    transition: border-color .15s, background .15s;
    white-space: nowrap;
    line-height: 1.3;
}
.bpc-chat-chip:hover {
    border-color: var(--bpc-chat-primary);
    background: var(--bpc-chat-primary-light);
    color: var(--bpc-chat-primary);
}

/* ── Actions (links) ─────────────────────────────────────────────── */
.bpc-chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.bpc-chat-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    font-size: 12px;
    background: var(--bpc-chat-primary);
    color: #fff;
    border-radius: 16px;
    text-decoration: none;
    transition: background .15s;
    line-height: 1.3;
}
.bpc-chat-action:hover {
    background: var(--bpc-chat-primary-hover);
    color: #fff;
    text-decoration: none;
}

/* ── Input area ──────────────────────────────────────────────────── */
.bpc-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--bpc-chat-border);
    background: var(--bpc-chat-bg);
    flex-shrink: 0;
}
.bpc-chat-input {
    flex: 1;
    border: 1px solid var(--bpc-chat-border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    max-height: 100px;
    outline: none;
    transition: border-color .15s;
    background: var(--bpc-chat-bg);
    color: var(--bpc-chat-text);
}
.bpc-chat-input:focus {
    border-color: var(--bpc-chat-primary);
}
.bpc-chat-input::placeholder {
    color: var(--bpc-chat-text-muted);
}
.bpc-chat-send {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--bpc-chat-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .15s;
    padding: 0;
}
.bpc-chat-send:hover {
    background: var(--bpc-chat-primary-hover);
}
.bpc-chat-send:active {
    transform: scale(.92);
}
.bpc-chat-send:disabled {
    opacity: .5;
    cursor: not-allowed;
}
.bpc-chat-send svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* ── Footer / branding ───────────────────────────────────────────── */
.bpc-chat-footer {
    text-align: center;
    padding: 6px;
    font-size: 11px;
    color: var(--bpc-chat-text-muted);
    background: var(--bpc-chat-bg);
    border-top: 1px solid var(--bpc-chat-border);
    flex-shrink: 0;
}
.bpc-chat-footer a {
    color: var(--bpc-chat-primary);
    text-decoration: none;
}

/* ── Escalation Form Overlay ─────────────────────────────────────── */
.bpc-chat-escalation-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: 20px;
    backdrop-filter: blur(2px);
}
.bpc-chat-escalation-form {
    background: var(--bpc-chat-bg);
    border-radius: 14px;
    padding: 20px;
    width: 100%;
    max-width: 340px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .18);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.bpc-chat-escalation-form h3 {
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 600;
    color: var(--bpc-chat-text);
}
.bpc-chat-escalation-form input,
.bpc-chat-escalation-form textarea {
    width: 100%;
    border: 1px solid var(--bpc-chat-border);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--bpc-chat-text);
    background: var(--bpc-chat-bg);
    outline: none;
    transition: border-color .15s;
    box-sizing: border-box;
}
.bpc-chat-escalation-form input:focus,
.bpc-chat-escalation-form textarea:focus {
    border-color: var(--bpc-chat-primary);
}
.bpc-chat-escalation-form textarea {
    resize: vertical;
    min-height: 70px;
}
.bpc-esc-buttons {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}
.bpc-esc-send {
    flex: 1;
    padding: 9px 16px;
    border: none;
    border-radius: 8px;
    background: var(--bpc-chat-primary);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.bpc-esc-send:hover {
    background: var(--bpc-chat-primary-hover);
}
.bpc-esc-send:disabled {
    opacity: .5;
    cursor: not-allowed;
}
.bpc-esc-cancel {
    padding: 9px 16px;
    border: 1px solid var(--bpc-chat-border);
    border-radius: 8px;
    background: var(--bpc-chat-bg);
    color: var(--bpc-chat-text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: border-color .15s, color .15s;
}
.bpc-esc-cancel:hover {
    border-color: var(--bpc-chat-primary);
    color: var(--bpc-chat-text);
}
.bpc-esc-status {
    font-size: 12px;
    text-align: center;
    min-height: 18px;
}
.bpc-esc-status.is-success {
    color: #16a34a;
}
.bpc-esc-status.is-error {
    color: #dc2626;
}

/* ── Avatar image in header ──────────────────────────────────────── */
.bpc-chat-header-avatar img {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .bpc-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    .bpc-chat-bubble {
        bottom: 16px;
        right: 16px;
    }
    .bpc-chat-window.is-open ~ .bpc-chat-bubble {
        display: none;
    }
}
