/*
 * ═══════════════════════════════════════════════════════════════
 *  AIKO VISUAL CHATBOT v2 — chat.css
 *  Layout: Avatar (bottom-right) + Chatbox (above, 50px from bottom)
 *          + Reply bubble (slides up from behind chatbox)
 * ═══════════════════════════════════════════════════════════════
 */

/* ── CSS Custom Properties ────────────────────────────────────────────────── */
:root {
    --aiko-scale:        1.0;          /* Default size */
    --aiko-max-w:        420px;
    --aiko-max-h:        600px;
    --aiko-avatar-w:     calc(var(--aiko-max-w) * var(--aiko-scale));
    --aiko-avatar-h:     calc(var(--aiko-max-h) * var(--aiko-scale));
    --aiko-chat-right:   10px;
    --aiko-chat-bottom:  50px;
    --aiko-chat-w:       400px;        /* Increased width */
    --aiko-blue:         #1A6BFF;
    --aiko-blue-dark:    #0044CC;
    --aiko-dark-bg:      rgba(8, 16, 36, 0.72);
    --aiko-glass-border: rgba(255, 255, 255, 0.1);
}

/* ═══════════════════════════════════════════════════════════════
   AVATAR FRAME
═══════════════════════════════════════════════════════════════ */
#aiko-avatar {
    position: fixed;
    bottom: 0;
    right: 0;
    width: var(--aiko-avatar-w);
    height: var(--aiko-avatar-h);
    max-width: var(--aiko-max-w);
    max-height: var(--aiko-max-h);
    z-index: 9990;
    pointer-events: none;
    overflow: hidden;
    transition: width 0.45s cubic-bezier(0.16, 1, 0.3, 1),
                height 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.aiko-vid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center bottom;
    /* will-change forces both players onto a dedicated GPU compositor layer
       so the browser keeps decoding frames even at opacity:0 — this is what
       makes requestVideoFrameCallback fire on time for the standby video. */
    will-change: opacity;
}

/* ═══════════════════════════════════════════════════════════════
   REPLY BUBBLE
   - z-index BELOW chatbox (9993 vs 9995) so it visually slides
     up from "behind" the chatbox
   - Initially pushed DOWN via translateY(130%) so it overlaps chatbox
   - Animates to translateY(0) = above chatbox
═══════════════════════════════════════════════════════════════ */
#aiko-reply-bubble {
    position: fixed;
    right: var(--aiko-chat-right);
    bottom: 165px;          /* dynamically overridden by JS via adjustBubblePosition() */
    width: var(--aiko-chat-w);
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(26, 107, 255, 0.14);
    border-radius: 28px;
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.13),
        0 2px 8px rgba(26, 107, 255, 0.08);
    z-index: 9993;
    transform: translateY(130%);
    opacity: 0;
    transition: transform 0.52s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.4s ease;
    pointer-events: none;
    box-sizing: border-box;
}

#aiko-reply-bubble.is-visible {
    transform: translateY(0);
    opacity: 1;
}

.aiko-bubble-inner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px 14px 14px;
    box-sizing: border-box;
    width: 100%;
}

.aiko-bubble-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid rgba(26, 107, 255, 0.25);
    box-shadow: 0 2px 8px rgba(26, 107, 255, 0.2);
}

#aiko-reply-content {
    flex: 1;
    min-width: 0;            /* critical: stops flex child from overflowing */
    font-size: 13.5px;
    line-height: 1.62;
    color: #1a2236;
    font-family: 'Inter', 'Plus Jakarta Sans', sans-serif;
    min-height: 24px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

/* ── Loading dots ── */
.aiko-loading-dots {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 4px 0;
}

.aiko-loading-dot {
    width: 7px;
    height: 7px;
    background: var(--aiko-blue);
    border-radius: 50%;
    animation: aiko-dot-pulse 1.4s infinite ease-in-out both;
}
.aiko-loading-dot:nth-child(1) { animation-delay: -0.32s; }
.aiko-loading-dot:nth-child(2) { animation-delay: -0.16s; }
.aiko-loading-dot:nth-child(3) { animation-delay:      0s; }

@keyframes aiko-dot-pulse {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40%            { transform: scale(1); opacity: 1;   }
}

.aiko-bubble-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--aiko-blue);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    display: block;
    margin-bottom: 6px;
    opacity: 0.75;
}

/* ── Word-by-word text reveal ── */
@keyframes aiko-word-in {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0);   }
}

