@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;800;900&display=swap');

:root {
  --sidebar: #221a10;
  --sidebar-2: #150f08;
  --sidebar-hover: #33271a;
  --sidebar-text: #e2d9cc;
  --sidebar-muted: #9b8f7e;
  --brand: #F6A821;
  --brand-dark: #D98B0B;
  --brand-soft: #fcefd6;
  --bg: #f4efe6;
  --card: #ffffff;
  --ink: #1d1a15;
  --muted: #736b5f;
  --line: #e7e0d3;
  --line-soft: #f0ebe2;
  --green: #146c43;
  --green-soft: #e8f6ee;
  --rose: #b42318;
  --rose-soft: #fde8e6;
  --gold: #8a6d12;
  --gold-soft: #f8efcf;
  --blue: #1d4ed8;
  --blue-soft: #e6eefc;
  --purple: #6d28d9;
  --purple-soft: #efe8fd;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(34, 26, 16, 0.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Tajawal', Tahoma, sans-serif;
  direction: rtl;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
i[class^="ri-"] { line-height: 1; }
code {
  background: #f3efe8; padding: 2px 7px; border-radius: 6px;
  font-size: 12px; direction: ltr; display: inline-block;
}

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

.sidebar {
  width: 272px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
  color: var(--sidebar-text);
  padding: 22px 16px 20px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  z-index: 200;
}
.sidebar-brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 18px; }
.sidebar-brand .mark {
  width: 44px; height: 44px; border-radius: 14px;
  background: var(--sidebar-hover); color: var(--brand);
  display: grid; place-items: center; font-size: 22px; flex-shrink: 0;
}
.sidebar-brand strong { display: block; font-size: 16px; color: #fff; font-weight: 800; }
.sidebar-brand span { color: var(--sidebar-muted); font-size: 12px; }

.sidebar-nav {
  flex: 1; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.12) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 8px; }
.nav-label {
  color: var(--sidebar-muted); font-size: 11px; font-weight: 800;
  letter-spacing: .06em; padding: 16px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 12px; margin-bottom: 3px;
  color: var(--sidebar-text); font-weight: 700; font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item i { font-size: 18px; color: var(--brand); }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-hover); color: #fff; box-shadow: inset -3px 0 0 var(--brand); }
.nav-count {
  margin-right: auto; background: var(--brand); color: #1d1405;
  font-size: 11px; font-weight: 900; padding: 1px 8px; border-radius: 999px;
}

.sidebar-footer { padding: 12px 4px 0; border-top: 1px solid rgba(255,255,255,.07); margin-top: 10px; }
.logout-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px;
  color: #e7b3ab; font-weight: 700; font-size: 14px;
}
.logout-link i { font-size: 18px; }
.logout-link:hover { background: rgba(180, 35, 24, .18); color: #fff; }

.overlay { display: none; position: fixed; inset: 0; background: rgba(20, 14, 6, .5); z-index: 150; }
.overlay.show { display: block; }

.main-area { flex: 1; min-width: 0; }

/* ===== الشريط العلوي ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 16px 28px;
  background: rgba(255, 255, 255, .75);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 100;
}
.topbar-title { min-width: 0; flex: 1; }
.topbar h1 { margin: 0; font-size: 22px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.menu-btn {
  display: none; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  width: 40px; height: 40px; font-size: 20px; cursor: pointer; color: var(--ink);
  place-items: center; flex-shrink: 0;
}
.who { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.who b { display: block; font-size: 14px; }
.who small { color: var(--muted); font-size: 12px; }
.who .avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--sidebar); color: var(--brand);
  display: grid; place-items: center; font-weight: 900;
}

.page-content { padding: 24px 28px 40px; max-width: 1400px; }

.page-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.page-actions .spacer { flex: 1; }
.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; font-weight: 800; color: var(--muted);
}
.back-link:hover { color: var(--brand-dark); }

/* ===== البطاقات ===== */
.card, .chart-card, .banner-form, .switch-row {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow);
}
.chart-card { margin-bottom: 16px; }
.chart-card h3, .card h3 { margin: 0 0 4px; font-size: 16px; font-weight: 800; }
.chart-sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-head h3 { margin: 0; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: row-reverse; justify-content: space-between; align-items: center; gap: 12px;
  min-width: 0;
}
a.stat-card:hover { border-color: var(--brand); }
.stat-info { min-width: 0; }
.stat-info .value { font-size: 28px; font-weight: 900; line-height: 1.1; word-break: break-word; }
.stat-info .label { color: var(--muted); font-weight: 700; font-size: 13px; margin-top: 6px; }
.stat-icon {
  width: 48px; height: 48px; border-radius: 14px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 22px;
}
.stat-icon.orange, .stat-icon.gold { background: var(--brand-soft); color: var(--brand-dark); }
.stat-icon.green, .stat-icon.teal { background: var(--green-soft); color: var(--green); }
.stat-icon.blue { background: var(--blue-soft); color: var(--blue); }
.stat-icon.purple, .stat-icon.pink { background: var(--purple-soft); color: var(--purple); }
.stat-icon.red, .stat-icon.rose { background: var(--rose-soft); color: var(--rose); }
.stat-icon.sand { background: #f3eee3; color: #6d5a2b; }

.chart-grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.chart-grid-3, .detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.detail-list { display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; margin: 12px 0 0; font-size: 14px; }
.detail-list dt { color: var(--muted); font-weight: 700; }
.detail-list dd { margin: 0; font-weight: 700; }

.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 12px; }
.image-grid img {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: #eee;
}
.avatar-lg { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; border: 2px solid var(--line); }

