/* Floating Chat Widget Styles - مطابق لهوية منصة مدعوم (نفس ألوان chat-customer.html) */

.floating-chat-widget {
    --chat-bg: #ffffff;
    --chat-bg-elevated: #f4f6f8;
    --chat-border: rgba(0, 51, 102, 0.1);
    --chat-text: #23272b;
    --chat-text-secondary: #5c6570;
    --chat-text-tertiary: #8a94a0;
    --chat-accent: #003366;
    --chat-accent-hover: #0055AA;
    --chat-bubble-bot: #f1f0f0;
    --chat-bubble-user: #003366;
    --chat-success: #22c55e;

    position: fixed;
    bottom: 2rem;
    left: 2rem;
    z-index: 9998;
    font-family: 'Cairo', sans-serif;
    direction: rtl;
}

.chat-bubble-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #003366 0%, #0055AA 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 51, 102, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.chat-bubble-btn:hover {
    transform: scale(1.12);
    box-shadow: 0 6px 24px rgba(0, 51, 102, 0.4);
}

.chat-bubble-btn:active {
    transform: scale(0.95);
}

.chat-bubble-icon {
    width: 30px;
    height: 30px;
}

.chat-bubble-icon svg {
    width: 100%;
    height: 100%;
    stroke: white;
    fill: none;
    stroke-width: 2;
}

/* ==================== Panel ==================== */

.chat-widget-panel {
    position: absolute;
    bottom: 80px;
    left: 0;
    width: 380px;
    height: 560px;
    background: var(--chat-bg);
    color: var(--chat-text);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--chat-border);
    transition: width 0.25s ease, height 0.25s ease;
}

.chat-widget-panel.active {
    display: flex;
    animation: chatSlideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-widget-panel.minimized {
    height: 68px;
}

.chat-widget-panel.minimized .chat-widget-body,
.chat-widget-panel.minimized .chat-widget-footer,
.chat-widget-panel.minimized .chat-settings-panel {
    display: none !important;
}

.chat-widget-panel.maximized {
    width: min(480px, calc(100vw - 2rem));
    height: min(760px, calc(100vh - 4rem));
}

@keyframes chatSlideUp {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ==================== Header ==================== */

.chat-widget-header {
    background: linear-gradient(135deg, #003366 0%, #0055AA 100%);
    color: white;
    padding: 1rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    cursor: move;
    user-select: none;
}

.chat-widget-panel.dragging {
    transition: none !important;
    animation: none !important;
}

.chat-widget-header-title {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-width: 0;
}

.chat-widget-header-icon {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-widget-header-icon svg {
    width: 22px;
    height: 22px;
    stroke: white;
    fill: none;
    stroke-width: 2;
}

.chat-widget-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.chat-widget-header p {
    margin: 0.15rem 0 0 0;
    font-size: 0.8rem;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-widget-header-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.chat-header-icon-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    opacity: 0.85;
    transition: all 0.15s ease;
    padding: 0;
}

.chat-header-icon-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.12);
}

.chat-header-icon-btn svg {
    width: 18px;
    height: 18px;
}

.chat-widget-close {
    font-size: 1.4rem;
    line-height: 1;
}

/* ==================== Settings dropdown ==================== */

.chat-settings-panel {
    display: none;
    flex-direction: column;
    background: var(--chat-bg-elevated);
    border-bottom: 1px solid var(--chat-border);
    animation: chatSlideDown 0.15s ease-out;
    flex-shrink: 0;
}

.chat-settings-panel.active {
    display: flex;
}

@keyframes chatSlideDown {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-settings-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--chat-border);
    font-size: 0.85rem;
    color: var(--chat-text);
}

.chat-settings-item:last-child {
    border-bottom: none;
}

.chat-settings-item-clickable {
    cursor: pointer;
    transition: background 0.15s ease;
}

.chat-settings-item-clickable:hover {
    background: rgba(0, 51, 102, 0.05);
}

.chat-settings-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--chat-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-settings-icon svg {
    width: 100%;
    height: 100%;
}

.chat-settings-label {
    flex: 1;
}

.chat-settings-action {
    color: #7ea6ff;
    text-decoration: none;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.85rem;
}

.chat-settings-action:hover {
    text-decoration: underline;
}

.chat-toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.chat-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.chat-toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #3a3d42;
    border-radius: 22px;
    transition: 0.2s;
}

