:root {
  --bg: #070c12;
  --surface: #0d151e;
  --raise: #131f2b;
  --line: #1c2b38;
  --text: #e6f3f8;
  --muted: #8aa5b3;
  --accent: #7de3fa;
  --accent-d: #4fa6c2;
  --accent-soft: rgba(125, 227, 250, .12);
  --on-accent: #041118;
  --grad: linear-gradient(135deg, #3c8ca9, #6bc9e5 60%, #7de3fa);
  --danger: #ff7b7b;
  --ok: #4fd6a0;
  --warn: #f0b95a;
  --r: 14px;
  font-family: "Readex Pro", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { line-height: 1.7; font-size: 15px; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.35; font-weight: 600; }
p { margin: 0; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ── أزرار وحقول ── */
.btn {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 10px; padding: 9px 18px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: border-color .15s, background .15s, box-shadow .15s, filter .15s;
}
.btn:hover { border-color: var(--accent-d); }
.btn.primary { background: var(--grad); color: var(--on-accent); border: 0; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn.line { background: transparent; color: var(--accent); border-color: var(--accent-d); }
.btn.line:hover { background: var(--accent-soft); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 14px; font-size: 13px; }
.btn.big { padding: 14px 28px; font-size: 17px; border-radius: 14px; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; box-shadow: none; }
.ib {
  width: 32px; height: 32px; padding: 0; display: inline-grid; place-items: center; cursor: pointer;
  color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: 8px;
}
.ib:hover { background: var(--raise); color: var(--text); border-color: var(--line); }
.ib.danger:hover { color: var(--danger); border-color: var(--danger); }
.ib:disabled { opacity: .3; cursor: not-allowed; pointer-events: none; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  font: inherit; width: 100%; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 96px; }
input[type=file] { padding: 7px 10px; }
.field { margin-bottom: 18px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }

/* ── صفحة الدخول ── */
.login {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr; align-items: center; gap: 40px;
  padding: 48px clamp(24px, 8vw, 120px);
  background: radial-gradient(60% 50% at 80% 40%, rgba(95, 208, 238, .09), transparent 70%);
}
.login h1 { font-size: clamp(28px, 4vw, 44px); margin-bottom: 16px; }
.login p { color: var(--muted); max-width: 46ch; margin-bottom: 28px; font-size: 16px; }
.login .btn { font-size: 16px; padding: 12px 26px; text-decoration: none; }
.login .err { color: var(--danger); margin-top: 16px; }
.login .logo { width: min(100%, 380px); justify-self: center; filter: drop-shadow(0 20px 60px rgba(95, 208, 238, .22)); }
@media (max-width: 800px) { .login { grid-template-columns: 1fr; } .login .logo { width: 150px; order: -1; justify-self: start; } }

/* ── هيكل التطبيق ── */
.shell { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-inline-end: 1px solid var(--line); padding: 22px 16px; display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 17px; color: var(--text); padding-inline: 4px; }
.brand img { width: 36px; height: 36px; }
.me { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; }
.me img { width: 42px; height: 42px; border-radius: 50%; background: var(--raise); flex: none; }
.me b { display: block; font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me small { color: var(--muted); font-size: 12px; }
.side nav { display: flex; flex-direction: column; gap: 4px; }
.side nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); }
.side nav a:hover { background: var(--raise); color: var(--text); }
.side nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.side .nav-sep { margin: 10px 12px 4px; font-size: 12px; color: var(--muted); opacity: .8; }
.logout { margin-top: auto; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); }
.logout:hover { background: var(--raise); color: var(--danger); }
main { padding: 36px clamp(20px, 4vw, 56px) 56px; max-width: 1120px; width: 100%; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 10px; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .side .me { order: 2; margin-inline-start: auto; padding: 6px; border: 0; background: none; }
  .side .me div, .side .nav-sep, .logout span { display: none; }
  .side nav { flex-direction: row; order: 3; width: 100%; overflow-x: auto; }
  .side nav a { white-space: nowrap; }
  .logout { margin: 0; order: 2; padding: 8px; }
}

/* ── ترويسة الصفحة والإحصائيات ── */
.page-head { margin-bottom: 26px; }
.page-head p { color: var(--muted); margin-top: 6px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 26px; }
.stat { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.stat span { display: block; font-size: 13px; color: var(--muted); }
.stat b { display: block; font-size: 30px; font-weight: 600; line-height: 1.3; }
.stat .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.stat .ic svg { width: 21px; height: 21px; }
.stat.warn .ic { background: rgba(240, 185, 90, .12); color: var(--warn); }
.stat.bad .ic { background: rgba(255, 123, 123, .12); color: var(--danger); }
.stat.good .ic { background: rgba(79, 214, 160, .12); color: var(--ok); }
@media (max-width: 900px) { .stats { grid-template-columns: 1fr 1fr; } }
@media (max-width: 420px) { .stat b { font-size: 24px; } .stat .ic { display: none; } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; margin-bottom: 22px; }
.panel > h3 { margin-bottom: 4px; }
.panel > .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; }
.panel.flush { padding: 0; overflow: hidden; }

/* ── صفوف التراخيص (العميل) ── */
.lic-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 22px; }
.lic-row {
  display: grid; grid-template-columns: minmax(230px, 1.5fr) repeat(3, minmax(96px, 1fr)) auto; gap: 18px; align-items: center;
  padding: 16px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
}
.lic-main { display: flex; align-items: center; gap: 14px; min-width: 0; }
.pic { width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.lic-main .nm { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 600; }
.lic-main .code { margin-top: 4px; display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.cell .k { display: block; font-size: 12px; color: var(--muted); }
.cell .v { font-weight: 500; }
.cell .v.date { color: var(--accent); }
.cell .sub { font-size: 12.5px; color: var(--muted); }
.cell .sub.bad { color: var(--danger); }
.cell .sub.soon { color: var(--warn); }
.lic-row .acts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 1000px) {
  .lic-row { grid-template-columns: 1fr 1fr 1fr; }
  .lic-main { grid-column: 1 / -1; }
  .lic-row .acts { grid-column: 1 / -1; justify-content: flex-start; }
}
@media (max-width: 520px) { .lic-row { grid-template-columns: 1fr 1fr; } }

.redeem { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.redeem .grow { flex: 1; min-width: 220px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; display: flex; gap: 12px; align-items: flex-start; color: var(--muted); font-size: 14px; }
.steps li::before { content: counter(s); flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.steps b { color: var(--text); font-weight: 500; }
@media (max-width: 760px) { .steps { grid-template-columns: 1fr; } }

/* ── شارات الحالة ── */
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 2px 11px; border-radius: 99px; font-size: 12px; font-weight: 500; background: var(--raise); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.tag.active { color: var(--ok); background: rgba(79, 214, 160, .1); border-color: rgba(79, 214, 160, .3); }
.tag.revoked, .tag.expired { color: var(--danger); background: rgba(255, 123, 123, .1); border-color: rgba(255, 123, 123, .3); }
.tag.unused { color: var(--warn); background: rgba(240, 185, 90, .1); border-color: rgba(240, 185, 90, .3); }
.code { font-family: ui-monospace, Consolas, monospace; direction: ltr; unicode-bidi: isolate; background: var(--bg); border: 1px solid var(--line); padding: 2px 9px; border-radius: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }

/* ── الجداول (الأدمن) ── */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.toolbar .grow { flex: 1; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 340px; }
.search svg { position: absolute; inset-block: 0; margin-block: auto; inset-inline-start: 12px; color: var(--muted); }
.search input { padding-inline-start: 38px; }
.toolbar select { width: auto; min-width: 140px; }
.scroll-x { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: start; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td .hint { margin-top: 0; }
th { color: var(--muted); font-weight: 500; font-size: 12.5px; background: rgba(255, 255, 255, .015); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(125, 227, 250, .03); }
td select { min-width: 130px; padding: 5px 10px; font-size: 13px; }
td .acts { display: flex; gap: 2px; flex-wrap: nowrap; }
td .code { font-size: 12.5px; }
.empty { color: var(--muted); padding: 28px 20px; text-align: center; }

dialog.dlg { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 18px; padding: 24px; width: min(560px, calc(100vw - 32px)); }
dialog.dlg::backdrop { background: rgba(2, 6, 10, .72); }
dialog.dlg h3 { margin-bottom: 18px; }
.dlg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.dlg-grid .full { grid-column: 1 / -1; }
.dlg-foot { display: flex; gap: 10px; justify-content: flex-start; margin-top: 6px; }
@media (max-width: 520px) { .dlg-grid { grid-template-columns: 1fr; } }

.toast { position: fixed; inset-block-end: 24px; inset-inline-start: 24px; background: var(--raise); border: 1px solid var(--line); padding: 12px 18px; border-radius: 10px; z-index: 100; max-width: 340px; }
.toast.err { border-color: var(--danger); }
.toast.ok { border-color: var(--ok); }
@media (prefers-reduced-motion: no-preference) { .toast { animation: tin .2s ease-out; } @keyframes tin { from { opacity: 0; transform: translateY(8px); } } }

/* ── محرر الكود ── */
body.ed-open { overflow: hidden; }
.ed { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: var(--bg); }
.ed-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.ed-top .grow { flex: 1; }
.ed-path { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13px; color: var(--muted); }
.ed-state { font-size: 12px; color: var(--ok); }
.ed-state.dirty { color: #f0b429; }
.ed-body { flex: 1; min-height: 0; display: flex; }
.ed-tree { width: 260px; flex: none; overflow: auto; border-inline-end: 1px solid var(--line); background: var(--surface); padding: 8px 0; }
.ed-d { color: var(--muted); font-size: 12px; padding: 6px 10px 2px; direction: ltr; text-align: left; }
.ed-f { display: block; width: 100%; direction: ltr; text-align: left; font: 13px ui-monospace, Menlo, Consolas, monospace; color: var(--text); background: none; border: 0; border-inline-start: 2px solid transparent; padding-block: 4px; padding-inline-end: 10px; cursor: pointer; }
.ed-f:hover { background: var(--raise); }
.ed-f.on { background: var(--raise); border-inline-start-color: var(--accent); color: var(--accent); }
.ed-f:disabled { opacity: .4; cursor: not-allowed; }
.ed-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ed-code { flex: 1; min-height: 0; display: flex; direction: ltr; background: #070d14; }
.ed-gut, #edTa { margin: 0; padding: 10px 0; font: 13px/20px ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; tab-size: 2; }
.ed-gut { width: 52px; flex: none; overflow: hidden; text-align: right; padding-inline: 8px; color: #4b6376; background: #0a1119; user-select: none; }
#edTa { flex: 1; min-width: 0; width: auto; border: 0; border-radius: 0; resize: none; outline: none; padding-inline: 12px; white-space: pre; overflow: auto; background: transparent; color: #d6e6ee; }
#edTa:disabled { opacity: .4; }
.ed-foot { padding: 6px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); background: var(--surface); }
.ed-foot.err { color: #ff8b84; }
.ed-histbox { padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); max-height: 30vh; overflow: auto; font-size: 13px; }
.ed-v { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; }
@media (max-width: 720px) {
  .ed-body { flex-direction: column; }
  .ed-tree { width: auto; max-height: 28vh; border-inline-end: 0; border-bottom: 1px solid var(--line); }
}
