/* =============================================================================
   ثيم داكن هادئ · مينمال · احترافي — ثنائي اللغة (RTL/LTR) — موبايل أولًا
   أنميشن راقٍ خفيف · تفاصيل دقيقة
   ============================================================================= */

:root {
  --bg: #0f1218;
  --bg-2: #0b0d12;
  --surface: #171b23;
  --surface-2: #1b212b;
  --surface-3: #212936;
  --border: #262d39;
  --border-strong: #333c4b;

  --ink: #eef1f6;
  --muted: #99a3b2;
  --faint: #6b7484;

  --accent: #7e7bf2;
  --accent-2: #9b8cf7;
  --accent-press: #6a67e6;
  --accent-soft: rgba(126, 123, 242, .16);
  --accent-grad: linear-gradient(135deg, #8f8bf8, #6f6cf0);

  --success: #34d399;
  --success-soft: rgba(52, 211, 153, .14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .14);
  --warn: #fbbf24;

  --r-xs: 8px;
  --r-sm: 11px;
  --r: 15px;
  --r-lg: 22px;

  --sh-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --sh-md: 0 8px 24px -10px rgba(0, 0, 0, .5);
  --sh-lg: 0 30px 70px -28px rgba(0, 0, 0, .75);

  --ease: cubic-bezier(.22, .7, .25, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
html, body { overflow-x: hidden; }

body {
  font-family: 'Inter', 'IBM Plex Sans Arabic', system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(1100px 520px at 50% -300px, rgba(126, 123, 242, .13), transparent 62%),
    radial-gradient(800px 400px at 100% 0%, rgba(52, 211, 153, .05), transparent 55%),
    var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body[dir="rtl"] { font-family: 'IBM Plex Sans Arabic', 'Inter', system-ui, "Segoe UI", sans-serif; }

/* ===== تخطيط (موبايل أولًا) ===== */
.shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  height: 60px; display: flex; align-items: center; justify-content: space-between;
  padding-inline: max(clamp(16px, 5vw, 40px), env(safe-area-inset-left)) max(clamp(16px, 5vw, 40px), env(safe-area-inset-right));
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--border);
  background: rgba(15, 18, 24, .72); backdrop-filter: blur(14px);
  position: sticky; top: 0; z-index: 20;
}
.stage {
  flex: 1; display: grid; place-items: center;
  padding: clamp(16px, 5vw, 56px) max(16px, env(safe-area-inset-left));
  padding-inline-end: max(16px, env(safe-area-inset-right));
}
.stack { width: 100%; max-width: 430px; }

/* ===== الشعار ===== */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15.5px; letter-spacing: -.01em; color: var(--ink); text-decoration: none; }
.brand .mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff;
  background: var(--accent-grad); box-shadow: 0 6px 16px -4px rgba(126, 123, 242, .6), inset 0 1px 0 rgba(255,255,255,.25);
  position: relative; overflow: hidden;
}
.brand .mark svg { width: 19px; height: 19px; }
.brand .mark::after { content: ""; position: absolute; inset: 0; background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.35) 50%, transparent 70%); transform: translateX(-120%); animation: sheen 5s var(--ease) infinite; }
@keyframes sheen { 0%, 55% { transform: translateX(-120%); } 75%, 100% { transform: translateX(120%); } }

/* ===== مبدّل اللغة ===== */
.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; gap: 2px; }
.seg button {
  border: 0; cursor: pointer; font-family: inherit; font-weight: 600; font-size: 13px;
  padding: 8px 16px; border-radius: 999px; color: var(--muted); background: transparent;
  transition: color .25s var(--ease), background .25s var(--ease); min-width: 46px;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.seg button.on { color: var(--ink); background: var(--surface-3); box-shadow: var(--sh-sm); }

/* ===== البطاقة ===== */
.card {
  position: relative;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--sh-lg); padding: clamp(24px, 4vw, 34px);
  animation: enter .55s var(--ease) both;
}
.card::before { content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px; background: linear-gradient(180deg, rgba(255,255,255,.08), transparent 40%); -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none; }
@keyframes enter { from { opacity: 0; transform: translateY(12px) scale(.99); } to { opacity: 1; transform: none; } }

