/* ============================================================
   الفرسان SPKS · مكتبة المكوّنات
   ============================================================ */

/* ---------------- الأزرار ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: 10px var(--s4); border-radius: var(--r-sm);
  font-family: var(--font-display); font-size: var(--fs-sm); font-weight: 600;
  border: 1px solid transparent; transition: var(--tr);
  white-space: nowrap; line-height: 1.4; user-select: none;
}
.btn:disabled { opacity: .5; pointer-events: none; }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-blue); }
.btn-primary:hover { background: var(--primary-hov); text-decoration: none; }

.btn-ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line); box-shadow: var(--shadow-1); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary); text-decoration: none; }

.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-soft:hover { background: var(--primary); color: var(--on-primary); text-decoration: none; }

.btn-quiet { color: var(--muted); }
.btn-quiet:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }

.btn-danger { background: var(--crit); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); text-decoration: none; }

.btn-lg { padding: 13px var(--s5); font-size: var(--fs-md); border-radius: 11px; }
.btn-sm { padding: 6px var(--s3); font-size: var(--fs-xs); border-radius: 7px; }
.btn-icon { padding: 9px; }
.btn-block { width: 100%; }

/* ---------------- البطاقات ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
}
.card-pad { padding: var(--s5); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line-2);
}
.card-head h3 { font-size: var(--fs-md); font-weight: 700; }
.card-head .sub { font-size: var(--fs-xs); color: var(--muted); font-weight: 400; }

/* بطاقة مؤشر KPI */
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: var(--s5); box-shadow: var(--shadow-1);
  display: flex; align-items: flex-start; gap: var(--s4); transition: var(--tr);
}
.kpi:hover { box-shadow: var(--shadow-2); border-color: #CBD5E1; }
.kpi .ico {
  width: 48px; height: 48px; border-radius: 13px; flex: none;
  display: grid; place-items: center; padding: 12px;
}
.kpi .ico svg { width: 100%; height: 100%; }
.kpi .body { flex: 1; min-width: 0; }
.kpi .label { font-size: var(--fs-sm); color: var(--muted); font-weight: 500; margin-bottom: 3px; }
.kpi .value {
  font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 700;
  line-height: 1.15; color: var(--ink); letter-spacing: -.02em;
}
.kpi .delta { font-size: var(--fs-xs); margin-top: 5px; display: flex; align-items: center; gap: 4px; }
.kpi .delta.up   { color: var(--ok); }
.kpi .delta.down { color: var(--crit); }
.kpi .delta span { color: var(--muted); }

/* ---------------- الشارات ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.5; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-flat::before { display: none; }
.badge-ok    { background: var(--ok-soft);      color: var(--ok); }
.badge-warn  { background: var(--warn-soft);    color: var(--warn); }
.badge-crit  { background: var(--crit-soft);    color: var(--crit); }
.badge-info  { background: var(--info-soft);    color: var(--info); }
.badge-blue  { background: var(--primary-soft); color: var(--primary); }
.badge-mute  { background: var(--surface-3);    color: var(--muted); }

/* ---------------- الحقول ---------------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.field label .req { color: var(--crit); margin-inline-start: 3px; }
.input, .select, .textarea {
  width: 100%; padding: 11px var(--s3);
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  transition: var(--tr); font-size: var(--fs-md); font-family: inherit;
}
.input:hover, .select:hover, .textarea:hover { border-color: #CBD5E1; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring);
}
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: .75; }
.textarea { resize: vertical; min-height: 96px; line-height: 1.7; }
.input.err, .select.err, .textarea.err { border-color: var(--crit); box-shadow: 0 0 0 4px var(--crit-soft); }
.field .msg  { font-size: var(--fs-xs); color: var(--crit); }
.field .hint { font-size: var(--fs-xs); color: var(--muted); }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-size: 16px;
  background-position: left var(--s3) center; padding-inline-end: var(--s3); padding-inline-start: 38px;
}
html[dir="rtl"] .select { background-position: left var(--s3) center; }
html[dir="ltr"] .select { background-position: right var(--s3) center; padding-inline-start: var(--s3); padding-inline-end: 38px; }

.check { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--ink-2); cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }

/* حقل بحث بأيقونة */
.search-field { position: relative; }
.search-field .input { padding-inline-start: 42px; }
.search-field > svg {
  position: absolute; inset-inline-start: 14px; inset-block-start: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; color: var(--muted); pointer-events: none;
}

/* ---------------- الجداول ---------------- */
.table-wrap {
  overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); box-shadow: var(--shadow-1);
}
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.data th, table.data td {
  padding: 13px var(--s4); text-align: start; border-bottom: 1px solid var(--line-2); vertical-align: middle;
}
table.data thead th {
  background: var(--surface-2); font-family: var(--font-display); font-weight: 700;
  font-size: var(--fs-xs); color: var(--muted); white-space: nowrap;
  position: sticky; top: 0; z-index: 1; letter-spacing: .01em;
}
table.data thead th.sortable { cursor: pointer; user-select: none; }
table.data thead th.sortable:hover { color: var(--primary); }
table.data tbody tr { transition: background var(--tr); }
table.data tbody tr:hover { background: var(--primary-soft); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.actions { white-space: nowrap; }
table.data td.mono, table.data td .mono { white-space: nowrap; }
table.data td a { color: var(--ink); font-weight: 600; }
table.data td a:hover { color: var(--primary); text-decoration: none; }

/* صورة مصغّرة داخل الجدول */
.tbl-thumb {
  width: 42px; height: 42px; border-radius: 10px; overflow: hidden; flex: none;
  background: var(--surface-3); display: grid; place-items: center; color: var(--muted);
  border: 1px solid var(--line-2);
}
.tbl-thumb img { width: 100%; height: 100%; object-fit: cover; }
.tbl-thumb svg { width: 45%; height: 45%; }

/* ---------------- الحالات ---------------- */
.empty, .errorbox {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s3); padding: var(--s8) var(--s5); text-align: center; color: var(--muted);
}
.empty .ic {
  width: 62px; height: 62px; border-radius: 50%; background: var(--primary-soft);
  color: var(--primary); display: grid; place-items: center; padding: 16px; margin-bottom: 2px;
}
.empty .ic svg { width: 100%; height: 100%; }
.empty h4 { color: var(--ink); font-size: var(--fs-lg); }
.empty p { max-width: 44ch; font-size: var(--fs-sm); line-height: 1.7; }

