/* ==========================================================
   Components — مكونات قابلة لإعادة الاستخدام في كل الصفحات.
   ========================================================== */

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--touch); padding: 0 var(--sp-4);
  font: inherit; font-size: var(--fs-sm); font-weight: 700; line-height: 1.2;
  color: var(--c-text); background: var(--c-surface);
  border: 1px solid var(--c-border-strong); border-radius: 10px;
  box-shadow: var(--shadow-sm);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--c-surface-2); border-color: var(--c-text-faint); color: var(--c-text); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn--primary { color: var(--c-on-primary); background: linear-gradient(180deg, #14b8a6, #0d9488); border-color: #0d9488; box-shadow: 0 4px 12px rgba(13, 148, 136, 0.3); }
.btn--primary:hover { color: var(--c-on-primary); background: linear-gradient(180deg, #0d9488, #0f766e); border-color: #0f766e; }
.btn--danger { color: #fff; background: var(--c-danger); border-color: var(--c-danger); box-shadow: 0 4px 12px rgba(185, 28, 28, 0.25); }
.btn--danger:hover { color: #fff; background: #991b1b; border-color: #991b1b; }
.btn--ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--c-text-soft); }
.btn--ghost:hover { background: var(--c-bg); border-color: transparent; }
.btn--block { width: 100%; }
.btn--icon { width: var(--touch); padding: 0; }
.btn.is-loading { position: relative; color: transparent; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 1.1rem; height: 1.1rem;
  border: 2px solid; border-color: #fff transparent #fff transparent;
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
.btn:not(.btn--primary):not(.btn--danger).is-loading::after { border-color: var(--c-primary) transparent var(--c-primary) transparent; }

/* ===== Cards ===== */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}
.card__title { margin-block-end: var(--sp-3); }
.muted-block { color: var(--c-text-muted); font-size: var(--fs-sm); margin: 0; }

/* ===== Forms ===== */
.form { display: flex; flex-direction: column; gap: var(--sp-4); }
.modal form { display: flex; flex-direction: column; gap: var(--sp-4); }
.form__actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); justify-content: flex-end; }
.form__actions .btn { flex: 1 1 auto; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field__label { font-weight: 700; font-size: var(--fs-sm); color: var(--c-text); }
.field__hint  { font-size: var(--fs-xs); color: var(--c-text-muted); font-weight: 400; line-height: 1.6; }
.field__error { font-size: var(--fs-sm); color: var(--c-danger); font-weight: 600; display: none; }
.field.is-invalid .field__error { display: block; }
.field.is-invalid .input, .field.is-invalid .select, .field.is-invalid .wx__btn { border-color: var(--c-danger); box-shadow: 0 0 0 4px var(--c-danger-soft); }

.input, .select, .textarea {
  width: 100%; min-height: var(--touch); padding: var(--sp-2) var(--sp-3);
  font: inherit; font-size: 16px; color: var(--c-text); background: var(--c-surface);
  border: 1px solid var(--c-border-strong); border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.input::placeholder, .textarea::placeholder { color: var(--c-text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--c-text-faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 4px var(--c-primary-ring); }
.input:disabled, .select:disabled { background: var(--c-bg); color: var(--c-text-muted); cursor: not-allowed; }
.select--auto, .input--auto { width: auto; min-width: 140px; }

/* select أصلي (على اللمس) */
.select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  background: var(--c-surface) url("data:image/svg+xml,%3Csvg 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'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat left 0.85rem center / 16px;
  padding-inline-end: var(--sp-3); padding-inline-start: 2.5rem;
}
.select option { font: inherit; color: var(--c-text); background: #fff; }

/* بحث بأيقونة */
input[type="search"] { appearance: none; -webkit-appearance: none; }
input[type="search"]::-webkit-search-cancel-button { appearance: none; }
.search input[type="search"], input.search[type="search"] {
  padding-inline-start: 2.8rem;
  background: var(--c-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='6.8'/%3E%3Cpath d='m20.5 20.5-4.7-4.7'/%3E%3C/svg%3E") no-repeat right 0.95rem center / 18px;
}

/* تاريخ أصلي (على اللمس) */
input[type="date"], input[type="datetime-local"], input[type="month"], input[type="time"] {
  appearance: none; -webkit-appearance: none; font: inherit; min-width: 160px; position: relative;
  background: var(--c-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3.5' y='5' width='17' height='15.5' rx='2.5'/%3E%3Cpath d='M3.5 10h17M8 3v4M16 3v4'/%3E%3C/svg%3E") no-repeat left 0.85rem center / 18px;
  padding-inline-start: 2.6rem;
}
input[type="date"]::-webkit-calendar-picker-indicator, input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator, input[type="time"]::-webkit-calendar-picker-indicator {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;
}
input[type="date"]::-webkit-datetime-edit { padding: 0; }

/* ملفات + checkbox */
input[type="file"] { padding: 6px; cursor: pointer; }
input[type="file"]::file-selector-button {
  font: inherit; font-weight: 700; margin-inline-end: var(--sp-3); padding: 0.45rem 1rem; cursor: pointer;
  color: var(--c-primary-hover); background: var(--c-primary-soft); border: 0; border-radius: 8px;
}
input[type="file"]::file-selector-button:hover { background: #ccefea; }
input[type="checkbox"], input[type="radio"], .toggle { accent-color: var(--c-primary); }

/* حقل الباسورد مع زر إظهار/إخفاء */
.password { position: relative; direction: ltr; }
.password .input { padding-inline-end: calc(var(--touch) + 1.25rem); }
.password__toggle {
  position: absolute; inset-block: 4px; inset-inline-end: 4px; padding: 0 var(--sp-3);
  border: 0; border-radius: 8px; background: transparent;
  color: var(--c-primary); font: inherit; font-size: var(--fs-sm); font-weight: 700; cursor: pointer;
}
.password__toggle:hover { background: var(--c-primary-soft); }

/* checkboxes الصلاحيات */
.checks { display: grid; gap: var(--sp-2); grid-template-columns: 1fr; }
@media (min-width: 640px) { .checks { grid-template-columns: 1fr 1fr; } }
.check {
  display: flex; align-items: flex-start; gap: var(--sp-2); min-height: var(--touch);
  padding: var(--sp-2) var(--sp-3); cursor: pointer;
  background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: var(--radius);
  transition: border-color 0.15s, background 0.15s;
}
.check:hover { border-color: var(--c-primary); background: var(--c-primary-soft); }
.check input { width: 1.25rem; height: 1.25rem; margin-block-start: 0.2rem; flex-shrink: 0; }
.check:has(input:disabled) { color: var(--c-text-muted); cursor: not-allowed; background: var(--c-bg); }
.check small { display: block; color: var(--c-text-muted); font-size: var(--fs-xs); }
.check small.dep { color: var(--c-primary-hover); font-weight: 600; }

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center; padding: 0 var(--sp-3);
  font-size: var(--fs-xs); font-weight: 700; line-height: 1.9; white-space: nowrap;
  border-radius: 999px; background: var(--c-bg); color: var(--c-text-muted); border: 1px solid var(--c-border);
}
.badge--success { background: var(--c-success-soft); color: var(--c-success); border-color: var(--c-success-border); }
.badge--warning { background: var(--c-warning-soft); color: var(--c-warning); border-color: var(--c-warning-border); }
.badge--danger  { background: var(--c-danger-soft);  color: var(--c-danger);  border-color: var(--c-danger-border); }
.badge--info    { background: var(--c-info-soft);    color: var(--c-info);    border-color: var(--c-info-border); }
.badge-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }

/* ===== Alerts ===== */
.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid transparent;
  border-inline-start-width: 4px;
  font-size: var(--fs-sm); line-height: 1.7;
}
.alert--success { background: var(--c-success-soft); color: var(--c-success); border-color: var(--c-success-border); }
.alert--warning { background: var(--c-warning-soft); color: var(--c-warning); border-color: var(--c-warning-border); }
.alert--danger  { background: var(--c-danger-soft);  color: var(--c-danger);  border-color: var(--c-danger-border); }
.alert--info    { background: var(--c-info-soft);    color: var(--c-info);    border-color: var(--c-info-border); }
.alert .btn { min-height: 34px; margin-inline-start: var(--sp-3); }
.dup-title { font-weight: 800; margin-block-end: var(--sp-1); }
.dup-list { margin: var(--sp-2) 0 0; padding-inline-start: 1.2rem; }
.dup-list li + li { margin-block-start: var(--sp-1); }

/* ===== Responsive table: جدول على الشاشات الكبيرة، كروت على الموبايل =====
   الاستخدام: <table class="table"> وكل <td> فيه data-label باسم العمود. */
.table-wrap {
  width: 100%; overflow-x: auto;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.table { width: 100%; border-collapse: collapse; background: var(--c-surface); }
.table th, .table td { padding: 14px 16px; text-align: center; vertical-align: middle; border-block-end: 1px solid var(--c-border); overflow-wrap: anywhere; }
.table th { font-size: var(--fs-xs); font-weight: 800; color: var(--c-text-muted); background: var(--c-surface-2); white-space: nowrap; }
.table td.ltr, .table th.ltr { text-align: center; }
.table td > .badge, .table td .badge-row { margin-inline: auto; justify-content: center; }
.table tbody tr { transition: background 0.15s; }
.table tbody tr:hover td { background: var(--c-surface-2); }
.table tbody tr:last-child td { border-block-end: 0; }
.table td.actions { text-align: center; }
.table td.actions .btn { margin-inline: auto; }
.client-link { font-weight: 800; color: var(--c-text); text-decoration: none; }
.client-link:hover { color: var(--c-primary); }
@media (min-width: 720px) {
  .table { min-width: 720px; }
  .table td:first-child, .table th:first-child { min-width: 160px; }
}
@media (max-width: 719px) {
  .table-wrap { overflow: visible; background: transparent; border: 0; box-shadow: none; border-radius: 0; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; background: transparent; }
  .table tr {
    margin-block-end: var(--sp-3);
    background: var(--c-surface);
    border: 1px solid var(--c-border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-2) var(--sp-4);
  }
  .table td { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); border: 0; padding: 10px 0; text-align: start; }
  .table td + td { border-block-start: 1px dashed var(--c-border); }
  .table td::before { content: attr(data-label); font-size: var(--fs-xs); font-weight: 700; color: var(--c-text-muted); flex-shrink: 0; }
  .table td.actions { justify-content: stretch; }
  .table td.actions .btn { width: 100%; }
  .table tbody tr:hover td { background: transparent; }
  .table td > .badge, .table td .badge-row, .table td .plates-view { margin-inline: 0; justify-content: flex-start; }
  /* خلايا الأرقام (LTR): نعكس الترتيب عشان العنوان يفضل يمين والقيمة شمال زي باقي الصفوف */
  .table td.ltr { flex-direction: row-reverse; }
}

/* ===== Tabs ===== */
.tabs { display: flex; gap: var(--sp-1); overflow-x: auto; border-block-end: 1px solid var(--c-border); margin-block-end: var(--sp-4); scrollbar-width: none; }
.tab {
  min-height: var(--touch); padding: 0 var(--sp-4);
  display: inline-flex; align-items: center; white-space: nowrap;
  font: inherit; font-size: 0.95rem; font-weight: 700;
  color: var(--c-text-muted); text-decoration: none; background: transparent; border: 0; cursor: pointer;
  border-block-end: 3px solid transparent; border-radius: 10px 10px 0 0;
  transition: color 0.15s, background 0.15s;
}
.tab:hover { background: var(--c-primary-soft); color: var(--c-primary-hover); }
.tab[aria-current="page"] { color: var(--c-primary); border-block-end-color: var(--c-primary); }
@media (min-width: 900px) { .tabs { margin-block-end: var(--sp-5); } }

/* ===== Toolbar (بحث + فلاتر) ===== */
.table-toolbar {
  display: flex; flex-wrap: wrap; gap: var(--sp-3); justify-content: space-between; align-items: center;
  margin-block-end: var(--sp-4); padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.table-toolbar .row { gap: var(--sp-3); }
.table-toolbar .field__label { margin: 0; color: var(--c-text-muted); }
.search { flex: 1 1 220px; max-width: 360px; }
@media (min-width: 900px) { .table-toolbar .search { max-width: 380px; } }

/* ===== Pagination ===== */
.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--sp-3); margin-block-start: var(--sp-4); }
.pagination__info { color: var(--c-text-muted); font-size: var(--fs-sm); font-weight: 600; }

/* ===== States: loading / empty / offline ===== */
.spinner {
  width: 1.6rem; height: 1.6rem; display: inline-block;
  border: 3px solid var(--c-border); border-top-color: var(--c-primary);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.skeleton {
  display: block; height: 1rem; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, #e9eef0 25%, #f4f7f8 50%, #e9eef0 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite;
}
.state { text-align: center; padding: var(--sp-6) var(--sp-4); color: var(--c-text-muted); }
.state__icon { display: grid; place-items: center; width: 68px; height: 68px; margin: 0 auto var(--sp-4); border-radius: 50%; background: var(--c-primary-soft); color: var(--c-primary); font-size: 0; }
.state__icon svg { width: 32px; height: 32px; }
.state__title { color: var(--c-text); }
#loading.state { padding-block: var(--sp-6); }

.offline-banner { position: sticky; top: 0; z-index: 40; padding: var(--sp-2) var(--sp-4); text-align: center; background: var(--c-warning); color: #fff; font-weight: 700; }

/* ===== Icons ===== */
.icon { display: inline-grid; place-items: center; line-height: 0; }
.icon svg { width: 1.35em; height: 1.35em; display: block; }
.tile__icon svg, .stat__icon svg { width: 28px; height: 28px; }

/* ===== Toast ===== */
.toasts {
  position: fixed; z-index: 60; inset-inline: var(--sp-4);
  bottom: calc(var(--bottomnav-h) + var(--sp-3) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: var(--sp-2); align-items: center;
  pointer-events: none;
}
.toast { pointer-events: auto; max-width: 420px; width: 100%; background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow); font-weight: 600; animation: toast-in 0.25s var(--ease) both; }
.toast.alert--success { border-inline-start-color: var(--c-success); }
.toast.alert--danger  { border-inline-start-color: var(--c-danger); }
.toast.alert--warning { border-inline-start-color: var(--c-warning); }
.toast.alert--info    { border-inline-start-color: var(--c-info); }
@media (min-width: 900px) { .toasts { bottom: var(--sp-5); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ===== Modal (عنصر <dialog> الأصلي) ===== */
.modal {
  width: min(92vw, 520px); max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  padding: var(--sp-5); color: var(--c-text); background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: var(--radius-xl); box-shadow: var(--shadow);
}
#create-modal, #edit-modal { width: min(92vw, 680px); }
.modal[open] { animation: pop 0.2s var(--ease) both; }
.modal::backdrop { background: rgba(15, 23, 42, 0.55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.modal h2, .modal h3 { margin-block-end: var(--sp-4); padding-inline-end: 48px; }  /* مساحة لزرار الإغلاق */
.modal { --modal-pad: clamp(1.1rem, 0.6rem + 2vw, 1.9rem); padding: var(--modal-pad); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); }
/* زرار الحفظ والإلغاء: ثابتين تحت النافذة ودايمًا ظاهرين حتى لو الفورم طويل */
.modal__actions {
  position: sticky; bottom: calc(-1 * var(--modal-pad)); z-index: 3;
  display: flex; flex-wrap: nowrap; flex-direction: row-reverse; gap: var(--sp-3);
  margin: var(--sp-5) calc(-1 * var(--modal-pad)) calc(-1 * var(--modal-pad));
  padding: var(--sp-3) var(--modal-pad) calc(var(--sp-3) + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(255,255,255,0.86), #fff 35%);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-block-start: 1px solid var(--c-border);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}
.modal__actions .btn { flex: 1 1 0; min-width: 0; }
@media (min-width: 640px) { .modal__actions { justify-content: flex-start; } .modal__actions .btn { flex: 0 0 auto; min-width: 110px; } }
/* زرار إغلاق (×) فوق على الشمال — بيتضاف تلقائيًا من ui.js */
.modal__close {
  position: sticky; top: 0; z-index: 4;
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0;
  margin-inline-start: auto; margin-block-end: -36px;   /* على الشمال، وبيتراكب على سطر العنوان */
  color: var(--c-text-muted); background: var(--c-bg); border: 1px solid var(--c-border); border-radius: 50%;
  cursor: pointer; line-height: 0; transition: background 0.15s, color 0.15s, transform 0.15s;
}
.modal__close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; pointer-events: none; }
.modal__close:hover { background: var(--c-danger-soft); color: var(--c-danger); border-color: var(--c-danger-border); transform: rotate(90deg); }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ===== Auth ===== */
.secret { font-family: var(--font-mono); font-size: var(--fs-lg); font-weight: 700; letter-spacing: 0.06em; direction: ltr; text-align: center; background: var(--c-surface-2); border: 2px dashed var(--c-border-strong); border-radius: var(--radius); padding: var(--sp-4); user-select: all; word-break: break-all; }
.auth-page { max-width: none; margin: 0; min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-4); background: radial-gradient(1200px 600px at 100% -10%, #ccfbf1 0%, transparent 60%), radial-gradient(900px 500px at -10% 110%, #dbeafe 0%, transparent 60%), var(--c-bg); }
.auth-card { width: min(100%, 420px); padding: var(--sp-6); border-radius: 22px; box-shadow: var(--shadow); }
.auth-card__brand { text-align: center; font-size: var(--fs-xl); font-weight: 800; color: var(--c-primary-hover); margin-block-end: var(--sp-4); }
.auth-card__brand::before {
  content: ""; display: block; width: 56px; height: 56px; margin: 0 auto var(--sp-3); border-radius: 16px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='5' y='3.5' width='14' height='17' rx='2'/%3E%3Cpath d='M9 8h2M13 8h2M9 12h2M13 12h2M10 20.5v-4h4v4'/%3E%3C/svg%3E") center / 28px no-repeat, linear-gradient(135deg, #14b8a6, #0d9488);
  box-shadow: 0 8px 20px rgba(13, 148, 136, 0.4);
}
.auth-card form + .muted-block { margin-block-start: var(--sp-4); text-align: center; }
.auth-card__title { text-align: center; font-size: var(--fs-xl); font-weight: 800; margin-block-end: var(--sp-4); }

/* ===== الصفحة الرئيسية ===== */
.hero { position: relative; overflow: hidden; background: radial-gradient(700px 240px at 0% 0%, rgba(255,255,255,0.16), transparent 60%), linear-gradient(135deg, #0f766e 0%, #0d9488 55%, #14b8a6 100%); color: #fff; border-radius: 22px; padding: var(--sp-6); margin-block-end: var(--sp-5); box-shadow: 0 14px 34px rgba(13, 148, 136, 0.3); }
.hero h2 { color: #fff; font-size: var(--fs-2xl); font-weight: 800; margin-block-end: var(--sp-1); }
.hero p { color: rgba(255, 255, 255, 0.9); margin: 0; }
.stats { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; margin-block-end: var(--sp-5); }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(3, 1fr); } }
.stat { display: flex; align-items: center; gap: var(--sp-4); }
.stat__icon { display: grid; place-items: center; flex: none; width: 52px; height: 52px; border-radius: 14px; background: var(--c-primary-soft); color: var(--c-primary); }
.stat__value { font-size: var(--fs-2xl); font-weight: 800; line-height: 1.2; }
.stat__label { color: var(--c-text-muted); font-size: var(--fs-sm); }
.section-title { font-size: var(--fs-lg); font-weight: 800; margin-block-end: var(--sp-3); }
.tiles { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile { display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-5); color: var(--c-text); text-decoration: none; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); transition: transform 0.2s var(--ease), box-shadow 0.2s, border-color 0.2s; }
.tile:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--c-primary); color: var(--c-text); }
.tile__icon { display: grid; place-items: center; flex-shrink: 0; width: 52px; height: 52px; border-radius: 14px; background: var(--c-primary-soft); color: var(--c-primary); }
.tile__title { display: block; font-weight: 800; font-size: var(--fs-lg); }
.tile__desc { display: block; color: var(--c-text-muted); font-size: var(--fs-sm); }

/* ===== تفاصيل العميل ===== */
.details { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.details > div { background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: var(--radius); padding: var(--sp-3) var(--sp-4); min-width: 0; }
.details dt { font-size: var(--fs-xs); color: var(--c-text-muted); font-weight: 700; margin-bottom: 2px; }
.details dd { font-weight: 800; overflow-wrap: anywhere; }
.details--meta > div { background: transparent; border-style: dashed; }
#detail .page-head { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); }
#detail { display: flex; flex-direction: column; gap: var(--sp-4); }

/* ===== السجل (History) ===== */
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-3); }
.event { padding: var(--sp-4) var(--sp-5); border-inline-start: 4px solid var(--c-primary); }
.event__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2); margin-block-end: var(--sp-2); }
.event__time { font-size: var(--fs-sm); color: var(--c-text-muted); font-weight: 600; }
.event__who { margin: 0; font-size: var(--fs-sm); color: var(--c-text-muted); }
.event__actor { font-weight: 800; color: var(--c-text); }
.event__desc { margin: 0; color: var(--c-text-soft); }
.event__client { margin: var(--sp-1) 0 0; font-weight: 800; color: var(--c-primary-hover); }
.event__client a { color: var(--c-primary-hover); text-decoration: none; }
.event__client a:hover { text-decoration: underline; }
.changes { list-style: none; margin: var(--sp-3) 0 0; padding: var(--sp-3); display: grid; gap: var(--sp-2); background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: var(--radius); }
.changes li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); }
.change__field { min-width: 7rem; color: var(--c-text-muted); font-weight: 700; }
.change__value { font-weight: 700; }
.change__before { color: var(--c-danger); text-decoration: line-through; text-decoration-color: rgba(185, 28, 28, 0.4); }
.change__after { color: var(--c-success); }

/* ===== استيراد / تصدير ===== */
.issues { list-style: none; margin: 0; padding: 2px; display: grid; gap: var(--sp-2); max-height: 320px; overflow-y: auto; direction: rtl; }
.issues li { padding: 10px 14px; font-size: var(--fs-sm); background: var(--c-warning-soft); color: var(--c-warning); border: 1px solid var(--c-warning-border); border-radius: var(--radius); }

/* ===== أرقام المركبات ===== */
.plates-field { display: grid; gap: var(--sp-2); }
.plates { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.plates-field .plates { justify-content: flex-start; }
.plates-add { display: flex; gap: var(--sp-2); }
.plates-add .input { flex: 1; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 12px; font-weight: 700; font-size: var(--fs-sm); color: var(--c-primary-hover); background: var(--c-primary-soft); border: 1px solid #b6e4de; border-radius: 999px; }
.chip__x { width: 22px; height: 22px; line-height: 20px; padding: 0; border: 0; border-radius: 50%; font-size: 1rem; color: var(--c-text-muted); background: transparent; cursor: pointer; }
.chip__x:hover { background: #fff; color: var(--c-danger); }
.plates > .chip.ltr { padding: 4px 12px; }
.plates-view { display: inline-block; text-align: center; }
.plates-view summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; font-weight: 700; font-size: var(--fs-xs); color: var(--c-primary-hover); background: var(--c-primary-soft); border: 1px solid #b6e4de; border-radius: 999px; padding: 2px 12px; }
.plates-view summary::-webkit-details-marker { display: none; }
.plates-view summary::after { content: ""; width: 14px; height: 14px; background: url("data:image/svg+xml,%3Csvg 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'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat; transition: transform 0.15s; }
.plates-view[open] summary::after { transform: rotate(180deg); }
.plates-view .plates { margin-top: 8px; }

/* ===== قائمة الاختيار والتقويم (widgets.js) ===== */
.wx { position: relative; width: 100%; }
.wx--auto { width: auto; min-width: 170px; }
.wx__native { position: absolute !important; inset-inline-start: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.wx__btn {
  display: flex; align-items: center; width: 100%; min-height: var(--touch); padding: 0 0.95rem 0 2.6rem;
  font: inherit; font-size: 16px; color: var(--c-text); text-align: start; cursor: pointer;
  background: #fff url("data:image/svg+xml,%3Csvg 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'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat left 0.85rem center / 16px;
  border: 1px solid var(--c-border-strong); border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.wx-date .wx__btn { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3.5' y='5' width='17' height='15.5' rx='2.5'/%3E%3Cpath d='M3.5 10h17M8 3v4M16 3v4'/%3E%3C/svg%3E"); background-size: 18px; }
.wx__btn:hover { border-color: var(--c-text-faint); }
.wx__btn:focus-visible, .wx.is-open .wx__btn { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 4px var(--c-primary-ring); }
.wx__btn:disabled { background-color: var(--c-bg); color: var(--c-text-muted); cursor: not-allowed; }
.wx__label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wx__label.is-placeholder { color: var(--c-text-muted); }
.wx__pop {
  position: absolute; inset-inline-start: 0; top: calc(100% + 6px); z-index: 80; min-width: 100%; max-width: calc(100vw - 24px);
  background: #fff; border: 1px solid var(--c-border); border-radius: 16px; box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18); padding: 6px;
}
.wx__pop.up { top: auto; bottom: calc(100% + 6px); }
.wx__list { list-style: none; margin: 0; max-height: 280px; overflow-y: auto; }
.wx__opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 10px; cursor: pointer; white-space: nowrap; font-size: var(--fs-sm); font-weight: 600; }
.wx__opt:hover, .wx__opt.is-active { background: var(--c-primary-soft); }
.wx__opt.is-selected { font-weight: 800; color: var(--c-primary-hover); }
.wx__opt.is-selected::after { content: ""; width: 16px; height: 16px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230d9488' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / contain no-repeat; }
.wx__opt.is-disabled { opacity: 0.45; cursor: not-allowed; }
.wx__cal { width: 296px; padding: 12px; }
.wx__cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.wx__nav { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; color: var(--c-text); cursor: pointer; }
.wx__nav:hover { background: var(--c-bg); }
.wx__nav svg { width: 18px; height: 18px; }
.wx__title { font: inherit; font-weight: 800; border: 0; background: transparent; padding: 6px 12px; border-radius: 10px; cursor: pointer; }
.wx__title:hover { background: var(--c-bg); }
.wx__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.wx__dow { font-size: 0.78rem; font-weight: 700; color: var(--c-text-muted); padding: 6px 0; }
.wx__day, .wx__year { font: inherit; font-size: 0.92rem; height: 38px; border: 0; border-radius: 50%; background: transparent; color: var(--c-text); cursor: pointer; }
.wx__day:hover, .wx__year:hover { background: var(--c-primary-soft); }
.wx__day.is-today { box-shadow: inset 0 0 0 1.5px var(--c-primary); }
.wx__day.is-selected, .wx__year.is-selected { background: var(--c-primary); color: #fff; font-weight: 800; box-shadow: none; }
.wx__years { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.wx__year { border-radius: 12px; }
.wx__foot { display: flex; justify-content: space-between; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--c-border); }
.wx__link { font: inherit; font-weight: 700; color: var(--c-primary); background: transparent; border: 0; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.wx__link:hover { background: var(--c-primary-soft); }
.wx__link--muted { color: var(--c-text-muted); }

/* ===== موبايل ===== */
@media (min-width: 640px) { .form__actions .btn { flex: 0 0 auto; } }
@media (max-width: 899px) {
  .hero { padding: var(--sp-5); border-radius: 18px; }
  .hero h2 { font-size: var(--fs-xl); }
  .card { padding: var(--sp-4); }
  .table-toolbar { padding: var(--sp-3); }
  .table-toolbar .row { width: 100%; }
  .search { max-width: none; }
  .select--auto, .input--auto, .wx--auto { flex: 1 1 140px; }
  .event { padding: var(--sp-4); }
}

/* ===== أزرار الإجراءات في صفوف الجدول (تعديل / حذف / استرجاع) ===== */
.table th.col-actions, .table td.col-actions { width: 1%; white-space: nowrap; }
.row-actions { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0;
  color: var(--c-text-muted); background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 12px; box-shadow: var(--shadow-sm); cursor: pointer; line-height: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.icon-btn .icon svg { width: 19px; height: 19px; }
.icon-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.icon-btn:active { transform: translateY(0); box-shadow: none; }
.icon-btn:focus-visible { outline: 3px solid var(--c-primary-ring); outline-offset: 2px; }
.icon-btn--edit { color: var(--c-primary); background: var(--c-primary-soft); border-color: var(--c-primary-ring); }
.icon-btn--delete, .icon-btn--purge { color: var(--c-danger); background: var(--c-danger-soft); border-color: var(--c-danger-border); }
.icon-btn--restore { color: var(--c-success); background: var(--c-success-soft); border-color: var(--c-success-border); }
.icon-btn--edit:hover { color: #fff; background: var(--c-primary); border-color: var(--c-primary); }
.icon-btn--delete:hover, .icon-btn--purge:hover { color: #fff; background: var(--c-danger); border-color: var(--c-danger); }
.icon-btn--restore:hover { color: #fff; background: var(--c-success); border-color: var(--c-success); }
@media (max-width: 719px) {
  .table td.col-actions { justify-content: flex-end; }
  .table td.col-actions::before { margin-inline-end: auto; }
  .icon-btn { width: 42px; height: 42px; }
}