/* ============================================================
   BPM SmartBot — Public Widget Styles
   All selectors are scoped to #bpmbot-* to avoid theme conflicts.
   ============================================================ */

#bpmbot-widget {
    --bpmbot-primary:    #2563eb;
    --bpmbot-bg:         #ffffff;
    --bpmbot-text:       #1f2937;
    --bpmbot-user-bg:    var(--bpmbot-primary);
    --bpmbot-user-text:  #ffffff;
    --bpmbot-bot-bg:     #f3f4f6;
    --bpmbot-bot-text:   var(--bpmbot-text);
    --bpmbot-border:     #e5e7eb;
    --bpmbot-shadow:     0 4px 24px rgba(0,0,0,0.15);
    --bpmbot-radius:     16px;
    --bpmbot-z:          99999;

    position: fixed;
    bottom: 24px;
    z-index: var(--bpmbot-z);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--bpmbot-text);
    box-sizing: border-box;
}

#bpmbot-widget *,
#bpmbot-widget *::before,
#bpmbot-widget *::after {
    box-sizing: inherit;
}

/* ---- Position variants ---- */

#bpmbot-widget.bpmbot-position-bottom-right {
    right: 24px;
}

#bpmbot-widget.bpmbot-position-bottom-left {
    left: 24px;
}

/* ---- Toggle button ---- */

#bpmbot-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--bpmbot-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--bpmbot-shadow);
    transition: transform 0.2s ease, background 0.2s ease;
    outline: none;
    padding: 0;
}

#bpmbot-toggle:hover {
    transform: scale(1.08);
}

#bpmbot-toggle:focus-visible {
    outline: 3px solid var(--bpmbot-primary);
    outline-offset: 3px;
}

/* ---- Chat panel ---- */

#bpmbot-panel {
    position: absolute;
    bottom: 68px;
    width: 380px;
    max-height: 520px;
    background: var(--bpmbot-bg);
    border-radius: var(--bpmbot-radius);
    box-shadow: var(--bpmbot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Hidden state */
    opacity: 0;
    transform: translateY(12px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.bpmbot-position-bottom-right #bpmbot-panel {
    right: 0;
}

.bpmbot-position-bottom-left #bpmbot-panel {
    left: 0;
}

#bpmbot-panel.bpmbot-panel-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ---- Header ---- */

#bpmbot-header {
    background: var(--bpmbot-primary);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 15px;
    flex-shrink: 0;
}

#bpmbot-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

#bpmbot-new,
#bpmbot-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    opacity: 0.85;
    transition: opacity 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}

#bpmbot-close {
    font-size: 22px;
    line-height: 1;
    padding: 0 2px;
}

#bpmbot-new:hover,
#bpmbot-close:hover { opacity: 1; }

/* ---- Messages area ---- */

#bpmbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

/* ---- Message bubbles ---- */

.bpmbot-message {
    display: flex;
    max-width: 85%;
}

.bpmbot-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.bpmbot-message-bot {
    align-self: flex-start;
}

.bpmbot-bubble {
    padding: 9px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}

.bpmbot-message-user .bpmbot-bubble {
    background: var(--bpmbot-user-bg);
    color: var(--bpmbot-user-text);
    border-bottom-right-radius: 4px;
}

.bpmbot-message-bot .bpmbot-bubble {
    background: var(--bpmbot-bot-bg);
    color: var(--bpmbot-bot-text);
    border-bottom-left-radius: 4px;
}

.bpmbot-message-error .bpmbot-bubble {
    background: #fee2e2;
    color: #991b1b;
}

/* Links inside bot messages */
.bpmbot-message-bot .bpmbot-bubble a {
    color: var(--bpmbot-primary);
    text-decoration: underline;
}

/* Inline code */
.bpmbot-message-bot .bpmbot-bubble code {
    background: rgba(0,0,0,0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.9em;
}

/* ---- Typing indicator ---- */

.bpmbot-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 14px;
}

.bpmbot-typing-indicator span {
    width: 7px;
    height: 7px;
    background: #9ca3af;
    border-radius: 50%;
    animation: bpmbot-bounce 1.2s infinite ease-in-out;
}

.bpmbot-typing-indicator span:nth-child(1) { animation-delay: 0s; }
.bpmbot-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.bpmbot-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bpmbot-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-6px); }
}

/* ---- Input bar ---- */

#bpmbot-input-bar {
    display: flex;
    align-items: flex-end;
    padding: 10px 12px;
    border-top: 1px solid var(--bpmbot-border);
    gap: 8px;
    flex-shrink: 0;
}

#bpmbot-input {
    flex: 1;
    border: 1px solid var(--bpmbot-border);
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    overflow-y: auto;
    background: #f9fafb;
    color: var(--bpmbot-text);
    transition: border-color 0.15s;
    line-height: 1.4;
}

#bpmbot-input:focus {
    border-color: var(--bpmbot-primary);
    background: #fff;
}

#bpmbot-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--bpmbot-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.15s;
    padding: 0;
}

#bpmbot-send:hover:not(:disabled) {
    transform: scale(1.08);
}

#bpmbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---- Option buttons ---- */

.bpmbot-has-options {
    flex-direction: column;
    max-width: 90%;
    align-items: flex-start;
}

.bpmbot-options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
    padding: 0 2px;
}

.bpmbot-option-btn {
    background: #fff;
    color: var(--bpmbot-primary);
    border: 1.5px solid var(--bpmbot-primary);
    border-radius: 20px;
    padding: 5px 14px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
    display: inline-block;
}

.bpmbot-option-btn:hover:not(:disabled) {
    background: var(--bpmbot-primary);
    color: #fff;
}

.bpmbot-option-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

/* ---- Inline error ---- */

.bpmbot-inline-error {
    font-size: 12px;
    color: #dc2626;
    padding: 4px 14px 0;
}

/* ---- Mobile ---- */

@media ( max-width: 480px ) {
    #bpmbot-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 75vh;
        max-height: 75dvh; /* dvh shrinks when iOS keyboard appears, keeping send button visible */
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        padding-bottom: env(safe-area-inset-bottom, 0); /* iPhone home bar */
    }

    #bpmbot-widget.bpmbot-position-bottom-right,
    #bpmbot-widget.bpmbot-position-bottom-left {
        right: 16px;
        left: auto;
        bottom: calc(16px + env(safe-area-inset-bottom, 0)); /* iPhone home bar */
    }
}
