/**
 * Chatbot Widget - Frontend Styles
 * 
 * Beautiful, modern chatbot interface
 *
 * @package UBMSChatbotEngine
 */

/* ===== Container & Positioning ===== */
.tce-chatbot-container {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

.tce-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.tce-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

.tce-position-top-right {
    top: 20px;
    right: 20px;
}

.tce-position-top-left {
    top: 20px;
    left: 20px;
}

/* ===== Chat Button ===== */
.tce-chat-button {
    width: 60px;
    height: 60px;
    border-radius: 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: visible;
}

.tce-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

/* Ensure button icon/content stays visible during animations */
.tce-button-icon {
    position: relative;
    z-index: 2;
    font-size: 28px;
    line-height: 1;
    pointer-events: none;
}

/* ===== Button Animation Effects ===== */

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    }

    50% {
        box-shadow: 0 4px 25px rgba(102, 126, 234, 0.8);
    }
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@keyframes wiggle {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-10deg);
    }

    75% {
        transform: rotate(10deg);
    }
}

@keyframes burst {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    }

    50% {
        transform: scale(1.15);
        box-shadow: 0 8px 30px rgba(102, 126, 234, 0.8);
    }
}

@keyframes glow {

    0%,
    100% {
        box-shadow: 0 0 15px currentColor, 0 0 25px currentColor;
    }

    50% {
        box-shadow: 0 0 25px currentColor, 0 0 40px currentColor, 0 0 60px currentColor;
    }
}

@keyframes rainbow {
    0% {
        filter: hue-rotate(0deg);
    }

    100% {
        filter: hue-rotate(360deg);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-3px) rotate(-2deg);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(3px) rotate(2deg);
    }
}

/* Apply effects to button */
.tce-chat-button.effect-pulse {
    animation: pulse 2s infinite;
}

.tce-chat-button.effect-bounce {
    animation: bounce 2s infinite;
}

.tce-chat-button.effect-wiggle {
    animation: wiggle 2s infinite;
}

.tce-chat-button.effect-burst {
    animation: burst 2s infinite;
}

.tce-chat-button.effect-glow {
    animation: glow 2s infinite;
}

.tce-chat-button.effect-rainbow {
    animation: rainbow 8s infinite;
}

.tce-chat-button.effect-shake {
    animation: shake 3s infinite;
}

.tce-chat-button.effect-none {
    animation: none;
}

/* Default animation removed - will be added via effect class */

.tce-button-icon {
    font-size: 28px;
    line-height: 1;
    display: block;
}

/* Ensure avatar/icon stays visible in all effects */
.tce-chat-button * {
    position: relative;
    z-index: 1;
}

.tce-button-text {
    display: none;
    /* Hidden on small button */
}

/* ===== Chat Window ===== */
.tce-chat-window {
    width: 420px;
    max-width: calc(100vw - 40px);
    height: 650px;
    max-height: calc(100vh - 80px);

    /* Tinted Glassmorphism */
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(230, 240, 255, 0.9));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.5);

    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== Header ===== */
.tce-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tce-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tce-agent-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    overflow: hidden;
}

.tce-agent-avatar img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 50%;
}

.tce-agent-info {
    flex: 1;
}

.tce-agent-name {
    font-weight: 600;
    font-size: 15px;
}

.tce-agent-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.tce-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 4px;
    background: #00ff88;
    animation: blink 2s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

.tce-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 16px;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s;
}

.tce-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ===== Messages Area ===== */
.tce-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
}

.tce-messages-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ===== Message Bubbles ===== */
.tce-message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tce-message-bot {
    align-self: flex-start;
}

.tce-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.tce-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    overflow: hidden;
}

.tce-message-avatar img {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 50%;
}

.tce-message-user .tce-message-avatar {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.tce-message-content {
    color: #2d3748;
    background: white;
    padding: 12px 16px;
    border-radius: 18px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    line-height: 1.5;
}

.tce-message-user .tce-message-content {
    color: #2d3748;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

/* ===== Progress Bar ===== */
.tce-progress-bar {
    height: 32px;
    background: white;
    border-top: 1px solid #e9ecef;
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 16px;
}

.tce-progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    opacity: 0.1;
    transition: width 0.3s ease;
}

.tce-progress-text {
    position: relative;
    z-index: 1;
    font-size: 12px;
    font-weight: 600;
    color: #667eea;
}

/* ===== Input Area ===== */
.tce-chat-input {
    background: rgba(255, 255, 255, 0.6);
    /* Semi-transparent */
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.5);
    padding: 16px;
}

.tce-input-container {
    /* Dynamically filled */
}

/* Text Input */
.tce-text-input {
    display: flex;
    gap: 8px;
}

