/* TapeDynamics Avatar Chatbot Widget Styles */
/* Layout: Big avatar + hidden chat (expandable) */

:root {
    --td-cyan: #36D7D9;
    --td-dark-navy: #252B42;
    --td-background: #2c3350;
    --td-gray: #8A94A7;
}

/* ===== Floating Button ===== */
#td-chatbot-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #25D366, #22C55E);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(37, 211, 102, 0.5);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 28px;
    animation: td-pulse 2s infinite;
}

#td-chatbot-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(37, 211, 102, 0.7);
}

#td-chatbot-button.active {
    background: #ff4444;
    animation: none;
}

@keyframes td-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(37, 211, 102, 0.5); }
    50% { box-shadow: 0 4px 30px rgba(37, 211, 102, 0.8); }
}

/* ===== Chat Container ===== */
#td-chatbot-container {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 110px);
    background: var(--td-dark-navy);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    z-index: 99998;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#td-chatbot-container.active {
    display: flex;
    animation: td-slideUp 0.3s ease;
}

@keyframes td-slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Header (compact) ===== */
.td-chatbot-header {
    background: linear-gradient(135deg, var(--td-cyan), #66D9B8);
    padding: 10px 16px;
    color: white;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.td-chatbot-header-text {
    flex: 1;
}

.td-chatbot-header-text h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.td-chatbot-header-text p {
    margin: 1px 0 0 0;
    font-size: 10px;
    opacity: 0.9;
}

.td-header-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
    flex-shrink: 0;
}

/* ===== Avatar 3D Canvas Area (BIG - fills available space) ===== */
.td-avatar-area {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 200px;
    background: radial-gradient(ellipse at center, #0a1628 0%, #050d1a 100%);
    overflow: hidden;
}

/* Scanline overlay for futuristic feel */
.td-avatar-area::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(54, 215, 217, 0.03) 2px,
        rgba(54, 215, 217, 0.03) 4px
    );
    pointer-events: none;
    z-index: 1;
}

/* When chat is expanded, avatar shrinks */
#td-chatbot-container.td-chat-expanded .td-avatar-area {
    flex: 0 0 200px;
    min-height: 160px;
}

#td-avatar-canvas {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.td-avatar-area canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* Loading spinner overlay */
.td-avatar-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: linear-gradient(180deg, #1a1f35 0%, var(--td-background) 100%);
    z-index: 2;
    transition: opacity 0.5s ease;
}

.td-avatar-loading.hidden {
    opacity: 0;
    pointer-events: none;
}

.td-avatar-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(54, 215, 217, 0.2);
    border-top-color: var(--td-cyan);
    border-radius: 50%;
    animation: td-spin 0.8s linear infinite;
}

@keyframes td-spin {
    to { transform: rotate(360deg); }
}

.td-avatar-loading span {
    color: var(--td-gray);
    font-size: 12px;
}

/* Speaking indicator */
.td-speaking-indicator {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 3px;
    padding: 4px 12px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 3;
}

.td-speaking-indicator.active {
    opacity: 1;
}

.td-speaking-indicator span {
    width: 4px;
    height: 16px;
    background: var(--td-cyan);
    border-radius: 2px;
    animation: td-soundbar 0.6s ease-in-out infinite;
}

.td-speaking-indicator span:nth-child(2) { animation-delay: 0.1s; }
.td-speaking-indicator span:nth-child(3) { animation-delay: 0.2s; }
.td-speaking-indicator span:nth-child(4) { animation-delay: 0.3s; }
.td-speaking-indicator span:nth-child(5) { animation-delay: 0.15s; }

@keyframes td-soundbar {
    0%, 100% { height: 4px; }
    50% { height: 16px; }
}

/* Mute button */
.td-mute-button {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    border: none;
    color: white;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
    transition: background 0.2s ease;
}

.td-mute-button:hover {
    background: rgba(0, 0, 0, 0.6);
}

.td-mute-button.muted {
    color: #ff6b6b;
}

/* ===== Chat Toggle Button ===== */
.td-chat-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 0;
    background: var(--td-background);
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--td-gray);
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.2s ease, background 0.2s ease;
    width: 100%;
}

.td-chat-toggle:hover {
    color: var(--td-cyan);
    background: rgba(54, 215, 217, 0.05);
}

.td-chat-toggle-icon {
    font-size: 10px;
    transition: transform 0.3s ease;
}

#td-chatbot-container.td-chat-expanded .td-chat-toggle-icon {
    transform: rotate(180deg);
}

/* ===== Messages Area (HIDDEN by default) ===== */
.td-chatbot-messages {
    overflow-y: auto;
    padding: 12px;
    background: var(--td-background);
    min-height: 0;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    padding-top: 0;
    padding-bottom: 0;
}