.skel { background: var(--surface-3); border-radius: var(--r-sm); position: relative; overflow: hidden; }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(148, 163, 184, .18), transparent);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skel-line { height: 13px; margin-bottom: 9px; }
.skel-line:last-child { width: 55%; margin-bottom: 0; }

.spinner {
  width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.35);
  border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite;
}
.btn-ghost .spinner, .btn-quiet .spinner { border-color: var(--line); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- التنبيهات ---------------- */
#toasts {
  position: fixed; inset-block-end: var(--s5); inset-inline-end: var(--s5);
  display: flex; flex-direction: column; gap: var(--s2); z-index: 9000; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--s3);
  min-width: 280px; max-width: 420px; padding: var(--s3) var(--s4);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); box-shadow: var(--shadow-3);
  font-size: var(--fs-sm); font-weight: 500; pointer-events: auto; animation: toast-in .24s cubic-bezier(.2,.9,.3,1.1);
}
.toast .tico { width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center; padding: 7px; }
.toast .tico svg { width: 100%; height: 100%; }
.toast.ok   .tico { background: var(--ok-soft);   color: var(--ok); }
.toast.err  .tico { background: var(--crit-soft); color: var(--crit); }
.toast.warn .tico { background: var(--warn-soft); color: var(--warn); }
.toast.info .tico { background: var(--primary-soft); color: var(--primary); }
.toast.out { animation: toast-out .2s ease-in forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(14px) scale(.97); } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(8px); } }

/* ---------------- النوافذ ---------------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(4px); z-index: 8000;
  display: flex; align-items: center; justify-content: center; padding: var(--s4);
  animation: fade .18s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-3); width: 100%; max-width: 580px;
  max-height: 88vh; display: flex; flex-direction: column;
  animation: pop .22s cubic-bezier(.2, .9, .3, 1.15);
}
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(10px); } }
.modal.wide { max-width: 900px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line-2);
}
.modal-head h3 { font-size: var(--fs-lg); font-weight: 700; }
.modal-body { padding: var(--s5); overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: var(--s2);
  padding: var(--s4) var(--s5); border-top: 1px solid var(--line-2);
  background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* ---------------- التبويبات ---------------- */
.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 5px;
  background: var(--surface-3); border-radius: 12px; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 9px 16px; border-radius: 9px; font-size: var(--fs-sm); white-space: nowrap;
  font-family: var(--font-display); font-weight: 600; color: var(--muted); transition: var(--tr);
  display: inline-flex; align-items: center; gap: 7px;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-1); }
