/* WEBRION Technologies - Webri AI Chatbot Widget Styling */

:root {
    --chat-bg: rgba(6, 9, 19, 0.85);
    --chat-border: rgba(6, 182, 212, 0.25);
    --chat-glow: rgba(6, 182, 212, 0.4);
    --chat-accent-cyan: #06b6d4;
    --chat-accent-purple: #8b5cf6;
    --chat-text-white: #ffffff;
    --chat-text-muted: #94a3b8;
    --chat-text-body: #ffffff;
    --chat-glass-header: rgba(12, 18, 36, 0.9);
    --chat-user-msg: linear-gradient(135deg, #06b6d4, #8b5cf6);
    --chat-bot-msg: rgba(255, 255, 255, 0.05);
    --chat-bubble-border: rgba(255, 255, 255, 0.08);
    --chat-input-bg: rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
    --chat-bg: rgba(248, 250, 252, 0.95);
    --chat-border: rgba(15, 23, 42, 0.08);
    --chat-glow: rgba(6, 182, 212, 0.15);
    --chat-text-muted: #475569;
    --chat-text-body: #0f172a;
    --chat-glass-header: rgba(255, 255, 255, 0.95);
    --chat-bot-msg: rgba(15, 23, 42, 0.05);
    --chat-bubble-border: rgba(15, 23, 42, 0.06);
    --chat-input-bg: rgba(15, 23, 42, 0.05);
}

.webri-chat-trigger {
    position: fixed;
    bottom: 95px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-accent-cyan), var(--chat-accent-purple));
    box-shadow: 0 8px 32px 0 rgba(6, 182, 212, 0.3), 0 0 15px 0 var(--chat-accent-cyan);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9999;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.webri-chat-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 10px 40px 0 rgba(6, 182, 212, 0.5), 0 0 25px 0 var(--chat-accent-purple);
}

.webri-chat-trigger .webri-chat-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    transform: scale(1.22); /* hides outer margins of custom avatar */
    transition: all 0.3s ease;
}

.webri-chat-trigger .webri-chat-close-icon {
    position: absolute;
    color: var(--chat-text-white);
    font-size: 22px;
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
    transition: all 0.3s ease;
}

/* Active states for custom image trigger */
.webri-chat-trigger.active .webri-chat-avatar-img {
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
}

.webri-chat-trigger.active .webri-chat-close-icon {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* Notification Badge (Pulsing Red Badge) */
.webri-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444; /* Premium bright red */
    color: #ffffff;
    font-family: 'Outfit', sans-serif;
    font-size: 11px;
    font-weight: 800;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #0c1224; /* Matches footer/chat dark background */
    box-shadow: 0 3px 10px rgba(239, 68, 68, 0.5);
    z-index: 10000;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    animation: badge-subtle-pulse 2s infinite ease-in-out;
}

[data-theme="light"] .webri-chat-badge {
    border-color: #ffffff;
    box-shadow: 0 3px 10px rgba(239, 68, 68, 0.3);
}

@keyframes badge-subtle-pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 3px 8px rgba(239, 68, 68, 0.4);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 3px 12px rgba(239, 68, 68, 0.6);
    }
}

/* Robot Avatar Image Subtle Wiggle Animation */
.webri-chat-trigger:not(.active) .webri-chat-avatar-img {
    animation: robot-wiggle 7s ease-in-out infinite;
}

@keyframes robot-wiggle {
    0%, 88.6%, 100% {
        transform: rotate(0) scale(1);
    }
    90% {
        transform: rotate(-12deg) scale(1.1);
    }
    93% {
        transform: rotate(10deg) scale(1.1);
    }
    96% {
        transform: rotate(-8deg) scale(1.1);
    }
    98% {
        transform: rotate(6deg) scale(1.1);
    }
}

@media (max-width: 480px) {
    .webri-chat-badge {
        width: 18px;
        height: 18px;
        font-size: 10px;
        top: -4px;
        right: -4px;
        border-width: 1.5px;
    }
}

