/* Popup Styling */
.user-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.notifications,
.messages,
.wishlist,
.cart {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    text-decoration: none;
    width: 40px;
    height: 40px;
    transition: all 0.3s ease;
}

.notifications,
.messages {
    color: var(--notifications-color);
}

.wishlist {
    color: var(--main-color);
}

.cart {
    color: var(--dark-color);
}

.count {
    position: absolute;
    top: -10px;
    background: #ff4757;
    color: #fff;
    font-size: 0.75rem;
    font-weight: bold;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    min-width: 22px;
    padding: 2px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    z-index: 10;
    transition: all 0.3s ease;
}

/* عند العداد الكبير (مثلاً 10 أو أكثر) */
.user-actions .count.long {
    width: auto;
    min-width: 22px;
    padding: 0 5px;
    border-radius: 12px;
}

.notifications,
.messages,
.wishlist,
.cart {
    position: relative;
    z-index: 1;
    /* الأيقونة نفسها */
}

.user-actions .count {
    z-index: 5;
    /* العداد فوقها فقط لما يكون ظاهر */
    transition: all 0.3s ease;
}

.user-actions .count.hidden {
    opacity: 0;
    transform: scale(0.6);
    pointer-events: none;
    z-index: -1;
    /* 👈 تحت الأيقونة */
}

/* 🟢 في الوضع LTR (الإنجليزي) */
html[dir="ltr"] .wishlist .count {
    left: -6px;
}

/* 🔵 في الوضع RTL (العربي) */
html[dir="rtl"] .wishlist .count {
    right: -6px;
}

/* 🟢 في الوضع LTR (الإنجليزي) */
html[dir="ltr"] .cart .count {
    left: -10px;
}

/* 🔵 في الوضع RTL (العربي) */
html[dir="rtl"] .cart .count {
    right: -10px;
}

/* 🟢 في الوضع LTR (الإنجليزي) */
html[dir="ltr"] .notifications .count {
    left: -10px;
}

/* 🔵 في الوضع RTL (العربي) */
html[dir="rtl"] .notifications .count {
    right: -10px;
}

/* 🟢 في الوضع LTR (الإنجليزي) */
html[dir="ltr"] .messages .count {
    left: -10px;
}

/* 🔵 في الوضع RTL (العربي) */
html[dir="rtl"] .messages .count {
    right: -10px;
}

.popup {
    position: absolute;
    top: 50px;
    right: 0;
    background: #fff;
    color: #333;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    width: 280px;
    max-height: 400px;
    overflow-y: auto;
    opacity: 0;
    transform: scale(0.9);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 1000;
}

/* ✅ لما تتفعل */
.popup.active {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

[dir="rtl"] .popup {
    right: auto;
    left: 0;
    /* direction: rtl; */
}

[dir="ltr"] .popup {
    left: auto;
    right: 0;
    /* direction: ltr; */
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
}

.popup-header h4 {
    font-size: 15px;
    padding: 5px;
    margin: 0;
}

.popup-header button {
    border: none;
    background: transparent;
    font-size: 16px;
    cursor: pointer;
    color: #888;
}

.popup-list {
    list-style: none;
    margin: 10px 0 0 0;
    padding: 0;
    max-height: 200px;
    overflow-y: auto;
}

.popup-list li {
    padding: 8px;
    border-bottom: 1px solid #eee;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.popup-list li:hover {
    background: #f9f9f9;
}

.popup-list .empty-msg {
    text-align: center;
    color: #999;
    font-style: italic;
    padding: 20px 10px;
    background: #fafafa;
    border: none;
}

.relative {
    position: relative;
    /* ضروري لتحديد مرجع الزر */
}

/* .open-chat-btn {
  position: absolute;
  top: 10px;
  inset-inline-end: 10px;

  background: #007bff;
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: background 0.3s;
} */

.open-chat-btn {
    position: absolute;
    top: 10px;
    inset-inline-end: 10px;
    /* يتأقلم تلقائياً مع RTL/LTR */
    display: inline-block;
    font-weight: 600;
    text-align: center;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    vertical-align: middle;
    user-select: none;
    border: 1px solid transparent;
    padding: 10px 20px;
    font-size: 1rem;
    line-height: 1.5;
    border-radius: var(--border-radius);
    transition: all 0.3s ease;
    cursor: pointer;
    color: var(--light-color);
    background: linear-gradient(45deg, var(--main-color), var(--secondary-color));
    box-shadow: var(--box-shadow);
}

.open-chat-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
}

.chat-popups {
    position: fixed;
    height: 400px;
    bottom: 0;
    right: 10px;
    display: flex;
    gap: 10px;
    flex-direction: row-reverse;
    z-index: 20000;
}

.chat-window {
    width: 320px;
    background: #fff;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Cairo', sans-serif;
    animation: fadeIn 0.25s ease-in-out;
    direction: ltr;
}

/* ==== HEADER ==== */
.chat-header {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ✅ عنصر المستخدم داخل الهيدر */
.chat-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ✅ تثبيت حجم الصورة وجعلها داخل إطار دائري */
.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: contain;
    border: 2px solid #fff;
    background: #eee;
    flex-shrink: 0;
}