.aiko-word {
    display: inline-block;
    opacity: 0;
    animation: aiko-word-in 0.22s ease forwards;
}

/* ═══════════════════════════════════════════════════════════════
   CHATBOX
═══════════════════════════════════════════════════════════════ */
#aiko-chat {
    position: fixed;
    bottom: var(--aiko-chat-bottom);
    right: var(--aiko-chat-right);
    width: var(--aiko-chat-w);
    background: var(--aiko-dark-bg);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    border: 1px solid var(--aiko-glass-border);
    border-radius: 28px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(26, 107, 255, 0.12) inset;
    z-index: 9995;
    overflow: hidden;
}

/* ── Quick shortcuts ── */
#aiko-shortcuts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 14px;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: all 0.3s ease;
}

#aiko-chat:hover #aiko-shortcuts {
    max-height: 80px;
    padding: 12px 14px 10px;
    opacity: 1;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.aiko-quick-btn {
    background: rgba(26, 107, 255, 0.14);
    border: 1px solid rgba(26, 107, 255, 0.28);
    border-radius: 20px;
    padding: 3px 8px;
    font-size: 9.5px;
    color: rgba(255, 255, 255, 0.78);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
}

.aiko-quick-btn:hover {
    background: rgba(26, 107, 255, 0.45);
    color: #ffffff;
    border-color: rgba(26, 107, 255, 0.6);
    transform: translateY(-1px);
}

/* ── Input row ── */
#aiko-input-row {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 12px 10px;
}

#aiko-chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.11);
    color: #ffffff;
    padding: 6px 13px;
    border-radius: 20px;
    font-size: 13px;
    outline: none;
    transition: all 0.2s ease;
    min-width: 0;
    font-family: 'Inter', sans-serif;
}

#aiko-chat-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

#aiko-chat-input:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(26, 107, 255, 0.48);
    box-shadow: 0 0 0 3px rgba(26, 107, 255, 0.1);
}

/* Icon buttons (mic, settings, log, size) */
.aiko-icon-btn {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11.5px;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.aiko-icon-btn:hover {
    background: rgba(26, 107, 255, 0.28);
    color: #ffffff;
    border-color: rgba(26, 107, 255, 0.45);
}

.aiko-icon-btn.aiko-active {
    background: rgba(26, 107, 255, 0.45);
    color: #ffffff;
    border-color: rgba(26, 107, 255, 0.7);
}

/* Mic listening state */
#aiko-mic-btn.aiko-listening {
    background: rgba(239, 68, 68, 0.4);
    color: #ffffff;
    border-color: rgba(239, 68, 68, 0.65);
    animation: aiko-mic-pulse 1.1s ease-in-out infinite;
}

@keyframes aiko-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
    50%       { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0);  }
}

/* Send button */
.aiko-send-btn {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--aiko-blue), var(--aiko-blue-dark));
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    box-shadow: 0 3px 12px rgba(26, 107, 255, 0.5);
    transition: all 0.22s ease;
    position: relative;
    overflow: hidden;
}

.aiko-send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 20px rgba(26, 107, 255, 0.7);
}

.aiko-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.aiko-send-btn i { margin-left: -1px; }

/* ═══════════════════════════════════════════════════════════════
   FLOATING PANELS (Settings & Log)
   Both slide up from their bottom position
═══════════════════════════════════════════════════════════════ */
#aiko-settings-panel,
#aiko-log-panel {
    position: fixed;
    right: var(--aiko-chat-right);
    bottom: 165px;          /* dynamically overridden by JS */
    width: calc(var(--aiko-chat-w) * 0.80);
    background: rgba(6, 12, 30, 0.65);
    backdrop-filter: blur(32px);
    -webkit-backdrop-filter: blur(32px);
    border: 1px solid var(--aiko-glass-border);
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    z-index: 9997;
    transform: translateY(16px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.3s ease;
    overflow: hidden;
}

#aiko-settings-panel.is-open,
#aiko-log-panel.is-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: all;
}

.aiko-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    letter-spacing: 0.02em;
}

.aiko-panel-header i {
    color: var(--aiko-blue);
    margin-right: 6px;
}

.aiko-panel-header button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    font-size: 14px;
    transition: color 0.2s;
    padding: 2px;
}

.aiko-panel-header button:hover {
    color: rgba(255, 255, 255, 0.9);
}