/* Chat Console Panel */
.webri-chat-panel {
    position: fixed;
    bottom: 170px;
    right: 30px;
    width: 380px;
    max-width: calc(100vw - 60px);
    height: 550px;
    max-height: calc(100vh - 215px);
    background: var(--chat-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--chat-border);
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), 0 0 30px rgba(6, 182, 212, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
    opacity: 0;
    transform: translateY(40px) scale(0.95);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.webri-chat-panel.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Chat Header */
.webri-chat-header {
    background: var(--chat-glass-header);
    padding: 16px 20px;
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.webri-chat-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(139, 92, 246, 0.2));
    border: 2px solid var(--chat-accent-cyan);
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

.webri-chat-avatar-header-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    transform: scale(1.22); /* scales robot image to meet outer border */
}

.webri-chat-avatar i {
    color: var(--chat-accent-cyan);
    font-size: 18px;
    text-shadow: 0 0 5px var(--chat-accent-cyan);
}

.webri-chat-status-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 11px;
    height: 11px;
    background-color: #22c55e;
    border: 2px solid var(--chat-glass-header);
    border-radius: 50%;
    box-shadow: 0 0 5px rgba(34, 197, 94, 0.6);
    z-index: 10;
}

.webri-chat-meta {
    display: flex;
    flex-direction: column;
}

.webri-chat-name {
    font-family: 'Outfit', sans-serif;
    font-size: 15px;
    font-weight: 700;
    color: var(--chat-text-body);
    letter-spacing: 0.5px;
}

.webri-chat-status-text {
    font-family: 'Outfit', sans-serif;
    font-size: 11px;
    color: #22c55e;
    font-weight: 600;
}

.webri-chat-close {
    background: transparent;
    border: none;
    color: var(--chat-text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.webri-chat-close:hover {
    color: var(--chat-text-body);
    background: var(--chat-bot-msg);
}

/* Chat Body (Messages Log) */
.webri-chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
}

/* Custom Scrollbar for Chat Body */
.webri-chat-body::-webkit-scrollbar {
    width: 5px;
}

.webri-chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.webri-chat-body::-webkit-scrollbar-thumb {
    background: rgba(6, 182, 212, 0.3);
    border-radius: 10px;
}

.webri-chat-body::-webkit-scrollbar-thumb:hover {
    background: rgba(6, 182, 212, 0.5);
}

/* Message Bubble */
.webri-msg {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: webri-fade-in-up 0.3s ease forwards;
}

@keyframes webri-fade-in-up {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.webri-msg.user {
    align-self: flex-end;
}

.webri-msg.bot {
    align-self: flex-start;
}

.webri-msg-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-family: 'Outfit', sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

.webri-msg.user .webri-msg-bubble {
    background: var(--chat-user-msg);
    color: var(--chat-text-white);
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(6, 182, 212, 0.2);
}

.webri-msg.bot .webri-msg-bubble {
    background: var(--chat-bot-msg);
    color: var(--chat-text-body);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--chat-bubble-border);
}

.webri-msg-bubble a {
    color: var(--chat-accent-cyan) !important;
    text-decoration: underline !important;
    cursor: pointer !important;
    pointer-events: auto !important;
    word-break: break-all;
}

.webri-msg-bubble a:hover {
    filter: brightness(1.2);
}

.webri-msg-time {
    font-size: 9px;
    color: var(--chat-text-muted);
    margin-top: 4px;
    align-self: flex-end;
}

.webri-msg.bot .webri-msg-time {
    align-self: flex-start;
}

/* Typing Indicator Bubble */
.webri-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 18px;
    background: var(--chat-bot-msg);
    border: 1px solid var(--chat-bubble-border);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    animation: webri-fade-in-up 0.2s ease forwards;
}

.webri-typing-dot {
    width: 6px;
    height: 6px;
    background: var(--chat-accent-cyan);
    border-radius: 50%;
    animation: webri-bounce 1.4s infinite ease-in-out both;
}

.webri-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.webri-typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes webri-bounce {
    0%, 80%, 100% { 
        transform: scale(0); 
    }
    40% { 
        transform: scale(1.0); 
    }
}

