@import url("/assets/fonts.css");

/* ═══ الأساس ═══════════════════════════════════════════════════════ */

:root {
  --bg:        #f4f5f9;
  --surface:   #ffffff;
  --ink:       #23233a;
  --muted:     #74748c;
  --faint:     #9a9ab0;
  --line:      #e4e5ef;
  --line-soft: #eff0f6;

  --brand:      #5b74d6;
  --brand-dark: #4a61bd;
  --brand-soft: #eef1fc;

  --ok:        #1a7f52;
  --ok-bg:     #e7f6ee;
  --warn:      #9a6a00;
  --warn-bg:   #fdf3e0;
  --danger:    #b3261e;
  --danger-bg: #fdecea;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(35, 35, 58, .04), 0 8px 24px rgba(35, 35, 58, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Tajawal", system-ui, "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 700; line-height: 1.4; }

/* ═══ الهيكل ═══════════════════════════════════════════════════════ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 56px;
  padding: 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar .brand { font-weight: 700; font-size: 1.0625rem; }
.topbar .brand span { color: var(--brand); }

.topbar .session { display: flex; align-items: center; gap: .75rem; font-size: .9375rem; }
.topbar .session .who { color: var(--muted); }
.topbar form { margin: 0; }

.shell { display: flex; align-items: flex-start; min-height: calc(100vh - 56px); }

.sidebar {
  position: sticky;
  top: 56px;
  flex: 0 0 220px;
  align-self: stretch;
  padding: 1.25rem .875rem;
  background: var(--surface);
  /* الفاصل بين القائمة والمحتوى — في RTL هذه هي الحافة اليسرى */
  border-inline-end: 1px solid var(--line);
  min-height: calc(100vh - 56px);
}

.sidebar .label {
  padding: 0 .625rem;
  margin-bottom: .5rem;
  color: var(--faint);
  font-size: .75rem;
  font-weight: 500;
  letter-spacing: .02em;
}

.sidebar nav { display: flex; flex-direction: column; gap: .125rem; }

.sidebar nav a {
  padding: .5rem .625rem;
  border-radius: 8px;
  color: var(--ink);
  font-size: .9375rem;
  font-weight: 500;
}

.sidebar nav a:hover { background: var(--line-soft); text-decoration: none; }
.sidebar nav a.on { background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; }

main { flex: 1; min-width: 0; padding: 1.75rem 1.5rem 3rem; }
.wrap { max-width: 64rem; margin: 0 auto; }

/* ═══ رأس الصفحة ═══════════════════════════════════════════════════ */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.page-head h1 { font-size: 1.375rem; }
.page-head .sub { margin: .125rem 0 0; color: var(--muted); font-size: .875rem; }

.tabs {
  display: flex;
  gap: .25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}

.tabs a {
  padding: .5rem .875rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--muted);
  font-size: .9375rem;
  font-weight: 500;
}

.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--brand-dark); border-bottom-color: var(--brand); font-weight: 700; }

/* ═══ البطاقات ═════════════════════════════════════════════════════ */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 1.25rem; }
.card > .card-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--line-soft); }
.card > .card-head h2 { font-size: 1rem; }
.card > .card-head p { margin: .125rem 0 0; color: var(--muted); font-size: .8125rem; }
.card > .card-body { padding: 1.25rem; }
.card > .card-foot {
  padding: .875rem 1.25rem;
  border-top: 1px solid var(--line-soft);
  background: #fafbfd;
  border-radius: 0 0 var(--radius) var(--radius);
  display: flex;
  gap: .625rem;
  align-items: center;
}

/* ═══ الجداول ══════════════════════════════════════════════════════ */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: .9375rem; }

th, td { padding: .75rem 1rem; text-align: right; vertical-align: middle; }

