/* ZATCA AI Chat Widget Styles */

:root {
    --chat-primary: #6647EE;
    --chat-primary-dark: #4A36B2;
    --chat-secondary: #00C9B1;
    --chat-accent: #FF6B35;
    --chat-dark: #1A1D29;
    --chat-light: #F8F9FC;
    --chat-gray: #6C757D;
    --chat-border: #E5E7EB;
    --chat-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    --chat-border-radius: 12px;
    --chat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --chat-typing-speed: 30;
}

/* Chat Button */
.zatca-chat-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9998;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: var(--chat-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
    color: white;
    font-size: 24px;
}

.zatca-chat-button:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 15px 40px rgba(102, 71, 238, 0.3);
}

.zatca-chat-button.active {
    background: linear-gradient(135deg, var(--chat-accent), #ff8c42);
}

/* Notification Badge */
.zatca-chat-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--chat-accent);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Chat Widget Container */
.zatca-chat-widget {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 420px;
    height: 600px;
    background: white;
    border-radius: var(--chat-border-radius);
    box-shadow: var(--chat-shadow);
    z-index: 9999;
    transform: translateY(100%) scale(0.8);
    opacity: 0;
    transition: var(--chat-transition);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--chat-border);
}

.zatca-chat-widget.active {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Chat Header */
.zatca-chat-header {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.zatca-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.zatca-chat-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.zatca-chat-title {
    font-weight: 600;
    font-size: 16px;
    margin: 0;
}

.zatca-chat-subtitle {
    font-size: 12px;
    opacity: 0.9;
    margin: 0;
}

.zatca-chat-actions {
    display: flex;
    gap: 8px;
}

.zatca-chat-action-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--chat-transition);
}

.zatca-chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Chat Body */
.zatca-chat-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Chat History Sidebar */
.zatca-chat-sidebar {
    width: 140px;
    background: #f8f9fa;
    border-right: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    transition: var(--chat-transition);
}

.zatca-chat-sidebar.hidden {
    width: 0;
    overflow: hidden;
}

.zatca-chat-sidebar-header {
    padding: 12px;
    border-bottom: 1px solid var(--chat-border);
}

.zatca-new-chat-btn {
    width: 100%;
    padding: 8px 12px;
    background: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: var(--chat-transition);
}

.zatca-new-chat-btn:hover {
    background: var(--chat-primary-dark);
    transform: translateY(-1px);
}

.zatca-chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.zatca-chat-history-item {
    padding: 8px;
    margin-bottom: 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--chat-transition);
    border: 1px solid transparent;
}

.zatca-chat-history-item:hover {
    background: rgba(102, 71, 238, 0.1);
    border-color: rgba(102, 71, 238, 0.2);
}

.zatca-chat-history-item.active {
    background: rgba(102, 71, 238, 0.15);
    border-color: var(--chat-primary);
}

.zatca-history-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--chat-dark);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.zatca-history-preview {
    font-size: 10px;
    color: var(--chat-gray);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.zatca-history-time {
    font-size: 9px;
    color: var(--chat-gray);
    margin-top: 2px;
}

/* Chat Messages Area */
.zatca-chat-messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.zatca-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
}

/* Welcome Message */
.zatca-chat-welcome {
    text-align: center;
    padding: 40px 20px;
    color: var(--chat-gray);
}

.zatca-welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
    color: var(--chat-primary);
}

.zatca-welcome-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--chat-dark);
    margin-bottom: 8px;
}

.zatca-welcome-text {
    font-size: 14px;
    line-height: 1.5;
}

/* Chat Message */
.zatca-chat-message {
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    animation: message-slide-in 0.3s ease-out;
}

@keyframes message-slide-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.zatca-chat-message.user {
    flex-direction: row-reverse;
}

.zatca-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.zatca-message-avatar.user {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: white;
}

