/* ChatFlow Widget Styles */

/* Main Container */
.chatflow-widget {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #f5f5f5;
    position: relative;
    overflow: hidden;
}

/* Messages Container */
.chatflow-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Hide scrollbar but keep functionality */
.chatflow-messages::-webkit-scrollbar {
    width: 6px;
}

.chatflow-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

.chatflow-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.chatflow-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Message Styles */
.chatflow-message {
    display: flex;
    margin-bottom: 16px;
    animation: slideUp 0.3s ease-out;
    opacity: 0;
    animation-fill-mode: forwards;
}

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

.chatflow-message.bot {
    justify-content: flex-start;
}

.chatflow-message.user {
    justify-content: flex-end;
}

/* Message Bubble */
.message-bubble {
    max-width: 70%;
    min-width: 120px;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

/* Bot message bubble - Fixed for RTL and mobile */
.chatflow-message.bot .message-bubble {
    background: #f0f0f0;
    color: #333;
    border-bottom-left-radius: 4px;
    width: fit-content;
    display: inline-block;
    min-width: 120px;
    /* Remove problematic styles */
    word-break: break-word; /* Changed from keep-all */
    white-space: normal; /* Changed from nowrap */
    max-width: 70%; /* Consistent max-width */
}

/* RTL Support for bot messages */
[dir="rtl"] .chatflow-message.bot .message-bubble,
.rtl .chatflow-message.bot .message-bubble {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 4px;
}

.chatflow-message.user .message-bubble {
    background: #007cba;
    color: white;
    border-bottom-right-radius: 4px;
}

/* RTL Support for user messages */
[dir="rtl"] .chatflow-message.user .message-bubble,
.rtl .chatflow-message.user .message-bubble {
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 4px;
}

/* Bot message with avatar */
.chatflow-message.bot.has-avatar {
    align-items: flex-start;
}

.chatflow-message.bot.has-avatar .message-content {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.chatflow-message.bot.has-avatar.avatar-right .message-content {
    flex-direction: row-reverse;
}

/* Avatar styles */
.chatflow-avatar {
    flex-shrink: 0;
}

.chatflow-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* Message bubble adjustments for avatar - Fixed */
.chatflow-message.bot.has-avatar .message-bubble {
    max-width: calc(70% - 50px); /* Adjusted calculation */
    white-space: normal; /* Ensure text wraps */
}

/* Support for HTML in welcome message */
.message-bubble p {
    margin: 0 0 0.5em 0;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

.message-bubble strong {
    font-weight: 600;
}

.message-bubble em {
    font-style: italic;
}

/* Emoji support */
.message-bubble .emoji {
    font-size: 1.2em;
    line-height: 1;
}

/* Line breaks */
.message-bubble br {
    display: block;
    content: "";
    margin-top: 0.5em;
}

/* Message with options - new container */
.chatflow-message-group {
    margin-bottom: 16px;
}

/* Options Container - Fixed for better visibility */
.chatflow-message-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    margin-bottom: 16px; /* Increased bottom margin */
    margin-left: 0;
    padding-left: 0;
    padding-bottom: 8px; /* Added padding for better scroll visibility */
}

/* RTL Support for options */
[dir="rtl"] .chatflow-message-options,
.rtl .chatflow-message-options {
    margin-right: 0;
    padding-right: 0;
}

/* Update option buttons for inline display */
.chatflow-message-options .chatflow-option-button {
    padding: 8px 16px;
    border: 2px solid #e0e0e0;
    background: white;
    color: #333;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
    outline: none;
    white-space: nowrap;
    /* Ensure buttons are always fully visible */
    margin-bottom: 4px;
}

.chatflow-message-options .chatflow-option-button:hover {
    background: #007cba;
    color: white;
    border-color: #007cba;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 124, 186, 0.2);
}

.chatflow-message-options .chatflow-option-button:active {
    transform: translateY(0);
}

.chatflow-message-options .chatflow-option-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Typing Indicator */
.chatflow-typing-indicator {
    display: flex;
    padding: 0 20px;
    margin-bottom: 16px;
}

/* RTL Support for typing indicator */
[dir="rtl"] .chatflow-typing-indicator,
.rtl .chatflow-typing-indicator {
    justify-content: flex-start;
}

.typing-dots {
    display: flex;
    align-items: center;
    background: #f0f0f0;
    padding: 12px 16px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}

/* RTL Support for typing dots */
[dir="rtl"] .typing-dots,
.rtl .typing-dots {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 4px;
}

.typing-dots span {
    height: 8px;
    width: 8px;
    background: #999;
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    animation: typing 1.4s infinite;
}

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

.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;
    }
}

