/**
 * Chatbot Widget V2 - Styles
 * Complete implementation with all features
 */

/* ============================================
   BASE STYLES
   ============================================ */

.chatbot-widget {
    position: fixed;
    z-index: 9999;
    font-family: var(--widget-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif);
}

/* Position classes */
.chatbot-widget.position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.chatbot-widget.position-bottom-left {
    bottom: 20px;
    left: 20px;
}

.chatbot-widget.position-top-right {
    top: 20px;
    right: 20px;
}

.chatbot-widget.position-top-left {
    top: 20px;
    left: 20px;
}

/* Default position (bottom-right) if no class specified */
.chatbot-widget:not([class*="position-"]) {
    bottom: 20px;
    right: 20px;
}

.chatbot-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ============================================
   TRIGGER BUTTON
   ============================================ */

.chatbot-trigger {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #003366, #0055aa);
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 51, 102, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: absolute;
    z-index: 10;
}

/* Position trigger button at bottom of widget container */
.chatbot-widget.position-bottom-right .chatbot-trigger,
.chatbot-widget.position-bottom-left .chatbot-trigger,
.chatbot-widget:not([class*="position-"]) .chatbot-trigger {
    bottom: 0;
    right: 0;
}

/* Position trigger button at top of widget container for top positions */
.chatbot-widget.position-top-right .chatbot-trigger,
.chatbot-widget.position-top-left .chatbot-trigger {
    top: 0;
}

/* Horizontal positioning for top positions */
.chatbot-widget.position-top-right .chatbot-trigger,
.chatbot-widget.position-bottom-right .chatbot-trigger,
.chatbot-widget:not([class*="position-"]) .chatbot-trigger {
    right: 0;
}

.chatbot-widget.position-top-left .chatbot-trigger,
.chatbot-widget.position-bottom-left .chatbot-trigger {
    left: 0;
}

.chatbot-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 51, 102, 0.5);
}

