/* ==========================================================================
   بطاقات — نظام التصميم المشترك
   ========================================================================== */

:root {
  --bg: #f6f2ec;
  --bg-deep: #efe8df;
  --surface: #ffffff;
  --surface-2: #fbf8f4;
  --ink: #221c26;
  --ink-soft: #4b4352;
  --muted: #7b7183;
  --line: #e7dfd5;
  --brand: #7c2d5b;
  --brand-dark: #5d1f44;
  --brand-soft: #f6e8f0;
  --gold: #c19a3d;
  --gold-soft: #f7efd9;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #1d7a4c;
  --ok-soft: #e6f5ec;
  --shadow-sm: 0 1px 2px rgba(34, 28, 38, .06), 0 6px 16px -10px rgba(34, 28, 38, .18);
  --shadow-md: 0 10px 30px -18px rgba(34, 28, 38, .35), 0 2px 6px rgba(34, 28, 38, .05);
  --shadow-lg: 0 30px 70px -40px rgba(34, 28, 38, .55), 0 8px 20px -12px rgba(34, 28, 38, .25);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;
  --font: "Tajawal", "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
  --mono: "Consolas", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.3; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

::selection { background: #e9c9dc; color: var(--brand-dark); }

/* ---------- عناصر عامة ---------- */

.wrap { width: min(1180px, calc(100% - 40px)); margin-inline: auto; }

.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  --btn-line: var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 18px;
  border: 1px solid var(--btn-line); border-radius: 12px;
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 600; font-size: 15px; white-space: nowrap;
  cursor: pointer; transition: transform .12s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); text-decoration: none; }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { --btn-bg: linear-gradient(135deg, var(--brand), #a2417a); --btn-fg: #fff; --btn-line: transparent; }
.btn-gold { --btn-bg: linear-gradient(135deg, #d3ac56, #b3892c); --btn-fg: #2a2113; --btn-line: transparent; }
.btn-dark { --btn-bg: #2b2230; --btn-fg: #fff; --btn-line: transparent; }
.btn-ghost { --btn-bg: transparent; --btn-line: var(--line); }
.btn-danger { --btn-bg: var(--danger-soft); --btn-fg: var(--danger); --btn-line: #f3cfca; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: 38px; min-height: 38px; border-radius: 10px; font-size: 17px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; color: var(--ink-soft);
  cursor: pointer; transition: .15s ease;
}
.chip:hover { border-color: #d8ccbf; background: #fffdfa; }
.chip[aria-pressed="true"], .chip.is-on { background: var(--brand); border-color: var(--brand); color: #fff; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: #c9e9d6; }
.badge-warn { background: var(--gold-soft); color: #8a6a17; border-color: #eddfb9; }
.badge-brand { background: var(--brand-soft); color: var(--brand); border-color: #ecd3e3; }

/* ---------- الحقول ---------- */

.field { display: grid; gap: 7px; margin-bottom: 16px; }
.label { font-size: 13.5px; font-weight: 700; color: var(--ink-soft); }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 11px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  font-size: 15px; outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.input:focus, .select:focus, .textarea:focus {
  border-color: #c095b1; box-shadow: 0 0 0 4px rgba(124, 45, 91, .1);
}
.input::placeholder, .textarea::placeholder { color: #a99fae; }
.field-row { display: flex; align-items: center; gap: 10px; }
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.error-text { font-size: 13px; color: var(--danger); font-weight: 600; }
.input-group { position: relative; }
.input-group .input { padding-inline-end: 46px; }
.input-group .peek {
  position: absolute; inset-inline-end: 6px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border: 0; border-radius: 9px; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 16px;
}
.input-group .peek:hover { background: var(--surface-2); color: var(--ink); }

.checkline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-soft); cursor: pointer; user-select: none; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }

/* ---------- التنبيهات المنبثقة ---------- */

#toasts {
  position: fixed; inset-block-start: 18px; inset-inline-start: 50%; transform: translateX(50%);
  display: grid; gap: 10px; z-index: 9000; width: min(420px, calc(100% - 32px));
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 13px 16px; border-radius: 14px;
  background: #241d29; color: #fff; box-shadow: var(--shadow-lg);
  font-size: 14px; line-height: 1.6; animation: toast-in .22s ease;
}
.toast .ico { flex: 0 0 auto; font-size: 16px; line-height: 1.5; }
.toast-ok { background: #123f2b; }
.toast-error { background: #4d1712; }
.toast-out { animation: toast-out .2s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px); } }

/* ---------- النوافذ ---------- */

.modal { position: fixed; inset: 0; z-index: 8000; display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(24, 18, 28, .55); backdrop-filter: blur(3px); }
.modal-card {
  position: relative; width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto;
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 26px; animation: pop .18s ease;
}
.modal-card.wide { width: min(760px, 100%); }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.985); } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 6px; }
.modal-head h3 { font-size: 20px; }
.modal-sub { color: var(--muted); font-size: 14px; margin-top: 6px; line-height: 1.7; }
.modal-close { border: 0; background: transparent; font-size: 22px; color: var(--muted); cursor: pointer; line-height: 1; padding: 4px; border-radius: 8px; }
.modal-close:hover { background: var(--surface-2); color: var(--ink); }
.modal-body { margin-top: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; flex-wrap: wrap; }

/* ==========================================================================
   صفحة الدخول
   ========================================================================== */

.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }

.auth-art {
  position: relative; overflow: hidden; padding: 54px;
  display: flex; flex-direction: column; justify-content: space-between;
  background:
    radial-gradient(900px 600px at 85% -10%, rgba(193, 154, 61, .38), transparent 62%),
    radial-gradient(700px 520px at 0% 100%, rgba(180, 83, 138, .45), transparent 60%),
    linear-gradient(160deg, #33122a 0%, #52203f 46%, #2a1023 100%);
  color: #fff;
}
.auth-art::before,
.auth-art::after {
  content: ""; position: absolute; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .16);
  pointer-events: none;
}
.auth-art::before { width: 520px; height: 520px; inset-block-start: -160px; inset-inline-start: -120px; }
.auth-art::after { width: 760px; height: 760px; inset-block-end: -420px; inset-inline-end: -180px; border-color: rgba(193, 154, 61, .3); }

.brand { display: inline-flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 46px; height: 46px; flex: 0 0 auto; display: grid; place-items: center;
  border-radius: 14px; color: #2b1a0c; font-weight: 800; font-size: 22px;
  background: linear-gradient(140deg, #edd49a, #c19a3d 70%);
  box-shadow: 0 10px 24px -12px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .6);
}
.brand-text { display: grid; gap: 1px; }
.brand-name { font-size: 20px; font-weight: 800; letter-spacing: 0; }
.brand-sub { font-size: 12px; color: rgba(255, 255, 255, .62); }

.auth-copy { position: relative; z-index: 1; max-width: 520px; }
.auth-copy .eyebrow {
  display: inline-flex; align-items: center; gap: 8px; margin-bottom: 18px;
  font-size: 13px; font-weight: 700; color: #f0d9a4;
  padding: 6px 14px; border-radius: 999px; background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .14);
}
.auth-copy h1 { font-size: clamp(30px, 3.4vw, 44px); line-height: 1.25; letter-spacing: -.02em; }
.auth-copy p { margin-top: 16px; font-size: 16.5px; line-height: 1.85; color: rgba(255, 255, 255, .76); }

.auth-feats { margin-top: 30px; display: grid; gap: 12px; }
.auth-feat { display: flex; align-items: flex-start; gap: 10px; font-size: 14.5px; color: rgba(255, 255, 255, .82); }
.auth-feat i {
  flex: 0 0 auto; width: 24px; height: 24px; display: grid; place-items: center;
  border-radius: 8px; background: rgba(255, 255, 255, .1); color: #f0d9a4; font-style: normal; font-size: 13px; font-weight: 700;
}

.auth-art-foot { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; color: rgba(255, 255, 255, .5); font-size: 12.5px; }

.auth-side { display: grid; place-items: center; padding: 40px 28px; background: var(--bg); }
.auth-card { width: min(420px, 100%); }
.auth-card .kicker { color: var(--gold); font-weight: 800; font-size: 13px; letter-spacing: 0; margin-bottom: 10px; }
.auth-card h2 { font-size: 30px; letter-spacing: -.02em; }
.auth-card .lede { color: var(--muted); margin-top: 10px; font-size: 15px; line-height: 1.7; }
.auth-form { margin-top: 26px; }
.auth-form .input { background: var(--surface); }
.auth-submit { margin-top: 6px; min-height: 48px; }
.auth-note {
  margin-top: 22px; padding: 14px 16px; border-radius: 14px;
  background: var(--surface); border: 1px dashed #ddd0c0;
  font-size: 13px; color: var(--ink-soft); line-height: 1.8;
}
.auth-note b { color: var(--ink); }
.auth-note code { font-family: var(--mono); background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: 12px; }
.auth-foot { margin-top: 20px; color: var(--muted); font-size: 12.5px; text-align: center; }
.form-error {
  display: none; margin-top: 4px; margin-bottom: 12px; padding: 10px 13px; border-radius: 10px;
  background: var(--danger-soft); color: var(--danger); font-size: 13.5px; font-weight: 600;
}
.form-error.is-on { display: block; }

@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 30px 24px 34px; gap: 26px; }
  .auth-feats { display: none; }
  .auth-art-foot { display: none; }
}

