/* =============================================================================
   components.css — مكوّنات مشتركة بين كل الشاشات
   ============================================================================= */

/* ------------------------------- الشريط العلوي ------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex; align-items: center; gap: var(--sp-4);
  height: 64px; padding-inline: var(--sp-6);
  max-width: 1440px; margin-inline: auto;
}
.brand {
  display: flex; align-items: center; gap: var(--sp-3);
  font-family: var(--font-display); font-weight: 800; font-size: 1.15rem;
  color: var(--text);
}
.brand-mark {
  width: 40px; height: 40px; border-radius: var(--r-sm);
  display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-700));
  color: var(--on-brand); font-size: 1.3rem; box-shadow: var(--shadow-brand);
}
.brand small { display: block; font-family: var(--font-body); font-weight: 500;
  font-size: .72rem; color: var(--text-muted); }

.topbar-nav { display: flex; gap: var(--sp-1); margin-inline-start: var(--sp-4); }
.topbar-nav a {
  padding: 8px 16px; border-radius: var(--r-pill); font-weight: 600;
  font-size: .92rem; color: var(--text-2); transition: all var(--dur-fast) var(--ease);
}
.topbar-nav a:hover { background: var(--surface-2); color: var(--text); }
.topbar-nav a.active { background: var(--brand); color: var(--on-brand); }

/* ------------------------------- زر السمة ------------------------------ */
.theme-toggle {
  width: 46px; height: 46px; border-radius: var(--r-sm);
  display: grid; place-items: center; flex: none;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); transition: all var(--dur) var(--ease);
  position: relative; overflow: hidden;
}
.theme-toggle:hover { border-color: var(--brand); transform: translateY(-1px); }
.theme-toggle svg { width: 22px; height: 22px; transition: transform var(--dur-slow) var(--ease-out); }
.theme-toggle .sun { display: none; }
[data-theme="dark"] .theme-toggle .sun { display: block; }
[data-theme="dark"] .theme-toggle .moon { display: none; }

/* ------------------------------- أزرار ------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 11px 20px; border-radius: var(--r-sm); font-weight: 700; font-size: .95rem;
  border: 1px solid transparent; transition: all var(--dur-fast) var(--ease);
  white-space: nowrap; user-select: none;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn svg { width: 18px; height: 18px; }

.btn-primary { background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-brand); }
.btn-primary:hover { background: var(--brand-600); transform: translateY(-1px); }

.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--border-strong); background: var(--surface-3); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); }

.btn-block { width: 100%; }
.btn-lg { padding: 15px 24px; font-size: 1.05rem; border-radius: var(--r-md); }
.btn-sm { padding: 7px 14px; font-size: .85rem; }

/* ------------------------------- بطاقات ------------------------------ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--sp-6); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-6); border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 1.1rem; }
.card-title-eyebrow { font-size: .72rem; letter-spacing: .08em; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase; }

/* ------------------------------- شارات الحالة ------------------------------ */
.status-pill {
  --c: var(--st-idle);
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 13px 5px 11px; border-radius: var(--r-pill);
  font-weight: 700; font-size: .82rem; line-height: 1;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
}
.status-pill .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none;
}
.status-pill.live .dot { animation: livepulse 1.6s var(--ease) infinite; }
@keyframes livepulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 60%, transparent); }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.status-pill[data-status="idle"]      { --c: var(--st-idle); }
.status-pill[data-status="loading"]   { --c: var(--st-loading); }
.status-pill[data-status="enroute"]   { --c: var(--st-enroute); }
.status-pill[data-status="arrived"]   { --c: var(--st-arrived); }
.status-pill[data-status="returning"] { --c: var(--st-returning); }
.status-pill[data-status="completed"] { --c: var(--text-muted); }

/* ------------------------------- شارات الصيانة ------------------------------ */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--r-pill);
  font-size: .78rem; font-weight: 700;
}
.chip.ok      { color: var(--ok); background: var(--ok-soft); }
.chip.warn    { color: var(--warn); background: var(--warn-soft); }
.chip.overdue { color: var(--danger); background: var(--danger-soft); }

/* ------------------------------- مقياس الصيانة ------------------------------ */
.gauge { display: flex; flex-direction: column; gap: 8px; }
.gauge-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.gauge-label { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .9rem; }
.gauge-ico { width: 30px; height: 30px; border-radius: var(--r-xs); display: grid; place-items: center; flex:none; }
.gauge-ico.oil     { background: var(--info-soft); color: var(--info); }
.gauge-ico.tires   { background: var(--surface-3); color: var(--text-2); }
.gauge-ico.service { background: var(--brand-soft); color: var(--brand-700); }
.gauge-ico svg { width: 18px; height: 18px; }
.gauge-remaining { font-size: .82rem; font-weight: 700; }
.gauge-track {
  height: 9px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden;
}
.gauge-fill {
  height: 100%; border-radius: var(--r-pill);
  transition: width var(--dur-slow) var(--ease-out);
}
.gauge[data-level="ok"]      .gauge-fill { background: var(--ok); }
.gauge[data-level="ok"]      .gauge-remaining { color: var(--ok); }
.gauge[data-level="warn"]    .gauge-fill { background: var(--warn); }
.gauge[data-level="warn"]    .gauge-remaining { color: var(--warn); }
.gauge[data-level="overdue"] .gauge-fill { background: var(--danger); }
.gauge[data-level="overdue"] .gauge-remaining { color: var(--danger); }

