/* ============================================
   IOSnack AI Chat Widget
   ============================================ */

/* Chat Bubble Button */
.iosnack-chat-bubble {
    position: fixed;
    bottom: 90px;
    right: 24px;
    z-index: 50;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
    transition: all 0.3s ease;
    border: none;
    outline: none;
    animation: chat-pulse 3s ease-in-out infinite;
}

.iosnack-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(139, 92, 246, 0.6);
    animation: none;
}

.iosnack-chat-bubble.active {
    animation: none;
}

@keyframes chat-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4); }
    50% { box-shadow: 0 4px 30px rgba(139, 92, 246, 0.7), 0 0 0 8px rgba(139, 92, 246, 0.1); }
}

.iosnack-chat-bubble svg {
    width: 30px;
    height: 30px;
}

.iosnack-chat-bubble .chat-close-icon {
    display: none;
}

.iosnack-chat-bubble.active .chat-open-icon {
    display: none;
}

.iosnack-chat-bubble.active .chat-close-icon {
    display: block;
}

/* Hover Tooltip */
.iosnack-chat-bubble .chat-tooltip {
    position: absolute;
    right: 70px;
    top: 50%;
    transform: translateY(-50%) translateX(8px);
    background: #1f2937;
    color: white;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 8px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.iosnack-chat-bubble .chat-tooltip::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right: none;
    border-left: 6px solid #1f2937;
}

.iosnack-chat-bubble:hover .chat-tooltip {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.iosnack-chat-bubble.active .chat-tooltip {
    display: none;
}

/* AI online indicator dot */
.iosnack-chat-bubble .ai-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: #22c55e;
    border-radius: 50%;
    border: 2.5px solid #111827;
    animation: dot-pulse 2s ease-in-out infinite;
}

.iosnack-chat-bubble.active .ai-dot {
    display: none;
}

@keyframes dot-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Unread badge */
.iosnack-chat-bubble .unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #22c55e;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: white;
    border: 2px solid #111827;
}

.iosnack-chat-bubble .unread-badge.show {
    display: flex;
}

.iosnack-chat-bubble .unread-badge.show + .ai-dot,
.iosnack-chat-bubble .unread-badge.show ~ .ai-dot {
    display: none;
}

/* Chat Panel */
.iosnack-chat-panel {
    position: fixed;
    bottom: 156px;
    right: 24px;
    z-index: 49;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #111827;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.8) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom right;
}

.iosnack-chat-panel.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* Chat Header */
.iosnack-chat-header {
    background: linear-gradient(135deg, #1f2937, #111827);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.iosnack-chat-header .avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: white;
    flex-shrink: 0;
}

.iosnack-chat-header .header-info {
    flex: 1;
    min-width: 0;
}

.iosnack-chat-header .header-info h4 {
    color: white;
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
}

.iosnack-chat-header .header-info .status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.iosnack-chat-header .header-info .status-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    animation: pulse-dot 2s infinite;
}

.iosnack-chat-header .header-info .status span {
    color: #9ca3af;
    font-size: 12px;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.iosnack-chat-header .close-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.iosnack-chat-header .close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* Chat Messages */
.iosnack-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.iosnack-chat-messages::-webkit-scrollbar {
    width: 4px;
}

.iosnack-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.iosnack-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

/* Message Bubbles */
.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.visitor {
    align-self: flex-end;
}

.chat-message.ai,
.chat-message.admin {
    align-self: flex-start;
}

.chat-message .bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-message.visitor .bubble {
    background: #8b5cf6;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.ai .bubble,
.chat-message.admin .bubble {
    background: #1f2937;
    color: #e5e7eb;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom-left-radius: 4px;
}

.chat-message .timestamp {
    font-size: 10px;
    color: #6b7280;
    margin-top: 4px;
    padding: 0 4px;
}

.chat-message.visitor .timestamp {
    text-align: right;
}

/* System messages */
.chat-message.system {
    align-self: center;
    max-width: 90%;
}

.chat-message.system .bubble {
    background: rgba(255, 255, 255, 0.05);
    color: #9ca3af;
    font-size: 12px;
    text-align: center;
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 8px 12px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #1f2937;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    align-self: flex-start;
}

.typing-indicator .dots {
    display: flex;
    gap: 4px;
}

.typing-indicator .dot {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-indicator .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

.typing-indicator .label {
    font-size: 12px;
    color: #9ca3af;
}

/* Chat Input */
.iosnack-chat-input {
    padding: 12px 16px;
    background: #1f2937;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.iosnack-chat-input textarea {
    flex: 1;
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 10px 14px;
    color: white;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 80px;
    min-height: 40px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.iosnack-chat-input textarea:focus {
    border-color: #8b5cf6;
}

.iosnack-chat-input textarea::placeholder {
    color: #6b7280;
}

.iosnack-chat-input .send-btn {
    width: 40px;
    height: 40px;
    background: #8b5cf6;
    border: none;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.iosnack-chat-input .send-btn:hover {
    background: #7c3aed;
}

.iosnack-chat-input .send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.iosnack-chat-input .send-btn svg {
    width: 18px;
    height: 18px;
    fill: white;
}

/* Powered By */
.iosnack-chat-footer {
    padding: 6px 16px;
    text-align: center;
    background: #111827;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.iosnack-chat-footer span {
    font-size: 10px;
    color: #4b5563;
}

/* Handoff Banner */
.handoff-banner {
    padding: 10px 16px;
    background: rgba(234, 179, 8, 0.1);
    border-top: 1px solid rgba(234, 179, 8, 0.2);
    text-align: center;
    font-size: 12px;
    color: #fbbf24;
    flex-shrink: 0;
    display: none;
}

.handoff-banner.show {
    display: block;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .iosnack-chat-panel {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .iosnack-chat-bubble {
        bottom: 80px;
        right: 16px;
    }
}
