/* وصلة — لوحة التحكم */
html, body { height: 100%; }
[hidden] { display: none !important; }
body { overflow: hidden; }
.muted { color: var(--ink-3); }
.center { text-align: center; }
.ltr-num { direction: ltr; unicode-bidi: isolate; }
.boot { height: 100vh; display: grid; place-items: center; }
.boot img { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; transform: scale(.94); } }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.input-sm { height: 34px; font-size: var(--fs-sm); padding: 0 10px; width: auto; }

/* ---------- الدخول ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 440px) 1fr; overflow: auto; height: 100vh; }
.auth-side {
  background: var(--lapis-800); color: #e9eef7; padding: 40px; display: flex; flex-direction: column; gap: 32px;
  background-image: radial-gradient(circle at 0% 100%, rgba(79, 86, 214, .35), transparent 55%);
}
.auth-side .logo { color: #fff; }
.auth-quote { font-size: 26px; line-height: 1.35; font-weight: 500; margin: auto 0 0; max-width: 16em; text-wrap: balance; }
.auth-chs { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.auth-chs li { display: flex; align-items: center; gap: 12px; color: #c4cee0; font-size: var(--fs-sm); }
.auth-main { display: grid; place-items: center; padding: 32px 20px; position: relative; }
.auth-card { width: 100%; max-width: 400px; display: grid; gap: 18px; }
.auth-card h1 { margin: 0; font-size: var(--fs-2xl); line-height: 1.2; letter-spacing: -0.01em; }
.auth-card > p { margin: -10px 0 4px; }
.auth-switch { text-align: center; color: var(--ink-2); font-size: var(--fs-sm); margin: 0; }
.auth-lang { position: absolute; top: 20px; inset-inline-end: 20px; }
.form-error { margin: 0; padding: 10px 12px; border-radius: var(--r-md); background: var(--rose-100); color: var(--rose-600); font-size: var(--fs-sm); }
@media (max-width: 760px) {
  .auth { grid-template-columns: 1fr; }
  .auth-side { padding: 22px 20px; gap: 0; }
  .auth-quote, .auth-chs { display: none; }
  .auth-lang { top: 18px; }
}

.lang-picker { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); position: relative; }
.lang-picker select { appearance: none; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-md); height: 36px; padding: 0 12px; cursor: pointer; font-size: var(--fs-sm); }

/* ---------- الإطار ---------- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.rail {
  background: var(--lapis-800); color: #c9d3e4; display: flex; flex-direction: column; min-height: 0;
  padding: 16px 12px; gap: 6px;
}
[data-theme="dark"] .rail { background: #0b1220; border-inline-end: 1px solid var(--line); }
.rail-logo { display: inline-flex; padding: 4px 8px 0; width: max-content; }
.rail-ws { padding: 10px 10px 16px; display: grid; border-bottom: 1px solid rgba(255, 255, 255, .08); margin-bottom: 6px; }
.rail-ws strong { color: #fff; font-weight: 600; font-size: var(--fs-md); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-ws span { font-size: var(--fs-xs); color: #8f9bb3; }
.rail-nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rail-nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: var(--r-md);
  color: inherit; text-decoration: none; font-size: var(--fs-sm); font-weight: 500; position: relative;
}
.rail-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.rail-nav a.on { background: rgba(255, 255, 255, .1); color: #fff; }
.rail-nav a.on::before { content: ""; position: absolute; inset-inline-start: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--saffron-500); }
[dir="rtl"] .rail-nav a.on::before { border-radius: 3px 0 0 3px; }
.rail-count { margin-inline-start: auto; background: var(--saffron-500); color: #2b1d00; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center; padding: 0 6px; }
.rail-foot { margin-top: auto; display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .08); }
.rail-btn { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border: 0; background: none; color: inherit; border-radius: var(--r-md); cursor: pointer; font-size: var(--fs-sm); }
.rail-btn:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.rail-lang { padding: 0 10px; color: #c9d3e4; }
.rail-lang select { background: transparent; border-color: rgba(255, 255, 255, .14); color: #e3e9f3; height: 32px; flex: 1; }
.rail-lang select option { color: #18222b; }
.rail-user { display: flex; align-items: center; gap: 10px; padding: 8px 4px 0 6px; min-width: 0; }
.rail-user > div { min-width: 0; flex: 1; display: grid; }
.rail-user strong { color: #fff; font-size: var(--fs-sm); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-user span { font-size: 11px; color: #8f9bb3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-user .btn-ghost { color: #aab5c8; }
.rail-user .btn-ghost:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.main { min-width: 0; min-height: 0; overflow: auto; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  color: #fff; font-weight: 600; font-size: 14px; letter-spacing: .02em; user-select: none;
}

/* ---------- صندوق الوارد ---------- */
.main:has(.inbox) { overflow: hidden; }
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: 100%; position: relative; }
.inbox.show-panel { grid-template-columns: 340px minmax(0, 1fr) 300px; }
.list-pane { border-inline-end: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 18px 16px 10px; }
.list-head h1 { margin: 0; font-size: var(--fs-xl); letter-spacing: -0.01em; }
.list-head select { max-width: 150px; }
.search { display: flex; align-items: center; gap: 8px; margin: 0 16px 10px; padding: 0 12px; height: 40px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-3); }
.search:focus-within { border-color: var(--accent); }
.search input { border: 0; background: none; outline: none; flex: 1; min-width: 0; height: 100%; color: var(--ink); }
.tabs { display: flex; gap: 0; padding: 0 10px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button {
  flex: 1 1 auto; justify-content: center; border: 0; background: none; padding: 10px 6px 11px; font-size: 13px; color: var(--ink-3); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; font-weight: 500;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs button b { font-size: 11px; font-weight: 600; color: var(--ink-3); }
.tabs button b:empty { display: none; }
.conv-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; min-height: 0; }
.conv {
  display: flex; gap: 12px; padding: 11px 10px; border-radius: var(--r-md); text-decoration: none; color: inherit; align-items: center;
}
.conv:hover { background: var(--surface-2); }
.conv.on { background: var(--accent-soft); }
.conv-av { position: relative; flex: none; }
.conv-av .ch { position: absolute; bottom: -2px; inset-inline-end: -3px; box-shadow: 0 0 0 2px var(--surface); }
.conv.on .conv-av .ch { box-shadow: 0 0 0 2px var(--accent-soft); }
.conv-body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.conv-top, .conv-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.conv-top strong { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.conv-top time { font-size: 11.5px; color: var(--ink-3); flex: none; }
.conv-preview { color: var(--ink-3); font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.conv.unread strong { font-weight: 650; }
.conv.unread .conv-preview { color: var(--ink); }
.conv.unread time { color: var(--accent); font-weight: 600; }
.badge { background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center; padding: 0 6px; flex: none; }
.conv-assignee .avatar { box-shadow: 0 0 0 2px var(--surface); }
.empty-list { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 48px 20px; color: var(--ink-3); }
.empty-list .icon { width: 32px; height: 32px; stroke-width: 1.4; }
.empty-list strong { font-weight: 500; color: var(--ink-2); max-width: 22em; }
.skeleton { list-style: none; height: 62px; margin: 6px 4px; border-radius: var(--r-md); background: linear-gradient(90deg, var(--line-2), var(--surface-2), var(--line-2)); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
.skeleton.tall { height: 200px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* المحادثة */
.thread-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.thread-empty { margin: auto; text-align: center; display: grid; justify-items: center; gap: 6px; padding: 24px; color: var(--ink-3); max-width: 360px; }
.thread-empty .icon { width: 44px; height: 44px; stroke-width: 1.2; margin-bottom: 6px; }
.thread-empty h2 { margin: 0; font-size: var(--fs-lg); color: var(--ink); font-weight: 600; }
.thread-empty p { margin: 0; }
.thread-loading { margin: auto; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); min-height: 64px; }
.thread-back { display: none; }
.thread-title { display: grid; min-width: 0; flex: 1; }
.thread-title strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-title span { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--ink-3); min-width: 0; white-space: nowrap; }
.thread-title bdi { padding-inline-start: 6px; border-inline-start: 1px solid var(--line); }
.thread-actions { display: flex; align-items: center; gap: 8px; }
.assign { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: var(--r-sm); color: var(--ink-3); background: var(--surface); }
.assign .icon { width: 15px; height: 15px; }
.assign select { border: 0; background: none; font-size: var(--fs-xs); color: var(--ink); cursor: pointer; outline: none; max-width: 120px; }
.btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 18px clamp(14px, 3vw, 32px) 8px; display: flex; flex-direction: column; gap: 4px; scroll-behavior: smooth; }
.messages:focus { outline: none; }
.day { display: flex; justify-content: center; margin: 14px 0 8px; }
.day span { font-size: 11.5px; color: var(--ink-3); background: var(--surface); border: 1px solid var(--line); padding: 3px 12px; border-radius: 99px; }
.msg { display: flex; flex-direction: column; max-width: min(72%, 560px); }
.msg-in { align-self: flex-start; align-items: flex-start; }
.msg-out, .msg-note { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 8px 12px 6px; border-radius: 14px; box-shadow: var(--shadow-1); position: relative; display: grid; gap: 4px; min-width: 88px; }
.msg-in .bubble { background: var(--surface); border-start-start-radius: 4px; }
.msg-out .bubble { background: var(--lapis-700); color: #f1f4fa; border-start-end-radius: 4px; }
[data-theme="dark"] .msg-out .bubble { background: #26406b; }
.msg-out .bubble a { color: #c3c6ff; }
.msg-note .bubble { background: var(--note); border: 1px dashed var(--note-line); box-shadow: none; border-start-end-radius: 4px; }
.note-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; color: #8a6514; }
[data-theme="dark"] .note-tag { color: #e6c06b; }
.note-tag .icon { width: 12px; height: 12px; }
.m-text { white-space: normal; overflow-wrap: anywhere; line-height: 1.55; }
.m-meta { display: flex; align-items: center; justify-content: flex-end; gap: 6px; font-size: 11px; opacity: .72; }
.m-meta span::after { content: ""; display: inline-block; width: 3px; height: 3px; border-radius: 50%; background: currentColor; margin-inline-start: 6px; vertical-align: middle; opacity: .6; }
.st { display: inline-flex; }
.st .icon { width: 15px; height: 15px; stroke-width: 2; }
.st-read { color: #aab0ff; opacity: 1; }
.st-failed { color: #ff9aa8; }
.msg-failed .bubble { box-shadow: 0 0 0 1.5px var(--rose-600); }
.m-error { display: flex; align-items: center; gap: 6px; color: var(--rose-600); font-size: var(--fs-xs); margin: 4px 2px 0; }
.m-error .icon { width: 14px; height: 14px; }
.m-img img { display: block; max-height: 300px; border-radius: 10px; background: var(--line-2); min-width: 120px; min-height: 80px; object-fit: cover; }
.m-file { display: inline-flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--r-md); background: rgba(127, 139, 158, .14); color: inherit; text-decoration: none; }
audio, video { max-width: 280px; border-radius: 10px; }
.msg-new { animation: arrive .28s ease-out; }
@keyframes arrive { from { opacity: 0; transform: translateY(6px); } }

/* محرّر الرد */
.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 10px 16px 12px; }
.composer.is-note { background: color-mix(in srgb, var(--note) 70%, var(--surface)); }
.window-closed { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; margin-bottom: 10px; border-radius: var(--r-md); background: var(--saffron-100); color: var(--ink); font-size: var(--fs-sm); }
.window-closed .icon { color: #a87510; margin-top: 2px; }
.window-closed div { display: grid; }
.window-closed span { color: var(--ink-2); }
.compose-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.compose-tabs button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 5px 10px; border-radius: var(--r-sm); font-size: var(--fs-xs); font-weight: 500; color: var(--ink-3); cursor: pointer; }
.compose-tabs button .icon { width: 14px; height: 14px; }
.compose-tabs button[aria-selected="true"] { background: var(--line-2); color: var(--ink); }
.is-note .compose-tabs button[aria-selected="true"] { background: var(--note-line); color: #5a420c; }
[data-theme="dark"] .is-note .compose-tabs button[aria-selected="true"] { color: #f6dfa5; }
.compose-tabs button:disabled { opacity: .4; cursor: not-allowed; }
.compose-box { display: flex; gap: 10px; align-items: flex-end; position: relative; }
.compose-box textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: var(--r-lg); padding: 10px 14px; min-height: 44px; max-height: 180px;
  background: var(--surface); line-height: 1.5; outline: none;
}
.compose-box textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
.send { height: 44px; border-radius: var(--r-lg); }
.compose-hint { margin: 6px 4px 0; font-size: 11px; color: var(--ink-3); }
.qr-pop { position: absolute; bottom: calc(100% + 8px); inset-inline-start: 0; width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); padding: 6px; z-index: 5; display: grid; }
.qr-pop button { display: grid; gap: 2px; text-align: start; border: 0; background: none; padding: 8px 10px; border-radius: var(--r-md); cursor: pointer; }
.qr-pop button[aria-selected="true"], .qr-pop button:hover { background: var(--accent-soft); }
.qr-pop b { font-size: var(--fs-xs); color: var(--accent); font-weight: 600; }
.qr-pop span { font-size: var(--fs-sm); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qr-empty { margin: 0; padding: 10px; color: var(--ink-3); font-size: var(--fs-sm); }

/* لوحة جهة الاتصال */
.contact-pane { display: none; background: var(--surface); border-inline-start: 1px solid var(--line); overflow-y: auto; padding: 24px 18px; }
.show-panel .contact-pane { display: block; }
.cp-head { display: grid; justify-items: center; gap: 8px; text-align: center; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.cp-name { border: 1px solid transparent; background: none; text-align: center; font-weight: 600; font-size: var(--fs-lg); padding: 4px 8px; border-radius: var(--r-sm); width: 100%; }
.cp-name:hover { border-color: var(--line); }
.cp-name:focus { outline: none; border-color: var(--accent); background: var(--surface-2); }
.cp-ch { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--ink-3); }
.cp-list { margin: 0; padding: 14px 0; display: grid; gap: 12px; border-bottom: 1px solid var(--line); }
.cp-list div { display: flex; justify-content: space-between; gap: 12px; font-size: var(--fs-sm); }
.cp-list dt { color: var(--ink-3); }
.cp-list dd { margin: 0; font-weight: 500; text-align: end; overflow-wrap: anywhere; }
.cp-notes { padding-top: 16px; }
.cp-notes textarea { min-height: 120px; background: var(--surface-2); }
.cp-notes small { color: var(--accent); }

/* ---------- الصفحات ---------- */
.page { padding: 28px clamp(16px, 4vw, 40px) 48px; max-width: 1100px; }
.page-narrow { max-width: 680px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: var(--fs-2xl); letter-spacing: -0.015em; line-height: 1.2; }
.page-head p { margin: 4px 0 0; max-width: 56ch; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px; display: grid; gap: 16px; margin-bottom: 18px; }
.panel h2 { margin: 0; font-size: var(--fs-lg); display: flex; align-items: center; gap: 8px; }
.panel > p { margin: -8px 0 0; }
.panel-foot { display: flex; justify-content: flex-end; }
.search-page { margin: 0 0 16px; max-width: 420px; background: var(--surface); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; font-size: var(--fs-sm); }
.table th { text-align: start; font-weight: 500; color: var(--ink-3); font-size: var(--fs-xs); padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr[data-open] { cursor: pointer; }
.table tbody tr[data-open]:hover { background: var(--surface-2); }
.table .num { text-align: end; font-variant-numeric: tabular-nums; }
.table .end { text-align: end; }
.cell-user { display: flex; align-items: center; gap: 10px; }
.cell-user > span { display: grid; }
.cell-user strong { font-weight: 500; }
.cell-ch { display: inline-flex; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 99px; font-size: 11.5px; font-weight: 500; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.pill-on { background: var(--accent-soft); color: var(--accent); }
.roles-note { display: flex; gap: 8px; align-items: flex-start; color: var(--ink-3); font-size: var(--fs-sm); margin: 16px 2px 0; max-width: 70ch; }
.roles-note .icon { margin-top: 2px; }
.empty-block { display: grid; justify-items: center; gap: 8px; padding: 56px 20px; color: var(--ink-3); text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r-lg); }
.empty-block .icon { width: 32px; height: 32px; stroke-width: 1.4; }
.empty-block p { margin: 0; max-width: 40ch; }

/* التقارير */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; display: grid; gap: 4px; }
.stat span { color: var(--ink-3); font-size: var(--fs-sm); }
.stat strong { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-lead { background: var(--lapis-800); border-color: var(--lapis-800); color: #fff; }
.stat-lead span { color: #aebad0; }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.bars li { display: grid; grid-template-columns: 150px 1fr 56px; align-items: center; gap: 12px; font-size: var(--fs-sm); }
.bar-label { display: inline-flex; align-items: center; gap: 8px; }
.bar-track { height: 10px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.bar { display: block; height: 100%; border-radius: 99px; }
.bar-whatsapp { background: var(--ch-whatsapp); } .bar-telegram { background: var(--ch-telegram); } .bar-instagram { background: var(--ch-instagram); } .bar-messenger { background: var(--ch-messenger); }
.bars b { text-align: end; font-variant-numeric: tabular-nums; }

/* القنوات */
.ch-grid { list-style: none; padding: 0; margin: 0 0 18px; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.ch-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 4px 14px; }
.ch-card .btn { grid-column: 3; }
.ch-card .pill { grid-column: 3; grid-row: 1; justify-self: end; }
.ch-card:has(.btn) .pill { grid-row: auto; display: none; }
.ch-info { display: grid; min-width: 0; }
.ch-info strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-info span { font-size: var(--fs-xs); color: var(--ink-3); }
.ch-card.is-soon { background: transparent; border-style: dashed; }
.ch-card.is-soon .ch { filter: grayscale(.6); opacity: .65; }
.ch-card.is-off .ch { filter: grayscale(1); opacity: .5; }
.ch-welcome { grid-column: 1 / -1; margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--line-2); display: flex; gap: 8px; font-size: var(--fs-xs); color: var(--ink-2); }
.ch-welcome .icon { width: 14px; height: 14px; color: var(--saffron-500); flex: none; margin-top: 2px; }
.ch-welcome span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.onboard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 40px 24px; text-align: center; display: grid; justify-items: center; gap: 8px; margin-bottom: 18px; }
.onboard > .icon { width: 40px; height: 40px; color: var(--accent); stroke-width: 1.4; }
.onboard h2 { margin: 8px 0 0; font-size: var(--fs-xl); }
.onboard p { margin: 0; color: var(--ink-2); max-width: 48ch; }
.onboard-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 14px; }
.platform code { background: var(--surface-2); border: 1px solid var(--line); padding: 8px 10px; border-radius: var(--r-sm); font-size: 12.5px; overflow-x: auto; white-space: nowrap; flex: 1; min-width: 0; }
.copy-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: var(--fs-sm); }
.copy-row > span { color: var(--ink-2); min-width: 120px; }
.hint { display: flex; gap: 8px; align-items: center; margin: 0; font-size: var(--fs-sm); }
.hint.ok { color: var(--accent); } .hint.warn { color: #a87510; }

/* الردود الجاهزة */
.qr-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.qr-list li { display: grid; grid-template-columns: 160px 1fr auto; gap: 16px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.qr-list li:last-child { border-bottom: 0; }
.qr-list code { font-family: inherit; font-weight: 600; color: var(--accent); font-size: var(--fs-sm); }
.qr-list p { margin: 0; color: var(--ink-2); font-size: var(--fs-sm); }
.qr-actions { display: flex; gap: 2px; }
.prefix { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.prefix:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.prefix b { padding-inline-start: 12px; color: var(--accent); }
.prefix .input { border: 0; box-shadow: none !important; }

/* ---------- نوافذ ---------- */
.dlg { border: 0; padding: 0; border-radius: var(--r-xl); background: var(--surface); color: var(--ink); width: min(520px, calc(100vw - 24px)); box-shadow: var(--shadow-pop); max-height: calc(100dvh - 32px); }
.dlg::backdrop { background: rgba(10, 18, 34, .5); backdrop-filter: blur(2px); }
.dlg[open] { animation: dlg-in .18s ease-out; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.dlg form { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.dlg-head h2 { margin: 0; font-size: var(--fs-lg); }
.dlg-body { padding: 10px 20px 4px; display: grid; gap: 16px; overflow-y: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px 20px; }
.dlg-ch { display: flex; align-items: center; gap: 12px; }
.dlg-ch > div { display: grid; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; background: var(--surface-2); border-radius: var(--r-md); border: 1px solid var(--line); }
.seg-3 { grid-template-columns: 1fr 1fr 1fr; }
.seg-3 button { flex-direction: column; gap: 4px; height: 56px; font-size: var(--fs-xs); line-height: 1.2; text-align: center; padding: 0 4px; }
.dlg-hint { display: flex; gap: 8px; align-items: flex-start; margin: 0; padding: 10px 12px; border-radius: var(--r-md); background: var(--accent-soft); color: var(--ink-2); font-size: var(--fs-sm); line-height: 1.6; }
.dlg-hint .icon { color: var(--accent); flex: none; margin-top: 2px; }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; border: 0; border-radius: var(--r-sm); background: none; cursor: pointer; font-weight: 500; color: var(--ink-2); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.steps { margin: 0; padding-inline-start: 22px; display: grid; gap: 6px; color: var(--ink-2); font-size: var(--fs-sm); background: var(--surface-2); border-radius: var(--r-md); padding-block: 12px; padding-inline-end: 14px; }
.steps li::marker { color: var(--accent); font-weight: 600; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: var(--fs-sm); }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 38px; height: 22px; border-radius: 11px; background: var(--line); position: relative; transition: background .15s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: inset-inline-start .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { inset-inline-start: 19px; }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.danger-zone { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-md); border: 1px solid var(--rose-100); }
.danger-zone > div { display: grid; font-size: var(--fs-sm); }
.danger-zone span { color: var(--ink-3); font-size: var(--fs-xs); }

/* ---------- إشعارات ---------- */
#toasts { position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; pointer-events: none; }
[dir="rtl"] #toasts { transform: translateX(50%); }
.toast { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: var(--r-md); background: var(--lapis-800); color: #fff; font-size: var(--fs-sm); box-shadow: var(--shadow-pop); animation: toast-in .2s ease-out; transition: opacity .3s, transform .3s; }
.toast .icon { color: #aab0ff; }
.toast-error { background: var(--rose-600); }
.toast-error .icon { color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- الشاشات الأصغر ---------- */
@media (max-width: 1180px) {
  .inbox.show-panel { grid-template-columns: 320px minmax(0, 1fr); }
  .inbox { grid-template-columns: 320px minmax(0, 1fr); }
  .show-panel .contact-pane { position: absolute; inset-block: 0; inset-inline-end: 0; width: 300px; z-index: 4; box-shadow: var(--shadow-pop); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .rail { flex-direction: row; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); order: 2; gap: 0; }
  .rail-logo, .rail-ws, .rail-foot { display: none; }
  .rail-nav { display: flex; width: 100%; justify-content: space-around; overflow-x: auto; }
  .rail-nav li { flex: 1; min-width: 0; }
  .rail-nav a { flex-direction: column; gap: 2px; font-size: 10.5px; padding: 7px 2px; justify-content: center; text-align: center; min-height: 48px; }
  .rail-nav a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .rail-nav a:not(.on) span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .rail-nav a .icon { width: 21px; height: 21px; }
  .rail-nav a.on::before { display: none; }
  .rail-count { position: absolute; top: 2px; inset-inline-start: 55%; margin: 0; min-width: 17px; height: 17px; font-size: 10px; }
  .main { order: 1; }
  .inbox, .inbox.show-panel { grid-template-columns: minmax(0, 1fr); }
  .inbox.has-active .list-pane { display: none; }
  .inbox:not(.has-active) .thread-pane { display: none; }
  .thread-back { display: inline-flex; }
  .thread-head { padding: 8px 10px; gap: 8px; }
  .thread-head > .avatar { width: 32px !important; height: 32px !important; }
  .thread-actions .btn span, .assign { display: none; }
  .show-panel .contact-pane { width: min(320px, 90vw); }
  .msg { max-width: 86%; }
  .compose-hint { display: none; }
  .send span { display: none; }
  .send { width: 44px; padding: 0; }
  .page { padding: 20px 16px 32px; }
  .qr-list li { grid-template-columns: 1fr auto; }
  .qr-list p { grid-column: 1 / -1; grid-row: 2; }
  .bars li { grid-template-columns: 110px 1fr 40px; }
  .table th:nth-child(3), .table td:nth-child(3) { display: none; }
  [data-ctable] .table th:nth-child(4), [data-ctable] .table td:nth-child(4) { display: none; }
  .table td, .table th { padding: 10px 10px; }
}

/* ---------- المساعد الذكي ---------- */
.ai-status { display: flex; gap: 12px; align-items: flex-start; padding: 16px 18px; border-radius: var(--r-lg); margin-bottom: 16px; border: 1px solid var(--line); background: var(--surface); }
.ai-status .icon { flex: none; margin-top: 2px; width: 22px; height: 22px; }
.ai-status > div { display: grid; gap: 4px; flex: 1; min-width: 0; }
.ai-status strong { font-weight: 600; }
.ai-status span { font-size: var(--fs-sm); color: var(--ink-2); }
.ai-status.ok { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); background: var(--accent-soft); }
.ai-status.ok .icon { color: var(--accent); }
.ai-status.warn { border-color: var(--note-line); background: var(--note); }
.ai-status.warn .icon { color: #a87510; }
.ai-bar { display: block; height: 7px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 22%, transparent); overflow: hidden; margin-top: 4px; max-width: 320px; }
.ai-bar b { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.ai-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ai-knowledge { min-height: 150px; line-height: 1.7; }
.switch-lg { font-weight: 600; font-size: var(--fs-md); }
.ai-adv { border: 1px solid var(--line); border-radius: var(--r-md); padding: 0 14px; background: var(--surface-2); }
.ai-adv summary { cursor: pointer; padding: 12px 0; font-weight: 500; font-size: var(--fs-sm); color: var(--ink-2); list-style: none; display: flex; align-items: center; gap: 6px; }
.ai-adv summary::-webkit-details-marker { display: none; }
.ai-adv summary::before { content: "+"; color: var(--accent); font-weight: 700; }
.ai-adv[open] summary::before { content: "–"; }
.ai-adv[open] { padding-bottom: 16px; }
.ai-adv .ai-own { display: grid; gap: 14px; margin-top: 6px; }
.ai-test h2 { display: flex; align-items: center; gap: 8px; }
.ai-test h2 .icon { color: var(--accent); }
.ai-test-row { display: flex; gap: 8px; }
.ai-test-row .input { flex: 1; }
.ai-test-out { padding: 12px 14px; border-radius: var(--r-md); font-size: var(--fs-sm); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-test-out.reply { background: var(--accent-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line)); }
.ai-test-out.note { background: var(--note); border: 1px dashed var(--note-line); }
.ai-test-out.err { background: var(--rose-100); color: var(--rose-600); }
@media (max-width: 600px) { .ai-row { grid-template-columns: 1fr; } }

/* ---------- الاشتراك ---------- */
.trial-chip { display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; padding: 4px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 500; text-decoration: none; background: rgba(240,168,48,.18); color: #f5c46d; }
.trial-chip .icon { width: 13px; height: 13px; }
.trial-chip.is-exp { background: rgba(244,113,138,.2); color: #ffabb9; }
.bill-current { gap: 18px; }
.bill-cur-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.bill-cur-head h2 { margin: 2px 0 0; font-size: var(--fs-2xl); }
.uses { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.use-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-size: var(--fs-sm); }
.use-top span { color: var(--ink-2); }
.use-top b { font-weight: 600; font-variant-numeric: tabular-nums; }
.use-top i { color: var(--ink-3); font-style: normal; font-weight: 400; font-size: var(--fs-xs); }
.use-bar { display: block; height: 7px; border-radius: 99px; background: var(--line-2); overflow: hidden; }
.use-bar b { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bill-h { font-size: var(--fs-xl); margin: 26px 0 14px; }
.bill-owner { margin-top: 24px; }
.bill-owner h2 { display: flex; align-items: center; gap: 8px; }
.bill-owner h2 .icon { color: var(--accent); }
/* بطاقات الباقات داخل اللوحة */
.plans { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.plan { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px; display: flex; flex-direction: column; gap: 6px; position: relative; }
.plan h3 { margin: 0; font-size: var(--fs-lg); font-weight: 600; }
.plan-price { display: flex; align-items: baseline; gap: 8px; margin: 10px 0 14px; }
.plan-price strong { font-size: 38px; font-weight: 600; letter-spacing: -0.03em; line-height: 1; }
.plan-price span { color: var(--ink-3); font-size: var(--fs-sm); }
.plan ul { list-style: none; padding: 16px 0 0; margin: 0 0 18px; display: grid; gap: 10px; border-top: 1px solid var(--line); flex: 1; align-content: start; }
.plan li { display: flex; gap: 10px; align-items: flex-start; font-size: var(--fs-sm); color: var(--ink-2); }
.plan li .icon { color: var(--accent); width: 17px; height: 17px; margin-top: 1px; flex: none; }
.plan .btn { width: 100%; }
.plan-pop { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.plan-flag { position: absolute; top: -10px; inset-inline-end: 18px; font-size: 11px; font-weight: 600; color: #fff; background: var(--accent); padding: 3px 10px; border-radius: 99px; }
@media (max-width: 760px) { .uses { grid-template-columns: 1fr; gap: 12px; } .plans { grid-template-columns: 1fr; } }

/* ---------- مستندات المعرفة ---------- */
.ai-docs { display: grid; gap: 8px; }
.ai-docs-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ai-docs-head > span { font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); }
.ai-docs-head .btn { cursor: pointer; }
.doc-list { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 8px; }
.doc-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); }
.doc-list .doc-ic { display: grid; place-items: center; width: 30px; height: 30px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent); flex: none; }
.doc-list .doc-ic .icon { width: 16px; height: 16px; }
.doc-info { display: grid; flex: 1; min-width: 0; }
.doc-info strong { font-weight: 500; font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-info span { font-size: var(--fs-xs); color: var(--ink-3); }
.doc-empty { border: 1px dashed var(--line) !important; background: transparent !important; justify-content: center; font-size: var(--fs-sm); }