.tce-input-field {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e9ecef;
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.tce-input-field:focus {
    border-color: #667eea;
}

.tce-textarea {
    border-radius: 12px;
    resize: none;
    font-family: inherit;
}

.tce-submit-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 24px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}

.tce-submit-btn:hover {
    transform: scale(1.05);
}

/* Multiple Choice */
.tce-multiple-choice {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tce-choice-button {
    padding: 14px 20px;
    background: white;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
}

.tce-choice-button:hover {
    border-color: #667eea;
    background: #f8f9fa;
    transform: translateX(4px);
}

/* Multi-Select Styles */
.tce-multi-select {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tce-multi-select .tce-options-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tce-multi-select .tce-states-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(38px, 1fr));
    gap: 5px;
    max-height: 280px;
    overflow-y: auto;
    padding: 12px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    border: 1px solid #dee2e6;
}

/* Compact button styles ONLY for states grid */
.tce-states-grid .tce-choice-button {
    padding: 8px 4px !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    letter-spacing: -0.5px !important;
    border-radius: 6px !important;
    margin: 0 !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 38px !important;
    height: 36px !important;
    transition: all 0.15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.tce-multi-select .tce-choice-button.selected {
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%) !important;
    color: white !important;
    border-color: #2563eb !important;
    transform: scale(1.04);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.tce-multi-select .tce-choice-button.limit-reached {
    animation: tce-shake 0.4s;
    border-color: #ef4444 !important;
}

@keyframes tce-shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-4px);
    }

    75% {
        transform: translateX(4px);
    }
}

.tce-selection-counter {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.2);
}

.tce-selected-states {
    background: #e3f2fd;
    padding: 8px 10px;
    border-radius: 6px;
    margin: 8px 0;
    font-size: 11px;
    font-weight: 600;
    border-left: 3px solid #667eea;
    max-height: 40px;
    overflow-y: auto;
}

.tce-continue-btn {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 24px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    margin: 10px 0 4px 0;
    width: 100%;
    box-shadow: 0 4px 8px rgba(40, 167, 69, 0.4);
    flex-shrink: 0;
}

.tce-continue-btn:disabled {
    background: linear-gradient(135deg, #adb5bd 0%, #868e96 100%);
    cursor: not-allowed;
    opacity: 0.7;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tce-continue-btn:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(40, 167, 69, 0.5);
    background: linear-gradient(135deg, #218838 0%, #1aa179 100%);
}

.tce-continue-btn.vibrant {
    background: linear-gradient(135deg, #2563eb 0%, #10b981 100%) !important;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
    animation: tce-pulse-green 2s infinite;
}

@keyframes tce-pulse-green {
    0% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(37, 99, 235, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
    }
}

.tce-continue-btn:not(:disabled):active {
    transform: translateY(0);
    box-shadow: 0 3px 6px rgba(40, 167, 69, 0.4);
}

/* Loading */
.tce-loading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    color: #667eea;
}

.tce-loading-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #e9ecef;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.tce-loading-text {
    font-size: 14px;
}

/* Error Message */
.tce-error-message {
    padding: 12px 16px;
    background: #fff3cd;
    border-left: 4px solid #ff9800;
    border-radius: 8px;
    color: #856404;
    font-size: 14px;
    animation: shake 0.5s;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

/* Success Message */
.tce-success-message {
    text-align: center;
    padding: 20px;
}

.tce-success-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.tce-success-message h3 {
    margin: 0 0 12px 0;
    color: #333;
}

.tce-success-message p {
    margin: 0 0 20px 0;
    color: #666;
}

.tce-lead-score {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
    margin: 20px 0;
}

.tce-score-label {
    font-size: 12px;
    color: #666;
    margin-bottom: 8px;
}

.tce-score-badge {
    display: inline-block;
    padding: 8px 20px;
    border-radius: 20px;
    color: white;
    font-weight: bold;
    font-size: 18px;
    margin-bottom: 8px;
}

.tce-score-value {
    font-size: 14px;
    color: #666;
}

.tce-close-final {
    padding: 12px 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 24px;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
}

/* Footer */
.tce-chat-footer {
    padding: 10px 16px;
    text-align: center;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    color: #999;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tce-security-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 10px;
    font-weight: 700;
    color: #2d3748;
    background: #e2e8f0;
    padding: 4px 10px;
    border-radius: 12px;
    margin-top: 5px;
    border: 1px solid #cbd5e0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tce-security-icon {
    font-size: 12px;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .tce-chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 80px);
        bottom: 10px;
        right: 10px;
    }

    .tce-position-bottom-right,
    .tce-position-bottom-left,
    .tce-position-top-right,
    .tce-position-top-left {
        bottom: 10px;
        right: 10px;
        left: auto;
        top: auto;
    }
}

/* ===== Typing Indicator ===== */
.tce-typing-indicator {
    opacity: 0.7;
}

