/* ==========================================================
   نظام تخصيص المطويات — التنسيقات العامة
   ========================================================== */
:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --ink: #1c1917;
  --ink-2: #44403c;
  --muted: #78716c;
  --line: #e7e5e4;
  --line-2: #d6d3d1;
  --primary: #0f766e;
  --primary-2: #115e59;
  --primary-soft: #e6f4f2;
  --accent: #ea580c;
  --accent-soft: #fff1e7;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --success: #15803d;
  --success-soft: #e8f6ec;
  --warn: #a16207;
  --warn-soft: #fef6dc;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(28, 25, 23, .06), 0 4px 16px rgba(28, 25, 23, .06);
  --shadow-lg: 0 10px 40px rgba(28, 25, 23, .14);
  --font: "fz-tajawal", "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
small, .muted { color: var(--muted); }
code, .mono { font-family: ui-monospace, Consolas, monospace; direction: ltr; unicode-bidi: embed; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 700; font-size: .95rem;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none !important; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); border-color: #a8a29e; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #c2410c; border-color: #c2410c; }
.btn-danger { color: var(--danger); border-color: #f1c6c6; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,.04); border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: .85rem; }
.btn-lg { padding: 13px 22px; font-size: 1.05rem; border-radius: 12px; }
.btn-block { width: 100%; }
.btn svg { width: 18px; height: 18px; flex: none; }

/* ---------- النماذج ---------- */
label { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 5px; color: var(--ink-2); }
.input, input[type=text], input[type=password], input[type=number], input[type=tel], select, textarea {
  width: 100%; font: inherit; font-size: .95rem;
  padding: 9px 12px; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .15);
}
input[type=file] { font: inherit; font-size: .9rem; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); vertical-align: middle; }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 14px; }
.field .hint { font-size: .82rem; color: var(--muted); margin-top: 4px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.check { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; cursor: pointer; margin: 0; }
.ltr { direction: ltr; text-align: left; }

/* ---------- البطاقات والتنبيهات ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }

.alert { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; border: 1px solid; font-size: .93rem; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: #f3c4c4; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: #bfe3ca; }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: #f1dea0; }
.alert-info { background: var(--primary-soft); color: var(--primary-2); border-color: #bfe0dc; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-amber { background: var(--warn-soft); color: var(--warn); }
.badge-gray { background: #f0eeeb; color: var(--muted); }
.badge-teal { background: var(--primary-soft); color: var(--primary-2); }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: 11px 10px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .8rem; color: var(--muted); font-weight: 700; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ==========================================================
   لوحة المدير
   ========================================================== */
.admin-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  background: #1c1917; color: #fff;
  display: flex; align-items: center; gap: 22px; padding: 0 22px; height: 58px;
  position: sticky; top: 0; z-index: 50;
}
.topbar .brand { font-weight: 800; font-size: 1.05rem; color: #fff; display: flex; align-items: center; gap: 9px; }
.topbar .brand .dot { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; font-size: .8rem; }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { color: #d6d3d1; padding: 7px 12px; border-radius: 8px; font-weight: 700; font-size: .92rem; white-space: nowrap; }
.topbar nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.topbar nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.topbar .user { color: #a8a29e; font-size: .88rem; white-space: nowrap; }
.topbar .user a { color: #fdba74; }
.admin-main { width: 100%; max-width: 1240px; margin: 0 auto; padding: 24px 20px 60px; flex: 1; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: .92rem; margin-top: 2px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 1.6rem; font-weight: 800; line-height: 1.2; }
.stat .l { color: var(--muted); font-size: .85rem; }

.thumb { width: 92px; aspect-ratio: 1.41; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: #eee; display: block; }
.thumb-empty { width: 92px; aspect-ratio: 1.41; border-radius: 6px; border: 1px dashed var(--line-2); display: grid; place-items: center; color: var(--muted); font-size: .75rem; }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 2.4rem; margin-bottom: 6px; }

/* شاشة الدخول والتثبيت */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .logo { text-align: center; margin-bottom: 18px; }
.auth-card .logo .mark { width: 54px; height: 54px; margin: 0 auto 8px; border-radius: 16px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.3rem; }

/* ==========================================================
   منطقة العرض (Stage) — مشتركة بين المصمم والعميل
   ========================================================== */
.stage-wrap { position: relative; }
.stage {
  position: relative; overflow: hidden; background: #e7e5e4;
  border-radius: 10px; box-shadow: var(--shadow); user-select: none; -webkit-user-select: none;
  touch-action: pan-y;
}
.stage .page { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.stage .page img { display: block; width: 100%; height: 100%; pointer-events: none; -webkit-user-drag: none; }
.stage .watermark {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.stage .watermark span {
  transform: rotate(-24deg); font-weight: 800; font-size: 9vw; color: rgba(0,0,0,.06);
  white-space: nowrap; letter-spacing: 2px;
}
.zone {
  position: absolute; outline: 2px dashed rgba(234, 88, 12, .85); outline-offset: 0;
  background: rgba(234, 88, 12, .04);
}
.zone.subtle { outline: 1.5px dashed rgba(15, 118, 110, .55); background: transparent; }
.zone .zone-label {
  position: absolute; top: -24px; right: -2px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px 6px 0 0; white-space: nowrap;
  pointer-events: none;
}
.zone .zone-move {
  position: absolute; top: -24px; left: -2px; height: 22px; padding: 0 8px; border-radius: 6px 6px 0 0;
  background: #1c1917; color: #fff; font-size: 11px; display: flex; align-items: center; gap: 4px; cursor: move; touch-action: none;
}
.handle {
  position: absolute; width: 14px; height: 14px; background: #fff; border: 2px solid var(--accent);
  border-radius: 4px; z-index: 5; touch-action: none;
}
.handle.nw { top: -8px; left: -8px; cursor: nwse-resize; }
.handle.ne { top: -8px; right: -8px; cursor: nesw-resize; }
.handle.sw { bottom: -8px; left: -8px; cursor: nesw-resize; }
.handle.se { bottom: -8px; right: -8px; cursor: nwse-resize; }

.item {
  position: absolute; white-space: nowrap; direction: rtl; cursor: grab; touch-action: none;
  line-height: 1.5; padding: 0; margin: 0;
}
.item:hover { outline: 1px dashed rgba(15, 118, 110, .7); }
.item.selected { outline: 1.5px solid var(--primary); background: rgba(15, 118, 110, .06); }
.item.dragging { cursor: grabbing; }
.item.hidden-item { opacity: .28; }
.item .rs {
  display: none; position: absolute; bottom: -9px; left: -9px; width: 18px; height: 18px;
  background: var(--primary); border: 2px solid #fff; border-radius: 50%;
  cursor: nesw-resize; box-shadow: 0 1px 4px rgba(0,0,0,.3); touch-action: none;
}
.item.selected .rs { display: block; }
.stage.drawing { cursor: crosshair; }
.draw-rect { position: absolute; outline: 2px dashed var(--accent); background: rgba(234,88,12,.08); pointer-events: none; }

/* ==========================================================
   صفحة المصمم (المدير)
   ========================================================== */
.designer { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.designer .side { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow: auto; }
.page-tabs { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.page-tabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.field-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: var(--surface-2); }
.field-card.selected { border-color: var(--primary); background: var(--primary-soft); }
.field-card .fc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.field-card .fc-head .key { font-size: .75rem; color: var(--muted); direction: ltr; }
.field-card .fc-head .grow { flex: 1; }
.field-card input[type=text] { padding: 6px 9px; font-size: .88rem; }
.field-card .mini-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.field-card .mini-row label { font-size: .75rem; margin-bottom: 2px; }
.style-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.style-row select { width: auto; padding: 5px 8px; font-size: .85rem; }
.style-row input[type=number] { width: 70px; padding: 5px 8px; font-size: .85rem; }
.swatches { display: flex; gap: 5px; flex-wrap: wrap; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line-2); cursor: pointer; padding: 0; }
.swatch.active { box-shadow: 0 0 0 2px var(--ink); }
.toggle-b { font-weight: 800; min-width: 34px; }
.toggle-b.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.zone-inputs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.zone-inputs label { font-size: .72rem; margin-bottom: 2px; }
.zone-inputs input { padding: 5px 6px; font-size: .85rem; direction: ltr; text-align: center; }
.savebar { display: flex; gap: 8px; flex-wrap: wrap; }
.loading-cover { position: fixed; inset: 0; background: rgba(245,243,239,.85); display: none; place-items: center; z-index: 200; }
.loading-cover.show { display: grid; }
.loading-cover .box { background: #fff; padding: 22px 28px; border-radius: 14px; box-shadow: var(--shadow-lg); text-align: center; min-width: 260px; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1c1917; color: #fff; padding: 11px 18px; border-radius: 10px; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 300; font-weight: 700; max-width: 92vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

@media (max-width: 960px) {
  .designer { grid-template-columns: 1fr; }
  .designer .side { position: static; max-height: none; }
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar .user span { display: none; }
}

/* اختيار طريقة العرض */
.layout-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lp { margin: 0; cursor: pointer; font-weight: 700; font-size: .85rem; }
.lp input { position: absolute; opacity: 0; pointer-events: none; }
.lp-box { display: block; border: 2px solid var(--line); border-radius: 10px; padding: 8px; text-align: center; background: #fff; transition: border-color .15s; }
.lp input:checked + .lp-box { border-color: var(--primary); background: var(--primary-soft); }
.lp-demo { display: flex; flex-direction: column; align-items: center; gap: 0; margin-bottom: 6px; padding: 6px; border: 1px dashed var(--line-2); border-radius: 6px; background: #fff; font-size: .7rem; line-height: 1.35; }
.lp-demo b { color: var(--accent); }
.lp-demo i, .lp-demo em { font-style: normal; color: var(--muted); letter-spacing: 1px; }
.lp-demo em { color: var(--ink-2); letter-spacing: 0; }
.style-title { font-size: .75rem; color: var(--muted); font-weight: 700; margin: 8px 0 4px; }

/* ==========================================================
   صفحة العميل
   ========================================================== */
.c-shell { min-height: 100vh; display: flex; flex-direction: column; }
.c-header {
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 12px 18px; display: flex; align-items: center; gap: 12px; justify-content: space-between;
}
.c-header .store { font-weight: 800; display: flex; align-items: center; gap: 9px; }
.c-header .store .dot { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: .8rem; }
.c-main { width: 100%; max-width: 1180px; margin: 0 auto; padding: 18px 16px 120px; flex: 1; }
.c-footer { text-align: center; color: var(--muted); font-size: .82rem; padding: 18px; }

.c-entry { max-width: 440px; margin: 6vh auto 0; }
.c-entry .hero { text-align: center; margin-bottom: 18px; }
.c-entry .hero .icon { width: 64px; height: 64px; border-radius: 18px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin: 0 auto 12px; }
.c-entry .hero .icon svg { width: 32px; height: 32px; }
.c-entry .hero h1 { font-size: 1.45rem; margin-bottom: 4px; }

.c-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.c-title h1 { font-size: 1.25rem; margin: 0; }
.c-title .meta { color: var(--muted); font-size: .86rem; }
.timer-pill { display: inline-flex; align-items: center; gap: 7px; background: var(--warn-soft); color: var(--warn); border: 1px solid #f1dea0; padding: 6px 12px; border-radius: 99px; font-weight: 700; font-size: .85rem; }
.timer-pill svg { width: 16px; height: 16px; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.editor .panel { position: sticky; top: 14px; }
.view-switch { display: flex; gap: 6px; margin-bottom: 10px; }
.view-switch .btn.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.gender-switch { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.gender-switch button { font: inherit; font-weight: 700; border: 0; background: transparent; padding: 8px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.gender-switch button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

.c-field { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; background: #fff; transition: border-color .15s, background .15s; }
.c-field.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.c-field.off { background: var(--surface-2); }
.c-field.off .c-inputs { display: none; }
.c-field .c-top { display: flex; align-items: center; gap: 8px; }
.c-field .c-top .label-edit { flex: 1; border: 1px dashed transparent; padding: 3px 6px; font-weight: 700; font-size: .9rem; background: transparent; border-radius: 6px; }
.c-field .c-top .label-edit:hover { border-color: var(--line-2); }
.c-field .c-top .label-edit:focus { border-style: solid; background: #fff; }
.c-field .c-inputs { margin-top: 8px; }
.c-field .c-inputs input { font-size: 1rem; padding: 10px 12px; }
.c-field .hint-label { font-size: .74rem; color: var(--muted); margin-top: 3px; }

.style-box { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 6px; }
.style-box h3 { font-size: .92rem; margin-bottom: 8px; }
.style-box .sb-row { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; flex-wrap: wrap; }
.style-box .sb-row > label { margin: 0; min-width: 44px; font-size: .82rem; }
.style-box select { width: auto; flex: 1; padding: 6px 8px; font-size: .9rem; }
.size-ctl { display: flex; align-items: center; gap: 6px; flex: 1; }
.size-ctl input[type=range] { flex: 1; accent-color: var(--primary); }
.size-ctl .btn { padding: 3px 10px; font-size: 1rem; }

.stage-hint { font-size: .82rem; color: var(--muted); margin-top: 8px; text-align: center; }

.c-actions {
  position: fixed; bottom: 0; left: 0; right: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(6px);
  border-top: 1px solid var(--line); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); z-index: 60;
}
.c-actions .inner { max-width: 1180px; margin: 0 auto; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.c-actions .status { font-size: .85rem; color: var(--muted); }
.c-actions .status.saved { color: var(--success); }

.state-card { max-width: 520px; margin: 7vh auto 0; text-align: center; }
.state-card .icon { width: 70px; height: 70px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 14px; }
.state-card .icon svg { width: 34px; height: 34px; }
.state-card .icon.warn { background: var(--warn-soft); color: var(--warn); }
.state-card .icon.red { background: var(--danger-soft); color: var(--danger); }
.state-card .icon.ok { background: var(--success-soft); color: var(--success); }
.state-card .msg { font-size: 1.1rem; font-weight: 700; margin-bottom: 10px; }
.state-card .phone { display: inline-block; direction: ltr; font-weight: 800; font-size: 1.15rem; color: var(--primary); margin: 4px 0 12px; }

@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; }
  .editor .panel { position: static; }
  .c-main { padding: 12px 10px 130px; }
  .c-title h1 { font-size: 1.1rem; }
}

/* ==========================================================
   محرر العميل بأسلوب كانفا (Flow)
   ========================================================== */
.flow-wrap { max-width: 920px; margin: 0 auto; }
.flow-stage .zone.subtle { outline: 1.5px dashed rgba(15, 118, 110, .45); }
.flow-stage .flow {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: space-evenly; box-sizing: border-box;
}
.flow-stage .g {
  position: relative; display: flex; flex-direction: column; align-items: center;
  cursor: pointer; touch-action: none; border-radius: 4px; max-width: 100%;
  -webkit-tap-highlight-color: transparent;
}
.flow-stage .g.inline { flex-direction: row; align-items: baseline; direction: rtl; }
.flow-stage .g.inline .lbl { margin-left: .3em; }
.flow-stage .el {
  white-space: nowrap; line-height: 1.5; direction: rtl; outline: none; min-width: .4em;
  border-radius: 3px; -webkit-user-select: none; user-select: none;
}
.flow-stage .el:empty::before { content: attr(data-ph); opacity: .4; }
.flow-stage .g:hover { outline: 1px dashed rgba(15, 118, 110, .55); outline-offset: 2px; }
.flow-stage .g.sel, .flow-stage .g.in { outline: 2px solid var(--primary); outline-offset: 3px; }
.flow-stage .g.in:not(.sel) { outline-style: dashed; outline-width: 1.5px; }
.flow-stage .el.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.flow-stage .el.editing {
  outline: 2px solid var(--accent); background: rgba(255, 255, 255, .7); cursor: text;
  caret-color: var(--accent); -webkit-user-select: text; user-select: text;
}
.flow-stage .g .rs {
  display: none; position: absolute; bottom: -12px; left: -12px; width: 22px; height: 22px;
  background: var(--primary); border: 3px solid #fff; border-radius: 50%;
  cursor: nesw-resize; box-shadow: 0 1px 5px rgba(0,0,0,.35); touch-action: none; z-index: 3;
}
.flow-stage .g.sel .rs { display: block; }
.flow-stage .g.dragging { opacity: .85; z-index: 10; outline: 2px solid var(--accent); transition: none; }

/* الشريط السفلي */
.c-bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 0 10px calc(10px + env(safe-area-inset-bottom)); pointer-events: none;
}
.c-bottom > * { pointer-events: auto; }
.tbar {
  display: flex; gap: 2px; background: #fff; border-radius: 18px; padding: 6px;
  box-shadow: 0 6px 28px rgba(28, 25, 23, .16), 0 0 0 1px rgba(28,25,23,.06);
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.tbar::-webkit-scrollbar { display: none; }
.tb {
  flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 60px; padding: 7px 8px 6px; border: 0; background: transparent; border-radius: 12px;
  font: inherit; font-size: .74rem; font-weight: 700; color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.tb:hover { background: var(--surface-2); }
.tb:disabled { opacity: .35; cursor: default; }
.tb.on { background: var(--primary-soft); color: var(--primary-2); }
.tb svg { width: 22px; height: 22px; }
.tb .dot { width: 22px; height: 22px; border-radius: 50%; box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--line-2); }
.tb .big { font-size: 1.15rem; line-height: 22px; font-weight: 800; }
.tb.danger { color: var(--danger); }
.tb-sep { width: 1px; background: var(--line); margin: 6px 3px; flex: none; }
.tb-title { align-self: center; padding: 0 8px; font-size: .75rem; color: var(--muted); font-weight: 700; white-space: nowrap; flex: none; }

.sheet {
  width: min(560px, 100%); background: #fff; border-radius: 16px; padding: 12px;
  box-shadow: 0 6px 28px rgba(28, 25, 23, .16), 0 0 0 1px rgba(28,25,23,.06);
}
.sheet[hidden] { display: none; }
.sheet .sh-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 800; font-size: .9rem; }
.sheet .fonts { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
.sheet .fonts button { font-size: 1.05rem; padding: 8px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.sheet .fonts button.active { border-color: var(--primary); background: var(--primary-soft); }
.sheet .swatches { justify-content: center; gap: 9px; }
.sheet .swatch { width: 32px; height: 32px; }
.sheet .size-row { display: flex; align-items: center; gap: 10px; }
.sheet .size-row input[type=range] { flex: 1; accent-color: var(--primary); }
.sheet .size-row .val { min-width: 44px; text-align: center; font-weight: 800; }
.sheet .add-list { display: grid; gap: 6px; }
.sheet .add-list button { text-align: right; justify-content: flex-start; }

.c-actions-row {
  width: min(920px, 100%); display: flex; gap: 10px; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,.96); backdrop-filter: blur(6px); border-radius: 14px; padding: 8px 10px 8px 14px;
  box-shadow: 0 2px 12px rgba(28,25,23,.08), 0 0 0 1px rgba(28,25,23,.05);
}
.c-actions-row .status { font-size: .82rem; color: var(--muted); }
.c-actions-row .status.saved { color: var(--success); }
.flow-hint { font-size: .8rem; color: var(--muted); text-align: center; margin: 8px 0 0; }
.c-main.has-bottom { padding-bottom: 210px; }

/* أثناء الكتابة على الجوال: نخفي شريط التنزيل لتوفير المساحة فوق الكيبورد */
body.typing .c-actions-row, body.typing .flow-hint { display: none; }
.c-bottom { transition: transform .12s ease-out; }

/* أسهم تدل على وجود أدوات إضافية في الشريط */
.tbar-wrap { position: relative; max-width: 100%; display: flex; }
.tbar-wrap .tbar { scroll-behavior: smooth; }
.tb-arrow {
  position: absolute; top: 4px; bottom: 4px; width: 46px; z-index: 2; border: 0; cursor: pointer; padding: 0;
  display: none; align-items: center;
}
.tb-arrow span {
  width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff;
  display: grid; place-items: center; box-shadow: 0 2px 8px rgba(15,118,110,.35);
}
.tb-arrow svg { width: 16px; height: 16px; }
.tb-arrow.right { right: 4px; justify-content: flex-start; padding-right: 2px; border-radius: 0 14px 14px 0; background: linear-gradient(to left, #fff 45%, rgba(255,255,255,0)); }
.tb-arrow.left { left: 4px; justify-content: flex-end; flex-direction: row-reverse; padding-left: 2px; border-radius: 14px 0 0 14px; background: linear-gradient(to right, #fff 45%, rgba(255,255,255,0)); }
.tbar-wrap.can-right .tb-arrow.right, .tbar-wrap.can-left .tb-arrow.left { display: flex; }
.tbar-wrap.can-left .tb-arrow.left span { animation: tb-nudge 1.2s ease-in-out 3; }
@keyframes tb-nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(-5px); } }

/* زر ✓ ثابت بجانب شريط الأدوات */
.tbar-row { display: flex; align-items: center; gap: 8px; max-width: 100%; }
.tbar-row .tbar-wrap { min-width: 0; flex: 0 1 auto; }
.tb-done {
  flex: none; width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer;
  background: #fff; color: var(--primary); display: grid; place-items: center;
  box-shadow: 0 6px 28px rgba(28, 25, 23, .16), 0 0 0 1px rgba(28,25,23,.06);
}
.tb-done svg { width: 26px; height: 26px; }
.tb-done:active { transform: scale(.94); }
.tb-done.active { background: var(--primary); color: #fff; }

/* ==========================================================
   صفحة العميل: الوضع المبسط / المتقدم
   ========================================================== */
.c-welcome { max-width: 1100px; margin: 0 auto 12px; }
.mode-tabs {
  max-width: 1100px; margin: 0 auto 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 4px;
}
.mode-tabs button {
  font: inherit; font-weight: 800; font-size: .95rem; border: 0; background: transparent; color: var(--muted);
  padding: 10px 8px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.mode-tabs button svg { width: 18px; height: 18px; }
.mode-tabs button[aria-selected="true"] { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(15,118,110,.25); }

.c-editor { max-width: 1100px; margin: 0 auto; }
.simple-panel { display: none; }

body.mode-simple .c-editor { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
body.mode-simple .flow-wrap { max-width: none; margin: 0; }
body.mode-simple .simple-panel { display: block; position: sticky; top: 14px; }
body.mode-simple .flow-hint, body.mode-simple .tbar-row, body.mode-simple #sheet { display: none !important; }
body.mode-simple .flow-stage .g { pointer-events: none; }
body.mode-simple .flow-stage .g, body.mode-simple .flow-stage .el { outline: none !important; }
body.mode-simple .flow-stage .g .rs { display: none !important; }
body.mode-advanced .flow-wrap { max-width: 920px; }

.simple-panel {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px;
}
.simple-panel .gender-switch { margin-bottom: 12px; }
.sf { border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 12px 12px; margin-bottom: 10px; background: #fff; transition: border-color .15s, background .15s; }
.sf:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.sf.off { background: var(--surface-2); }
.sf.off .sf-label, .sf.off .sf-value { opacity: .55; }
.sf-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sf-head input[type=checkbox] { width: 22px; height: 22px; flex: none; cursor: pointer; }
.sf input.sf-label {
  flex: 1; min-width: 0; border: 1px dashed transparent !important; background: transparent !important; box-shadow: none !important;
  font: inherit; font-weight: 800; font-size: 1rem; color: var(--primary-2); padding: 3px 6px !important; border-radius: 8px;
}
.sf input.sf-label:focus { border-color: var(--line-2) !important; background: #fff !important; }
.sf input.sf-label::placeholder { color: var(--muted); font-weight: 500; }
.sf-icon { flex: none; width: 32px; height: 32px; border: 0; border-radius: 8px; background: var(--surface-2); color: var(--ink-2); cursor: pointer; display: grid; place-items: center; }
.sf-icon:hover { background: #ece9e5; }
.sf-icon svg { width: 17px; height: 17px; }
.sf-icon.danger { color: var(--danger); }
.sf input.sf-value { font-size: 1.05rem !important; font-weight: 700; padding: 11px 12px !important; text-align: center; }
.sf input.sf-value::placeholder { font-weight: 500; letter-spacing: 1px; }
.sf-add { border-style: dashed; color: var(--primary-2); }
.sf-note { font-size: .8rem; color: var(--muted); margin: 10px 2px 0; text-align: center; }

@media (max-width: 900px) {
  body.mode-simple .c-editor { grid-template-columns: 1fr; gap: 12px; }
  body.mode-simple .simple-panel { position: static; }
}

/* نقل الحقل لأعلى/لأسفل في الوضع المبسط */
.sf-move { display: inline-flex; gap: 4px; flex: none; }
.sf-icon:disabled { opacity: .3; cursor: default; }
.sf.moved { animation: sf-flash .6s ease-out; }
@keyframes sf-flash { 0% { background: var(--primary-soft); border-color: var(--primary); } 100% { background: #fff; } }

/* ألوان مستخرجة من المطوية في صفحة المدير */
.swatch.doc { border-radius: 8px; }
.sw-sep { width: 1px; height: 22px; background: var(--line-2); margin: 1px 3px; align-self: center; }
