/*
 * الألوان: القيم هنا هي ألوان العلامة الافتراضية،
 * وتُستبدل عند التحميل من config.json → theme (انظر THEME_VARS في js/cart.js).
 */
:root {
  --bg: #fdf8e5;
  --surface: #ffffff;
  --ink: #2b1d17;
  --muted: #7d6b5d;
  --line: #ebe1cb;
  --brand: #6d191b;
  --brand-hover: #521214;
  --brand-soft: #f6e9e4;
  --accent: #b19154;
  --accent-soft: #f5edda;
  --success: #1f8a4c;
  --danger: #b42318;
  --stock-lot: #16a34a;
  --stock-middle: #eab308;
  --stock-little: #dc2626;
  --stock-nothing: #9ca3af;
  --pattern: #6d191b;

  /* درجات مشتقة تلقائياً من الألوان أعلاه */
  --surface-alt: color-mix(in srgb, var(--bg) 45%, var(--surface));
  --line-soft: color-mix(in srgb, var(--line) 55%, var(--surface));
  --row-hover: color-mix(in srgb, var(--brand-soft) 45%, var(--surface));
  --ink-soft: color-mix(in srgb, var(--ink) 85%, var(--surface));
  --brand-soft-strong: color-mix(in srgb, var(--brand) 16%, var(--surface));
  --accent-strong: color-mix(in srgb, var(--accent) 72%, black);
  --success-strong: color-mix(in srgb, var(--success) 82%, black);
  --success-soft: color-mix(in srgb, var(--success) 14%, var(--surface));
  --danger-strong: color-mix(in srgb, var(--danger) 85%, black);
  --danger-soft: color-mix(in srgb, var(--danger) 7%, var(--surface));
  --danger-border: color-mix(in srgb, var(--danger) 35%, var(--surface));

  --radius: 16px;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

/* أثناء تطبيق ألوان config */
.no-transition *, .no-transition *::before, .no-transition *::after { transition: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }

.page-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 36px 22px 64px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.currency-switch {
  display: flex;
  align-items: center;
}

.currency-select {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

h1 { margin: 0; font-size: clamp(1.5rem, 3vw, 2.1rem); }

.page-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.view-switch {
  display: flex;
  gap: 6px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.view-btn {
  white-space: nowrap;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 20px;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.view-btn:hover { color: var(--brand); }

.view-btn.is-active {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--brand) 25%, transparent);
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 12px;
  padding: 18px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filter-field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.control {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.control::placeholder { color: var(--muted); }

.control:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent);
}

.btn-reset {
  height: 42px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.btn-reset:hover {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--brand-soft);
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 2px 14px;
}

.count { color: var(--muted); font-size: 0.9rem; }
.count strong { color: var(--ink); }

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.product-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.product-table th {
  padding: 14px 16px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
  white-space: nowrap;
}

.product-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 0.9rem;
  vertical-align: middle;
}

.product-table tbody tr:last-child td { border-bottom: 0; }
.product-table tbody tr:hover { background: var(--row-hover); }

.cell-name { display: block; font-weight: 700; }

.cell-category {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.75rem;
}

.code-chip {
  padding: 5px 10px;
  border: 0;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.2s;
}

.code-chip:hover { background: var(--brand-soft-strong); }

.brand-tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
}

.price { font-weight: 800; white-space: nowrap; }

.thumb,
.thumb-fallback {
  width: 72px;
  height: 60px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand-soft), var(--accent-soft));
  color: var(--brand);
  font-weight: 800;
  object-fit: contain;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb { background: var(--surface); }

.product-table tbody tr.is-clickable { cursor: pointer; }

/* ---------- دائرة التوفر */
.stock {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.stock-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9);
}