/* ==========================================================================
   هيكل التطبيق (لوحة التحكم)
   ========================================================================== */

.shell { min-height: 100vh; display: grid; grid-template-columns: 264px 1fr; }

.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 24px 18px;
  display: flex; flex-direction: column; gap: 22px;
  background: linear-gradient(175deg, #2c1226 0%, #3d1832 55%, #240f1f 100%);
  color: #fff;
}
.sidebar .brand { padding: 4px 6px; }
.sidebar .brand-sub { color: rgba(255, 255, 255, .5); }
.nav { display: grid; gap: 4px; }
.nav-label { font-size: 11.5px; font-weight: 700; color: rgba(255, 255, 255, .38); padding: 10px 12px 6px; letter-spacing: 0; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 13px; border-radius: 12px;
  color: rgba(255, 255, 255, .74); font-size: 14.5px; font-weight: 600;
  cursor: pointer; border: 0; background: transparent; width: 100%; text-align: start;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.nav-item.is-active { background: rgba(255, 255, 255, .12); color: #fff; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1); }
.nav-item .ico { width: 20px; text-align: center; font-size: 16px; opacity: .95; }
.nav-item .count { margin-inline-start: auto; font-size: 11.5px; font-weight: 700; color: rgba(255, 255, 255, .6); background: rgba(255, 255, 255, .08); padding: 2px 7px; border-radius: 999px; }

.side-card {
  margin-top: auto; padding: 16px; border-radius: 16px;
  background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .1);
  display: grid; gap: 8px;
}
.side-card h4 { font-size: 14px; color: #fff; }
.side-card p { font-size: 12.5px; color: rgba(255, 255, 255, .62); line-height: 1.7; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 10px 6px 0; border-top: 1px solid rgba(255, 255, 255, .1); }
.avatar {
  width: 36px; height: 36px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center; font-weight: 800; font-size: 15px;
  background: linear-gradient(140deg, #edd49a, #c19a3d); color: #33240f;
}
.side-user .who { display: grid; gap: 1px; min-width: 0; }
.side-user .who b { font-size: 13.5px; color: #fff; font-weight: 700; }
.side-user .who span { font-size: 11.5px; color: rgba(255, 255, 255, .5); }

.main { min-width: 0; display: flex; flex-direction: column; }
.page { min-width: 0; max-width: 100%; grid-template-columns: minmax(0, 1fr); }
.shell { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 28px; background: rgba(246, 242, 236, .86); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.topbar-spacer { flex: 1 1 auto; }
.topbar > div { min-width: 0; }
.topbar .search { position: relative; width: min(300px, 46vw); }
.topbar .search input { padding-inline-start: 38px; min-height: 40px; background: var(--surface); }
.topbar .search span { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; }

.page { padding: 26px 28px 40px; display: grid; gap: 24px; grid-template-columns: minmax(0, 1fr); }

/* ---------- بطاقات الإحصاء ---------- */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm);
  display: grid; gap: 6px;
}
.stat .ico {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  font-size: 18px; background: var(--brand-soft); color: var(--brand); margin-bottom: 4px;
}
.stat:nth-child(2) .ico { background: var(--gold-soft); color: #8a6a17; }
.stat:nth-child(3) .ico { background: #e8f0fb; color: #1f5fa8; }
.stat:nth-child(4) .ico { background: var(--ok-soft); color: var(--ok); }
.stat .k { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 27px; font-weight: 800; letter-spacing: -.02em; }
.stat .t { font-size: 12px; color: var(--muted); }

/* ---------- شريط الأدوات ---------- */

.bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bar h2 { font-size: 18px; }
.bar .spacer { flex: 1 1 auto; }
.seg { display: inline-flex; padding: 4px; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.seg button {
  border: 0; background: transparent; padding: 7px 13px; border-radius: 9px;
  font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button.is-on { background: var(--brand); color: #fff; }

/* ---------- شبكة التصميمات ---------- */

.grid-designs { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.design {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
  transition: transform .16s ease, box-shadow .2s ease;
}
.design:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.design .thumb {
  position: relative; aspect-ratio: 4 / 5; background: var(--surface-2);
  display: grid; place-items: center; overflow: hidden; cursor: pointer;
}
.design .thumb canvas { max-width: 100%; max-height: 100%; width: auto; height: auto; display: block; }
.design .thumb .float { position: absolute; inset-block-start: 10px; inset-inline-start: 10px; display: flex; gap: 6px; }
.design .meta { padding: 13px 14px 14px; display: grid; gap: 8px; }
.design .meta h3 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.design .meta .row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.design .actions { display: flex; gap: 6px; padding: 0 10px 12px; flex-wrap: wrap; }
.design .actions .btn { flex: 1 1 auto; }
.design.ghost {
  border-style: dashed; background: transparent; box-shadow: none; min-height: 260px;
  display: grid; place-items: center; text-align: center; padding: 20px; cursor: pointer;
}
.design.ghost:hover { background: rgba(255, 255, 255, .55); }
.design.ghost .plus { font-size: 30px; color: var(--brand); }
.design.ghost b { display: block; margin-top: 8px; font-size: 15px; }
.design.ghost span { color: var(--muted); font-size: 12.5px; }

.empty {
  padding: 40px 20px; text-align: center; color: var(--muted);
  border: 1px dashed #ddd0c0; border-radius: var(--radius); background: rgba(255, 255, 255, .5);
}
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 6px; }

/* ---------- صف القوالب ---------- */

.rail { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; min-width: 0; max-width: 100%; }
.tpl {
  flex: 0 0 168px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  background: var(--surface); cursor: pointer; transition: transform .15s, box-shadow .2s;
  text-align: start;
}
.tpl:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.tpl canvas { width: 100%; aspect-ratio: 4 / 5; display: block; background: #eee; }
.tpl .cap { padding: 9px 11px; display: grid; gap: 2px; }
.tpl .cap b { font-size: 13px; }
.tpl .cap span { font-size: 11.5px; color: var(--muted); }

/* ==========================================================================
   المصمم
   ========================================================================== */

.editor { height: 100vh; display: flex; flex-direction: column; background: var(--bg-deep); overflow: hidden; }
.editor-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 18px; background: #fff; border-bottom: 1px solid var(--line); z-index: 20;
}
.editor-head .title-input {
  border: 1px solid transparent; background: transparent; border-radius: 10px;
  padding: 7px 10px; font-size: 16px; font-weight: 700; width: min(280px, 40vw);
}
.editor-head .title-input:hover { border-color: var(--line); }
.editor-head .title-input:focus { border-color: #c095b1; box-shadow: 0 0 0 4px rgba(124, 45, 91, .1); outline: none; background: #fff; }
.editor-head .saved { font-size: 12px; color: var(--muted); min-width: 66px; }
.editor-body { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 340px 1fr; }

.panel {
  background: #fff; border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.panel-tabs { display: flex; gap: 2px; padding: 8px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.panel-tabs button {
  flex: 1 0 auto; border: 0; background: transparent; padding: 9px 8px; border-radius: 9px;
  font-size: 13px; font-weight: 700; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.panel-tabs button.is-on { background: var(--brand-soft); color: var(--brand); }
.panel-body { padding: 14px; overflow-y: auto; display: block; min-height: 0; }
.pane { display: none; }
.pane.is-on { display: block; }

.group { margin-bottom: 22px; }
.group:last-child { margin-bottom: 6px; }
.group > .label { display: block; margin-bottom: 9px; color: var(--ink); font-size: 13px; }
.hr { height: 1px; background: var(--line); margin: 18px 0; }

.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px; }
.swatch {
  aspect-ratio: 1; border-radius: 9px; border: 2px solid rgba(0, 0, 0, .06);
  cursor: pointer; padding: 0; transition: transform .12s;
}
.swatch:hover { transform: scale(1.07); }
.swatch.is-on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--brand); }

.grad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grad { aspect-ratio: 4 / 3; border-radius: 10px; border: 2px solid transparent; cursor: pointer; padding: 0; }
.grad.is-on { border-color: var(--brand); box-shadow: 0 0 0 2px #fff inset; }

.emoji-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.emoji {
  aspect-ratio: 1; display: grid; place-items: center; font-size: 20px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); cursor: pointer;
}
.emoji:hover { background: #fff; border-color: #d9c9b8; transform: translateY(-1px); }

.shape-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.shape {
  aspect-ratio: 1; display: grid; place-items: center; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface-2); cursor: pointer;
}
.shape:hover { background: #fff; }
.shape i { display: block; width: 24px; height: 24px; background: var(--ink-soft); }
.shape i.i-circle { border-radius: 50%; }
.shape i.i-rect { border-radius: 4px; }
.shape i.i-line { height: 4px; margin-block: 10px; }
.shape i.i-star { clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.shape i.i-heart { clip-path: path("M12 21s-8-5.2-8-11a4.6 4.6 0 0 1 8-3 4.6 4.6 0 0 1 8 3c0 5.8-8 11-8 11z"); }

.ctx-empty { padding: 26px 10px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.9; }
.ctx-empty .big { font-size: 26px; display: block; margin-bottom: 8px; opacity: .6; }

.ctrl { display: grid; gap: 6px; margin-bottom: 14px; }
.ctrl .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.ctrl .top output { font-family: var(--mono); font-size: 11.5px; color: var(--muted); font-weight: 600; background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }
input[type="range"] { width: 100%; accent-color: var(--brand); }
.color-row { display: flex; align-items: center; gap: 8px; }
.color-row input[type="color"] {
  width: 42px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; cursor: pointer;
}
.color-row .input { min-height: 38px; font-family: var(--mono); font-size: 12.5px; direction: ltr; text-align: left; }

.stage {
  position: relative; min-width: 0; min-height: 0; overflow: auto;
  display: grid; place-items: center; padding: 26px;
  background:
    radial-gradient(1000px 500px at 50% -10%, #fdfbf8, transparent 70%),
    repeating-linear-gradient(45deg, #efe8df 0 12px, #f2ece4 12px 24px);
}
.canvas-wrap { position: relative; box-shadow: var(--shadow-lg); border-radius: 6px; background: #fff; }
.canvas-wrap canvas { display: block; border-radius: 6px; }
#overlayCanvas { position: absolute; inset: 0; touch-action: none; cursor: default; }
.stage-foot {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; margin-top: 8px; border-radius: 999px;
  background: rgba(255, 255, 255, .9); border: 1px solid var(--line);
  box-shadow: var(--shadow-sm); font-size: 12px; color: var(--muted);
}

.text-edit {
  position: absolute; z-index: 30; margin: 0; padding: 0;
  background: rgba(255, 255, 255, .04); color: inherit; border: 2px solid #4ea3ff;
  border-radius: 4px; outline: none; resize: none; overflow: hidden;
  font-family: var(--font); text-align: center; line-height: 1.35;
  caret-color: #4ea3ff;
}

/* ---------- صفحة المشاركة ---------- */

.share-page { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; background:
  radial-gradient(900px 480px at 50% -20%, #fdf6ff, transparent 70%), var(--bg); }
.share-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 24px; }
.share-main { display: grid; grid-template-columns: minmax(0, 460px) minmax(0, 380px); gap: 40px; align-items: center; justify-content: center; padding: 10px 24px 40px; }
.share-card { position: relative; }
.share-card canvas { width: 100%; height: auto; border-radius: 14px; box-shadow: var(--shadow-lg); }
.share-info h2 { font-size: 26px; }
.share-info .occ { color: var(--gold); font-weight: 800; font-size: 13px; margin-bottom: 8px; }
.share-info p { color: var(--muted); line-height: 1.9; margin-top: 12px; font-size: 15px; }
.share-actions { display: grid; gap: 9px; margin-top: 22px; }
.share-btn {
  display: flex; align-items: center; gap: 11px; padding: 12px 15px; border-radius: 13px;
  background: var(--surface); border: 1px solid var(--line); font-weight: 700; font-size: 14.5px;
  cursor: pointer; text-align: start; transition: transform .12s, box-shadow .18s;
}
.share-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); text-decoration: none; }
.share-btn .ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-size: 14px; flex: 0 0 auto; }
.share-btn .ico.wa { background: #25d366; }
.share-btn .ico.fb { background: #1877f2; }
.share-btn .ico.tg { background: #229ed9; }
.share-btn .ico.x { background: #111; }
.share-btn .ico.ln { background: var(--brand-soft); color: var(--brand); }
.share-link {
  display: flex; align-items: center; gap: 8px; margin-top: 14px;
  padding: 8px 8px 8px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.share-link input { flex: 1 1 auto; border: 0; background: transparent; font-family: var(--mono); font-size: 12px; direction: ltr; text-align: left; min-width: 0; }
.share-stats { display: flex; gap: 18px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.share-stats div { display: grid; gap: 2px; }
.share-stats b { font-size: 19px; }
.share-stats span { font-size: 12px; color: var(--muted); }
.share-foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 18px; }

@media (max-width: 900px) {
  .share-main { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .share-card { max-width: 420px; margin-inline: auto; width: 100%; }
}

/* ---------- استجابة الشاشات الصغيرة ---------- */

@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .editor-body { grid-template-columns: 300px 1fr; }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 12px; padding: 12px 14px; overflow-x: auto; }
  .sidebar .side-card, .sidebar .side-user { display: none; }
  .nav { display: flex; gap: 4px; }
  .nav-label { display: none; }
  .nav-item { white-space: nowrap; padding: 9px 12px; font-size: 13.5px; }
  .nav-item .count { display: none; }
  .topbar { padding: 12px 16px; }
  .page { padding: 18px 16px 32px; }
  .editor-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .panel { border-inline-end: 0; border-bottom: 1px solid var(--line); max-height: 42vh; }
  .panel-body { overflow-y: auto; }
  .stage { padding: 16px; }
}

@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .grid-designs { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .topbar .search { width: 100%; }
  .modal-card { padding: 20px; }
}

/* ---------- أدوات مساعدة ---------- */

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.mt-0 { margin-top: 0; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.spin { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, #eee7dd 25%, #f6f1ea 37%, #eee7dd 63%);
  background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: 10px;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- إضافات المصمم ---------- */

.sel-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 12px; border-top: 1px solid var(--line); background: var(--surface-2);
}

.mini-tpls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.mini-tpls .tpl { flex: initial; width: 100%; }
.mini-tpls .tpl canvas { aspect-ratio: 4 / 5; object-fit: cover; }
.mini-tpls .cap { padding: 7px 9px; }
.mini-tpls .cap b { font-size: 12.5px; }

.size-list { display: grid; gap: 8px; }
.size-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 13px; border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface-2); cursor: pointer; text-align: start;
}
.size-item:hover { background: #fff; border-color: #d9c9b8; }
.size-item b { font-size: 13.5px; }
.size-item span { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.size-item.is-on { border-color: var(--brand); background: var(--brand-soft); }

.editor-head .topbar-spacer { flex: 1 1 auto; }

.swatch-group { display: grid; gap: 8px; }

