/**
 * BTNG AI Chat Widget Styles
 */

/* CSS Variables for theming */
:root {
    --btng-primary: #2563eb;
    --btng-primary-hover: #1d4ed8;
    --btng-primary-light: #eff6ff;
    --btng-text: #1f2937;
    --btng-text-light: #6b7280;
    --btng-border: #e5e7eb;
    --btng-bg: #ffffff;
    --btng-bg-secondary: #f9fafb;
    --btng-success: #10b981;
    --btng-error: #ef4444;
    --btng-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --btng-radius: 12px;
}

/* Dark theme */
.btng-chat-widget[data-theme="dark"],
.btng-chat-bubble[data-theme="dark"] {
    --btng-primary: #3b82f6;
    --btng-primary-hover: #60a5fa;
    --btng-primary-light: #1e3a5f;
    --btng-text: #f9fafb;
    --btng-text-light: #9ca3af;
    --btng-border: #374151;
    --btng-bg: #1f2937;
    --btng-bg-secondary: #111827;
}

/* ===============================================
   FLOATING BUBBLE
   =============================================== */
.btng-chat-bubble {
    position: fixed;
    z-index: 99999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--btng-primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--btng-shadow);
    transition: transform 0.2s, background-color 0.2s;
}

.btng-chat-bubble:hover {
    transform: scale(1.05);
    background: var(--btng-primary-hover);
}

.btng-chat-bubble-bottom-right {
    bottom: 20px;
    right: 20px;
}

.btng-chat-bubble-bottom-left {
    bottom: 20px;
    left: 20px;
}

.btng-chat-bubble-icon,
.btng-chat-bubble-close {
    display: flex;
    align-items: center;
    justify-content: center;
}

.btng-chat-bubble-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--btng-error);
    color: white;
    font-size: 12px;
    font-weight: 600;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===============================================
   CHAT WIDGET CONTAINER
   =============================================== */
.btng-chat-widget {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--btng-text);
    background: var(--btng-bg);
    border-radius: var(--btng-radius);
    box-shadow: var(--btng-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Floating mode */
.btng-chat-floating {
    position: fixed;
    z-index: 99998;
    width: 380px;
    height: 550px;
    max-height: calc(100vh - 100px);
}

.btng-chat-floating-bottom-right {
    bottom: 90px;
    right: 20px;
}

.btng-chat-floating-bottom-left {
    bottom: 90px;
    left: 20px;
}

/* Embedded mode */
.btng-chat-embedded {
    width: 100%;
    height: 600px;
    max-width: 500px;
    margin: 0 auto;
    border: 1px solid var(--btng-border);
}

/* ===============================================
   HEADER
   =============================================== */
.btng-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--btng-primary);
    color: white;
    flex-shrink: 0;
}

.btng-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btng-chat-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btng-chat-title {
    font-weight: 600;
    font-size: 16px;
}

.btng-chat-subtitle {
    font-size: 12px;
    opacity: 0.9;
}

.btng-chat-close {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.btng-chat-close:hover {
    background: rgba(255,255,255,0.2);
}

/* ===============================================
   MESSAGES AREA
   =============================================== */
.btng-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--btng-bg-secondary);
}

.btng-chat-messages-inner {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btng-chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
}

.btng-chat-message-user {
    align-self: flex-end;
    background: var(--btng-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.btng-chat-message-assistant {
    align-self: flex-start;
    background: var(--btng-bg);
    color: var(--btng-text);
    border: 1px solid var(--btng-border);
    border-bottom-left-radius: 4px;
}

.btng-chat-message-time {
    font-size: 11px;
    color: var(--btng-text-light);
    margin-top: 4px;
    text-align: right;
}

.btng-chat-message-user .btng-chat-message-time {
    color: rgba(255,255,255,0.7);
}

/* Typing indicator */
.btng-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.btng-typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--btng-text-light);
    border-radius: 50%;
    animation: btng-typing 1.4s infinite ease-in-out both;
}

.btng-typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.btng-typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
.btng-typing-indicator span:nth-child(3) { animation-delay: 0s; }

@keyframes btng-typing {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.6; }
    40% { transform: scale(1); opacity: 1; }
}

/* ===============================================
   SUGGESTIONS
   =============================================== */
.btng-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    background: var(--btng-bg);
    border-top: 1px solid var(--btng-border);
}

.btng-chat-suggestion {
    padding: 8px 16px;
    background: var(--btng-primary-light);
    color: var(--btng-primary);
    border: 1px solid var(--btng-primary);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.btng-chat-suggestion:hover {
    background: var(--btng-primary);
    color: white;
}

/* ===============================================
   INPUT AREA
   =============================================== */
.btng-chat-input-area {
    padding: 12px 16px;
    background: var(--btng-bg);
    border-top: 1px solid var(--btng-border);
    flex-shrink: 0;
}

.btng-chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--btng-bg-secondary);
    border: 1px solid var(--btng-border);
    border-radius: 24px;
    padding: 8px 16px;
    transition: border-color 0.2s;
}