.aiko-panel-body {
    padding: 10px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.aiko-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.aiko-field > span:first-child {
    font-size: 9.5px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.45);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* Paid services notice */
.aiko-paid-notice {
    font-size: 9px;
    color: rgba(80, 160, 255, 0.9);
    line-height: 1.5;
    margin: 0;
    padding: 0 2px;
}

/* Blue separator line between sections */
.aiko-panel-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(26, 107, 255, 0.5), transparent);
    margin: 2px 0;
}

.aiko-field select {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.13);
    color: rgba(255, 255, 255, 0.9);
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 12.5px;
    outline: none;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    transition: border-color 0.2s;
}

.aiko-field select:focus {
    border-color: rgba(26, 107, 255, 0.5);
}

.aiko-field select option {
    background: #060c1e;
    color: #ffffff;
}

/* Row field (label + toggle) */
.aiko-field-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.aiko-field-row > span:first-child {
    font-size: 12.5px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
    text-transform: none;
    letter-spacing: normal;
}

/* Toggle switch */
.aiko-switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 22px;
    cursor: pointer;
}

.aiko-switch input { display: none; }

.aiko-switch-track {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 22px;
    transition: background 0.3s;
}

.aiko-switch-track::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: #ffffff;
    border-radius: 50%;
    left: 3px;
    top: 3px;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.aiko-switch input:checked + .aiko-switch-track {
    background: var(--aiko-blue);
}

.aiko-switch input:checked + .aiko-switch-track::before {
    transform: translateX(16px);
}

/* ── Log panel ── */
#aiko-log-panel {
    display: flex;
    flex-direction: column;
    max-height: 420px;
}

#aiko-log-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 300px;
    scroll-behavior: smooth;
}

#aiko-log-messages::-webkit-scrollbar {
    width: 3px;
}
#aiko-log-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.aiko-log-empty {
    text-align: center;
    color: rgba(255, 255, 255, 0.3);
    font-size: 12px;
    padding: 20px 0;
    font-style: italic;
}

.aiko-log-entry {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    animation: aiko-word-in 0.2s ease forwards;
}

.aiko-log-entry.user { flex-direction: row-reverse; }

.aiko-log-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--aiko-blue), var(--aiko-blue-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    flex-shrink: 0;
}

.aiko-log-icon img {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    object-fit: cover;
}

.aiko-log-bubble {
    max-width: 82%;
    background: rgba(255, 255, 255, 0.07);
    border-radius: 12px;
    padding: 6px 10px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.78);
    line-height: 1.5;
    word-wrap: break-word;
}

.aiko-log-entry.user .aiko-log-bubble {
    background: rgba(26, 107, 255, 0.28);
    color: rgba(255,255,255,0.9);
}

#aiko-log-clear {
    margin: 8px 14px 12px;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.28);
    color: rgba(239, 68, 68, 0.85);
    border-radius: 10px;
    padding: 8px;
    cursor: pointer;
    font-size: 12px;
    font-family: 'Inter', sans-serif;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

#aiko-log-clear:hover {
    background: rgba(239, 68, 68, 0.28);
    color: #ffffff;
    border-color: rgba(239, 68, 68, 0.5);
}

/* ═══════════════════════════════════════════════════════════════
   LIGHT-SWEEP EFFECT (universal, inherits from main theme)
═══════════════════════════════════════════════════════════════ */
.light-sweep {
    position: relative;
    overflow: hidden;
}

.light-sweep::after {
    content: '';
    position: absolute;
    top: 0;
    left: -110%;
    width: 60%;
    height: 100%;
    background: linear-gradient(
        105deg,
        transparent 20%,
        rgba(255, 255, 255, 0.22) 50%,
        transparent 80%
    );
    transform: skewX(-15deg);
    transition: left 0s;
    pointer-events: none;
}

.light-sweep:hover::after {
    left: 140%;
    transition: left 0.55s ease;
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Hide avatar on mobile — too much screen space */
    #aiko-avatar {
        display: none !important;
    }

    /* Full-width chatbox */
    #aiko-chat {
        width: auto;
        left: 10px;
        right: 10px;
        bottom: 12px;
        border-radius: 18px;
    }

    /* Full-width reply bubble */
    #aiko-reply-bubble {
        width: auto;
        left: 10px;
        right: 10px;
    }

    /* Full-width panels */
    #aiko-settings-panel,
    #aiko-log-panel {
        width: auto;
        left: 10px;
        right: 10px;
    }
}
