/* Chat Widget Styles - Docked Left Panel Design */
:root {
    --font-headings: var(--font-family-arabic, 'Cairo', sans-serif);
    --font-content: var(--font-family-arabic, 'Cairo', sans-serif);
    --chat-panel-width: var(--chatbot-panel-width, 360px);
    --chat-collapsed-width: 50px;
}

/* ===== Docked Chat Panel (Left by default for RTL, Right for LTR) ===== */
.chat-panel {
    position: fixed;
    left: 0;
    /* Default to left side for RTL books */
    top: 120px;
    /* Fixed position below header - will be adjusted by JS if needed */
    height: calc(100vh - 120px);
    width: var(--chat-panel-width);
    background: var(--bg-color, #ffffff);
    border-inline-end: 1px solid var(--border-color, #e0e0e0);
    display: flex !important;
    /* Force display */
    flex-direction: column;
    z-index: 900;
    /* Below header (1000) but above content (100) */
    transition: width 0.3s ease, transform 0.3s ease, top 0.3s ease;
    /* Add top transition */
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.05);
}

/* Chat Panel Left Position (explicit, same as default for RTL) */
.chat-panel.position-left {
    right: auto;
    left: 0;
    border-inline-start: none;
    border-inline-end: 1px solid var(--border-color, #e0e0e0);
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.05);
}

/* Chat Panel Right Position (for LTR books) */
.chat-panel.position-right {
    right: 0;
    left: auto;
    border-inline-end: none;
    border-inline-start: 1px solid var(--border-color, #e0e0e0);
    box-shadow: -2px 0 15px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .chat-panel {
    background: #1a1a1a;
    border-color: rgba(255, 255, 255, 0.1);
}

/* Collapsed State - Vertical Bar with Toggle */
.chat-panel.collapsed {
    width: var(--chat-collapsed-width);
}

.chat-panel.collapsed .chat-header,
.chat-panel.collapsed .chat-body-container,
.chat-panel.collapsed .chat-input-area,
.chat-panel.collapsed .chat-window-controls {
    /* Hide Controls Row too */
    display: none;
}

.chat-panel.collapsed .chat-collapse-bar {
    display: flex !important;
}

/* Collapse Bar (visible when collapsed) */
.chat-collapse-bar {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    /* Space between Title and Bottom Button */
    height: 100%;
    /* remove cursor: pointer since we have a button now? Or keep it as big click target? */
    /* Let's keep specific button for action to be clear */
    background: linear-gradient(180deg, var(--chatbot-primary-color, #f39c12), var(--chatbot-secondary-color, #d35400));
    color: white;
    padding: 20px 0;
    -webkit-user-select: none;
    user-select: none;
    overflow: hidden;
    width: 100%;
    /* Ensure it fills the 50px panel */
    z-index: 10001;
    /* Force top */
    /* writing-mode removed to debug visibility */
}

/* Title Container */
.chat-collapse-bar-title {
    white-space: nowrap;
    font-weight: 600;
    font-size: 1.1em;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* Arabic text: vertical, top-to-bottom, right-to-left characters */
.chat-collapse-bar-title .text-direction-arabic {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
}

/* Latin text: vertical, top-to-bottom (A at top, k at bottom) */
.chat-collapse-bar-title .text-direction-latin {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(0deg);
}

/* Bottom Toggle Button in Bar */
.chat-expand-btn {
    background: rgba(0, 0, 0, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 10px;
    transition: background 0.2s;
}

.chat-expand-btn:hover {
    background: rgba(0, 0, 0, 0.4);
}

.chat-collapse-bar:hover {
    background: linear-gradient(180deg, var(--chatbot-secondary-color, #e67e22), var(--chatbot-primary-color, #c0392b));
}

/* 1. Remove chat icon as requested */
.chat-collapse-bar .collapse-icon {
    display: none;
}

/* 2. Text styling for Arabic (Up-to-Down reading) */
/* By default vertical-rl runs Top-to-Bottom.  */
/* But the orientation of characters might need adjustment. */
.chat-collapse-bar span {
    /* Ensure nice letter spacing */
    letter-spacing: 2px;
}

/* Helper for direction - handled in .chat-collapse-bar-title */
.text-direction-arabic {
    display: inline-block;
}

.text-direction-latin {
    display: inline-block;
}

/* Maximized State - Fullscreen Overlay */
.chat-panel.maximized {
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    z-index: 10000 !important;
    /* Above everything */
}

/* Hide collapse bar when maximized */
.chat-panel.maximized .chat-collapse-bar {
    display: none !important;
}

/* Hide old floating launcher */
.chat-launcher {
    display: none !important;
}

/* Window Controls Row - X left, drag handle center, maximize right */
.chat-window-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0;
    background: rgba(0, 0, 0, 0.4);
    padding: 6px 8px;
    /* Added padding for breathing room */
    direction: ltr;
    position: relative;
    min-height: 44px;
    /* Industry-standard touch target height */
}

/* Drag handle in center - more prominent */
.chat-window-controls::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 5px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 3px;
    pointer-events: none;
}

/* Close button styling - Match maximize button */
.chat-close-btn {
    background: transparent !important;
}

.chat-close-btn:hover {
    background: #2f4356 !important;
}

/* Right-side panel: controls stay same order (maximize left, close right) */
.chat-panel.position-right .chat-window-controls {
    justify-content: space-between;
}

/* Window control buttons - 44x44px touch targets (Apple HIG standard) */
.chat-win-btn {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    border-radius: 8px;
}

.chat-win-btn svg {
    width: 20px;
    height: 20px;
}

.chat-win-btn:hover {
    background: #2f4356;
}

/* Header - Compact layout with stars inline */
.chat-header {
    padding: 12px 5px 12px 16px;
    background: var(--chatbot-header-bg, linear-gradient(135deg, #f39c12, #d35400));
    color: white;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 10;
    min-height: 60px;
    overflow: visible;
}

/* Title with stars inline */
.chat-title {
    font-family: var(--font-headings, 'Cairo', sans-serif);
    font-weight: 700;
    font-size: 1.1em;
    flex-shrink: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Stars inline with title */
.chat-title::before {
    content: '✨';
    display: inline-block;
    font-size: 1.1em;
    line-height: 1;
    flex-shrink: 0;
}

/* Action Buttons */
.chat-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow: visible;
    position: relative;
}

.chat-action-btn {
    width: 40px;
    height: 40px;
    padding: 10px;
    flex-shrink: 0;
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.chat-action-btn svg {
    width: 24px !important;
    height: 24px !important;
    min-width: 24px;
    min-height: 24px;
}

/* Font Size Controls */
.chat-font-size-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-inline-end: 6px;
    padding: 4px 8px;
    background: transparent;
    border: 1.5px solid rgba(255, 255, 255, 0.4);
    border-radius: 8px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-font-size-controls:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.6);
}

.chat-font-btn {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    width: auto;
    min-width: 20px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0 4px;
    line-height: 1;
}

.chat-font-btn:hover {
    transform: scale(1.15);
    opacity: 0.8;
}

.chat-font-letter {
    color: white;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font-headings, 'Cairo', sans-serif);
    user-select: none;
    padding: 0 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    line-height: 1;
}

/* Settings Dropdown */
.chat-settings-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--bg-color, #ffffff);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    padding: 4px 0;
    z-index: 99999 !important;
    display: none;
    min-width: 160px;
}

.chat-settings-dropdown.active {
    display: block !important;
}

.chat-settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-settings-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.chat-settings-item span {
    font-size: 14px;
    color: var(--text-color, #333);
    font-weight: 500;
}

.chat-settings-item svg {
    width: 18px;
    height: 18px;
    color: var(--text-color, #666);
}

/* Font controls in dropdown */
.chat-settings-item .chat-font-size-controls {
    border-color: var(--border-color, #ccc);
    margin: 0;
}

.chat-settings-dropdown .chat-font-btn {
    color: var(--text-color, #333);
}

.chat-settings-dropdown .chat-font-letter {
    color: var(--text-color, #333);
}

/* Extra compact for very narrow screens */
@media (max-width: 380px) {
    .chat-header {
        padding: 3px 4px !important;
        gap: 1px !important;
    }

    .chat-title {
        font-size: 0.75em !important;
        padding-left: 22px !important;
        max-width: 90px !important;
    }

    .chat-header::before {
        font-size: 1em !important;
        left: 4px !important;
    }

    .chat-action-btn {
        width: 22px !important;
        height: 22px !important;
    }

    .chat-action-btn svg {
        width: 11px !important;
        height: 11px !important;
    }

    .chat-font-size-controls {
        padding: 1px 2px !important;
    }

    .chat-font-btn {
        font-size: 12px !important;
        min-width: 12px !important;
        height: 18px !important;
    }

    .chat-font-letter {
        font-size: 10px !important;
        min-width: 10px !important;
    }
}

/* Tooltips for font size controls group */
.chat-font-size-controls[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 30, 30, 0.95);
    color: white;
    font-size: 11px;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 10010;
    font-family: var(--font-content, sans-serif);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

.chat-font-size-controls[data-tooltip]::before {
    content: '';
    position: absolute;
    top: calc(100% + 3px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: rgba(30, 30, 30, 0.95);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 10010;
}

.chat-font-size-controls:hover[data-tooltip]::after,
.chat-font-size-controls:hover[data-tooltip]::before {
    opacity: 1;
    visibility: visible;
}

.chat-action-btn {
    background: transparent;
    border: 1.5px solid rgba(255, 255, 255, 0.4);
    color: white;
    cursor: pointer;
    border-radius: 6px;
    width: 26px !important;
    height: 26px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: relative;
    flex-shrink: 0;
}

.chat-action-btn svg {
    width: 13px !important;
    height: 13px !important;
}

.chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.05);
}

/* CSS Tooltips - positioned below buttons */
.chat-action-btn[aria-label]::after {
    content: attr(aria-label);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 30, 30, 0.95);
    color: white;
    font-size: 11px;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 10010;
    font-family: var(--font-content, sans-serif);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

/* Tooltip arrow */
.chat-action-btn[aria-label]::before {
    content: '';
    position: absolute;
    top: calc(100% + 3px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: rgba(30, 30, 30, 0.95);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 10010;
}

.chat-action-btn:hover::after,
.chat-action-btn:hover::before {
    opacity: 1;
    visibility: visible;
}

/* Chat Body Container */
.chat-body-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-radius: 0 0 20px 20px;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    background: rgba(0, 0, 0, 0.02);
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

[data-theme="dark"] .chat-messages {
    background: rgba(255, 255, 255, 0.02);
}

/* Message Bubbles - Modern Wide Design */
.chat-message {
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 95%;
    /* Increased from 85% to use more space */
    font-size: 0.95em;
    line-height: 1.6;
    position: relative;
    font-family: var(--font-content, sans-serif);
    animation: messageIn 0.3s ease-out;
    margin-bottom: 8px;
    /* Slight separation */
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User Message - Right Side (RTL Start) */
.chat-message.user {
    background: linear-gradient(135deg, var(--chatbot-user-bubble-color, #f39c12), var(--chatbot-secondary-color, #e67e22));
    color: white;
    align-self: flex-start;
    /* In RTL flex-container this is Right */
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(243, 156, 18, 0.2);
    margin-left: auto;
    /* Push to right just in case */
    max-width: 90%;
}

/* Bot Message - Left Side (RTL End) / Full Width preference */
.chat-message.bot {
    background: var(--chatbot-bot-bubble-color, #ffffff);
    border: 1px solid rgba(0, 0, 0, 0.05);
    color: var(--text-color, #333);
    align-self: flex-end;
    /* In RTL this is Left */
    /* Make bot message nearly full width for reading comfort */
    width: 98%;
    max-width: 100%;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
}

/* Dark Mode Support */
[data-theme="dark"] .chat-message.bot {
    background: #2c3e50;
    border-color: rgba(255, 255, 255, 0.1);
    color: #ecf0f1;
}

[data-theme="dark"] .chat-window {
    background: #1a1a1a;
    border-color: rgba(255, 255, 255, 0.1);
}

/* Markdown Styling inside Bubbles */
.chat-message.bot strong {
    color: var(--chatbot-primary-color, #e67e22);
}

.chat-message.bot ul {
    margin: 8px 0;
    padding-right: 20px;
}

.chat-message.bot li {
    margin-bottom: 4px;
}

/* Input Area */
.chat-input-area {
    padding: 15px;
    background: var(--bg-color, #ffffff);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    border-radius: 0 0 20px 20px;
}

[data-theme="dark"] .chat-input-area {
    background: #1a1a1a;
    border-color: rgba(255, 255, 255, 0.1);
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 20px;
    resize: none;
    height: 44px;
    max-height: 100px;
    font-family: inherit;
    font-size: 0.95em;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: rgba(0, 0, 0, 0.02);
    overflow-y: auto;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

/* Hide scrollbar for Chrome/Safari */
.chat-input::-webkit-scrollbar {
    display: none;
}

[data-theme="dark"] .chat-input {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    color: white;
}

.chat-input:focus {
    border-color: var(--chatbot-primary-color, #f39c12);
    box-shadow: 0 0 0 3px rgba(243, 156, 18, 0.15);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chatbot-primary-color, #f39c12), var(--chatbot-secondary-color, #d35400));
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(243, 156, 18, 0.3);
}

.chat-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(243, 156, 18, 0.4);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: default;
    transform: none;
    box-shadow: none;
}

/* Typing Indicator */
.typing-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: currentColor;
    border-radius: 50%;
    margin: 0 2px;
    opacity: 0.4;
    animation: typing 1s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    50% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* History View Layer */
.history-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color, #ffffff);
    z-index: 10;
    flex-direction: column;
    display: none;
    animation: fadeIn 0.3s;
}

.history-view.active {
    display: flex;
}

[data-theme="dark"] .history-view {
    background: #1a1a1a;
}

.history-header {
    padding: 15px;
    font-weight: bold;
    color: var(--chatbot-primary-color, #f39c12);
    border-bottom: 2px solid rgba(0, 0, 0, 0.05);
    font-family: var(--font-headings, 'Cairo', sans-serif);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* History Items */
.history-item {
    padding: 12px;
    margin-bottom: 8px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
    border-right: 3px solid transparent;
}

[data-theme="dark"] .history-item {
    background: rgba(255, 255, 255, 0.05);
}

.history-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .history-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.history-item.current {
    background: rgba(243, 156, 18, 0.1);
    border-right-color: var(--chatbot-primary-color, #f39c12);
}

.history-date {
    font-size: 0.8em;
    color: #888;
    margin-bottom: 4px;
}

.history-preview {
    font-size: 0.95em;
    color: var(--text-color, #333);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

[data-theme="dark"] .history-preview {
    color: #ecf0f1;
}

.empty-history {
    text-align: center;
    padding: 40px 20px;
    color: #888;
    font-style: italic;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 20px);
        right: 10px;
        bottom: 80px;
        height: 70vh;
        border-radius: 16px;
    }

    .chat-window-controls {
        border-radius: 16px 16px 0 0;
    }

    .chat-body-container {
        border-radius: 0 0 16px 16px;
    }

    .chat-launcher {
        right: 15px;
        bottom: 15px;
        width: 54px;
        height: 54px;
    }

    /* Mobile maximized - nearly full screen with small margin */
    .chat-window.maximized {
        width: calc(100vw - 16px);
        height: calc(100vh - 16px);
        right: 50%;
        bottom: 8px;
        transform: translateX(50%) scale(1);
        border-radius: 12px;
    }

    .chat-window.maximized .chat-window-controls {
        border-radius: 12px 12px 0 0;
    }
}

/* Chatbot header and button contrast fix */
.chat-header {
    background: var(--chatbot-header-bg, linear-gradient(135deg, #2c3e50, #34495e)) !important;
}

.chat-send-btn {
    background: linear-gradient(135deg, var(--chatbot-primary-color, #f39c12), var(--chatbot-secondary-color, #d35400)) !important;
}

.chat-send-btn svg {
    transform: scaleX(-1) !important;
}

/* Flip expand arrow for proper direction */
/* Default (left panel LTR): arrow points right (>) to indicate "open" */
.chat-expand-btn svg {
    transform: scaleX(1);
}

/* RTL with left panel: arrow should ALSO point right (>) to indicate "open" - NO FLIP */
/* (The default scaleX(1) already shows right arrow, so no override needed) */

/* When panel is on right side (LTR): arrow points left (<) to indicate "open" */
.chat-panel.position-right .chat-expand-btn svg {
    transform: scaleX(1);
}

/* RTL with right panel: arrow points right (>) to indicate "open" */
[dir="rtl"] .chat-panel.position-right .chat-expand-btn svg {
    transform: scaleX(1);
}

/* Window controls bar styling */
.chat-window-controls {
    background: var(--chatbot-controls-bg, #f39c12) !important;
}

[data-theme="dark"] .chat-window-controls {
    background: var(--chatbot-controls-bg, #0d1117) !important;
}

/* Sepia Theme Support */
[data-theme="sepia"] .chat-panel {
    background: #f4ecd8;
    border-color: #d4c8b4;
}

[data-theme="sepia"] .chat-messages {
    background: #faf7f0;
}

[data-theme="sepia"] .chat-message.bot {
    background: #e8dcc8;
    border-color: #d4c8b4;
    color: #5c4b37;
}

[data-theme="sepia"] .chat-window {
    background: #f4ecd8;
    border-color: #d4c8b4;
}

[data-theme="sepia"] .chat-input-area {
    background: #f4ecd8;
    border-color: #d4c8b4;
}

[data-theme="sepia"] .chat-input {
    background: #faf7f0;
    border-color: #d4c8b4;
    color: #5c4b37;
}

[data-theme="sepia"] .history-view {
    background: #f4ecd8;
}

[data-theme="sepia"] .history-item {
    background: #e8dcc8;
}

[data-theme="sepia"] .history-item:hover {
    background: #ddd0b8;
}

[data-theme="sepia"] .history-preview {
    color: #5c4b37;
}

[data-theme="sepia"] .chat-window-controls {
    background: var(--chatbot-controls-bg, #8b6914) !important;
}

/* High Contrast Theme Support */
[data-theme="high-contrast"] .chat-panel {
    background: #000000;
    border-color: #ffffff;
    border-width: 2px;
}

[data-theme="high-contrast"] .chat-messages {
    background: #000000;
}

[data-theme="high-contrast"] .chat-message.bot {
    background: #1a1a1a;
    border-color: #ffffff;
    color: #ffffff;
}

[data-theme="high-contrast"] .chat-window {
    background: #000000;
    border-color: #ffffff;
}

[data-theme="high-contrast"] .chat-input-area {
    background: #000000;
    border-color: #ffffff;
}

[data-theme="high-contrast"] .chat-input {
    background: #1a1a1a;
    border-color: #ffffff;
    color: #ffffff;
}

[data-theme="high-contrast"] .history-view {
    background: #000000;
}

[data-theme="high-contrast"] .history-item {
    background: #1a1a1a;
    border: 1px solid #ffffff;
}

[data-theme="high-contrast"] .history-item:hover {
    background: #333333;
}

[data-theme="high-contrast"] .history-preview {
    color: #ffffff;
}

[data-theme="high-contrast"] .chat-window-controls {
    background: var(--chatbot-controls-bg, #00ff00) !important;
}


/* Registration Prompt Styles */
.chat-message.registration-wall {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 16px;
    margin: 10px;
}

.registration-prompt {
    text-align: center;
}

.prompt-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.prompt-message {
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 16px;
}

.prompt-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.prompt-btn {
    display: block;
    padding: 12px 20px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s;
}

.prompt-btn.primary {
    background: white;
    color: #764ba2;
}

.prompt-btn.primary:hover {
    background: #f0f0f0;
    transform: translateY(-2px);
}

.prompt-btn.secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.prompt-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Usage Warning */
.chat-usage-warning {
    text-align: center;
    padding: 8px 12px;
    margin: 5px 10px;
    background: #fff3cd;
    color: #856404;
    border-radius: 8px;
    font-size: 12px;
}

.chat-usage-warning small {
    display: block;
}


/* Clarify Modal Registration Prompt */
.clarify-registration-prompt {
    text-align: center;
    padding: 30px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    color: white;
}

.clarify-registration-prompt .prompt-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.clarify-registration-prompt .prompt-message {
    font-size: 15px;
    line-height: 1.7;
    margin-bottom: 20px;
}

.clarify-registration-prompt .prompt-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.clarify-registration-prompt .prompt-btn {
    display: block;
    padding: 12px 24px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s;
}

.clarify-registration-prompt .prompt-btn.primary {
    background: white;
    color: #764ba2;
}

.clarify-registration-prompt .prompt-btn.primary:hover {
    background: #f0f0f0;
    transform: translateY(-2px);
}

.clarify-registration-prompt .prompt-btn.secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.clarify-registration-prompt .prompt-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.3);
}


/* ========================================
   MOBILE RESPONSIVE CHATBOT STYLES
   ======================================== */

/* Tablet Breakpoint (768px - 1024px) */
@media (max-width: 1024px) {
    .chat-panel {
        width: 320px;
    }

    .chat-panel.collapsed {
        width: var(--chat-collapsed-width);
    }

    .chat-panel.maximized {
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: none !important;
    }
}

/* Mobile Breakpoint (below 860px) */
@media (max-width: 860px) {

    /* Mobile-specific header adjustments */
    .chat-header {
        padding: 10px 10px 10px 12px;
        gap: 12px;
        min-height: 56px;
    }

    /* Mobile-specific title - larger font, no wrap */
    .chat-title {
        font-size: 1.15em !important;
        line-height: 1 !important;
        white-space: nowrap !important;
        overflow: visible !important;
        text-overflow: clip !important;
        flex-shrink: 0 !important;
        flex-grow: 1 !important;
        max-width: none !important;
    }

    /* Mobile action buttons - slightly smaller */
    .chat-action-btn {
        width: 38px;
        height: 38px;
        padding: 9px;
    }

    .chat-action-btn svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* Hide desktop collapse arrow icon on mobile */
    .chat-win-btn.chat-close-btn svg {
        display: none !important;
    }

    /* Show X icon on mobile using CSS - smaller size */
    .chat-win-btn.chat-close-btn::before {
        content: '×';
        /* Use small multiplication sign instead of heavy X */
        font-size: 18px;
        font-weight: 300;
        line-height: 1;
    }

    /* Remove background from restore button when maximized */
    .chat-panel.maximized .chat-win-btn {
        background: transparent !important;
    }

    .chat-panel.maximized .chat-win-btn:hover {
        background: rgba(255, 255, 255, 0.1) !important;
    }

    /* Hide print button on narrow mobile screens to save space */
    #btn-print-chat {
        display: none !important;
    }

    /* Chat Panel - Transform to slide-up overlay */
    .chat-panel:not(.force-desktop) {
        position: fixed;
        left: 0 !important;
        right: 0 !important;
        bottom: 0;
        top: auto !important;
        width: 100% !important;
        height: 70vh;
        max-height: calc(100vh - var(--header-height, 70px) - 20px);
        border-radius: 20px 20px 0 0;
        border: none;
        border-top: 1px solid var(--border-color, #e0e0e0);
        box-shadow: 0 -5px 30px rgba(0, 0, 0, 0.2);
        transform: translateY(100%);
        transition: transform 0.3s ease, height 0.3s ease;
        z-index: 2000;
    }

    /* Right position override for mobile */
    .chat-panel.position-right:not(.force-desktop) {
        left: 0 !important;
        right: 0 !important;
    }

    /* Show chat panel when expanded (not collapsed) */
    .chat-panel:not(.collapsed):not(.force-desktop) {
        transform: translateY(0);
    }

    /* Collapsed state - show as floating button */
    .chat-panel.collapsed:not(.force-desktop) {
        width: 60px !important;
        height: 60px !important;
        top: auto !important;
        /* Override desktop top positioning */
        bottom: 20px;
        left: auto !important;
        right: 20px !important;
        border-radius: 50%;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
        transform: translateY(0);
        overflow: hidden;
    }

    /* RTL: Move FAB to left side */
    [dir="rtl"] .chat-panel.collapsed:not(.force-desktop) {
        right: auto !important;
        left: 20px !important;
    }

    /* Collapsed bar becomes circular FAB */
    .chat-panel.collapsed .chat-collapse-bar {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        padding: 0;
        justify-content: center;
        align-items: center;
    }

    .chat-panel.collapsed .chat-collapse-bar-title {
        display: none;
    }

    .chat-panel.collapsed .chat-expand-btn {
        width: 100%;
        height: 100%;
        margin: 0;
        background: transparent;
        border-radius: 50%;
    }

    .chat-panel.collapsed .chat-expand-btn svg {
        width: 28px;
        height: 28px;
        transform: none !important;
    }

    /* Replace arrow with chat icon on mobile FAB */
    .chat-panel.collapsed .chat-expand-btn svg {
        display: block !important;
        width: 28px;
        height: 28px;
    }

    /* Chat bubble SVG icon for mobile FAB */
    @media (max-width: 860px) {
        .chat-panel.collapsed .chat-expand-btn svg {
            /* Show SVG chat bubble icon */
        }
    }

    /* Maximized state on mobile - full screen */
    .chat-panel.maximized {
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        transform: translateY(0) !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* Ensure body container doesn't overflow in maximized state */
    .chat-panel.maximized .chat-body-container {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }

    /* Ensure messages area is scrollable */
    .chat-panel.maximized .chat-messages {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        min-height: 0 !important;
    }

    /* Ensure input area stays at bottom */
    .chat-panel.maximized .chat-input-area {
        flex: 0 0 auto !important;
        position: relative !important;
        bottom: 0 !important;
    }

    /* Window controls adjustments */
    .chat-window-controls {
        border-radius: 20px 20px 0 0;
        padding: 4px 8px;
    }

    .chat-panel.maximized .chat-window-controls {
        border-radius: 0;
    }

    /* Add drag handle indicator */
    .chat-window-controls::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
    }

    /* Header adjustments */
    .chat-header {
        padding: 10px 16px;
    }

    .chat-title {
        font-size: 1rem;
    }

    /* Messages area */
    .chat-messages {
        padding: 15px;
        gap: 12px;
    }

    .chat-message {
        max-width: 90%;
        font-size: 0.9em;
        padding: 10px 14px;
    }

    .chat-message.bot {
        width: 95%;
    }

    /* Input area */
    .chat-input-area {
        padding: 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        border-radius: 0;
    }

    .chat-input {
        padding: 10px 14px;
        font-size: 16px;
        /* Prevent iOS zoom */
    }

    .chat-send-btn {
        width: 40px;
        height: 40px;
    }

    /* History view */
    .history-header {
        padding: 12px;
    }

    .history-item {
        padding: 10px;
    }
}

/* Small Mobile (below 480px) */
@media (max-width: 480px) {
    .chat-panel {
        height: 80vh;
    }

    .chat-panel.collapsed {
        width: 56px !important;
        height: 56px !important;
        bottom: 16px;
        right: 16px !important;
    }

    [dir="rtl"] .chat-panel.collapsed {
        left: 16px !important;
    }

    .chat-panel.collapsed .chat-collapse-bar {
        width: 56px;
        height: 56px;
    }

    .chat-panel.collapsed .chat-expand-btn::before {
        font-size: 24px;
    }

    .chat-message {
        font-size: 0.85em;
        padding: 8px 12px;
    }

    .chat-input {
        padding: 8px 12px;
    }

    .chat-send-btn {
        width: 36px;
        height: 36px;
    }
}

/* Mobile Overlay Background */
@media (max-width: 860px) {
    .chat-panel-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1999;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .chat-panel-overlay.active {
        display: block;
        opacity: 1;
    }
}

/* Landscape Mobile */
@media (max-width: 860px) and (orientation: landscape) {
    .chat-panel {
        height: 90vh;
        max-height: calc(100vh - 20px);
    }

    .chat-panel.maximized {
        height: 100vh;
        max-height: 100vh;
    }
}

/* Safe area support for notched devices */
@supports (padding: max(0px)) {
    @media (max-width: 860px) {
        .chat-input-area {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }

        .chat-panel.collapsed {
            bottom: max(20px, calc(env(safe-area-inset-bottom) + 10px));
        }
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .chat-panel {
        transition: none;
    }

    .chat-message {
        animation: none;
    }
}

/* ===== Mobile Chat Header Refinements (Industry-Standard UX) ===== */
@media (max-width: 860px) {
    .chat-header {
        padding: 12px 16px 12px 16px;
        /* +10px right padding */
        gap: 12px;
        /* Tighter gap for mobile */
        min-height: 56px;
    }

    /* Prevent title truncation on mobile - show full name */
    .chat-title {
        font-size: 1em;
        white-space: nowrap;
        overflow: visible;
        /* Allow full name to show */
        text-overflow: clip;
        flex-shrink: 0;
        /* Don't shrink the title */
        max-width: none;
        /* Remove max-width constraint */
    }

    /* Industry-standard touch target: 44x44px minimum */
    .chat-action-btn {
        width: 36px !important;
        height: 36px !important;
        border-radius: 8px;
    }

    .chat-action-btn svg {
        width: 18px !important;
        height: 18px !important;
    }

    /* Optimal button spacing: 12px (Apple HIG / Material Design) */
    .chat-actions {
        gap: 12px;
    }

    /* Font controls slightly larger for touch */
    .chat-font-size-controls {
        padding: 6px 10px;
    }

    .chat-font-btn {
        min-width: 24px;
        height: 28px;
        font-size: 15px;
    }
}

/* ========================================
   RTL SPECIFIC OVERRIDES
   ======================================== */

/* Fix Dropdown positioning in RTL */
[dir="rtl"] .chat-settings-dropdown {
    right: auto;
    left: 0;
}

/* Swap window control buttons order in RTL */
[dir="rtl"] .chat-window-controls {
    flex-direction: row-reverse;
}