:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e5e2dc;
  --primary: #b4532a;
  --primary-dark: #8f3f1e;
  --danger-bg: #fdecea;
  --danger: #a12622;
  --ok-bg: #e8f5ec;
  --ok: #1e6b3a;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

a { color: var(--primary); }

/* ---------- القائمة الجانبية (على غرار ووردبريس) ---------- */
:root {
  --sb-w: 230px;
  --sb-bg: #1d2327;
  --sb-bg-2: #2c3338;
  --sb-text: #f0f0f1;
  --sb-muted: #a7aaad;
  --sb-hover: #f2b48f;
}

.sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;            /* يمين الشاشة في الواجهة العربية */
  width: var(--sb-w);
  background: var(--sb-bg);
  color: var(--sb-text);
  display: flex;
  flex-direction: column;
  z-index: 40;
}
.sb-brand { padding: 18px 20px; font-size: 20px; font-weight: 700; border-bottom: 1px solid #3c434a; }
.sb-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.sb-nav ul { list-style: none; margin: 0; padding: 0; }
.sb-section { padding: 16px 20px 6px; font-size: 12px; color: var(--sb-muted); }
.sb-section.is-acting { color: #f0c27b; font-weight: 600; border-top: 1px solid #3c434a; margin-top: 8px; }

.sb-nav li > a,
.sb-nav li > form > button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 20px;
  color: var(--sb-text); text-decoration: none;
  background: none; border: 0; font: inherit; text-align: start; cursor: pointer;
}
.sb-nav li > form { margin: 0; }
.sb-nav li > a:hover,
.sb-nav li > form > button:hover { background: var(--sb-bg-2); color: var(--sb-hover); }
.sb-nav li.is-active > a { background: var(--primary); color: #fff; font-weight: 600; }
.sb-nav .ic { width: 20px; height: 20px; flex: none; }

.sb-sub { background: var(--sb-bg-2); padding: 6px 0 !important; }
.sb-sub li a { display: block; padding: 6px 50px 6px 20px; color: var(--sb-muted); text-decoration: none; font-size: 14px; }
.sb-sub li a:hover { color: var(--sb-hover); }
.sb-sub li.is-current a { color: #fff; font-weight: 600; }

.sb-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 20px; border-top: 1px solid #3c434a; font-size: 14px; }
.sb-name { color: var(--sb-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-user form { margin: 0; }
.sb-user button { display: flex; align-items: center; gap: 6px; background: none; border: 0; color: var(--sb-text); font: inherit; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.sb-user button:hover { background: var(--sb-bg-2); color: var(--sb-hover); }
.sb-user .ic { width: 18px; height: 18px; }

.content { margin-inline-start: var(--sb-w); min-height: 100vh; }
.content .container { max-width: 1100px; margin: 0; }

.mobile-bar { display: none; }
.nav-overlay { display: none; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .nav-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
  .content { margin-inline-start: 0; }
  .mobile-bar {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 20;
    padding: 10px 14px; background: var(--sb-bg); color: var(--sb-text);
  }
  .mobile-bar .brand { font-weight: 700; }
  .menu-toggle { background: none; border: 0; color: inherit; padding: 4px; cursor: pointer; display: flex; }
  .menu-toggle .ic { width: 26px; height: 26px; }
}

.container { max-width: 960px; margin: 0 auto; padding: 24px 16px; }
.narrow { max-width: 420px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card + .card { margin-top: 16px; }

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 0 0 12px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}
.field input:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.field input[dir="ltr"] { text-align: left; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-light { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-light:hover { background: var(--bg); }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert ul { margin: 0; padding-inline-start: 18px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat .num { font-size: 28px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 14px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

/* الجداول */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; background: #faf9f7; }
.table tr:last-child td { border-bottom: 0; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; background: var(--bg); color: var(--muted); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: var(--danger-bg); color: var(--danger); }
.badge-warn { background: #fff4e0; color: #8a5a00; }

.btn-sm { padding: 6px 12px; font-size: 14px; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #7d1c19; }

/* الفروع والطاولات */
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: '▸ '; color: var(--muted); }
details.card[open] > summary::before { content: '▾ '; }

.add-tables { display: flex; flex-wrap: wrap; gap: 10px 28px; padding: 12px 14px; background: #faf9f7; border: 1px solid var(--border); border-radius: 10px; }
.add-tables form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0; }
.add-tables input { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; }

.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-top: 16px; }
.qr-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; text-align: center; background: #fff; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.qr-card.is-off { opacity: .55; }
.qr-label { font-weight: 700; font-size: 18px; }
.qr-img { width: 150px; height: 150px; }
.qr-img svg { width: 100%; height: 100%; }
.qr-link { font-size: 12px; color: var(--muted); word-break: break-all; }
.qr-actions { display: flex; gap: 6px; align-items: flex-start; }
.qr-more { position: relative; }
.qr-more > summary { list-style: none; }
.qr-more > summary::-webkit-details-marker { display: none; }
.qr-menu { position: absolute; z-index: 5; top: 110%; inset-inline-end: 0; width: 220px; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.08); display: flex; flex-direction: column; gap: 8px; }
.qr-menu form { margin: 0; display: flex; gap: 6px; }
.qr-menu input { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font: inherit; }
.qr-menu .btn { width: 100%; }
.qr-menu form:first-child .btn { width: auto; white-space: nowrap; }

.approval-card { border: 2px solid #f0c27b; background: #fffaf0; margin-bottom: 16px; }
.approval-card.is-rejected { border-color: #f0c4c0; background: var(--danger-bg); }

/* سجّل متجرك */
.type-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.type-chip { cursor: pointer; }
.type-chip input { position: absolute; opacity: 0; pointer-events: none; }
.type-chip span { display: inline-block; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border); background: #fff; font-weight: 600; transition: background .15s, color .15s; }
.type-chip input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.type-chip input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }
.hours-box { border: 1px solid var(--line, #e5e7eb); border-radius: 10px; padding: 12px; margin: 0 0 14px; }
.hours-sec { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; align-items: start; padding: 8px 0; }
.hours-sec + .hours-sec { border-top: 1px dashed var(--line, #e5e7eb); }
.hours-label { font-weight: 700; padding-top: 6px; }
.hours-days { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.hours-days .check, .hours-line .check { margin: 0; }
.hours-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 6px; }
.hours-line input[type=time] { width: auto; padding: 6px 8px; }
.hours-note { display: block; margin-top: 8px; }
#hours_closed_days { font-weight: 600; color: #b42318; }
@media (max-width: 600px) { .hours-sec { grid-template-columns: 1fr; } }
.done-check {width: 64px; height: 64px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 34px; display: flex; align-items: center; justify-content: center; margin: 0 auto 10px; }

/* المدن والأحياء */
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.inline-form .field { margin: 0; flex: 1; min-width: 160px; }
.add-districts { display: grid; grid-template-columns: 2fr 1fr auto; gap: 10px; align-items: end; }
.add-districts .field { margin: 0; }
@media (max-width: 700px) { .add-districts { grid-template-columns: 1fr; } }
.row-form { display: flex; gap: 6px; margin: 0; }
.row-form input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font: inherit; width: 130px; }
.row-off td { opacity: .55; }

/* كود QR لمنيو المطعم */
.menu-qr-card { display: flex; gap: 18px; align-items: center; margin-bottom: 16px; }
.menu-qr { width: 150px; height: 150px; flex: none; }
.menu-qr svg { width: 100%; height: 100%; }
@media (max-width: 600px) { .menu-qr-card { flex-direction: column; text-align: center; } }

/* تعديل الصفحة الرئيسية */
.home-form details.card > summary h2 { display: inline; margin: 0; font-size: 18px; }
.home-form details.card[open] > summary { margin-bottom: 14px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; margin-bottom: 8px; }
.row3 input, .home-form fieldset input, .home-form fieldset textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; }
@media (max-width: 600px) { .row3 { grid-template-columns: 1fr; } }
.sticky-save { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--border); }

/* صفحة المطعم وصور الفروع */
.branch-box { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px 14px; margin: 0 0 14px; }
.branch-box legend { padding: 0 6px; font-weight: 700; }
.branch-box.is-off { opacity: .65; }
.branch-box .field { margin-bottom: 10px; }
.cover-current { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.cover-current img { width: 100%; max-height: 180px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin: 10px 0; }
.thumb { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); aspect-ratio: 4 / 3; background: #fafafa; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb form { position: absolute; top: 6px; inset-inline-end: 6px; margin: 0; }
.thumb button { border: 0; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; font: inherit; font-size: 12px; padding: 3px 8px; cursor: pointer; }

/* التقارير */
.report-period { font-size: 16px; font-weight: 400; }
.filters { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; margin-bottom: 16px; }
.filter-row { display: flex; align-items: flex-start; gap: 12px; }
.filter-label { flex: none; width: 52px; padding-top: 7px; font-weight: 700; color: var(--muted); font-size: 14px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }
.seg-btn {
  display: inline-block; padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  text-decoration: none; font-size: 14px; cursor: pointer; white-space: nowrap; list-style: none;
}
.seg-btn::-webkit-details-marker { display: none; }
.seg-btn:hover { background: var(--bg); border-color: #d6d2ca; }
.seg-btn.is-on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.custom-range { position: relative; }
.custom-range[open] .range-form { margin-top: 8px; }
.range-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; font-size: 14px; }
.range-form input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; }
@media (max-width: 600px) {
  .filter-row { flex-direction: column; gap: 6px; }
  .filter-label { width: auto; padding-top: 0; }
}
.stats .stat .num { font-variant-numeric: tabular-nums; }
.num-cell { font-variant-numeric: tabular-nums; }
.top-items .bar-col { width: 34%; }
.qbar { display: block; height: 10px; border-radius: 0; border-start-end-radius: 4px; border-end-end-radius: 4px; background: var(--primary); min-width: 2px; }

/* نسيت كلمة المرور */
.forgot { margin: 16px 0 0; text-align: center; font-size: 14px; }
.forgot-summary { cursor: pointer; color: var(--primary); font-weight: 600; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 22px 0 16px; }
.codes-new { border-color: #f0c27b; background: #fffaf0; }
.codes-list { font-family: Consolas, "Courier New", monospace; font-size: 20px; font-weight: 700; letter-spacing: 1px; line-height: 1.9; }

/* صور التصنيفات */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.cat-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.cat-card form { margin: 0; }
.cat-img { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); background: #fff; }
.cat-img.is-logo { object-fit: contain; padding: 10px; opacity: .6; }
.cat-img.is-empty { display: inline-flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 700; color: var(--muted); background: var(--bg); }
.cat-form label.btn { cursor: pointer; }

/* الشعار */
.name-with-logo { display: inline-flex; align-items: center; gap: 10px; }
.logo-thumb { width: 36px; height: 36px; border-radius: 8px; object-fit: contain; background: #fff; border: 1px solid var(--border); }
.logo-empty { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 700; background: var(--bg); }
.logo-current { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.logo-current img { width: 72px; height: 72px; object-fit: contain; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.field input[type="file"] { padding: 8px; background: #faf9f7; }


.danger-zone { margin-top: 32px; border-color: #f0c4c0; }
.danger-zone h2 { color: var(--danger); }

/* النماذج */
.form-narrow { max-width: 640px; }
.form-actions { margin-top: 16px; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; }
.input-prefix { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.input-prefix span { padding: 10px 12px; background: #faf9f7; color: var(--muted); border-inline-end: 1px solid var(--border); white-space: nowrap; }
.input-prefix input { border: 0 !important; border-radius: 0 !important; flex: 1; min-width: 0; }

.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- التطبيق (PWA): نافذة الشرح وأزرار التثبيت والإشعارات ---------- */
.pwa-sheet { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.pwa-sheet-in { background: #fff; color: #1f2328; width: min(480px, 100%); border-radius: 16px 16px 0 0; padding: 18px 18px max(18px, env(safe-area-inset-bottom)); line-height: 1.7; font-family: inherit; }
.pwa-sheet-in h3 { margin: 0 0 8px; }
.pwa-sheet-in ol { margin: 0 0 8px; padding-inline-start: 20px; }
.pwa-tip { font-size: 13px; color: #6b7280; }
.pwa-close { display: block; width: 100%; margin-top: 10px; border: 0; border-radius: 10px; padding: 11px; background: #166b52; color: #fff; font: inherit; font-weight: 700; cursor: pointer; }
.pwa-btn { border: 1px solid #166b52; color: #166b52; background: #fff; border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.pwa-btn.is-on { background: #e7f3ee; border-color: #e7f3ee; cursor: default; }
.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 640px) { .field-row-3 { grid-template-columns: 1fr; } }
.grace-form { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 14px; }
.grace-form input { width: 70px; }

/* ---------- قائمة الموقع السفلية في صفحات الأدمن ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  display: flex; justify-content: space-around; align-items: stretch;
  background: #fff; border-top: 1px solid var(--border);
  padding: 4px 4px max(4px, env(safe-area-inset-bottom));
  box-shadow: 0 -2px 10px rgba(0,0,0,.05);
}
.bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: #6b7280; font-size: 12px; text-decoration: none; }
.bottom-nav svg { width: 24px; height: 24px; }
.bottom-nav a.is-on { color: #166b52; font-weight: 700; }
body.has-bottom-nav { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
@media (min-width: 861px) { /* الشريط الجانبي ظاهر: القائمة في وسط منطقة المحتوى */
  .bottom-nav { left: 0; right: var(--sb-w); margin: 0 auto; width: min(560px, calc(100% - var(--sb-w))); border: 1px solid var(--border); border-bottom: 0; border-radius: 16px 16px 0 0; }
}
/* أزرار بطاقة المنيو: فتح الجدول + التحديث */
.sync-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-sheet { background: #188038; color: #fff; }
.btn-sheet:hover { background: #12672c; color: #fff; }

/* عروض متجري */
.offer-edit { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0; }
.offer-edit input[name], .offer-edit select { width: 110px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; }
