/* ==========================================================================
   يمن كود للتقنيات الذكية - نظام التصميم
   Mobile-first · RTL/LTR · Dark/Light · بلا أي خطوة بناء
   ========================================================================== */

:root {
  /* الهوية البصرية: أخضر تقني عميق + كهرماني */
  --brand: #0e9384;
  --brand-600: #0b7d70;
  --brand-700: #0a665c;
  --accent: #e0a82e;

  /* محايدات فاتحة */
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-2: #f0f3f5;
  --border: #e2e8ec;
  --text: #14222b;
  --text-muted: #5d717c;

  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0284c7;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(16, 38, 48, .06);
  --shadow: 0 4px 16px rgba(16, 38, 48, .08);
  --shadow-lg: 0 12px 32px rgba(16, 38, 48, .12);
  --sidebar-w: 264px;
  --header-h: 62px;
  --font: "Cairo", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
}

[data-theme="dark"] {
  --bg: #0c161c;
  --surface: #121f28;
  --surface-2: #182832;
  --border: #243744;
  --text: #e7eef2;
  --text-muted: #93a6b1;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 4px 16px rgba(0, 0, 0, .35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--bg); }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { line-height: 1.3; font-weight: 700; }

/* ---------------- التخطيط العام ---------------- */
.layout { display: flex; min-height: 100vh; }

/* ---------------- توافق مع قوالب الواجهة الحالية ---------------- */
.app-shell { display: flex; min-height: 100vh; overflow-x: clip; }
.app-main { flex: 1; min-width: 0; }
.app-content { padding: 20px 18px 40px; max-width: 1200px; width: 100%; }
.topbar {
  height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px; position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 17px; font-weight: 800; flex: 1; min-width: 0; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }

.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; min-height: var(--header-h);
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-700));
  display: grid; place-items: center; color: #fff; font-weight: 800; flex-shrink: 0;
}
.brand-text { min-width: 0; }
.brand-text strong { display: block; font-size: 15px; font-weight: 800; }
.brand-text small { display: block; font-size: 11px; color: var(--text-muted); font-weight: 500; }

.sidebar-nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.sidebar-close {
  margin-inline-start: auto;
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: none;
  align-items: center; justify-content: center;
  font-size: 22px; line-height: 1;
  cursor: pointer;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 14px 16px 16px;
  display: grid;
  gap: 12px;
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--surface) 88%, transparent));
}

.user-chip { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar {
  width: 42px; height: 42px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #000 18%));
  color: #fff; display: grid; place-items: center; font-weight: 800; flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-meta strong, .user-meta small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { color: var(--text-muted); }

.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 600; font-size: 14px;
  margin-bottom: 2px; transition: all .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.nav-ico { width: 20px; height: 20px; display: grid; place-items: center; flex-shrink: 0; }
.nav-ico svg { width: 20px; height: 20px; }
.nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 55;
}
.sidebar-overlay.show { display: block; }

.offline-banner {
  position: fixed;
  inset-inline: 16px;
  inset-block-end: 16px;
  z-index: 80;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}


.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: transform .25s ease;
}
.sidebar__brand {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
}
.sidebar__logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-700));
  display: grid; place-items: center; color: #fff; font-weight: 800;
  flex-shrink: 0;
}
.sidebar__title { font-size: 15px; font-weight: 800; }
.sidebar__title small { display: block; font-size: 11px; color: var(--text-muted); font-weight: 500; }

.nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav__section { font-size: 11px; color: var(--text-muted); padding: 14px 12px 6px; font-weight: 700; letter-spacing: .02em; }
.nav__link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 600; font-size: 14px;
  margin-bottom: 2px; transition: all .15s;
}
.nav__link svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav__link:hover { background: var(--surface-2); color: var(--text); }
.nav__link.active { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }

.main { flex: 1; margin-inline-start: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.header {
  height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px; position: sticky; top: 0; z-index: 50;
}
.header__title { font-size: 17px; font-weight: 800; flex: 1; }
.header__actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  position: relative;
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
  display: grid; place-items: center; transition: all .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 19px; height: 19px; }

.menu-toggle { display: none; }

.content { padding: 20px 18px 40px; max-width: 1200px; width: 100%; }