.stock.is-lot .stock-dot { background: var(--stock-lot); }
.stock.is-middle .stock-dot { background: var(--stock-middle); }
.stock.is-little .stock-dot { background: var(--stock-little); }
.stock.is-nothing .stock-dot { background: var(--stock-nothing); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- الكروت: نفس الحجم تقريباً */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

.product-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.card-media {
  position: relative;
  height: 260px;
  flex: none;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.card-media > .stock {
  position: absolute;
  top: 12px;
  inset-inline-start: 12px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
}

.card-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 16px;
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.card-title {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.5;
  min-height: 3em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-category {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-specs {
  margin-top: 10px;
  min-height: 4.4em;
}

.card-spec {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-spec.is-empty { color: var(--muted); }

.more-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.more-link:hover { text-decoration: underline; }

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.card-price {
  color: var(--brand);
  font-size: 1.2rem;
  font-weight: 800;
}

.card-packing {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

/* ---------- عارض الصور */
.slider {
  position: relative;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: pan-y;
  user-select: none;
}

.slides { width: 100%; height: 100%; }

.slides .slide,
.slides > .thumb-fallback {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 10px;
}

.slides .slide { display: none; }
.slides .slide.is-active { display: block; }

.slides .thumb-fallback,
.slides .slide.thumb-fallback.is-active {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  font-size: 2.5rem;
  background: linear-gradient(135deg, var(--brand-soft), var(--accent-soft));
  color: var(--brand);
  font-weight: 800;
}

.slider-dots {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.35);
}

.dot {
  width: 9px;
  height: 9px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.dot.is-active { background: var(--surface); transform: scale(1.25); }

.slider-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

.slider-arrow.is-prev { right: 10px; }
.slider-arrow.is-next { left: 10px; }
.slider:hover .slider-arrow,
.slider:focus-within .slider-arrow { opacity: 1; }

/* الهاتف: لا أسهم، التنقل بالسحب أو النقاط */
@media (hover: none) {
  .slider-arrow { display: none; }
  .dot { width: 11px; height: 11px; }
}

/* ---------- تحميل المزيد */
.load-more {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 18px;
}

.sentinel { width: 100%; height: 1px; }

.btn-more {
  height: 42px;
  padding: 0 32px;
  border: 1px solid var(--brand);
  border-radius: 999px;
  background: var(--surface);
  color: var(--brand);
  font-weight: 700;
  cursor: pointer;
}

.btn-more:hover { background: var(--brand-soft); }
.btn-more:disabled { opacity: 0.6; cursor: default; }

/* ---------- النافذة المنبثقة */
body.modal-open { overflow: hidden; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.55);
}

.modal {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  width: min(980px, 100%);
  max-height: calc(100vh - 40px);
  overflow: hidden;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.modal-media {
  height: min(560px, calc(100vh - 40px));
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.modal-body h2 { margin: 0; font-size: 1.35rem; }

/* مساحة لزر الإغلاق (يسار في RTL) */
.modal-body .card-top { padding-inline-end: 44px; }

.modal-facts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin: 16px 0;
  padding: 12px 0;
  border-block: 1px solid var(--line-soft);
}

.modal-close {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(17, 24, 39, 0.75);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.specs-title {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.specs {
  margin: 0;
  padding-inline-start: 18px;
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.9;
}

@media (max-width: 760px) {
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    grid-template-columns: 1fr;
    max-height: 92vh;
    overflow-y: auto;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .modal-media { height: 320px; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .modal-body { overflow: visible; }
}

.state-panel {
  padding: 42px 20px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  line-height: 1.9;
}

.state-panel.is-error {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger-strong);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 10;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 0.85rem;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.is-visible { opacity: 1; transform: none; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent);
  outline-offset: 2px;
}

@media (max-width: 900px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .btn-reset { grid-column: 1 / -1; }
}

@media (max-width: 600px) {
  .page-shell { padding: 24px 14px 48px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .view-switch { width: 100%; }
  .view-btn { flex: 1; }
  .filters { grid-template-columns: 1fr; }
}

/* ================================================================== الطلب والسلة */
.cart-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  margin-inline-start: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
}

.cart-badge[hidden] { display: none; }

.order-input {
  display: grid;
  grid-template-columns: auto minmax(110px, 1fr);
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  cursor: default;
}

.unit-toggle {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-alt);
}

.unit-option { position: relative; cursor: pointer; }

.unit-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.unit-option span {
  display: block;
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  transition: background 0.15s, color 0.15s;
}

.unit-option input:checked + span {
  background: var(--brand);
  color: #fff;
}

.unit-option input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); }
.unit-option input:disabled + span { cursor: default; opacity: 0.6; }

.qty-input {
  width: 100%;
  height: 38px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 700;
  text-align: center;
}

.qty-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent); }
.qty-input.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 15%, transparent); }
.qty-input:disabled { background: var(--surface-alt); color: var(--muted); }

.btn-add {
  grid-column: 1 / -1;
  height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.btn-add:hover { background: var(--brand-hover); }

.order-input.is-in-cart .btn-add,
.btn-add:disabled {
  background: var(--success-soft);
  color: var(--success-strong);
  cursor: default;
}

/* ---------- شاشة السلة */
.cart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.cart-head h2 { margin: 0; }
.cart-head .count { margin: 4px 0 0; }

.view-switch.is-small .view-btn { padding: 6px 14px; }

.cart-table .unit-toggle { white-space: nowrap; }
.cart-table .qty-stepper { width: 124px; }

.btn-remove {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--danger-border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--danger-strong);
  font-weight: 700;
  cursor: pointer;
}

.btn-remove:hover { background: var(--danger-soft); }

.cart-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.cart-card {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.cart-card-media .thumb,
.cart-card-media .thumb-fallback { width: 110px; height: 110px; }

.cart-card .card-title { min-height: 0; font-size: 0.95rem; }

.cart-card-order {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.cart-card-order .qty-stepper { width: 124px; }

.cart-notes {
  margin-top: 18px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.cart-notes label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.cart-notes textarea.control {
  height: auto;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.7;
}

.cart-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}

.btn-send {
  height: 46px;
  padding: 0 26px;
  border: 0;
  border-radius: 12px;
  background: var(--success);
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
}

.btn-send:hover { background: var(--success-strong); }
.btn-send:disabled { opacity: 0.6; cursor: default; }

.btn-danger-outline {
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--danger-border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--danger-strong);
  font-weight: 700;
  cursor: pointer;
}

.btn-danger-outline:hover { background: var(--danger-soft); }

/* ---------- تحذير تفريغ السلة */
.confirm {
  width: min(440px, 100%);
  padding: 26px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.confirm-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 2rem;
  font-weight: 900;
  line-height: 56px;
}

.confirm h2 { margin: 0 0 8px; color: var(--danger-strong); }
.confirm p { margin: 0 0 20px; color: var(--ink-soft); line-height: 1.8; }

.confirm-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.btn-danger {
  height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  background: var(--danger);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.btn-danger:hover { background: var(--danger-strong); }

@media (max-width: 600px) {
  .cart-head { flex-direction: column; align-items: stretch; }
  .cart-actions { flex-direction: column-reverse; align-items: stretch; }
  .cart-card { grid-template-columns: 84px 1fr; }
  .cart-card-media .thumb,
  .cart-card-media .thumb-fallback { width: 84px; height: 84px; }
}

.qty-stepper {
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}

.qty-stepper:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent); }

.qty-stepper .qty-input {
  height: 100%;
  min-width: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  font-variant-numeric: tabular-nums;
}

.qty-stepper .qty-input:focus { box-shadow: none; }

.qty-step {
  border: 0;
  background: var(--surface-alt);
  color: var(--brand);
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
}

.qty-step:hover { background: var(--brand-soft); }
.qty-step:disabled { color: var(--muted); cursor: default; background: var(--surface-alt); }

.qty-stepper:has(.qty-input.is-invalid) { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 15%, transparent); }