/* Chat expanded: show messages */
#td-chatbot-container.td-chat-expanded .td-chatbot-messages {
    flex: 1;
    max-height: 500px;
    opacity: 1;
    padding: 12px;
}

.td-chatbot-message {
    margin-bottom: 10px;
    display: flex;
    gap: 6px;
    animation: td-msgSlideIn 0.3s ease;
}

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

.td-chatbot-message.user {
    flex-direction: row-reverse;
}

.td-message-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--td-cyan);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 12px;
}

.td-chatbot-message.user .td-message-avatar {
    background: var(--td-gray);
}

.td-message-content {
    max-width: 82%;
}

.td-message-bubble {
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 12px;
    line-height: 1.5;
    word-wrap: break-word;
}

.td-chatbot-message.user .td-message-bubble {
    background: var(--td-cyan);
    color: var(--td-dark-navy);
}

.td-message-time {
    font-size: 9px;
    color: var(--td-gray);
    margin-top: 2px;
}

/* ===== Typing Indicator ===== */
.td-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    width: fit-content;
}

.td-typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--td-cyan);
    animation: td-typing 1.4s infinite;
}

.td-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.td-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

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

/* ===== Input Area (always visible) ===== */
.td-chatbot-input-area {
    padding: 10px 14px;
    background: var(--td-dark-navy);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.td-chatbot-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.td-chatbot-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--td-background);
    border: 1px solid rgba(54, 215, 217, 0.3);
    border-radius: 20px;
    color: white;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
    font-family: inherit;
}

.td-chatbot-input:focus {
    border-color: var(--td-cyan);
    box-shadow: 0 0 0 2px rgba(54, 215, 217, 0.1);
}

.td-chatbot-input::placeholder {
    color: var(--td-gray);
}

.td-send-button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--td-cyan);
    border: none;
    color: var(--td-dark-navy);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.td-send-button:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(54, 215, 217, 0.4);
}

.td-send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== Welcome Message ===== */
.td-welcome-message {
    background: rgba(54, 215, 217, 0.1);
    border: 1px solid rgba(54, 215, 217, 0.3);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    color: white;
}

.td-welcome-message h4 {
    color: var(--td-cyan);
    margin: 0 0 4px 0;
    font-size: 13px;
}

.td-welcome-message p {
    margin: 0;
    font-size: 11px;
    line-height: 1.4;
    opacity: 0.9;
}

/* ===== Lead Form ===== */
.td-lead-form {
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin: 10px 0;
}

.td-lead-form h4 {
    color: var(--td-cyan);
    margin: 0 0 8px 0;
    font-size: 12px;
    font-weight: 600;
}

.td-lead-form input,
.td-lead-form textarea {
    width: 100%;
    padding: 8px 10px;
    background: var(--td-dark-navy);
    border: 1px solid rgba(54, 215, 217, 0.3);
    border-radius: 6px;
    color: white;
    font-size: 13px;
    margin-bottom: 6px;
    font-family: inherit;
    box-sizing: border-box;
}

.td-lead-form input:focus,
.td-lead-form textarea:focus {
    outline: none;
    border-color: var(--td-cyan);
}

.td-lead-form textarea {
    resize: vertical;
    min-height: 44px;
}

.td-lead-submit {
    width: 100%;
    padding: 10px;
    background: var(--td-cyan);
    color: var(--td-dark-navy);
    border: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.td-lead-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(54, 215, 217, 0.4);
}

/* ===== Scrollbar ===== */
.td-chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

.td-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.td-chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(54, 215, 217, 0.3);
    border-radius: 2px;
}

/* ===== Text-only fallback (no avatar) ===== */
#td-chatbot-container.td-text-only .td-avatar-area {
    display: none;
}

#td-chatbot-container.td-text-only .td-chatbot-messages {
    flex: 1;
    max-height: none;
    opacity: 1;
    padding: 12px;
}

#td-chatbot-container.td-text-only .td-chat-toggle {
    display: none;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    #td-chatbot-container {
        width: calc(100vw - 24px);
        height: calc(100vh - 100px);
        max-height: none;
        bottom: 80px;
        right: 12px;
        left: 12px;
        border-radius: 14px;
    }

    #td-chatbot-container.td-chat-expanded .td-avatar-area {
        flex: 0 0 170px;
        min-height: 140px;
    }

    #td-chatbot-button {
        width: 54px;
        height: 54px;
        bottom: 16px;
        right: 16px;
        font-size: 24px;
    }

    .td-chatbot-input {
        font-size: 16px;
    }
}

@media (max-width: 380px) {
    #td-chatbot-container.td-chat-expanded .td-avatar-area {
        flex: 0 0 140px;
        min-height: 120px;
    }
}
