/* ============================================================
   KL — لوحة التحكم  |  ثيم Onyx OLED (أسود + أزرق)  |  Responsive
   ============================================================ */
:root {
  --blue-50: #0b1220;
  --blue-100: #0e1830;
  --blue-200: #16315e;
  --blue-400: #60a5fa;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-glow: rgba(59, 130, 246, 0.45);

  --bg: #000000;          /* OLED أسود */
  --bg-2: #05060a;
  --card: #0b0d12;        /* بطاقات أونيكس */
  --card-2: #111520;
  --text: #eaf0fb;
  --muted: #8b94a7;
  --line: #1a1f2c;
  --line-2: #232a3a;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 8px 28px -16px rgba(0, 0, 0, 0.9);
  --shadow-lg: 0 30px 70px -25px rgba(0, 0, 0, 0.95);
  --glow: 0 0 0 1px rgba(59,130,246,0.15), 0 10px 30px -16px var(--blue-glow);
  --sidebar-w: 270px;
  --ease: cubic-bezier(.4, 0, .2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Tajawal', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 540px at 100% -10%, rgba(37,99,235,0.10), transparent 60%),
    radial-gradient(820px 460px at -10% 110%, rgba(37,99,235,0.08), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
i[data-lucide] { width: 1em; height: 1em; stroke-width: 2.2; vertical-align: -0.15em; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #232a3a; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- شاشة الإقلاع ---------- */
.boot { height: 100vh; height: 100dvh; display: grid; place-content: center; gap: 22px; justify-items: center; }
.boot-logo {
  width: 84px; height: 84px; border-radius: 24px; display: grid; place-content: center;
  font-weight: 900; font-size: 34px; color: #fff;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
  box-shadow: var(--glow); letter-spacing: 1px;
}
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #1c2433; border-top-color: var(--blue-500); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- تسجيل الدخول ---------- */
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-content: center; padding: 24px; }
.auth-card {
  background: linear-gradient(180deg, #0d1018, #0a0c11); border-radius: 28px; padding: 44px 38px; width: min(420px, 92vw);
  box-shadow: var(--shadow-lg); text-align: center; border: 1px solid var(--line-2); animation: pop .5s var(--ease);
}
@keyframes pop { from { transform: translateY(14px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.auth-card .logo { width: 88px; height: 88px; margin: 0 auto 18px; border-radius: 26px; display: grid; place-content: center; font-weight: 900; font-size: 36px; color: #fff; background: linear-gradient(135deg, var(--blue-500), var(--blue-700)); box-shadow: var(--glow); }
.auth-card h1 { font-size: 26px; font-weight: 800; }
.auth-card p { color: var(--muted); margin: 8px 0 26px; }
.btn-discord {
  width: 100%; padding: 15px; border-radius: 14px; border: none; color: #fff; font-size: 16px; font-weight: 700;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-600));
  display: flex; align-items: center; justify-content: center; gap: 10px; transition: .2s var(--ease);
  box-shadow: 0 10px 28px -12px var(--blue-glow);
}
.btn-discord:hover { transform: translateY(-2px); box-shadow: 0 18px 36px -12px var(--blue-glow); }
.auth-note { margin-top: 18px; font-size: 13px; color: var(--muted); }
.auth-error { background: rgba(239,68,68,.12); color: #fca5a5; border: 1px solid rgba(239,68,68,.35); padding: 12px; border-radius: 12px; margin-bottom: 18px; font-weight: 600; font-size: 14px; }

/* ---------- التخطيط ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  background: linear-gradient(180deg, #0a0c11, #07090d); border-inline-start: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 22px 16px; position: sticky; top: 0; height: 100vh; height: 100dvh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 20px; }
.brand .mark { width: 46px; height: 46px; border-radius: 14px; display: grid; place-content: center; color: #fff; font-weight: 900; font-size: 20px; background: linear-gradient(135deg, var(--blue-500), var(--blue-700)); box-shadow: var(--glow); }
.brand .name { font-weight: 800; font-size: 18px; }
.brand .sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1; padding-inline: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 13px; color: var(--muted);
  font-weight: 600; font-size: 15px; border: none; background: transparent; width: 100%; text-align: start; transition: .18s var(--ease); min-height: 44px;
}
.nav-item i { font-size: 19px; }
.nav-item:hover { background: var(--blue-50); color: #cfe0ff; }
.nav-item.active { background: linear-gradient(135deg, var(--blue-600), var(--blue-700)); color: #fff; box-shadow: var(--glow); }
.nav-foot { padding-top: 14px; border-top: 1px solid var(--line); margin-top: 10px; }

.main { padding: 26px clamp(16px, 3vw, 40px) 60px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 16px; margin-bottom: 26px; }
.topbar .hb { display: none; }
.page-title { flex: 1; min-width: 0; }
.page-title h2 { font-size: clamp(20px, 2.4vw, 28px); font-weight: 800; display: flex; align-items: center; gap: 10px; }
.page-title p { color: var(--muted); font-size: 14px; }
.user-chip { display: flex; align-items: center; gap: 10px; background: var(--card); padding: 7px 8px 7px 14px; border-radius: 40px; box-shadow: var(--shadow); border: 1px solid var(--line-2); }
.user-chip img { width: 34px; height: 34px; border-radius: 50%; }
.user-chip .uname { font-weight: 700; font-size: 14px; }
.user-chip button { border: none; background: var(--blue-50); color: #cfe0ff; width: 34px; height: 34px; border-radius: 50%; display: grid; place-content: center; }
.user-chip button:hover { background: rgba(239,68,68,.15); color: #fca5a5; }

/* ---------- البطاقات ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 18px; align-items: start; }
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--line); animation: rise .4s var(--ease) both; transition: border-color .2s var(--ease); }
.card:hover { border-color: var(--line-2); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.card.full { grid-column: 1 / -1; }
.field-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.field-head .lbl { font-weight: 700; font-size: 15.5px; }
.field-head .help { color: var(--muted); font-size: 13px; margin-top: 3px; line-height: 1.55; }

/* ---------- أدوات التحكم ---------- */
.toggle { position: relative; width: 50px; height: 29px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .track { position: absolute; inset: 0; background: #2a313f; border-radius: 30px; transition: .25s var(--ease); }
.toggle .track::before { content: ""; position: absolute; width: 23px; height: 23px; border-radius: 50%; background: #fff; top: 3px; right: 3px; transition: .25s var(--ease); box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.toggle input:checked + .track { background: linear-gradient(135deg, var(--blue-500), var(--blue-600)); }
.toggle input:checked + .track::before { transform: translateX(-21px); }

.input, .select, textarea.input {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--line-2); border-radius: var(--radius-sm); font-size: 15px;
  background: var(--card-2); color: var(--text); transition: .18s var(--ease); font-family: inherit;
}
.input::placeholder, textarea.input::placeholder { color: #5a6478; }
.input:focus, .select:focus, textarea.input:focus { outline: none; border-color: var(--blue-500); background: #0d111b; box-shadow: 0 0 0 4px rgba(59,130,246,.18); }
textarea.input { resize: vertical; min-height: 84px; }
.select option { background: #0d111b; color: var(--text); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row2 .sub { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: block; }

/* picker */
.picker { position: relative; }
.picker-btn { width: 100%; display: flex; align-items: center; gap: 8px; padding: 11px 14px; border: 1.5px solid var(--line-2); border-radius: var(--radius-sm); background: var(--card-2); font-size: 15px; color: var(--text); transition: .18s var(--ease); }
.picker-btn:hover { border-color: var(--blue-200); }
.picker-btn .ph { color: #5a6478; }
.picker-btn .chev { margin-inline-start: auto; color: var(--muted); }
.picker-btn span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-pop {
  position: fixed; z-index: 9999; background: #0d1018; border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); overflow: hidden; max-height: 300px;
  display: flex; flex-direction: column; animation: pop .14s var(--ease);
}
.picker-search { padding: 10px; border-bottom: 1px solid var(--line); }
.picker-search input { width: 100%; padding: 9px 12px; border: 1.5px solid var(--line-2); border-radius: 10px; font-family: inherit; font-size: 14px; background: var(--card-2); color: var(--text); }
.picker-list { overflow-y: auto; padding: 6px; }
.picker-opt { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 10px; cursor: pointer; font-size: 14.5px; min-width: 0; }
.picker-opt:hover, .picker-opt.kbd { background: var(--blue-50); }
.picker-opt img { width: 26px; height: 26px; border-radius: 50%; }
.picker-opt span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); }
.opt-muted { color: var(--muted); }

/* chips / tags */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 7px; background: var(--blue-50); color: #cfe0ff; border-radius: 30px; padding: 6px 6px 6px 12px; font-size: 13.5px; font-weight: 600; border: 1px solid var(--line-2); }
.chip img { width: 20px; height: 20px; border-radius: 50%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.chip .x { width: 22px; height: 22px; border-radius: 50%; border: none; background: #0d1018; color: #fca5a5; display: grid; place-content: center; font-size: 12px; }
.chip .x:hover { background: rgba(239,68,68,.2); }

/* rows editor */
.editor-row { display: grid; gap: 8px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; background: var(--card-2); }
.editor-row.lr { grid-template-columns: 90px 1fr 40px; }
.editor-row.tc { grid-template-columns: 64px 1fr 1fr 40px; }
.editor-row.sm { grid-template-columns: 64px 1fr 1fr 40px; }
.editor-row .input { padding: 9px 11px; }
.icon-btn { border: 1px solid var(--line-2); width: 38px; height: 38px; border-radius: 10px; display: grid; place-content: center; background: #0d1018; color: #fca5a5; }
.icon-btn:hover { background: rgba(239,68,68,.18); }
.btn-add { display: inline-flex; align-items: center; gap: 8px; border: 1.5px dashed var(--blue-200); color: #cfe0ff; background: var(--blue-50); padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px; }
.btn-add:hover { background: var(--blue-100); }

/* buttons */
.btn { border: none; border-radius: 12px; padding: 11px 18px; font-weight: 700; font-size: 14.5px; display: inline-flex; align-items: center; gap: 8px; transition: .18s var(--ease); }
.btn-primary { background: linear-gradient(135deg, var(--blue-500), var(--blue-600)); color: #fff; box-shadow: 0 10px 22px -12px var(--blue-glow); }
.btn-primary:hover { transform: translateY(-1px); }
.btn-ghost { background: var(--blue-50); color: #cfe0ff; }

/* نظرة عامة */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--line); display: flex; align-items: center; gap: 16px; }
.stat .ic { width: 52px; height: 52px; border-radius: 15px; display: grid; place-content: center; font-size: 24px; color: #fff; background: linear-gradient(135deg, var(--blue-500), var(--blue-700)); box-shadow: var(--glow); }
.stat .v { font-size: 24px; font-weight: 800; line-height: 1.1; }
.stat .k { color: var(--muted); font-size: 13.5px; }

/* access */
.access-list { display: flex; flex-direction: column; gap: 10px; }
.access-item { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--card-2); }
.access-item img { width: 42px; height: 42px; border-radius: 50%; }
.access-item .nm { font-weight: 700; }
.access-item .id { color: var(--muted); font-size: 12.5px; }
.badge-owner { background: #92400e; color: #fde68a; font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 20px; }

/* Skeleton */
.sk { position: relative; overflow: hidden; background: #11151f; border-radius: 8px; }
.sk::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { 100% { transform: translateX(100%); } }
.sk-card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.sk-line { height: 14px; margin-bottom: 12px; }
.sk-line.w60 { width: 60%; } .sk-line.w40 { width: 40%; } .sk-line.w80 { width: 80%; }
.sk-ctrl { height: 44px; border-radius: 12px; }

/* Toasts */
.toasts { position: fixed; bottom: 22px; inset-inline-start: 22px; z-index: 10000; display: flex; flex-direction: column; gap: 10px; }
.toast { background: #0d1018; border: 1px solid var(--line-2); border-inline-start: 4px solid var(--blue-500); border-radius: 12px; padding: 13px 18px; box-shadow: var(--shadow-lg); font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 10px; min-width: 220px; animation: toastIn .3s var(--ease); }
.toast.ok { border-inline-start-color: var(--ok); } .toast.ok i { color: var(--ok); }
.toast.err { border-inline-start-color: var(--danger); } .toast.err i { color: var(--danger); }
.toast.info i { color: var(--blue-400); }
@keyframes toastIn { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateX(-20px); opacity: 0; } }

/* مؤشرات التركيز (a11y) */
:focus-visible { outline: 3px solid var(--blue-500); outline-offset: 2px; border-radius: 6px; }
.input:focus-visible, .select:focus-visible, textarea.input:focus-visible, .picker-btn:focus-visible, .btn:focus-visible, .btn-discord:focus-visible, .nav-item:focus-visible, .icon-btn:focus-visible, .chip .x:focus-visible { outline: 3px solid var(--blue-500); outline-offset: 2px; }
.toggle input:focus-visible + .track { box-shadow: 0 0 0 4px rgba(59,130,246,.35); }

/* موبايل */
.scrim { display: none; }
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 0; height: 100vh; height: 100dvh; width: 280px; z-index: 60; transform: translateX(110%); transition: transform .3s var(--ease); inset-inline-end: 0; }
  .sidebar.open { transform: none !important; }
  .topbar .hb { display: grid; place-content: center; width: 44px; height: 44px; border-radius: 12px; background: var(--card); border: 1px solid var(--line-2); color: #cfe0ff; box-shadow: var(--shadow); }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 55; backdrop-filter: blur(2px); }
  .grid { grid-template-columns: 1fr; }
  .main { padding: 18px 16px 50px; }
}
@media (max-width: 560px) {
  .editor-row.tc, .editor-row.sm, .editor-row.lr { display: flex; flex-wrap: wrap; }
  .editor-row.tc > *, .editor-row.sm > *, .editor-row.lr > * { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .editor-row .icon-btn { flex: 1 1 100%; }
  .editor-row .picker { flex: 1 1 100%; }
  .picker-btn, .input, .select { min-height: 46px; }
  .icon-btn { min-height: 44px; }
}
@media (max-width: 480px) { .user-chip .uname { display: none; } }

/* ===== متجر/نقاط الروليت ===== */
.rp-results { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.rp-result { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 13px; background: var(--card-2); cursor: pointer; transition: .16s var(--ease); }
.rp-result:hover { border-color: var(--blue-500); transform: translateY(-1px); }
.rp-result img { width: 38px; height: 38px; border-radius: 50%; }
.rp-result .nm { font-weight: 700; }
.rp-result .id { color: var(--muted); font-size: 12px; }
.rp-card { background: linear-gradient(160deg, var(--card-2), var(--card)); border: 1px solid var(--line-2); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); }
.rp-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.rp-av { width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--blue-500); object-fit: cover; }
.rp-name { font-weight: 800; font-size: 18px; }
.rp-pts-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; }
.rp-pts-wrap .sub { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.rp-pts { font-size: 24px !important; font-weight: 800; text-align: center; }
.rp-items { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.rp-item { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.rp-emoji { font-size: 26px; display: block; }
.rp-iname { display: block; color: var(--muted); font-size: 12.5px; margin: 4px 0 6px; }
.rp-save { margin-top: 16px; width: 100%; justify-content: center; }