.zatca-message-avatar.assistant {
    background: linear-gradient(135deg, var(--chat-secondary), #00a693);
    color: white;
}

.zatca-message-content {
    max-width: 80%;
    background: #f1f3f4;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
}

.zatca-chat-message.user .zatca-message-content {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: white;
}

/* Message text improvements for RTL/LTR support */
.zatca-message-text {
    margin: 0;
    line-height: 1.4;
    font-size: 14px;
    word-wrap: break-word;
    white-space: pre-wrap; /* Preserve whitespace and wrap text */
    unicode-bidi: embed; /* Support proper bidirectional text */
}

.zatca-message-text strong {
    font-weight: 600;
}

.zatca-message-text em {
    font-style: italic;
}

.zatca-message-text a {
    color: inherit;
    text-decoration: underline;
    transition: var(--chat-transition);
}

.zatca-message-text a:hover {
    opacity: 0.8;
}

.zatca-chat-message.user .zatca-message-text a {
    color: rgba(255, 255, 255, 0.9);
}

.zatca-message-text code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

.zatca-message-text p {
    margin: 0 0 8px 0;
}

.zatca-message-text p:last-child {
    margin-bottom: 0;
}

/* Ensure proper spacing for multi-line messages */
.zatca-message-text br {
    line-height: 1.6;
}

/* List item styling */
.zatca-message-text div[style*="padding-left: 16px"] {
    line-height: 1.5;
}

/* Improve readability for user messages with formatted content */
.zatca-chat-message.user .zatca-message-text div[style*="color: var(--chat-primary)"] span {
    color: rgba(255, 255, 255, 0.9) !important;
}

/* Adjust code blocks in user messages */
.zatca-chat-message.user .zatca-message-text code {
    background: rgba(255, 255, 255, 0.2) !important;
}

/* RTL support for Arabic messages */
.zatca-message-text[dir="rtl"] {
    text-align: right;
    direction: rtl;
}

.zatca-message-text[dir="ltr"] {
    text-align: left;
    direction: ltr;
}

/* RTL support for message time */
.zatca-message-time[style*="text-align: right"] {
    text-align: right !important;
}

.zatca-message-time[style*="text-align: left"] {
    text-align: left !important;
}

/* Ensure proper RTL layout for Arabic content */
.zatca-chat-message .zatca-message-content {
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* Arabic font support - use system fonts that support Arabic */
.zatca-message-text {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Noto Sans Arabic', 'Helvetica Neue', Arial, sans-serif;
}

/* Better spacing for RTL lists */
.zatca-message-text[style*="direction: rtl"] div[style*="padding-left: 16px"] {
    padding-left: 0;
    padding-right: 16px;
    text-align: right;
}

.zatca-message-text[style*="direction: rtl"] div[style*="padding-left: 16px"] span {
    left: auto;
    right: 0;
}

/* Typing Indicator */
.zatca-typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
}

.zatca-typing-dots {
    display: flex;
    gap: 4px;
}

.zatca-typing-dot {
    width: 6px;
    height: 6px;
    background: var(--chat-gray);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.zatca-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.zatca-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Chat Input */
.zatca-chat-input {
    padding: 16px 20px;
    border-top: 1px solid var(--chat-border);
    background: white;
}

.zatca-input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f8f9fa;
    border-radius: 24px;
    padding: 8px 12px;
    border: 2px solid transparent;
    transition: var(--chat-transition);
}

.zatca-input-container:focus-within {
    border-color: var(--chat-primary);
    background: white;
}

.zatca-message-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-size: 14px;
    line-height: 1.4;
    max-height: 100px;
    min-height: 20px;
    font-family: inherit;
}

.zatca-send-btn {
    background: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--chat-transition);
    flex-shrink: 0;
}

.zatca-send-btn:hover:not(:disabled) {
    background: var(--chat-primary-dark);
    transform: scale(1.05);
}

.zatca-send-btn:disabled {
    background: var(--chat-gray);
    cursor: not-allowed;
    transform: none;
}

/* Quick Actions */
.zatca-quick-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.zatca-quick-action {
    background: white;
    border: 1px solid var(--chat-border);
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: var(--chat-transition);
    color: var(--chat-dark);
}

