/* CES Chat Widget */

#ces-widget-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9998;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #0f172a;
    border: 2px solid #4ade80;
    box-shadow: 0 4px 20px rgba(74, 222, 128, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 250ms ease, box-shadow 250ms ease;
}

#ces-widget-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(74, 222, 128, 0.45);
}

#ces-widget-btn svg {
    width: 24px;
    height: 24px;
    color: #4ade80;
    flex-shrink: 0;
}

/* Panel */
#ces-widget-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    z-index: 9999;
    width: 360px;
    max-width: calc(100vw - 32px);
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid rgba(74, 222, 128, 0.18);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* translateZ forces GPU compositing, eliminating the anti-aliasing halo at border-radius corners */
    transform: scale(0.92) translateY(12px) translateZ(0);
    transform-origin: bottom right;
    opacity: 0;
    pointer-events: none;
    transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1),
                opacity 250ms ease;
}

#ces-widget-panel.ces-open {
    transform: scale(1) translateY(0) translateZ(0);
    opacity: 1;
    pointer-events: all;
}

/* Header */
#ces-widget-header {
    background: #0f172a;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

#ces-widget-header .ces-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #4ade80;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#ces-widget-header .ces-avatar svg {
    width: 16px;
    height: 16px;
    color: #0f172a;
}

#ces-widget-header .ces-title {
    flex: 1;
}

#ces-widget-header .ces-title strong {
    display: block;
    color: #ffffff;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: 'Inter', -apple-system, sans-serif;
    line-height: 1.2;
}

#ces-widget-header .ces-title span {
    color: #4ade80;
    font-size: 0.75rem;
    font-family: 'Inter', -apple-system, sans-serif;
}

#ces-widget-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: color 150ms ease, background 150ms ease;
}

#ces-widget-close:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

#ces-widget-close svg {
    width: 16px;
    height: 16px;
}

/* Messages */
#ces-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 360px;
    min-height: 120px;
}

.ces-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    gap: 4px;
}

.ces-msg.ces-user {
    align-self: flex-end;
    align-items: flex-end;
}

.ces-msg.ces-assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.ces-msg .ces-bubble {
    padding: 10px 13px;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.55;
    font-family: 'Inter', -apple-system, sans-serif;
    color: #1e293b;
}

.ces-msg.ces-user .ces-bubble {
    background: #0f172a;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.ces-msg.ces-assistant .ces-bubble {
    background: #f1f5f9;
    border-bottom-left-radius: 4px;
}

/* Typing indicator */
.ces-typing .ces-bubble {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 13px;
}

.ces-typing .ces-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: ces-bounce 1.2s infinite ease-in-out;
}

.ces-typing .ces-dot:nth-child(2) { animation-delay: 0.18s; }
.ces-typing .ces-dot:nth-child(3) { animation-delay: 0.36s; }

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

/* Input area */
#ces-widget-input-row {
    border-top: 1px solid #e2e8f0;
    padding: 12px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

#ces-widget-input {
    flex: 1;
    resize: none;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 0.875rem;
    font-family: 'Inter', -apple-system, sans-serif;
    color: #1e293b;
    line-height: 1.4;
    max-height: 100px;
    overflow-y: auto;
    outline: none;
    transition: border-color 150ms ease;
}

#ces-widget-input:focus {
    border-color: #4ade80;
}

#ces-widget-input::placeholder {
    color: #94a3b8;
}

#ces-widget-send {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #4ade80;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 150ms ease, transform 150ms ease;
}

#ces-widget-send:hover {
    background: #22c55e;
    transform: scale(1.05);
}

#ces-widget-send:disabled {
    background: #e2e8f0;
    cursor: default;
    transform: none;
}

#ces-widget-send svg {
    width: 16px;
    height: 16px;
    color: #0f172a;
}

#ces-widget-send:disabled svg {
    color: #94a3b8;
}

/* Error state */
.ces-error .ces-bubble {
    background: #fff1f2;
    color: #e11d48;
    font-size: 0.8125rem;
}

/* Markdown rendering inside assistant bubbles */
.ces-msg.ces-assistant .ces-bubble p,
.ces-msg.ces-assistant .ces-bubble br + br {
    margin: 0;
}
.ces-msg.ces-assistant .ces-bubble ul,
.ces-msg.ces-assistant .ces-bubble ol {
    margin: 6px 0 4px 0;
    padding-left: 18px;
}
.ces-msg.ces-assistant .ces-bubble li {
    margin-bottom: 3px;
    line-height: 1.5;
}
.ces-msg.ces-assistant .ces-bubble strong {
    font-weight: 600;
    color: #0f172a;
}
.ces-msg.ces-assistant .ces-bubble em {
    font-style: italic;
}

/* Scrollbar */
#ces-widget-messages::-webkit-scrollbar {
    width: 4px;
}
#ces-widget-messages::-webkit-scrollbar-track {
    background: transparent;
}
#ces-widget-messages::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 9999px;
}

/* Mobile: full-screen panel so the keyboard doesn't cover it.
   JS uses visualViewport API to shrink the panel to the visible area. */
@media (max-width: 600px) {
    #ces-widget-panel {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        /* Slide up from bottom instead of scale on mobile */
        transform: translateY(100%) translateZ(0);
        transform-origin: bottom center;
    }

    #ces-widget-panel.ces-open {
        transform: translateY(0) translateZ(0);
    }

    #ces-widget-messages {
        max-height: none;
        min-height: 0;
        flex: 1;
    }

    #ces-widget-btn {
        bottom: 16px;
        right: 16px;
    }

    /* Larger tap targets on mobile */
    #ces-widget-input {
        font-size: 1rem; /* prevents iOS auto-zoom on focus */
    }
}
