/* Opolevel Chat — Estilos base */
:root {
    --opol-primary:    #2563eb;
    --opol-primary-h:  #1d4ed8;
    --opol-bg:         #f8fafc;
    --opol-border:     #e2e8f0;
    --opol-text:       #1e293b;
    --opol-text-muted: #64748b;
    --opol-bot-bg:     #f1f5f9;
    --opol-user-bg:    #dbeafe;
    --opol-error:      #fee2e2;
    --opol-error-text: #991b1b;
    --opol-radius:     12px;
    --opol-shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

.opolevel-chat {
    max-width: 800px;
    margin: 2rem auto;
    font-family: system-ui, -apple-system, sans-serif;
    color: var(--opol-text);
}

/* Header */
.opol-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1rem 1.25rem;
    background: var(--opol-primary);
    color: #fff;
    border-radius: var(--opol-radius) var(--opol-radius) 0 0;
}
.opol-header h2 { margin: 0; font-size: 1.1rem; font-weight: 600; flex: 1; }
.opol-icon { font-size: 1.4rem; }
.opol-balance { text-align: right; }
.opol-balance-label { font-size: .75rem; opacity: .85; display: block; }
.opol-balance-value { font-size: 1.4rem; font-weight: 700; }

/* Mensajes */
.opol-messages {
    min-height: 200px;
    max-height: 420px;
    overflow-y: auto;
    padding: 1rem;
    background: #fff;
    border-left: 1px solid var(--opol-border);
    border-right: 1px solid var(--opol-border);
    display: flex;
    flex-direction: column;
    gap: .75rem;
    scroll-behavior: smooth;
}

.opol-message {
    max-width: 85%;
    padding: .75rem 1rem;
    border-radius: 10px;
    line-height: 1.55;
    font-size: .9rem;
}
.opol-message p { margin: 0 0 .5rem; }
.opol-message p:last-child { margin: 0; }

.opol-message--bot {
    background: var(--opol-bot-bg);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.opol-message--user {
    background: var(--opol-user-bg);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    text-align: right;
}
.opol-message--loading {
    background: var(--opol-bot-bg);
    align-self: flex-start;
    display: flex;
    gap: .4rem;
    align-items: center;
    padding: .6rem .9rem;
}

/* Puntos indicador en el mensaje de respuesta */
.opol-puntos-badge {
    display: inline-block;
    font-size: .72rem;
    color: var(--opol-text-muted);
    margin-top: .4rem;
}

/* Typing indicator */
.opol-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--opol-text-muted);
    animation: opol-pulse 1.2s ease-in-out infinite;
}
.opol-dot:nth-child(2) { animation-delay: .2s; }
.opol-dot:nth-child(3) { animation-delay: .4s; }
@keyframes opol-pulse {
    0%, 80%, 100% { opacity: .3; transform: scale(.8); }
    40%            { opacity: 1;  transform: scale(1);   }
}

/* Formulario */
.opol-form {
    background: var(--opol-bg);
    border: 1px solid var(--opol-border);
    border-radius: 0 0 var(--opol-radius) var(--opol-radius);
    padding: 1rem 1.25rem;
}

.opol-accion-selector {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: .75rem;
    flex-wrap: wrap;
}
.opol-accion-selector label { font-size: .85rem; color: var(--opol-text-muted); white-space: nowrap; }
.opol-accion-selector select {
    border: 1px solid var(--opol-border);
    border-radius: 6px;
    padding: .35rem .6rem;
    font-size: .85rem;
    background: #fff;
    cursor: pointer;
}
.opol-coste-preview { font-size: .82rem; color: var(--opol-text-muted); margin-left: auto; }

.opol-input-area { position: relative; }
.opol-input-area textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--opol-border);
    border-radius: 8px;
    padding: .7rem .9rem;
    font-size: .9rem;
    font-family: inherit;
    resize: vertical;
    line-height: 1.5;
    transition: border-color .15s;
}
.opol-input-area textarea:focus {
    outline: none;
    border-color: var(--opol-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.opol-char-count {
    text-align: right;
    font-size: .72rem;
    color: var(--opol-text-muted);
    margin-top: .25rem;
}

.opol-form-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: .75rem;
}

.opol-btn-primary {
    background: var(--opol-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: .6rem 1.4rem;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, transform .1s;
}
.opol-btn-primary:hover   { background: var(--opol-primary-h); }
.opol-btn-primary:active  { transform: scale(.98); }
.opol-btn-primary:disabled {
    opacity: .55;
    cursor: not-allowed;
    transform: none;
}

/* Error */
.opol-error {
    background: var(--opol-error);
    color: var(--opol-error-text);
    border: 1px solid #fca5a5;
    border-radius: 8px;
    padding: .75rem 1rem;
    font-size: .88rem;
    margin-top: .75rem;
}

/* Invitado */
.opolevel-guest { padding: 1.5rem; background: #fff; border: 1px solid var(--opol-border); border-radius: var(--opol-radius); text-align: center; }

/* Fuentes */
.opol-fuentes { margin-top: .5rem; font-size: .78rem; color: var(--opol-text-muted); }
.opol-fuentes a { color: var(--opol-primary); }
