/* BabylonChat — نافذة الدردشة (زجاجية راقية، عمودان على الحاسوب وشاشة واحدة على الهاتف) */
.chat-modal { padding: 16px; }
.chat-box { width: min(980px, 100%); max-width: none; height: min(84vh, 720px); padding: 0; display: grid; grid-template-columns: 290px 1fr; overflow: hidden; gap: 0; border-radius: 24px; }
/* «فتح الطلب» من الدردشة: قائمة الطلب فوقها، وما يُفتح منها (تعديل/ملاحظات/تاريخ/وصل) فوق القائمة */
.om-modal { z-index: 72; }
#edit-modal, #notes-modal, #history-modal, #receipt-modal, #confirm-modal { z-index: 80; }
.om-box { width: min(440px, 100%); display: grid; gap: 14px; padding: 22px; max-height: 92vh; overflow-y: auto; }
.om-ic { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; vertical-align: -0.2em; }
.om-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.om-head h2 { margin: 0; display: flex; align-items: center; gap: 8px; font-family: Consolas, ui-monospace, monospace; direction: ltr; font-size: 19px; color: var(--ink); }
.om-head h2 .om-ic { color: var(--brand); width: 22px; height: 22px; }
.om-state { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; padding: 5px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--brand-dark); border: 1px solid rgba(34,211,238,.28); }
.om-state.self { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.om-state.sched { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.om-state.pending { background: rgba(255,255,255,.06); color: var(--ink-soft); border-color: var(--line); }
.om-rows { display: grid; }
.om-row { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 11px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.om-row:last-child { border-bottom: 0; }
.om-k { color: var(--ink-soft); flex: none; }
.om-v { font-weight: 700; text-align: end; min-width: 0; overflow-wrap: anywhere; }
.om-phone { color: var(--ink); text-decoration: underline dotted; text-underline-offset: 4px; }
.om-badge { display: inline-block; padding: 2px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--accent-soft); color: var(--brand-dark); border: 1px solid rgba(34,211,238,.28); }
.om-badge.self { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.om-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
.om-btn { display: inline-flex; align-items: center; gap: 7px; font: inherit; font-size: 13.5px; font-weight: 700; color: var(--ink); background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 999px; padding: 8px 15px; cursor: pointer; transition: background .15s, transform .15s, border-color .15s; }
.om-btn:hover { background: rgba(255,255,255,.12); }
.om-btn:active { transform: scale(.96); }
.om-btn.primary { background: var(--brand-grad); color: #0b1020; border-color: transparent; }
.om-btn.amber { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.om-btn.green { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.om-foot { display: flex; justify-content: flex-start; }


.ci { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; vertical-align: -0.2em; }
.chat-icon-btn { width: 34px; height: 34px; border-radius: 10px; border: 0; background: transparent; color: var(--ink-soft); display: inline-grid; place-items: center; cursor: pointer; flex: none; transition: background .15s, color .15s; }
.chat-icon-btn:hover { background: rgba(255,255,255,.09); color: var(--ink); }
.chat-icon-btn .ci { width: 19px; height: 19px; }

/* ── الجانب ── */
.chat-side { border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: rgba(255,255,255,.03); }
.chat-me { display: flex; align-items: center; gap: 10px; padding: 14px 14px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chat-me .grow { flex: 1; min-width: 0; }
.chat-me b { display: block; font-size: 14px; line-height: 1.3; }
.chat-me small { color: var(--ink-soft); font-size: 12px; }
.chat-status-sel { order: 5; flex-basis: 100%; font: inherit; font-size: 12px; padding: 5px 10px; border-radius: 10px; background: rgba(0,0,0,.18); width: 100%; }
:root[data-theme="light"] .chat-status-sel { background: rgba(0,0,0,.05); }
.chat-close-side { display: none; }
.chat-rooms { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; scrollbar-width: thin; }
.chat-sep { font-size: 11px; color: var(--ink-faint); padding: 12px 10px 4px; letter-spacing: .4px; }
.chat-room { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border: 0; border-radius: 14px; background: transparent; color: inherit; font: inherit; text-align: start; cursor: pointer; transition: background .15s; position: relative; }
.chat-room:hover { background: rgba(255,255,255,.06); }
.chat-room.on { background: var(--accent-soft); }
.chat-room.on::before { content: ''; position: absolute; inset-inline-start: 0; top: 22%; bottom: 22%; width: 3px; border-radius: 3px; background: var(--brand); }
.chat-room .grow { flex: 1; min-width: 0; }
.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-room .tab-badge { position: static; }
.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: #0b1020; border: 0; padding: 0; cursor: pointer; overflow: hidden; }
.chat-avatar.sm { width: 28px; height: 28px; font-size: 11px; cursor: default; }
.chat-avatar-txt.h0 { background: linear-gradient(135deg, #67e8f9, #60a5fa); }
.chat-avatar-txt.h1 { background: linear-gradient(135deg, #fde68a, #fb923c); }
.chat-avatar-txt.h2 { background: linear-gradient(135deg, #c4b5fd, #a78bfa); }
.chat-avatar-txt.h3 { background: linear-gradient(135deg, #86efac, #34d399); }
.chat-avatar-txt.h4 { background: linear-gradient(135deg, #fca5a5, #f472b6); }
.chat-avatar-txt.h5 { background: linear-gradient(135deg, #a5f3fc, #818cf8); }
.chat-avatar-txt.h6 { background: linear-gradient(135deg, #fcd34d, #f59e0b); }
.chat-avatar-txt.h7 { background: linear-gradient(135deg, #99f6e4, #2dd4bf); }
.chat-avatar-gen { background: var(--brand-grad); color: #0b1020; }
.chat-avatar-gen .ci { width: 20px; height: 20px; }
.chat-avatar-me { position: relative; }
.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: #6b7280; border: 2px solid var(--surface-solid); }
.chat-dot.on { background: #22c55e; box-shadow: 0 0 8px rgba(34,197,94,.7); }

/* ── الرأس ── */
.chat-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.03); }
.chat-head .grow { flex: 1; min-width: 0; }
.chat-head b { display: block; font-size: 15.5px; line-height: 1.3; }
.chat-head small { color: var(--ink-soft); font-size: 12px; }
.chat-back { display: none; }

/* ── الرسائل ── */
.chat-msgs { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; scrollbar-width: thin; }
.chat-empty { text-align: center; margin: auto; }
.chat-day { text-align: center; margin: 12px 0 6px; }
.chat-day span { font-size: 11px; color: var(--ink-soft); background: rgba(255,255,255,.06); border-radius: 999px; padding: 3px 12px; }
.chat-m { display: flex; align-items: flex-end; gap: 7px; max-width: min(72%, 520px); animation: chatIn .22s var(--ease-out); }
.chat-m.mine { align-self: flex-end; flex-direction: row-reverse; }
.chat-m:not(.mine) { align-self: flex-start; }
@keyframes chatIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.chat-bubble { background: rgba(255,255,255,.075); border: 1px solid rgba(255,255,255,.07); border-radius: 18px 18px 18px 5px; padding: 7px 12px 5px; font-size: 14px; line-height: 1.6; position: relative; min-width: 64px; width: fit-content; max-width: 100%; word-break: break-word; overflow-wrap: anywhere; }
.chat-m.mine .chat-bubble { background: linear-gradient(135deg, rgba(34,211,238,.2), rgba(99,102,241,.2)); border-color: rgba(34,211,238,.22); border-radius: 18px 18px 5px 18px; }
:root[data-theme="light"] .chat-bubble { background: rgba(15,23,42,.05); border-color: rgba(15,23,42,.06); }
:root[data-theme="light"] .chat-m.mine .chat-bubble { background: linear-gradient(135deg, rgba(34,211,238,.22), rgba(99,102,241,.14)); }
.chat-who { display: block; font-size: 11.5px; font-weight: 700; color: var(--brand-dark); margin-bottom: 1px; }
.chat-edited { display: block; font-size: 10.5px; color: var(--ink-faint); margin-bottom: 1px; letter-spacing: .2px; }
.chat-bubble time { display: block; text-align: end; font-size: 10px; color: var(--ink-faint); margin-top: 1px; line-height: 1.4; }
.chat-text { white-space: normal; }
.chat-text a.chat-hash { color: var(--brand-dark); text-decoration: underline dotted; cursor: pointer; }
.chat-cap { margin-top: 5px; }
.chat-gone { display: flex; align-items: center; gap: 6px; color: var(--ink-faint); font-size: 13px; font-style: italic; padding: 2px 0; }
.chat-bubble.is-gone { background: transparent; border-style: dashed; border-color: var(--line); }

/* قائمة خيارات الرسالة */
.chat-more { position: absolute; top: 3px; inset-inline-end: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.35); color: #fff; display: grid; place-items: center; cursor: pointer; opacity: 0; transition: opacity .15s; padding: 0; }
.chat-more .ci { width: 14px; height: 14px; stroke-width: 3; }
.chat-m:hover .chat-more, .chat-more:focus-visible { opacity: 1; }
@media (hover: none) { .chat-more { opacity: .75; } }
.chat-menu { position: fixed; z-index: 90; min-width: 170px; background: var(--surface-solid); border: 1px solid var(--line); border-radius: 14px; padding: 5px; box-shadow: 0 18px 50px rgba(0,0,0,.5); display: grid; gap: 1px; }
.chat-menu[hidden] { display: none; }
.chat-menu button { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 13.5px; padding: 9px 12px; border-radius: 10px; cursor: pointer; text-align: start; }
.chat-menu button:hover { background: var(--accent-soft); }
.chat-menu button.danger { color: var(--danger); }
.chat-menu button.danger:hover { background: var(--danger-bg); }

/* صورة */
.chat-img-link { display: block; }
.chat-img { max-width: min(230px, 56vw); max-height: 250px; border-radius: 12px; display: block; object-fit: cover; }

/* مشغّل الصوت */
.chat-voice { display: flex; align-items: center; gap: 9px; min-width: 190px; padding: 3px 0 1px; }
.chat-play { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--brand-grad); color: #0b1020; display: grid; place-items: center; cursor: pointer; flex: none; padding: 0; transition: transform .15s; }
.chat-play:active { transform: scale(.92); }
.chat-play .ci { width: 15px; height: 15px; fill: currentColor; stroke: none; }
.chat-wave { display: flex; align-items: center; gap: 2px; height: 28px; flex: 1; min-width: 110px; cursor: pointer; direction: rtl; }
.chat-wave i { display: block; flex: 1; max-width: 4px; min-width: 2px; border-radius: 2px; background: currentColor; opacity: .3; transition: opacity .12s; }
.chat-wave i.w0 { height: 35%; } .chat-wave i.w1 { height: 60%; } .chat-wave i.w2 { height: 85%; } .chat-wave i.w3 { height: 45%; }
.chat-wave i.w4 { height: 100%; } .chat-wave i.w5 { height: 55%; } .chat-wave i.w6 { height: 75%; } .chat-wave i.w7 { height: 40%; }
.chat-wave i.p { opacity: 1; color: var(--brand); }
.chat-vtime { font-size: 11px; color: var(--ink-soft); font-variant-numeric: tabular-nums; min-width: 30px; text-align: end; }

/* بطاقة الطلب داخل الرسالة */
.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: rgba(0,0,0,.2); border: 1px solid var(--line); border-radius: 12px; padding: 7px 11px; cursor: pointer; transition: border-color .15s; }
:root[data-theme="light"] .chat-ref { background: rgba(15,23,42,.05); }
.chat-ref:hover { border-color: var(--brand); }
.chat-ref b { color: var(--brand-dark); display: flex; align-items: center; gap: 6px; }
.chat-ref-miss { display: inline-block; color: var(--ink-faint); font-size: 12px; border: 0; background: transparent; padding: 0; cursor: default; }

/* الإكمال بـ# */
.chat-mention { position: absolute; bottom: 74px; inset-inline: 16px; max-height: 240px; overflow-y: auto; background: var(--surface-solid); border: 1px solid var(--line); border-radius: 14px; padding: 6px; display: flex; flex-direction: column; gap: 2px; box-shadow: 0 18px 50px rgba(0,0,0,.45); z-index: 5; }
.chat-mention[hidden] { display: none; }
.chat-mention-item { display: flex; justify-content: space-between; gap: 10px; font: inherit; color: inherit; background: transparent; border: 0; border-radius: 10px; padding: 8px 11px; cursor: pointer; text-align: start; }
.chat-mention-item:hover { background: var(--accent-soft); }
.chat-mention-item small { color: var(--ink-soft); }

/* تسجيل / تعديل */
.chat-rec, .chat-editbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; font-size: 13px; border-top: 1px solid var(--line); }
.chat-rec { background: var(--danger-bg); }
.chat-rec[hidden], .chat-editbar[hidden] { display: none; }
.chat-rec-dot { width: 9px; height: 9px; border-radius: 50%; background: #ef4444; animation: recBlink 1s infinite; }
@keyframes recBlink { 50% { opacity: .2; } }
.chat-editbar { background: var(--accent-soft); color: var(--brand-dark); }
.chat-editbar .grow { flex: 1; min-width: 0; }
.chat-editbar b { display: block; font-size: 12.5px; }
.chat-editbar small { display: block; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* المؤلّف */
.chat-composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: rgba(255,255,255,.03); }
.chat-composer textarea { flex: 1; min-height: 40px; max-height: 120px; resize: none; padding: 9px 14px; font-size: 14px; line-height: 1.5; border-radius: 20px; }
.chat-tool { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.07); color: var(--ink-soft); display: grid; place-items: center; cursor: pointer; flex: none; transition: background .15s, color .15s, transform .15s; padding: 0; }
.chat-tool:hover { background: rgba(255,255,255,.13); color: var(--ink); }
.chat-tool:active { transform: scale(.93); }
.chat-tool .ci { width: 19px; height: 19px; }
.chat-tool.on { background: var(--danger-solid); color: #fff; animation: recBlink 1.2s infinite; }
.chat-send { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--brand-grad); color: #0b1020; display: grid; place-items: center; cursor: pointer; flex: none; padding: 0; transition: transform .15s; }
.chat-send:active { transform: scale(.93); }
.chat-send .ci { width: 18px; height: 18px; transform: scaleX(-1); }
.chat-main .msg { padding: 0 16px 8px; min-height: 0; }

/* بطاقة الطلب المنبثقة */
.chat-ref-pop { position: fixed; inset: 0; z-index: 60; background: rgba(5,8,22,.6); display: grid; place-items: center; padding: 20px; }
.chat-ref-pop[hidden] { display: none; }
.chat-ref-card { background: var(--surface-solid); border: 1px solid var(--line); border-radius: 20px; padding: 18px; width: min(360px, 100%); display: grid; gap: 12px; font-size: 14px; box-shadow: 0 30px 80px rgba(0,0,0,.55); }
.chat-ref-head { display: flex; align-items: center; gap: 12px; }
.chat-ref-head b { display: block; font-size: 16px; color: var(--brand-dark); }
.chat-ref-head small { display: flex; align-items: center; gap: 5px; color: var(--ink-soft); font-size: 12px; }
.chat-ref-ic { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: var(--accent-soft); color: var(--brand); flex: none; }
.chat-ref-ic .ci { width: 22px; height: 22px; }
.chat-ref-body { display: grid; gap: 4px; padding: 10px 12px; border-radius: 12px; background: rgba(255,255,255,.05); border: 1px solid var(--line); line-height: 1.6; }
.chat-ref-card .row { display: flex; gap: 8px; }
.chat-ref-card .row .btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }

/* زر الشريط */
.chat-btn { position: relative; }
.chat-btn .tab-badge { position: absolute; top: -6px; inset-inline-start: -4px; }

/* أدوات المدير: تنظيف الدردشة */
.chat-clean { padding: 10px 12px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.chat-clean-body { display: grid; gap: 8px; font-size: 13px; }
.chat-clean-body[hidden], .chat-mgr[hidden] { display: none; }
.chat-clean select { margin-inline-start: 6px; }
.chat-clean .btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }

@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-grid; }
  .chat-main { display: none; }
  .chat-modal.is-room .chat-side { display: none; }
  .chat-modal.is-room .chat-main { display: flex; }
  .chat-back { display: inline-grid; }
  .chat-m { max-width: 86%; }
  .chat-msgs { padding: 12px; }
}
