/* ==========================================================================
   منصة العروض التفاعلية — نمط الواجهة
   ========================================================================== */

:root {
  --brand:        #6d28d9;
  --brand-600:    #7c3aed;
  --brand-100:    #ede9fe;
  --brand-50:     #f5f3ff;

  --ink:          #111827;
  --ink-2:        #374151;
  --muted:        #6b7280;
  --muted-2:      #9ca3af;

  --bg:           #f6f7f9;
  --surface:      #ffffff;
  --line:         #e5e7eb;
  --line-2:       #f0f1f3;

  --ok:           #059669;
  --ok-bg:        #ecfdf5;
  --warn:         #b45309;
  --warn-bg:      #fffbeb;
  --err:          #dc2626;
  --err-bg:       #fef2f2;
  --info-bg:      #eff6ff;
  --info:         #1d4ed8;

  --page-max:     1200px;
  --r:            14px;
  --r-sm:         10px;
  --shadow:       0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg:    0 10px 30px -12px rgba(16,24,40,.18);
  --font:         "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  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, h4 { margin: 0 0 .4em; line-height: 1.35; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
p  { margin: 0 0 1em; }

/* ---------- الشريط العلوي ---------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: var(--page-max); margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 22px; min-height: 62px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; color: var(--ink); font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #a855f7);
  color: #fff; display: grid; place-items: center; font-size: 15px;
}
.topnav { display: flex; gap: 4px; margin-inline-end: auto; flex-wrap: wrap; }
.topnav a {
  padding: 7px 12px; border-radius: 8px; color: var(--ink-2);
  font-size: 14px; font-weight: 500; white-space: nowrap;
}
.topnav a:hover { background: var(--line-2); text-decoration: none; color: var(--ink); }
.topnav a.is-active { background: var(--brand-50); color: var(--brand); }

.user-menu details { position: relative; }
.user-menu summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 9px;
  padding: 5px 10px 5px 6px; border-radius: 10px; border: 1px solid var(--line);
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--line-2); }
.user-name { font-size: 14px; font-weight: 500; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--brand-100);
  color: var(--brand); display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.menu-pop {
  position: absolute; inset-inline-start: 0; top: calc(100% + 8px);
  min-width: 230px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 60;
}
.menu-head { padding: 10px 12px; border-bottom: 1px solid var(--line-2); margin-bottom: 6px; display: grid; gap: 6px; }
.menu-pop a { display: block; padding: 9px 12px; border-radius: 8px; color: var(--ink-2); font-size: 14px; }
.menu-pop a:hover { background: var(--line-2); text-decoration: none; }
.menu-pop a.danger { color: var(--err); }
.nav-toggle { display: none; background: none; border: 0; font-size: 20px; cursor: pointer; }

/* ---------- التخطيط ---------- */

/* صفحات العرض العريض تكبّر الشريط العلوي والمحتوى معاً */
body.wide { --page-max: 1440px; }

.main { max-width: var(--page-max); margin: 0 auto; padding: 28px 20px 60px; }
.main-bare { min-height: 100vh; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-head .sub { color: var(--muted); margin: 0; font-size: 14px; }

.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.crumbs .current { color: var(--ink-2); font-weight: 600; }
.crumbs .sep { color: var(--muted-2); }

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

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow);
}
.card-pad { padding: 22px; }
.card-head {
  padding: 16px 22px; border-bottom: 1px solid var(--line-2);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; }

.grid { display: grid; gap: 18px; }
/* يمنع الجداول العريضة من تمديد أعمدة الشبكة */
.grid > * { min-width: 0; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* تخطيط «محتوى + لوحة جانبية» المستخدم في صفحات الإدارة */
.grid-sidebar {
  display: grid; gap: 18px; align-items: start;
  grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr);
}
.grid-sidebar > * { min-width: 0; }
@media (max-width: 1024px) {
  .grid-sidebar { grid-template-columns: 1fr; }
}

/* بطاقة قسم */
.section-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 20px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow); transition: transform .15s ease, box-shadow .15s ease, border-color .15s;
  color: inherit; position: relative; overflow: hidden;
}
a.section-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: #d8d5e8; }
.section-card .ic {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  font-size: 22px; background: var(--brand-50); color: var(--brand);
}
.section-card h3 { margin: 0; font-size: 17px; }
.section-card .desc { color: var(--muted); font-size: 13.5px; margin: 0; min-height: 42px; }
.section-card .foot { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); margin-top: auto; padding-top: 8px; border-top: 1px solid var(--line-2); }