thead th {
  color: var(--muted);
  font-size: .8125rem;
  font-weight: 500;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody tr + tr td { border-top: 1px solid var(--line-soft); }
tbody tr:hover { background: #fafbfd; }

td.num { font-variant-numeric: tabular-nums; }
td .host { direction: ltr; display: inline-block; unicode-bidi: isolate; }

.empty { padding: 3rem 1.25rem; text-align: center; color: var(--muted); }
.empty p { margin: 0 0 1rem; }

/* ═══ الشارات ══════════════════════════════════════════════════════ */

.badge {
  display: inline-block;
  padding: .0625rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge.active { background: var(--ok-bg);     color: var(--ok); }
.badge.paused { background: var(--warn-bg);   color: var(--warn); }
.badge.closed { background: var(--danger-bg); color: var(--danger); }
.badge.soft   { background: var(--line-soft); color: var(--muted); }
.badge.brand  { background: var(--brand-soft); color: var(--brand-dark); }

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

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.25rem; }
.grid .full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; }
.field label { margin-bottom: .375rem; font-size: .875rem; font-weight: 500; }
.field .hint { margin: .375rem 0 0; color: var(--faint); font-size: .8125rem; }

input[type=text], input[type=password], input[type=number], input[type=file], select {
  width: 100%;
  padding: .5625rem .75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfd;
  color: inherit;
  font: inherit;
  font-size: .9375rem;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(91, 116, 214, .15);
  background: #fff;
}

input[dir=ltr] { text-align: left; }

input[type=color] {
  width: 3rem;
  height: 2.375rem;
  padding: .1875rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.color-row { display: flex; align-items: center; gap: .625rem; }
.color-row input[type=text] { flex: 1; direction: ltr; text-align: left; }

.check { display: flex; align-items: center; gap: .5rem; }
.check input[type=checkbox] { width: 1.0625rem; height: 1.0625rem; accent-color: var(--brand); cursor: pointer; }

.preview {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .5rem;
  padding: .5rem .75rem;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfbfd;
}

.preview img { max-height: 2.5rem; max-width: 8rem; object-fit: contain; }
.preview .none { color: var(--faint); font-size: .875rem; }

/* ═══ الأزرار ══════════════════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  padding: .5rem 1rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-size: .9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}

.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn:active { transform: translateY(1px); }

.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: var(--line-soft); color: var(--ink); }

.btn.danger { background: transparent; border-color: transparent; color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); }

.btn.small { padding: .3125rem .625rem; font-size: .8125rem; }

.row-actions { display: flex; gap: .25rem; justify-content: flex-start; }
.row-actions form { margin: 0; }

/* ═══ التنبيهات ════════════════════════════════════════════════════ */

.alert {
  margin: 0 0 1rem;
  padding: .625rem .875rem;
  border-radius: 8px;
  font-size: .9375rem;
}

.alert.success { background: var(--ok-bg);     color: var(--ok); }
.alert.error   { background: var(--danger-bg); color: var(--danger); }

.alert ul { margin: .25rem 0 0; padding-inline-start: 1.25rem; }

/* ═══ صفحة الدخول ══════════════════════════════════════════════════ */

.center { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }

.auth-card {
  width: 100%;
  max-width: 23rem;
  padding: 2rem 1.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.auth-card h1 { margin-bottom: .25rem; font-size: 1.25rem; }
.auth-card .sub { margin: 0 0 1.5rem; color: var(--muted); font-size: .875rem; }
.auth-card label { display: block; margin-bottom: .375rem; font-size: .875rem; font-weight: 500; }
.auth-card input { margin-bottom: 1rem; }
.auth-card .btn { width: 100%; }

/* ═══ المنتجات ═════════════════════════════════════════════════════ */

.tabs.sub { margin-top: -.5rem; border-bottom: 0; }
.tabs.sub a { font-size: .875rem; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  margin-bottom: 1.25rem;
}

.filters input[type=text] { flex: 1 1 14rem; min-width: 10rem; }
.filters select { flex: 0 1 11rem; }

.thumb {
  display: block;
  width: 3rem;
  height: 3rem;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--line-soft);
}

.thumb.none {
  display: grid;
  place-items: center;
  color: var(--faint);
  font-size: .875rem;
}

.muted-line { color: var(--muted); font-size: .8125rem; }
.strike { text-decoration: line-through; }

textarea {
  width: 100%;
  padding: .5625rem .75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfd;
  color: inherit;
  font: inherit;
  font-size: .9375rem;
  line-height: 1.8;
  resize: vertical;
  transition: border-color .15s, box-shadow .15s;
}

textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(91, 116, 214, .15);
  background: #fff;
}

.confirm-name {
  margin: .75rem 0 1.25rem;
  padding: .75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line-soft);
  font-weight: 700;
  user-select: all;
}

.btn.danger-solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger-solid:hover { background: #8f1e17; color: #fff; }

.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: 0; }
.inline-form input[type=text] { flex: 1 1 12rem; min-width: 8rem; }