/* Input Area - now only for text inputs */
.chatflow-input-area {
    padding: 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: none;
}

.chatflow-input-area.active {
    display: block;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

/* Text input container with inline submit button */
.chatflow-text-input-wrapper {
    position: relative;
}

.chatflow-text-input-container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Update text input to work with inline button */
.chatflow-text-input {
    flex: 1;
    padding: 12px 50px 12px 16px; /* Add padding for button */
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s ease;
}

/* RTL support for input */
[dir="rtl"] .chatflow-text-input,
.rtl .chatflow-text-input {
    padding: 12px 16px 12px 50px;
    text-align: right;
    direction: rtl;
}

.chatflow-text-input:focus {
    border-color: #007cba;
}

.chatflow-text-input.error {
    border-color: #dc3545;
}

/* Inline submit button */
.chatflow-submit-button {
    position: absolute;
    right: 4px;
    width: 40px;
    height: 40px;
    padding: 0;
    background: #007cba;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.chatflow-submit-button:hover {
    background: #005a8b;
    transform: scale(1.1);
}

.chatflow-submit-button:active {
    transform: scale(0.95);
}

.chatflow-submit-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Icon inside submit button */
.chatflow-submit-button i,
.chatflow-submit-button svg,
.chatflow-submit-button img {
    width: 15px;
    height: 15px;
    font-size: 15px;
    line-height: 0.7;
    display: block;
}

/* Fix for Elementor icons */
.chatflow-submit-button .eicon {
    font-size: 20px;
    width: auto;
    height: auto;
}

/* Positioning fix for RTL */
[dir="rtl"] .chatflow-submit-button,
.rtl .chatflow-submit-button {
    right: auto;
    left: 4px;
}

/* Fix for large icons appearing outside container */
.chatflow-widget * {
    box-sizing: border-box;
}

/* Ensure icons stay within bounds */
.chatflow-widget i[class*="fa-"],
.chatflow-widget i[class*="eicon-"] {
    max-width: 100%;
    max-height: 100%;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip link for accessibility */
.chatflow-skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #000;
    color: #fff;
    padding: 8px;
    z-index: 100;
    text-decoration: none;
}

.chatflow-skip-link:focus {
    top: 0;
}

/* Error Message */
.chatflow-error-message {
    color: #dc3545;
    font-size: 12px;
    margin-top: 5px;
    padding: 0 16px;
}

/* RTL Support for error message */
[dir="rtl"] .chatflow-error-message,
.rtl .chatflow-error-message {
    text-align: right;
}

/* Loading State */
.chatflow-loading {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

/* RTL Support for loading */
[dir="rtl"] .chatflow-loading,
.rtl .chatflow-loading {
    margin-left: 0;
    margin-right: 8px;
}

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

/* Mobile Responsiveness - Enhanced */
@media (max-width: 768px) {
    .chatflow-widget {
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    .chatflow-messages {
        padding: 15px;
        /* Better padding for mobile */
        padding-bottom: 20px;
    }
    
    .message-bubble {
        max-width: 85%;
        font-size: 14px;
        /* Better text wrapping */
        word-break: break-word;
        hyphens: auto;
    }
    
    /* Fix bot message width on mobile */
    .chatflow-message.bot .message-bubble {
        max-width: 85%;
        white-space: normal;
    }
    
    /* Fix avatar message width */
    .chatflow-message.bot.has-avatar .message-bubble {
        max-width: calc(85% - 50px);
    }
    
    .chatflow-message-options {
        gap: 6px;
        /* Ensure options are visible */
        padding-bottom: 10px;
        margin-bottom: 20px;
    }
    
    .chatflow-message-options .chatflow-option-button {
        font-size: 13px;
        padding: 8px 12px;
        /* Ensure minimum touch target */
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .chatflow-input-area {
        padding: 15px;
    }
    
    .chatflow-text-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* iOS Specific Fixes */
@supports (-webkit-touch-callout: none) {
    .chatflow-widget {
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    .chatflow-messages {
        -webkit-overflow-scrolling: touch;
        /* Add safe area padding for notch */
        padding-bottom: env(safe-area-inset-bottom, 20px);
    }
    
    .chatflow-text-input {
        font-size: 16px; /* Prevents zoom on iOS */
        -webkit-appearance: none;
    }
}

/* Editor Preview Styles */
.chatflow-editor-preview .chatflow-editor-notice {
    text-align: center;
    padding: 20px;
    color: #666;
    font-style: italic;
    background: #f9f9f9;
    border-radius: 8px;
    margin: 10px;
}

/* Smooth Scroll for Message Container */
.chatflow-messages.smooth-scroll {
    scroll-behavior: smooth;
}

/* Accessibility */
.chatflow-widget:focus-within .chatflow-option-button:focus,
.chatflow-widget:focus-within .chatflow-text-input:focus,
.chatflow-widget:focus-within .chatflow-submit-button:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .chatflow-input-area,
    .chatflow-typing-indicator {
        display: none !important;
    }
    
    .chatflow-messages {
        overflow: visible;
        height: auto;
    }
}

/* Welcome message specific styling - Fixed for mobile */
.chatflow-message.welcome-message .message-bubble {
    min-width: 60%; /* Reduced from 80% */
    white-space: normal; /* Ensure text wraps */
}
.chatflow-message.welcome-message .message-bubble li {
  list-style: none !important;
  padding: 0;
  margin: 0;
}
.chatflow-message.welcome-message .message-bubble li {
  position: relative;
  right: 0;
  padding-right: 25px;
  margin-bottom: 0.7em;
  font-size: 1em; /* אפשר להתאים */
  line-height: 1.6;
}
.chatflow-message.welcome-message .message-bubble li::before {
  content: '✔';
  color: #AC7F64;
  font-weight: bold;
  position: absolute;
  right: 0;
  top: 0.1em;
}

@media (max-width: 768px) {
    .chatflow-message.welcome-message .message-bubble {
        min-width: auto; /* Let it size naturally */
        max-width: 85%; /* Consistent with other messages */
        white-space: normal;
    }
}

/* Additional RTL fixes for message alignment */
[dir="rtl"] .chatflow-message.bot,
.rtl .chatflow-message.bot {
    justify-content: flex-start;
}

[dir="rtl"] .chatflow-message.user,
.rtl .chatflow-message.user {
    justify-content: flex-end;
}

/* Ensure proper text direction in messages */
[dir="rtl"] .message-bubble,
.rtl .message-bubble {
    text-align: right;
    direction: rtl;
}

/* Fix for message group spacing */
.chatflow-message-group + .chatflow-message-group {
    margin-top: 8px;
}

/* Ensure messages don't overflow container */
.chatflow-messages {
    overflow-x: hidden;
    overflow-y: auto;
}

/* Better spacing for last message */
.chatflow-messages > *:last-child {
    margin-bottom: 20px;
}

/* Privacy Consent Styles */
.chatflow-privacy-options {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin: 15px 20px;
}

/* Privacy Agree Button - Default green style */
.chatflow-privacy-agree-btn {
    background-color: #28a745 !important;
    color: #ffffff !important;
    border: none;
    font-weight: 500;
}

.chatflow-privacy-agree-btn:hover:not(:disabled) {
    background-color: #218838 !important;
    transform: translateY(-2px);
}

/* Privacy Disagree Button - Subtle gray style */
.chatflow-privacy-disagree-btn {
    background-color: #f8f9fa !important;
    color: #6c757d !important;
    border: 1px solid #dee2e6;
}

.chatflow-privacy-disagree-btn:hover:not(:disabled) {
    background-color: #e2e6ea !important;
    border-color: #adb5bd;
}

/* Privacy Version Display */
.chatflow-privacy-version {
    display: inline-block;
    font-size: 0.9em;
    color: #666;
    font-weight: 500;
    padding: 2px 8px;
    background: rgba(0, 123, 255, 0.1);
    border-radius: 4px;
    margin: 4px 0;
}

/* Privacy notice below start button */
.chatflow-privacy-notice {
    font-size: 12px;
    color: #666;
    text-align: center;
    margin-top: 10px;
    padding: 0 20px;
    line-height: 1.4;
    opacity: 0.9;
}

/* Links in consent messages */
.message-bubble a {
    color: #007bff;
    text-decoration: underline;
    font-weight: 500;
}

.message-bubble a:hover {
    color: #0056b3;
    text-decoration: none;
}

/* RTL support for privacy options */
[dir="rtl"] .chatflow-privacy-options,
.rtl .chatflow-privacy-options {
    flex-direction: row-reverse;
}

/* Mobile responsive privacy buttons */
@media (max-width: 480px) {
    .chatflow-privacy-options {
        flex-direction: column;
        gap: 8px;
    }
    
    .chatflow-privacy-agree-btn,
    .chatflow-privacy-disagree-btn {
        width: 100%;
        padding: 12px 20px;
    }
}