.btng-chat-input-wrapper:focus-within {
    border-color: var(--btng-primary);
}

.btng-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    color: var(--btng-text);
    max-height: 120px;
    outline: none;
}

.btng-chat-input::placeholder {
    color: var(--btng-text-light);
}

.btng-chat-send {
    background: var(--btng-primary);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, opacity 0.2s;
    flex-shrink: 0;
}

.btng-chat-send:hover:not(:disabled) {
    background: var(--btng-primary-hover);
}

.btng-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btng-chat-powered {
    text-align: center;
    font-size: 11px;
    color: var(--btng-text-light);
    margin-top: 8px;
}

.btng-chat-powered a {
    color: var(--btng-primary);
    text-decoration: none;
}

/* ===============================================
   LOADING STATE
   =============================================== */
.btng-chat-loading {
    position: absolute;
    inset: 0;
    background: var(--btng-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.btng-chat-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--btng-border);
    border-top-color: var(--btng-primary);
    border-radius: 50%;
    animation: btng-spin 0.8s linear infinite;
}

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

.btng-chat-loading-text {
    color: var(--btng-text-light);
    font-size: 14px;
}

/* ===============================================
   ERROR STATE
   =============================================== */
.btng-chat-error {
    position: absolute;
    inset: 0;
    background: var(--btng-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 32px;
    text-align: center;
}

.btng-chat-error-icon {
    width: 48px;
    height: 48px;
    background: var(--btng-error);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
}

.btng-chat-error-message {
    color: var(--btng-text);
}

.btng-chat-retry {
    padding: 10px 24px;
    background: var(--btng-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btng-chat-retry:hover {
    background: var(--btng-primary-hover);
}

/* ===============================================
   COMPLETION STATE
   =============================================== */
.btng-chat-complete {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 32px;
    text-align: center;
    z-index: 10;
}

/* Dark mode support for completion overlay */
.btng-chat-widget[data-theme="dark"] .btng-chat-complete {
    background: rgba(17, 24, 39, 0.95);
}

.btng-chat-complete-icon {
    color: var(--btng-success);
}

.btng-chat-complete-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--btng-text);
}

.btng-chat-complete-ref {
    font-size: 16px;
    font-weight: 500;
    color: var(--btng-primary);
    background: var(--btng-primary-light);
    padding: 8px 16px;
    border-radius: 8px;
}

.btng-chat-complete-message {
    color: var(--btng-text-light);
    max-width: 300px;
}

.btng-chat-new {
    padding: 12px 24px;
    background: var(--btng-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-top: 8px;
}

.btng-chat-new:hover {
    background: var(--btng-primary-hover);
}

/* ===============================================
   RESPONSIVE
   =============================================== */
@media (max-width: 480px) {
    .btng-chat-floating {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        bottom: 80px;
        right: 10px;
        left: 10px;
        border-radius: 16px;
    }

    .btng-chat-bubble {
        width: 56px;
        height: 56px;
    }

    .btng-chat-bubble-bottom-right,
    .btng-chat-bubble-bottom-left {
        bottom: 16px;
        right: 16px;
        left: auto;
    }

    .btng-chat-embedded {
        height: 500px;
        border-radius: 0;
    }
}

/* Scrollbar styling */
.btng-chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.btng-chat-messages::-webkit-scrollbar-thumb {
    background: var(--btng-border);
    border-radius: 3px;
}

.btng-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--btng-text-light);
}

/* ===============================================
   HERO EMBEDDED MODE
   Transparent/glass styling for dark hero backgrounds
   =============================================== */
.btng-chat-hero-embedded {
    --btng-primary: #f97316;
    --btng-primary-hover: #ea580c;
    --btng-primary-light: rgba(249, 115, 22, 0.15);
    --btng-text: #ffffff;
    --btng-text-light: rgba(255, 255, 255, 0.7);
    --btng-border: rgba(255, 255, 255, 0.15);
    --btng-bg: transparent;
    --btng-bg-secondary: rgba(255, 255, 255, 0.05);

    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    height: auto;
    max-height: none;
}

