/* ============================================================
   سامان — chat UI (admin two-pane + customer page) + toasts
   ============================================================ */
.chat-wrap { display: grid; grid-template-columns: 330px 1fr; height: calc(100vh - 68px - 0px); }
.chat-list { border-inline-start: 1px solid var(--border); background: #fff; display: flex; flex-direction: column; overflow: hidden; }
.chat-list-head { padding: 16px 18px 12px; border-bottom: 1px solid var(--slate-100); }
.chat-list-head h3 { font-size: 16px; font-weight: 800; color: var(--navy-900); }
.chat-search { position: relative; margin-top: 12px; }
.chat-search input { width: 100%; padding: 9px 38px 9px 12px; border: 1.5px solid var(--slate-200); border-radius: 10px; font-family: inherit; font-size: 13.5px; background: var(--slate-50); }
.chat-search input:focus { outline: none; border-color: var(--green-400); background: #fff; box-shadow: 0 0 0 3px var(--green-50); }
.chat-search svg { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--slate-400); }
.chat-filters { display: flex; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--slate-100); flex-wrap: wrap; }
.chat-filters .cf { font-size: 12px; font-weight: 600; padding: 5px 11px; border-radius: 8px; color: var(--slate-500); cursor: pointer; border: 1.5px solid var(--slate-200); }
.chat-filters .cf.on { background: var(--navy-900); color: #fff; border-color: var(--navy-900); }

.conv-scroll { overflow-y: auto; flex: 1; }
.conv-item { display: flex; gap: 12px; padding: 13px 16px; cursor: pointer; border-bottom: 1px solid var(--slate-50); transition: background .12s; position: relative; }
.conv-item:hover { background: var(--slate-50); }
.conv-item.active { background: var(--green-50); }
.conv-item.active::before { content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 3px; background: var(--green-500); }
.conv-av { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-weight: 800; flex: none; position: relative; }
.conv-av .pres { position: absolute; bottom: -1px; left: -1px; width: 13px; height: 13px; border-radius: 50%; border: 2.5px solid #fff; background: var(--slate-300); }
.conv-av .pres.on { background: var(--green-500); }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; align-items: center; gap: 8px; }
.conv-name { font-size: 14px; font-weight: 700; color: var(--navy-900); }
.conv-time { margin-inline-start: auto; font-size: 11px; color: var(--slate-400); white-space: nowrap; }
.conv-sub { font-size: 12.5px; color: var(--slate-500); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-prev { font-size: 12.5px; color: var(--slate-400); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.conv-unread { margin-inline-start: auto; min-width: 19px; height: 19px; padding: 0 6px; border-radius: 999px; background: var(--green-500); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; }
.pri-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.pri-high { background: var(--danger); } .pri-med { background: var(--warn); } .pri-normal { background: var(--slate-300); }

/* ---- thread pane ---- */
.thread { display: flex; flex-direction: column; overflow: hidden; background: var(--slate-50); }
.thread-empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--slate-400); }
.thread-empty .ic { width: 76px; height: 76px; border-radius: 22px; background: #fff; border: 1px solid var(--border); display: grid; place-items: center; margin: 0 auto 16px; color: var(--slate-300); }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 13px 20px; background: #fff; border-bottom: 1px solid var(--border); flex: none; }
.thread-head .conv-av { width: 42px; height: 42px; border-radius: 11px; }
.thread-head .ti .nm { font-size: 15px; font-weight: 800; color: var(--navy-900); }
.thread-head .ti .pres-txt { font-size: 12px; color: var(--slate-400); display: flex; align-items: center; gap: 6px; }
.thread-head .ti .pres-txt .d { width: 7px; height: 7px; border-radius: 50%; background: var(--slate-300); }
.thread-head .ti .pres-txt .d.on { background: var(--green-500); }
.thread-actions { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; }

.msgs { flex: 1; overflow-y: auto; padding: 22px 26px; display: flex; flex-direction: column; gap: 9px;
  background-image: radial-gradient(var(--slate-200) 0.8px, transparent 0.8px); background-size: 22px 22px; }
.bubble-row { display: flex; }
.bubble-row.mine { justify-content: flex-end; }
.bubble-row.theirs { justify-content: flex-start; }
.bubble { max-width: 68%; padding: 9px 13px 7px; border-radius: 16px; box-shadow: var(--sh-xs); position: relative; }
.bubble-row.theirs .bubble { background: #fff; border-bottom-right-radius: 5px; }
.bubble-row.mine .bubble { background: var(--green-500); color: #fff; border-bottom-left-radius: 5px; }
.btext { font-size: 14px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; }
.bmeta { display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 3px; font-size: 10.5px; opacity: .75; }
.bubble-row.theirs .bmeta { color: var(--slate-400); }
.bmeta .tick { width: 16px; height: 16px; opacity: .9; }
.bmeta .tick.seen { color: #bfe9ff; }
.bubble-row.theirs .bubble .btext { color: var(--slate-700); }

.composer { display: flex; align-items: flex-end; gap: 10px; padding: 14px 18px; background: #fff; border-top: 1px solid var(--border); flex: none; }
.composer textarea { flex: 1; resize: none; max-height: 120px; min-height: 44px; padding: 11px 15px; border: 1.5px solid var(--slate-200); border-radius: 14px; font-family: inherit; font-size: 14px; line-height: 1.6; background: var(--slate-50); }
.composer textarea:focus { outline: none; border-color: var(--green-400); background: #fff; box-shadow: 0 0 0 3px var(--green-50); }
.send-btn { width: 46px; height: 46px; border-radius: 13px; background: var(--green-500); color: #fff; display: grid; place-items: center; flex: none; box-shadow: var(--sh-green); transition: .15s; }
.send-btn:hover { background: var(--green-600); }
.send-btn:disabled { background: var(--slate-200); color: var(--slate-400); box-shadow: none; cursor: not-allowed; }
.typing { font-size: 12px; color: var(--green-600); padding: 2px 26px 0; height: 16px; }

/* status pill in thread */
.tstat { font-size: 11.5px; font-weight: 700; padding: 5px 11px; border-radius: 999px; }
.tstat.open { background: var(--green-50); color: var(--green-700); }
.tstat.pending { background: #fdf4e3; color: #a8761a; }
.tstat.closed { background: var(--slate-100); color: var(--slate-500); }

/* ---- toast ---- */
.toast-host { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast { background: var(--navy-900); color: #fff; padding: 12px 20px; border-radius: 12px; font-size: 13.5px; font-weight: 600; box-shadow: var(--sh-lg); display: flex; align-items: center; gap: 10px; animation: toastIn .3s cubic-bezier(.2,.8,.3,1); }
.toast .ti { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--green-500); flex: none; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px); } }

/* ---- generic modal (admin) ---- */
.modal-back { position: fixed; inset: 0; background: rgba(7,23,42,.55); backdrop-filter: blur(3px); z-index: 150; display: none; align-items: center; justify-content: center; padding: 30px 20px; }
.modal-back.show { display: flex; }
.modal { background: #fff; border-radius: var(--r-xl); width: 100%; max-width: 460px; box-shadow: var(--sh-lg); animation: toastIn .25s ease; overflow: hidden; }
.modal-top { padding: 18px 22px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.modal-top h3 { font-size: 17px; font-weight: 800; color: var(--navy-900); }
.modal-close { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--slate-500); background: var(--slate-100); }
.modal-close:hover { background: var(--slate-200); }
.modal-body { padding: 20px 22px; }
.mfield { margin-bottom: 15px; }
.mfield label { display: block; font-size: 13px; font-weight: 600; color: var(--slate-600); margin-bottom: 7px; }
.mfield input, .mfield select, .mfield textarea { width: 100%; padding: 11px 13px; border: 1.5px solid var(--slate-200); border-radius: 10px; font-family: inherit; font-size: 14px; background: #fff; }
.mfield input:focus, .mfield select:focus, .mfield textarea:focus { outline: none; border-color: var(--green-500); box-shadow: 0 0 0 3px var(--green-50); }

/* ---- toggle switch for user status ---- */
.switch { position: relative; width: 42px; height: 24px; flex: none; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--slate-300); border-radius: 999px; transition: .2s; }
.switch .track::before { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; top: 3px; right: 3px; transition: .2s; box-shadow: var(--sh-xs); }
.switch input:checked + .track { background: var(--green-500); }
.switch input:checked + .track::before { transform: translateX(-18px); }

.row-actions { display: flex; gap: 6px; align-items: center; }
.ico-btn { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: var(--slate-500); background: var(--slate-50); transition: .15s; border: 1px solid transparent; }
.ico-btn:hover { background: var(--slate-100); color: var(--navy-900); }
.ico-btn.danger:hover { background: #fdeaea; color: var(--danger); }
.ico-btn.ok:hover { background: var(--green-50); color: var(--green-700); }

@media (max-width: 860px) {
  .chat-wrap { grid-template-columns: 1fr; }
  .chat-wrap.has-active .chat-list { display: none; }
  .chat-wrap:not(.has-active) .thread { display: none; }
}
