/* Widget de chat del dashboard — usa los tokens de dashboard/index.css */

.cw-fab {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 48px;
    padding: 0 20px 0 16px;
    border-radius: 999px;
    background: var(--ink);
    color: var(--ink-contrast);
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    transition: transform .15s, box-shadow .15s, opacity .2s;
}
.cw-fab:hover { transform: translateY(-2px); }
.cw-fab.is-hidden { opacity: 0; pointer-events: none; transform: scale(.9); }
.cw-badge {
    min-width: 20px; height: 20px; padding: 0 6px;
    border-radius: 999px;
    background: #ef4444; color: #fff;
    font-size: 11px; font-weight: 700;
    display: none; place-items: center;
}
.cw-badge.is-visible { display: inline-grid; }

.cw-panel {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2600;
    width: 390px;
    height: min(640px, calc(100vh - 40px));
    height: min(640px, calc(100dvh - 40px));
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(16, 24, 40, .22);
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(.92) translateY(12px);
    opacity: 0;
    pointer-events: none;
    transition: transform .2s ease, opacity .2s ease;
}
.cw-panel.is-open { transform: none; opacity: 1; pointer-events: auto; }

/* Cabecera */
.cw-head {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 12px 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.cw-head .brand-mark { width: 38px; height: 38px; }
.cw-head-text { flex: 1; min-width: 0; line-height: 1.25; }
.cw-head-text strong { display: block; font-size: 14.5px; font-weight: 700; }
.cw-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); }
.cw-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.cw-status[data-state="connected"]::before { background: #22c55e; }
.cw-status[data-state="connecting"]::before,
.cw-status[data-state="reconnecting"]::before { background: #f59e0b; animation: cw-blink 1s infinite; }
.cw-status[data-state="error"]::before { background: #ef4444; }
@keyframes cw-blink { 50% { opacity: .3; } }

.cw-head-actions { display: flex; gap: 2px; }
.cw-icon-btn {
    width: 34px; height: 34px; border-radius: 10px;
    display: grid; place-items: center;
    color: var(--text-3);
    transition: background .15s, color .15s;
}
.cw-icon-btn:hover { background: var(--surface-2); color: var(--text); }
.cw-icon-btn.is-confirm { background: #fee2e2; color: #b91c1c; width: auto; padding: 0 10px; font-size: 12px; font-weight: 600; }
.cw-icon-btn[hidden] { display: none; }

/* Formulario */
.cw-form {
    flex: 1;
    overflow-y: auto;
    padding: 22px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.cw-form h3 { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.cw-form > p { font-size: 13.5px; color: var(--text-2); margin-top: -8px; }
.cw-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cw-field { display: flex; flex-direction: column; gap: 6px; }
.cw-field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.cw-field label span { color: var(--anticretico); }
.cw-input, .cw-select {
    height: 42px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    outline: none;
    width: 100%;
    min-width: 0;
    transition: border-color .15s, box-shadow .15s;
}
.cw-input:focus, .cw-select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.cw-input.is-invalid { border-color: #ef4444; }
.cw-phone { display: grid; grid-template-columns: 160px 1fr; gap: 8px; }
.cw-error { font-size: 12px; color: #dc2626; min-height: 0; }
.cw-error:empty { display: none; }
.cw-submit {
    margin-top: 4px;
    height: 46px;
    border-radius: 12px;
    background: var(--ink);
    color: var(--ink-contrast);
    font-size: 14.5px;
    font-weight: 600;
    transition: filter .15s;
}
.cw-submit:hover { filter: brightness(1.15); }
.cw-note { font-size: 11.5px; color: var(--text-3); text-align: center; }

/* Conversación */
.cw-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.cw-chat[hidden], .cw-form[hidden] { display: none; }
.cw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg);
}
.cw-day { align-self: center; font-size: 11px; color: var(--text-3); padding: 2px 10px; border-radius: 999px; background: var(--surface-2); }
.cw-msg { display: flex; flex-direction: column; max-width: 84%; }
.cw-msg.bot { align-self: flex-start; }
.cw-msg.user { align-self: flex-end; align-items: flex-end; }
.cw-bubble {
    padding: 10px 13px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    overflow-wrap: anywhere;
    white-space: pre-line;
}
.cw-msg.bot .cw-bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; color: var(--text); }
.cw-msg.user .cw-bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 6px; }
:root[data-theme="dark"] .cw-msg.user .cw-bubble { color: var(--brand-contrast); }
.cw-bubble a { color: var(--brand); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.cw-msg.user .cw-bubble a { color: inherit; }
.cw-bubble strong { font-weight: 700; }
.cw-bubble ul { margin: 4px 0; padding-left: 18px; white-space: normal; }
.cw-bubble li { margin: 2px 0; }
.cw-bubble img { display: block; max-width: 100%; border-radius: 10px; margin-top: 4px; }
/* Respuestas en HTML (tarjetas de propiedades) */
.cw-msg.bot:has(.cw-bubble.rich) { max-width: 92%; }
.cw-bubble.rich { white-space: normal; padding: 12px; }
.cw-bubble.rich h4 { font-size: 14px; font-weight: 700; line-height: 1.35; margin: 0 0 10px; }
.cw-bubble.rich h4 a { color: var(--text); text-decoration: none; }
.cw-bubble.rich h4 a:hover { color: var(--brand); }
.cw-bubble.rich p { margin: 6px 0; }
.cw-bubble.rich ul { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; }
.cw-bubble.rich ul + ul { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.cw-bubble.rich li { position: relative; padding-left: 14px; margin: 0; font-size: 13px; color: var(--text-2); }
.cw-bubble.rich li::before { content: ""; position: absolute; left: 2px; top: .62em; width: 5px; height: 5px; border-radius: 50%; background: var(--brand); }
.cw-bubble.rich li b, .cw-bubble.rich li strong { color: var(--text); font-weight: 600; }
.cw-gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; border-radius: 12px; overflow: hidden; }
.cw-gallery > * { aspect-ratio: 4 / 3; overflow: hidden; background: var(--surface-3); }
.cw-gallery img { width: 100%; height: 100%; object-fit: cover; margin: 0; border-radius: 0; cursor: zoom-in; transition: transform .3s; }
.cw-gallery img:hover { transform: scale(1.04); }
.cw-bubble.rich a.cw-cta {
    display: flex; align-items: center; justify-content: center;
    margin-top: 12px; height: 38px; border-radius: 10px;
    background: var(--ink); color: var(--ink-contrast);
    font-size: 13px; font-weight: 600; text-decoration: none;
}
.cw-bubble.rich a.cw-cta:hover { filter: brightness(1.15); }
.cw-time { font-size: 10.5px; color: var(--text-3); margin-top: 3px; padding: 0 4px; }

.cw-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.cw-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); animation: cw-bounce 1.2s infinite; }
.cw-typing span:nth-child(2) { animation-delay: .15s; }
.cw-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes cw-bounce { 0%, 60%, 100% { transform: none; opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.cw-empty { margin: auto; text-align: center; color: var(--text-3); font-size: 13px; padding: 20px; }
.cw-empty strong { display: block; color: var(--text); font-size: 14px; margin-bottom: 4px; }

.cw-to-bottom {
    position: absolute; right: 14px; bottom: 76px;
    width: 34px; height: 34px; border-radius: 50%;
    display: none; place-items: center;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text-2); box-shadow: var(--shadow-md);
}
.cw-to-bottom.is-visible { display: grid; }

.cw-composer {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}
.cw-composer textarea {
    flex: 1;
    min-height: 42px;
    max-height: 120px;
    resize: none;
    padding: 10px 14px;
    border-radius: 21px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
}
.cw-composer textarea:focus { border-color: var(--brand); background: var(--surface); }
.cw-send {
    width: 42px; height: 42px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--brand); color: #fff;
    flex-shrink: 0;
    transition: filter .15s, opacity .15s;
}
:root[data-theme="dark"] .cw-send { color: var(--brand-contrast); }
.cw-send:disabled { opacity: .4; cursor: not-allowed; }
.cw-send:not(:disabled):hover { filter: brightness(1.1); }

@media (max-width: 860px) {
    .cw-fab { right: 16px; bottom: 16px; }
    .cw-panel { right: 0; bottom: 0; width: 100%; height: 100%; border-radius: 0; border: none; }
}
