/* AI Chat Widget — floating bubble + expandable panel.
   Designed to coexist with the existing LiveChat button (we offset above it). */

#dian-ai-widget {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

#dian-ai-widget .dai-bubble {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: auto;
    height: auto;
    padding: 0;
    border-radius: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 2147483600;
    display: flex;
    align-items: center;
    justify-content: center;
}
#dian-ai-widget .dai-bubble:focus {
    outline: 2px solid #1976d2;
    outline-offset: 4px;
}
#dian-ai-widget .dai-bubble .robot-svg {
    display: block;
    width: 68px;
    height: auto;
    overflow: visible;
    transition: transform 0.15s ease;
}
#dian-ai-widget .dai-bubble:hover .robot-svg,
#dian-ai-widget .dai-bubble:focus-visible .robot-svg {
    transform: scale(1.05);
}

@keyframes dai-robot-blink {
    0%, 92%, 100% { transform: scaleY(1); }
    94%, 98% { transform: scaleY(0.1); }
}
@keyframes dai-robot-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}
@keyframes dai-robot-antenna-left-wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-8deg); }
    75% { transform: rotate(4deg); }
}
@keyframes dai-robot-antenna-right-wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(6deg); }
    75% { transform: rotate(-4deg); }
}
@keyframes dai-robot-dot-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
    30% { transform: translateY(-5px); opacity: 1; }
}
@keyframes dai-robot-bubble-pop {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* Robot launcher animations (match standalone DIANai demo). Default on; respect OS reduce-motion. */
#dian-ai-widget .dai-bubble .robot-svg .dai-robot-eye {
    animation: dai-robot-blink 4s ease-in-out infinite;
    transform-origin: center;
    transform-box: fill-box;
}
#dian-ai-widget .dai-bubble .robot-svg .dai-robot-head {
    animation: dai-robot-bob 3s ease-in-out infinite;
    transform-origin: 155px 200px;
    transform-box: fill-box;
}
#dian-ai-widget .dai-bubble .robot-svg .dai-robot-antenna-left {
    animation: dai-robot-antenna-left-wiggle 3s ease-in-out infinite;
    transform-origin: 105px 80px;
    transform-box: fill-box;
}
#dian-ai-widget .dai-bubble .robot-svg .dai-robot-antenna-right {
    animation: dai-robot-antenna-right-wiggle 3s ease-in-out infinite;
    transform-origin: 200px 75px;
    transform-box: fill-box;
}
#dian-ai-widget .dai-bubble .robot-svg .dai-robot-bubble {
    animation: dai-robot-bubble-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s both;
    transform-origin: 90px 185px;
    transform-box: fill-box;
}
#dian-ai-widget .dai-bubble .robot-svg .dai-robot-dot {
    animation: dai-robot-dot-bounce 1.4s ease-in-out infinite;
    transform-origin: center;
    transform-box: fill-box;
}
#dian-ai-widget .dai-bubble .robot-svg .dai-robot-dot-2 { animation-delay: 0.2s; }
#dian-ai-widget .dai-bubble .robot-svg .dai-robot-dot-3 { animation-delay: 0.4s; }

@media (prefers-reduced-motion: reduce) {
    #dian-ai-widget .dai-bubble .robot-svg .dai-robot-eye,
    #dian-ai-widget .dai-bubble .robot-svg .dai-robot-head,
    #dian-ai-widget .dai-bubble .robot-svg .dai-robot-antenna-left,
    #dian-ai-widget .dai-bubble .robot-svg .dai-robot-antenna-right,
    #dian-ai-widget .dai-bubble .robot-svg .dai-robot-bubble,
    #dian-ai-widget .dai-bubble .robot-svg .dai-robot-dot {
        animation: none !important;
    }
}

#dian-ai-widget .dai-panel {
    position: fixed;
    bottom: 168px;
    right: 24px;
    width: 360px;
    height: 520px;
    max-height: calc(100vh - 200px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 2147483601;
}
#dian-ai-widget.dai-open .dai-panel { display: flex; }

#dian-ai-widget .dai-header {
    background: #1976d2;
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
#dian-ai-widget .dai-header .dai-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
}
#dian-ai-widget .dai-header .dai-actions {
    display: flex;
    gap: 8px;
}
#dian-ai-widget .dai-header button {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    font-size: 18px;
    line-height: 1;
}
#dian-ai-widget .dai-header button:hover { background: rgba(255,255,255,0.15); }
#dian-ai-widget .dai-header button svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    display: block;
}

#dian-ai-widget .dai-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px 14px;
    background: #f6f8fb;
}

