/* ============================================================
   ALTARA WIDGET — shared floating chat UI
   ============================================================ */

/* Floating bubble trigger button */
#altaraBubble {
    position: fixed;
    bottom: calc(56px + 32px + 10px + env(safe-area-inset-bottom, 0px));
    left: 18px;
    z-index: 700;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, #00D4AA 0%, #2BEAD2 50%, #00b89a 100%);
    box-shadow: 0 4px 20px rgba(0, 212, 170, 0.45), 0 2px 8px rgba(0,0,0,0.4);
    display: none;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    font-size: 24px;
    line-height: 1;
}
#altaraBubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 212, 170, 0.6), 0 3px 12px rgba(0,0,0,0.4);
}
#altaraBubble:active { transform: scale(0.96); }
#altaraBubble.open { transform: scale(0.9); opacity: 0.7; }

/* Pulse animation on first load */
@keyframes altaraPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(0, 212, 170, 0.45), 0 2px 8px rgba(0,0,0,0.4); }
    50% { box-shadow: 0 4px 28px rgba(0, 212, 170, 0.7), 0 0 0 8px rgba(0, 212, 170, 0.12); }
}
#altaraBubble.pulse { animation: altaraPulse 2.5s ease-in-out 3; }

/* Unread dot */
#altaraBubble .altara-unread-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #0d0d0d;
    display: none;
}
#altaraBubble.has-unread .altara-unread-dot { display: block; }

/* Backdrop overlay */
#altaraBackdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 698;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
#altaraBackdrop.open { display: block; }

/* Speech bubble chat modal */
#altaraPanel {
    position: fixed;
    z-index: 699;
    bottom: 200px;
    left: 24px;
    width: 380px;
    height: 480px;
    max-height: calc(100vh - 240px);
    background: #0d0d0d;
    border: 1.5px solid rgba(0, 212, 170, 0.3);
    border-radius: 24px;
    box-shadow: 0 16px 64px rgba(0,0,0,0.75), 0 0 0 1px rgba(0,212,170,0.06), 0 0 40px rgba(0,212,170,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: scale(0.92);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}
#altaraPanel.open {
    opacity: 1;
    transform: scale(1);
    pointer-events: all;
}

/* Speech bubble tail */
#altaraPanel::after {
    content: '';
    position: absolute;
    bottom: -12px;
    left: 28px;
    width: 0;
    height: 0;
    border-left: 14px solid transparent;
    border-right: 14px solid transparent;
    border-top: 14px solid #0d0d0d;
    filter: drop-shadow(0 3px 4px rgba(0,0,0,0.4));
}
#altaraPanel::before {
    content: '';
    position: absolute;
    bottom: -14px;
    left: 27px;
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 15px solid rgba(0, 212, 170, 0.3);
    z-index: -1;
}

/* Panel header */
.altara-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px 12px;
    background: linear-gradient(135deg, rgba(0,212,170,0.12) 0%, rgba(0,0,0,0) 100%);
    border-bottom: 1px solid rgba(0, 212, 170, 0.12);
    flex-shrink: 0;
}
.altara-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00D4AA, #2BEAD2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 0 12px rgba(0, 212, 170, 0.4);
}
.altara-header-text { flex: 1; min-width: 0; }
.altara-name {
    font-family: 'Syne', sans-serif;
    font-size: 15px;
    font-weight: 700;
    color: #00D4AA;
    letter-spacing: 0.02em;
}
.altara-tagline {
    font-size: 10px;
    color: rgba(255,255,255,0.4);
    margin-top: 1px;
    letter-spacing: 0.04em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.altara-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.4);
    font-size: 20px;
    cursor: pointer;
    padding: 6px;
    line-height: 1;
    border-radius: 8px;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}
.altara-close:hover { color: rgba(255,255,255,0.8); background: rgba(255,255,255,0.06); }

/* Messages area */
.altara-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    min-width: 0;
    min-height: 0;
}
.altara-messages::-webkit-scrollbar { width: 3px; }
.altara-messages::-webkit-scrollbar-track { background: transparent; }
.altara-messages::-webkit-scrollbar-thumb { background: rgba(0,212,170,0.2); border-radius: 2px; }

/* Chat bubbles */
.altara-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    min-width: 0;
    animation: altaraMsgIn 0.2s ease;
}
.altara-timestamp {
    font-size: 10px;
    color: rgba(255,255,255,0.3);
    margin-bottom: 3px;
    padding: 0 2px;
}
@keyframes altaraMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.altara-msg.user { align-self: flex-end; align-items: flex-end; }
.altara-msg.bot { align-self: flex-start; align-items: flex-start; }