/* ── منطقة السحب والإفلات ── */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  padding: 2rem 1rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: #fbfbfd;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.dropzone:hover { border-color: var(--brand); }
.dropzone.over  { border-color: var(--brand); background: var(--brand-soft); }
.dropzone.busy  { opacity: .6; pointer-events: none; }
.dropzone strong { font-size: .9375rem; }
.dropzone span   { color: var(--muted); font-size: .8125rem; }

/* ── شبكة الصور ── */

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
  gap: .75rem;
  margin-top: 1.25rem;
}

.image-card {
  position: relative;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  cursor: grab;
}

.image-card.is-main { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.image-card.dragging { opacity: .4; }

.image-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.image-card figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .25rem;
  padding: .375rem .5rem;
  border-top: 1px solid var(--line-soft);
}

.image-card .dims { color: var(--faint); font-size: .6875rem; direction: ltr; }

.order-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: .875rem;
}

.image-actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: .5rem;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line-soft);
}

.image-action-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .375rem;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.image-action-row form { margin: 0; }
.image-action-row .thumb { width: 2.25rem; height: 2.25rem; }

/* ═══ الأقسام القابلة للطي ═════════════════════════════════════════ */

details.fold > summary {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 1rem 1.25rem;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

details.fold > summary::-webkit-details-marker { display: none; }

details.fold > summary::before {
  content: '◀';
  color: var(--faint);
  font-size: .75rem;
  transition: transform .15s;
}

details.fold[open] > summary::before { transform: rotate(-90deg); }
details.fold[open] > summary { border-bottom: 1px solid var(--line-soft); }
details.fold > summary:hover { background: #fafbfd; }

/* ═══ الصفوف المتكررة ══════════════════════════════════════════════ */

.repeat { display: flex; flex-direction: column; gap: .625rem; margin: 1rem 0; }

.repeat-row {
  display: flex;
  align-items: flex-start;
  gap: .625rem;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfbfd;
}

.repeat-row.dragging { opacity: .4; }

.grip {
  flex: 0 0 auto;
  padding: .375rem .125rem;
  color: var(--faint);
  cursor: grab;
  line-height: 1;
  letter-spacing: -.15em;
}

.grip:active { cursor: grabbing; }

.repeat-fields {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: .625rem;
  align-items: flex-end;
}

.repeat-fields.stack { flex-direction: column; align-items: stretch; }

.repeat-fields > .field { flex: 1 1 8rem; min-width: 0; }
.repeat-fields > .field.wide { flex: 2 1 16rem; }
.repeat-fields > .field.narrow { flex: 0 0 auto; }
.repeat-fields .field label { font-size: .75rem; color: var(--muted); }

.with-button { display: flex; gap: .375rem; }
.with-button input { flex: 1; min-width: 0; }
.with-button .btn { flex: 0 0 auto; }

.option-head { display: flex; flex-wrap: wrap; gap: .625rem; align-items: flex-end; }
.option-head > .field.wide { flex: 1 1 14rem; }

.values {
  display: flex;
  flex-direction: column;
  gap: .375rem;
  padding: .625rem;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.values:empty::before {
  content: 'لا قيم بعد';
  color: var(--faint);
  font-size: .8125rem;
}

.value-row { display: flex; flex-wrap: wrap; align-items: center; gap: .375rem; }
.value-row > input[type=text]   { flex: 1 1 8rem; min-width: 0; }
.value-row > input[type=number] { flex: 0 0 7rem; }
.value-row > input[type=file]   { flex: 1 1 10rem; min-width: 0; font-size: .8125rem; }

.thumb.tiny { width: 1.75rem; height: 1.75rem; }
.tiny-label { font-size: .75rem; color: var(--muted); }

.inline-image { display: flex; align-items: center; gap: .625rem; margin-bottom: .5rem; }

.card-foot.sticky {
  position: sticky;
  bottom: 0;
  flex-wrap: wrap;
  background: #fafbfd;
  box-shadow: 0 -4px 12px rgba(35, 35, 58, .05);
}

/* ═══ الشاشات الصغيرة ══════════════════════════════════════════════ */

@media (max-width: 820px) {
  .shell { flex-direction: column; }

  .sidebar {
    position: static;
    flex: none;
    width: 100%;
    min-height: 0;
    border-inline-end: 0;
    border-bottom: 1px solid var(--line);
    padding: .75rem;
  }

  .sidebar .label { display: none; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }

  main { padding: 1.25rem 1rem 2.5rem; }
  .grid { grid-template-columns: 1fr; }
}