.chat-toggle-slider::before {
    content: '';
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.2s;
}

.chat-toggle-switch input:checked + .chat-toggle-slider {
    background: var(--chat-accent);
}

.chat-toggle-switch input:checked + .chat-toggle-slider::before {
    transform: translateX(18px);
}

/* ==================== Body ==================== */

.chat-widget-body {
    flex: 1;
    padding: 1.25rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.chat-widget-body::-webkit-scrollbar { width: 6px; }
.chat-widget-body::-webkit-scrollbar-track { background: transparent; }
.chat-widget-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.chat-widget-message {
    display: flex;
    animation: chatFadeInMsg 0.25s ease-out;
}

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

.chat-widget-message.bot { justify-content: flex-start; }
.chat-widget-message.user { justify-content: flex-end; }

.chat-widget-bubble {
    max-width: 78%;
    padding: 0.8rem 1rem;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.6;
    word-wrap: break-word;
}

.chat-widget-message.bot .chat-widget-bubble {
    background: var(--chat-bubble-bot);
    color: var(--chat-text);
    border-radius: 4px 14px 14px 14px;
}

.chat-widget-message.bot .chat-widget-bubble a {
    color: #7ea6ff;
    font-weight: 600;
    text-decoration: none;
}

.chat-widget-message.bot .chat-widget-bubble a:hover {
    text-decoration: underline;
}

.chat-widget-message.user .chat-widget-bubble {
    background: var(--chat-bubble-user);
    color: white;
    border-radius: 14px 4px 14px 14px;
}

/* System / presence events (joined / left the chat) */

.chat-widget-system-event {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.4rem;
    padding: 0.75rem 0;
}

.chat-widget-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    flex-shrink: 0;
}

.chat-widget-system-text {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--chat-text);
}

.chat-widget-system-time {
    font-size: 0.75rem;
    color: var(--chat-text-tertiary);
}

/* ==================== Suggested question / support option buttons ==================== */

.chat-widget-option {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1rem;
    background: var(--chat-bg-elevated);
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.88rem;
    color: var(--chat-text);
    font-weight: 500;
    width: 100%;
    text-align: right;
    font-family: inherit;
}

.chat-widget-option:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--chat-accent);
}

.chat-widget-option-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-widget-option-icon svg {
    width: 100%;
    height: 100%;
    fill: var(--chat-text-secondary);
}

.chat-widget-option-text {
    flex: 1;
    text-align: right;
}

.chat-widget-end-btn {
    justify-content: center;
    color: #f87171;
    font-weight: 600;
}

/* ==================== Footer / input row ==================== */

.chat-widget-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    flex-shrink: 0;
}

.chat-widget-input-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--chat-bg-elevated);
    border: 1px solid var(--chat-border);
    border-radius: 24px;
    padding: 0.4rem 0.5rem 0.4rem 1rem;
}

.chat-widget-attach-btn {
    background: none;
    border: none;
    color: var(--chat-text-tertiary);
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 50%;
    transition: all 0.15s ease;
}

.chat-widget-attach-btn:hover {
    color: var(--chat-text);
    background: rgba(255, 255, 255, 0.08);
}

.chat-widget-attach-btn svg {
    width: 18px;
    height: 18px;
}

.chat-widget-send-btn {
    background: var(--chat-accent);
    border: none;
    color: white;
    cursor: pointer;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 50%;
    transition: all 0.15s ease;
}

.chat-widget-send-btn:hover {
    background: var(--chat-accent-hover);
}

.chat-widget-send-btn svg {
    width: 16px;
    height: 16px;
}

.chat-widget-msg-time {
    font-size: 0.7rem;
    opacity: 0.65;
    margin-top: 0.3rem;
    text-align: left;
}

/* Bot quick-reply option buttons (رسائل البوت: عندي استفسار / عندي مشكلة...) */
.bot-quick-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-self: flex-start;
    max-width: 90%;
    margin-top: 0.25rem;
}