.btng-chat-hero-embedded .btng-chat-messages {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    max-height: 240px;
    min-height: 180px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btng-chat-hero-embedded .btng-chat-messages-inner {
    padding: 16px;
}

.btng-chat-hero-embedded .btng-chat-message {
    max-width: 90%;
}

.btng-chat-hero-embedded .btng-chat-message-assistant {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: white;
}

.btng-chat-hero-embedded .btng-chat-message-user {
    background: var(--btng-primary);
    color: white;
}

.btng-chat-hero-embedded .btng-chat-suggestions {
    background: transparent;
    border-top: none;
    padding: 12px 0;
    gap: 8px;
}

.btng-chat-hero-embedded .btng-chat-suggestion {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 12px;
    padding: 8px 14px;
}

.btng-chat-hero-embedded .btng-chat-suggestion:hover {
    background: var(--btng-primary);
    border-color: var(--btng-primary);
    color: white;
}

.btng-chat-hero-embedded .btng-chat-input-area {
    background: transparent;
    border-top: none;
    padding: 12px 0 0;
}

.btng-chat-hero-embedded .btng-chat-input-wrapper {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 24px;
}

.btng-chat-hero-embedded .btng-chat-input-wrapper:focus-within {
    border-color: var(--btng-primary);
    background: rgba(255, 255, 255, 0.15);
}

.btng-chat-hero-embedded .btng-chat-input {
    color: white;
}

.btng-chat-hero-embedded .btng-chat-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.btng-chat-hero-embedded .btng-chat-send {
    background: var(--btng-primary);
}

.btng-chat-hero-embedded .btng-chat-send:hover:not(:disabled) {
    background: var(--btng-primary-hover);
}

.btng-chat-hero-embedded .btng-chat-send:disabled {
    opacity: 0.4;
    background: rgba(255, 255, 255, 0.2);
}

.btng-chat-hero-embedded .btng-chat-send svg {
    stroke: white;
}

/* Hero Loading State */
.btng-chat-hero-embedded .btng-chat-loading {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
}

.btng-chat-hero-embedded .btng-chat-spinner {
    border-color: rgba(255, 255, 255, 0.2);
    border-top-color: var(--btng-primary);
}

.btng-chat-hero-embedded .btng-chat-loading-text {
    color: rgba(255, 255, 255, 0.8);
}

/* Hero Error State */
.btng-chat-hero-embedded .btng-chat-error {
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
}

.btng-chat-hero-embedded .btng-chat-error-message {
    color: white;
}

/* Hero Complete State */
.btng-chat-hero-embedded .btng-chat-complete {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 24px;
}

.btng-chat-hero-embedded .btng-chat-complete-icon {
    color: #22c55e;
}

.btng-chat-hero-embedded .btng-chat-complete-title {
    color: white;
    font-size: 18px;
}

.btng-chat-hero-embedded .btng-chat-complete-ref {
    background: rgba(255, 255, 255, 0.1);
    color: var(--btng-primary);
}

.btng-chat-hero-embedded .btng-chat-complete-message {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
}

.btng-chat-hero-embedded .btng-chat-new {
    background: var(--btng-primary);
}

.btng-chat-hero-embedded .btng-chat-new:hover {
    background: var(--btng-primary-hover);
}

/* Hero Typing Indicator */
.btng-chat-hero-embedded .btng-typing-indicator span {
    background: rgba(255, 255, 255, 0.6);
}

/* Hero Mode Responsive */
@media (max-width: 768px) {
    .btng-chat-hero-embedded .btng-chat-messages {
        max-height: 200px;
        min-height: 150px;
    }

    .btng-chat-hero-embedded .btng-chat-suggestion {
        font-size: 11px;
        padding: 6px 10px;
    }
}

/* ===============================================
   WHATSAPP FALLBACK (Critical Error State)
   =============================================== */
.btng-chat-whatsapp-fallback {
    display: none;
    padding: 20px 16px;
    background: var(--btng-bg);
    border-top: 1px solid var(--btng-border);
    text-align: center;
}

.btng-fallback-message {
    margin-bottom: 16px;
}

.btng-fallback-message p {
    margin: 0;
    color: var(--btng-text);
    font-size: 14px;
}

.btng-fallback-message .btng-fallback-submessage {
    color: var(--btng-text-light);
    font-size: 13px;
    margin-top: 4px;
}

.btng-whatsapp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 24px;
    background: #25D366;
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.btng-whatsapp-btn:hover {
    background: #128C7E;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(37, 211, 102, 0.4);
    color: white;
}

.btng-whatsapp-btn svg {
    flex-shrink: 0;
}

/* Hero embedded mode WhatsApp fallback */
.btng-chat-hero-embedded .btng-chat-whatsapp-fallback {
    background: transparent;
    border-top: none;
    padding: 16px 0;
}

.btng-chat-hero-embedded .btng-fallback-message p {
    color: var(--btng-text);
}

.btng-chat-hero-embedded .btng-fallback-message .btng-fallback-submessage {
    color: var(--btng-text-light);
}

/* Override for white hero card */
.hero-card .btng-chat-whatsapp-fallback {
    background: transparent;
}

.hero-card .btng-fallback-message p {
    color: var(--navy, #0a1628);
}

.hero-card .btng-fallback-message .btng-fallback-submessage {
    color: var(--gray-500, #64748b);
}