/* Chat Footer (Input Area) */
.webri-chat-footer {
    padding: 16px 20px;
    background: var(--chat-glass-header);
    border-top: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.webri-chat-input-wrapper {
    width: 100%;
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
}

.webri-chat-input {
    flex: 1;
    background: var(--chat-input-bg);
    border: 1px solid var(--chat-border);
    border-radius: 50px;
    padding: 12px 18px;
    padding-right: 45px;
    font-family: 'Outfit', sans-serif;
    font-size: 13px;
    color: var(--chat-text-body);
    outline: none;
    transition: all 0.3s ease;
}

.webri-chat-input:focus {
    border-color: var(--chat-accent-cyan);
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.2);
}

.webri-chat-input::placeholder {
    color: var(--chat-text-muted);
}

.webri-chat-send {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-accent-cyan), var(--chat-accent-purple));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.webri-chat-send:hover {
    transform: translateY(-50%) scale(1.05);
    box-shadow: 0 0 8px var(--chat-accent-cyan);
}

.webri-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
    transform: translateY(-50%) !important;
    box-shadow: none !important;
}

.webri-chat-send i {
    color: var(--chat-text-white);
    font-size: 12px;
}

/* Quick replies container */
.webri-quick-replies {
    display: flex;
    gap: 8px;
    padding: 0 4px;
    overflow-x: auto;
    width: 100%;
}

.webri-quick-replies::-webkit-scrollbar {
    height: 3px;
}

.webri-quick-replies::-webkit-scrollbar-thumb {
    background: rgba(6, 182, 212, 0.2);
    border-radius: 10px;
}

.webri-quick-reply-btn {
    background: rgba(6, 182, 212, 0.1);
    border: 1px solid rgba(6, 182, 212, 0.2);
    color: var(--chat-accent-cyan);
    font-family: 'Outfit', sans-serif;
    font-size: 11px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 50px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
}

.webri-quick-reply-btn:hover {
    background: var(--chat-accent-cyan);
    color: var(--chat-text-white);
    border-color: var(--chat-accent-cyan);
    transform: translateY(-1px);
}

