/* ═══════════════════════════════════════════════════
   Teddy AI Chat Widget — Global Floating Assistant
   Include on all pages for universal AI chat support
   ═══════════════════════════════════════════════════ */

/* Floating button */
.teddy-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 2px solid rgba(0, 212, 255, 0.4);
    background: linear-gradient(135deg, #0A2540, #1a3a5c);
    cursor: pointer;
    z-index: 9998;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), 0 0 15px rgba(0, 212, 255, 0.2);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    animation: teddyFloat 3s ease-in-out infinite;
}

.teddy-fab img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    pointer-events: none;
}

.teddy-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.4), 0 0 25px rgba(0, 212, 255, 0.4);
    border-color: rgba(0, 212, 255, 0.7);
}

.teddy-fab.open {
    animation: none;
    transform: scale(0.9) rotate(15deg);
    opacity: 0.7;
}

@keyframes teddyFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* Notification pulse */
.teddy-fab::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    background: #e67e22;
    border-radius: 50%;
    border: 2px solid #0A2540;
    animation: teddyPulse 2s ease-in-out infinite;
}

.teddy-fab.open::after { display: none; }

@keyframes teddyPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
}

/* Chat window */
.teddy-chat {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 500px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.teddy-chat.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Chat header */
.teddy-chat-header {
    background: linear-gradient(135deg, #0A2540, #1a4a6c);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.teddy-chat-header img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid rgba(0, 212, 255, 0.4);
}

.teddy-chat-header .info {
    flex: 1;
}

.teddy-chat-header .info h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    font-family: 'Orbitron', monospace;
    letter-spacing: 0.5px;
}

.teddy-chat-header .info p {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.7);
    margin: 2px 0 0;
}

.teddy-chat-close {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.teddy-chat-close:hover {
    background: rgba(255,255,255,0.2);
}

/* Messages area */
.teddy-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #fafafa;
    scroll-behavior: smooth;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.teddy-chat-messages::-webkit-scrollbar { width: 5px; }
.teddy-chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

.teddy-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.55;
    animation: teddyMsgIn 0.3s ease-out;
    word-wrap: break-word;
}

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

.teddy-msg.ai {
    background: #fff;
    border: 1px solid #e0e0e0;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    color: #333;
}

.teddy-msg.user {
    background: linear-gradient(135deg, #0A2540, #1a4a6c);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.teddy-msg.typing {
    background: #f0f0f0;
    border: 1px solid #e0e0e0;
    align-self: flex-start;
    padding: 10px 16px;
}

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

.teddy-typing-dots span {
    width: 7px;
    height: 7px;
    background: #0A2540;
    border-radius: 50%;
    animation: teddyTyping 1.2s ease-in-out infinite;
}
.teddy-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.teddy-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

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

/* Input area */
.teddy-chat-input {
    display: flex;
    padding: 10px 12px;
    border-top: 1px solid #e0e0e0;
    gap: 8px;
    background: #fff;
    flex-shrink: 0;
    min-height: 0;
}

.teddy-chat-input input {
    flex: 1;
    padding: 10px 14px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 10px;
    color: #333;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    /* Prevent iOS zoom on focus */
    -webkit-text-size-adjust: 100%;
}

.teddy-chat-input input:focus {
    border-color: #0A2540;
    background: #fff;
}

.teddy-chat-input button {
    padding: 10px 16px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #e67e22, #d35400);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    white-space: nowrap;
}

.teddy-chat-input button:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 10px rgba(230, 126, 34, 0.4);
}

.teddy-chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Powered by footer */
.teddy-chat-footer {
    display: none;
}

/* Body scroll lock when chat is open on mobile */
body.teddy-chat-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

/* ─── Mobile: LifeOS-style viewport-fitted layout ─── */
@media (max-width: 480px) {
    .teddy-chat {
        bottom: 0;
        right: 0;
        top: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        height: 100vh; /* fallback */
        max-height: none;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .teddy-chat-messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .teddy-chat-input {
        padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    }

    .teddy-chat-footer {
        padding-bottom: max(6px, env(safe-area-inset-bottom, 6px));
    }

    .teddy-fab {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .teddy-fab img {
        width: 40px;
        height: 40px;
    }
}

/* Tablet */
@media (min-width: 481px) and (max-width: 768px) {
    .teddy-chat {
        width: calc(100vw - 32px);
        max-height: calc(100vh - 120px);
        bottom: 100px;
        right: 16px;
    }
}