/* ================================================================== تخطيط السلة */
.cart-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.cart-main { min-width: 0; }

.cart-side {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.cart-side h2 { margin: 0; font-size: 1.05rem; }

.cart-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
}

.cart-summary div {
  padding: 10px 6px;
  border-radius: 12px;
  background: var(--surface-alt);
  text-align: center;
}

.cart-summary dt { color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.cart-summary dd { margin: 4px 0 0; font-size: 1.25rem; font-weight: 800; }

.cart-side .cart-notes { margin: 0; padding: 0; border: 0; background: none; }
.cart-side .btn-send,
.cart-side .btn-danger-outline { width: 100%; }

.invoice-actions { display: none; gap: 8px; }
.invoice-actions .btn-secondary { flex: 1; }

/* أزرار الفاتورة تظهر على الكمبيوتر فقط (مؤشر دقيق + hover) */
@media (hover: hover) and (pointer: fine) {
  .invoice-actions.desktop-only { display: flex; }
}

.btn-secondary {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--brand);
  border-radius: 10px;
  background: var(--surface);
  color: var(--brand);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.btn-secondary:hover { background: var(--brand-soft); }
.btn-secondary:disabled { opacity: 0.6; cursor: default; }

/* ---------- جدول السلة: أعمدة ثابتة والمساحة الزائدة لاسم المنتج */
.cart-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.cart-table col.c-index { width: 44px; }
.cart-table col.c-image { width: 88px; }
.cart-table col.c-unit { width: 150px; }
.cart-table col.c-qty { width: 140px; }
.cart-table col.c-remove { width: 92px; }

.cart-table th {
  padding: 12px 10px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
}

.cart-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.cart-table tbody tr:last-child td { border-bottom: 0; }
.cart-table .t-index { color: var(--muted); font-weight: 700; text-align: center; }
.cart-table th:first-child { text-align: center; }
.cart-table .thumb,
.cart-table .thumb-fallback { width: 64px; height: 64px; }
.cart-table .cell-name { overflow-wrap: anywhere; }

.cart-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 6px;
}

