/* ReplyHub — لوحة تحكم بوت واتساب. RTL، خط واحد (IBM Plex Sans Arabic)، ألوان قابلة للتخصيص من الإعدادات */
:root {
  --ink: #0b3d2c;
  --ink-2: #12573f;
  --canvas: #f4f8f6;
  --surface: #ffffff;
  --line: #dbe7e0;
  --line-2: #eaf2ee;
  --text: #14261f;
  --muted: #586b62;
  --primary: #12805a;
  --primary-ink: #0a5a3e;
  --primary-soft: #e4f4ec;
  --accent: #e8a317;
  --accent-soft: #fdf3dc;
  --danger: #c93b3b;
  --danger-soft: #fbe9e9;
  --ok: #1e8e5a;
  --bubble-in: #ffffff;
  --bubble-out: #d9f2e6;
  --bubble-bot: #e4f4ec;
  --bubble-ai: #efe6fa;
  --chat-bg: #e9e4da;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 61, 44, .06), 0 4px 14px rgba(11, 61, 44, .05);
  --font: "IBM Plex Sans Arabic", Tahoma, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--canvas); color: var(--text); font-family: var(--font); font-size: 14.5px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
::selection { background: var(--primary-soft); }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.35; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }
.gap-s { gap: 6px; } .gap-l { gap: 18px; }
.ltr { direction: ltr; unicode-bidi: plaintext; text-align: left; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.sm { width: 15px; height: 15px; }
svg.i.lg { width: 22px; height: 22px; }

/* ---------- الهيكل ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; height: 100vh; height: 100dvh; }
.side {
  background: var(--ink); color: #d5ebe0; display: flex; flex-direction: column; padding: 14px 10px; gap: 4px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 14px; color: #fff; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--primary); display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; overflow: hidden;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand b { display: block; font-size: 15px; line-height: 1.2; }
.brand span { font-size: 11.5px; color: #9cc5b1; }
.nav-group { padding: 12px 12px 4px; font-size: 11.5px; color: #86b39d; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; color: #d5ebe0; text-decoration: none; cursor: pointer;
  border: 0; background: none; width: 100%; text-align: right; font-size: 14px;
}
.nav-item:hover { background: rgba(255, 255, 255, .07); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .badge { margin-inline-start: auto; }
.side-foot { margin-top: auto; padding: 10px; border-top: 1px solid rgba(255, 255, 255, .1); display: flex; flex-direction: column; gap: 8px; }
.conn-pill { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #8a97ad; flex: none; }
.dot.on { background: #35c88a; box-shadow: 0 0 0 3px rgba(53, 200, 138, .2); }
.dot.wait { background: var(--accent); }
.dot.off { background: #e06a6a; }
.side-me { display: flex; align-items: center; gap: 8px; color: #fff; font-size: 13px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-ink); display: grid; place-items: center;
  font-weight: 600; flex: none; font-size: 14px;
}
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: none; align-items: center; gap: 10px; padding: 10px 14px; background: var(--ink); color: #fff; }
.page { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 26px 40px; }
.page.flush { padding: 0; overflow: hidden; }
.page-head { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head p { color: var(--muted); margin-top: 2px; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- عناصر عامة ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card h3 { font-size: 15px; margin-bottom: 4px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.card-body { padding: 18px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 15px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: #f5f8fb; border-color: #c9d3e1; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-ink); border-color: var(--primary-ink); }
.btn.danger { color: var(--danger); border-color: #efc7c7; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(11, 61, 44, .06); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 7px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.input, .select, .textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; transition: border-color .12s, box-shadow .12s;
}
.textarea { resize: vertical; min-height: 84px; line-height: 1.7; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(11, 122, 107, .15); }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > label, .lbl { font-weight: 500; font-size: 13.5px; }
.hint { font-size: 12.5px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--line-2); color: var(--muted); line-height: 1.7; }
.badge.red { background: var(--danger); color: #fff; }
.badge.green { background: var(--primary-soft); color: var(--primary-ink); }
.badge.amber { background: var(--accent-soft); color: #8a5a00; }
.badge.blue { background: #e4ecfb; color: #0f6b4a; }
.badge.purple { background: #efe6fa; color: #5b3a8c; }
.nav-item .badge { background: var(--accent); color: #2a1d00; }

.switch { position: relative; width: 38px; height: 22px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: #c3ccda; border-radius: 99px; cursor: pointer; transition: background .15s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; top: 3px; inset-inline-start: 3px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(-16px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

.seg { display: inline-flex; background: var(--line-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg button.on { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(11, 61, 44, .12); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tabs button.on { color: var(--primary-ink); border-bottom-color: var(--primary); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: text; min-height: 42px; align-items: center; }
.chips:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(11, 122, 107, .15); }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--primary-soft); color: var(--primary-ink); border-radius: 6px; padding: 2px 4px 2px 8px; font-size: 13px; }
.chip button { border: 0; background: none; cursor: pointer; color: inherit; padding: 0 2px; line-height: 1; opacity: .7; font-size: 15px; }
.chip button:hover { opacity: 1; }
.chips input { border: 0; outline: 0; flex: 1; min-width: 120px; padding: 3px 4px; background: none; }

.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 4px; font-size: 16px; }
.empty .btn { margin-top: 14px; }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 9px; background: var(--accent-soft); color: #6d4a00; border: 1px solid #f2dca2; font-size: 13.5px; }
.notice.info { background: #e8f0fd; color: #24407c; border-color: #cddcf6; }
.notice.bad { background: var(--danger-soft); color: #8d2323; border-color: #efc7c7; }
.notice.good { background: var(--primary-soft); color: var(--primary-ink); border-color: #bfe3dc; }
.kbd { font-family: ui-monospace, Menlo, monospace; background: var(--line-2); border-radius: 5px; padding: 0 5px; font-size: 12px; direction: ltr; display: inline-block; }
code.var { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: var(--line-2); border-radius: 5px; padding: 1px 6px; cursor: pointer; direction: ltr; display: inline-block; border: 0; color: var(--ink-2); }
code.var:hover { background: var(--primary-soft); color: var(--primary-ink); }

.toasts { position: fixed; bottom: 18px; inset-inline-end: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 9px; box-shadow: 0 8px 24px rgba(11, 61, 44, .28); max-width: 380px; animation: pop .18s ease-out; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--primary-ink); }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.overlay { position: fixed; inset: 0; background: rgba(11, 61, 44, .45); display: grid; place-items: center; z-index: 90; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal { background: #fff; border-radius: 12px; width: min(560px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(11, 61, 44, .35); }
.modal.wide { width: min(860px, 100%); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 10px; }
.modal-head h3 { font-size: 16px; flex: 1; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line-2); display: flex; gap: 8px; justify-content: flex-start; flex-wrap: wrap; }

/* ---------- قائمة + محرر (الردود/القوائم/المعرفة) ---------- */
.split { display: grid; grid-template-columns: 300px 1fr; gap: 18px; align-items: start; }
.list-pane { position: sticky; top: 0; max-height: calc(100vh - 150px); display: flex; flex-direction: column; }
.list-scroll { overflow-y: auto; flex: 1; }
.list-item { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line-2); cursor: pointer; align-items: center; }
.list-item:hover { background: #f7f9fc; }
.list-item.sel { background: var(--primary-soft); box-shadow: inset -3px 0 0 var(--primary); }
.list-item.off .li-title { color: var(--muted); text-decoration: line-through; text-decoration-color: #b8c2d2; }
.li-title { font-weight: 500; }
.list-cat { padding: 8px 14px 4px; font-size: 12px; color: var(--muted); background: #f7f9fc; border-bottom: 1px solid var(--line-2); font-weight: 600; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.editor-grid > .col { position: sticky; top: 0; }
.msg-part { border: 1px solid var(--line); border-radius: 9px; background: #fbfcfe; padding: 10px; margin-bottom: 10px; }
.msg-part .textarea { background: #fff; min-height: 90px; }
.media-pill { display: flex; align-items: center; gap: 10px; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.thumb { width: 48px; height: 48px; border-radius: 7px; background: var(--line-2) center/cover no-repeat; display: grid; place-items: center; color: var(--muted); flex: none; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.opt-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: #fbfcfe; }
.opt-card .num { width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 600; flex: none; }

/* ---------- معاينة واتساب ---------- */
.phone { background: var(--chat-bg); border-radius: 16px; border: 1px solid var(--line); overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.phone-top { background: #0b5a50; color: #fff; padding: 10px 14px; display: flex; align-items: center; gap: 10px; }
.phone-top .avatar { background: rgba(255, 255, 255, .18); color: #fff; }
.phone-body { padding: 14px 12px; display: flex; flex-direction: column; gap: 6px; min-height: 220px; max-height: 440px; overflow-y: auto; background-image: radial-gradient(rgba(0, 0, 0, .035) 1px, transparent 1px); background-size: 14px 14px; }
.bub { max-width: 86%; padding: 6px 10px 5px; border-radius: 9px; box-shadow: 0 1px 1px rgba(0, 0, 0, .12); white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.6; position: relative; }
.bub.me { align-self: flex-start; background: var(--bubble-out); border-start-start-radius: 2px; }
.bub.them { align-self: flex-end; background: var(--bubble-in); border-start-end-radius: 2px; }
.bub .meta { display: block; font-size: 11px; color: #6a7684; margin-top: 2px; text-align: left; direction: ltr; }
.bub img, .bub video { max-width: 100%; border-radius: 6px; display: block; margin-bottom: 4px; }
.bub .opt-hint { display: block; margin-top: 6px; padding-top: 6px; border-top: 1px dashed rgba(0, 0, 0, .15); font-size: 12.5px; color: #4a5a70; }
.bub.sys { align-self: center; background: #fff7d6; font-size: 12.5px; color: #6b5a1a; text-align: center; }
.phone-foot { display: flex; gap: 6px; padding: 8px; background: #f0f2f5; }
.phone-foot .input { border-radius: 99px; }
.trace { font-size: 12.5px; }
.trace li { padding: 5px 0; border-bottom: 1px dashed var(--line); list-style: none; display: flex; gap: 8px; }
.trace ul { margin: 0; padding: 0; }
.trace .tag { font-size: 11px; padding: 0 7px; border-radius: 99px; background: var(--line-2); color: var(--muted); height: 20px; line-height: 20px; flex: none; }
.trace .tag.rule { background: var(--primary-soft); color: var(--primary-ink); }
.trace .tag.fallback, .trace .tag.warn { background: var(--accent-soft); color: #8a5a00; }
.trace .tag.ai { background: #efe6fa; color: #5b3a8c; }

/* قائمة واتساب التفاعلية (معاينة/محاكي) */
.list-btn-row { margin: 8px -10px -2px; padding: 8px 10px 4px; border-top: 1px solid rgba(0, 0, 0, .1); text-align: center; }
.sim-list-btn { border: 0; background: none; color: #0a7a5f; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 7px; cursor: pointer; padding: 2px 6px; }
button.sim-list-btn:hover { text-decoration: underline; }
.wa-sheet { background: #fff; border-radius: 14px; border: 1px solid var(--line); overflow: hidden; box-shadow: var(--shadow); }
.wa-sheet-title { text-align: center; font-weight: 600; padding: 12px; border-bottom: 1px solid var(--line-2); }
.wa-row { display: flex; flex-direction: column; gap: 1px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.wa-row:last-of-type { border-bottom: 0; }
.wa-row:hover { background: #f4f8fb; }
.wa-row b { font-weight: 500; font-size: 15px; }
.wa-row span { font-size: 12.5px; color: var(--muted); }
.wa-sheet-foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 12px; border-top: 1px solid var(--line-2); }

/* ---------- صندوق الرسائل ---------- */
.inbox { display: grid; grid-template-columns: 340px 1fr; height: 100%; min-height: 0; }
.inbox.with-info { grid-template-columns: 340px 1fr 300px; }
.conv-pane { background: #fff; border-inline-start: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.conv-tools { padding: 12px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line-2); }
.search { position: relative; }
.search svg { position: absolute; top: 50%; transform: translateY(-50%); inset-inline-start: 10px; color: var(--muted); }
.search .input { padding-inline-start: 34px; }
.conv-list { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line-2); cursor: pointer; align-items: center; }
.conv:hover { background: #f7f9fc; }
.conv.sel { background: var(--primary-soft); }
.conv .top { display: flex; align-items: center; gap: 6px; }
.conv .name { font-weight: 600; }
.conv .time { margin-inline-start: auto; font-size: 11.5px; color: var(--muted); flex: none; }
.conv .last { color: var(--muted); font-size: 13px; }
.unread { background: var(--primary); color: #fff; border-radius: 99px; min-width: 20px; height: 20px; padding: 0 6px; font-size: 11.5px; display: grid; place-items: center; font-weight: 600; }
.chat-pane { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); min-width: 0; }
.chat-head { background: #fff; padding: 10px 16px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.chat-body { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 5px; background-image: radial-gradient(rgba(0, 0, 0, .035) 1px, transparent 1px); background-size: 14px 14px; }
.m { max-width: min(72%, 560px); position: relative; }
.m .bub { max-width: 100%; }
.m.customer { align-self: flex-end; }
.m.out { align-self: flex-start; }
.m.note { align-self: center; max-width: 80%; }
.m .who { font-size: 11.5px; font-weight: 600; margin-bottom: 1px; display: flex; gap: 4px; align-items: center; }
.m.out .bub { background: var(--bubble-out); }
.m.bot .bub { background: var(--bubble-bot); }
.m.ai .bub { background: var(--bubble-ai); }
.m.note .bub { background: #fff3c4; border: 1px dashed #e2c35a; }
.m.customer .bub { background: var(--bubble-in); }
.m.call .bub { background: #fde8e8; }
.m .acts { position: absolute; top: -10px; inset-inline-end: 6px; display: none; gap: 2px; background: #fff; border-radius: 7px; box-shadow: var(--shadow); padding: 2px; border: 1px solid var(--line); }
.m:hover .acts { display: flex; }
.m.show-acts .acts { display: flex; }
@media (hover: none) { .m:hover:not(.show-acts) .acts { display: none; } }
.day-sep { align-self: center; background: #fff; border-radius: 99px; padding: 1px 12px; font-size: 12px; color: var(--muted); margin: 8px 0; box-shadow: 0 1px 1px rgba(0, 0, 0, .08); }
.handoff-bar { background: var(--accent-soft); border-bottom: 1px solid #f2dca2; padding: 8px 16px; display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: #6d4a00; }
.composer { background: #f0f2f5; padding: 10px 12px; display: flex; gap: 8px; align-items: flex-end; position: relative; }
.composer.note-mode { background: #fff3c4; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; max-height: 140px; min-height: 40px; background: #fff; line-height: 1.6; }
.composer textarea:focus { outline: none; border-color: var(--primary); }
.pop { position: absolute; bottom: 62px; inset-inline-start: 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(11, 61, 44, .18); width: min(380px, calc(100% - 24px)); max-height: 320px; overflow-y: auto; z-index: 20; }
.pop-item { padding: 9px 12px; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.pop-item:hover { background: #f4f8fb; }
.info-pane { background: #fff; border-inline-end: 1px solid var(--line); overflow-y: auto; padding: 16px; }
.info-pane h4 { font-size: 13px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.pick-chat { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 20px; }

/* ---------- الإحصائيات / مكتبة / متفرقات ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { padding: 16px 18px; }
.stat .n { font-size: 28px; font-weight: 700; line-height: 1.2; }
.stat .l { color: var(--muted); font-size: 13px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; min-width: 0; }
.bar { width: 100%; max-width: 38px; display: flex; flex-direction: column-reverse; border-radius: 5px 5px 0 0; overflow: hidden; background: var(--line-2); min-height: 2px; }
.bar i { display: block; width: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.legend b { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; vertical-align: -1px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.lib-item { overflow: hidden; display: flex; flex-direction: column; }
.lib-prev { height: 120px; background: var(--line-2); display: grid; place-items: center; color: var(--muted); }
.lib-prev img { width: 100%; height: 100%; object-fit: cover; }
.lib-item.pickable { cursor: pointer; }
.lib-item.pickable:hover { border-color: var(--primary); }
.qr-box { width: 280px; height: 280px; border: 1px solid var(--line); border-radius: 12px; background: #fff; display: grid; place-items: center; padding: 10px; }
.qr-box img { width: 100%; height: 100%; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: right; padding: 10px 14px; border-bottom: 1px solid var(--line-2); }
.tbl th { color: var(--muted); font-weight: 500; font-size: 13px; background: #f7f9fc; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.steps { counter-reset: s; padding: 0; margin: 0; list-style: none; }
.steps li { counter-increment: s; padding-inline-start: 38px; position: relative; margin-bottom: 12px; }
.steps li::before { content: counter(s); position: absolute; inset-inline-start: 0; top: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-ink); display: grid; place-items: center; font-weight: 600; font-size: 13px; }
.checklist li { list-style: none; display: flex; gap: 8px; align-items: center; padding: 6px 0; }
.checklist { padding: 0; margin: 0; }
.ok-ic { color: var(--ok); } .no-ic { color: #b3bccb; }

/* ---------- تسجيل الدخول والمعالج ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(360px, 480px) 1fr; background: var(--surface); }
.auth-card { padding: 48px 44px; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.auth-card h1 { font-size: 26px; margin-bottom: 4px; }
.auth-art { background: var(--ink); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center; gap: 22px; position: relative; overflow: hidden; }
.auth-art h2 { font-size: 30px; line-height: 1.5; max-width: 520px; }
.auth-art p { color: #cfe6da; max-width: 480px; }
.auth-art .phone { max-width: 340px; align-self: flex-start; }
.tpl-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tpl { border: 1px solid var(--line); border-radius: 9px; padding: 10px 8px; text-align: center; cursor: pointer; background: #fff; font-size: 13px; }
.tpl:hover { border-color: var(--primary); }
.tpl.sel { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.tpl .em { font-size: 22px; display: block; }
.err-text { color: var(--danger); font-size: 13.5px; min-height: 20px; }

.scrim, .bnav, .top-conn { display: none; }
.info-top { display: none; align-items: center; gap: 8px; margin-bottom: 10px; }
.sim-grid { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 18px; align-items: start; }
.more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.more-tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; min-height: 86px; padding: 12px 6px; border: 1px solid var(--line); border-radius: 14px; background: #fff; color: var(--text); text-decoration: none; font-size: 12.5px; font-weight: 500; text-align: center; position: relative; }
.more-tile svg { width: 24px; height: 24px; color: var(--primary); }
.more-tile:active { background: var(--primary-soft); }
.more-tile .badge { position: absolute; top: 7px; inset-inline-start: 7px; }
.more-user { display: flex; align-items: center; gap: 12px; padding: 4px 2px 14px; }
.bars.dense .bar-col > span:first-child { display: none; }
.bars.dense .bar-col:not(:nth-child(5n)) > span:last-child { visibility: hidden; }
.bar-col > span { font-size: 11px; white-space: nowrap; }
@media (max-width: 1180px) {
  .editor-grid { grid-template-columns: 1fr; }
  .editor-grid > .col { position: static; }
  .inbox.with-info { grid-template-columns: 320px 1fr; }
  .inbox.with-info .info-pane { position: fixed; inset-block: 0; inset-inline-end: 0; width: min(320px, 92vw); z-index: 40; box-shadow: -10px 0 40px rgba(11, 61, 44, .25); }
}
@media (max-width: 900px) {
  :root { --nav-h: 64px; --sb: env(safe-area-inset-bottom, 0px); --st: env(safe-area-inset-top, 0px); }
  html, body { overflow-x: hidden; overscroll-behavior: none; }
  body { font-size: 15px; -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
  .app { display: block; height: 100vh; height: 100dvh; }
  .side, .scrim { display: none !important; }
  .main { height: 100vh; height: 100dvh; }
  .topbar { display: flex; justify-content: space-between; padding: calc(11px + var(--st)) 16px 11px; position: relative; z-index: 5; }
  .topbar b { font-size: 17px; }
  .top-conn { display: flex; align-items: center; gap: 7px; font-size: 12px; color: #b9c6de; }
  .page { padding: 14px 14px calc(var(--nav-h) + var(--sb) + 22px); -webkit-overflow-scrolling: touch; }
  .page.flush { padding: 0 0 calc(var(--nav-h) + var(--sb)); }
  body.chat-open .topbar, body.chat-open .bnav { display: none; }
  body.chat-open .page.flush { padding-bottom: 0; }

  /* شريط التنقل السفلي */
  .bnav { display: flex; position: fixed; bottom: 0; inset-inline: 0; z-index: 50; background: rgba(255, 255, 255, .96); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + var(--sb)); }
  .bn-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 50px; padding: 4px 2px; border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 500; text-decoration: none; position: relative; border-radius: 12px; cursor: pointer; }
  .bn-item svg { width: 23px; height: 23px; }
  .bn-item.active { color: var(--primary); }
  .bn-item.active::before { content: ""; position: absolute; top: -7px; width: 28px; height: 3px; border-radius: 0 0 4px 4px; background: var(--primary); }
  .bn-item .badge { position: absolute; top: 0; inset-inline-start: calc(50% + 2px); background: var(--danger); color: #fff; min-width: 18px; justify-content: center; }

  /* عناصر مناسبة للمس (لا تكبير تلقائي في iOS) */
  .btn { min-height: 44px; padding: 9px 16px; }
  .btn.sm { min-height: 38px; padding: 6px 12px; }
  .btn.icon { min-width: 44px; padding: 8px; }
  .input, .select, .textarea { font-size: 16px; min-height: 46px; padding: 10px 12px; }
  .textarea { min-height: 96px; }
  .chips input { font-size: 16px; min-height: 30px; }
  .switch { width: 46px; height: 28px; }
  .switch span::before { width: 22px; height: 22px; top: 3px; }
  .switch input:checked + span::before { transform: translateX(-18px); }
  .seg button { padding: 8px 13px; }

  /* رؤوس الصفحات والشبكات */
  .page-head { display: block; margin-bottom: 14px; }
  .page-head h1 { font-size: 22px; }
  .page-head .actions { margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
  .page-head .actions .btn { flex: 1 1 calc(50% - 8px); }
  .card-head, .card-body, .card-pad { padding: 14px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .split { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .split > *, .editor-grid > *, .sim-grid > * { min-width: 0; }
  .list-pane { position: static; max-height: 46vh; max-height: 46dvh; }
  .editor-grid { grid-template-columns: minmax(0, 1fr); }
  .editor-grid > .col { position: static; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px; } .stat .n { font-size: 24px; }
  .sim-grid { grid-template-columns: minmax(0, 1fr); }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: 110px 1fr; }
  .lib-grid { grid-template-columns: repeat(2, 1fr); }
  .tpl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tpl { overflow-wrap: anywhere; }
  .seg.wrap { flex-wrap: wrap; overflow: visible; }
  .card-head { flex-wrap: wrap; }
  .card-head .legend { width: 100%; }
  .sim-body { min-height: 300px !important; }
  .tabs { margin-inline: -14px; padding-inline: 14px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar, .seg::-webkit-scrollbar { display: none; }
  .tabs button { padding: 12px 14px; }
  .phone-body { max-height: 46vh; max-height: 46dvh; }
  .qr-box { width: min(280px, 100%); height: auto; aspect-ratio: 1; margin-inline: auto; }
  .bars { gap: 3px; }

  /* الجداول ← بطاقات */
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: auto !important; }
  .tbl thead { display: none; }
  .tbl tr { padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
  .tbl td { padding: 2px 0; border: 0; text-align: right !important; }
  .tbl td:last-child { padding-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }

  /* النوافذ ← أوراق تنزلق من الأسفل */
  .overlay { align-items: end; padding: 0; }
  .modal, .modal.wide { width: 100%; max-height: 92vh; max-height: 92dvh; border-radius: 20px 20px 0 0; animation: sheet .26s cubic-bezier(.2, .8, .2, 1); }
  .modal::before { content: ""; display: block; flex: none; width: 40px; height: 4px; border-radius: 4px; background: #cfd7e3; margin: 9px auto 0; }
  .modal-head { padding: 8px 16px 12px; }
  .modal-body { padding: 14px 16px; -webkit-overflow-scrolling: touch; }
  .modal-foot { padding: 12px 16px calc(12px + var(--sb)); }
  .modal-foot .btn { flex: 1; }
  .toasts { inset-inline: 12px; bottom: calc(var(--nav-h) + var(--sb) + 12px); }
  body.chat-open .toasts { bottom: calc(84px + var(--sb)); }
  .toast { max-width: none; }

  /* صندوق الرسائل */
  .inbox, .inbox.with-info { grid-template-columns: minmax(0, 1fr); height: 100%; }
  .conv-pane, .chat-pane { min-width: 0; }
  .conv-pane { border: 0; }
  .conv-tools { padding: 12px 14px; }
  .seg { display: flex; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .seg button { white-space: nowrap; flex: none; }
  .conv { padding: 13px 14px; min-height: 76px; gap: 12px; }
  .conv .avatar { width: 48px; height: 48px; font-size: 17px; }
  .conv .name { font-size: 15.5px; } .conv .last { font-size: 14px; }
  .inbox .chat-pane { display: none; }
  .inbox.chat-open .conv-pane { display: none; }
  .inbox.chat-open .chat-pane { display: flex; height: 100%; }
  .chat-head { padding: calc(8px + var(--st)) 10px 8px; gap: 8px; }
  .chat-head .avatar { width: 38px; height: 38px; }
  .chat-body { padding: 12px 10px; }
  .m { max-width: 86%; }
  .handoff-bar { padding: 8px 12px; font-size: 13px; }
  .composer { padding: 8px 8px calc(8px + var(--sb)); gap: 4px; }
  .composer textarea { font-size: 16px; border-radius: 22px; min-height: 44px; padding: 10px 14px; }
  .composer .btn.primary.icon { border-radius: 50%; width: 44px; height: 44px; flex: none; }
  .hide-sm, .only-wide { display: none !important; }
  .info-pane { position: fixed; inset: 0; z-index: 80; width: auto !important; padding: calc(12px + var(--st)) 16px calc(24px + var(--sb)); box-shadow: none; }
  .pop { inset-inline: 8px; width: auto; bottom: calc(66px + var(--sb)); }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .auth-card { padding: calc(32px + var(--st)) 22px 32px; }
}
@media (max-width: 1180px) { .info-top { display: flex; } }
@media (min-width: 901px) { .only-narrow { display: none !important; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- صفحة الدخول: هوية أضواء ---------- */
.auth-art { background: radial-gradient(circle at 15% 10%, #1d8a62 0, transparent 55%), linear-gradient(150deg, #12805a, #0b3d2c); align-items: center; text-align: center; }
.auth-art h2 { font-size: 36px; }
.auth-art p { font-size: 16px; line-height: 1.9; }
.auth-logo { width: 92px; height: 92px; border-radius: 26px; background: #fff; color: #12805a; display: grid; place-items: center; font-size: 52px; font-weight: 700; box-shadow: 0 14px 36px rgba(0, 0, 0, .22); }
.auth-points { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; width: min(360px, 100%); }
.auth-points li { background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18); border-radius: 12px; padding: 11px 16px; }
.auth-card h1 { color: #0b3d2c; }
.auth-card .input { padding-block: 11px; }

/* ---------- هوية أضواء لخدمات الأعمال ---------- */
.auth-wrap { grid-template-columns: minmax(380px, 520px) 1fr; }
.auth-art { background: #2ba384; color: #000; gap: 34px; padding: 48px; }
.auth-art::before, .auth-art::after { content: ""; position: absolute; border: 56px solid rgba(255, 255, 255, .08); border-radius: 90px; width: 420px; height: 420px; }
.auth-art::before { top: -210px; right: -150px; transform: rotate(20deg); }
.auth-art::after { bottom: -240px; left: -160px; transform: rotate(35deg); }
.auth-brand { width: min(480px, 78%); height: auto; position: relative; }
.auth-art .auth-tag { color: #000; font-size: 17px; font-weight: 500; position: relative; padding-top: 28px; border-top: 2px solid rgba(0, 0, 0, .18); max-width: 520px; }
.auth-card { padding: 48px 60px; }
.auth-card h1 { color: #0b0f0e; font-size: 28px; }
.auth-card .input { padding-block: 12px; border-radius: 12px; }
.auth-card .btn.primary { background: #0b0f0e; border-color: #0b0f0e; color: #fff; border-radius: 12px; padding-block: 13px !important; font-weight: 600; margin-top: 4px; }
.auth-card .btn.primary:hover { background: #1f8069; border-color: #1f8069; }
.auth-mini { display: none; }
.brand-mark { background: #2ba384; }
.brand-mark img[src*="logo-mark"] { object-fit: contain; padding: 5px; }
@media (max-width: 860px), (max-width: 900px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .auth-card { padding: 32px 22px; max-width: 480px; width: 100%; margin-inline: auto; }
  .auth-mini { display: flex; justify-content: center; background: #2ba384; border-radius: 20px; padding: 26px; margin-bottom: 22px; }
  .auth-mini img { width: min(250px, 100%); height: auto; }
}

/* ---------- ثبات الجوال ---------- */
.install-hint { position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, .5); display: flex; align-items: flex-end; }
.install-hint > div { background: #fff; width: 100%; border-radius: 20px 20px 0 0; padding: 22px 22px calc(22px + env(safe-area-inset-bottom, 0px)); line-height: 2; }
.install-hint .btn { width: 100%; }
@media (max-width: 900px) {
  html, body { width: 100%; height: 100%; overflow: hidden; }
  body:has(.auth-wrap) { overflow-y: auto; }
  #root { position: fixed; top: 0; left: 0; right: 0; height: 100%; display: flex; flex-direction: column; overflow: hidden; }
  .app { flex: 1; min-height: 0; height: auto; display: flex; flex-direction: column; overflow: hidden; }
  .main { flex: 1; height: auto; min-height: 0; width: 100%; }
  .page { overflow-x: hidden; overscroll-behavior: contain; width: 100%; padding-bottom: 24px; }
  .page.flush, body.chat-open .page.flush { padding: 0; }
  .page > *, .page .card, .page .card-body, .page .field, .page .grid2 > *, .page .grid3 > *, .page .row > .grow { min-width: 0; max-width: 100%; }
  .page .input, .page .select, .page .textarea { width: 100%; min-width: 0; max-width: 100%; }
  .page .row > .input { width: auto; flex: 1; }
  .page p, .page .hint, .page .notice { overflow-wrap: anywhere; }
  .page .tabs { max-width: none; overscroll-behavior-x: contain; }
  .bnav { position: static; flex: none; padding: 7px 6px max(8px, calc(env(safe-area-inset-bottom, 0px) - 10px)); background: #fff; -webkit-backdrop-filter: none; backdrop-filter: none; }
  .bn-item { min-width: 0; white-space: nowrap; font-size: 10.5px; }
  .toasts { bottom: calc(86px + var(--sb)); }
  .chat-head { flex: none; }
  .chat-body { min-height: 0; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; overflow-x: hidden; }
  .composer { flex: none; }
  .m .bub { overflow-wrap: anywhere; }
  html.kb-open #root { top: var(--vvt); height: var(--vvh); }
  html.kb-open .bnav { display: none; }
  html.kb-open .composer { padding-bottom: 8px; }
  html.kb-open .overlay { top: var(--vvt); bottom: auto; height: var(--vvh); }
}
@media (max-width: 900px) {
  /* الخلفية أسفل الشاشة بنفس لون الشريط */
  html, body { background: #fff; }
  .page:not(.flush) { background: var(--canvas); }
  .bn-item { min-height: 52px; }
  .bn-item span:not(.badge) { display: block; line-height: 1.4; }
}