/* بطاقة عرض */
.pres-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease; color: inherit;
}
a.pres-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.pres-thumb {
  aspect-ratio: 16/9; background: linear-gradient(135deg, #ede9fe, #dbeafe);
  display: grid; place-items: center; font-size: 34px; color: var(--brand); position: relative;
}
.pres-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pres-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.pres-body h3 { margin: 0; font-size: 15.5px; }
.pres-body .desc { color: var(--muted); font-size: 13px; margin: 0; }
.pres-meta { display: flex; gap: 12px; align-items: center; font-size: 12.5px; color: var(--muted-2); margin-top: auto; padding-top: 8px; }

/* ---------- الشارات ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2);
  line-height: 1.6; white-space: nowrap; /* لا تلتف داخل أعمدة الجداول الضيقة */
}
.badge-admin  { background: var(--brand-100); color: var(--brand); }
.badge-ok     { background: var(--ok-bg);   color: var(--ok); }
.badge-warn   { background: var(--warn-bg); color: var(--warn); }
.badge-err    { background: var(--err-bg);  color: var(--err); }
.badge-lock   { background: #fff7ed; color: #c2410c; }

/* ---------- الأزرار ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); font-family: inherit; font-size: 14px;
  font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--line-2); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--err); }
.btn-danger:hover { background: var(--err-bg); }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

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

.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 6px; color: var(--ink-2); }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }

input[type=text], input[type=password], input[type=email], input[type=number],
input[type=url], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-sm);
  font-family: inherit; font-size: 14.5px; background: #fff; color: var(--ink); 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 var(--brand-50);
}
textarea { resize: vertical; min-height: 88px; line-height: 1.6; }
select { cursor: pointer; }

input[type=color] {
  width: 100%; height: 42px; padding: 4px; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff;
}

/* حقول اختيار الملفات الأصلية — تنسيق موحّد مع بقية الحقول */
input[type=file] {
  width: 100%; padding: 8px 10px; background: #fff; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  font-family: inherit; font-size: 13.5px; color: var(--muted);
}
input[type=file]::file-selector-button {
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 6px 12px; margin-inline-end: 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--line-2); color: var(--ink-2);
}
input[type=file]::file-selector-button:hover { background: #e6e6ec; }
input[type=file]:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }

.check { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 10px; font-size: 14px; cursor: pointer; }
.check input { margin-top: 5px; width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; flex: none; }
.check span { color: var(--ink-2); }
.check .hint { display: block; font-size: 12.5px; color: var(--muted); }

.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > * { flex: 1 1 220px; }

fieldset {
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px 18px; margin: 0 0 18px; min-width: 0;
}
fieldset > *:last-child { margin-bottom: 0; }
legend {
  font-weight: 700; font-size: 13.5px; padding: 0 8px; color: var(--ink-2);
  background: var(--surface);
}