.altara-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
    overflow-wrap: break-word;
    min-width: 0;
    max-width: 100%;
    hyphens: auto;
}
.altara-msg.user .altara-bubble {
    background: #00D4AA;
    color: #000;
    border-radius: 16px 16px 4px 16px;
    font-weight: 500;
}
.altara-msg.bot .altara-bubble {
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.9);
    border-radius: 16px 16px 16px 4px;
    border: 1px solid rgba(255,255,255,0.06);
}

/* Typing indicator */
.altara-typing .altara-bubble {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.06);
    padding: 12px 16px;
}
.altara-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}
.altara-dots span {
    width: 6px; height: 6px;
    background: #00D4AA;
    border-radius: 50%;
    opacity: 0.6;
    animation: altaraDot 1.2s ease-in-out infinite;
}
.altara-dots span:nth-child(2) { animation-delay: 0.2s; }
.altara-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes altaraDot {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
    40% { transform: scale(1.1); opacity: 1; }
}

/* Nudge banner — appears inside the panel */
.altara-nudge {
    margin: 0 16px 4px;
    padding: 10px 14px;
    background: rgba(0, 212, 170, 0.08);
    border: 1px solid rgba(0, 212, 170, 0.25);
    border-radius: 12px;
    font-size: 12.5px;
    color: rgba(255,255,255,0.75);
    line-height: 1.5;
    display: flex;
    gap: 8px;
    align-items: flex-start;
    animation: altaraMsgIn 0.3s ease;
}
.altara-nudge-icon { font-size: 14px; flex-shrink: 0; }
.altara-nudge-text { flex: 1; }
.altara-nudge-dismiss {
    background: none;
    border: none;
    color: rgba(255,255,255,0.3);
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}
.altara-nudge-dismiss:hover { color: rgba(255,255,255,0.6); }

/* Welcome message */
.altara-welcome {
    text-align: center;
    padding: 8px 16px 4px;
    font-size: 11px;
    color: rgba(255,255,255,0.25);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* Input area */
.altara-input-area {
    padding: 12px 16px 16px;
    border-top: 1px solid rgba(0, 212, 170, 0.1);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: rgba(0,0,0,0.3);
    flex-shrink: 0;
}
.altara-input {
    flex: 1;
    min-width: 0;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 22px;
    padding: 10px 16px;
    color: rgba(255,255,255,0.9);
    font-family: 'Outfit', sans-serif;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
    resize: none;
    max-height: 90px;
    overflow-y: auto;
    transition: border-color 0.2s;
    caret-color: #00D4AA;
}
.altara-input::placeholder { color: rgba(255,255,255,0.3); }
.altara-input:focus { border-color: rgba(0, 212, 170, 0.35); }
.altara-send {
    width: 38px;
    height: 38px;
    background: #00D4AA;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.15s;
}
.altara-send:hover { opacity: 0.88; }
.altara-send:active { transform: scale(0.9); }
.altara-send:disabled { opacity: 0.35; cursor: default; }
.altara-send svg { width: 16px; height: 16px; fill: #000; }

/* Voice mic button */
.altara-mic {
    width: 38px;
    height: 38px;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 15px;
    color: rgba(255,255,255,0.3);
    transition: background 0.2s, border-color 0.2s, box-shadow 0.2s, color 0.2s;
}
.altara-mic:hover { background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.7); }
.altara-mic.listening {
    background: rgba(239,68,68,0.12);
    border-color: rgba(239,68,68,0.45);
    color: #ef4444;
    animation: altaraMicPulse 1.1s ease-in-out infinite;
}
@keyframes altaraMicPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.35); }
    50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}
.altara-mic.hidden { display: none !important; }

/* Speaker toggle button in header */
.altara-voice-toggle {
    width: 30px;
    height: 30px;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    color: rgba(255,255,255,0.3);
    flex-shrink: 0;
    transition: color 0.2s, background 0.2s;
}
.altara-voice-toggle:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.7); }
.altara-voice-toggle.active { color: #00D4AA; }

/* Tap-to-listen fallback button */
.altara-tap-listen {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 12px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 16px;
    background: rgba(255,255,255,0.06);
    color: #00D4AA;
    font-size: 13px;
    cursor: pointer;
}

/* Altara limit bar (free-user daily limit) */
.altara-limit-bar {
    padding: 6px 16px 8px;
    background: rgba(0,0,0,0.4);
    border-top: 1px solid rgba(0,212,170,0.08);
    font-size: 11px;
    color: rgba(255,255,255,0.35);
    text-align: center;
    flex-shrink: 0;
}

/* Responsive — mobile full-width at bottom */
@media (max-width: 480px) {
    #altaraPanel {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 85vh;
        border-radius: 24px 24px 0 0;
        transform: translateY(100%);
    }
    #altaraPanel.open {
        transform: translateY(0);
    }
    #altaraPanel::after,
    #altaraPanel::before { display: none; }
    #altaraBubble {
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
}