.bot-quick-option-btn {
    background: var(--chat-bg-elevated);
    border: 1.5px solid var(--chat-accent);
    color: var(--chat-text);
    padding: 0.5rem 1rem;
    border-radius: 1.25rem;
    font-family: 'Cairo', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.bot-quick-option-btn:hover {
    background: var(--chat-accent);
    color: white;
}

.bot-quick-option-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* حالات وسط الجسم (تحميل / خطأ / تسجيل دخول / انتهاء المحادثة) */
.chat-widget-center-state {
    margin: auto;
    text-align: center;
    color: var(--chat-text-secondary);
    font-size: 0.9rem;
    line-height: 1.7;
    padding: 1rem;
}

.chat-widget-primary-link {
    display: inline-block;
    margin-top: 0.85rem;
    background: var(--chat-accent);
    color: white !important;
    text-decoration: none;
    font-weight: 700;
    padding: 0.6rem 1.5rem;
    border-radius: 999px;
    transition: background 0.15s ease;
}

.chat-widget-primary-link:hover {
    background: var(--chat-accent-hover);
}

.chat-settings-provide-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.chat-widget-typing-row {
    padding: 0 1.25rem 0.5rem;
    flex-shrink: 0;
}

.chat-widget-text-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--chat-text);
    font-family: 'Cairo', sans-serif;
    font-size: 0.88rem;
    text-align: right;
    min-width: 0;
}

.chat-widget-text-input::placeholder {
    color: var(--chat-text-tertiary);
    text-align: right;
}

.chat-widget-form-input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--chat-border);
    background: var(--chat-bg-elevated);
    color: var(--chat-text);
    border-radius: 8px;
    font-family: 'Cairo', sans-serif;
    text-align: right;
    box-sizing: border-box;
}

.chat-widget-rating-row {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
}

.chat-widget-rating-btn {
    font-size: 2rem;
    background: none;
    border: 2px solid var(--chat-border);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-widget-rating-btn:hover {
    border-color: var(--chat-accent);
    transform: scale(1.1);
}

/* ==================== Responsive ==================== */

@media (max-width: 768px) {
    .floating-chat-widget { bottom: 1rem; left: 1rem; }
    .chat-bubble-btn { width: 56px; height: 56px; }
    .chat-widget-panel {
        width: calc(100vw - 2rem);
        max-width: 380px;
        height: min(70vh, 560px);
        bottom: 70px;
    }
    .chat-widget-panel.maximized {
        width: calc(100vw - 1rem);
        height: calc(100vh - 6rem);
    }
    .chat-widget-bubble { max-width: 85%; }
}

@media (max-width: 480px) {
    .floating-chat-widget { bottom: 0.75rem; left: 0.75rem; }
    .chat-bubble-btn { width: 52px; height: 52px; }
    .chat-widget-panel { width: calc(100vw - 1.5rem); bottom: 62px; }
    .chat-widget-header { padding: 0.85rem 1rem; }
    .chat-widget-body { padding: 1rem; }
    .chat-widget-footer { padding: 0.85rem 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    .chat-widget-panel,
    .chat-widget-message,
    .chat-bubble-btn,
    .chat-settings-panel {
        animation: none !important;
        transition: none !important;
    }
}


/* ==================== Accessibility & extra polish ====================
   تحسينات وصول (focus states) وتفاصيل إضافية (typing indicator، صور/أكواد
   داخل الفقاعات). كانت سابقاً في ملف منفصل chat-widget-enhanced.css، ودُمجت
   هنا في ملف واحد. */

.chat-bubble-btn:focus-visible,
.chat-widget-option:focus-visible,
.chat-header-icon-btn:focus-visible,
.chat-widget-text-input:focus-visible,
.chat-widget-attach-btn:focus-visible {
    outline: 2px solid #7ea6ff;
    outline-offset: 2px;
}

.chat-widget-bubble code {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.chat-widget-bubble img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin-top: 0.5rem;
}

.chat-widget-typing {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0.6rem 0.2rem;
}

.chat-widget-typing-text {
    font-size: 0.78rem;
    color: var(--chat-text-tertiary, #7d818a);
    font-family: 'Cairo', sans-serif;
}

.chat-widget-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chat-text-tertiary, #7d818a);
    animation: chatTypingDot 1.4s infinite;
}

.chat-widget-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-widget-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatTypingDot {
    0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-6px); }
}