/* ✅ اسم المستخدم بجانب الصورة */
.chat-title {
    font-weight: bold;
    font-size: 15px;
    color: #fff;
}

.chat-header button {
    background: transparent;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    transition: 0.2s;
}

.chat-header button:hover {
    color: #ffcccc;
}

/* ==== BODY ==== */
.chat-body {
    flex: 1;
    background: #f0f2f5;
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}

.chat-body::-webkit-scrollbar {
    width: 6px;
}

.chat-body::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 3px;
}

.message {
    padding: 8px 12px;
    border-radius: 12px;
    max-width: 75%;
    word-wrap: break-word;
    line-height: 1.4;
    transition: all 0.2s ease-in-out;
}

.sent {
    background: var(--light-gray);
    color: var(--text-dark);
    align-self: flex-end;
    text-align: right !important;
    border-bottom-right-radius: 4px;
}

/* [dir="rtl"] .sent {
    text-align: left !important;
}

[dir="ltr"] .sent {
    text-align: right !important;
} */

.sent:hover {
    background: var(--gray-color);
}

.received {
    background: #fff;
    align-self: flex-start;
    border: 1px solid #ddd;
    border-bottom-left-radius: 4px;
}

.msg-status {
    font-size: 11px;
    color: #888;
    text-align: right;
    margin-top: 2px;
}

.msg-time {
    font-size: 0.75rem;
    color: #888;
    display: inline-block;
    text-align: right;
    margin-top: 3px;
}

.sent .msg-time,
.sent .msg-status {
    text-align: right;
    float: right;
    margin-left: 6px;
}

.typing {
    font-size: 13px;
    color: #007bff;
    margin: 5px 10px;
    animation: blink 1.2s infinite;
}

/* ==== FOOTER ==== */
.chat-footer {
    display: flex;
    align-items: center;
    padding: 8px;
    border-top: 1px solid #ddd;
    background: #fff;
    gap: 6px;
    position: relative;
}

.chat-footer textarea,
.chat-textarea {
    flex: 1;
    resize: none;
    border: 1px solid #ccc;
    border-radius: 10px;
    padding: 8px 10px;
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    outline: none;
    transition: 0.2s;
    font-family: inherit;
}

.chat-footer textarea:focus,
.chat-textarea:focus {
    border-color: #007bff;
    box-shadow: 0 0 3px rgba(0, 123, 255, 0.3);
}

html[dir="rtl"] .chat-textarea {
    direction: rtl;
    text-align: right;
}

html[dir="ltr"] .chat-textarea {
    direction: ltr;
    text-align: left;
}

.chat-footer button {
    background: #007bff;
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-footer button:hover {
    background: #0056b3;
}

.chat-footer .emoji-btn,
.chat-footer .icon-btn {
    background: #e9ecef;
    color: #333;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

.chat-footer .emoji-btn:hover,
.chat-footer .icon-btn:hover {
    background: #d6d8da;
}

.msg-status {
    font-size: 12px;
    text-align: right;
    margin-top: 3px;
    user-select: none;
}

.msg-status.not-seen {
    color: var(--accent);
    content: "✓";
}

.msg-status.seen {
    color: #045496;
    /* أزرق مثل واتساب */
    font-weight: bold;
}

.msg-text {
    word-wrap: break-word;
}



/* 💬 عناصر المحادثة */
.chat-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    transition: background 0.2s ease-in-out;
    cursor: pointer;
}

.chat-item:hover {
    background: #f9f9f9;
}

/* .chat-avatar {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  margin-right: 10px;
  border: 2px solid #ddd;
}*/

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.chat-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-name {
    font-weight: 600;
    color: #222;
    font-size: 15px;
}

.chat-time {
    font-size: 12px;
    color: #888;
}

.chat-bottom {
    margin-top: 2px;
}

.chat-preview {
    font-size: 14px;
    color: #555;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.emoji-container {
    position: relative;
}

.emoji-btn {
    background: transparent;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #555;
}

.emoji-picker {
    position: absolute;
    bottom: 45px;
    left: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    padding: 10px;
    width: 250px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 20px;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

/* [dir="rtl"] .emoji-picker  {
  right: auto !important;
  left: 0 !important; 
  direction: rtl;
} */

.emoji-picker span {
    cursor: pointer;
    transition: transform 0.1s;
}

.emoji-picker span:hover {
    transform: scale(1.3);
}


/* ==== ANIMATIONS ==== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes blink {

    0%,
    100% {
        opacity: 0.3;
    }

    50% {
        opacity: 1;
    }
}

@media (max-width: 768px) {
    .popup {
        right: 0 !important;
        left: auto !important;
        transform: none !important;
        /* يمنع التحريك الجانبي */
    }

    [dir="rtl"] .popup-header {
        flex-direction: row-reverse;
    }

    [dir="ltr"] .popup-header {
        flex-direction: row;
    }
}