/* ========== CHATBOT GREETING BUBBLE ========== */
.webri-chat-greeting-bubble {
    position: fixed;
    bottom: 165px; /* Just above trigger button which is bottom 95px */
    right: 30px;
    background: rgba(12, 18, 36, 0.95);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(6, 182, 212, 0.3);
    color: #ffffff;
    padding: 12px 35px 12px 18px;
    border-radius: 18px 18px 4px 18px; /* pointy bottom-right style */
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 12.5px;
    font-weight: 600;
    box-shadow: 0 10px 30px rgba(6, 182, 212, 0.15), 0 0 15px rgba(6, 182, 212, 0.05);
    z-index: 9998;
    max-width: 250px;
    opacity: 0;
    transform: translateY(15px);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.webri-chat-greeting-bubble::after {
    content: '';
    position: absolute;
    bottom: -7px;
    right: 20px;
    width: 12px;
    height: 12px;
    background: inherit;
    border-right: 1px solid rgba(6, 182, 212, 0.3);
    border-bottom: 1px solid rgba(6, 182, 212, 0.3);
    transform: rotate(45deg);
}

.webri-chat-greeting-bubble.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

[data-theme="light"] .webri-chat-greeting-bubble {
    background: rgba(255, 255, 255, 0.98);
    color: #0f172a;
    border: 1px solid rgba(6, 182, 212, 0.25);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

[data-theme="light"] .webri-chat-greeting-bubble::after {
    border-right: 1px solid rgba(6, 182, 212, 0.25);
    border-bottom: 1px solid rgba(6, 182, 212, 0.25);
}

.webri-chat-greeting-close {
    position: absolute;
    top: 5px;
    right: 8px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
    transition: all 0.2s ease;
    opacity: 0.7;
    outline: none;
}

.webri-chat-greeting-close:hover {
    color: #ef4444;
    opacity: 1;
}

/* Hide greeting bubble when chat trigger is active (hidden trigger on mobile fullscreen) */
.webri-chat-trigger.active ~ .webri-chat-greeting-bubble {
    opacity: 0 !important;
    transform: translateY(15px) !important;
    pointer-events: none !important;
}

/* Adjust greeting bubble position on mobile and tablet query sizes */
@media (max-width: 480px) {
    .webri-chat-greeting-bubble {
        bottom: 145px;
        right: 15px;
        max-width: 220px;
        font-size: 11.5px;
    }
}
@media (min-width: 481px) and (max-width: 768px) {
    .webri-chat-greeting-bubble {
        bottom: 155px;
        right: 20px;
    }
}

/* ========== MOBILE FULLSCREEN CHAT EXPERIENCE ========== */
@media (max-width: 480px) {
    /* Fullscreen takeover on mobile - like WhatsApp/Telegram DMs */
    /* NOTE: height is set dynamically by JS via visualViewport API */
    .webri-chat-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
        z-index: 10000;
        box-shadow: none;
        background: var(--chat-bg);
        backdrop-filter: blur(30px);
        -webkit-backdrop-filter: blur(30px);
    }

    .webri-chat-panel.active {
        transform: translateY(0) scale(1);
    }

    /* Header gets safe-area padding for notched phones */
    .webri-chat-panel .webri-chat-header {
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
        padding-left: calc(16px + env(safe-area-inset-left, 0px));
        padding-right: calc(16px + env(safe-area-inset-right, 0px));
        flex-shrink: 0;
    }

    /* Chat body fills the remaining space */
    .webri-chat-panel .webri-chat-body {
        padding: 12px 14px;
        gap: 10px;
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    /* Footer/Input sticks at bottom - never hidden */
    .webri-chat-panel .webri-chat-footer {
        padding: 10px 14px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        flex-shrink: 0;
    }

    /* Force input text visible on mobile - override browser defaults */
    .webri-chat-input {
        font-size: 16px !important; /* 16px prevents iOS auto-zoom */
        color: #ffffff !important;
        -webkit-text-fill-color: #ffffff !important;
        opacity: 1 !important;
        -webkit-opacity: 1 !important;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        background: rgba(255, 255, 255, 0.08) !important;
        border: 1px solid rgba(6, 182, 212, 0.3) !important;
    }

    .webri-chat-input:focus {
        color: #ffffff !important;
        -webkit-text-fill-color: #ffffff !important;
        background: rgba(255, 255, 255, 0.12) !important;
        border-color: var(--chat-accent-cyan) !important;
    }

    .webri-chat-input::placeholder {
        color: #94a3b8 !important;
        -webkit-text-fill-color: #94a3b8 !important;
        opacity: 1 !important;
    }

    /* Light theme mobile input */
    [data-theme="light"] .webri-chat-input {
        color: #0f172a !important;
        -webkit-text-fill-color: #0f172a !important;
        background: rgba(15, 23, 42, 0.06) !important;
        border: 1px solid rgba(15, 23, 42, 0.15) !important;
    }

    [data-theme="light"] .webri-chat-input:focus {
        color: #0f172a !important;
        -webkit-text-fill-color: #0f172a !important;
        background: rgba(15, 23, 42, 0.08) !important;
    }

    [data-theme="light"] .webri-chat-input::placeholder {
        color: #64748b !important;
        -webkit-text-fill-color: #64748b !important;
    }

    /* Smaller trigger button on mobile */
    .webri-chat-trigger {
        bottom: 75px;
        right: 15px;
        width: 55px;
        height: 55px;
    }

    /* Hide floating action buttons when chat is open */
    body.webri-chat-fullscreen .floating-actions-bar {
        display: none !important;
    }

    /* Hide chat trigger when chat is open */
    .webri-chat-trigger.active {
        opacity: 0;
        pointer-events: none;
        transform: scale(0.5);
    }

    /* Prevent body scroll when chat is open on mobile */
    body.webri-chat-fullscreen {
        overflow: hidden !important;
        touch-action: none;
    }
}

/* Tablet adjustments */
@media (min-width: 481px) and (max-width: 768px) {
    .webri-chat-panel {
        bottom: 155px;
        right: 20px;
        width: 370px;
        max-height: calc(100vh - 200px);
    }

    .webri-chat-trigger {
        bottom: 85px;
        right: 20px;
    }
}
