/* ========================================
   TRENJ - نظام المحادثات (Phase 2)
   WhatsApp-Inspired Chat — Mobile-First
   RTL Arabic, Tajawal Font
   ======================================== */

/* ========================================
   0. متغيرات التصميم
   ======================================== */
:root {
    --wa-teal: #075E54;
    --wa-teal-dark: #054d44;
    --wa-green: #25D366;
    --wa-green-light: #dcf8c6;
    --wa-green-bubble: #d9fdd3;
    --wa-bg: #efeae2;
    --wa-bg-pattern: #d1cdc7;
    --wa-header-h: 56px;
    --wa-input-h: 56px;
    --wa-white-bubble: #fff;
    --wa-text: #111b21;
    --wa-text-secondary: #667781;
    --wa-check: #53bdeb;
    --wa-time: #667781;
    --wa-divider: #e9edef;
    --wa-hover: #f5f6f6;
    --wa-active: #f0f2f5;
    --wa-unread-bg: #25D366;
    --wa-search-bg: #f0f2f5;
}

/* ========================================
   1. صفحة الرسائل — Layout (App-Like)
   ======================================== */

/* قفل body — منع أي تمرير خارج صندوق المحادثة */
html.chat-fullscreen,
html.chat-fullscreen body {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    height: calc(var(--app-height, 100vh)) !important;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    padding-bottom: 0 !important;
}

/* إزالة padding-top من main-content عند إخفاء الهيدر في صفحة المحادثة */
.chat-fullscreen .main-content,
.chat-fullscreen #spa-content {
    padding-top: 0 !important;
    min-height: 0 !important;
    height: calc(var(--app-height, 100vh)) !important;
    overflow: hidden !important;
}

.messages-page {
    padding: 0;
    height: 100%;
    height: calc(var(--app-height, 100vh) - 64px);
    background: var(--wa-bg);
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: pan-y;
}

/* إخفاء header و footer في صفحة الرسائل (نُبقي bottom-nav ظاهراً) */
.messages-page ~ footer,
.chat-fullscreen .site-header,
.chat-fullscreen .header:not(.host-header),
.chat-fullscreen #main-header:not(.host-header) {
    display: none !important;
}

/* إظهار bottom-nav في صفحة الرسائل */
.chat-fullscreen #bottom-nav {
    display: flex !important;
}

/* إظهار host-bottom-nav في صفحة رسائل المضيف */
.chat-fullscreen #host-bottom-nav {
    display: flex !important;
}

.messages-container {
    display: flex;
    height: 100%;
    height: calc(var(--app-height, 100vh) - 64px);
    max-width: 1400px;
    margin: 0 auto;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0,0,0,0.08);
}

/* ========================================
   2. قائمة المحادثات (يمين)
   ======================================== */
.conv-list-panel {
    width: 420px;
    min-width: 420px;
    background: #fff;
    border-left: 1px solid var(--wa-divider);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.conv-list-header {
    padding: 0 16px;
    background: var(--wa-teal);
    display: flex;
    align-items: center;
    height: var(--wa-header-h);
    flex-shrink: 0;
}

.conv-list-header h2 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
}

.conv-list-header h2 i {
    margin-left: 8px;
    color: rgba(255,255,255,0.85);
}

/* زر الرجوع في رأس قائمة المحادثات */
.msg-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    margin-left: 10px;
    flex-shrink: 0;
    transition: background 0.2s;
}
.msg-back-btn:hover {
    background: rgba(255,255,255,0.25);
}

.conv-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: #fff;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

/* --- عنصر محادثة --- */
.conv-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--wa-divider);
    transition: background 0.15s;
    position: relative;
    cursor: pointer;
}

.conv-item:hover {
    background: var(--wa-hover);
}

.conv-item.active {
    background: var(--wa-active);
}

.conv-item.unread .conv-item-name,
.conv-item.unread .conv-item-preview {
    font-weight: 700;
    color: var(--wa-text);
}

.conv-item.unread .conv-item-time {
    color: var(--wa-unread-bg);
    font-weight: 600;
}

.conv-item-image {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: #dfe5e7;
}

.conv-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.conv-item-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--wa-teal) 0%, #128c7e 100%);
    color: #fff;
    font-size: 1.2rem;
}

.conv-item-content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.conv-item-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 3px;
}

