:root {
  --coral: #E76043; --coral-d: #C94A2F; --coral-50: #FFF1EC;
  --teal: #27A5A5; --teal-d: #17797A; --mint: #E1F4F4;
  --bg: #F6F3F1; --card: #fff; --ink: #1D2626; --ink-2: #4A5454; --muted: #6B7373;
  --line: #E8E1DC; --ok: #1E8A5A; --warn-bg: #FFF4E5; --warn: #7A4A00;
  --shadow: 0 1px 2px rgba(29,38,38,.05), 0 10px 30px -14px rgba(29,38,38,.18);
  --ease: cubic-bezier(.2,.7,.2,1);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.6 "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif; }
h1, h2, h3, p { margin: 0; }
h1, h2 { font-family: "Readex Pro", "IBM Plex Sans Arabic", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; border-radius: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.muted { color: var(--muted); }
.wrap { width: min(1200px, 100% - 32px); margin: 0 auto; padding: 24px 0 60px; }

/* أزرار */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 20px; border-radius: 12px; border: 0; cursor: pointer; font-weight: 600; text-decoration: none; transition: background .2s, transform .15s, box-shadow .2s; white-space: nowrap; }
.btn:active { transform: scale(.98); }
.btn.sm { min-height: 38px; padding: 6px 14px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.primary { background: var(--coral); color: #fff; }
.btn.primary:hover { background: var(--coral-d); }
.btn.teal { background: var(--teal-d); color: #fff; }
.btn.teal:hover { background: #126364; }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn.ghost:hover { box-shadow: inset 0 0 0 1px var(--teal); color: var(--teal-d); }
.btn:disabled { opacity: .55; cursor: default; }
.msg { color: #B3361E; font-size: 14px; }
.msg:empty { display: none; }
.hint { font-size: 12px; color: var(--muted); }
.center { text-align: center; }

/* الدخول */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 80% 10%, #FFE1D7, transparent 40%), radial-gradient(circle at 10% 90%, #CDEEEE, transparent 40%), var(--bg); }
.login-card { width: min(380px, 100%); background: #fff; border-radius: 28px; padding: 36px 28px; display: grid; gap: 14px; justify-items: center; text-align: center; box-shadow: var(--shadow); }
.login-card img { width: 84px; height: auto; margin-bottom: 4px; }
.login-card h1 { font-size: 26px; }
.login-card input { width: 100%; min-height: 52px; border-radius: 14px; border: 1.5px solid var(--line); padding: 8px 16px; text-align: center; font-size: 18px; letter-spacing: 2px; background: var(--bg); }
.login-card input:focus { outline: none; border-color: var(--teal); background: #fff; }

/* الشريط العلوي */
.top { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-in { width: min(1200px, 100% - 32px); margin: 0 auto; display: flex; align-items: center; gap: 14px; min-height: 68px; }
.top h1 { font-size: 19px; margin-inline-end: auto; }
.brand img { width: 52px; height: auto; }

/* الملخص */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: #fff; border-radius: 20px; padding: 18px 20px; box-shadow: inset 0 0 0 1px var(--line); display: grid; }
.stat span { font-family: "Readex Pro", sans-serif; font-size: 32px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 14px; }
.s-coral { background: var(--coral); color: #fff; box-shadow: none; }
.s-coral small { color: rgba(255,255,255,.88); }
.s-teal { background: var(--teal-d); color: #fff; box-shadow: none; }
.s-teal small { color: rgba(255,255,255,.85); }

/* التبويب */
.tabs { display: inline-flex; background: #fff; border-radius: 14px; padding: 4px; box-shadow: inset 0 0 0 1px var(--line); margin-bottom: 16px; }
.tab { border: 0; background: transparent; padding: 8px 20px; border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--ink-2); }
.tab[aria-selected="true"] { background: var(--ink); color: #fff; }

.bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 0; background: #fff; box-shadow: inset 0 0 0 1px var(--line); padding: 6px 14px; border-radius: 99px; cursor: pointer; font-size: 14px; }
.chip.on { background: var(--mint); color: var(--teal-d); box-shadow: inset 0 0 0 1px #BFE5E5; font-weight: 600; }
.search { flex: 1; min-width: 200px; min-height: 40px; border-radius: 12px; border: 1px solid var(--line); padding: 6px 14px; background: #fff; }
.search:focus { outline: none; border-color: var(--teal); }

/* قائمة الطلبات */
.list { display: grid; gap: 10px; }
.lead { background: #fff; border-radius: 18px; padding: 16px 18px; box-shadow: inset 0 0 0 1px var(--line); display: grid; grid-template-columns: 1.4fr 1fr .7fr 1fr auto; gap: 14px; align-items: center; animation: in .3s var(--ease); }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }
.lead h3 { font-size: 16px; font-weight: 700; }
.lead .sub { color: var(--muted); font-size: 13px; }
.lead a.tel { color: var(--teal-d); font-weight: 600; text-decoration: none; direction: ltr; unicode-bidi: isolate; }
.lead select { min-height: 38px; border-radius: 10px; border: 1px solid var(--line); padding: 4px 10px; background: #fff; cursor: pointer; }
.lead select[data-s="new"] { background: var(--coral-50); border-color: #F6C4B6; color: var(--coral-d); }
.lead select[data-s="contacted"] { background: #FFF8E6; border-color: #F1D79A; }
.lead select[data-s="converted"] { background: #E7F6EE; border-color: #B5E0C7; color: var(--ok); }
.lead select[data-s="rejected"] { background: #F2F2F2; color: var(--muted); }
.lead .notes { grid-column: 1 / -1; width: 100%; border: 1px dashed var(--line); border-radius: 10px; padding: 6px 12px; background: var(--bg); font-size: 14px; min-height: 36px; resize: vertical; }
.lead .notes:focus { outline: none; border-style: solid; border-color: var(--teal); background: #fff; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 4px 12px; border-radius: 99px; }
.badge.ok { background: #E7F6EE; color: var(--ok); }
.empty { text-align: center; padding: 50px 16px; color: var(--muted); background: #fff; border-radius: 20px; box-shadow: inset 0 0 0 1px var(--line); }

/* شبكة المتاجر */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.store { background: #fff; border-radius: 22px; overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); display: flex; flex-direction: column; transition: transform .25s var(--ease), box-shadow .25s; animation: in .3s var(--ease); }
.store:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.store.paused { opacity: .7; }
.st-hero { height: 110px; position: relative; display: grid; place-items: center; }
.st-hero .lg { width: 64px; height: 64px; border-radius: 16px; background: #fff; display: grid; place-items: center; overflow: hidden; box-shadow: 0 6px 16px -8px rgba(0,0,0,.35); font-weight: 700; font-size: 26px; }
.st-hero .lg img { width: 100%; height: 100%; object-fit: contain; }
.st-sw { position: absolute; bottom: 10px; inset-inline-start: 12px; display: flex; gap: 4px; }
.st-sw i { width: 16px; height: 16px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255,255,255,.9); }
.st-body { padding: 14px 16px 16px; display: grid; gap: 4px; flex: 1; }
.st-body h3 { font-size: 17px; }
.st-body code { font-size: 12px; color: var(--muted); direction: ltr; unicode-bidi: isolate; }
.st-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 16px 16px; }

/* المفتاح */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; }
.switch i { width: 44px; height: 26px; border-radius: 99px; background: #D5CEC9; position: relative; transition: background .2s; flex: none; }
.switch i::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: inset-inline-start .2s var(--ease); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + i { background: var(--teal); }
.switch input:checked + i::after { inset-inline-start: 21px; }
.switch input:focus-visible + i { outline: 3px solid var(--teal); outline-offset: 2px; }
.switch span { font-size: 14px; }

/* النوافذ */
.modal { border: 0; padding: 0; border-radius: 24px; background: #fff; color: var(--ink); box-shadow: 0 40px 100px -30px rgba(0,0,0,.5); width: min(1100px, 100% - 24px); max-height: calc(100vh - 24px); }
.modal[open] { display: flex; flex-direction: column; animation: rise .3s var(--ease); }
.modal.small { width: min(460px, 100% - 24px); }
.modal form[method="dialog"] { display: flex; flex-direction: column; min-height: 0; }
.modal::backdrop { background: rgba(29,38,38,.45); backdrop-filter: blur(3px); }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
.m-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.m-head h2 { font-size: 20px; }
.m-body { padding: 18px 22px; display: grid; gap: 12px; overflow: auto; }
.m-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); }
.m-foot .msg { margin-inline-end: auto; }
.x { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--bg); cursor: pointer; }
.f { display: grid; gap: 4px; font-size: 14px; font-weight: 600; }
.f em { font-style: normal; color: var(--muted); font-weight: 400; font-size: 12px; }
.f input:not([type=range]), .f select { min-height: 44px; border-radius: 12px; border: 1.5px solid var(--line); padding: 6px 12px; background: var(--bg); font-weight: 400; width: 100%; min-width: 0; }
.f input:focus, .f select:focus { outline: none; border-color: var(--teal); background: #fff; }
.f input[type=range] { accent-color: var(--coral); min-height: 44px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* المحرر */
.ed { display: grid; grid-template-columns: 1fr 360px; min-height: 0; overflow: hidden; flex: 1; }
.ed-form { overflow: auto; padding: 8px 22px 22px; display: grid; gap: 6px; align-content: start; }
fieldset { border: 0; padding: 14px 0; margin: 0; display: grid; gap: 12px; border-bottom: 1px solid var(--line); min-width: 0; }
fieldset:last-child { border-bottom: 0; }
legend { font-family: "Readex Pro", sans-serif; font-weight: 600; font-size: 15px; padding: 0; margin-bottom: 4px; color: var(--teal-d); }
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.preset { border: 0; background: #fff; box-shadow: inset 0 0 0 1px var(--line); border-radius: 14px; padding: 8px 12px 8px 10px; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; font-weight: 600; transition: box-shadow .2s, transform .15s; }
.preset:hover { box-shadow: inset 0 0 0 1.5px var(--teal); transform: translateY(-1px); }
.preset .dots { display: flex; }
.preset .dots i { width: 16px; height: 16px; border-radius: 50%; margin-inline-start: -5px; box-shadow: 0 0 0 2px #fff; }
.preset .dots i:first-child { margin-inline-start: 0; }
.from-logo { background: linear-gradient(135deg, #FFF1EC, #E1F4F4); border-radius: 16px; padding: 12px; display: grid; gap: 8px; animation: in .35s var(--ease); }
.fl-title { font-weight: 700; font-size: 13px; color: var(--teal-d); }
.from-logo .preset { background: #fff; }
.preset.on { box-shadow: inset 0 0 0 2px var(--coral); }
.colors { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.clr { display: flex; align-items: center; gap: 10px; background: var(--bg); border-radius: 14px; padding: 8px; cursor: pointer; font-size: 14px; font-weight: 600; }
.clr input { width: 40px; height: 40px; border: 0; padding: 0; border-radius: 10px; background: none; cursor: pointer; flex: none; }
.clr input::-webkit-color-swatch-wrapper { padding: 0; }
.clr input::-webkit-color-swatch { border: 0; border-radius: 10px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.clr small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.warn { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 8px 12px; font-size: 13px; }
.logo-up { display: flex; gap: 14px; align-items: center; }
.logo-box { width: 84px; height: 84px; border-radius: 18px; border: 2px dashed var(--line); display: grid; place-items: center; overflow: hidden; flex: none; background: var(--bg); }
.logo-box span { font-size: 11px; color: var(--muted); }
.logo-box img { width: 100%; height: 100%; object-fit: contain; }
.file { position: relative; overflow: hidden; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* المعاينة */
.ed-preview { background: var(--bg); border-inline-start: 1px solid var(--line); padding: 18px; display: grid; gap: 12px; align-content: start; justify-items: center; overflow: auto; }
.ed-preview code { font-size: 11px; word-break: break-all; }
.pv-toggle { display: inline-flex; background: #fff; border-radius: 12px; padding: 3px; box-shadow: inset 0 0 0 1px var(--line); }
.pv-toggle button { border: 0; background: none; padding: 6px 14px; border-radius: 9px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.pv-toggle button.on { background: var(--ink); color: #fff; }
.pv-phone { width: 290px; background: #1D2626; border-radius: 40px; padding: 10px; box-shadow: 0 30px 60px -30px rgba(0,0,0,.5); }
.pv {
  --p: #E76043; --a: #27A5A5; --bg: #FBF7F5; --sf: #fff; --tx: #1D2626; --r: 22px; --on-p: #fff;
  background: var(--bg); color: var(--tx); border-radius: 32px; min-height: 540px; padding: 36px 16px 18px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; transition: background .3s, color .3s;
}
.pv-logo { width: 64px; height: 64px; border-radius: calc(var(--r) * .6); display: grid; place-items: center; overflow: hidden; background: var(--sf); font-weight: 700; font-size: 26px; color: var(--p); box-shadow: 0 4px 14px -6px rgba(0,0,0,.25); }
.pv-logo img { width: 100%; height: 100%; object-fit: contain; }
.pv-store { font-weight: 700; font-size: 15px; }
.pv-welcome { font-size: 13px; opacity: .75; min-height: 1em; }
.pv-card { width: 100%; background: var(--sf); border-radius: var(--r); padding: 20px 14px; display: grid; justify-items: center; gap: 4px; margin-top: 6px; box-shadow: 0 6px 20px -12px rgba(0,0,0,.3); }
.pv-ring { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--a) 16%, transparent); margin-bottom: 6px; }
.pv-ring span { width: 28px; height: 28px; border-radius: 50%; border: 4px solid var(--a); border-top-color: transparent; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pv[data-state="ready"] .pv-ring { background: color-mix(in srgb, var(--p) 16%, transparent); }
.pv[data-state="ready"] .pv-ring span { animation: none; border: 0; width: 28px; height: 15px; border-radius: 0; border-bottom: 5px solid var(--p); border-left: 5px solid var(--p); transform: rotate(-45deg) translate(-2px, -2px); }
.pv-title { font-weight: 700; font-size: 18px; }
.pv[data-state="ready"] .pv-title { color: var(--p); }
.pv-sub { font-size: 12px; opacity: .7; }
.pv[data-state="prep"] .pv-ready, .pv[data-state="ready"] .pv-prep { display: none; }
.pv-bar { width: 100%; height: 7px; border-radius: 99px; background: color-mix(in srgb, var(--a) 16%, transparent); margin-top: 10px; overflow: hidden; }
.pv-bar i { display: block; height: 100%; width: 55%; background: var(--a); border-radius: inherit; }
.pv[data-state="ready"] .pv-bar i { width: 100%; background: var(--p); }
.pv-items { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.pv-items span { font-size: 11px; background: var(--sf); border-radius: 99px; padding: 2px 10px; }
.pv-game { display: flex; align-items: center; gap: 3px; background: var(--sf); border-radius: var(--r); padding: 10px 14px; width: 100%; justify-content: center; direction: ltr; }
.pv-game i { width: 12px; height: 12px; border-radius: 4px; background: var(--a); }
.pv-game b { width: 12px; height: 12px; border-radius: 50%; background: var(--p); margin-left: 10px; }
.pv-game small { direction: rtl; margin-left: 12px; font-size: 11px; opacity: .75; }
.pv[data-state="ready"] .pv-game { display: none; }
.pv-btn { margin-top: auto; width: 100%; min-height: 46px; border: 0; border-radius: calc(var(--r) * .7); background: var(--p); color: var(--on-p); font-weight: 700; opacity: .35; }
.pv[data-state="ready"] .pv-btn { opacity: 1; }

/* الاشتراك */
.s-warn { background: var(--warn-bg); box-shadow: inset 0 0 0 1px #F1D79A; }
.s-warn span { color: var(--warn); }
.sub-quick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sub-note { font-size: 13px; color: var(--muted); }
.sub-note:empty { display: none; }
.sub { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; width: fit-content; }
.sub.active { background: #E7F6EE; color: var(--ok); }
.sub.expiring { background: var(--warn-bg); color: var(--warn); }
.sub.expired { background: #FDE8E6; color: #B3261E; }
.sub.upcoming { background: var(--mint); color: var(--teal-d); }
.sub.none { background: #F2F2F2; color: var(--muted); }
.store.sub-expired { box-shadow: inset 0 0 0 2px #F3B7AE; }
.store.sub-expiring { box-shadow: inset 0 0 0 2px #F1D79A; }

/* وضع التاجر ووضع الأدمن */
body.mode-store .admin-only, body.mode-admin .store-only { display: none !important; }
.store-hello { background: linear-gradient(135deg, var(--coral-50), var(--mint)); border-radius: 22px; padding: 22px 24px; margin-bottom: 18px; display: grid; gap: 6px; }
.store-hello h2 { font-size: 22px; }
body.mode-store .grid { grid-template-columns: minmax(0, 420px); }
body.mode-store .st-body code, body.mode-store .st-body .hint { display: none; }
body.mode-store .sub { font-size: 13px; padding: 5px 12px; }
.st-status { font-size: 13px; font-weight: 600; color: var(--ok); }
.acc-box { background: var(--bg); border-radius: 16px; padding: 14px; display: grid; gap: 6px; }
.acc-box small { color: var(--muted); font-size: 12px; }
.acc-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.acc-row code { font-size: 14px; word-break: break-all; }
.acc-code { font-size: 22px !important; font-weight: 700; letter-spacing: 2px; color: var(--teal-d); }

/* إشعار */
.toast { position: fixed; bottom: 20px; left: 50%; translate: -50% 20px; background: var(--ink); color: #fff; padding: 10px 20px; border-radius: 12px; opacity: 0; pointer-events: none; transition: opacity .25s, translate .25s var(--ease); z-index: 100; font-weight: 600; }
.toast.show { opacity: 1; translate: -50% 0; }
.toast.err { background: #B3361E; }

@media (max-width: 900px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .lead { grid-template-columns: 1fr 1fr; }
  .lead .act { grid-column: 1 / -1; }
  .ed { grid-template-columns: 1fr; overflow: auto; }
  .ed-form { overflow: visible; }
  .ed-preview { border-inline-start: 0; border-top: 1px solid var(--line); order: -1; }
  .modal.editor { max-height: calc(100vh - 12px); width: calc(100% - 12px); }
}
@media (max-width: 520px) {
  .lead { grid-template-columns: 1fr; }
  .row2 { grid-template-columns: 1fr; }
  .top h1 { font-size: 16px; }
  .search { min-width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