/* ------------------------------- جداول ------------------------------ */
.table-wrap { overflow-x: auto; border-radius: var(--r-md); }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: right; font-weight: 700; font-size: .8rem;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em;
  padding: 13px 16px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data tbody td {
  padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle;
}
table.data tbody tr { transition: background var(--dur-fast) var(--ease); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
.cell-strong { font-weight: 700; color: var(--text); }

/* ------------------------------- نماذج ------------------------------ */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: var(--sp-4); }
.field label { font-weight: 700; font-size: .88rem; color: var(--text-2); }
.input, .select {
  width: 100%; padding: 12px 14px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1.5px solid var(--border);
  color: var(--text); transition: all var(--dur-fast) var(--ease);
}
.input::placeholder { color: var(--text-muted); }
.input:focus, .select:focus {
  outline: none; border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent);
}
.select { appearance: none; background-image:
  url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%237A879B' stroke-width='2'><path d='M4 6l4 4 4-4'/></svg>");
  background-repeat: no-repeat; background-position: left 14px center; padding-left: 40px; }

/* شريط بحث */
.search {
  display: flex; align-items: center; gap: 10px; flex: 1; max-width: 380px;
  padding: 9px 14px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1.5px solid var(--border);
  transition: border var(--dur-fast) var(--ease);
}
.search:focus-within { border-color: var(--brand); }
.search svg { width: 18px; height: 18px; color: var(--text-muted); flex: none; }
.search input { flex: 1; background: none; border: none; outline: none; color: var(--text); }

/* ================================================================
   نظام النوافذ المنبثقة (Modals) + الأوراق السفلية (Bottom Sheets)
   ================================================================ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(6, 11, 22, .55);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-6);
  opacity: 0; visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility var(--dur) var(--ease);
}
.modal-backdrop.open { opacity: 1; visibility: visible; }

.modal {
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  transform: translateY(16px) scale(.97);
  transition: transform var(--dur) var(--ease-out);
  overscroll-behavior: contain;
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal.wide { max-width: 720px; }

.modal-grip { display: none; }   /* يظهر فقط كورقة سفلية على الجوال */

.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-6) var(--sp-6) var(--sp-4);
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.modal-head h3 { font-size: 1.3rem; }
.modal-head p { color: var(--text-muted); font-size: .9rem; margin-top: 2px; }
.modal-close {
  width: 38px; height: 38px; border-radius: var(--r-sm); flex: none;
  display: grid; place-items: center; background: var(--surface-2);
  color: var(--text-2); border: 1px solid var(--border);
  transition: all var(--dur-fast) var(--ease);
}
.modal-close:hover { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.modal-body { padding: 0 var(--sp-6) var(--sp-6); }
.modal-foot {
  display: flex; gap: var(--sp-3); padding: var(--sp-4) var(--sp-6) var(--sp-6);
  position: sticky; bottom: 0; background: var(--surface);
}
.modal-foot .btn { flex: 1; }

/* على الجوال: تتحول النافذة إلى ورقة سفلية قابلة للسحب للأسفل */
@media (max-width: 640px) {
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%; max-height: 92vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    transform: translateY(100%);
  }
  .modal-backdrop.open .modal { transform: translateY(0); }
  /* أثناء السحب باللمس نلغي الانتقال ليتبع الإصبع */
  .modal.dragging { transition: none; }
  .modal-grip {
    display: block; width: 42px; height: 5px; border-radius: var(--r-pill);
    background: var(--border-strong); margin: 10px auto 0; flex: none;
    cursor: grab;
  }
  .modal-head { padding-top: var(--sp-3); }
}

/* منع تمرير الجسم عند فتح نافذة (Scroll Lock) */
body.scroll-locked { position: fixed; inset: 0; width: 100%; overflow: hidden; }

/* ------------------------------- إشعارات (Toasts) ------------------------------ */
.toast-wrap {
  position: fixed; z-index: 200; bottom: 22px; left: 22px;
  display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 12px;
  min-width: 260px; max-width: 380px;
  padding: 14px 18px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); color: var(--text);
  transform: translateX(-120%); opacity: 0;
  transition: transform var(--dur) var(--ease-out), opacity var(--dur) var(--ease);
  pointer-events: auto;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast .bar { width: 4px; align-self: stretch; border-radius: var(--r-pill); flex: none; }
.toast.ok      .bar { background: var(--ok); }
.toast.warn    .bar { background: var(--warn); }
.toast.danger  .bar { background: var(--danger); }
.toast.info    .bar { background: var(--info); }
.toast strong { font-family: var(--font-display); display:block; font-size: .95rem; }
.toast span { color: var(--text-muted); font-size: .85rem; }

/* ------------------------------- حالة فارغة ------------------------------ */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: var(--sp-12) var(--sp-6); text-align: center; color: var(--text-muted);
}
.empty svg { width: 48px; height: 48px; opacity: .5; }

/* دخول العناصر */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.animate-in { animation: fadeUp var(--dur-slow) var(--ease-out) both; }
