@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&family=Syne:wght@600;700&display=swap');

:root {
    --aivs-bg-deep: #0a0b0e;
    --aivs-bg-card: #13151a;
    --aivs-bg-hover: #1c1f27;
    --aivs-border: #252830;
    --aivs-accent: #f0a500;
    --aivs-accent-dim: rgba(240,165,0,.15);
    --aivs-text-hi: #f0f0f0;
    --aivs-text-lo: #888c9e;
    --aivs-success: #2ecc71;
    --aivs-error: #e74c3c;
    --aivs-radius: 16px;
}

.aivs-chat-container {
    font-family: 'DM Sans', -apple-system, sans-serif;
    max-width: 520px;
    margin: 0 auto;
    background: var(--aivs-bg-deep);
    border: 1px solid var(--aivs-border);
    border-radius: var(--aivs-radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 740px;
    box-shadow: 0 12px 48px rgba(0,0,0,.5);
}

/* ── Video Area ── */
.aivs-chat-video-area {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    max-height: 420px;
    background: radial-gradient(ellipse at center, #1a1c22 0%, #0a0b0e 100%);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aivs-chat-video-area video.aivs-chat-video-player,
.aivs-chat-video-area video.aivs-chat-clip-player {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
    z-index: 1;
}

.aivs-chat-video-area video.active {
    display: block;
}

.aivs-chat-idle-video {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    z-index: 0;
}

.aivs-chat-idle-video.hidden { display: none; }



/* Overlay controls */
.aivs-chat-video-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 14px 18px;
    background: linear-gradient(transparent, rgba(0,0,0,.8));
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    z-index: 2;
}

.aivs-chat-agent-tag {
    display: flex;
    align-items: center;
    gap: 8px;
}

.aivs-chat-agent-tag .name {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: 15px;
    color: #fff;
}

.aivs-chat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--aivs-success);
    flex-shrink: 0;
}

.aivs-chat-status-dot.connecting {
    background: var(--aivs-accent);
    animation: aivs-blink 1s infinite;
}

@keyframes aivs-blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: .3; }
}

.aivs-chat-overlay-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Record + Download buttons */
.aivs-chat-rec-btn,
.aivs-chat-dl-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    background: rgba(255,255,255,.1);
    backdrop-filter: blur(6px);
}

.aivs-chat-rec-btn svg,
.aivs-chat-dl-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

.aivs-chat-rec-btn:hover,
.aivs-chat-dl-btn:hover {
    background: rgba(255,255,255,.2);
    transform: scale(1.08);
}

.aivs-chat-rec-btn.recording {
    background: var(--aivs-error);
    animation: aivs-rec-pulse 1s ease infinite;
}

@keyframes aivs-rec-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,.4); }
    50%      { box-shadow: 0 0 0 8px rgba(231,76,60,0); }
}

.aivs-chat-dl-btn.has-video {
    background: var(--aivs-accent);
}
.aivs-chat-dl-btn.has-video svg { fill: #0a0b0e; }

/* Thinking badge */
.aivs-chat-thinking-badge {
    position: absolute;
    top: 14px;
    left: 14px;
    background: rgba(0,0,0,.65);
    backdrop-filter: blur(8px);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    color: var(--aivs-accent);
    display: none;
    align-items: center;
    gap: 6px;
    z-index: 3;
}

.aivs-chat-thinking-badge.visible { display: flex; }

.aivs-chat-thinking-badge .dots {
    display: flex;
    gap: 3px;
}

.aivs-chat-thinking-badge .dots span {
    width: 5px;
    height: 5px;
    background: var(--aivs-accent);
    border-radius: 50%;
    animation: aivs-bounce .6s infinite alternate;
}

.aivs-chat-thinking-badge .dots span:nth-child(2) { animation-delay: .15s; }
.aivs-chat-thinking-badge .dots span:nth-child(3) { animation-delay: .3s; }

@keyframes aivs-bounce {
    from { opacity: .3; transform: translateY(0); }
    to   { opacity: 1;  transform: translateY(-3px); }
}

/* Connection badge */
.aivs-chat-conn-badge {
    position: absolute;
    top: 14px;
    right: 14px;
    background: rgba(0,0,0,.65);
    backdrop-filter: blur(8px);
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 11px;
    color: var(--aivs-text-lo);
    display: flex;
    align-items: center;
    gap: 5px;
    z-index: 3;
}

.aivs-chat-conn-badge .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--aivs-text-lo);
}

