/*
 * CLE MasterBuilders chat widget — floating bubble + slide-out panel.
 * Scoped via .cmb-chat-* prefixes to avoid clashes with picklist page CSS.
 */

.cmb-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #c91a09;
    color: #fff;
    border: none;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    z-index: 9998;
    transition: transform 0.15s, box-shadow 0.15s;
}
.cmb-chat-bubble:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}
.cmb-chat-bubble svg { width: 28px; height: 28px; fill: currentColor; }
.cmb-chat-bubble.cmb-pulse::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid #c91a09;
    animation: cmb-pulse 1.4s ease-out infinite;
}
@keyframes cmb-pulse {
    0% { transform: scale(1); opacity: 0.7; }
    100% { transform: scale(1.4); opacity: 0; }
}

.cmb-chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    max-width: 100vw;
    background: #f4f5f7;
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.2s ease-out;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #1f2328;
}
.cmb-chat-panel.cmb-open { transform: translateX(0); }

.cmb-chat-panel * { box-sizing: border-box; }

.cmb-chat-header {
    background: linear-gradient(135deg, #c91a09, #a51409);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.cmb-chat-header h3 { font-size: 15px; margin: 0; flex: 1; font-weight: 700; }
.cmb-chat-header a, .cmb-chat-header button {
    background: rgba(255,255,255,0.18);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.cmb-chat-header a:hover, .cmb-chat-header button:hover { background: rgba(255,255,255,0.28); }

.cmb-chat-transcript {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cmb-msg {
    max-width: 90%;
    padding: 10px 13px;
    border-radius: 11px;
    line-height: 1.45;
    font-size: 14px;
    word-wrap: break-word;
}
.cmb-msg p { margin: 0 0 0.5em; }
.cmb-msg p:last-child { margin-bottom: 0; }
.cmb-msg ul, .cmb-msg ol { margin: 0.3em 0 0.3em 1.3em; padding: 0; }
.cmb-msg code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: rgba(0,0,0,0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.9em;
}
.cmb-msg pre {
    background: rgba(0,0,0,0.04);
    padding: 8px 10px;
    border-radius: 5px;
    overflow-x: auto;
    margin: 0.5em 0;
    font-size: 12px;
}
.cmb-msg-user {
    align-self: flex-end;
    background: #0055bf;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.cmb-msg-user a { color: #fff; text-decoration: underline; }
.cmb-msg-assistant {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e1e4e8;
    border-bottom-left-radius: 4px;
}
.cmb-msg-system {
    align-self: stretch;
    max-width: 100%;
    background: #fffbe6;
    border: 1px solid #f5e2a0;
    color: #5b4500;
    font-size: 13px;
}

.cmb-tool-call {
    align-self: flex-start;
    max-width: 90%;
    background: #f5f5f7;
    color: #57606a;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    padding: 5px 10px;
    border-radius: 5px;
    border: 1px solid #e1e4e8;
    cursor: pointer;
}
.cmb-tool-call.cmb-error { background: #fff0f0; color: #8a1c1c; border-color: #f3c5c5; }

.cmb-chat-composer {
    display: flex;
    gap: 8px;
    padding: 10px;
    background: #fff;
    border-top: 1px solid #e1e4e8;
    flex-shrink: 0;
}
.cmb-chat-composer textarea {
    flex: 1;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    outline: none;
    resize: none;
    font: inherit;
    font-size: 14px;
    padding: 7px 9px;
    background: #f8f9fb;
    max-height: 120px;
}
.cmb-chat-composer textarea:focus { border-color: #c91a09; background: #fff; }
.cmb-chat-composer button {
    background: #c91a09;
    color: #fff;
    border: none;
    padding: 0 14px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
}
.cmb-chat-composer button:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 500px) {
    .cmb-chat-panel { width: 100vw; }
    .cmb-chat-bubble { bottom: 16px; right: 16px; }
}