/* ---------------- البطاقات ---------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card__head { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card__head h3 { font-size: 15px; }
.card__body { padding: 18px; }

.grid { display: grid; gap: 16px; }
.grid-stats { grid-template-columns: repeat(2, 1fr); }
.grid-2 { grid-template-columns: 1fr; }

.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 6px;
}
.stat__icon { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; color: #fff; margin-bottom: 4px; }
.stat__icon svg { width: 22px; height: 22px; }
.stat__value { font-size: 28px; font-weight: 800; }
.stat__label { color: var(--text-muted); font-size: 13px; font-weight: 600; }
.bg-brand { background: var(--brand); }
.bg-accent { background: var(--accent); }
.bg-success { background: var(--success); }
.bg-danger { background: var(--danger); }
.bg-info { background: var(--info); }

/* ---------------- الأزرار ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-family: inherit; font-weight: 700; font-size: 14px; cursor: pointer;
  transition: all .15s; background: var(--surface-2); color: var(--text);
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { transform: translateY(-1px); }
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-600); }
.btn--accent { background: var(--accent); color: #3a2c05; }
.btn--danger { background: var(--danger); color: #fff; }
.btn--ghost { background: transparent; border-color: var(--border); }
.btn--block { width: 100%; }
.btn--sm { padding: 7px 12px; font-size: 13px; }

/* ---------------- النماذج ---------------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 7px; }
.input, .select, .textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 14px; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.textarea { resize: vertical; min-height: 90px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 200px; }

/* ---------------- الجداول ---------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 12px 14px; text-align: start; white-space: nowrap; }
.table thead th { background: var(--surface-2); color: var(--text-muted); font-size: 12px; font-weight: 700; }
.table tbody tr { border-top: 1px solid var(--border); }
.table tbody tr:hover { background: var(--surface-2); }

/* ---------------- الشارات ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--surface-2); color: var(--text-muted);
}
.badge--success { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.badge--danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.badge--warning { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.badge--info { background: color-mix(in srgb, var(--info) 16%, transparent); color: var(--info); }

/* ---------------- التنبيهات ---------------- */
.flash { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.alert {
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; gap: 10px;
}
.alert--success { border-inline-start: 4px solid var(--success); }
.alert--danger { border-inline-start: 4px solid var(--danger); }
.alert--warning { border-inline-start: 4px solid var(--warning); }
.alert--info { border-inline-start: 4px solid var(--info); }

/* ---------------- الصلاحيات (Checkboxes) ---------------- */
.perm-group { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin-bottom: 14px; }
.perm-group__title { font-size: 13px; font-weight: 800; margin-bottom: 10px; color: var(--brand); }
.perm-list { display: grid; grid-template-columns: 1fr; gap: 8px; }
.perm-item { display: flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; }
.perm-item input { width: 18px; height: 18px; accent-color: var(--brand); }

/* ---------------- المصادقة ---------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--bg), var(--surface-2)); }
.auth-card { width: 100%; max-width: 410px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg); padding: 30px 26px; }
.auth-logo { width: 58px; height: 58px; border-radius: 16px; background: linear-gradient(135deg, var(--brand), var(--brand-700)); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 22px; margin: 0 auto 16px; }

/* ---------------- مساعدات ---------------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { font-size: 20px; }
.text-muted { color: var(--text-muted); }
.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.flex { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; }
.qr-box { text-align: center; padding: 16px; }
.qr-box img { max-width: 240px; border-radius: 12px; border: 1px solid var(--border); }

.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 55; }

.install-banner {
  display: none; position: fixed; inset-block-end: 16px; inset-inline: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 14px 16px; z-index: 70;
  align-items: center; gap: 12px; max-width: 460px; margin-inline: auto;
}

/* ---------------- التجاوب (Mobile-first enhancements) ---------------- */
@media (min-width: 640px) {
  .grid-stats { grid-template-columns: repeat(4, 1fr); }
  .perm-list { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 24px; }
}
@media (min-width: 992px) {
  .grid-2 { grid-template-columns: 2fr 1fr; }
}

@media (max-width: 991px) {
  .sidebar {
    width: min(var(--sidebar-w), 86vw);
    transform: translate3d(calc(100% + 24px), 0, 0);
    visibility: hidden;
    pointer-events: none;
    box-shadow: var(--shadow-lg);
  }
  [dir="ltr"] .sidebar {
    transform: translate3d(calc(-100% - 24px), 0, 0);
  }
  .sidebar.open {
    transform: translate3d(0, 0, 0);
    visibility: visible;
    pointer-events: auto;
  }
  .main { margin-inline-start: 0; }
  .menu-toggle { display: grid; }
  .sidebar-close { display: inline-grid; }
}


.app-shell { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; }
.app-content { padding: 1rem; }
.muted { color: var(--text-muted); }
.page-head { display:flex; align-items:center; justify-content:space-between; gap:1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stack > * + * { margin-top: 1rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.row-between { display:flex; align-items:center; justify-content:space-between; gap:1rem; }
.actions { display:flex; gap:.5rem; flex-wrap: wrap; }
.list-item { display:flex; justify-content:space-between; gap:1rem; padding:.65rem 0; border-bottom:1px solid var(--border); }
.list-item:last-child { border-bottom:none; }
.chips { display:flex; flex-wrap:wrap; gap:.35rem; margin-top:.75rem; }
.perm-check { display:inline-flex; align-items:center; gap:.35rem; padding:.3rem .55rem; border:1px solid var(--border); border-radius:999px; font-size:.9rem; }
.auth-card { max-width: 460px; margin: 4rem auto; }
.auth-hint { margin-top: 1rem; color: var(--text-muted); font-size: .9rem; }
.qr-box { white-space: pre-wrap; word-break: break-word; }
.notif-item { display:flex; justify-content:space-between; gap:1rem; padding:1rem 0; border-bottom:1px solid var(--border); }
.notif-item:last-child { border-bottom: none; }
.notif-item.is-unread { font-weight: 700; }
.notif-badge {
  position: absolute;
  translate: 10px -10px;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
}


/* ---- البصمة / شاشة الدخول ---- */
.auth-stack { display: grid; gap: 16px; }
.biometric-box { display: grid; gap: 10px; }
.biometric-state { padding: 12px 14px; border: 1px dashed var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-muted); text-align: center; }
