/* ====================================================================
   Hayat Store Order Manager — styles
   تصميم mobile-first، RTL، بألوان دافئة مستوحاة من هوية المتجر.
   ==================================================================== */

:root {
  /* لوحة الألوان */
  --bg:           #fdfcfa;   /* خلفية كريمية دافئة */
  --surface:      #ffffff;
  --surface-alt:  #f7f6f3;
  --border:       #e7e5e4;
  --border-strong:#d6d3d1;
  --text:         #1f1d18;
  --text-muted:   #78716c;
  --text-faint:   #a8a29e;

  --primary:      #3f5e3a;   /* زيتوني */
  --primary-dark: #2d4329;
  --primary-soft: #eaf0e8;

  --ok:           #10b981;
  --warn:         #f59e0b;
  --error:        #dc2626;
  --ok-soft:      #d1fae5;
  --warn-soft:    #fef3c7;
  --error-soft:   #fee2e2;

  --shadow-sm:    0 1px 2px rgba(28, 25, 23, 0.05);
  --shadow-md:    0 4px 12px rgba(28, 25, 23, 0.08);
  --shadow-lg:    0 12px 28px rgba(28, 25, 23, 0.14);

  --radius-sm:    6px;
  --radius:       10px;
  --radius-lg:    16px;

  --header-h:     56px;
  --max-w:        1180px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Tajawal', -apple-system, system-ui, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

body {
  direction: rtl;
  min-height: 100dvh;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ====================================================================
   شريط علوي
   ==================================================================== */

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.appbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
}

.appbar__brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
}

.appbar__spacer { flex: 1; }

.appbar__action {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.appbar__action:hover { background: var(--surface-alt); color: var(--text); }

/* ====================================================================
   التخطيط الرئيسي
   ==================================================================== */

.page {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 96px; /* مساحة للـ FAB */
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  align-items: stretch;
}

.search {
  flex: 1 1 220px;
  position: relative;
}
.search input {
  width: 100%;
  padding: 10px 38px 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}
.search input:focus { border-color: var(--primary); }
.search::before {
  content: "🔍";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  opacity: 0.5;
  pointer-events: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-alt); }