.tab .cnt {
  font-size: 10.5px; background: var(--surface-3); color: var(--muted);
  padding: 1px 6px; border-radius: var(--r-full); font-family: var(--font-mono);
}
.tab.active .cnt { background: var(--primary-soft); color: var(--primary); }

/* ---------------- بطاقة المنتج ---------------- */
.pcard {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  overflow: hidden; transition: var(--tr); display: flex; flex-direction: column;
  color: inherit; text-decoration: none; box-shadow: var(--shadow-1);
}
.pcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-3); border-color: var(--primary); text-decoration: none; }
.pcard .media {
  aspect-ratio: 4 / 3; background: var(--surface-3); position: relative;
  display: grid; place-items: center; color: var(--muted); overflow: hidden;
}
.pcard .media img { width: 100%; height: 100%; object-fit: cover; }
.pcard .media > svg { width: 34%; height: 34%; opacity: .5; }
.pcard .media .tag { position: absolute; inset-block-start: 10px; inset-inline-start: 10px; }
.pcard .body { padding: var(--s4); display: flex; flex-direction: column; gap: 5px; flex: 1; }
.pcard .code { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--primary); font-weight: 600; }
.pcard .name {
  font-family: var(--font-display); font-weight: 700; font-size: var(--fs-md); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pcard .alt { font-size: var(--fs-xs); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .foot {
  margin-top: auto; padding-top: var(--s3); display: flex; align-items: center;
  justify-content: space-between; gap: var(--s2); border-top: 1px solid var(--line-2);
}
.pcard .price { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-md); color: var(--ink); }

/* ---------------- قائمة الأكثر بحثاً ---------------- */
.rank-row {
  display: flex; align-items: center; gap: var(--s3);
  padding: 11px var(--s5); border-bottom: 1px solid var(--line-2);
  color: inherit; text-decoration: none; transition: var(--tr);
}
.rank-row:last-child { border-bottom: 0; }
.rank-row:hover { background: var(--primary-soft); text-decoration: none; }
.rank-row .n {
  width: 24px; height: 24px; border-radius: 7px; flex: none; display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  background: var(--surface-3); color: var(--muted);
}
.rank-row:nth-child(1) .n { background: var(--primary); color: var(--on-primary); }
.rank-row:nth-child(2) .n { background: var(--primary-soft); color: var(--primary); }
.rank-row .txt { flex: 1; min-width: 0; }
.rank-row .txt b {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; font-size: var(--fs-sm); font-weight: 600; line-height: 1.45;
}
.rank-row .txt small { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); }
.rank-row .val { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-sm); }

/* ---------------- الخط الزمني للنشاطات ---------------- */
.timeline { display: flex; flex-direction: column; }
.tl-item {
  display: flex; gap: var(--s3); padding: 13px var(--s5);
  border-bottom: 1px solid var(--line-2); align-items: flex-start;
}
.tl-item:last-child { border-bottom: 0; }
.tl-item .dot {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: grid; place-items: center; padding: 8px;
}
.tl-item .dot svg { width: 100%; height: 100%; }
.tl-item .txt { flex: 1; min-width: 0; }
.tl-item .txt b { display: block; font-size: var(--fs-sm); font-weight: 600; }
.tl-item .txt small { color: var(--muted); font-size: var(--fs-xs); display: block; margin-top: 1px; }
.tl-item .when { font-size: 11px; color: var(--muted); white-space: nowrap; flex: none; }

/* ---------------- نقطة بيعية ---------------- */
.sp-item {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s4); background: var(--surface-2);
  border: 1px solid var(--line-2); border-radius: 12px;
}
.sp-item .ck {
  width: 26px; height: 26px; border-radius: 50%; flex: none; margin-top: 1px;
  display: grid; place-items: center; padding: 5px;
  background: var(--ok-soft); color: var(--ok);
}
.sp-item .ck svg { width: 100%; height: 100%; }
.sp-item p { font-size: var(--fs-md); line-height: 1.65; font-weight: 500; }

/* ---------------- شريط التقدّم ---------------- */
.bar { height: 7px; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; flex: 1; }
.bar > i { display: block; height: 100%; border-radius: var(--r-full); transition: width .5s cubic-bezier(.4,0,.2,1); }

/* ---------------- الترقيم ---------------- */
.pager { display: flex; align-items: center; gap: 5px; }
.pager button {
  min-width: 34px; height: 34px; padding: 0 9px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  font-size: var(--fs-sm); font-weight: 600; transition: var(--tr);
}
.pager button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pager button:disabled { opacity: .45; pointer-events: none; }
.pager button.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
