#chatWidget {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9998;
    font-family: 'IBM Plex Sans Arabic', 'Jost', sans-serif;
}

#chatWidget.rtl {
    left: auto;
    right: 20px;
}

.chat-widget-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #0d6efd;
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: transform 0.3s, background 0.3s;
    position: relative;
}

.chat-widget-btn:hover {
    transform: scale(1.1);
    background: #0b5ed7;
}

.chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    display: none;
}

.chat-popup {
    position: fixed;
    bottom: 90px;
    left: 20px;
    width: 360px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
}

#chatWidget.rtl .chat-popup {
    left: auto;
    right: 20px;
}

.chat-popup.active {
    display: flex;
}

.chat-popup-header {
    background: #0d6efd;
    color: white;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-popup-header h5 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-popup-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.chat-status-indicator {
    font-size: 12px;
    opacity: 0.85;
    margin-top: 2px;
}

.chat-popup-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f0f2f5;
}

.chat-widget-bubble {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    word-wrap: break-word;
}

.chat-widget-bubble.customer {
    align-self: flex-end;
    background: #0d6efd;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-widget-bubble.master {
    align-self: flex-start;
    background: white;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.chat-widget-bubble.system {
    align-self: center;
    background: #e9ecef;
    color: #666;
    font-size: 11px;
    text-align: center;
}

.chat-widget-bubble .bubble-time {
    font-size: 10px;
    opacity: 0.7;
    display: block;
    margin-top: 4px;
    text-align: right;
}

.chat-widget-typing {
    display: none;
    padding: 4px 12px;
    font-size: 12px;
    color: #888;
}

.chat-widget-typing.active {
    display: block;
}

.chat-popup-input {
    padding: 10px 12px;
    border-top: 1px solid #eee;
    background: white;
}

.chat-widget-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-widget-input-row textarea {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    resize: none;
    max-height: 60px;
    font-family: inherit;
}

.chat-widget-input-row textarea:focus {
    outline: none;
    border-color: #0d6efd;
}

.chat-widget-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #0d6efd;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.chat-widget-send-btn:hover {
    background: #0b5ed7;
}

.chat-widget-toolbar {
    display: flex;
    gap: 6px;
    padding: 4px 12px 0;
}

.chat-widget-toolbar button {
    background: none;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 12px;
    color: #555;
}

.chat-widget-toolbar button:hover {
    background: #f0f0f0;
}

.chat-widget-image-preview {
    padding: 4px 12px;
    display: none;
}

.chat-widget-image-preview img {
    max-height: 60px;
    border-radius: 4px;
}

.chat-widget-image-preview button {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 10px;
    cursor: pointer;
    margin-left: 4px;
    vertical-align: top;
}

/* Chat Start Form */
.chat-start-form {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    justify-content: center;
}

.chat-start-form h6 {
    text-align: center;
    margin: 0;
    color: #333;
}

.chat-start-form input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
}

.chat-start-form input:focus {
    outline: none;
    border-color: #0d6efd;
}

.chat-start-form .btn-start {
    background: #0d6efd;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.chat-start-form .btn-start:hover {
    background: #0b5ed7;
}

.chat-start-form .btn-start:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

/* Chat closed message */
.chat-closed-msg {
    text-align: center;
    padding: 12px;
    background: #fff3cd;
    color: #856404;
    font-size: 12px;
    border-radius: 8px;
    margin: 8px 0;
}

/* Lightbox for widget */
.chat-widget-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
}

.chat-widget-lightbox.active {
    display: flex;
}

.chat-widget-lightbox img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
}

.chat-widget-lightbox button {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
}

@media (max-width: 480px) {
    .chat-popup {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        bottom: 80px;
        left: 10px;
    }
    #chatWidget.rtl .chat-popup {
        left: auto;
        right: 10px;
    }
}