.cart-meta .cell-category { margin: 0; }
.cart-table .qty-stepper { width: 100%; }
.cart-table .unit-toggle { display: flex; width: fit-content; }

.cart-main .cart-cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

@media (max-width: 1000px) {
  .cart-layout { grid-template-columns: 1fr; }
  .cart-side { position: static; }
}

/* الشاشات الضيقة: كل صف يصبح بطاقة مدمجة بدون تمرير أفقي */
@media (max-width: 720px) {
  .cart-table, .cart-table tbody, .cart-table tr, .cart-table td { display: block; }
  .cart-table thead, .cart-table colgroup { display: none; }
  .cart-table tr {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr) auto;
    gap: 10px 12px;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--line-soft);
  }
  .cart-table td { padding: 0; border: 0; }
  .cart-table .t-index { display: none; }
  .cart-table .t-image { grid-column: 1; grid-row: 1 / 3; }
  .cart-table .t-name { grid-column: 2; grid-row: 1; }
  .cart-table .t-remove { grid-column: 3; grid-row: 1; align-self: start; }
  .cart-table .t-unit { grid-column: 2; grid-row: 2; }
  .cart-table .t-qty { grid-column: 3; grid-row: 2; width: 124px; }
}

/* ================================================================== الهوية: الشعار والنقوش */
.brand-pattern {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: var(--pattern);
  opacity: 0.06;
  -webkit-mask-image: url("../assets/pattern.png");
  mask-image: url("../assets/pattern.png");
  -webkit-mask-size: 600px auto;
  mask-size: 600px auto;
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
}

.page-shell { position: relative; z-index: 1; }

.brand-head {
  display: flex;
  align-items: center;
  gap: 20px;
  min-width: 0;
}

.brand-logo {
  flex: none;
  display: block;
  padding-inline-end: 20px;
  border-inline-end: 1px solid var(--line);
  line-height: 0;
}

.brand-logo img {
  width: auto;
  height: 88px;
}

.brand-text { min-width: 0; }

@media (max-width: 600px) {
  .brand-head { flex-direction: column; align-items: flex-start; gap: 12px; }
  .brand-logo { padding: 0 0 12px; border: 0; border-bottom: 1px solid var(--line); }
  .brand-logo img { height: 64px; }
  .brand-pattern { -webkit-mask-size: 420px auto; mask-size: 420px auto; }
}

@media print {
  .brand-pattern { display: none; }
}