/* Trigger icon management - keep visible when open */
.chatbot-trigger-icon {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.chatbot-icon-default {
    display: inline-flex !important;
}

.chatbot-icon-close {
    display: none !important;
}

.chatbot-widget.open .chatbot-icon-default {
    display: none !important;
}

.chatbot-widget.open .chatbot-icon-close {
    display: inline-flex !important;
}

/* ============================================
   TOOLTIPS ABOVE WIDGET
   ============================================ */

.chatbot-tooltip {
    background: #ffffff;
    color: #333333;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 10px;
    animation: tooltipFadeIn 0.3s ease;
    text-align: center;
    white-space: normal;
    word-wrap: break-word;
    max-width: 250px;
    transition: opacity 0.3s ease;
}

/* Hide tooltips when widget is open */
.chatbot-widget.open .chatbot-tooltip {
    display: none !important;
}

/* Tooltip positioning - adjust when widget is open */
.chatbot-widget.position-bottom-right .chatbot-tooltip,
.chatbot-widget.position-bottom-left .chatbot-tooltip,
.chatbot-widget:not([class*="position-"]) .chatbot-tooltip {
    margin-bottom: 80px;  /* Space for trigger button */
}

.chatbot-widget.position-top-right .chatbot-tooltip,
.chatbot-widget.position-top-left .chatbot-tooltip {
    margin-top: 80px;  /* Space for trigger button */
    margin-bottom: 10px;
}

.chatbot-tooltip-1 {
    color: #333333;
}

.chatbot-tooltip-2 {
    color: #333333;
    margin-bottom: 8px;
}

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

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

/* ============================================
   CHAT WINDOW
   ============================================ */

.chatbot-window {
    display: none;
    width: 380px;
    height: var(--widget-height, 700px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

/* When widget is open, window moves up to make room for trigger button */
.chatbot-widget.open .chatbot-window {
    display: flex;
    position: relative;
}

/* Bottom positions: window moves up */
.chatbot-widget.position-bottom-right.open .chatbot-window,
.chatbot-widget.position-bottom-left.open .chatbot-window,
.chatbot-widget:not([class*="position-"]).open .chatbot-window {
    top: -70px;
}

/* Top positions: window moves down */
.chatbot-widget.position-top-right.open .chatbot-window,
.chatbot-widget.position-top-left.open .chatbot-window {
    top: 70px;
}

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

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

/* ============================================
   ANIMATIONS
   ============================================ */

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

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

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.animated-message {
    animation: fadeInUp 0.3s ease forwards;
}

.animated-button {
    animation: fadeInUp 0.3s ease forwards;
    opacity: 0;
}

.animated-card {
    animation: fadeInScale 0.3s ease forwards;
}

/* ============================================
   HEADER
   ============================================ */

.chatbot-header {
    padding: 16px;
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chatbot-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

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

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

.chatbot-subtitle {
    font-size: 12px;
    opacity: 0.8;
}

.chatbot-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chatbot-btn-tts,
.chatbot-btn-reset,
.chatbot-btn-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

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

.chatbot-btn-tts.active {
    background: rgba(76, 175, 80, 0.9);
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.5);
}

.chatbot-btn-tts.active:hover {
    background: rgba(76, 175, 80, 1);
}

.chatbot-btn-tts:not(.active) {
    opacity: 0.7;
}

.chatbot-btn-tts:not(.active):hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.3);
}

.chatbot-language-select {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
}

.chatbot-language-select option {
    background: #333;
    color: white;
}

/* ============================================
   MESSAGES CONTAINER
   ============================================ */

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

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

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

/* ============================================
   MESSAGE BUBBLES
   ============================================ */

.chatbot-message {
    display: flex;
    max-width: 85%;
}

.chatbot-message-user {
    align-self: flex-end;
}

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

.chatbot-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chatbot-message-user .chatbot-bubble {
    background: linear-gradient(135deg, #003366, #0055aa);
    color: white;
    border-bottom-right-radius: 4px;
}

.chatbot-message-bot .chatbot-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* ============================================
   TYPING INDICATOR
   ============================================ */

.chatbot-typing {
    align-self: flex-start;
}

.chatbot-typing .chatbot-bubble {
    display: flex;
    gap: 4px;
    padding: 16px;
}

.chatbot-typing span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

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

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

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* ============================================
   MENU BUTTONS
   ============================================ */

.chatbot-menu-wrapper {
    align-self: flex-start;
    max-width: 85%;
}

.chatbot-menu {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chatbot-menu-btn {
    background: var(--button-background-color, #ffffff);
    border: 2px solid var(--button-border-color, #003366);
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 14px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    color: var(--button-text-color, #003366);
    flex: 1 1 auto;
    min-width: 80px;
    max-width: calc(50% - 4px);
    flex-grow: 1;
}

.chatbot-menu-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    filter: brightness(0.95);
}

.chatbot-menu-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Single button takes full width */
.chatbot-menu-btn:only-child {
    max-width: 100%;
}

/* Two buttons side by side */
.chatbot-menu-btn:nth-last-child(2):first-child,
.chatbot-menu-btn:nth-last-child(2):first-child~.chatbot-menu-btn {
    max-width: calc(50% - 4px);
}

/* Three or more buttons - flexible layout */
.chatbot-menu:nth-child(n+3) .chatbot-menu-btn {
    flex: 1 1 calc(50% - 8px);
}

/* ============================================
   CARDS
   ============================================ */

.chatbot-card-wrapper {
    align-self: flex-start;
    max-width: 85%;
}

.chatbot-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.chatbot-card-image {
    width: 170px;
    height: 150px;
    object-fit: cover;
    flex-shrink: 0;
}

.chatbot-card-content {
    padding: 12px;
}

.chatbot-card-title {
    display: none;
}

.chatbot-card-desc {
    font-size: 13px;
    color: #666;
    line-height: 1.5;
    margin-bottom: 12px;
}

.chatbot-card-btn {
    display: inline-block;
    background: linear-gradient(135deg, #003366, #0055aa);
    color: white;
    padding: 10px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
}

.chatbot-card-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 51, 102, 0.3);
}

/* ============================================
   CAROUSEL
   ============================================ */

.chatbot-carousel-wrapper {
    align-self: flex-start;
    max-width: 95%;
    width: auto;
}

.chatbot-carousel-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 12px;
    padding: 0 4px;
}

/* Follow-up message and button (after cards) */
.chatbot-follow-up-wrapper {
    align-self: flex-start;
    max-width: 85%;
    margin-top: 12px;
    animation: fadeInUp 0.3s ease;
}

.chatbot-follow-up-message {
    background: white;
    color: #333;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    margin-bottom: 12px;
}

.chatbot-follow-up-button-wrapper {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chatbot-follow-up-btn {
    background: var(--button-background-color, #ffffff);
    border: 2px solid var(--button-border-color, #003366);
    color: var(--button-text-color, #003366);
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.chatbot-follow-up-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 51, 102, 0.2);
}

.chatbot-carousel {
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    width: 100%;
    max-width: 100%;
    scroll-snap-type: x mandatory;
}

.chatbot-carousel:active {
    cursor: grabbing;
}

/* Horizontal scrollbar only */
.chatbot-carousel::-webkit-scrollbar {
    height: 6px;
}

.chatbot-carousel::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

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

.chatbot-carousel::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Ensure track fills the available width */
.chatbot-carousel-track {
    display: flex;
    flex-direction: row;
    gap: 12px;
    padding: 12px;
}

.chatbot-carousel-track .chatbot-card {
    min-width: 170px;
    max-width: 170px;
    flex-shrink: 0;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    scroll-snap-align: center;
}

/* Hide carousel controls for continuous scroll */
.chatbot-carousel-controls {
    display: none;
}

/* RTL support for carousel - minimal, widget-rtl.css handles the rest */
.chatbot-widget[dir="rtl"] .chatbot-carousel-title {
    text-align: right;
}

/* ============================================
   SOURCES
   ============================================ */

.chatbot-sources {
    align-self: flex-start;
    max-width: 85%;
    background: #f0f4f8;
    border-radius: 8px;
    padding: 10px 12px;
    margin-top: 4px;
}

.chatbot-sources-title {
    font-size: 11px;
    color: #666;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chatbot-sources-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chatbot-source-link {
    font-size: 12px;
    color: #003366;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chatbot-source-link:hover {
    text-decoration: underline;
}

/* ============================================
   INPUT AREA
   ============================================ */

.chatbot-input-container {
    display: flex;
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #eee;
    gap: 8px;
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.chatbot-input:focus {
    border-color: #003366;
}

.chatbot-input::placeholder {
    color: #999;
}

.chatbot-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #003366, #0055aa);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chatbot-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 51, 102, 0.3);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 480px) {
    /* Keep widget visible on mobile */
    .chatbot-widget.position-bottom-right,
    .chatbot-widget:not([class*="position-"]) {
        bottom: 10px;
        right: 10px;
    }

    .chatbot-widget.position-bottom-left {
        bottom: 10px;
        left: 10px;
    }

    .chatbot-widget.position-top-right {
        top: 10px;
        right: 10px;
    }

    .chatbot-widget.position-top-left {
        top: 10px;
        left: 10px;
    }

    /* Adjust window size for mobile */
    .chatbot-window {
        width: calc(100vw - 20px);
        max-width: 400px;
        height: calc(100vh - 100px);
        max-height: 600px;
        border-radius: 12px;
    }

    /* When widget is open on mobile, make it fullscreen */
    .chatbot-widget.open .chatbot-window {
        width: 100vw;
        height: 100vh;
        max-width: none;
        max-height: none;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
    }

    .chatbot-carousel-wrapper {
        max-width: 90%;
    }
}

/* ============================================
   DARK MODE SUPPORT
   ============================================ */

@media (prefers-color-scheme: dark) {
    .chatbot-messages {
        background: #1a1a2e;
    }

    .chatbot-message-bot .chatbot-bubble {
        background: #2d2d44;
        color: #e0e0e0;
    }

    .chatbot-menu-btn {
        background: #2d2d44;
        border-color: #3d3d54;
        color: #e0e0e0;
    }

    .chatbot-menu-btn:hover:not(:disabled) {
        background: #3d3d54;
        border-color: var(--button-border-color, #0055aa);
    }

    .chatbot-card {
        background: #2d2d44;
    }

    .chatbot-card-title {
        color: #e0e0e0;
    }

    .chatbot-card-desc {
        color: #a0a0b0;
    }

    .chatbot-carousel-controls {
        background: #2d2d44;
        border-top-color: #3d3d54;
    }

    .chatbot-carousel-prev,
    .chatbot-carousel-next {
        background: #3d3d54;
        border-color: #4d4d64;
        color: #e0e0e0;
    }

    .chatbot-carousel-dot {
        background: #4d4d64;
    }

    .chatbot-carousel-dot.active {
        background: #0055aa;
    }

    .chatbot-input-container {
        background: #1a1a2e;
        border-top-color: #3d3d54;
    }

    .chatbot-input {
        background: #2d2d44;
        border-color: #3d3d54;
        color: #e0e0e0;
    }

    .chatbot-input::placeholder {
        color: #707080;
    }

    .chatbot-sources {
        background: #2d2d44;
    }

    .chatbot-sources-title {
        color: #a0a0b0;
    }

    .chatbot-source-link {
        color: #66aaff;
    }
}

/* ============================================
   RTL SUPPORT (Arabic)
   ============================================ */

.chatbot-widget[dir="rtl"] .chatbot-message-user {
    align-self: flex-start;
}

.chatbot-widget[dir="rtl"] .chatbot-message-bot {
    align-self: flex-end;
}

.chatbot-widget[dir="rtl"] .chatbot-message-user .chatbot-bubble {
    border-bottom-right-radius: 16px;
    border-bottom-left-radius: 4px;
}

.chatbot-widget[dir="rtl"] .chatbot-message-bot .chatbot-bubble {
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 4px;
}

.chatbot-widget[dir="rtl"] .chatbot-menu-btn {
    text-align: right;
}

.chatbot-widget[dir="rtl"] .chatbot-bubble {
    direction: rtl;
}