/* ═══════════════════════════════════════════════════════════════════
   لوحة تحكّم خطنا — نظام تصميم مطابق لهوية التطبيق
   كحلي عميق + ذهبي نحاسي، خط طجوال، اتجاه من اليمين لليسار.
   ═══════════════════════════════════════════════════════════════════ */

@font-face { font-family: 'Tajawal'; src: url('Tajawal-Light.ttf')     format('truetype'); font-weight: 300; font-display: swap; }
@font-face { font-family: 'Tajawal'; src: url('Tajawal-Regular.ttf')   format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Tajawal'; src: url('Tajawal-Medium.ttf')    format('truetype'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Tajawal'; src: url('Tajawal-Bold.ttf')      format('truetype'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Tajawal'; src: url('Tajawal-ExtraBold.ttf') format('truetype'); font-weight: 800; font-display: swap; }

:root {
  --ink:        #061020;
  --navy:       #0E2340;
  --navy-soft:  #1B3F72;
  --navy-bright:#2A62B8;
  --brass:      #C79A3E;
  --brass-light:#E2C078;
  --brass-deep: #9A7526;

  --success: #15905B;
  --warning: #C4890F;
  --danger:  #C23B3B;
  --star:    #F0A500;
  --whatsapp:#1FA855;

  --bg:            #F4F6FA;
  --surface:       #FFFFFF;
  --surface-alt:   #EDF1F7;
  --outline:       #E1E7F0;
  --outline-strong:#CBD5E3;
  --text:          #0D1726;
  --text-2:        #56637A;
  --text-3:        #8A96A8;

  --brand-grad: linear-gradient(215deg, #1E4C8A, #0B1B33);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 999px;

  --shadow-soft: 0 6px 18px rgba(13, 23, 38, .08);
  --shadow-lift: 0 12px 28px rgba(13, 23, 38, .12);

  --sidebar-w: 262px;
}

[data-theme="dark"] {
  --bg:            #060B14;
  --surface:       #0F1826;
  --surface-alt:   #162236;
  --outline:       #223046;
  --outline-strong:#2E4059;
  --text:          #EDF2F9;
  --text-2:        #9DACC2;
  --text-3:        #6B7B92;
  --shadow-soft: 0 6px 18px rgba(0, 0, 0, .45);
  --shadow-lift: 0 12px 28px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

/* السمة hidden يجب أن تتغلّب على أي display في الأصناف أدناه. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: 'Tajawal', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.35; }
p { margin: 0 0 .6rem; }
a { color: inherit; text-decoration: none; }
code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .85em;
  background: var(--surface-alt);
  padding: 1px 5px;
  border-radius: 5px;
  direction: ltr;
  display: inline-block;
}
.muted { color: var(--text-2); }
.tiny  { font-size: 12.5px; color: var(--text-2); }
.ltr   { direction: ltr; text-align: right; unicode-bidi: isolate; }
.nowrap{ white-space: nowrap; }

/* ── الأزرار ─────────────────────────────────────────────────────── */
.btn {
  font: inherit;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  padding: .55rem 1.1rem;
  cursor: pointer;
  transition: filter .15s, background .15s, border-color .15s, transform .05s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  min-height: 42px;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--navy); color: #fff; }
[data-theme="dark"] .btn-primary { background: var(--navy-bright); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); }
.btn-brass   { background: var(--brass); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-whatsapp{ background: var(--whatsapp); color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--outline-strong);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: 13px; border-radius: var(--r-sm); }

.icon-btn {
  font: inherit;
  font-size: 17px;
  line-height: 1;
  background: transparent;
  border: 1px solid var(--outline);
  color: var(--text-2);
  width: 38px; height: 38px;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }

/* ── الحقول ──────────────────────────────────────────────────────── */
.field { display: block; margin-bottom: 1rem; }
.field > span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: .35rem;
}
.field input, .field select, .field textarea {
  font: inherit;
  width: 100%;
  padding: .6rem .8rem;
  border: 1px solid var(--outline);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { min-height: 90px; resize: vertical; line-height: 1.7; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--navy-bright);
  box-shadow: 0 0 0 3px rgba(42, 98, 184, .16);
}
.field-hint { font-size: 12px; color: var(--text-3); margin-top: .3rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }

.check {
  display: flex; align-items: center; gap: .55rem;
  padding: .55rem .7rem;
  border: 1px solid var(--outline);
  border-radius: var(--r-md);
  margin-bottom: .55rem;
  cursor: pointer;
  background: var(--surface);
}
.check input { width: 18px; height: 18px; accent-color: var(--navy-bright); margin: 0; }
.check:hover { background: var(--surface-alt); }

.chip-grid { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: 1rem; }
.chip {
  border: 1px solid var(--outline);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--r-pill);
  padding: .3rem .8rem;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.chip[aria-pressed="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }
[data-theme="dark"] .chip[aria-pressed="true"] { background: var(--navy-bright); border-color: var(--navy-bright); }

/* شريط البحث فوق الحبّات حين تكثر الخيارات */
.chip-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: .6rem;
}
.chip-search {
  flex: 1 1 200px;
  min-width: 0;
  border: 1px solid var(--outline);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: .45rem .7rem;
  font: inherit;
  font-size: 13.5px;
}
.chip-search:focus { outline: 2px solid var(--navy-bright); outline-offset: -1px; }
.chip-count { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.chip-none { margin: 0 0 1rem; }
.chip-grid .chip[hidden] { display: none; }

/* ── شاشة الدخول ─────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(900px 420px at 78% -10%, rgba(199,154,62,.16), transparent 60%),
    linear-gradient(180deg, #0E2340, #061020);
}
.login-card {
  width: min(430px, 100%);
  background: rgba(255,255,255,.055);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--r-lg);
  padding: 2rem 1.6rem 1.4rem;
  color: #fff;
  backdrop-filter: blur(10px);
}
.login-logo { width: 76px; height: 76px; display: block; margin: 0 auto .9rem; border-radius: 20px; }
.login-card h1 { text-align: center; font-size: 21px; }
.login-card > .muted { text-align: center; color: rgba(255,255,255,.6); margin-bottom: 1.6rem; font-size: 13.5px; }
.login-card .field > span { color: rgba(255,255,255,.7); }
.login-card .field input {
  background: rgba(255,255,255,.07);
  border-color: rgba(255,255,255,.16);
  color: #fff;
}
.login-card .field input::placeholder { color: rgba(255,255,255,.32); }
.login-card .field input:focus { border-color: var(--brass-light); box-shadow: 0 0 0 3px rgba(226,192,120,.18); }
.login-card .btn-primary { background: #fff; color: var(--navy); margin-top: .4rem; }
.login-error {
  margin: .9rem 0 0;
  background: rgba(194,59,59,.16);
  border: 1px solid rgba(194,59,59,.4);
  color: #ffc9c9;
  border-radius: var(--r-sm);
  padding: .6rem .8rem;
  font-size: 13.5px;
  white-space: pre-line;
}
.login-help { margin-top: 1.3rem; font-size: 13px; color: rgba(255,255,255,.65); }
.login-help summary { cursor: pointer; color: var(--brass-light); font-weight: 600; }
.login-help ol { margin: .7rem 0 0; padding-inline-start: 1.2rem; line-height: 1.9; }
.login-help code { background: rgba(255,255,255,.12); color: #fff; }

/* ── الهيكل ──────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--brand-grad);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 40;
}
.brand {
  display: flex; align-items: center; gap: .65rem;
  padding: 1.1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.brand-logo { width: 38px; height: 38px; border-radius: 11px; }
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; font-size: 12px; color: rgba(255,255,255,.6); }
.sidebar-close { display: none; margin-inline-start: auto; border-color: rgba(255,255,255,.2); color: #fff; }

.nav { flex: 1; overflow-y: auto; padding: .7rem .6rem; }
.nav-group {
  font-size: 11.5px;
  color: rgba(255,255,255,.42);
  font-weight: 700;
  padding: 1rem .6rem .35rem;
  letter-spacing: .02em;
}
.nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .7rem;
  border-radius: var(--r-sm);
  color: rgba(255,255,255,.82);
  font-size: 14.5px;
  margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 700; }
.nav-ico { width: 20px; text-align: center; opacity: .8; font-size: 13px; }
.nav-count {
  margin-inline-start: auto;
  font-style: normal;
  font-size: 11.5px;
  font-weight: 700;
  background: rgba(255,255,255,.14);
  border-radius: var(--r-pill);
  padding: 1px 7px;
  min-width: 22px;
  text-align: center;
}
.nav-count:empty { display: none; }
.nav-count--alert { background: var(--brass); color: #fff; }

.sidebar-foot { padding: .8rem; border-top: 1px solid rgba(255,255,255,.1); }
.admin-chip { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.admin-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--brass); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
  line-height: 1;
  overflow: hidden;
  flex: 0 0 36px;
}
.admin-chip strong { display: block; font-size: 13.5px; }
.admin-chip span:not(.admin-avatar) { display: block; font-size: 11px; color: rgba(255,255,255,.5); overflow: hidden; text-overflow: ellipsis; max-width: 150px; white-space: nowrap; }
.sidebar-foot .btn-ghost { color: #fff; border-color: rgba(255,255,255,.22); min-height: 38px; font-size: 13.5px; }
.sidebar-foot .btn-ghost:hover { background: rgba(255,255,255,.1); }

.sidebar-scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .8rem;
  padding: .8rem 1.2rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--outline);
}
.topbar h1 { font-size: 19px; flex: 1; }
.topbar-actions { display: flex; gap: .45rem; }
.menu-btn { display: none; }

.content { padding: 1.2rem; flex: 1; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed; inset-inline-start: 0; top: 0;
    transform: translateX(100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lift);
  }
  .shell.nav-open .sidebar { transform: translateX(0); }
  .shell.nav-open .sidebar-scrim {
    display: block; position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: 35;
  }
  .sidebar-close, .menu-btn { display: inline-flex; }
  .content { padding: 1rem .8rem 2rem; }
}

/* ── البطاقات والجداول ───────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  margin-bottom: 1rem;
}
.card-head {
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--outline);
}
.card-head h2 { font-size: 16px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 1rem; }

.toolbar {
  display: flex; gap: .6rem; flex-wrap: wrap; align-items: center;
  margin-bottom: 1rem;
}
.toolbar input[type="search"], .toolbar select {
  font: inherit;
  padding: .5rem .85rem;
  min-height: 42px;
  border: 1px solid var(--outline);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text);
  min-width: 240px;
}
.toolbar input[type="search"]:focus, .toolbar select:focus {
  outline: none; border-color: var(--navy-bright);
}
.toolbar .spacer { flex: 1; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: right;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-2);
  padding: .65rem .8rem;
  background: var(--surface-alt);
  white-space: nowrap;
  position: sticky; top: 0;
}
tbody td {
  padding: .7rem .8rem;
  border-top: 1px solid var(--outline);
  vertical-align: middle;
}
tbody tr:hover { background: var(--surface-alt); }
td.actions { white-space: nowrap; text-align: left; }
td.actions .btn { margin-inline-start: .3rem; }

.thumb {
  width: 54px; height: 40px; object-fit: cover;
  border-radius: 8px; background: var(--surface-alt);
  display: block;
}
.thumb-empty {
  width: 54px; height: 40px; border-radius: 8px;
  background: var(--surface-alt); display: grid; place-items: center;
  color: var(--text-3); font-size: 15px;
}

.avatar-sm {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 12.5px;
  line-height: 1;
  overflow: hidden;
  flex: 0 0 34px;
}
.cell-user { display: flex; align-items: center; gap: .55rem; }
.cell-user strong { display: block; font-size: 14px; }
.cell-user span:not(.avatar-sm) { display: block; font-size: 12px; color: var(--text-2); }

/* ── الشارات ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  font-size: 12px; font-weight: 700;
  border-radius: var(--r-pill);
  padding: .15rem .6rem;
  background: var(--surface-alt);
  color: var(--text-2);
  white-space: nowrap;
}
.badge-ok      { background: rgba(21,144,91,.14);  color: var(--success); }
.badge-warn    { background: rgba(196,137,15,.16); color: var(--warning); }
.badge-danger  { background: rgba(194,59,59,.14);  color: var(--danger); }
.badge-brass   { background: rgba(199,154,62,.18); color: var(--brass-deep); }
[data-theme="dark"] .badge-brass { color: var(--brass-light); }
.badge-info    { background: rgba(42,98,184,.16);  color: var(--navy-bright); }

/* ── لوحة المعلومات ──────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: .8rem;
  margin-bottom: 1.3rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--r-lg);
  padding: 1rem;
  box-shadow: var(--shadow-soft);
}
.stat b { display: block; font-size: 27px; line-height: 1.2; font-weight: 800; }
.stat span { display: block; font-size: 13px; color: var(--text-2); }
.stat .stat-ico { font-size: 16px; color: var(--brass); margin-bottom: .35rem; display: block; }

.hero {
  background: var(--brand-grad);
  color: #fff;
  border-radius: var(--r-lg);
  padding: 1.4rem;
  margin-bottom: 1.2rem;
  box-shadow: var(--shadow-lift);
}
.hero h2 { font-size: 20px; margin-bottom: .3rem; }
.hero p { color: rgba(255,255,255,.72); margin: 0; font-size: 14px; }

.bar-list { display: grid; gap: .6rem; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: .3rem .8rem; align-items: center; }
.bar-row > span:first-child { font-size: 13.5px; }
.bar-row > b { font-size: 13px; font-weight: 700; }
.bar-track {
  grid-column: 1 / -1;
  height: 7px; border-radius: var(--r-pill);
  background: var(--surface-alt); overflow: hidden;
}
.bar-fill { height: 100%; background: var(--navy-bright); border-radius: var(--r-pill); }

/* ── الحالات ─────────────────────────────────────────────────────── */
.empty, .loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-2);
}
.empty-ico { font-size: 34px; opacity: .35; display: block; margin-bottom: .7rem; }
.empty h3 { font-size: 16px; margin-bottom: .35rem; color: var(--text); }
.spinner {
  display: inline-block;
  width: 17px; height: 17px;
  border: 2px solid var(--outline-strong);
  border-top-color: var(--navy-bright);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -3px;
  margin-inline-end: .4rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert {
  border-radius: var(--r-md);
  padding: .8rem 1rem;
  margin-bottom: 1rem;
  font-size: 14px;
  border: 1px solid;
  white-space: pre-line;
}
.alert-warn   { background: rgba(196,137,15,.10); border-color: rgba(196,137,15,.35); }
.alert-danger { background: rgba(194,59,59,.09);  border-color: rgba(194,59,59,.34); }
.alert-info   { background: rgba(42,98,184,.09);  border-color: rgba(42,98,184,.3); }
.alert b { display: block; margin-bottom: .2rem; }

/* ── النافذة المنبثقة ────────────────────────────────────────────── */
.modal-scrim {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(6,16,32,.6);
  display: grid; place-items: center;
  padding: 1rem;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  width: min(620px, 100%);
  max-height: 90vh;
  max-height: 90dvh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lift);
  border: 1px solid var(--outline);
}
.modal-head {
  display: flex; align-items: center; gap: .7rem;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid var(--outline);
}
.modal-head h2 { font-size: 17px; flex: 1; }
.modal-body { padding: 1.1rem; overflow-y: auto; }
.modal-foot {
  display: flex; gap: .55rem; justify-content: flex-start;
  padding: .85rem 1.1rem;
  border-top: 1px solid var(--outline);
  background: var(--surface-alt);
}
.modal-foot .spacer { flex: 1; }

.section-title {
  font-size: 13px; font-weight: 700; color: var(--brass-deep);
  margin: 1.2rem 0 .6rem;
  padding-bottom: .3rem;
  border-bottom: 1px solid var(--outline);
}
[data-theme="dark"] .section-title { color: var(--brass-light); }
.section-title:first-child { margin-top: 0; }

/* ── الإشعارات ───────────────────────────────────────────────────── */
.toasts {
  position: fixed; inset-block-end: 1rem; inset-inline-start: 1rem;
  z-index: 80; display: grid; gap: .5rem; max-width: min(420px, calc(100vw - 2rem));
}
.toast {
  background: var(--ink);
  color: #fff;
  border-radius: var(--r-md);
  padding: .7rem 1rem;
  font-size: 14px;
  box-shadow: var(--shadow-lift);
  display: flex; gap: .5rem; align-items: flex-start;
  animation: toast-in .2s ease;
  white-space: pre-line;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.toast-ok   { border-inline-start: 3px solid var(--success); }
.toast-err  { border-inline-start: 3px solid var(--danger); }
.toast-warn { border-inline-start: 3px solid var(--warning); }
.toast-info { border-inline-start: 3px solid var(--brass); }

/* أدوات مساعدة */
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.mt { margin-top: 1rem; }
.mb0 { margin-bottom: 0; }
.stars { color: var(--star); letter-spacing: 1px; font-size: 13px; }