.btn:active { transform: scale(0.98); }
.btn--primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn--primary:hover { background: var(--primary-dark); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--danger {
  background: white;
  color: var(--error);
  border-color: var(--error-soft);
}
.btn--danger:hover { background: var(--error-soft); }

/* ====================================================================
   بطاقات الطلبات (الجوال) و الجدول (الديسكتوب)
   ==================================================================== */

.orders-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.order-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 14px 18px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.order-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.order-card::after {
  /* الشريط الجانبي للتحقق — الميزة المميّزة */
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 4px;
  background: var(--text-faint);
}
.order-card[data-recon="ok"]::after    { background: var(--ok); }
.order-card[data-recon="warn"]::after  { background: var(--warn); }
.order-card[data-recon="error"]::after { background: var(--error); }

.order-card__top {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.order-card__top .invoice-btn {
  flex-shrink: 0;
}
.order-card__date {
  color: var(--text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.order-card__number {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
}
.order-card__status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  color: white;
  font-size: 11px;
  font-weight: 600;
  margin-inline-start: auto;
}

.order-card__customers {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.4;
}
.order-card__customers .muted {
  color: var(--text-faint);
}

.order-card__totals {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.order-card__totals strong {
  color: var(--text);
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}
.empty-state h2 { color: var(--text); margin: 0 0 8px; font-weight: 600; }
.empty-state p { margin: 0; }

/* ====================================================================
   الزر العائم (FAB)
   ==================================================================== */

.fab {
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  box-shadow: var(--shadow-lg);
  font-size: 28px;
  line-height: 1;
  display: grid;
  place-items: center;
  z-index: 15;
  transition: transform 0.1s;
}
.fab:hover  { background: var(--primary-dark); }
.fab:active { transform: scale(0.94); }

/* ====================================================================
   النوافذ المنبثقة (Modals)
   ==================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px);
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
}
.modal-backdrop.open .modal { transform: translateY(0); }

.modal__header {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.modal__title {
  font-size: 16px;
  font-weight: 700;
  flex: 1;
}
.modal__close {
  background: transparent;
  border: none;
  font-size: 24px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-muted);
}
.modal__close:hover { background: var(--surface-alt); color: var(--text); }

.modal__body {
  padding: 16px;
  flex: 1;
}

.modal__footer {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ====================================================================
   النماذج
   ==================================================================== */

.fieldset {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.fieldset__legend {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 10px;
  letter-spacing: 0.02em;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.field__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
  font-variant-numeric: tabular-nums;
}
.field input:focus,
.field select:focus,
.field textarea:focus { border-color: var(--primary); }

.field textarea { resize: vertical; min-height: 60px; }

.field--row {
  display: flex;
  flex-direction: row;
  align-items: end;
  gap: 6px;
}
.field--row > * { flex: 1; }
.field--row .btn { flex: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (max-width: 520px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.password-wrap { position: relative; }
.password-wrap input { padding-inline-start: 38px; }
.password-wrap__toggle {
  position: absolute;
  inset-inline-start: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  font-size: 16px;
  padding: 6px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}
.password-wrap__toggle:hover { background: var(--surface-alt); }

.hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* ====================================================================
   جدول الزبائن داخل النموذج
   ==================================================================== */

.customers {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.customer-row {
  display: grid;
  grid-template-columns: 1.6fr 0.6fr 0.9fr 0.9fr 1fr 1fr 1fr auto;
  gap: 6px;
  align-items: center;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.customer-row input {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-alt);
  text-align: end;
  font-variant-numeric: tabular-nums;
}
.customer-row input[name="name"] { text-align: start; }
.customer-row input:focus { border-color: var(--primary); background: var(--surface); }
.customer-row .computed {
  padding: 7px 8px;
  background: var(--primary-soft);
  border-radius: 4px;
  text-align: end;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--primary-dark);
}
.customer-row__remove {
  background: transparent;
  border: none;
  color: var(--error);
  font-size: 18px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
}
.customer-row__remove:hover { background: var(--error-soft); }

.customer-row__labels {
  display: grid;
  grid-template-columns: 1.6fr 0.6fr 0.9fr 0.9fr 1fr 1fr 1fr auto;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 8px;
}
.customer-row__labels span { text-align: center; }
.customer-row__labels span:first-child { text-align: start; }

/* جوال: نُحوّل الصفّ إلى بطاقة */
@media (max-width: 720px) {
  .customer-row__labels { display: none; }
  .customer-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px;
  }
  .customer-row > div.field-cell {
    display: flex;
    flex-direction: column;
    gap: 3px;
  }
  .customer-row .field-cell::before {
    content: attr(data-label);
    font-size: 10px;
    color: var(--text-muted);
    text-transform: none;
  }
  .customer-row .field-cell--full { grid-column: 1 / -1; }
  .customer-row__remove {
    position: absolute;
    inset-inline-end: 8px;
    top: 8px;
  }
  .customer-row { position: relative; }
}

/* ====================================================================
   شريط التحقق (داخل المودال)
   ==================================================================== */

.recon-banner {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  text-align: center;
  line-height: 1.5;
}
.recon-banner[data-state="ok"]    { background: var(--ok-soft);    color: #065f46; }
.recon-banner[data-state="warn"]  { background: var(--warn-soft);  color: #92400e; }
.recon-banner[data-state="error"] { background: var(--error-soft); color: #991b1b; }

.totals-summary {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}
.totals-summary strong { color: var(--text); font-weight: 600; }

/* ====================================================================
   شريط الحالة السفلي
   ==================================================================== */

.statusbar {
  position: fixed;
  bottom: 0; right: 0; left: 0;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  z-index: 10;
  font-variant-numeric: tabular-nums;
}
.page { padding-bottom: 100px; }

/* ====================================================================
   صفحة تسجيل الدخول
   ==================================================================== */

.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-md);
}
.login-card__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.login-card__mark {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--primary);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 24px;
}
.login-card__title { font-size: 18px; font-weight: 700; }
.login-card__sub { font-size: 13px; color: var(--text-muted); }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form__error {
  background: var(--error-soft);
  color: #991b1b;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
}
.login-form__error.show { display: block; }

/* ====================================================================
   إشعارات toast
   ==================================================================== */

.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  max-width: 90vw;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast--ok    { background: #065f46; }
.toast--error { background: #991b1b; }

/* ====================================================================
   جدول الأرصدة المتبقية
   ==================================================================== */

.balances-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.balances-table th,
.balances-table td {
  padding: 10px 8px;
  text-align: end;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.balances-table th {
  background: var(--surface-alt);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-align: end;
}
.balances-table th:first-child,
.balances-table td:first-child {
  text-align: start;
  font-weight: 500;
}
.balances-table tr:last-child td { border-bottom: none; }

/* ====================================================================
   شاشات أكبر
   ==================================================================== */

@media (min-width: 720px) {
  .toolbar { flex-wrap: nowrap; }
  .fab { width: 60px; height: 60px; }
}


/* ====================================================================
   زر الفاتورة
   ==================================================================== */

.btn--small {
  padding: 5px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  gap: 4px;
}
.invoice-btn {
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
  margin-inline-start: 8px;
  margin-inline-end: 8px;
  font-size: 13px;
  white-space: nowrap;
}
.invoice-btn:hover {
  background: var(--primary);
  color: white;
}

@media (max-width: 520px) {
  .order-card__top {
    flex-wrap: wrap;
    gap: 4px;
  }
  .order-card__number {
    font-size: 13px;
  }
  .invoice-btn {
    margin-inline-start: 0;
    margin-top: 2px;
    font-size: 11px;
    padding: 3px 8px;
    order: 2;
  }
  .order-card__status {
    margin-inline-start: auto;
    order: 3;
    font-size: 10px;
    padding: 2px 8px;
  }
}

/* ====================================================================
   سلات شي إن (Carts)
   ==================================================================== */

.carts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: box-shadow 0.2s, border-color 0.15s;
}
.cart-card:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--border-strong);
}

.cart-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.cart-card__info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.cart-card__info strong {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cart-card__date {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.cart-card__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.cart-card__count {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 3px 10px;
  border-radius: 20px;
}

.cart-card__amount {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.cart-card__url {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-all;
}
.cart-card__url a {
  color: var(--text-muted);
  text-decoration: none;
}
.cart-card__url a:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* ---- منتجات السلة ---- */

.cart-products {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.cart-product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s;
}
.cart-product-card:hover {
  box-shadow: var(--shadow-sm);
}

.cart-product-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
}

.cart-product-card__noimg {
  width: 100%;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-alt);
  font-size: 32px;
  color: var(--text-muted);
}

.cart-product-card__info {
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cart-product-card__name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cart-product-card__meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.cart-product-card__link {
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  margin-top: 4px;
}
.cart-product-card__link:hover {
  text-decoration: underline;
}

.tag {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--surface-alt);
  color: var(--text-muted);
}
.tag--price {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* ---- مودال عريض للسلات ---- */

.modal--wide {
  max-width: 900px;
  width: 96%;
}

/* ---- استيراد من سلة (داخل نموذج الطلب) ---- */

.cart-import-section {
  background: var(--primary-soft);
  border: 1px dashed var(--primary);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.cart-import-section__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-dark);
  margin-bottom: 10px;
}
.cart-import-select {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.cart-import-select select {
  flex: 1;
  min-width: 200px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
}
.cart-import-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}
.cart-import-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.cart-import-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}
.cart-import-item__name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cart-import-item__price {
  font-weight: 600;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
