/* BabylonChat — نافذة الدردشة (عمودان على الحاسوب وشاشة واحدة على الهاتف) */
.chat-modal { padding: 12px; }
.chat-box { width: min(1040px, 100%); max-width: none; height: min(86vh, 760px); padding: 0; display: grid; grid-template-columns: 300px 1fr; overflow: hidden; gap: 0; }
.chat-side { border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--surface-2); }
.chat-me { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.chat-me b { display: block; font-size: 14px; }
.chat-me small { color: var(--ink-soft); font-size: 12px; }
.chat-status-sel { display: block; margin-top: 3px; font: inherit; font-size: 12px; padding: 2px 8px; min-height: 0; border-radius: 10px; width: auto; background: var(--surface); }
.chat-me .grow, .chat-room .grow, .chat-head .grow { flex: 1; min-width: 0; }
.chat-close-side { display: none; }
.chat-rooms { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.chat-sep { font-size: 11.5px; color: var(--ink-faint); padding: 8px 8px 2px; letter-spacing: .3px; }
.chat-room { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid transparent; border-radius: 20px; background: transparent; color: inherit; font: inherit; text-align: start; cursor: pointer; transition: background .2s; }
.chat-room:hover { background: var(--hover); }
.chat-room.on { background: var(--accent-soft); border-color: transparent; }
.chat-room b { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-room small { display: block; color: var(--ink-soft); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: none; display: inline-grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff; border: 0; padding: 0; cursor: pointer; overflow: hidden; }
.chat-avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.chat-avatar-txt.h0 { background: linear-gradient(135deg, #5b8dff, #2f6bff); }
.chat-avatar-txt.h1 { background: linear-gradient(135deg, #f7b84b, #e8930c); }
.chat-avatar-txt.h2 { background: linear-gradient(135deg, #a07bf8, #7a62f0); }
.chat-avatar-txt.h3 { background: linear-gradient(135deg, #4cc36a, #2fa84f); }
.chat-avatar-txt.h4 { background: linear-gradient(135deg, #f0688c, #e5446d); }
.chat-avatar-txt.h5 { background: linear-gradient(135deg, #3a4bd8, #8b5cf6); }
.chat-avatar-txt.h6 { background: linear-gradient(135deg, #f5a524, #d9820a); }
.chat-avatar-txt.h7 { background: linear-gradient(135deg, #2cc6d2, #0e97a3); }
.chat-avatar-gen { background: var(--brand-grad); font-size: 18px; }
.chat-avatar-me { position: relative; }
.chat-avatar-me::after { content: '✎'; position: absolute; bottom: -2px; inset-inline-start: -2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface-solid); color: var(--ink); font-size: 10px; display: grid; place-items: center; border: 1px solid var(--line); }
.chat-av-wrap { position: relative; flex: none; display: inline-flex; }
.chat-dot { position: absolute; bottom: 0; inset-inline-start: 0; width: 11px; height: 11px; border-radius: 50%; background: #b4bacb; border: 2px solid var(--surface-solid); }
.chat-dot.on { background: #37b24d; box-shadow: 0 0 0 3px rgba(55, 178, 77, .18); }
.chat-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.chat-head b { display: block; font-size: 15px; }
.chat-head small { color: var(--ink-soft); font-size: 12px; }
.chat-back { display: none; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; scroll-behavior: smooth; }
.chat-empty { text-align: center; margin: auto; }
.chat-day { text-align: center; margin: 8px 0 4px; }
.chat-day span { font-size: 11.5px; color: var(--ink-soft); background: var(--surface-2); border-radius: 999px; padding: 3px 12px; }
.chat-m { display: flex; align-items: flex-end; gap: 8px; max-width: 78%; animation: chatIn .25s var(--ease-out); }
.chat-m.mine { align-self: flex-end; flex-direction: row-reverse; }   /* RTL: رسائلي على اليسار كواتساب */
.chat-m:not(.mine) { align-self: flex-start; }
@keyframes chatIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.chat-bubble { background: var(--surface-2); border: 1px solid var(--line); border-radius: 20px 20px 20px 6px; padding: 8px 12px 6px; font-size: 14px; line-height: 1.55; position: relative; min-width: 90px; word-break: break-word; }
.chat-m.mine .chat-bubble { background: var(--accent-soft); border-color: transparent; border-radius: 20px 20px 6px 20px; }
.chat-who { display: block; font-size: 12px; color: var(--brand-dark); margin-bottom: 2px; }
.chat-bubble time { display: block; text-align: left; font-size: 10.5px; color: var(--ink-faint); margin-top: 2px; }
.chat-text a.chat-hash { color: var(--brand-dark); text-decoration: underline dotted; cursor: pointer; }
.chat-img { max-width: min(320px, 70vw); max-height: 320px; border-radius: 16px; display: block; }
.chat-voice audio { width: min(260px, 60vw); height: 36px; }
.chat-voice small { display: block; color: var(--ink-soft); font-size: 11px; }
.chat-refs { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.chat-ref { display: flex; flex-direction: column; gap: 1px; text-align: start; font: inherit; font-size: 12.5px; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 7px 12px; cursor: pointer; transition: border-color .2s; }
.chat-ref:hover { border-color: var(--brand); }
.chat-ref b { color: var(--brand-dark); }
.chat-ref-miss { display: inline-block; color: var(--ink-faint); font-size: 12px; }
.chat-mention { position: absolute; bottom: 70px; inset-inline: 14px; max-height: 240px; overflow-y: auto; background: var(--surface-solid); border: 1px solid var(--line); border-radius: 20px; padding: 6px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--menu-shadow); z-index: 2; }
.chat-main { position: relative; }
.chat-mention-item { display: flex; justify-content: space-between; gap: 10px; font: inherit; color: inherit; background: transparent; border: 0; border-radius: 14px; padding: 8px 10px; cursor: pointer; text-align: start; }
.chat-mention-item:hover { background: var(--accent-soft); }
.chat-mention-item small { color: var(--ink-soft); }
.chat-rec { display: flex; align-items: center; gap: 10px; padding: 8px 14px; font-size: 13px; border-top: 1px solid var(--line); background: var(--danger-bg); }
.chat-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #e5446d; animation: recBlink 1s infinite; }
@keyframes recBlink { 50% { opacity: .2; } }
.chat-composer { display: flex; align-items: flex-end; gap: 6px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--surface); }
.chat-composer textarea { flex: 1; min-height: 42px; max-height: 120px; resize: none; padding: 10px 14px; font-size: 14.5px; line-height: 1.4; border-radius: 21px; }
.chat-tool { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line2); background: var(--surface); color: var(--ink); font-size: 18px; cursor: pointer; flex: none; transition: background .2s, transform .15s; }
.chat-tool:active { transform: scale(.94); }
.chat-tool.on { background: var(--danger-solid); border-color: transparent; animation: recBlink 1.2s infinite; }
.chat-send { width: 44px; height: 42px; border-radius: 16px; border: 0; background: var(--brand); color: #fff; box-shadow: var(--brand-glow); font-size: 18px; cursor: pointer; flex: none; transform: scaleX(-1); }
.chat-main .msg { padding: 0 14px 8px; min-height: 0; }
.chat-ref-pop { position: fixed; inset: 0; z-index: 60; background: var(--scrim); display: grid; place-items: center; padding: 20px; }
.chat-ref-card { background: var(--surface-solid); border: 1px solid var(--card-line, transparent); border-radius: 28px; padding: 18px 20px; width: min(380px, 100%); display: grid; gap: 6px; font-size: 14px; box-shadow: var(--modal-shadow); }
.chat-ref-card .row { display: flex; gap: 8px; margin-top: 8px; }
.chat-ref-card b { font-size: 16px; color: var(--brand-dark); }
/* زر الشريط */
.chat-btn { position: relative; }
.chat-btn .tab-badge { position: absolute; top: -6px; inset-inline-start: -4px; }

@media (max-width: 720px) {
  .modal.chat-modal { padding: 0; align-items: stretch; }
  .modal .modal-box.chat-box { width: 100%; height: 100vh; height: 100dvh; max-height: none; border-radius: 0; grid-template-columns: 1fr; padding: 0; animation: none; }
  .modal .modal-box.chat-box::before { display: none; }
  .chat-side { border: 0; }
  .chat-close-side { display: inline-flex; }
  .chat-main { display: none; }
  .chat-modal.is-room .chat-side { display: none; }
  .chat-modal.is-room .chat-main { display: flex; }
  .chat-back { display: inline-flex; }
  .chat-m { max-width: 88%; }
  .chat-msgs { padding: 10px; }
}

/* ═══════════════════ لمسة راقية (v2): هيدر، فقاعات، مؤلّف رسائل، قوائم ═══════════════════ */
.chat-box { border-radius: 28px; box-shadow: var(--modal-shadow, 0 30px 80px rgba(15, 23, 42, .35)); }
.chat-side { background: linear-gradient(180deg, var(--surface-2), var(--surface)); }
.chat-me { padding: 16px 16px 14px; background: linear-gradient(135deg, rgba(47, 107, 255, .09), transparent 70%); }
.chat-me b { font-size: 15px; letter-spacing: .1px; }
.chat-rooms { scrollbar-width: thin; padding: 10px; gap: 2px; }
.chat-room { padding: 10px 12px; border-radius: 18px; transition: background .18s, transform .12s, box-shadow .18s; }
.chat-room:hover { background: var(--hover); }
.chat-room:active { transform: scale(.985); }
.chat-room.on { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--brand); }
.chat-avatar { box-shadow: 0 1px 4px rgba(15, 23, 42, .18); }
.chat-dot.on { animation: chatPulse 2.4s ease-in-out infinite; }
@keyframes chatPulse { 0%, 100% { box-shadow: 0 0 0 3px rgba(55, 178, 77, .18); } 50% { box-shadow: 0 0 0 5px rgba(55, 178, 77, .06); } }

.chat-head { padding: 12px 14px 12px 16px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); box-shadow: 0 6px 18px -14px rgba(15, 23, 42, .5); position: relative; z-index: 3; }
.chat-head b { font-size: 15.5px; }
.chat-icon-btn { width: 36px; height: 36px; border-radius: 12px; border: 1px solid transparent; background: transparent; color: var(--ink-soft); font-size: 18px; line-height: 1; cursor: pointer; display: inline-grid; place-items: center; flex: none; transition: background .18s, color .18s, transform .12s; font-family: inherit; }
.chat-icon-btn:hover { background: var(--hover); color: var(--ink); }
.chat-icon-btn:active { transform: scale(.92); }
.chat-icon-btn.chat-x:hover { background: var(--danger-bg); color: var(--danger); }
.chat-icon-btn[hidden] { display: none; }

.chat-msgs { padding: 18px 18px 10px; gap: 4px; scrollbar-width: thin;
  background: radial-gradient(1200px 400px at 100% 0, rgba(47, 107, 255, .05), transparent 60%), radial-gradient(900px 360px at 0 100%, rgba(139, 92, 246, .05), transparent 60%), var(--surface); }
.chat-day { margin: 12px 0 8px; }
.chat-day span { font-weight: 600; letter-spacing: .2px; background: color-mix(in srgb, var(--surface-2) 90%, transparent); border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(15, 23, 42, .06); }

.chat-m { max-width: min(78%, 560px); margin-top: 2px; }
.chat-bubble { background: var(--surface-solid, var(--surface)); border: 1px solid var(--line); border-radius: 20px 20px 20px 6px; padding: 8px 14px 6px; box-shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 6px 14px -10px rgba(15, 23, 42, .25); transition: box-shadow .2s; }
.chat-m:hover .chat-bubble { box-shadow: 0 1px 2px rgba(15, 23, 42, .08), 0 10px 22px -12px rgba(15, 23, 42, .35); }
.chat-m.mine .chat-bubble { background: var(--brand-grad, linear-gradient(135deg, #2f6bff, #5b8dff)); color: #fff; border-color: transparent; border-radius: 20px 20px 6px 20px; box-shadow: 0 2px 6px rgba(47, 107, 255, .28), 0 10px 22px -12px rgba(47, 107, 255, .55); }
.chat-m.mine .chat-bubble time { color: rgba(255, 255, 255, .78); }
.chat-m.mine .chat-text a.chat-hash { color: #fff; text-decoration-color: rgba(255, 255, 255, .7); }
.chat-m.mine .chat-voice small { color: rgba(255, 255, 255, .8); }
.chat-m.mine .chat-edited { color: rgba(255, 255, 255, .9); background: rgba(255, 255, 255, .18); }
.chat-who { font-weight: 700; }
.chat-img { border-radius: 14px; box-shadow: 0 2px 10px rgba(15, 23, 42, .18); }
.chat-ref { box-shadow: 0 1px 2px rgba(15, 23, 42, .06); color: var(--ink); }

/* تم التعديل — فوق محتوى الرسالة */
.chat-edited { display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; font-weight: 700; color: var(--ink-soft); background: var(--surface-2); border-radius: 999px; padding: 1px 8px; margin-bottom: 4px; }
/* رسالة محذوفة للجميع */
.chat-m.gone .chat-bubble, .chat-m.gone.mine .chat-bubble { background: transparent; border: 1px dashed var(--line2, var(--line)); box-shadow: none; color: var(--ink-faint); }
.chat-m.gone .chat-bubble time { color: var(--ink-faint); }
.chat-gone { font-style: italic; font-size: 13px; }

/* زر خيارات الرسالة */
.chat-bubble { padding-inline-end: 16px; }
.chat-m-menu { position: absolute; top: 4px; inset-inline-end: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(15, 23, 42, .12); color: inherit; font-size: 15px; line-height: 1; cursor: pointer; display: grid; place-items: center; opacity: 0; transform: scale(.85); transition: opacity .15s, transform .15s, background .15s; font-family: inherit; padding: 0; }
.chat-m.mine .chat-m-menu { background: rgba(255, 255, 255, .22); }
.chat-m:hover .chat-m-menu, .chat-m-menu:focus-visible { opacity: 1; transform: none; }
.chat-m-menu:hover { background: rgba(15, 23, 42, .22); }
.chat-m.mine .chat-m-menu:hover { background: rgba(255, 255, 255, .34); }
@media (hover: none) { .chat-m-menu { opacity: .7; transform: none; } }

/* قائمة منبثقة (خيارات الرسالة / خيارات الدردشة) */
.chat-pop { position: absolute; z-index: 70; min-width: 190px; background: var(--surface-solid, var(--surface)); border: 1px solid var(--line); border-radius: 18px; padding: 6px; box-shadow: var(--menu-shadow, 0 18px 40px rgba(15, 23, 42, .28)); display: flex; flex-direction: column; gap: 2px; animation: chatIn .15s var(--ease-out); }
.chat-pop[hidden] { display: none; }
.chat-pop-item { display: flex; align-items: center; gap: 10px; font: inherit; font-size: 13.5px; color: inherit; background: transparent; border: 0; border-radius: 12px; padding: 9px 12px; cursor: pointer; text-align: start; transition: background .15s; }
.chat-pop-item:hover { background: var(--hover); }
.chat-pop-item.danger { color: var(--danger); }
.chat-pop-item.danger:hover { background: var(--danger-bg); }
.chat-pop-item span { width: 20px; text-align: center; }
.chat-confirm { text-align: center; gap: 10px; }
.chat-confirm .row { justify-content: center; }

/* شريط التعديل */
.chat-editbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--line); background: var(--accent-soft); animation: chatIn .18s var(--ease-out); }
.chat-editbar[hidden] { display: none; }
.chat-editbar .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-editbar b { font-size: 12.5px; color: var(--brand-dark); }
.chat-editbar small { color: var(--ink-soft); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-editbar-ic { color: var(--brand); font-size: 16px; }
.chat-modal.is-editing .chat-send { background: linear-gradient(135deg, #2fa84f, #37b24d); }

/* مؤلّف الرسائل: كبسولة واحدة */
.chat-composer { margin: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px)); padding: 6px; gap: 4px; border: 1px solid var(--line); border-radius: 26px; background: var(--surface-solid, var(--surface)); box-shadow: 0 6px 22px -12px rgba(15, 23, 42, .45); align-items: flex-end; transition: border-color .2s, box-shadow .2s; }
.chat-composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus-ring, rgba(47, 107, 255, .18)), 0 6px 22px -12px rgba(15, 23, 42, .45); }
.chat-composer textarea { border: 0; background: transparent; box-shadow: none; padding: 10px 6px; min-height: 40px; }
.chat-composer textarea:focus { outline: none; box-shadow: none; border: 0; }
.chat-tool { width: 40px; height: 40px; border: 0; background: transparent; }
.chat-tool:hover { background: var(--hover); }
.chat-send { width: 42px; height: 42px; border-radius: 50%; background: var(--brand-grad, var(--brand)); transition: transform .15s, filter .15s; }
.chat-send:hover { filter: brightness(1.06); }
.chat-send:active { transform: scaleX(-1) scale(.92); }
.chat-rec { border-radius: 16px; margin: 0 12px; }
.chat-main .msg { padding: 0 18px 6px; }
.chat-empty { color: var(--ink-faint); font-size: 14px; padding: 40px 0; }

@media (max-width: 720px) {
  .chat-msgs { padding: 12px 10px 6px; }
  .chat-composer { margin: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px)); }
  .chat-icon-btn { width: 40px; height: 40px; }
}

/* ═══ v3: صندوق أنحف وأرشق، خط أنعم، ومشغّل صوت مختصر ═══ */
.chat-box { width: min(760px, 100%); height: min(78vh, 640px); grid-template-columns: 236px 1fr; border-radius: 26px; }
.chat-me { padding: 12px 12px 10px; }
.chat-room { padding: 8px 10px; }
.chat-avatar { width: 36px; height: 36px; font-size: 13px; }
.chat-avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.chat-head { padding: 9px 12px 9px 14px; }
.chat-head b { font-size: 14.5px; }
.chat-msgs { padding: 14px 14px 8px; }
.chat-m { max-width: min(76%, 380px); }
.chat-bubble { font-size: 14px; line-height: 1.65; padding: 7px 12px 5px; border-radius: 18px 18px 18px 5px; min-width: 70px; letter-spacing: .1px; }
.chat-m.mine .chat-bubble { border-radius: 18px 18px 5px 18px; }
.chat-text { font-weight: 450; }
.chat-who { font-size: 11.5px; }
.chat-bubble time { font-size: 10px; margin-top: 1px; }
.chat-img { max-width: min(250px, 62vw); max-height: 240px; border-radius: 12px; }
.chat-composer { margin: 6px 10px calc(10px + env(safe-area-inset-bottom, 0px)); border-radius: 22px; }
.chat-composer textarea { font-size: 14px; }
.chat-tool, .chat-send { width: 38px; height: 38px; }
.chat-send { font-size: 16px; }
.chat-day span { font-size: 11px; padding: 2px 11px; }

.chat-voice { display: flex; align-items: center; gap: 9px; min-width: 190px; padding: 2px 0; }
.chat-vplay { width: 32px; height: 32px; flex: none; border-radius: 50%; border: 0; background: var(--brand); color: #fff; font-size: 12px; line-height: 1; cursor: pointer; display: grid; place-items: center; transition: transform .12s, filter .15s; font-family: inherit; padding: 0; }
.chat-vplay:hover { filter: brightness(1.08); }
.chat-vplay:active { transform: scale(.92); }
.chat-vbar { position: relative; flex: 1; height: 6px; border-radius: 3px; background: rgba(15, 23, 42, .14); cursor: pointer; min-width: 90px; }
.chat-vbar::before { content: ''; position: absolute; inset: -9px 0; }
.chat-vfill { position: absolute; inset-block: 0; inset-inline-start: 0; width: 0; border-radius: 3px; background: var(--brand); }
.chat-vtime { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--ink-soft); flex: none; min-width: 30px; text-align: end; }
.chat-m.mine .chat-vplay { background: #fff; color: var(--brand); }
.chat-m.mine .chat-vbar { background: rgba(255, 255, 255, .3); }
.chat-m.mine .chat-vfill { background: #fff; }
.chat-m.mine .chat-vtime { color: rgba(255, 255, 255, .88); }
.chat-voice.playing .chat-vplay { box-shadow: 0 0 0 4px rgba(47, 107, 255, .18); }

@media (max-width: 720px) {
  .modal .modal-box.chat-box { width: 100%; height: 100dvh; }
  .chat-m { max-width: 86%; }
}