.conv-item-name {
    font-size: 1rem;
    font-weight: 500;
    color: var(--wa-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item-time {
    font-size: 0.72rem;
    color: var(--wa-time);
    flex-shrink: 0;
    margin-right: 8px;
}

.conv-item-chalet {
    font-size: 0.76rem;
    color: var(--wa-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 1px;
}

.conv-item-preview {
    font-size: 0.85rem;
    color: var(--wa-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item-badge {
    background: var(--wa-unread-bg);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    flex-shrink: 0;
}

/* حالة فارغة */
.conv-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--wa-text-secondary);
}

.conv-empty i {
    font-size: 3.5rem;
    margin-bottom: 16px;
    color: #c3ccd2;
}

.conv-empty p {
    font-size: 1rem;
    font-weight: 600;
    color: var(--wa-text);
}

.conv-empty small {
    font-size: 0.85rem;
    margin-top: 6px;
    color: var(--wa-text-secondary);
}

/* ========================================
   3. نافذة المحادثة (يسار)
   ======================================== */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--wa-bg);
    position: relative;
}

/* خلفية واتساب */
.chat-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23c6bfb6' fill-opacity='0.12'%3E%3Cpath d='M30 5c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2zm-10 8c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm20 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm-25 12c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm30 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zM20 37c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm20 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm-10 8c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2z'/%3E%3C/g%3E%3C/svg%3E");
    opacity: 0.6;
    pointer-events: none;
    z-index: 0;
}

.chat-panel > * {
    position: relative;
    z-index: 1;
}

/* --- رأس المحادثة --- */
.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    background: var(--wa-teal);
    height: var(--wa-header-h);
    flex-shrink: 0;
    color: #fff;
}

.chat-back-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.1rem;
    color: #fff;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    margin-left: -4px;
    transition: background 0.2s;
}

.chat-back-btn:hover {
    background: rgba(255,255,255,0.15);
}