/* تتابع دخول العناصر */
.stagger > * { opacity: 0; animation: rise .5s var(--ease) forwards; }
.stagger > *:nth-child(1) { animation-delay: .05s; }
.stagger > *:nth-child(2) { animation-delay: .12s; }
.stagger > *:nth-child(3) { animation-delay: .19s; }
.stagger > *:nth-child(4) { animation-delay: .26s; }
.stagger > *:nth-child(5) { animation-delay: .33s; }
.stagger > *:nth-child(6) { animation-delay: .40s; }
@keyframes rise { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }

/* ===== نصوص ===== */
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--accent-2); }
body[dir="rtl"] .eyebrow { letter-spacing: 0; text-transform: none; }
h1 { font-size: clamp(23px, 4.4vw, 29px); font-weight: 750; letter-spacing: -.02em; line-height: 1.24; }
body[dir="rtl"] h1 { letter-spacing: 0; font-weight: 700; }
.lead { color: var(--muted); font-size: 15px; margin-top: 9px; }

/* ===== كود الجلسة ===== */
.code-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 22px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface-2);
}
.code-row .k { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.code-row .lbl { font-size: 11.5px; color: var(--faint); }
.code-row .val { font-family: 'Inter', ui-monospace, monospace; font-weight: 650; letter-spacing: .02em; direction: ltr; color: var(--ink); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface-3); cursor: pointer; color: var(--muted);
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; transition: all .2s var(--ease); flex: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.icon-btn:hover { color: var(--ink); border-color: var(--border-strong); }
.icon-btn.done { color: var(--success); border-color: var(--success); }

/* ===== الأزرار ===== */
.btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px; width: 100%;
  border: 0; cursor: pointer; font-family: inherit; font-weight: 600; font-size: 15.5px;
  height: 54px; border-radius: 14px; color: #fff; text-decoration: none;
  transition: transform .12s var(--ease), box-shadow .25s var(--ease), background .2s;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn-primary { background: var(--accent-grad); box-shadow: 0 12px 28px -12px rgba(126, 123, 242, .8); }
.btn-primary::after { content: ""; position: absolute; inset: 0; background: linear-gradient(120deg, transparent 35%, rgba(255,255,255,.28) 50%, transparent 65%); transform: translateX(-130%); transition: transform .7s var(--ease); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 16px 34px -12px rgba(126, 123, 242, .9); }
.btn-primary:hover::after { transform: translateX(130%); }
.btn-primary:active { transform: translateY(0); background: var(--accent-press); }
.btn-ghost { background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--ink); }
.btn-ghost:hover { border-color: var(--accent); }
/* زر تجريبي مميّز (بلا أنميشن مستمرة) */
.btn-trial {
  background: linear-gradient(180deg, rgba(126,123,242,.20), rgba(126,123,242,.07));
  border: 1px solid rgba(126,123,242,.55); color: var(--accent-2); font-weight: 700;
}
.btn-trial:hover { transform: translateY(-1px); border-color: var(--accent); background: linear-gradient(180deg, rgba(126,123,242,.28), rgba(126,123,242,.12)); color: #fff; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(248,113,113,.3); }
.btn:disabled { opacity: .55; cursor: default; transform: none; box-shadow: none; }
.btn .spin, .spin { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: rot .7s linear infinite; }
@keyframes rot { to { transform: rotate(1turn); } }

.link-btn {
  display: block; width: 100%; text-align: center; margin-top: 10px; background: none; border: 0;
  cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 600; color: var(--muted);
  transition: color .2s; padding: 12px; min-height: 44px; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.link-btn:hover { color: var(--accent-2); }
.link-btn:disabled { opacity: .5; cursor: default; }

/* ===== خط الخطوات ===== */
.steps { display: flex; align-items: center; gap: 8px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); flex-wrap: nowrap; }
.steps .s { display: flex; align-items: center; gap: 8px; flex: 1 1 0; min-width: 0; justify-content: center; }
.steps .n { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--accent-soft); color: var(--accent-2); flex: none; }
.steps .t { font-size: 12px; color: var(--muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.steps .sep { width: 14px; height: 1px; background: var(--border-strong); flex: none; }

/* ===== كشف المفتاح التجريبي (مدمج، بلا فراغ عند الإخفاء) ===== */
.trial-reveal {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  margin-top: 12px; padding: 11px 14px; border: 1px solid rgba(52,211,153,.4);
  border-radius: 12px; background: var(--surface-2); animation: enter .28s var(--ease) both;
}
.trial-reveal.hidden { display: none !important; }
.trial-reveal .tcap { font-size: 12px; color: var(--faint); white-space: nowrap; }
.trial-reveal .tval { flex: 1; font-family: 'Inter', ui-monospace, monospace; direction: ltr; font-weight: 700; color: var(--good); font-size: 15px; text-align: center; overflow: hidden; text-overflow: ellipsis; }

/* ===== تنبيه مميّز في الرئيسية ===== */
.notice {
  display: flex; align-items: flex-start; gap: 11px; margin-bottom: 16px; padding: 14px 16px;
  border-radius: var(--r); border: 1px solid rgba(126,123,242,.35);
  background: linear-gradient(180deg, rgba(126,123,242,.16), rgba(126,123,242,.06));
  box-shadow: var(--sh-md); animation: enter .5s var(--ease) both;
}
.notice .ico { flex: none; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-grad); color: #fff; font-size: 14px; box-shadow: 0 4px 12px -3px rgba(126,123,242,.7); }
.notice .txt { font-size: 13.5px; color: var(--ink); font-weight: 500; line-height: 1.55; }

/* ===== سطر الثقة ===== */
.trust { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px; font-size: 12px; color: var(--faint); }
.trust span { display: inline-flex; align-items: center; gap: 5px; }
.trust .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--success); box-shadow: 0 0 8px var(--success); }