#dian-ai-widget .dai-msg {
    margin-bottom: 10px;
    display: flex;
}
#dian-ai-widget .dai-msg-bubble {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}
#dian-ai-widget .dai-msg.dai-user { justify-content: flex-end; }
#dian-ai-widget .dai-msg.dai-user .dai-msg-bubble {
    background: #1976d2;
    color: #fff;
    border-bottom-right-radius: 4px;
}
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-bubble {
    background: #fff;
    color: #1f2933;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-bubble a {
    color: #1976d2;
    text-decoration: underline;
}
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-bubble a:hover { color: #145ca8; }
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-bubble p {
    margin: 0 0 8px 0;
}
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-bubble p:last-child { margin-bottom: 0; }
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-bubble ul,
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-bubble ol {
    margin: 4px 0 8px 0;
    padding-left: 22px;
}
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-bubble ul:last-child,
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-bubble ol:last-child {
    margin-bottom: 0;
}
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-bubble li {
    margin: 0 0 2px 0;
}
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-bubble li:last-child { margin-bottom: 0; }
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-meta {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 4px;
}

#dian-ai-widget .dai-typing {
    display: inline-block;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    background: #fff;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}
#dian-ai-widget .dai-typing span {
    display: inline-block;
    width: 6px; height: 6px;
    margin: 0 1px;
    background: #94a3b8;
    border-radius: 50%;
    animation: dai-bounce 1.2s infinite ease-in-out;
}
#dian-ai-widget .dai-typing span:nth-child(2) { animation-delay: 0.15s; }
#dian-ai-widget .dai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dai-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40% { transform: translateY(-4px); opacity: 1; }
}

#dian-ai-widget .dai-disclaimer {
    font-size: 11px;
    color: #64748b;
    padding: 4px 14px;
    background: #f0f3f8;
    border-top: 1px solid #e2e8f0;
    text-align: center;
}

#dian-ai-widget .dai-input-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
}
#dian-ai-widget .dai-input {
    flex: 1 1 auto;
    resize: none;
    border: 1px solid #cbd5e1;
    border-radius: 18px;
    padding: 8px 14px;
    font-size: 14px;
    line-height: 1.4;
    min-height: 38px;
    max-height: 96px;
    outline: none;
}
#dian-ai-widget .dai-input:focus { border-color: #1976d2; }

#dian-ai-widget .dai-icon-btn {
    background: #f1f5f9;
    border: none;
    border-radius: 50%;
    width: 38px; height: 38px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
#dian-ai-widget .dai-icon-btn:hover { background: #e2e8f0; }
#dian-ai-widget .dai-icon-btn svg { width: 18px; height: 18px; fill: #1976d2; }
#dian-ai-widget .dai-icon-btn.dai-active { background: #d32f2f; }
#dian-ai-widget .dai-icon-btn.dai-active svg { fill: #fff; }
#dian-ai-widget .dai-icon-btn.dai-send svg { fill: #fff; }
#dian-ai-widget .dai-icon-btn.dai-send { background: #1976d2; }
#dian-ai-widget .dai-icon-btn.dai-send:hover { background: #145ca8; }
#dian-ai-widget .dai-icon-btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

#dian-ai-widget .dai-error {
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    padding: 8px 12px;
    border-radius: 8px;
    margin: 6px 0;
    font-size: 13px;
}

#dian-ai-widget .dai-status {
    color: #1e40af;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    padding: 6px 12px;
    border-radius: 8px;
    margin: 6px 0;
    font-size: 12px;
    text-align: center;
    animation: dai-pulse 1.6s ease-in-out infinite;
}
@keyframes dai-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

/* Live-agent fallback (LiveChat) ----------------------------------------- */

/* Always-visible "Talk to a human" footer link, sits between the disclaimer and
   the input row. Muted by default to not pull focus from the AI conversation,
   but discoverable on hover. */
#dian-ai-widget .dai-footer-extras {
    padding: 4px 14px 6px;
    background: #f0f3f8;
    border-top: 1px solid #e2e8f0;
    text-align: center;
}
#dian-ai-widget .dai-live-agent-link {
    font-size: 12px;
    color: #475569;
    text-decoration: none;
    cursor: pointer;
}
#dian-ai-widget .dai-live-agent-link:hover {
    color: #1976d2;
    text-decoration: underline;
}

/* The inline offer bubble that appears after an AI failure. Same shape as a
   regular assistant bubble but with a brand-blue border to draw the eye. */
#dian-ai-widget .dai-msg.dai-assistant .dai-msg-bubble.dai-live-agent-offer {
    border: 1px solid #1976d2;
    background: #eff6ff;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}
#dian-ai-widget .dai-msg-bubble.dai-live-agent-offer .dai-live-agent-text {
    margin: 0;
}
#dian-ai-widget .dai-live-agent-btn {
    background: #1976d2;
    color: #fff;
    border: none;
    border-radius: 18px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    align-self: flex-start;
}
#dian-ai-widget .dai-live-agent-btn:hover { background: #145ca8; }
#dian-ai-widget .dai-live-agent-btn:focus { outline: 2px solid #93c5fd; outline-offset: 2px; }

@media (max-width: 480px) {
    #dian-ai-widget .dai-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: auto;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    #dian-ai-widget .dai-bubble {
        bottom: 80px;
        right: 16px;
    }
}