.tce-typing-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.tce-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typing 1.4s infinite;
}

.tce-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.tce-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.7;
    }

    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ===== Scrollbar Styling ===== */
.tce-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.tce-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

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

.tce-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}


/* ===== Dynamic Capacity Styles ===== */
.tce-capacity-loading {
    text-align: center;
    padding: 30px 20px;
    color: #666;
}

.tce-loading-spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 15px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: tce-spin 1s linear infinite;
}

@keyframes tce-spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.tce-capacity-options .tce-choice-button {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 15px;
    text-align: left;
    min-height: 80px;
}

.tce-option-label {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 5px;
    color: #1a1a1a;
}

.tce-option-price {
    font-size: 13px;
    color: #667eea;
    font-weight: 600;
    margin-bottom: 5px;
}

.tce-option-desc {
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}

/* ===== Waitlist Styles ===== */
.tce-waitlist-message {
    padding: 20px;
    text-align: center;
}

.tce-sold-out-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.tce-sold-out-text {
    font-size: 16px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 10px;
}

.tce-sold-out-subtext {
    font-size: 14px;
    color: #666;
    margin-bottom: 20px;
    line-height: 1.5;
}

.tce-waitlist-btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%) !important;
}

.tce-waitlist-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 87, 108, 0.4) !important;
}

.tce-error {
    color: #dc2626;
    padding: 20px;
    text-align: center;
    font-size: 14px;
}

/* ===== Bubble Visual Styles ===== */

/* Standard (Default) is already defined above */

/* Glassmorphism (Deep & Premium) */
.tce-style-glassmorphism .tce-chat-button {
    background: radial-gradient(circle at top left, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.1)) !important;
    backdrop-filter: blur(16px) !important;
    -webkit-backdrop-filter: blur(16px) !important;
    border: 1px solid rgba(255, 255, 255, 0.4) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.1) !important;
    box-shadow:
        0 8px 32px 0 rgba(31, 38, 135, 0.25),
        inset 0 0 0 1px rgba(255, 255, 255, 0.1),
        inset 0 4px 6px rgba(255, 255, 255, 0.2) !important;
}

.tce-style-glassmorphism .tce-chat-button:hover {
    background: radial-gradient(circle at top left, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.2)) !important;
    box-shadow:
        0 12px 40px 0 rgba(31, 38, 135, 0.35),
        inset 0 0 0 1px rgba(255, 255, 255, 0.2),
        inset 0 4px 12px rgba(255, 255, 255, 0.3) !important;
    transform: translateY(-2px);
}

/* Neumorphism */
.tce-style-neumorphism .tce-chat-button {
    background: #e0e5ec !important;
    box-shadow: 9px 9px 16px rgb(163, 177, 198, 0.6),
        -9px -9px 16px rgba(255, 255, 255, 0.5) !important;
    border: none !important;
    color: #4a4a4a !important;
}

.tce-style-neumorphism .tce-chat-button:active {
    box-shadow: inset 6px 6px 10px 0 rgba(163, 177, 198, 0.7),
        inset -6px -6px 10px 0 rgba(255, 255, 255, 0.8) !important;
}

/* Flat */
.tce-style-flat .tce-chat-button {
    box-shadow: none !important;
    border: 2px solid rgba(0, 0, 0, 0.1) !important;
}

.tce-style-flat .tce-chat-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
}

/* Gradient (Enhanced) */
.tce-style-gradient .tce-chat-button {
    background: linear-gradient(45deg, #FF3CAC 0%, #784BA0 50%, #2B86C5 100%) !important;
    box-shadow: 0 4px 15px rgba(120, 75, 160, 0.4) !important;
    background-size: 200% 200%;
    animation: gradientMove 5s ease infinite;
}

@keyframes gradientMove {
    0% {
        background-position: 0% 50%
    }

    50% {
        background-position: 100% 50%
    }

    100% {
        background-position: 0% 50%
    }
}

/* ===== Bubble Sizes ===== */

/* Small */
.tce-size-small .tce-chat-button {
    width: 40px;
    height: 40px;
}

.tce-size-small .tce-button-icon {
    font-size: 20px;
}

/* Medium (Default - 60px) */

/* Large */
.tce-size-large .tce-chat-button {
    width: 70px;
    height: 70px;
}

.tce-size-large .tce-button-icon {
    font-size: 32px;
}

.tce-size-large .tce-agent-avatar img {
    width: 70px;
    height: 70px;
}

/* Extra Large */
.tce-size-xl .tce-chat-button {
    width: 80px;
    height: 80px;
}

.tce-size-xl .tce-button-icon {
    font-size: 36px;
}

.tce-size-xl .tce-agent-avatar img {
    width: 80px;
    height: 80px;
}