/* ===== CHAT BOX STYLES ===== */
.assistant-widget-box {
    position: fixed !important;
    z-index: 9997 !important;
    width: 360px;
    max-height: 560px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e5e7eb;
}
.assistant-widget-box.open { display: flex; }

.assistant-widget-header {
    padding: 16px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
}
.assistant-widget-header .header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}
.assistant-widget-header .header-text { flex: 1; }
.assistant-widget-header .header-title { font-weight: 600; font-size: 15px; }
.assistant-widget-header .header-subtitle { font-size: 12px; opacity: 0.85; }

.assistant-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f9fafb;
    min-height: 250px;
}
.assistant-widget-messages::-webkit-scrollbar { width: 4px; }
.assistant-widget-messages::-webkit-scrollbar-track { background: transparent; }
.assistant-widget-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

.assistant-msg { margin-bottom: 12px; display: flex; flex-direction: column; }
.assistant-msg.ai .msg-bubble {
    background: #fff; border: 1px solid #e5e7eb;
    border-radius: 4px 16px 16px 16px; color: #1f2937; align-self: flex-start;
}
.assistant-msg.customer .msg-bubble {
    background: #2563eb; border-radius: 16px 4px 16px 16px; color: #fff; align-self: flex-end;
}
.assistant-msg.agent .msg-bubble {
    background: #059669; border-radius: 4px 16px 16px 16px; color: #fff; align-self: flex-start;
}
.assistant-msg.system .msg-bubble {
    background: #fef3c7; border: 1px solid #fde68a; border-radius: 8px;
    color: #92400e; align-self: center; text-align: center; font-size: 12px;
}
.msg-bubble { padding: 10px 14px; max-width: 85%; font-size: 14px; line-height: 1.5; word-wrap: break-word; }
.msg-time { font-size: 10px; color: #9ca3af; margin-top: 2px; padding: 0 4px; }

.assistant-widget-input {
    padding: 12px 16px; border-top: 1px solid #e5e7eb;
    display: flex; gap: 8px; align-items: center; background: #fff;
}
.assistant-widget-input input {
    flex: 1; border: 1px solid #d1d5db; border-radius: 20px;
    padding: 8px 14px; font-size: 14px; outline: none;
}
.assistant-widget-input input:focus { border-color: #2563eb; }
.assistant-widget-input button {
    width: 36px; height: 36px; border-radius: 50%; border: none; color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0; transition: opacity 0.2s;
}
.assistant-widget-input button:disabled { opacity: 0.5; cursor: not-allowed; }

.assistant-widget-start { padding: 32px 24px; text-align: center; }
.assistant-widget-start .start-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.8; }
.assistant-widget-start .start-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.assistant-widget-start .start-desc { font-size: 13px; color: #6b7280; margin-bottom: 20px; }
.assistant-widget-start .form-control {
    border-radius: 8px; padding: 10px 14px; margin-bottom: 10px;
    font-size: 14px; border: 1px solid #d1d5db;
}
.assistant-widget-start .form-control:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.assistant-widget-start .btn-start-chat {
    border: none; padding: 10px 24px; border-radius: 8px; color: #fff;
    font-weight: 500; width: 100%; cursor: pointer; transition: opacity 0.2s;
}
.assistant-widget-start .btn-start-chat:hover { opacity: 0.9; }

.assistant-widget-footer { padding: 8px 16px; text-align: center; font-size: 11px; color: #9ca3af; border-top: 1px solid #f3f4f6; background: #f9fafb; }

.assistant-typing { padding: 8px 16px; font-size: 12px; color: #6b7280; font-style: italic; display: none; }
.assistant-typing.show { display: block; }
.assistant-typing .dots { display: inline-flex; gap: 3px; margin-left: 4px; }
.assistant-typing .dots span {
    width: 5px; height: 5px; border-radius: 50%; background: #6b7280;
    animation: asstTyping 1.4s infinite ease-in-out;
}
.assistant-typing .dots span:nth-child(1) { animation-delay: -0.32s; }
.assistant-typing .dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes asstTyping { 0%,80%,100% { transform: scale(0); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

.assistant-widget-escalate { padding: 8px 16px; text-align: center; }
.assistant-widget-escalate button {
    border: 1px solid #d1d5db; background: #fff; padding: 6px 14px;
    border-radius: 6px; font-size: 12px; color: #6b7280; cursor: pointer; transition: all 0.2s;
}
.assistant-widget-escalate button:hover { border-color: #f59e0b; color: #92400e; background: #fffbeb; }

.assistant-widget-rating { padding: 16px; text-align: center; background: #f9fafb; border-top: 1px solid #e5e7eb; }
.assistant-widget-rating .rating-title { font-size: 13px; font-weight: 500; margin-bottom: 8px; }
.assistant-widget-rating .stars { display: flex; justify-content: center; gap: 4px; margin-bottom: 8px; }
.assistant-widget-rating .stars button {
    background: none; border: none; font-size: 24px; cursor: pointer;
    color: #d1d5db; transition: color 0.15s;
}
.assistant-widget-rating .stars button.active { color: #f59e0b; }
.assistant-widget-rating .stars button:hover { color: #f59e0b; }
.assistant-widget-rating .rating-feedback {
    width: 100%; padding: 8px; border: 1px solid #d1d5db;
    border-radius: 6px; font-size: 12px; resize: none; outline: none; margin-bottom: 8px;
}
.assistant-widget-rating .rating-feedback:focus { border-color: #2563eb; }
.assistant-widget-rating .btn-submit-rating {
    border: none; padding: 6px 16px; border-radius: 6px; color: #fff; font-size: 12px; cursor: pointer; transition: opacity 0.2s;
}
.assistant-widget-rating .btn-submit-rating:hover { opacity: 0.9; }
.assistant-widget-rating .rating-thanks { font-size: 13px; color: #059669; font-weight: 500; }

.assistant-widget-error { padding: 10px 16px; background: #fef2f2; border-top: 1px solid #fecaca; color: #991b1b; font-size: 12px; display: none; text-align: center; }
.assistant-widget-error.show { display: block; }

@media (max-width: 420px) {
    .assistant-widget-box { width: calc(100vw - 24px); max-height: 70vh; }
}

.assistant-widget-box.position-left {
    left: 8px;
    bottom: 90px;
}
.assistant-widget-box.position-right {
    right: 8px;
    bottom: 90px;
}

.msg-bubble a { color: inherit; text-decoration: underline; }
.assistant-msg.ai .msg-bubble a { color: #2563eb; }

/* ===== BLOB PEEKING FROM EDGE ===== */
.assistant-blob {
    position: fixed !important;
    z-index: 9999 !important;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: none;
}

/* Peek from left edge */
.assistant-blob.position-left {
    left: -8px;
}
/* Peek from right edge */
.assistant-blob.position-right {
    right: -8px;
    left: auto !important;
}

.assistant-blob.dragging {
    cursor: grabbing;
}

.blob-shape {
    position: relative;
    width: 52px;
    height: 52px;
    border-radius: 40% 60% 55% 45% / 50% 45% 55% 50%;
    background: radial-gradient(circle at 35% 25%, #60a5fa 0%, #2563EB 30%, #7c3aed 55%, #10B981 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 8px 32px rgba(37,99,235,0.4),
        inset 0 -6px 12px rgba(0,0,0,0.25),
        inset 0 3px 8px rgba(255,255,255,0.2);
    animation: blobMorph 6s ease-in-out infinite,
               blobFade 4s ease-in-out infinite;
    transform-origin: center;
}

/* Main highlight - glossy sphere reflection */
.blob-shape::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 6px;
    width: 24px;
    height: 16px;
    background: radial-gradient(ellipse, rgba(255,255,255,0.45) 0%, rgba(255,255,255,0.1) 60%, transparent 100%);
    border-radius: 50%;
    transform: rotate(-30deg);
    pointer-events: none;
    z-index: 3;
}

/* Deep shadow at bottom for 3D sphere volume */
.blob-shape::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 5%;
    width: 90%;
    height: 35%;
    background: radial-gradient(ellipse at 50% 100%, rgba(0,0,0,0.3) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

.blob-eyes {
    display: flex;
    gap: 10px;
    position: relative;
    z-index: 4;
}
.blob-eye {
    width: 14px;
    height: 18px;
    background: radial-gradient(circle at 40% 35%, #ffffff, #e2e8f0);
    border-radius: 50%;
    position: relative;
    box-shadow:
        inset 0 1.5px 3px rgba(0,0,0,0.15),
        0 1px 2px rgba(0,0,0,0.1);
    overflow: visible;
}
/* Iris */
.blob-eye .iris {
    position: absolute;
    width: 11px;
    height: 11px;
    background: radial-gradient(circle at 35% 30%, #60a5fa 0%, #1e293b 60%, #0f172a 100%);
    border-radius: 50%;
    top: 3.5px;
    left: 1.5px;
    box-shadow: inset 0 1px 2px rgba(255,255,255,0.1);
}
/* Pupil */
.blob-eye .pupil {
    position: absolute;
    width: 6px;
    height: 6px;
    background: #020617;
    border-radius: 50%;
    top: 2.5px;
    left: 2.5px;
    box-shadow: inset 0 1px 1px rgba(0,0,0,0.3);
}
/* Eye reflection - main */
.blob-eye .reflect {
    position: absolute;
    width: 4px;
    height: 4px;
    background: rgba(255,255,255,0.8);
    border-radius: 50%;
    top: 1.5px;
    right: 1.5px;
    z-index: 5;
    box-shadow: 0 0 2px rgba(255,255,255,0.4);
}
/* Eye reflection - small */
.blob-eye .reflect-sm {
    position: absolute;
    width: 2px;
    height: 2px;
    background: rgba(255,255,255,0.4);
    border-radius: 50%;
    bottom: 4px;
    left: 4px;
    z-index: 5;
}

/* Badge */
.assistant-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    border: 2px solid #fff;
    border-radius: 50%;
    font-size: 10px;
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(239,68,68,0.4);
    z-index: 2;
}
.assistant-badge.show { display: flex; }
.assistant-badge.has-messages {
    animation: badgePulse 1s ease-in-out infinite;
}

/* Open state */
.assistant-blob.open .blob-shape {
    box-shadow: 0 8px 32px rgba(37,99,235,0.5);
}

/* ===== ANIMATIONS ===== */
/* Blob morphing */
@keyframes blobMorph {
    0%, 100% {
        border-radius: 40% 60% 55% 45% / 50% 45% 55% 50%;
    }
    33% {
        border-radius: 55% 45% 48% 52% / 52% 55% 45% 48%;
    }
    66% {
        border-radius: 48% 52% 42% 58% / 54% 46% 54% 46%;
    }
}

/* Fade in/out */
@keyframes blobFade {
    0%, 30% { opacity: 1; }
    55% { opacity: 0.2; }
    75%, 100% { opacity: 1; }
}

/* Badge pulse */
@keyframes badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* Hover */
.assistant-blob:not(.dragging):hover .blob-shape {
    box-shadow:
        0 8px 32px rgba(37,99,235,0.5),
        inset 0 -6px 12px rgba(0,0,0,0.25),
        inset 0 3px 8px rgba(255,255,255,0.2);
}
.assistant-blob:not(.dragging):hover .blob-shape::before {
    width: 26px;
    height: 18px;
    opacity: 0.8;
}

/* Responsive */
@media (max-width: 420px) {
    .blob-shape { width: 42px; height: 42px; }
    .blob-eye { width: 11px; height: 14px; }
    .blob-eye .iris { width: 9px; height: 9px; top: 2.5px; left: 1px; }
    .blob-eye .pupil { width: 5px; height: 5px; top: 2px; left: 2px; }
    .blob-eye .reflect { width: 3px; height: 3px; top: 1px; right: 1px; }
    .blob-eyes { gap: 8px; }
    .assistant-blob.position-left { left: -6px; }
    .assistant-blob.position-right { right: -6px; }
}