.aivs-chat-conn-badge.live .dot { background: var(--aivs-success); }
.aivs-chat-conn-badge.live { color: var(--aivs-success); }
.aivs-chat-conn-badge.connecting .dot { background: var(--aivs-accent); animation: aivs-blink 1s infinite; }
.aivs-chat-conn-badge.connecting { color: var(--aivs-accent); }

/* Transcript */
.aivs-chat-transcript {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,.7);
    backdrop-filter: blur(8px);
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 13px;
    color: #fff;
    max-width: 80%;
    text-align: center;
    display: none;
    pointer-events: none;
    z-index: 5;
}

.aivs-chat-transcript.visible {
    display: block;
    animation: aivs-msg-in .3s ease;
}

/* ── Messages ── */
.aivs-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--aivs-border) transparent;
}

.aivs-chat-messages::-webkit-scrollbar { width: 4px; }
.aivs-chat-messages::-webkit-scrollbar-track { background: transparent; }
.aivs-chat-messages::-webkit-scrollbar-thumb { background: var(--aivs-border); border-radius: 4px; }

.aivs-chat-msg {
    display: flex;
    max-width: 88%;
    animation: aivs-msg-in .25s ease;
}

@keyframes aivs-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.aivs-chat-msg.bot { align-self: flex-start; }
.aivs-chat-msg.user { align-self: flex-end; }

.aivs-chat-bubble {
    padding: 9px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--aivs-text-hi);
    word-break: break-word;
}

.aivs-chat-msg.bot .aivs-chat-bubble {
    background: var(--aivs-bg-card);
    border: 1px solid var(--aivs-border);
    border-top-left-radius: 4px;
}

.aivs-chat-msg.user .aivs-chat-bubble {
    background: linear-gradient(135deg, var(--aivs-accent), #d4900a);
    color: #0a0b0e;
    border-top-right-radius: 4px;
    font-weight: 500;
}

.aivs-chat-bubble p { margin: 0 0 6px; }
.aivs-chat-bubble p:last-child { margin-bottom: 0; }
.aivs-chat-bubble code { background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.aivs-chat-bubble pre { background: rgba(0,0,0,.3); padding: 8px; border-radius: 8px; overflow-x: auto; margin: 6px 0; }
.aivs-chat-bubble strong { color: var(--aivs-accent); }
.aivs-chat-bubble a { color: var(--aivs-accent); text-decoration: underline; }
.aivs-chat-bubble ul, .aivs-chat-bubble ol { margin: 4px 0; padding-left: 16px; }

/* Welcome */
.aivs-chat-welcome-text {
    text-align: center;
    padding: 8px 16px;
    color: var(--aivs-text-lo);
    font-size: 13px;
}

.aivs-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    padding: 0 16px 8px;
}

.aivs-chat-suggestion {
    background: var(--aivs-accent-dim);
    border: 1px solid rgba(240,165,0,.25);
    color: var(--aivs-accent);
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all .2s;
    font-family: 'DM Sans', sans-serif;
}

.aivs-chat-suggestion:hover {
    background: rgba(240,165,0,.25);
    border-color: var(--aivs-accent);
}

/* ── Input Area ── */
.aivs-chat-input-area {
    border-top: 1px solid var(--aivs-border);
    padding: 10px 14px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--aivs-bg-card);
    flex-shrink: 0;
}

.aivs-chat-input {
    flex: 1;
    background: var(--aivs-bg-deep);
    border: 1px solid var(--aivs-border);
    border-radius: 12px;
    padding: 10px 14px;
    color: var(--aivs-text-hi);
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    resize: none;
    min-height: 20px;
    max-height: 80px;
    outline: none;
    transition: border-color .2s;
    line-height: 1.4;
}

.aivs-chat-input:focus { border-color: var(--aivs-accent); }
.aivs-chat-input::placeholder { color: var(--aivs-text-lo); }

.aivs-chat-mic {
    background: none;
    border: 2px solid var(--aivs-border);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    flex-shrink: 0;
}