.list-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line-soft);
}
.list-row:last-child { border-bottom: 0; }
.list-row b { display: block; font-size: 14px; }
.list-row small { color: var(--muted); font-size: 12px; }

/* ===== الجداول ===== */
.table-scroll {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px 14px;
}
.table-scroll.flat { box-shadow: none; border: 0; padding: 0; border-radius: 0; margin-top: 6px; }
table { width: 100%; min-width: 560px; border-collapse: collapse; }
th, td {
  text-align: right; padding: 12px 8px; border-bottom: 1px solid var(--line);
  font-size: 13.5px; vertical-align: middle; white-space: nowrap;
}
th { color: var(--muted); font-size: 12px; font-weight: 800; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fcfaf6; }
td .btn, td form.inline { margin-left: 4px; }
td form.inline .btn { margin-left: 0; }

.offer-title, .cell-strong { font-weight: 800; }
.offer-title { max-width: 200px; white-space: normal; line-height: 1.35; }
.offer-title a:hover, .cell-strong a:hover { color: var(--brand-dark); }
.cell-wrap { white-space: normal; min-width: 200px; max-width: 360px; line-height: 1.5; }
.cell-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.thumb-link { color: var(--brand-dark); font-weight: 800; }
.thumb-link:hover { text-decoration: underline; }
.banner-thumb { width: 130px; height: 54px; object-fit: cover; border-radius: 12px; background: #eee; border: 1px solid var(--line); }

.stat-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.stat-used { background: var(--blue-soft); color: var(--blue); }
.stat-left { background: var(--brand-soft); color: var(--brand-dark); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 800;
}
.badge.published { background: var(--green-soft); color: var(--green); }
.badge.pending { background: var(--gold-soft); color: var(--gold); }
.badge.rejected { background: var(--rose-soft); color: var(--rose); }
.badge.neutral { background: #efece6; color: #4b4538; }

/* ===== الأزرار ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 8px 14px;
  font: inherit; font-size: 13px; font-weight: 800; cursor: pointer;
  background: var(--sidebar); color: #fff;
  transition: background .15s, border-color .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn i { font-size: 16px; }
.btn-primary { background: var(--brand); color: #1d1405; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-approve { background: var(--green-soft); color: var(--green); }
.btn-approve:hover { background: #d3eedf; }
.btn-reject { background: var(--rose-soft); color: var(--rose); }
.btn-reject:hover { background: #f9d3cf; }
.btn-delete { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-delete:hover { border-color: #cfc5b3; background: #fbf9f5; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
form.inline { display: inline; }

/* ===== الفلاتر والبحث ===== */
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.search-form { display: flex; gap: 8px; margin-right: auto; }
.search-input, .field-grid input, .field-grid select, .field-grid textarea,
.banner-form input[type=text], .banner-form input[type=number], .banner-form input[type=url],
.banner-form input[type=file], .banner-form textarea, .banner-form select,
.form-toolbar input[type=date] {
  border: 1px solid var(--line); background: #fff; border-radius: 12px;
  padding: 10px 12px; font: inherit; font-size: 14px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.search-input { min-width: 240px; width: auto; padding: 8px 12px; font-size: 13px; }
.filter-row > .search-input { margin-right: auto; }
.search-input:focus, .field-grid input:focus, .field-grid select:focus, .field-grid textarea:focus,
.banner-form input:focus, .banner-form textarea:focus, .banner-form select:focus, .legal-editor:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(246, 168, 33, .18);
}
.form-toolbar input[type=date] { width: auto; }

/* ===== النماذج ===== */
.banner-form { margin-bottom: 16px; }
.banner-form > strong { display: block; font-size: 16px; font-weight: 800; }
.banner-form label, .field-grid label {
  display: block; font-weight: 700; font-size: 13px; color: var(--ink);
  margin: 14px 0 6px;
}
.field-grid label { margin-top: 0; }
.banner-form .field-grid { margin-top: 14px; }
.form-actions, .form-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.form-toolbar label { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-grid .span-2, .span-2 { grid-column: 1 / -1; }
.check-field { display: flex; align-items: flex-end; }
.check-field label { display: flex; align-items: center; gap: 8px; cursor: pointer; margin: 0 0 10px; }
.check-field input { width: auto; accent-color: var(--brand); }
.form-section-title { font-weight: 800; display: block; margin-bottom: 10px; font-size: 15px; }
.form-spaced { margin-top: 10px; }
.form-spaced-lg { margin-top: 18px; }
[hidden] { display: none !important; }

.size-hint, .hint {
  background: #fdf7ea; border: 1px dashed #ecd9a8; border-radius: 12px;
  padding: 12px 14px; font-size: 13px; color: #6b5316; line-height: 1.7; margin: 6px 0 10px;
}
.hint code { background: rgba(246, 168, 33, .16); color: #6b5316; }

.tab-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tab-row a {
  padding: 9px 16px; border-radius: 12px; background: #fff; border: 1px solid var(--line);
  font-weight: 800; font-size: 13.5px; color: var(--muted);
}
.tab-row a:hover { color: var(--ink); border-color: #cfc5b3; }
.tab-row a.active { background: var(--sidebar); color: #fff; border-color: var(--sidebar); }
.legal-editor {
  width: 100%; min-height: 420px; font: inherit; font-size: 14px; line-height: 1.8;
  padding: 14px 16px; border-radius: 16px; border: 1px solid var(--line); background: #fff; resize: vertical;
}
.link-row { margin-bottom: 16px; display: flex; gap: 16px; flex-wrap: wrap; }
.link-row a { color: var(--brand-dark); font-weight: 800; }
.link-row a:hover { text-decoration: underline; }
.ref-list { line-height: 1.9; font-size: 14px; margin: 0; padding-right: 20px; }
.ref-list a { color: var(--brand-dark); font-weight: 800; }

/* ===== مفتاح الإعدادات ===== */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.switch-row .info h3 { margin: 0 0 6px; font-size: 16px; }
.switch-row .info p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.switch-btn { flex-shrink: 0; width: 56px; height: 30px; border-radius: 20px; border: none; cursor: pointer; position: relative; transition: background .2s; }
.switch-btn.on { background: var(--green); }
.switch-btn.off { background: #d9d3c7; }
.switch-btn .knob { position: absolute; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: right .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch-btn.on .knob { right: 3px; }
.switch-btn.off .knob { right: 29px; }
.status-label { font-weight: 800; font-size: 13px; margin-left: 10px; }
.status-label.on { color: var(--green); }
.status-label.off { color: var(--muted); }

/* ===== الرسائل ===== */
.success-msg, .error-msg {
  padding: 12px 14px; border-radius: 12px; margin-bottom: 16px;
  font-weight: 700; font-size: 14px; border: 1px solid;
}
.success-msg { background: var(--green-soft); color: var(--green); border-color: #b7e4c7; }
.error-msg { background: var(--rose-soft); color: var(--rose); border-color: #f5c2c0; }
.empty {
  text-align: center; color: var(--muted); padding: 40px 12px; font-weight: 700;
  background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius);
}
.chart-card .empty, .table-scroll .empty { border: 0; background: none; }

/* ===== الدخول ===== */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 500px at 10% 0%, rgba(246, 168, 33, .2), transparent 50%),
    linear-gradient(160deg, #1b140b 0%, #2c2114 55%, #1b140b 100%);
}
.login-box {
  width: min(440px, 100%); background: rgba(255,255,255,.97); color: var(--ink);
  border-radius: 28px; padding: 36px 32px 28px; box-shadow: 0 30px 80px rgba(0,0,0,.3);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.login-brand .mark {
  width: 50px; height: 50px; border-radius: 16px; background: var(--sidebar); color: var(--brand);
  display: grid; place-items: center; font-size: 24px;
}
.login-brand h1 { margin: 0; font-size: 24px; font-weight: 900; }
.login-brand span { color: var(--brand-dark); font-weight: 800; font-size: 13px; }
.login-box .sub { margin: 6px 0 22px; color: var(--muted); font-size: 14px; }
.login-box label { display: block; font-weight: 700; margin: 14px 0 6px; font-size: 14px; }
.login-box input {
  width: 100%; border: 1px solid #ddd5c7; border-radius: 14px; padding: 13px 14px;
  font: inherit; background: #fcfaf6;
}
.login-box input:focus { outline: 2px solid rgba(246,168,33,.35); border-color: var(--brand); }
.login-box button {
  width: 100%; margin-top: 22px; border: 0; border-radius: 14px; padding: 13px;
  font: inherit; font-weight: 800; font-size: 15px; background: var(--sidebar); color: #fff; cursor: pointer;
}
.login-box button:hover { background: #3a2c1a; }
.login-box .error-msg { margin: 14px 0 0; }
.login-hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 16px; }

/* ===== الشاشات الصغيرة ===== */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-grid-2, .chart-grid-3, .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar {
    position: fixed; right: 0; top: 0; height: 100vh; width: 272px;
    transform: translateX(100%); transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: -12px 0 30px rgba(0,0,0,.3); }
  .menu-btn { display: grid; }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 18px; }
  .topbar p { display: none; }
  .who > div:first-child { display: none; }
  .page-content { padding: 16px; }
  .stats-grid { gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-info .value { font-size: 21px; }
  .stat-icon { width: 40px; height: 40px; font-size: 18px; }
  .field-grid { grid-template-columns: 1fr; }
  .search-form { width: 100%; margin-right: 0; }
  .search-input { min-width: 0; width: 100%; }
  .filter-row > .search-input { margin-right: 0; }
  .detail-list { grid-template-columns: 1fr; gap: 2px; }
  .detail-list dd { margin-bottom: 10px; }
  .login-box { padding: 28px 22px; }
}

/* ===== الصور المصغّرة ===== */
.thumb {
  width: 54px; height: 54px; object-fit: cover; border-radius: 12px;
  background: #efe9df; border: 1px solid var(--line); display: block;
}
.thumb-wrap { position: relative; display: inline-block; }
.thumb-count {
  position: absolute; bottom: -4px; left: -4px;
  background: var(--sidebar); color: #fff; font-size: 11px; font-weight: 800;
  padding: 1px 6px; border-radius: 999px;
}
.thumb-empty { display: grid; place-items: center; color: #b3a891; font-size: 20px; }
.user-cell { display: inline-flex; align-items: center; gap: 10px; }
.avatar-sm {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
  border: 1px solid var(--line); background: #efe9df;
}
.avatar-empty { display: grid; place-items: center; color: var(--brand-dark); font-weight: 900; font-size: 14px; }

/* ===== تكبير الصور ===== */
.zoomable { cursor: zoom-in; transition: transform .15s, box-shadow .15s; }
.zoomable:hover { transform: scale(1.06); box-shadow: 0 4px 14px rgba(34, 26, 16, .18); }
.avatar-lg { width: 72px; height: 72px; }
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(15, 11, 6, .82); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 24px; cursor: zoom-out;
  animation: lightbox-in .15s ease;
}
.lightbox img {
  max-width: min(92vw, 720px); max-height: 86vh; object-fit: contain;
  border-radius: 18px; box-shadow: 0 30px 80px rgba(0, 0, 0, .45); background: #fff; cursor: default;
}
.lightbox-close {
  position: absolute; top: 18px; left: 18px;
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255, 255, 255, .15); color: #fff; font-size: 24px; display: grid; place-items: center;
}
.lightbox-close:hover { background: rgba(255, 255, 255, .28); }
@keyframes lightbox-in { from { opacity: 0; } to { opacity: 1; } }

/* ===== شعار التطبيق ===== */
.mark-logo { object-fit: cover; padding: 0; background: #fff; }
.login-brand .mark-logo { box-shadow: 0 6px 18px rgba(34, 26, 16, .18); }