.zatca-quick-action:hover {
    border-color: var(--chat-primary);
    background: rgba(102, 71, 238, 0.05);
    transform: translateY(-1px);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .zatca-chat-widget {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        border-radius: 0;
        position: fixed;
        z-index: 9999;
    }
    
    .zatca-chat-button {
        bottom: 16px;
        right: 16px;
    }
    
    /* Mobile Header - Ensure it stays visible */
    .zatca-chat-header {
        position: relative;
        z-index: 10001;
        padding: 12px 16px;
        min-height: 60px;
        flex-shrink: 0;
    }
    
    .zatca-chat-avatar {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
    
    .zatca-chat-title {
        font-size: 15px;
    }
    
    .zatca-chat-subtitle {
        font-size: 11px;
    }
    
    .zatca-chat-action-btn {
        width: 40px;
        height: 40px;
        border-radius: 6px;
    }
    
    /* Ensure buttons are always visible and touchable on mobile */
    .zatca-chat-actions {
        gap: 6px;
        min-width: 90px;
    }
    
    /* Mobile Body */
    .zatca-chat-body {
        height: calc(100vh - 60px);
        flex: 1;
        display: flex;
        overflow: hidden;
    }
    
    /* Mobile Sidebar */
    .zatca-chat-sidebar {
        position: absolute;
        top: 0;
        left: -100%;
        height: 100%;
        z-index: 10;
        background: white;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        width: 85%;
        max-width: 320px;
        transition: left 0.3s ease;
    }
    
    .zatca-chat-sidebar.mobile-open {
        left: 0;
    }
    
    .zatca-chat-sidebar.hidden {
        width: 85%;
        left: -100%;
    }
    
    /* Mobile Messages Container */
    .zatca-chat-messages-container {
        flex: 1;
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    
    /* Mobile Messages */
    .zatca-chat-messages {
        flex: 1;
        padding: 12px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Mobile Input */
    .zatca-chat-input {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        background: white;
        border-top: 1px solid var(--chat-border);
        flex-shrink: 0;
    }
    
    .zatca-input-container {
        padding: 8px 12px;
    }
    
    .zatca-message-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .zatca-send-btn {
        width: 32px;
        height: 32px;
    }
    
    /* Mobile Messages */
    .zatca-message-content {
        max-width: 85%;
    }
    
    /* Mobile Overlay */
    .zatca-mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .zatca-mobile-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

@media (max-width: 480px) {
    .zatca-chat-widget {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        border-radius: 0;
    }
    
    .zatca-chat-header {
        padding: 10px 12px;
        min-height: 56px;
    }
    
    .zatca-chat-body {
        height: calc(100vh - 56px);
    }
    
    .zatca-chat-messages {
        padding: 8px;
    }
    
    .zatca-chat-input {
        padding: 8px 12px;
    }
}

/* Scrollbar Styling */
.zatca-chat-messages::-webkit-scrollbar,
.zatca-chat-history::-webkit-scrollbar {
    width: 6px;
}

.zatca-chat-messages::-webkit-scrollbar-track,
.zatca-chat-history::-webkit-scrollbar-track {
    background: transparent;
}

.zatca-chat-messages::-webkit-scrollbar-thumb,
.zatca-chat-history::-webkit-scrollbar-thumb {
    background: rgba(102, 71, 238, 0.3);
    border-radius: 3px;
}

.zatca-chat-messages::-webkit-scrollbar-thumb:hover,
.zatca-chat-history::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 71, 238, 0.5);
}

/* Loading Animation */
.zatca-loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error State */
.zatca-error-message {
    background: #fee;
    color: #c53030;
    padding: 12px;
    border-radius: var(--chat-border-radius);
    margin: 8px 0;
    font-size: 13px;
    border: 1px solid #feb2b2;
}

/* Success State */
.zatca-success-message {
    background: #f0fff4;
    color: #2d7d32;
    padding: 12px;
    border-radius: var(--chat-border-radius);
    margin: 8px 0;
    font-size: 13px;
    border: 1px solid #c6f6d5;
}

/* Animations */
@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slide-up {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.zatca-fade-in {
    animation: fade-in 0.3s ease-out;
}

.zatca-slide-up {
    animation: slide-up 0.3s ease-out;
}

/* Utility Classes */
.zatca-hidden {
    display: none !important;
}

.zatca-invisible {
    visibility: hidden;
    opacity: 0;
}

.zatca-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;
}

/* RTL Support */
[dir="rtl"] .zatca-chat-widget {
    right: auto;
    left: 24px;
}

[dir="rtl"] .zatca-chat-button {
    right: auto;
    left: 24px;
}

[dir="rtl"] .zatca-chat-message.user {
    flex-direction: row;
}

[dir="rtl"] .zatca-chat-message:not(.user) {
    flex-direction: row-reverse;
}

[dir="rtl"] .zatca-chat-sidebar {
    border-right: none;
    border-left: 1px solid var(--chat-border);
}