/* ==========================================================================
   ويدجت الدردشة العائم (Chat Bubble + Panel) — مستقل ذاتياً
   ========================================================================== */
.chat-widget {
    position: fixed;
    bottom: 22px;
    inset-inline-end: 22px;
    z-index: 9999;
    font-family: 'Readex Pro', 'Baloo Bhaijaan 2', system-ui, sans-serif;
}

.chat-widget__bubble {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: #ff6f1e;
    border: 2px solid #171717;
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
    transition: transform .2s ease;
    position: relative;
}

.chat-widget__bubble:hover { transform: scale(1.06); }
.chat-widget__bubble svg { width: 26px; height: 26px; }

.chat-widget__panel {
    position: absolute;
    bottom: 70px;
    inset-inline-end: 0;
    width: 340px;
    max-width: calc(100vw - 30px);
    height: 440px;
    max-height: calc(100vh - 120px);
    background: #fdfbf9;
    border: 2px solid #171717;
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* إصلاح: زر الإغلاق يعمل (السمة hidden تتجاوز display: flex) */
.chat-widget__panel[hidden] { display: none; }

.chat-widget__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px;
    background: #ff6f1e;
    color: #171717;
    border-bottom: 2px solid #171717;
}

.chat-widget__head-info strong { font-size: 16px; display: block; line-height: 1.2; }
.chat-widget__head-info span { font-size: 12px; opacity: .85; }

.chat-widget__close {
    background: none;
    border: none;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}

.chat-widget__messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f7efe9;
}

.chat-widget__empty { text-align: center; color: #6b6257; font-size: 13px; padding: 20px 0; }

.chat-msg { max-width: 82%; display: flex; flex-direction: column; }
.chat-msg--mine { align-self: flex-start; }
.chat-msg--other { align-self: flex-end; }

.chat-msg__meta {
    font-size: 11px;
    color: #6b6257;
    margin-bottom: 3px;
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.chat-msg--other .chat-msg__meta { justify-content: flex-end; }

.chat-msg__role {
    font-size: 10px;
    font-weight: 700;
    color: #fdfbf9;
    background: #171717;
    border-radius: 6px;
    padding: 1px 6px;
}

.chat-msg__body {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-msg--mine .chat-msg__body { background: #fdfbf9; border: 1.5px solid #171717; }
.chat-msg--other .chat-msg__body { background: #ff6f1e; color: #171717; border: 1.5px solid #171717; }

.chat-widget__fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px;
    background: #f7efe9;
    border-bottom: 1.5px solid #171717;
}

.chat-widget__fields[hidden] { display: none; }

.chat-widget__fields-title {
    font-size: 12px;
    font-weight: 700;
    color: #6b6257;
    text-align: center;
}

.chat-widget__fields .chat-widget__input { text-align: center; }

.chat-widget__note {
    padding: 6px 14px 10px;
    font-size: 12px;
    color: #b3261e;
    background: #fdfbf9;
}

.chat-widget__note[hidden] { display: none; }

.chat-widget__form {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1.5px solid #171717;
    background: #fdfbf9;
}

.chat-widget__input {
    flex: 1;
    min-width: 0;
    border: 1.5px solid #171717;
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 14px;
    background: #fff;
    font-family: inherit;
}

.chat-widget__input:focus { outline: none; border-color: #ff6f1e; }

.chat-widget__send {
    width: 42px;
    height: 42px;
    flex: none;
    border-radius: 50%;
    border: 1.5px solid #171717;
    background: #ff6f1e;
    color: #fff;
    cursor: pointer;
    display: grid;
    place-items: center;
}

.chat-widget__send svg { width: 18px; height: 18px; }

@media (max-width: 480px) {
    .chat-widget__panel { width: calc(100vw - 30px); }
}

/* --------------------------------------------------------------------------
   دردشة الإدارة — صندوق محادثات (قائمة يمين + محادثة يسار)
   -------------------------------------------------------------------------- */
.chat-inbox {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 16px;
    align-items: start;
}

@media (max-width: 880px) {
    .chat-inbox { grid-template-columns: 1fr; }
}

.chat-inbox__list { overflow: hidden; }

.chat-threads { max-height: 560px; overflow-y: auto; }

.chat-thread {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid #eee7dd;
    text-decoration: none;
    color: inherit;
    transition: background .15s ease;
}

.chat-thread:hover { background: #faf6f1; }

.chat-thread.is-active { background: #f7efe9; box-shadow: inset 3px 0 0 #ff6f1e; }

.chat-thread__avatar {
    width: 42px;
    height: 42px;
    flex: none;
    border: 1.5px solid #171717;
    border-radius: 50%;
    background: #fdfbf9;
    display: grid;
    place-items: center;
    font-family: 'Baloo Bhaijaan 2', 'Readex Pro', sans-serif;
    font-weight: 700;
    font-size: 18px;
    color: #171717;
}

.chat-thread__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }

.chat-thread__name {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    font-size: 14.5px;
    color: #171717;
}

.chat-thread__name .chip { font-size: 10px; padding: 1px 8px; }

.chat-thread__snippet {
    font-size: 12.5px;
    color: #6b6257;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-thread__meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }

.chat-inbox__pane { display: flex; flex-direction: column; overflow: hidden; }

.chat-inbox__placeholder { padding: 70px 20px; text-align: center; color: #6b6257; }
.chat-inbox__placeholder svg { width: 40px; height: 40px; margin: 0 auto 10px; opacity: .5; }
.chat-inbox__placeholder p { margin: 0; }

.chat-thread-view {
    flex: 1;
    height: 440px;
    overflow-y: auto;
    padding: 18px;
    background: #f7efe9;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-bubble { display: flex; flex-direction: column; gap: 3px; max-width: 78%; }
.chat-bubble--user { align-self: flex-start; }
.chat-bubble--admin { align-self: flex-end; }

.chat-bubble__meta { font-size: 11px; color: #6b6257; }
.chat-bubble--admin .chat-bubble__meta { text-align: end; }

.chat-bubble__text {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-bubble--user .chat-bubble__text { background: #fdfbf9; border: 1.5px solid #171717; }
.chat-bubble--admin .chat-bubble__text { background: #ff6f1e; color: #1a1a1a; border: 1.5px solid #171717; }

.chat-inbox__form {
    display: flex;
    gap: 10px;
    padding: 12px;
    border-top: 1.5px solid #171717;
    background: #fdfbf9;
    align-items: flex-end;
}

.chat-inbox__form textarea {
    flex: 1;
    min-width: 0;
    border: 1.5px solid #171717;
    border-radius: 12px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    min-height: 46px;
    max-height: 140px;
}

.chat-inbox__form textarea:focus { outline: none; border-color: #ff6f1e; }
