/* منصة وابل لواتساب الأعمال - أنماط موحدة RTL */
:root {
  --green: #00a884;
  --green-dark: #008069;
  --ink: #111b21;
  --muted: #667781;
  --bg: #f0f2f5;
  --line: #e9edef;
  --card: #ffffff;
  --danger: #d32f2f;
  --warn-bg: #fff8e1;
  --navy: #0f2027;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: "Vazirmatn", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14.5px; font-family: inherit; background: #fff; margin-bottom: 10px;
}
/* سهم منسدلة مخصص بهامش كافٍ (بدل السهم الأصلي الملتصق) - يظهر يسار الحقل في RTL */
select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667781' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  background-size: 12px;
  padding: 10px 12px;
  padding-inline-end: 36px;
}
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.btn { background: var(--green); color: #fff; border: none; padding: 10px 22px; border-radius: 8px; font-size: 14.5px; }
.btn:hover { background: var(--green-dark); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: none; border: 1px solid var(--line); color: var(--ink); padding: 9px 18px; border-radius: 8px; font-size: 14px; }
.btn-danger { background: var(--danger); color: #fff; border: none; padding: 8px 16px; border-radius: 8px; font-size: 13.5px; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

/* ---------- صفحة الدخول ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, var(--navy) 0 45%, var(--bg) 45%); padding: 20px; }
.auth-card { background: #fff; border-radius: 16px; box-shadow: 0 8px 40px rgba(0,0,0,.18); width: 420px; max-width: 95vw; padding: 36px 40px; }
.auth-card .logo { font-size: 44px; text-align: center; }
.auth-card h1 { font-size: 21px; text-align: center; margin: 6px 0 2px; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }
.auth-tabs { display: flex; border-bottom: 2px solid var(--line); margin-bottom: 18px; }
.auth-tabs button { flex: 1; background: none; border: none; padding: 10px; font-size: 15px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; }
.auth-tabs button.on { color: var(--green-dark); border-color: var(--green); font-weight: 600; }
.form-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 6px; }

/* ---------- هيكل اللوحة ---------- */
/* شاشة إقلاع: تغطّي اللوحة حتى يكتمل تحميل المصادقة والهوية فلا يومض المحتوى الافتراضي */
#boot-loading { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; background: var(--navy, #0b2239); }
body:not(.booting) #boot-loading { display: none; }
body.booting .shell { visibility: hidden; }
.boot-spin { width: 38px; height: 38px; border: 3px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: boot-spin 0.8s linear infinite; }
@keyframes boot-spin { to { transform: rotate(360deg); } }

.shell { display: flex; min-height: 100vh; }
.side {
  width: 230px; background: var(--navy); color: #fff; padding: 18px 0; flex-shrink: 0;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; align-self: flex-start;
  transition: width .18s ease;
}
/* طي الشريط الجانبي */
.side-top { display: flex; justify-content: flex-end; padding: 0 16px 8px; }
.shell.side-collapsed .side-top { justify-content: center; padding: 0 0 8px; }
.side-toggle { background: rgba(255,255,255,.08); border: none; color: #fff; width: 32px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.side-toggle:hover { background: rgba(255,255,255,.18); }
.shell.side-collapsed .side { width: 62px; }
.shell.side-collapsed .side .brand #b-name,
.shell.side-collapsed .side .brand small,
.shell.side-collapsed .side .brand .alerts,
.shell.side-collapsed .side nav button span.nav-label,
.shell.side-collapsed .side .foot { display: none; }
.shell.side-collapsed .side nav button { text-align: center; padding: 12px 0; }
.shell.side-collapsed .side .brand { display: flex; justify-content: center; align-items: center; padding: 0 0 12px; }
.shell.side-collapsed .side .brand img.brand-logo { margin: 0 !important; }
.shell.side-collapsed .side .brand #b-logo-emoji { margin: 0; }
.side .brand { padding: 0 20px 16px; font-weight: 700; font-size: 16px; border-bottom: 1px solid rgba(255,255,255,.12); }
.side .brand .alerts { display: flex; gap: 10px; margin-top: 10px; }
.side .brand .alerts button {
  position: relative; background: rgba(255,255,255,.08); border: none; color: #fff;
  width: 36px; height: 32px; border-radius: 8px; font-size: 16px; cursor: pointer;
}
.side .brand .alerts button:hover { background: rgba(255,255,255,.16); }
.al-badge {
  position: absolute; top: -6px; inset-inline-end: -6px; background: #e53935; color: #fff;
  font-size: 10.5px; min-width: 16px; height: 16px; line-height: 16px; border-radius: 9px; padding: 0 4px; font-weight: 700;
}
.views-bar { display: flex; gap: 4px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.views-bar select { margin: 0; flex: 1; font-size: 13px; }
.msg-link { color: inherit; text-decoration: none; cursor: pointer; }
.msg-link:hover { text-decoration: none; color: var(--green-dark); }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.chart-wrap { position: relative; height: 300px; }
.srt-h { cursor: pointer; user-select: none; white-space: nowrap; }
.srt-h:hover { color: var(--green-dark); }
.srt-h .srt, .srt-h .srt-a { font-size: 10px; color: var(--green-dark); }
.log-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.log-controls select, .log-controls input { margin: 0; width: auto; font-size: 13.5px; }
.rem-btn { background: none; border: none; cursor: pointer; font-size: 12px; opacity: .55; padding: 0 2px; }
.rem-btn:hover { opacity: 1; }
.nf-item { display: flex; flex-direction: column; align-items: stretch; gap: 3px; padding: 11px 12px; border-bottom: 1px solid var(--line); font-size: 14px; cursor: pointer; color: var(--ink); }
.nf-item:hover { background: var(--bg); }
.nf-item.unread { background: #fff; border-inline-start: 4px solid var(--green); }
.nf-item .nf-t { display: block; width: 100%; font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.nf-item .nf-b { display: block; width: 100%; color: var(--ink); line-height: 1.6; white-space: pre-line; overflow-wrap: anywhere; unicode-bidi: plaintext; }
.nf-item .nf-time { display: block; width: 100%; color: var(--muted); font-size: 12px; }
.side .brand small { display: block; font-weight: 400; color: rgba(255,255,255,.55); font-size: 11.5px; margin-top: 3px; }
.side nav { flex: 1; padding-top: 10px; overflow-y: auto; }
.side nav button {
  display: block; width: 100%; text-align: right; background: none; border: none; color: rgba(255,255,255,.8);
  padding: 12px 20px; font-size: 14.5px;
}
.side nav button.on { background: rgba(255,255,255,.1); color: #fff; border-inline-start: 3px solid var(--green); }
.side .foot { padding: 14px 20px; font-size: 12.5px; color: rgba(255,255,255,.5); }
.side .foot button { background: none; border: none; color: rgba(255,255,255,.7); padding: 0; font-size: 12.5px; text-decoration: underline; }
.main { flex: 1; padding: 26px 30px; min-width: 0; }
.main h2 { margin: 0 0 18px; font-size: 20px; }
.cards-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 22px; min-width: 150px; }
.stat .v { font-size: 26px; font-weight: 700; color: var(--green-dark); }
.stat .k { font-size: 12.5px; color: var(--muted); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 22px; margin-bottom: 18px; max-width: 980px; }
.panel h3 { margin: 0 0 14px; font-size: 16px; }
.note { font-size: 13px; color: var(--muted); line-height: 1.8; }
.note code, .panel code { background: var(--bg); padding: 2px 8px; border-radius: 5px; font-size: 12.5px; direction: ltr; display: inline-block; word-break: break-all; }
.ok-text { color: #0a5c36; }
.err-text { color: var(--danger); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: right; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 2px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid #f3f5f6; }
.badge { display: inline-block; font-size: 11.5px; padding: 3px 10px; border-radius: 10px; background: var(--bg); }
.badge.g { background: #d1f4e0; color: #0a5c36; }
.badge.y { background: var(--warn-bg); color: #664d03; }
.badge.r { background: #fde2e1; color: #8a1f1c; }
.badge.p { background: #ede9fe; color: #5b21b6; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.toast {
  position: fixed; bottom: 22px; right: 50%; transform: translateX(50%);
  background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 8px; font-size: 14px; z-index: 99; max-width: 85vw;
}

/* ---------- صندوق المحادثات ---------- */
.inbox { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; height: calc(100vh - 130px); }
.chat-list { width: var(--chat-w, 300px); min-width: 210px; max-width: 520px; border-inline-end: 1px solid var(--line); overflow-y: auto; flex-shrink: 0; }
.chat-resizer { flex: 0 0 6px; cursor: col-resize; background: transparent; position: relative; }
.chat-resizer::before { content: ""; position: absolute; inset: 0 2px; border-radius: 3px; background: transparent; transition: background .15s; }
.chat-resizer:hover::before, .chat-resizer.dragging::before { background: var(--green); }
.chat-list .head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; }
.chat-list .head input { margin: 0; }
/* صندوق بحث برقاقة وسم وقائمة وسوم مخصّصة */
.q-box { flex: 1; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; background: #fff; min-width: 0; }
.q-box input { border: none !important; outline: none; flex: 1; min-width: 60px; margin: 0 !important; padding: 6px 0 !important; font-size: 14px; background: transparent; }
.tag-chip { display: inline-flex; align-items: center; gap: 5px; background: var(--green); color: #fff; border-radius: 12px; padding: 3px 6px 3px 10px; font-size: 12.5px; white-space: nowrap; }
.tag-chip button { background: none; border: none; color: #fff; cursor: pointer; font-size: 13px; padding: 0; line-height: 1; }
.tag-dd { position: absolute; top: 100%; inset-inline-start: 14px; inset-inline-end: 54px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.14); z-index: 30; max-height: 260px; overflow: auto; margin-top: 3px; }
.tag-dd-row { padding: 9px 12px; font-size: 13.5px; cursor: pointer; border-bottom: 1px solid #f3f5f6; display: flex; align-items: center; gap: 8px; }
.tag-dd-row:last-child { border-bottom: none; }
.tag-dd-row:hover { background: var(--bg); }
.tag-dd-empty { padding: 10px 12px; color: var(--muted); font-size: 13px; }
.chat-item { display: flex; gap: 10px; padding: 11px 14px; cursor: pointer; border-bottom: 1px solid #f5f6f6; align-items: center; }
.chat-item:hover { background: var(--bg); }
.chat-item.on { background: #e9edef; }
.chat-item .av { width: 38px; height: 38px; border-radius: 50%; background: #dfe5e7; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.chat-item .m { flex: 1; min-width: 0; }
.chat-item .t { display: flex; justify-content: space-between; font-size: 14px; }
.chat-item .t time { font-size: 11px; color: var(--muted); }
.chat-item .p { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; justify-content: space-between; gap: 6px; }
.unread { background: var(--green); color: #fff; font-size: 11px; border-radius: 10px; min-width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; }
.chat-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 11px 16px; border-bottom: 1px solid var(--line); background: var(--bg); display: flex; align-items: center; gap: 10px; }
.chat-head .who { flex: 1; }
.chat-head .who b { font-size: 15px; }
.chat-head .who span { display: block; font-size: 12px; color: var(--muted); direction: ltr; text-align: right; }
.wbadge { font-size: 11.5px; padding: 4px 10px; border-radius: 10px; background: #d1f4e0; color: #0a5c36; }
.wbadge.x { background: #fde2e1; color: #8a1f1c; }
.msgs { flex: 1; overflow-y: auto; padding: 18px 6%; background: #efeae2; display: flex; flex-direction: column; gap: 3px; }
.bb { max-width: 70%; padding: 7px 10px 8px; border-radius: 8px; font-size: 14px; line-height: 1.5; box-shadow: 0 1px 1px rgba(0,0,0,.08); white-space: pre-wrap; word-wrap: break-word; }
.int-note { align-self: center; max-width: 78%; background: #fff8e1; border: 1px solid #ffe5a3; border-radius: 10px; padding: 7px 12px; margin: 5px auto; font-size: 13.5px; color: #6b5b1e; }
.int-note-h { font-weight: 700; font-size: 12px; margin-bottom: 3px; }
.int-note-t { font-size: 10.5px; color: #a18a3e; margin-top: 3px; text-align: end; direction: ltr; }
.composer.note-mode { background: #fff8e1; }
.composer.note-mode textarea { background: #fffdf5; }
#btn-note.on { color: #c99a00; }
.bb-row { display: flex; width: 100%; border-radius: 8px; transition: background .3s; }
.bb-row.bb-flash { background: rgba(0,168,132,.18); animation: bb-flash 2.2s ease; }
@keyframes bb-flash { 0%,100% { background: transparent; } 15%,60% { background: rgba(0,168,132,.22); } }
.bb-row.out { justify-content: flex-start; }
.bb-row.in { justify-content: flex-end; }
.bb.in { background: #fff; border-start-end-radius: 0; }
.bb.out { background: #d9fdd3; border-start-start-radius: 0; }
.reaction-badge { position: absolute; bottom: -10px; inset-inline-start: 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 0 5px; font-size: 13px; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.bb { position: relative; }
.num-badge { font-size: 10px; background: var(--bg); color: var(--muted); border-radius: 8px; padding: 0 5px; margin-inline-start: 5px; }
.tr-text { margin-top: 5px; padding: 5px 8px; background: rgba(0,0,0,.05); border-radius: 6px; font-size: 13px; color: #44525d; }
.bb-quote { border-inline-start: 3px solid var(--green); background: rgba(0,0,0,.04); border-radius: 5px; padding: 3px 7px; margin-bottom: 4px; font-size: 12.5px; color: var(--muted); max-height: 48px; overflow: hidden; }
#reply-bar { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: #eef7f3; border-top: 1px solid var(--line); font-size: 13px; }
#reply-bar .reply-bar-icon { flex-shrink: 0; }
#reply-bar #reply-bar-text { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#reply-bar #reply-bar-cancel { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 14px; }
.bb img, .bb video { max-width: 300px; max-height: 300px; border-radius: 6px; display: block; }
.bb audio { max-width: 260px; }
.bb .mt { display: flex; justify-content: flex-end; gap: 4px; font-size: 10.5px; color: var(--muted); margin-top: 2px; direction: ltr; }
.bb .by { font-size: 11px; color: var(--green-dark); margin-bottom: 2px; }
.tick { letter-spacing: -3px; }
.tick.read { color: #53bdeb; }
.no-window { padding: 9px 14px; background: var(--warn-bg); font-size: 13px; text-align: center; color: #664d03; }
.composer { display: flex; gap: 8px; padding: 10px 14px; background: var(--bg); align-items: flex-end; }
.composer textarea { flex: 1; margin: 0; resize: none; max-height: 110px; border: none; border-radius: 10px; padding: 11px 14px; }
.composer .ic { background: none; border: none; font-size: 19px; padding: 8px; border-radius: 50%; }
.composer .ic:hover { background: rgba(0,0,0,.06); }
.composer .send { background: var(--green); color: #fff; width: 40px; height: 40px; border-radius: 50%; border: none; font-size: 16px; transform: scaleX(-1); }
.empty-pane { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); background: var(--bg); }
/* معاينة شكل واتساب اللحظية (للبوت والنماذج والسلاسل) */
.wa-prev { background: #e5ddd5; background-image: linear-gradient(rgba(229,221,213,.55), rgba(229,221,213,.55)); border-radius: 12px; padding: 16px 14px; }
.wa-prev .wa-hint { color: #5b6b73; font-size: 12px; text-align: center; }
.wa-bubble { background: #fff; border-radius: 0 8px 8px 8px; padding: 8px 10px 6px; font-size: 14px; line-height: 1.7; box-shadow: 0 1px 1px rgba(0,0,0,.12); white-space: pre-wrap; word-break: break-word; max-width: 88%; color: #111b21; }
.wa-bubble .wa-h { font-weight: 700; margin-bottom: 3px; }
.wa-bubble .wa-f { color: #667781; font-size: 12px; margin-top: 5px; }
.wa-btns { display: flex; flex-direction: column; gap: 5px; margin-top: 5px; max-width: 88%; }
.wa-btn { background: #fff; color: #027eb5; text-align: center; padding: 9px; border-radius: 8px; font-size: 14.5px; font-weight: 500; box-shadow: 0 1px 1px rgba(0,0,0,.12); display: flex; align-items: center; justify-content: center; gap: 6px; }
.wa-list-rows { background: #fff; border-radius: 8px; margin-top: 5px; max-width: 88%; overflow: hidden; box-shadow: 0 1px 1px rgba(0,0,0,.12); }
.wa-list-rows .wa-row { padding: 9px 12px; border-bottom: 1px solid #eef0f1; font-size: 14px; color: #111b21; display: flex; justify-content: space-between; align-items: center; }
.wa-list-rows .wa-row:last-child { border-bottom: none; }
.wa-list-rows .wa-row::after { content: "○"; color: #8696a0; }
.wa-form-field { background: #f7f8fa; border: 1px solid #e3e6e8; border-radius: 6px; padding: 8px 10px; margin-top: 6px; font-size: 13px; color: #667781; }
/* مقابض سحب محرر البوت الشجري */
.bot-drag, .opt-drag { cursor: grab; color: #8696a0; user-select: none; padding: 0 2px; font-size: 15px; line-height: 1; }
.bot-drag:active, .opt-drag:active { cursor: grabbing; }
.sortable-ghost { opacity: .45; }
.sortable-chosen { box-shadow: 0 0 0 2px var(--green); }
.bot-tree-node { padding: 4px 0; }
.bot-tree-node .bt-edge { color: var(--muted); }
.bot-tree-orphan { color: var(--danger); }
dialog { border: none; border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.2); padding: 22px; width: 430px; max-width: 92vw; }
dialog::backdrop { background: rgba(17,27,33,.45); }
dialog h3 { margin: 0 0 14px; }
.dlg-actions { display: flex; gap: 10px; margin-top: 12px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .side { width: 100%; flex-direction: row; align-items: center; padding: 0; overflow-x: auto; position: static; height: auto; }
  .side .brand { border: none; padding: 12px 16px; white-space: nowrap; }
  .side nav { display: flex; padding: 0; }
  .side nav button { white-space: nowrap; padding: 14px 14px; }
  .side .foot { display: none; }
  .main { padding: 16px; }
  .chat-list { width: 40%; min-width: 150px; }
  .grid2 { grid-template-columns: 1fr; }
}

.cstatus-filter { display: flex; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.cstatus-filter button { flex: 1; background: none; border: none; padding: 6px 4px; font-size: 12.5px; color: var(--muted); border-radius: 6px; }
.cstatus-filter button.on { background: var(--green); color: #fff; }
.chat-item .st-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.chat-item .st-dot.open { background: #25d366; }
.chat-item .st-dot.pending { background: #f0b500; }
.chat-item .st-dot.resolved { background: #b0bcc4; }
.snip-row { display: flex; gap: 8px; align-items: center; padding: 7px 10px; border-bottom: 1px solid #f3f5f6; cursor: pointer; }
.snip-row:hover { background: var(--bg); }
.snip-row .s-t { font-weight: 600; font-size: 13.5px; }
.snip-row .s-x { font-size: 12.5px; color: var(--muted); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
