:root {
  --bg: #07080f;
  --bg2: #0c0f1d;
  --panel: #111529;
  --panel2: #171c35;
  --line: #242a4a;
  --text: #e9ebf8;
  --muted: #8b91b9;
  --violet: #8b5cf6;
  --violet2: #a78bfa;
  --cyan: #22d3ee;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --grad: linear-gradient(135deg, #8b5cf6 0%, #22d3ee 100%);
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Cairo", system-ui, Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--cyan); text-decoration: none; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Logo ---------- */
.logo { display: inline-flex; align-items: center; gap: 10px; direction: ltr; }
.logo-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--grad);
  display: grid; place-items: center; box-shadow: 0 0 24px rgba(139, 92, 246, .55);
}
.logo-mark svg { width: 20px; height: 20px; }
.logo-text {
  font-family: "Orbitron", sans-serif; font-weight: 800; letter-spacing: .06em; font-size: 18px;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo.big .logo-mark { width: 56px; height: 56px; border-radius: 16px; }
.logo.big .logo-mark svg { width: 32px; height: 32px; }
.logo.big .logo-text { font-size: 34px; }

/* ---------- Buttons & fields ---------- */
.btn {
  border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; cursor: pointer;
  font-weight: 700; background: var(--panel2); transition: transform .08s, filter .15s, background .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--grad); color: #fff; box-shadow: 0 4px 18px rgba(139, 92, 246, .35); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { background: var(--red); color: #fff; }
.btn.success { background: var(--green); color: #04110a; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--panel2); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.danger-text { color: #fca5a5 !important; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea, .input {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none;
  transition: border-color .15s, box-shadow .15s; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus, .input:focus {
  border-color: var(--violet); box-shadow: 0 0 0 3px rgba(139, 92, 246, .2);
}
.field textarea { min-height: 90px; resize: vertical; }
.field small { color: var(--muted); font-size: 12px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--violet); }
.form-err, .modal-err {
  background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .4); color: #fecaca;
  padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 12px;
}

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero {
  position: relative; overflow: hidden; padding: 56px; display: flex; flex-direction: column; justify-content: center; gap: 22px;
  background: radial-gradient(800px 500px at 80% 10%, rgba(139, 92, 246, .35), transparent 60%),
              radial-gradient(700px 500px at 10% 90%, rgba(34, 211, 238, .22), transparent 60%), var(--bg2);
  border-left: 1px solid var(--line);
}
.auth-hero h1 { font-size: 34px; margin: 0; line-height: 1.3; }
.auth-hero p { color: var(--muted); margin: 0; font-size: 17px; max-width: 460px; }
.features { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 12px; }
.features li { display: flex; gap: 10px; align-items: center; }
.features li::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 10px var(--cyan); flex: none;
}
.auth-side { display: grid; place-items: center; padding: 32px 20px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 26px; box-shadow: var(--shadow);
}
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg2); border-radius: 12px; padding: 4px; margin-bottom: 22px; }
.tabs button { border: 0; background: transparent; padding: 9px; border-radius: 9px; cursor: pointer; font-weight: 700; color: var(--muted); }
.tabs button.on { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: var(--bg2); border-left: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh;
}
.side .brand { padding: 4px 8px 6px; }
.side .center-name { padding: 0 8px 14px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--muted); font-weight: 600;
  transition: background .15s, color .15s;
}
.nav a svg { width: 19px; height: 19px; flex: none; }
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.on { background: linear-gradient(90deg, rgba(139, 92, 246, .08), rgba(139, 92, 246, .22)); color: #fff; box-shadow: inset -3px 0 0 var(--violet); }
.me { border-top: 1px solid var(--line); padding: 12px 8px 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.me b { display: block; font-size: 14px; }
.me small { color: var(--muted); font-size: 12px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 0 8px 8px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.live.on i { background: var(--green); box-shadow: 0 0 8px var(--green); }

.main { padding: 26px 30px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 24px; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.page-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.loader { padding: 60px; text-align: center; color: var(--muted); }
.error-box { padding: 20px; border-radius: var(--radius); background: rgba(239, 68, 68, .1); border: 1px solid rgba(239, 68, 68, .35); }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat span { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat b { display: block; font-size: 26px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.violet b { color: var(--violet2); }
.stat.green b { color: #4ade80; }
.stat.cyan b { color: var(--cyan); }
.stat.muted b { color: var(--muted); }

/* ---------- Device cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.dev {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px;
  display: flex; flex-direction: column; gap: 10px; overflow: hidden; transition: border-color .2s, transform .15s;
}
.dev::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--line); }
.dev.free::before { background: var(--green); }
.dev.busy::before { background: var(--grad); }
.dev.busy { border-color: rgba(139, 92, 246, .45); box-shadow: 0 0 0 1px rgba(139, 92, 246, .1), 0 8px 30px rgba(139, 92, 246, .12); }
.dev.offline { opacity: .7; }
.dev.ending::before { background: var(--amber); }
.dev-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dev-name { font-weight: 800; font-size: 18px; }
.dev-tier { color: var(--muted); font-size: 13px; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px; }
.pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.free { color: #4ade80; background: rgba(34, 197, 94, .12); }
.pill.busy { color: var(--violet2); background: rgba(139, 92, 246, .15); }
.pill.offline { color: var(--muted); background: rgba(139, 145, 185, .12); }
.dev-body { min-height: 62px; display: flex; flex-direction: column; justify-content: center; }
.timer { font-family: "Orbitron", monospace; font-size: 28px; font-weight: 800; direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.dev.ending .timer { color: var(--amber); }
.dev-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.dev-meta b { color: var(--text); }
.dev-idle { color: var(--muted); font-size: 14px; }
.dev-actions { display: flex; gap: 8px; }
.dev-actions .btn { flex: 1; }
.dev-actions .btn.more { flex: 0 0 auto; padding-inline: 10px; }
.offline-note { font-size: 12px; color: var(--amber); }

/* ---------- Table ---------- */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 560px; }
.table th, .table td { padding: 12px 14px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-size: 13px; font-weight: 700; background: var(--bg2); }
.table tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.badge.ok { color: #4ade80; background: rgba(34, 197, 94, .12); }
.badge.bad { color: #fca5a5; background: rgba(239, 68, 68, .12); }
.badge.muted { color: var(--muted); background: rgba(139, 145, 185, .12); }
.badge.violet { color: var(--violet2); background: rgba(139, 92, 246, .15); }
.game-cell { display: flex; align-items: center; gap: 10px; }
.thumb {
  width: 38px; height: 38px; border-radius: 9px; background: var(--grad); display: grid; place-items: center;
  font-weight: 800; color: #fff; overflow: hidden; flex: none;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Cards / misc ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.tier-card h4 { margin: 0 0 4px; font-size: 18px; }
.tier-price { font-size: 26px; font-weight: 800; color: var(--cyan); }
.tier-price small { font-size: 13px; color: var(--muted); font-weight: 600; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.pair-code {
  font-family: "Orbitron", monospace; font-size: 40px; font-weight: 800; letter-spacing: .25em; direction: ltr; text-align: center;
  padding: 18px; border-radius: 14px; background: var(--bg2); border: 1px dashed var(--violet); margin: 12px 0;
  background-image: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.pair-box { background: var(--bg2); border-radius: 14px; border: 1px dashed var(--violet); margin: 12px 0; }
.steps { margin: 0; padding-inline-start: 20px; color: var(--muted); display: grid; gap: 6px; }
.empty { text-align: center; padding: 50px 20px; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty h3 { margin: 0 0 6px; }
.empty p { color: var(--muted); margin: 0 auto 16px; max-width: 420px; }
.range { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.range .input { width: auto; padding: 7px 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--bg2); padding: 7px 14px; border-radius: 999px; cursor: pointer; font-weight: 700; font-size: 14px;
}
.chip.on { border-color: var(--violet); background: rgba(139, 92, 246, .18); color: #fff; }
.estimate { background: var(--bg2); border-radius: 10px; padding: 12px; display: flex; justify-content: space-between; align-items: center; }
.estimate b { font-size: 20px; color: var(--cyan); }
.menu-list { display: grid; gap: 8px; }
.menu-list .btn { justify-content: flex-start; padding: 12px 14px; }

/* ---------- Modal & toast ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(3, 4, 10, .7); backdrop-filter: blur(4px); display: grid; place-items: center;
  padding: 16px; z-index: 50; animation: fade .15s ease;
}
.modal {
  width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  animation: pop .18s ease; max-height: calc(100vh - 32px); display: flex; flex-direction: column;
}
.modal.wide { max-width: 560px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.modal-head h3 { margin: 0; font-size: 19px; }
.modal-head .x { background: none; border: 0; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 12px 20px 4px; overflow-y: auto; }
.modal-err { margin: 0 20px 8px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-start; padding: 12px 20px 18px; }
.modal-foot .btn[type=submit] { flex: 1; }
#toasts { position: fixed; bottom: 20px; left: 20px; display: grid; gap: 8px; z-index: 60; }
.toast {
  background: var(--panel2); border: 1px solid var(--line); border-right: 4px solid var(--green); padding: 12px 16px; border-radius: 12px;
  box-shadow: var(--shadow); animation: pop .18s ease; max-width: 340px;
}
.toast.err { border-right-color: var(--red); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-hero { padding: 32px 22px; border-left: 0; border-bottom: 1px solid var(--line); }
  .auth-hero h1 { font-size: 24px; }
  .auth-hero .features { display: none; }
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; bottom: 0; top: auto; inset-inline: 0; height: auto; z-index: 40; flex-direction: row; padding: 6px;
    border-left: 0; border-top: 1px solid var(--line);
  }
  .side .brand, .side .center-name, .side .me, .side .live { display: none; }
  .nav { flex-direction: row; overflow-x: auto; gap: 2px; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 10px; min-width: 64px; text-align: center; }
  .nav a.on { box-shadow: inset 0 -3px 0 var(--violet); }
  .main { padding: 16px 16px 96px; }
  .mobile-top { display: flex !important; }
  .settings-grid, .row { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat { padding: 10px; }
  .stat span { font-size: 11px; }
  .stat b { font-size: 18px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .dev { padding: 12px; min-width: 0; gap: 8px; }
  .dev-name { font-size: 16px; }
  .dev-actions { gap: 6px; }
  .dev-actions .btn { padding: 7px 6px; font-size: 12px; min-width: 0; }
  .dev-idle, .dev-meta { font-size: 12px; }
  .timer { font-size: 20px; }
  .pair-code { font-size: 30px; }
}
.mobile-top { display: none; align-items: center; justify-content: space-between; margin-bottom: 14px; }

/* ---------- POS الكافتريا ---------- */
.pos { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.pos-cart { position: sticky; top: 20px; }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.item { position: relative; }
.item-main {
  width: 100%; min-height: 96px; border: 1px solid var(--line); background: var(--panel); border-radius: 14px; padding: 14px; cursor: pointer;
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; gap: 8px; text-align: right;
  transition: border-color .15s, transform .08s, background .15s;
}
.item-main:hover { border-color: var(--violet); background: var(--panel2); }
.item-main:active { transform: scale(.97); }
.item-name { font-weight: 800; font-size: 16px; }
.item-price { color: var(--cyan); font-weight: 700; font-size: 14px; }
.item-qty {
  position: absolute; top: -8px; left: -8px; min-width: 26px; height: 26px; border-radius: 13px; background: var(--grad); color: #fff;
  font-weight: 800; display: grid; place-items: center; font-size: 13px; padding: 0 6px; box-shadow: 0 4px 12px rgba(139, 92, 246, .5);
}
.item-edit { position: absolute; bottom: 8px; left: 8px; border: 0; background: var(--bg2); border-radius: 8px; padding: 4px 7px; cursor: pointer; font-size: 13px; }
.item.off .item-main { opacity: .45; cursor: not-allowed; }
.item-off { position: absolute; top: 8px; left: 8px; font-size: 11px; color: var(--muted); }
.cart-line { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cl-name { font-weight: 700; }
.cl-sum { color: var(--muted); font-size: 13px; min-width: 70px; text-align: left; }
.qty { display: inline-flex; align-items: center; gap: 6px; background: var(--bg2); border-radius: 9px; padding: 2px; }
.qty button { width: 28px; height: 28px; border: 0; border-radius: 7px; background: var(--panel2); cursor: pointer; font-weight: 800; font-size: 16px; }
.qty b { min-width: 18px; text-align: center; }
h3.sec { margin: 24px 0 10px; font-size: 18px; }
@media (max-width: 860px) {
  .pos { grid-template-columns: 1fr; }
  .pos-cart { position: static; }
  .items { grid-template-columns: repeat(2, 1fr); }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
.timer.up { color: var(--cyan); }
.open-tag { color: var(--cyan) !important; font-weight: 700; }
.chip.open-chip { border-color: rgba(34, 211, 238, .4); color: var(--cyan); }
.chip.open-chip.on { background: rgba(34, 211, 238, .16); border-color: var(--cyan); color: #fff; }

/* ---------- التحديد الجماعي ---------- */
.dev { cursor: pointer; }
.dev.picked { border-color: var(--cyan) !important; box-shadow: 0 0 0 2px rgba(34, 211, 238, .35), 0 8px 30px rgba(34, 211, 238, .15) !important; }
.dev-name { display: inline-flex; align-items: center; gap: 8px; }
.pick {
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line); background: var(--bg2); cursor: pointer;
  display: inline-grid; place-items: center; font-size: 13px; font-weight: 900; color: #04131a; padding: 0; flex: none;
}
.pick:hover { border-color: var(--cyan); }
.pick.on { background: var(--cyan); border-color: var(--cyan); }
.bulk {
  position: sticky; top: 10px; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px; padding: 12px 16px; border-radius: 14px; background: rgba(17, 21, 41, .92); backdrop-filter: blur(10px);
  border: 1px solid rgba(34, 211, 238, .45); box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
.bulk-n { color: var(--muted); font-size: 14px; }
.bulk-n b { color: var(--cyan); font-size: 17px; }
.bulk-act { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 860px) { .bulk { top: 6px; } .bulk-act { width: 100%; } .bulk-act .btn { flex: 1; } }

.img-pick { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 14px; }
.img-pick .field { margin-bottom: 8px; }
.img-prev { width: 84px; aspect-ratio: 2 / 3; border-radius: 10px; background: var(--bg2); border: 1px dashed var(--line); display: grid; place-items: center; overflow: hidden; flex: none; font-size: 26px; }
.img-prev img { width: 100%; height: 100%; object-fit: cover; }