/* ===== ناتج المفتاح ===== */
.keyout { margin-top: 22px; padding: 20px; border: 1px solid rgba(52,211,153,.4); background: var(--success-soft); border-radius: var(--r); text-align: center; animation: enter .4s var(--ease) both; }
.keyout .cap { font-size: 12px; color: var(--muted); }
.keyout .val {
  font-family: 'Inter', ui-monospace, monospace; font-weight: 700; font-size: clamp(15px, 4vw, 19px); letter-spacing: .04em;
  color: var(--ink); direction: ltr; word-break: break-all; margin: 8px 0; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.keyout .meta { font-size: 12.5px; color: var(--muted); }
.keyout .meta b { color: var(--ink); font-weight: 650; }

/* ===== البوابة ===== */
.ring-wrap { display: grid; place-items: center; margin: 8px 0 6px; }
.ring-box { position: relative; display: grid; place-items: center; }
.ring { width: 96px; height: 96px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 6; stroke-linecap: round; }
.ring .track { stroke: var(--border); }
.ring .bar { stroke: url(#g1); transition: stroke-dashoffset .95s linear; }
.ring-num { position: absolute; font-size: 30px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ===== التحقق (الاستلام) ===== */
.checks { margin-top: 20px; }
.check { display: flex; align-items: center; gap: 11px; padding: 9px 0; font-size: 13.5px; color: var(--muted); }
.check + .check { border-top: 1px solid var(--border); }
.check .st { width: 20px; height: 20px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 11px; background: var(--surface-3); color: var(--faint); transition: all .3s var(--ease); }
.check.ok .st { background: var(--success-soft); color: var(--success); transform: scale(1.05); }
.check.ok { color: var(--ink); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: .3; animation: blink 1.1s var(--ease) infinite; }
.dots i:nth-child(2) { animation-delay: .18s; } .dots i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* ===== الحقول ===== */
.field, input.field, select.field {
  width: 100%; height: 46px; padding-inline: 14px; border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--surface-2); color: var(--ink); font-family: inherit; font-size: 14px; transition: border-color .2s, box-shadow .2s;
}
input.mono { font-family: 'Inter', ui-monospace, monospace; direction: ltr; font-size: 13px; }
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ===== أدوات ===== */
.center { text-align: center; }
.muted { color: var(--muted); } .faint { color: var(--faint); }
.hidden { display: none !important; }
.mt { margin-top: 16px; }
.title-ic { width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center; margin: 0 auto 12px; font-size: 22px; background: var(--accent-soft); color: var(--accent-2); }
.title-ic svg { width: 26px; height: 26px; }
.title-ic.ok { background: var(--success-soft); color: var(--success); }
.title-ic.lock { background: var(--surface-3); color: var(--faint); }
.foot { text-align: center; padding: 20px; padding-bottom: max(20px, env(safe-area-inset-bottom)); color: var(--faint); font-size: 12px; }

*:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* =============================================================================
   لوحة التحكم (Dashboard)
   ============================================================================= */
.dash { width: 100%; max-width: 960px; margin-inline: auto; padding: 18px max(16px, env(safe-area-inset-left)) 40px; }
.dash-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.dash-head h1 { font-size: 20px; }
.tabs { display: flex; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin-bottom: 18px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabs button { flex: 1; min-width: max-content; border: 0; background: transparent; color: var(--muted); font-family: inherit; font-weight: 600; font-size: 13.5px; padding: 10px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap; transition: all .2s var(--ease); }
.tabs button.on { background: var(--surface-3); color: var(--ink); box-shadow: var(--sh-sm); }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 620px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat { background: linear-gradient(180deg, var(--surface), var(--surface-2)); border: 1px solid var(--border); border-radius: var(--r); padding: 16px; }
.stat .n { font-size: 26px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat .n.accent { color: var(--accent-2); } .stat .n.good { color: var(--success); }

.panel { background: linear-gradient(180deg, var(--surface), var(--surface-2)); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 18px; margin-top: 16px; }
.panel h2 { font-size: 15px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 12px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 460px; }
th, td { text-align: start; padding: 11px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--faint); font-weight: 600; font-size: 12px; background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.mono, .mono { font-family: 'Inter', ui-monospace, monospace; direction: ltr; }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.tag.full { background: var(--accent-soft); color: var(--accent-2); }
.tag.trust { background: rgba(251,191,36,.14); color: var(--warn); }
.tag.live { background: var(--success-soft); color: var(--success); }
.tag.dead { background: var(--surface-3); color: var(--faint); }
.row-form { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.row-form .full { grid-column: 1 / -1; }
.field-label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; display: block; }
.toast { position: fixed; inset-block-end: 20px; inset-inline: 0; margin-inline: auto; width: max-content; max-width: 90vw; background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--ink); padding: 12px 18px; border-radius: 12px; box-shadow: var(--sh-lg); font-size: 13.5px; opacity: 0; transform: translateY(10px); transition: all .3s var(--ease); z-index: 60; }
.toast.show { opacity: 1; transform: none; }
.link-x { color: var(--danger); cursor: pointer; font-weight: 600; background: none; border: 0; font-family: inherit; font-size: 12.5px; }

/* مفتاح تبديل */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; color: var(--ink); -webkit-tap-highlight-color: transparent; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 46px; height: 27px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border-strong); transition: .22s var(--ease); position: relative; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 21px; height: 21px; border-radius: 50%; background: var(--faint); transition: .22s var(--ease); }
.switch input:checked + .track { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + .track::after { inset-inline-start: 21px; background: var(--accent); }

/* شريط أدوات المخزون */
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.controls .btn { width: auto; height: 42px; padding: 0 16px; font-size: 13.5px; }
.pill-btn { height: 42px; padding: 0 14px; border-radius: 11px; border: 1px solid var(--border-strong); background: var(--surface-3); color: var(--ink); font-family: inherit; font-weight: 600; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; transition: all .18s var(--ease); -webkit-tap-highlight-color: transparent; }
.pill-btn:hover { border-color: var(--accent); }
.pill-btn.danger { color: var(--danger); border-color: rgba(248,113,113,.3); }
.pill-btn.danger:hover { border-color: var(--danger); }

/* شريط تقدّم المخزون */
.poolbar { height: 12px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin: 10px 0 6px; border: 1px solid var(--border); }
.poolbar > i { display: block; height: 100%; background: var(--accent-grad); border-radius: 999px; transition: width .5s var(--ease); }

.checkcell { width: 34px; }
input[type=checkbox].chk { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.seg-filter { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; gap: 2px; }
.seg-filter button { border: 0; background: transparent; color: var(--muted); font-family: inherit; font-weight: 600; font-size: 12.5px; padding: 7px 12px; border-radius: 8px; cursor: pointer; }
.seg-filter button.on { background: var(--surface-3); color: var(--ink); }

@media (max-width: 480px) { .steps .t { display: none; } .row-form { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { *, *::after, *::before { animation: none !important; transition: none !important; } }
