/* ============================================================
   المكوّنات
   ============================================================ */

/* ---- الأزرار ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 18px; border: 1px solid transparent; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14px; font-weight: 600; line-height: 1.35;
  cursor: pointer; white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 6px 13px; font-size: 13px; }

.btn-primary, .btn-accent { background: var(--brand-accent); color: #fff; border-color: var(--brand-accent); }
.btn-primary:hover, .btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: var(--surface); color: var(--heading); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { filter: brightness(.92); }
.btn-outline-accent { background: var(--surface); color: var(--brand-accent); border-color: var(--brand-accent); }
.btn-outline-accent:hover { background: var(--accent-soft); }

/* ---- التبويبات ---- */
.tabs {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.tab {
  display: inline-flex; align-items: center; gap: 7px; padding: 11px 16px;
  border: 0; border-bottom: 3px solid transparent; background: transparent;
  color: var(--text-2); font-family: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.tab:hover { color: var(--heading); text-decoration: none; }
.tab.active { color: var(--heading); font-weight: 600; border-bottom-color: var(--brand-accent); }
.tab .count {
  padding: 1px 7px; background: var(--muted-bg); border-radius: var(--radius-pill);
  font-size: 11.5px; font-weight: 700; color: var(--text-2);
}
.tab.active .count { background: var(--accent-soft); color: var(--brand-accent); }

/* ---- شريط الأدوات ---- */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.tool-search { position: relative; min-width: 210px; flex: 0 1 260px; }
.tool-search input {
  width: 100%; height: 36px; padding-inline: 34px 12px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  color: var(--text); font-family: inherit; font-size: 13.5px;
}
.tool-search::before { content: "⌕"; position: absolute; inset-inline-start: 11px; top: 50%;
  transform: translateY(-50%); color: var(--text-3); font-size: 15px; pointer-events: none; }
.tool-search input:focus { outline: none; border-color: var(--brand-accent); box-shadow: var(--ring); }

/* رقائق الفلترة */
.chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 14px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-pill);
  color: var(--text); font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast);
}
.chip:hover { border-color: var(--text-3); text-decoration: none; }
.chip.on { border-color: var(--brand-accent); color: var(--brand-accent); background: var(--accent-soft); font-weight: 600; }
.chip select {
  border: 0; background: transparent; color: inherit; font-family: inherit; font-size: 13px;
  font-weight: inherit; cursor: pointer; padding: 0; min-width: 60px;
}
.chip select:focus { outline: none; }