.chat-header-chalet {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.chat-header-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.2);
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-title {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-title:hover {
    color: rgba(255,255,255,0.9);
}

.chat-header-subtitle {
    font-size: 0.78rem;
    color: rgba(255,255,255,0.7);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-price {
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    background: rgba(255,255,255,0.15);
    padding: 4px 12px;
    border-radius: 20px;
    backdrop-filter: blur(4px);
}

/* --- منطقة الرسائل --- */
.chat-messages {
    flex: 1;
    min-height: 0; /* ضروري لمنع flex overflow على الموبايل */
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

/* --- فقاعة رسالة --- */
.chat-msg {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    max-width: 80%;
    animation: msgFadeIn 0.2s ease;
    margin-bottom: 2px;
}

@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-msg.mine {
    align-self: flex-start;
    flex-direction: row;
}

.chat-msg.theirs {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg.system {
    align-self: center;
    max-width: 85%;
}

.msg-avatar {
    width: 0;
    height: 0;
    overflow: hidden;
    display: none;
}

.msg-bubble {
    background: var(--wa-white-bubble);
    border-radius: 8px 0 8px 8px;
    padding: 6px 8px 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.06);
    position: relative;
    word-break: break-word;
    min-width: 80px;
}

.chat-msg.mine .msg-bubble {
    background: var(--wa-green-bubble);
    color: var(--wa-text);
    border-radius: 0 8px 8px 8px;
}

.chat-msg.theirs .msg-bubble {
    background: var(--wa-white-bubble);
    border-radius: 8px 0 8px 8px;
}

/* ذيل الفقاعة — رسالتي (يسار RTL = يمين الشاشة) */
.chat-msg.mine .msg-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    right: -8px;
    width: 0; height: 0;
    border-style: solid;
    border-width: 0 0 10px 10px;
    border-color: transparent transparent transparent var(--wa-green-bubble);
}

/* ذيل الفقاعة — رسالة الآخر */
.chat-msg.theirs .msg-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0; height: 0;
    border-style: solid;
    border-width: 0 10px 10px 0;
    border-color: transparent var(--wa-white-bubble) transparent transparent;
}

/* إخفاء الذيل عن الرسائل المتتالية من نفس الشخص */
.chat-msg.continuation .msg-bubble::before {
    display: none;
}
.chat-msg.continuation .msg-bubble {
    border-radius: 8px;
}

.msg-system {
    background: rgba(255,255,255,0.85);
    color: var(--wa-text-secondary);
    padding: 5px 14px;
    border-radius: 8px;
    font-size: 0.76rem;
    text-align: center;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
    backdrop-filter: blur(4px);
}

/* --- بطاقة إشعارات الحجز (داخل msg-system) --- */
.booking-notif {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    max-width: 340px;
    margin: 0 auto;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    text-align: right;
    direction: rtl;
}

.msg-system:has(.booking-notif) {
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
    padding: 4px 0;
}

.booking-notif-header {
    padding: 10px 14px;
    font-weight: 700;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
}

.booking-notif--new .booking-notif-header    { background: linear-gradient(135deg, #2196F3, #1565C0); }
.booking-notif--success .booking-notif-header { background: linear-gradient(135deg, #4CAF50, #2E7D32); }
.booking-notif--danger .booking-notif-header  { background: linear-gradient(135deg, #ef5350, #c62828); }
.booking-notif--complete .booking-notif-header { background: linear-gradient(135deg, #7E57C2, #4527A0); }
.booking-notif--info .booking-notif-header    { background: linear-gradient(135deg, #78909C, #455A64); }

.booking-notif-chalet {
    padding: 8px 14px;
    font-size: 0.80rem;
    font-weight: 600;
    color: #333;
    background: #f8f9fa;
    border-bottom: 1px solid #f0f0f0;
}

.booking-notif-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 8px;
    padding: 10px 12px;
}

.booking-notif-cell {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 7px 10px;
    background: #f8f9fa;
    border-radius: 8px;
    font-size: 0.78rem;
}

.booking-notif-cell span {
    font-size: 0.68rem;
    opacity: 0.65;
    white-space: nowrap;
}

.booking-notif-cell strong {
    font-size: 0.82rem;
    color: #1a1a1a;
    line-height: 1.3;
    word-break: break-word;
}

/* الخلية الأولى (عادةً التاريخ الأساسي فقط) لا تمتد — عمودين */
/* إذا كان عدد الخلايا فردي، الأخيرة تمتد على العمودين */
.booking-notif-cell:last-child:nth-child(odd) {
    grid-column: 1 / -1;
}

.booking-notif-footer {
    padding: 8px 14px;
    font-size: 0.70rem;
    color: #888;
    border-top: 1px solid #f0f0f0;
    text-align: center;
}

.booking-notif-action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #1565C0, #0D47A1);
    color: #fff !important;
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
    border-top: 1px solid #f0f0f0;
    transition: background 0.2s;
}

.booking-notif-action:hover {
    background: linear-gradient(135deg, #1976D2, #1565C0);
}

.booking-notif-action:active {
    background: #0D47A1;
}

.booking-notif--success .booking-notif-action { background: linear-gradient(135deg, #2E7D32, #1B5E20); }
.booking-notif--success .booking-notif-action:hover { background: linear-gradient(135deg, #388E3C, #2E7D32); }
.booking-notif--danger .booking-notif-action { background: linear-gradient(135deg, #c62828, #B71C1C); }
.booking-notif--danger .booking-notif-action:hover { background: linear-gradient(135deg, #D32F2F, #c62828); }
.booking-notif--complete .booking-notif-action { background: linear-gradient(135deg, #4527A0, #311B92); }
.booking-notif--complete .booking-notif-action:hover { background: linear-gradient(135deg, #512DA8, #4527A0); }

@media (max-width: 480px) {
    .booking-notif {
        max-width: 100%;
        border-radius: 10px;
    }

    .booking-notif-header {
        font-size: 0.78rem;
        padding: 9px 12px;
    }

    .booking-notif-grid {
        gap: 5px 6px;
        padding: 8px 10px;
    }

    .booking-notif-cell {
        padding: 6px 8px;
    }
}

.msg-text {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--wa-text);
    padding-left: 60px; /* مساحة للتوقيت */
}

.msg-meta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    float: left;
    margin-top: 2px;
    margin-right: 4px;
    position: relative;
    top: 4px;
}

.msg-time {
    font-size: 0.68rem;
    color: var(--wa-time);
}

.chat-msg.mine .msg-time {
    color: #667781;
}

.msg-read {
    font-size: 0.72rem;
    color: var(--wa-check);
}

.msg-sent {
    font-size: 0.72rem;
    color: #b3bfc5;
}

/* --- زر إعادة الإرسال --- */
.msg-retry-btn {
    display: block;
    background: none;
    border: none;
    color: #e74c3c;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0 0;
    margin-top: 4px;
}

.msg-retry-btn i {
    margin-left: 4px;
}

.msg-retry-btn:hover {
    text-decoration: underline;
}

.chat-msg.send-failed .msg-bubble {
    border: 1px solid #e74c3c;
}

/* رسالة قيد الإرسال — ساعة بدل علامة صح */
.msg-bubble[data-pending="1"] .msg-sent {
    color: #b3bfc5;
}
.msg-bubble[data-pending="1"] .msg-sent::before {
    content: '\f017';
    font-family: 'Font Awesome 6 Free';
    font-weight: 400;
    font-size: 0.72rem;
}

/* --- بطاقة الاستفسار --- */
.inquiry-card {
    background: rgba(0,0,0,0.04);
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 6px;
}

.chat-msg.theirs .inquiry-card {
    background: #f0f7ff;
    border-color: #d0e4f7;
}

.inquiry-badge {
    font-size: 0.76rem;
    font-weight: 700;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--wa-teal);
}

.chat-msg.theirs .inquiry-badge {
    color: #2980b9;
}

.inquiry-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 0.82rem;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.chat-msg.theirs .inquiry-row {
    border-bottom-color: #e4edf5;
}

.inquiry-row:last-child {
    border-bottom: none;
}

.inquiry-row span {
    opacity: 0.8;
}

/* ========================================
   4. قوالب الردود السريعة
   ======================================== */
.quick-replies-bar {
    display: flex;
    gap: 6px;
    padding: 6px 12px;
    overflow-x: auto;
    background: transparent;
    scrollbar-width: none;
}

.quick-replies-bar::-webkit-scrollbar {
    display: none;
}

.quick-reply-chip {
    background: #fff;
    border: 1px solid var(--wa-divider);
    border-radius: 18px;
    padding: 5px 14px;
    font-size: 0.78rem;
    font-family: 'Tajawal', sans-serif;
    color: var(--wa-teal);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.quick-reply-chip:hover {
    background: var(--wa-teal);
    color: #fff;
    border-color: var(--wa-teal);
}

/* ========================================
   5. شريط الإرسال
   ======================================== */
.chat-input-bar {
    padding: 6px 8px;
    background: var(--wa-bg);
    flex-shrink: 0;
}

.chat-input-group {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.chat-input-group > textarea,
#chatInput {
    flex: 1;
    border: none;
    background: #fff;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.95rem;
    padding: 10px 14px;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.5;
    direction: rtl;
    border-radius: 24px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--wa-teal);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    flex-shrink: 0;
    transition: all 0.15s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.chat-send-btn:hover {
    background: var(--wa-teal-dark);
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chat-send-btn i {
}

/* ========================================
   6. حالة فارغة (لا محادثة مفتوحة)
   ======================================== */
.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--wa-text-secondary);
    padding: 40px 24px;
    background: #f0f2f5;
}

.chat-empty-state i {
    font-size: 4.5rem;
    color: #c3ccd2;
    margin-bottom: 24px;
}

.chat-empty-state h3 {
    font-size: 1.4rem;
    color: var(--wa-text);
    margin-bottom: 10px;
    font-weight: 300;
}

.chat-empty-state p {
    font-size: 0.9rem;
    max-width: 400px;
    line-height: 1.7;
    color: var(--wa-text-secondary);
}

.btn-chat-explore {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 24px;
    padding: 10px 28px;
    background: var(--wa-teal);
    color: #fff;
    text-decoration: none;
    border-radius: 25px;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.btn-chat-explore:hover {
    background: var(--wa-teal-dark);
    transform: translateY(-1px);
}

/* ========================================
   7. Modal استفسار منظّم (chalet-details)
   ======================================== */
.inquiry-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.inquiry-modal-overlay.show {
    display: flex;
}

.inquiry-modal {
    background: #fff;
    border-radius: 20px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    animation: modalSlideUp 0.3s ease;
}

@keyframes modalSlideUp {
    from { transform: translateY(30px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

.inquiry-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid #eee;
}

.inq-header-right {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.inquiry-modal-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.inq-chalet-sub {
    font-size: 0.78rem;
    color: #888;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
}

.inquiry-modal-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    color: #888;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    transition: all 0.2s;
}

.inquiry-modal-close:hover {
    background: #f0f0f0;
    color: #333;
}

.inquiry-modal-body {
    padding: 16px 20px;
}

.inquiry-modal-body .form-group {
    margin-bottom: 12px;
}

.inquiry-modal-body label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #444;
    margin-bottom: 6px;
}

/* Inline group: label + input/select on same row */
.inq-inline-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.inq-inline-group label {
    flex-shrink: 0;
    white-space: nowrap;
    margin-bottom: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: #444;
}

.inq-inline-group select,
.inq-inline-group input {
    flex: 1;
    min-width: 0;
}

.inquiry-modal-body input,
.inquiry-modal-body select,
.inquiry-modal-body textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #e0e0e0;
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.92rem;
    transition: border-color 0.2s;
    box-sizing: border-box;
    direction: rtl;
}

.inquiry-modal-body input:focus,
.inquiry-modal-body select:focus,
.inquiry-modal-body textarea:focus {
    border-color: var(--primary-color, #FF385C);
    outline: none;
}

.inquiry-date-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.inquiry-modal-footer {
    padding: 12px 20px 20px;
}

.btn-send-inquiry {
    width: 100%;
    padding: 12px;
    background: var(--primary-color, #FF385C);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-family: 'Tajawal', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-send-inquiry:hover {
    background: #e0314f;
}

.btn-send-inquiry:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* -------- InquiryPicker: layout containers -------- */

.inq-date-input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #e0e0e0;
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.92rem;
    transition: border-color 0.2s;
    box-sizing: border-box;
    direction: rtl;
}

.inq-date-input:focus {
    border-color: #FF385C;
    outline: none;
}

.inq-shifts-section {
    margin-bottom: 16px;
}

.inq-shifts-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.inquiry-success {
    text-align: center;
    padding: 30px 20px;
}

.inquiry-success i {
    font-size: 3rem;
    color: #27ae60;
    margin-bottom: 15px;
}

.inquiry-success h4 {
    font-size: 1.15rem;
    margin-bottom: 8px;
}

.inquiry-success p {
    color: #666;
    font-size: 0.9rem;
}

/* ========================================
   8. نموذج التواصل (بدون مضيف)
   ======================================== */
.contact-form-modal .inquiry-modal-header {
    background: linear-gradient(135deg, #2980b9 0%, #3498db 100%);
    color: #fff;
    border-radius: 20px 20px 0 0;
}

.contact-form-modal .inquiry-modal-close {
    color: rgba(255,255,255,0.8);
}

.contact-form-modal .btn-send-inquiry {
    background: #2980b9;
}

.contact-form-modal .btn-send-inquiry:hover {
    background: #2471a3;
}

/* ========================================
   9. بادج الرسائل غير المقروءة
   ======================================== */
.chat-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--wa-unread-bg, #25D366);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    padding: 0 5px;
    position: absolute;
    top: -4px;
    right: -4px;
}

/* بادج في dropdown */
.dropdown-item .chat-unread-badge {
    position: static;
    margin-right: auto;
    margin-left: 4px;
}

/* بادج في bottom nav */
.bottom-nav-item .chat-unread-dot {
    position: absolute;
    top: 4px;
    right: calc(50% - 16px);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color, #FF385C);
    border: 2px solid #fff;
}

/* ========================================
   10. معدل الاستجابة في صفحة الشاليه
   ======================================== */
.host-response-live {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--wa-teal);
    margin-top: 4px;
}

.host-response-live i {
    font-size: 0.7rem;
}

.host-response-live .rate-badge {
    background: #eafaf1;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

/* ========================================
   11. Responsive — Mobile-First WhatsApp Experience
   ======================================== */
@media (max-width: 768px) {
    .messages-page {
        height: 100%;
        height: calc(var(--app-height, 100vh) - 64px);
        position: relative;
        overflow: hidden;
    }
    
    .messages-container {
        height: 100%;
        height: calc(var(--app-height, 100vh) - 64px);
        position: relative;
    }
    
    .conv-list-panel {
        width: 100%;
        min-width: 100%;
        height: 100%;
        position: absolute;
        inset: 0;
        z-index: 10;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .conv-list-panel.has-active {
        transform: translateX(100%);
    }
    
    .chat-panel {
        position: absolute;
        inset: 0;
        z-index: 11;
        height: 100%;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .chat-panel.active {
        transform: translateX(0);
    }
    
    .chat-back-btn {
        display: flex;
    }
    
    .chat-msg {
        max-width: 85%;
    }
    
    .inquiry-date-row {
        grid-template-columns: 1fr;
    }
    
    .inquiry-modal {
        max-width: 95%;
        margin: 10px;
    }

    .inq-chalet-sub {
        max-width: 180px;
    }

    .inquiry-modal-body {
        padding: 12px 14px;
    }

    .inq-inline-group {
        gap: 8px;
    }

    .inq-inline-group label {
        font-size: 0.8rem;
    }
    
    .conv-list-header {
        padding: 0 14px;
    }
    
    /* safe-area لأجهزة بنوتش */
    .conv-list-header,
    .chat-header {
        padding-top: env(safe-area-inset-top, 0);
        height: calc(var(--wa-header-h) + env(safe-area-inset-top, 0));
    }
    
    .chat-input-bar {
        padding-bottom: max(6px, env(safe-area-inset-bottom, 6px));
    }
    
    /* منع أي تمرير على العناصر غير القابلة للسكرول */
    .chat-header,
    .chat-input-bar,
    .conv-list-header {
        touch-action: none;
        -webkit-touch-callout: none;
    }
    
    .quick-replies-bar {
        touch-action: pan-x;
    }
}

@media (max-width: 480px) {
    .conv-list-panel {
        width: 100%;
    }
    
    .chat-header {
        padding: 0 10px;
    }
    
    .chat-messages {
        padding: 8px 10px 6px;
    }
    
    .chat-input-bar {
        padding: 5px 6px;
        padding-bottom: max(5px, env(safe-area-inset-bottom, 5px));
    }
    
    .chat-header-price {
        display: none;
    }
    
    .msg-text {
        font-size: 0.88rem;
        padding-left: 55px;
    }
    
    .chat-msg {
        max-width: 88%;
    }
    
    /* textarea أصغر على الشاشات الصغيرة */
    #chatInput {
        font-size: 0.9rem;
        padding: 8px 12px;
    }
    
    .chat-send-btn {
        width: 40px;
        height: 40px;
        font-size: 0.95rem;
    }
}

/* ========================================
   12. تاب الرسائل في my-account
   ======================================== */
.account-messages-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.account-msg-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: #fff;
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    transition: all 0.2s;
}

.account-msg-item:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transform: translateY(-1px);
}

.account-msg-item.unread {
    border-right: 3px solid var(--primary-color, #FF385C);
}

.account-msg-thumb {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
    background: #f0f0f0;
}

.account-msg-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.account-msg-info {
    flex: 1;
    min-width: 0;
}

.account-msg-title {
    font-size: 0.92rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-msg-preview {
    font-size: 0.82rem;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.account-msg-time {
    font-size: 0.75rem;
    color: #aaa;
    white-space: nowrap;
}

/* ========================================
   13. إدارة الردود السريعة
   ======================================== */
.quick-replies-manage {
    margin-top: 20px;
}

.qr-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #f9f9f9;
    border-radius: 10px;
    margin-bottom: 8px;
}

.qr-item-title {
    font-weight: 600;
    min-width: 80px;
    color: var(--primary-color, #FF385C);
}

.qr-item-body {
    flex: 1;
    font-size: 0.88rem;
    color: #555;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.qr-item-actions {
    display: flex;
    gap: 6px;
}

.qr-item-actions button {
    background: none;
    border: none;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.qr-item-actions .qr-delete {
    color: #e74c3c;
}

.qr-item-actions .qr-delete:hover {
    background: #fce8e8;
}

/* ========================================
   14. Scrollbar styling
   ======================================== */
.conv-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.conv-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.conv-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.12);
    border-radius: 4px;
}

.conv-list::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.2);
}

/* ========================================
   15. فاصل التاريخ في المحادثة
   ======================================== */
.chat-date-separator {
    text-align: center;
    padding: 8px 0;
}

.chat-date-separator span {
    background: rgba(255,255,255,0.9);
    color: var(--wa-text-secondary);
    font-size: 0.72rem;
    padding: 4px 14px;
    border-radius: 8px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}

/* ========================================
   16. أنيموشن الكتابة
   ======================================== */
.typing-indicator {
    display: inline-flex;
    gap: 3px;
    padding: 10px 14px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.06);
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #90a4ae;
    animation: typingBounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}