.aivs-chat-mic svg { width: 20px; height: 20px; fill: var(--aivs-text-lo); transition: fill .2s; }
.aivs-chat-mic:hover { border-color: var(--aivs-accent); }
.aivs-chat-mic:hover svg { fill: var(--aivs-accent); }

.aivs-chat-mic.recording {
    border-color: var(--aivs-error);
    background: rgba(231,76,60,.12);
    animation: aivs-mic-pulse 1.2s ease infinite;
}
.aivs-chat-mic.recording svg { fill: var(--aivs-error); }

@keyframes aivs-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,.3); }
    50%      { box-shadow: 0 0 0 10px rgba(231,76,60,0); }
}

.aivs-chat-send {
    background: linear-gradient(135deg, var(--aivs-accent), #d4900a);
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s, opacity .2s;
    flex-shrink: 0;
}

.aivs-chat-send:hover { transform: scale(1.06); }
.aivs-chat-send:active { transform: scale(.94); }
.aivs-chat-send:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.aivs-chat-send svg { width: 20px; height: 20px; fill: #0a0b0e; }

@media (max-width: 540px) {
    .aivs-chat-container {
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        border: none;
    }
    .aivs-chat-video-area { max-height: 340px; }
    
}

/* Speaking sync visual */
.aivs-chat-video-area.speaking::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 2px solid rgba(99,102,241,0.6);
    border-radius: inherit;
    animation: aivs-speak-glow 0.8s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: 10;
}
@keyframes aivs-speak-glow {
    from { border-color: rgba(99,102,241,0.3); box-shadow: inset 0 0 12px rgba(99,102,241,0.1); }
    to   { border-color: rgba(99,102,241,0.8); box-shadow: inset 0 0 24px rgba(99,102,241,0.25); }
}

/* Audio-reactive bars overlay */
.aivs-chat-audio-bars {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 80px;
    pointer-events: none;
    z-index: 5;
    mix-blend-mode: screen;
}

/* Webcam PiP (bottom-right) */
.aivs-chat-webcam-wrap {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 120px;
    height: 160px;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    border: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    z-index: 6;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity .3s, transform .3s;
}
.aivs-chat-webcam-wrap.active { opacity: 1; transform: translateY(0); }
.aivs-chat-webcam {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* mirror */
    display: block;
}
.aivs-chat-webcam-toggle {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.6);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity .2s;
}
.aivs-chat-webcam-wrap:hover .aivs-chat-webcam-toggle { opacity: 1; }

/* Vision toggle button */
.aivs-chat-vision-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.4);
    color: #888;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
}
.aivs-chat-vision-btn.active {
    background: rgba(99,102,241,0.9);
    color: #fff;
    box-shadow: 0 0 12px rgba(99,102,241,0.5);
}

/* Mobile: smaller webcam */
@media (max-width: 600px) {
    .aivs-chat-webcam-wrap {
        width: 90px;
        height: 120px;
        bottom: 8px;
        right: 8px;
    }
}

/* v3 pro stream video (full body) — opacity fade */
.aivs-chat-stream-video {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.35s ease;
    z-index: 2;
    pointer-events: none;
}
.aivs-chat-stream-video.active { opacity: 1; }
.aivs-chat-idle-video {
    transition: opacity 0.35s ease;
    z-index: 1;
}
.aivs-chat-idle-video.hidden { opacity: 0; }

/* Lokal lip-sync (Wav2Lip) konusma videosu — TTS ses seviyesiyle JS surulur */
.aivs-chat-talk-video {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    z-index: 2;
    pointer-events: none;
    display: none;
}
.aivs-chat-talk-video.ready { display: block; }

/* Record button */
.aivs-chat-rec-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.4);
    color: #ff5555;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    margin-left: 6px;
}
.aivs-chat-rec-btn:hover { background: rgba(255,85,85,0.3); }
.aivs-chat-rec-btn.recording {
    background: #ff3333;
    color: #fff;
    animation: aivs-rec-pulse 1.2s ease-in-out infinite;
}
@keyframes aivs-rec-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,51,51,0.7); }
    50% { box-shadow: 0 0 0 10px rgba(255,51,51,0); }
}