/* ---- البطاقات ---- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 16px;
}
.card-title {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  font-size: 15px; font-weight: 700; color: var(--heading);
  padding-bottom: 13px; margin-bottom: 15px; border-bottom: 1px solid var(--line);
}
.card-title .spacer { flex: 1; }
.hint { font-size: 12.5px; color: var(--text-2); line-height: 1.75; }

/* ---- بطاقات المؤشرات ---- */
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 17px 19px;
}
.kpi-label { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-3); }
.kpi-value { font-family: var(--font-num); font-size: 30px; font-weight: 700; line-height: 1.15;
  color: var(--heading); margin-top: 7px; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.kpi-sub { display: block; font-size: 12px; color: var(--text-2); margin-top: 5px; }
.kpi-up { color: var(--ok); font-weight: 600; }
.kpi-down { color: var(--danger); font-weight: 600; }

/* ---- الجداول ---- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow-x: auto; margin-bottom: 16px;
}
.table { width: 100%; border-collapse: collapse; min-width: 680px; }
.table thead th {
  padding: 12px 16px; text-align: start; white-space: nowrap;
  font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-3); background: var(--surface); border-bottom: 1px solid var(--line-strong);
}
.table thead th a { color: inherit; }
.table thead th a::after { content: " ⇅"; opacity: .45; font-size: 10px; }
.table tbody td {
  padding: 13px 16px; font-size: 13.5px; color: var(--text);
  border-bottom: 1px solid var(--line); vertical-align: middle; font-variant-numeric: tabular-nums;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--accent-soft); }
.table a { color: var(--link); font-weight: 500; }
.card > .table { min-width: 0; }

/* خلية الهوية: صورة رمزية + اسم + وصف */
.cell-id { display: flex; align-items: center; gap: 11px; }
.cell-id .avatar { width: 32px; height: 32px; font-size: 12px; }
.cell-id-text { min-width: 0; }
.cell-id-text strong { display: block; font-size: 13.5px; font-weight: 600; color: var(--brand-accent); }
.cell-id-text a { color: var(--brand-accent); font-weight: 600; }
.cell-id-text span { display: block; font-size: 12px; color: var(--text-3); }
.cell-owner { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.cell-score { font-family: var(--font-num); font-weight: 700; color: var(--brand-accent); font-size: 14px; }
.cell-muted { color: var(--text-3); }

/* ---- الشارات ---- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: var(--radius-xs); font-size: 11.5px; font-weight: 600; white-space: nowrap; line-height: 1.6;
}
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-green { background: var(--green-bg); color: var(--green); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-danger { background: var(--danger-bg); color: var(--danger); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-muted { background: var(--muted-bg); color: var(--text-2); }
.b-accent { background: var(--accent-soft); color: var(--brand-accent); }
.tag-chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius-pill);
  font-size: 12px; color: var(--text-2); }

/* ---- النماذج ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--heading); }
.field input, .field select, .field textarea,
input[type="month"], input[type="date"], input[type="datetime-local"] {
  width: 100%; padding: 9px 12px; min-height: 40px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.field textarea { min-height: 100px; resize: vertical; line-height: 1.65; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand-accent); box-shadow: var(--ring);
}
.field input::placeholder, .field textarea::placeholder { color: var(--text-3); }
.field input:disabled, .field select:disabled { background: var(--surface-2); color: var(--text-3); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field-error, .err { color: var(--danger); font-size: 12px; font-weight: 500; margin-top: 3px; }
.form-grid { display: grid; gap: 15px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .form-grid { grid-template-columns: repeat(2,1fr); } }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-top: 20px; padding-top: 17px; border-top: 1px solid var(--line); }

.filters {
  display: flex; gap: 11px; flex-wrap: wrap; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 17px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.filters .field { margin-bottom: 0; min-width: 145px; }

/* ---- سجل العميل (ثلاثة أعمدة) ---- */
.record { display: grid; gap: 16px; grid-template-columns: 1fr; align-items: start; margin-bottom: 18px; }
@media (min-width: 1100px) { .record { grid-template-columns: 300px minmax(0,1fr); } }
@media (min-width: 1500px) { .record { grid-template-columns: 300px minmax(0,1fr) 320px; } }
.record-aside { display: flex; flex-direction: column; gap: 16px; }
@media (min-width: 1100px) { .record-aside { position: sticky; top: calc(var(--topbar-h) + 18px); } }

.record-id { text-align: center; padding: 22px 20px; }
.record-id .avatar { margin: 0 auto 12px; }
.record-id h2 { font-size: 19px; margin-bottom: 3px; }
.record-id .role { font-size: 13px; color: var(--text-2); }
.record-id .contact-line { font-size: 13.5px; margin-top: 6px; }

/* أزرار الإجراءات الدائرية */
.quick-actions { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.qa {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: transparent; border: 0; font-family: inherit; cursor: pointer;
  color: var(--text-2); font-size: 11px; width: 56px;
}
.qa i {
  width: 38px; height: 38px; display: grid; place-items: center; font-style: normal; font-size: 15px;
  border: 1px solid var(--line-strong); border-radius: 50%; background: var(--surface);
  color: var(--link); transition: border-color var(--t-fast), background var(--t-fast);
}
.qa:hover { text-decoration: none; color: var(--heading); }
.qa:hover i { border-color: var(--brand-accent); background: var(--accent-soft); color: var(--brand-accent); }

/* أقسام قابلة للطي */
.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.section > summary, .section-head {
  display: flex; align-items: center; gap: 9px; padding: 14px 18px; cursor: pointer;
  font-size: 14px; font-weight: 700; color: var(--heading); list-style: none;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before { content: "▸"; font-size: 11px; color: var(--text-3); transition: transform var(--t-fast); }
.section[open] > summary::before { transform: rotate(90deg); }
html[dir="rtl"] .section > summary::before { content: "◂"; }
html[dir="rtl"] .section[open] > summary::before { transform: rotate(-90deg); }
.section > summary .spacer, .section-head .spacer { flex: 1; }
.section-body { padding: 4px 18px 18px; border-top: 1px solid var(--line); padding-top: 16px; }

/* قائمة تسمية/قيمة */
.kv { display: grid; gap: 13px; }
.kv > div { display: grid; gap: 2px; }
.kv dt, .kv .k { font-size: 12px; color: var(--text-2); }
.kv dd, .kv .v { font-size: 14px; color: var(--heading); font-weight: 500; margin: 0; }
@media (min-width: 700px) { .kv.kv-2 { grid-template-columns: 1fr 1fr; gap: 14px 20px; } }

/* ---- لوحة Kanban ---- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(280px,1fr);
  gap: 14px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 16px; }
.kanban-col { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; min-height: 230px; }
.kanban-col-head { display: flex; align-items: center; gap: 9px; padding: 12px 15px;
  font-size: 13px; font-weight: 700; color: var(--heading);
  border-bottom: 1px solid var(--line); border-top: 3px solid var(--col-color, var(--brand-accent));
  border-radius: var(--radius) var(--radius) 0 0; }
.kanban-count { margin-inline-start: auto; padding: 1px 9px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill); font-size: 11px; color: var(--text-2); }
.kanban-body { padding: 10px; display: flex; flex-direction: column; gap: 9px; flex: 1; min-height: 60px; }
.kanban-body.drag-over { background: var(--accent-soft); }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 12px 14px; cursor: grab; font-size: 13.5px;
  transition: box-shadow var(--t-fast), border-color var(--t-fast); }
.kcard:hover { box-shadow: var(--shadow-md); border-color: var(--line-strong); }
.kcard.dragging { opacity: .45; }
.kcard strong { display: block; font-weight: 600; font-size: 13.5px; color: var(--heading); }
.kmeta { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 8px; font-size: 11.5px; color: var(--text-2); }
.kscore { font-family: var(--font-num); font-weight: 700; color: var(--brand-accent); }

/* ---- التنبيهات ---- */
.toast { position: relative; padding: 13px 17px; margin-bottom: 15px;
  background: var(--surface); border: 1px solid var(--line);
  border-inline-start: 3px solid var(--info); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); font-size: 13.5px; animation: toastIn .22s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } }
.toast-success { border-inline-start-color: var(--ok); }
.toast-error { border-inline-start-color: var(--danger); }
.toast-warning { border-inline-start-color: var(--warn); }

/* ---- النافذة المشروطة ---- */
.modal-overlay { position: fixed; inset: 0; z-index: 200; padding: 16px;
  background: rgba(16,26,36,.55); display: grid; place-items: center; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 26px;
  max-width: 430px; width: 100%; box-shadow: var(--shadow-lg); animation: modalIn .18s ease; }
.modal h3 { font-size: 16px; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
@keyframes modalIn { from { opacity: 0; transform: scale(.97); } }

/* ---- الحالات الفارغة ---- */
.empty-state { text-align: center; padding: 54px 20px; color: var(--text-2); font-size: 13.5px; }
.empty-state .empty-icon { display: grid; place-items: center; width: 62px; height: 62px; margin: 0 auto 15px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 50%; font-size: 26px; }
.empty-state strong { display: block; color: var(--heading); font-size: 15.5px; font-weight: 700; margin-bottom: 5px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--radius-xs); min-height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- الترقيم ---- */
.pagination { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.pagination a { padding: 7px 13px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 13px; color: var(--text); }
.pagination a:hover { background: var(--surface-2); text-decoration: none; }
.pagination a.active { background: var(--brand-accent); color: #fff; border-color: var(--brand-accent); }
.pg-total { color: var(--text-3); font-size: 12.5px; margin-inline-start: 8px; }

/* ---- الخط الزمني ---- */
.timeline { position: relative; padding-inline-start: 24px; }
.timeline::before { content: ""; position: absolute; inset-block: 6px; inset-inline-start: 6px;
  width: 2px; background: var(--line); }
.tl-item { position: relative; padding-bottom: 22px; }
.tl-item::before { content: ""; position: absolute; inset-inline-start: -23px; top: 5px;
  width: 11px; height: 11px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand-accent); }
.tl-time { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.tl-body { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 11px 14px; margin-top: 6px; font-size: 13.5px; line-height: 1.7; }

/* ---- التقدم ---- */
.progress { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-pill);
  height: 8px; overflow: hidden; }
.progress span { display: block; height: 100%; border-radius: var(--radius-pill);
  background: var(--brand-accent); transition: width var(--t); }

/* ---- صندوق الرسائل ---- */
.inbox { display: grid; grid-template-columns: 1fr; border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; background: var(--surface); min-height: 64vh; box-shadow: var(--shadow); }
@media (min-width: 900px) { .inbox { grid-template-columns: 320px 1fr; } }
.inbox-list { border-inline-end: 1px solid var(--line); overflow-y: auto; max-height: 74vh; background: var(--surface-2); }
@media (max-width: 899px) { .inbox-list.has-open { display: none; } }
.conv-item { display: flex; gap: 11px; align-items: center; padding: 13px 15px;
  border-bottom: 1px solid var(--line); color: var(--text); }
.conv-item:hover { background: var(--surface); text-decoration: none; }
.conv-item.active { background: var(--surface); box-shadow: inset 3px 0 0 var(--brand-accent); }
html[dir="rtl"] .conv-item.active { box-shadow: inset -3px 0 0 var(--brand-accent); }
.conv-item img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.conv-meta { min-width: 0; flex: 1; }
.conv-meta strong { display: flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600; color: var(--heading); }
.conv-meta span { display: block; font-size: 12px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-thread { display: flex; flex-direction: column; min-height: 64vh; }
.thread-msgs { flex: 1; padding: 20px; overflow-y: auto; max-height: 62vh; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 74%; padding: 10px 14px; border-radius: 16px; font-size: 13.5px; line-height: 1.6; }
.msg.in { background: var(--surface-2); border: 1px solid var(--line); align-self: flex-start; border-start-start-radius: 4px; }
.msg.out { background: var(--brand-accent); color: #fff; align-self: flex-end; border-start-end-radius: 4px; }
.msg time { display: block; font-size: 10.5px; opacity: .7; margin-top: 4px; }
.thread-input { display: flex; gap: 9px; padding: 13px; border-top: 1px solid var(--line); background: var(--surface); }
.thread-input input { flex: 1; padding: 10px 15px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill); background: var(--surface); color: var(--text); font-family: inherit; font-size: 14px; }
.thread-input input:focus { outline: none; border-color: var(--brand-accent); box-shadow: var(--ring); }

/* ---- القمع ---- */
.funnel-step { background: var(--brand-accent); color: #fff; padding: 14px 18px; border-radius: var(--radius-sm);
  margin: 0 auto; text-align: center; font-weight: 600; font-size: 13.5px;
  font-variant-numeric: tabular-nums; transition: width var(--t); }
.funnel-step:nth-child(4n) { background: color-mix(in srgb, var(--brand-accent) 78%, #1B2A3A); }
.funnel-drop { text-align: center; font-size: 11.5px; color: var(--text-3); padding: 6px 0; font-weight: 600; }

/* ---- متفرقات ---- */
.meta { display: flex; gap: 15px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.check { color: var(--ok); font-weight: 700; }
.no { color: var(--danger); font-weight: 700; }
.nps, .total { font-family: var(--font-num); font-weight: 700; font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }
.footer { text-align: center; padding: 24px 0 6px; color: var(--text-3); font-size: 12px; }

/* ============================================================
   بطاقات المؤشرات الملوّنة
   ============================================================ */
.kpi { position: relative; overflow: hidden; padding: 18px 20px 20px; }
.kpi::after {
  content: ""; position: absolute; inset-inline: 0; bottom: 0; height: 3px;
  background: var(--k, var(--brand-accent));
}
.kpi .kpi-value { color: var(--k, var(--heading)); font-size: 34px; font-weight: 700; }
.kpi .kpi-label { order: 2; }
.kpi-icon {
  position: absolute; inset-inline-end: 16px; top: 50%; transform: translateY(-50%);
  font-size: 40px; line-height: 1; opacity: .13; pointer-events: none; user-select: none;
}
.k-orange { --k: var(--k-orange); }
.k-teal   { --k: var(--k-teal); }
.k-blue   { --k: var(--k-blue); }
.k-purple { --k: var(--k-purple); }
.k-green  { --k: var(--k-green); }
.k-pink   { --k: var(--k-pink); }
.k-plain  { --k: var(--line-strong); }
.k-plain .kpi-value { color: var(--heading); }

/* ============================================================
   الحالة الفارغة داخل إطار متقطّع
   ============================================================ */
.empty-wrap {
  border: 2px dashed var(--line-strong); border-radius: var(--radius);
  background: var(--surface); padding: 20px; margin-bottom: 18px;
}
.empty-state { padding: 60px 24px; }
.empty-state .empty-icon {
  width: 84px; height: 84px; margin: 0 auto 20px; border-radius: 20px; border: 0;
  background: var(--accent-soft); color: var(--brand-accent); font-size: 34px;
}
.empty-state strong { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.empty-state p { max-width: 420px; margin: 0 auto 20px; color: var(--text-2); line-height: 1.8; }

/* رأس الصفحة بأيقونة */
.page-head .head-icon {
  width: 40px; height: 40px; border-radius: var(--radius-sm); flex-shrink: 0;
  display: grid; place-items: center; font-size: 19px;
  background: var(--accent-soft); color: var(--brand-accent);
}
.page-head .head-text { display: flex; align-items: center; gap: 12px; }