/* منطقة السحب والإفلات — display:block ضروري لأن العنصر <label> (سطري افتراضياً) */
.dropzone {
  display: block;
  border: 2px dashed #d4d4de; border-radius: var(--r); padding: 26px 20px; text-align: center;
  background: #fafafb; cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--brand); background: var(--brand-50); }
.dropzone .dz-icon { font-size: 32px; color: var(--brand); }
.dropzone .dz-main { font-weight: 600; margin: 6px 0 2px; }
.dropzone .dz-sub { color: var(--muted); font-size: 13px; }
.dropzone input[type=file] { display: none; }
.dz-file { margin-top: 12px; font-size: 13.5px; color: var(--ok); font-weight: 600; }

/* ---------- الجداول ---------- */

.table-wrap { overflow-x: auto; border-radius: var(--r); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface); }
table.data th, table.data td { padding: 11px 14px; text-align: right; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data th { background: #fafafb; font-weight: 600; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
table.data tbody tr:hover { background: #fcfcfd; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.actions { white-space: nowrap; }
table.data td.actions > form { display: inline-block; }
table.data td.actions > *:not(:first-child) { margin-inline-start: 5px; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; direction: ltr; display: inline-block; }

/* جدول «مفتاح: قيمة» للبيانات التعريفية (لا رؤوس أعمدة) */
table.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
table.kv th, table.kv td { padding: 9px 0; border-bottom: 1px solid var(--line-2); vertical-align: top; text-align: right; }
table.kv th { width: 40%; font-weight: 500; font-size: 13px; color: var(--muted); background: none; white-space: nowrap; }
table.kv tr:last-child th, table.kv tr:last-child td { border-bottom: 0; }

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

.alert {
  padding: 12px 16px; border-radius: var(--r-sm); margin-bottom: 18px;
  font-size: 14px; border: 1px solid transparent; font-weight: 500;
}
.alert-success { background: var(--ok-bg);  color: #065f46; border-color: #a7f3d0; }
.alert-error   { background: var(--err-bg); color: #991b1b; border-color: #fecaca; }
.alert-warning { background: var(--warn-bg);color: #92400e; border-color: #fde68a; }
.alert-info    { background: var(--info-bg);color: #1e40af; border-color: #bfdbfe; }

.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty .ic { font-size: 44px; opacity: .35; display: block; margin-bottom: 10px; }
.empty h3 { color: var(--ink-2); }

/* ---------- الإحصائيات ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; }

/* ---------- صفحة الدخول / القفل ---------- */

.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1100px 520px at 70% -10%, #ede9fe 0%, transparent 60%), var(--bg);
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 34px 30px; box-shadow: var(--shadow-lg);
}
.auth-logo { text-align: center; margin-bottom: 22px; }
.auth-logo .mark {
  width: 52px; height: 52px; border-radius: 15px; margin: 0 auto 12px;
  background: linear-gradient(135deg, var(--brand), #a855f7); color: #fff;
  display: grid; place-items: center; font-size: 24px;
}
.auth-logo h1 { font-size: 20px; margin-bottom: 2px; }
.auth-logo p { color: var(--muted); font-size: 13.5px; margin: 0; }

/* ---------- مشغّل العرض ---------- */

.viewer { position: fixed; inset: 0; display: flex; flex-direction: column; background: #0f1117; }
.viewer-bar {
  display: flex; align-items: center; gap: 14px; padding: 0 16px; height: 52px;
  background: #171923; color: #e5e7eb; border-bottom: 1px solid #262a36; flex: none;
}
.viewer-bar .v-title { font-weight: 600; font-size: 14.5px; margin-inline-end: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar .v-sec { color: #9aa0ae; font-size: 12.5px; font-weight: 400; }
.viewer-bar a, .viewer-bar button {
  color: #cbd0da; background: transparent; border: 1px solid #2d323f; border-radius: 8px;
  padding: 6px 12px; font-size: 13px; font-family: inherit; cursor: pointer; white-space: nowrap;
}
.viewer-bar a:hover, .viewer-bar button:hover { background: #232733; color: #fff; text-decoration: none; }
.viewer-frame { flex: 1; border: 0; width: 100%; background: #fff; }

/* ---------- متفرقات ---------- */

.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-3 { margin-top: 18px; } .mb-3 { margin-bottom: 18px; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.divider { height: 1px; background: var(--line-2); margin: 20px 0; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.perm-item { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; background: #fff; }
.perm-item.on { border-color: var(--brand); background: var(--brand-50); }
.perm-item .sub { margin-inline-start: 25px; padding-top: 6px; border-top: 1px dashed var(--line); margin-top: 8px; }

.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; direction: ltr; }

@media (max-width: 640px) {
  .viewer-bar { height: auto; min-height: 52px; padding: 8px 12px; flex-wrap: wrap; gap: 8px; }
  .viewer-bar .v-title { width: 100%; order: -1; margin-inline-end: 0; }
  .viewer-bar .v-sec { display: block; }
}

/* شريط التنقل يحتوي 6 روابط للمدير — يتحول لقائمة منسدلة مبكراً حتى لا يتزاحم */
@media (max-width: 940px) {
  .topbar-inner { flex-wrap: wrap; gap: 12px; min-height: 56px; padding: 10px 16px; }
  .topnav { order: 3; width: 100%; display: none; }
  .topnav.open { display: flex; }
  .topnav a { padding: 9px 12px; }
  .nav-toggle { display: block; }
  .brand { margin-inline-end: auto; }
}

@media (max-width: 780px) {
  .user-name { display: none; }
  .main { padding: 20px 16px 48px; }
  h1 { font-size: 22px; }
  .page-head { margin-bottom: 16px; }
  .card-pad { padding: 18px; }
  .card-head { padding: 14px 18px; }
  .stat .value { font-size: 23px; }
}

@media print {
  .topbar, .btn, .crumbs { display: none !important; }
  body { background: #fff; }
}
