/* ==========================================================================
   Expertiseweb Chatbot Widget - v2.0 Distinctive AI Assistant
   ========================================================================== */

/* ============================
   Toggle Button (Pill-shaped)
   ============================ */
.chatbot-toggle {
    position: fixed;
    height: 48px !important;
    min-height: 48px !important;
    max-height: 48px !important;
    border-radius: 24px !important;
    background: var(--chatbot-toggle, var(--chatbot-primary, #06a18b)) !important;
    color: #fff !important;
    border: none !important;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25), 0 0 0 0 rgba(var(--chatbot-toggle-rgb, 6,161,139), 0.4);
    z-index: 2147483646;
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 20px 0 16px !important;
    margin: 0 !important;
    outline: none;
    -webkit-appearance: none;
    box-sizing: border-box !important;
    line-height: 1 !important;
    text-indent: 0 !important;
    letter-spacing: normal !important;
    white-space: nowrap;
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-radius 0.3s ease, width 0.3s ease, padding 0.3s ease;
    animation: chatbot-entry 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards, chatbot-glow 3s ease-in-out 2s infinite;
    opacity: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.chatbot-toggle:hover {
    transform: scale(1.04);
    box-shadow: 0 6px 28px rgba(0,0,0,0.3);
    animation: none;
    opacity: 1;
}

/* When chat is open: shrink to circle */
.chatbot-toggle-active {
    width: 48px !important;
    min-width: 48px !important;
    max-width: 48px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    background: #555 !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: none;
    opacity: 1;
}

.chatbot-toggle-active:hover {
    background: #444 !important;
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

.chatbot-toggle-icon-open,
.chatbot-toggle-icon-close {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    flex-shrink: 0;
}

.chatbot-toggle-label {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1;
    color: #fff;
    pointer-events: none;
}

/* Entry animation: slide in from right with bounce */
@keyframes chatbot-entry {
    0% {
        opacity: 0;
        transform: translateX(80px) scale(0.8);
    }
    60% {
        opacity: 1;
        transform: translateX(-6px) scale(1.02);
    }
    80% {
        transform: translateX(2px) scale(0.99);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* Subtle glow pulse */
@keyframes chatbot-glow {
    0%, 100% {
        box-shadow: 0 4px 20px rgba(0,0,0,0.25), 0 0 0 0 rgba(var(--chatbot-toggle-rgb, 6,161,139), 0.4);
    }
    50% {
        box-shadow: 0 4px 20px rgba(0,0,0,0.25), 0 0 0 8px rgba(var(--chatbot-toggle-rgb, 6,161,139), 0);
    }
}

/* ============================
   Teaser Bubble
   ============================ */
.chatbot-teaser {
    position: fixed;
    z-index: 2147483646;
    animation: chatbot-teaser-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    opacity: 0;
}

.chatbot-teaser-content {
    background: #fff;
    border-radius: 14px;
    padding: 12px 36px 12px 16px;
    box-shadow: 0 6px 30px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 280px;
    position: relative;
    cursor: pointer;
}

.chatbot-teaser-text {
    font-size: 13.5px;
    line-height: 1.4;
    color: #333;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.chatbot-teaser-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px !important;
    height: 22px !important;
    min-width: 22px !important;
    min-height: 22px !important;
    max-width: 22px !important;
    max-height: 22px !important;
    border-radius: 50% !important;
    background: #f0f0f0 !important;
    border: none !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    margin: 0 !important;
    line-height: 0 !important;
    box-sizing: border-box !important;
    text-indent: 0 !important;
    outline: none;
    transition: background 0.2s;
}

.chatbot-teaser-close:hover {
    background: #e0e0e0 !important;
}

.chatbot-teaser-close svg {
    width: 12px !important;
    height: 12px !important;
    stroke: #666 !important;
}

.chatbot-teaser-arrow {
    width: 12px;
    height: 12px;
    background: #fff;
    transform: rotate(45deg);
    box-shadow: 3px 3px 6px rgba(0,0,0,0.06);
    margin-left: 24px;
    margin-top: -7px;
}

@keyframes chatbot-teaser-in {
    0% {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chatbot-teaser-out {
    animation: chatbot-teaser-out 0.25s ease forwards !important;
}

@keyframes chatbot-teaser-out {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(6px) scale(0.95);
    }
}

/* ============================
   Positions
   ============================ */
.chatbot-pos-bottom-right .chatbot-toggle {
    bottom: 28px;
    right: 24px;
}
.chatbot-pos-bottom-right .chatbot-window {
    bottom: 88px;
    right: 24px;
}
.chatbot-pos-bottom-right .chatbot-teaser {
    bottom: 86px;
    right: 24px;
}

.chatbot-pos-bottom-left .chatbot-toggle {
    bottom: 28px;
    left: 24px;
}
.chatbot-pos-bottom-left .chatbot-window {
    bottom: 88px;
    left: 24px;
}
.chatbot-pos-bottom-left .chatbot-teaser {
    bottom: 86px;
    left: 24px;
}
.chatbot-pos-bottom-left .chatbot-teaser-arrow {
    margin-left: auto;
    margin-right: 24px;
}

.chatbot-pos-middle-right .chatbot-toggle {
    top: 50%;
    right: 24px;
    transform: translateY(-50%);
}
.chatbot-pos-middle-right .chatbot-toggle:hover {
    transform: translateY(-50%) scale(1.04);
}
.chatbot-pos-middle-right .chatbot-window {
    top: 50%;
    right: 24px;
    transform: translateY(-50%);
    bottom: auto;
}
.chatbot-pos-middle-right .chatbot-teaser {
    top: calc(50% - 70px);
    right: 24px;
}

.chatbot-pos-top-right .chatbot-toggle {
    top: 100px;
    right: 24px;
}
.chatbot-pos-top-right .chatbot-window {
    top: 160px;
    right: 24px;
    bottom: auto;
}
.chatbot-pos-top-right .chatbot-teaser {
    top: 56px;
    right: 24px;
}

/* ============================
   Chat Window
   ============================ */
.chatbot-window {
    position: fixed;
    width: 600px;
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
    z-index: 2147483647;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatbot-slideUp 0.25s ease;
}

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

/* ============================
   Header
   ============================ */
.chatbot-header {
    background: var(--chatbot-primary, #06a18b) !important;
    color: #fff !important;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.chatbot-header-title {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}

.chatbot-header-status {
    font-size: 11px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 5px;
    line-height: 1.2;
}

.chatbot-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    box-shadow: 0 0 4px rgba(74, 222, 128, 0.6);
}

.chatbot-header-actions {
    display: flex;
    gap: 4px;
}

.chatbot-header-btn {
    background: rgba(255, 255, 255, 0.15) !important;
    border: none !important;
    color: #fff !important;
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
    max-width: 32px !important;
    max-height: 32px !important;
    border-radius: 8px !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    line-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    outline: none;
    box-sizing: border-box !important;
    text-indent: 0 !important;
}

.chatbot-header-btn:hover {
    background: rgba(255, 255, 255, 0.3) !important;
}

/* Force SVG visibility (theme overrides protection) */
#chatbot-widget .chatbot-toggle-icon-open svg {
    display: inline-block !important;
    visibility: visible !important;
    overflow: visible !important;
    width: 22px !important;
    height: 22px !important;
    fill: #fff !important;
    stroke: none !important;
}

#chatbot-widget .chatbot-toggle-icon-close svg {
    display: inline-block !important;
    visibility: visible !important;
    overflow: visible !important;
    width: 20px !important;
    height: 20px !important;
    fill: none !important;
    stroke: #fff !important;
}

#chatbot-widget .chatbot-header-btn svg {
    display: inline-block !important;
    visibility: visible !important;
    overflow: visible !important;
    width: 16px !important;
    height: 16px !important;
    fill: none !important;
    stroke: #fff !important;
}

#chatbot-widget .chatbot-send svg {
    display: inline-block !important;
    visibility: visible !important;
    overflow: visible !important;
    width: 18px !important;
    height: 18px !important;
    fill: #fff !important;
    stroke: none !important;
}

#chatbot-widget .chatbot-avatar svg {
    display: inline-block !important;
    visibility: visible !important;
    overflow: visible !important;
    width: 18px !important;
    height: 18px !important;
    fill: #fff !important;
    stroke: none !important;
}

/* ============================
   Messages
   ============================ */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.chatbot-msg {
    display: flex;
    max-width: 88%;
}

.chatbot-msg-user {
    align-self: flex-end;
    margin-left: auto;
}

.chatbot-msg-assistant {
    align-self: flex-start;
}

.chatbot-msg-error {
    align-self: center;
    max-width: 90%;
}

/* ============================
   Bubbles
   ============================ */
.chatbot-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chatbot-bubble-user {
    background: var(--chatbot-primary, #06a18b);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chatbot-bubble-assistant {
    background: #f0f2f5;
    color: #1a1a1a;
    border-bottom-left-radius: 4px;
}

.chatbot-bubble-assistant a {
    color: var(--chatbot-primary, #06a18b);
    text-decoration: underline;
    font-weight: 500;
}

.chatbot-bubble-assistant a:hover {
    opacity: 0.8;
}

.chatbot-bubble-assistant ul,
.chatbot-bubble-assistant ol {
    margin: 6px 0;
    padding-left: 18px;
}

.chatbot-bubble-assistant li {
    margin-bottom: 3px;
}

.chatbot-bubble-assistant strong {
    font-weight: 600;
}

.chatbot-bubble-error {
    background: #fef2f2;
    color: #b91c1c;
    border-radius: 10px;
    font-size: 13px;
    text-align: center;
}

/* ============================
   Typing Indicator
   ============================ */
.chatbot-typing {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.chatbot-typing-dots {
    display: flex;
    gap: 3px;
}

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

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

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

@keyframes chatbot-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-4px);
    }
}

.chatbot-typing-text {
    font-size: 12px;
    color: #888;
    font-style: italic;
}

/* ============================
   Input Area
   ============================ */
.chatbot-input-area {
    padding: 12px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
    background: #fff;
}

.chatbot-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    resize: none;
    outline: none;
    max-height: 100px;
    line-height: 1.4;
    font-family: inherit;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    box-sizing: border-box;
}

.chatbot-input:focus {
    border-color: var(--chatbot-primary, #06a18b);
}

.chatbot-send {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    max-width: 40px !important;
    max-height: 40px !important;
    border-radius: 50% !important;
    background: var(--chatbot-primary, #06a18b) !important;
    color: #fff !important;
    border: none !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.2s;
    line-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    outline: none;
    box-sizing: border-box !important;
    text-indent: 0 !important;
}

.chatbot-send:hover:not(:disabled) {
    transform: scale(1.05);
}

.chatbot-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

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

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

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

/* ============================
   Mobile Responsive
   ============================ */
@media (max-width: 480px) {
    .chatbot-window {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0;
        transform: none !important;
    }

    /* When Android keyboard is open, shrink to visible area */
    .chatbot-window.chatbot-keyboard-open {
        height: calc(var(--chatbot-vh, 100vh)) !important;
        max-height: calc(var(--chatbot-vh, 100vh)) !important;
        top: auto !important;
        bottom: 0 !important;
    }

    .chatbot-toggle {
        bottom: 20px !important;
        right: 16px !important;
        left: auto !important;
        top: auto !important;
        height: 44px !important;
        min-height: 44px !important;
        max-height: 44px !important;
        transform: none !important;
        font-size: 13px;
    }

    .chatbot-toggle-label {
        font-size: 13px;
    }

    .chatbot-toggle-active {
        width: 44px !important;
        min-width: 44px !important;
        max-width: 44px !important;
    }

    .chatbot-teaser {
        bottom: 72px !important;
        right: 16px !important;
        left: auto !important;
        top: auto !important;
    }

    .chatbot-teaser-content {
        max-width: 250px;
    }

    .chatbot-input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .chatbot-window {
        width: 480px;
        height: calc(100vh - 120px);
    }
}

/* ============================
   Attach Button
   ============================ */
.chatbot-attach {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    max-width: 36px !important;
    max-height: 36px !important;
    border-radius: 50% !important;
    background: #f0f2f5 !important;
    border: none !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
    padding: 0 !important;
    margin: 0 !important;
    outline: none;
    box-sizing: border-box !important;
    line-height: 0 !important;
    text-indent: 0 !important;
    color: #666;
}

.chatbot-attach:hover {
    background: var(--chatbot-primary, #06a18b) !important;
    color: #fff;
}

#chatbot-widget .chatbot-attach svg {
    display: inline-block !important;
    visibility: visible !important;
    overflow: visible !important;
    width: 18px !important;
    height: 18px !important;
    fill: none !important;
    stroke: currentColor !important;
}

/* ============================
   File Preview (pending files)
   ============================ */
.chatbot-file-preview {
    padding: 8px 12px 4px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    border-top: 1px solid #e5e7eb;
    background: #fafafa;
    flex-shrink: 0;
}

.chatbot-preview-item {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e0e0e0;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.chatbot-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chatbot-preview-pdf {
    color: #999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-preview-pdf + span {
    font-size: 8px;
    color: #666;
    text-align: center;
    line-height: 1.1;
    padding: 0 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.chatbot-preview-remove {
    position: absolute;
    top: 1px;
    right: 1px;
    width: 18px !important;
    height: 18px !important;
    min-width: 18px !important;
    min-height: 18px !important;
    max-width: 18px !important;
    max-height: 18px !important;
    border-radius: 50% !important;
    background: rgba(0,0,0,0.55) !important;
    color: #fff !important;
    border: none !important;
    cursor: pointer;
    font-size: 13px;
    line-height: 18px !important;
    text-align: center;
    padding: 0 !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    text-indent: 0 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
}

.chatbot-preview-remove:hover {
    background: rgba(0,0,0,0.75) !important;
}

/* ============================
   Attachments Display (in bubbles)
   ============================ */
.chatbot-attachments-display {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.chatbot-attachment-thumb {
    width: 80px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.3);
}

.chatbot-attachment-file {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    background: rgba(255,255,255,0.2);
    border-radius: 6px;
    font-size: 11px;
    gap: 4px;
}

/* ============================
   Voice Button
   ============================ */
.chatbot-voice {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    max-width: 36px !important;
    max-height: 36px !important;
    border-radius: 50% !important;
    background: #f0f2f5 !important;
    border: none !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
    padding: 0 !important;
    margin: 0 !important;
    outline: none;
    box-sizing: border-box !important;
    line-height: 0 !important;
    text-indent: 0 !important;
    color: #666;
}

.chatbot-voice:hover {
    background: #e5e7eb !important;
    color: #333;
}

#chatbot-widget .chatbot-voice svg {
    display: inline-block !important;
    visibility: visible !important;
    overflow: visible !important;
    width: 18px !important;
    height: 18px !important;
}

#chatbot-widget .chatbot-voice-icon-mic svg {
    fill: none !important;
    stroke: currentColor !important;
}

#chatbot-widget .chatbot-voice-icon-stop svg {
    fill: currentColor !important;
    stroke: none !important;
}

.chatbot-voice-icon-mic,
.chatbot-voice-icon-stop {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.chatbot-voice-listening {
    background: #ef4444 !important;
    color: #fff !important;
    animation: chatbot-voice-pulse 1.5s ease-in-out infinite;
}

.chatbot-voice-listening:hover {
    background: #dc2626 !important;
}

@keyframes chatbot-voice-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }
}

/* ============================
   Mobile Responsive (Attachments + Voice)
   ============================ */
@media (max-width: 480px) {
    .chatbot-attach,
    .chatbot-voice {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        min-height: 32px !important;
        max-width: 32px !important;
        max-height: 32px !important;
    }

    .chatbot-preview-item {
        width: 48px;
        height: 48px;
    }

    .chatbot-attachment-thumb {
        width: 60px;
        height: 45px;
    }
}
