:root {
  --bg: #0b0f1a; --bg2: #101626; --card: #151c2f; --card2: #1b2440; --line: #242e4a;
  --text: #e8ecf8; --muted: #8b96b8;
  --brand: #6c5ce7; --brand2: #00d1ff; --ok: #1fd18a; --warn: #ffb020; --bad: #ff4d6d;
  --shadow: 0 8px 28px rgba(0,0,0,.35);
  --radius: 16px;
}
[data-theme="light"] {
  --bg: #eef1f8; --bg2: #ffffff; --card: #ffffff; --card2: #f3f5fb; --line: #dfe4f0;
  --text: #1a2038; --muted: #6a7494; --shadow: 0 6px 22px rgba(30,40,90,.10);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background-image: radial-gradient(900px 420px at 85% -80px, rgba(108,92,231,.16), transparent); background-attachment: fixed; }
body { font-family: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }
a { color: inherit; text-decoration: none; }
.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }

/* layout */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side { background: var(--bg2); border-left: 1px solid var(--line); padding: 18px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.logo .shop-name { flex: 1; min-width: 0; overflow-wrap: anywhere; line-height: 1.3; }
.iconbtn.small { width: 30px; height: 30px; border-radius: 8px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; padding: 6px 10px 18px; }
.logo .badge { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand), var(--brand2)); color: #fff; box-shadow: 0 6px 18px rgba(108,92,231,.5); }
.nav a, .nav button { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; color: var(--muted); font-weight: 600; width: 100%; background: none; border: 0; font: inherit; cursor: pointer; transition: .15s; text-align: right; }
.nav a:hover, .nav button:hover { background: var(--card2); color: var(--text); }
.nav a.active { background: linear-gradient(135deg, rgba(108,92,231,.25), rgba(0,209,255,.12)); color: var(--text); box-shadow: inset 3px 0 0 var(--brand); }
.nav form { margin: 0; }
.side .grow { flex: 1; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--bg2); position: sticky; top: 0; z-index: 20; }
.topbar h1 { font-size: 20px; margin: 0; flex: 1; }
.clock { font-variant-numeric: tabular-nums; font-weight: 700; padding: 8px 14px; border-radius: 10px; background: var(--card2); }
.search { display: flex; align-items: center; gap: 6px; background: var(--card2); border-radius: 10px; padding: 0 10px; border: 1px solid var(--line); }
.search input { background: none; border: 0; color: var(--text); width: 130px; padding: 9px 4px; outline: none; font: inherit; }
.iconbtn { background: var(--card2); border: 1px solid var(--line); color: var(--text); width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; }
.iconbtn:hover { border-color: var(--brand); }
.content { padding: 22px 24px 60px; }
.menu-toggle { display: none; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); }
.stat .ico { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; color: #fff; }
.stat .ico.a { background: linear-gradient(135deg, #6c5ce7, #a29bfe); }
.stat .ico.b { background: linear-gradient(135deg, #00b894, #1fd18a); }
.stat .ico.c { background: linear-gradient(135deg, #0984e3, #00d1ff); }
.stat .ico.d { background: linear-gradient(135deg, #e17055, #ffb020); }
.stat .ico.e { background: linear-gradient(135deg, #d63031, #ff4d6d); }
.stat small { color: var(--muted); display: block; }
.stat b { font-size: 24px; font-variant-numeric: tabular-nums; }

/* device cards */
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 14px; }
.dev { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; transition: transform .15s, border-color .2s; }
.dev:hover { transform: translateY(-3px); }
.dev::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--line); }
.dev.busy::before { background: linear-gradient(90deg, var(--ok), var(--brand2)); }
.dev.over { border-color: var(--bad); animation: pulse 1s infinite; }
.dev.over::before { background: var(--bad); }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(255,77,109,.28); } }
.dev header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.dno { font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.chip { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px; background: var(--card2); color: var(--muted); }
.chip.on { background: rgba(31,209,138,.16); color: var(--ok); }
.chip.multi { background: rgba(108,92,231,.2); color: #a29bfe; }
.ring-wrap { position: relative; width: 140px; height: 140px; margin: 4px auto 8px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; }
.ring .bg { stroke: var(--card2); }
.ring .fg { stroke: url(#grad); stroke-linecap: round; transition: stroke-dashoffset .9s linear; }
.dev.over .ring .fg { stroke: var(--bad); }
.ring-txt { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-txt b { font-size: 21px; font-variant-numeric: tabular-nums; }
.ring-txt small { color: var(--muted); font-size: 12px; }
.meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--card2); border-radius: 12px; padding: 10px 6px; text-align: center; margin-bottom: 12px; }
.meta span { display: block; font-size: 11px; color: var(--muted); }
.meta b { font-variant-numeric: tabular-nums; }
.meta .sum { color: var(--ok); }
.who { font-size: 13px; color: var(--muted); margin: 0 0 10px; text-align: center; height: 20px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dev .actions, .dev > .btn.block { margin-top: auto; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .btn { min-width: 0; padding: 10px 6px; white-space: nowrap; }
.free-art { flex: 1; min-height: 110px; display: grid; place-items: center; color: var(--line); }
.free-art .i { width: 72px; height: 72px; stroke-width: 1.2; }
.rates { display: flex; justify-content: center; gap: 8px; margin-bottom: 12px; font-size: 12px; color: var(--muted); }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; transition: .15s; }
.btn:hover { border-color: var(--brand); transform: translateY(-1px); }
.btn.primary { background: linear-gradient(135deg, var(--brand), #8e7bff); border-color: transparent; color: #fff; box-shadow: 0 6px 16px rgba(108,92,231,.4); }
.btn.success { background: linear-gradient(135deg, #12b886, var(--ok)); border-color: transparent; color: #04271b; }
.btn.danger { background: linear-gradient(135deg, #e63757, var(--bad)); border-color: transparent; color: #fff; }
.btn.small { padding: 5px 12px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
input, select, textarea { background: var(--card2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; width: 100%; outline: none; }
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(108,92,231,.25); }
input[type=checkbox] { width: auto; accent-color: var(--brand); }
label { display: block; font-weight: 700; font-size: 13px; margin: 10px 0 5px; color: var(--muted); }
.errorlist { color: var(--bad); list-style: none; padding: 0; margin: 4px 0; font-size: 13px; }

/* panels & tables */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 14px; font-size: 17px; }
.inline { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.inline > div { flex: 1 1 150px; }
.inline > div label { margin-top: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { color: var(--muted); font-size: 13px; text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: right; }
tr:hover td { background: rgba(108,92,231,.06); }
td form { margin: 0; display: inline; }
.low td { background: rgba(255,77,109,.1); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.cards .stat { display: block; }
.cards .stat b { display: block; margin-top: 4px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(5,8,18,.7); backdrop-filter: blur(5px); display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal.show { display: flex; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; width: min(560px, 100%); max-height: 92vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.5); animation: pop .2s; }
.modal-card.wide { width: min(820px, 100%); }
@keyframes pop { from { transform: translateY(14px) scale(.97); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 18px 20px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg input { display: none; }
.seg label { margin: 0; text-align: center; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2); cursor: pointer; color: var(--text); }
.seg input:checked + label { background: linear-gradient(135deg, var(--brand), #8e7bff); color: #fff; border-color: transparent; }
.seg small { display: block; opacity: .8; font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 8px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--card2); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }
.chips button.on { background: var(--brand2); color: #02222b; border-color: transparent; }
.sum-list { background: var(--card2); border-radius: 14px; padding: 6px 16px; margin-bottom: 14px; }
.sum-list div { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.sum-list div:last-child { border: 0; font-size: 20px; font-weight: 800; color: var(--ok); }

/* orders panel */
.prods { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-bottom: 16px; }
.prod { background: var(--card2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 8px; cursor: pointer; text-align: center; color: var(--text); font: inherit; transition: .15s; }
.prod:hover { border-color: var(--brand); transform: translateY(-2px); }
.prod b { display: block; }
.prod span { color: var(--ok); font-weight: 700; font-size: 13px; }
.prod small { display: block; color: var(--muted); font-size: 11px; }
.prod.out { opacity: .4; pointer-events: none; }
.alert { background: rgba(255,77,109,.14); color: var(--bad); padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-weight: 700; }

/* toasts */
.toasts { position: fixed; bottom: 20px; left: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: var(--card); border: 1px solid var(--line); border-right: 4px solid var(--brand); border-radius: 12px; padding: 12px 16px; box-shadow: var(--shadow); min-width: 240px; animation: pop .25s; font-weight: 600; }
.toast.error { border-right-color: var(--bad); }
.toast.success { border-right-color: var(--ok); }
.toast.warn { border-right-color: var(--warn); }

/* invoice */
.receipt { max-width: 440px; margin: 0 auto; }
.receipt .head { text-align: center; padding-bottom: 12px; border-bottom: 2px dashed var(--line); margin-bottom: 12px; }
.receipt .head h2 { margin: 6px 0 2px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(900px 500px at 80% -10%, rgba(108,92,231,.35), transparent), radial-gradient(700px 400px at 0% 110%, rgba(0,209,255,.2), transparent), var(--bg); }
.login-card { width: min(400px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-card .logo { justify-content: center; flex-direction: column; padding-bottom: 20px; }

@media (max-width: 900px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat { padding: 12px; gap: 10px; }
  .stat b { font-size: 20px; }
  .devices { grid-template-columns: 1fr 1fr; gap: 10px; }
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; right: 0; top: 0; z-index: 90; width: 260px; transform: translateX(100%); transition: .2s; }
  .side.open { transform: none; box-shadow: -10px 0 40px rgba(0,0,0,.5); }
  .menu-toggle { display: grid; }
  .content { padding: 16px 14px 60px; }
  .topbar { padding: 12px 14px; }
  .clock, .search { display: none; }
}
@media print {
  .side, .topbar, .noprint, .toasts { display: none !important; }
  .app { display: block; }
  body { background: #fff; color: #000; }
  .panel { box-shadow: none; border: 0; }
  :root { --text: #000; --muted: #444; --card: #fff; --card2: #f3f3f3; --line: #ccc; }
}

@media (max-width: 520px) { .devices { grid-template-columns: 1fr; } }

.trial-badge { display: inline-block; background: rgba(255,176,32,.16); color: var(--warn); border: 1px solid rgba(255,176,32,.4); padding: 4px 12px; border-radius: 99px; font-size: 13px; font-weight: 700; white-space: nowrap; }
@media (max-width: 900px) { .topbar .trial-badge { font-size: 11px; padding: 3px 8px; } }

/* ---- تنبيه انتهاء الوقت: فلاشر + أزرار الصوت/الفلاشر ---- */
.flasher { position: fixed; inset: 0; z-index: 200; pointer-events: none; opacity: 0; background: radial-gradient(circle at center, rgba(255,77,109,.25), rgba(255,77,109,.65)); }
.flasher.go { animation: flasher .9s ease-out; }
@keyframes flasher { 0% { opacity: 0; } 12% { opacity: .9; } 28% { opacity: .1; } 44% { opacity: .8; } 100% { opacity: 0; } }
body.no-flash .dev.over { animation: none; }
.iconbtn.off { opacity: .6; color: var(--muted); }
@media print { .flasher { display: none !important; } }
@media (prefers-reduced-motion: reduce) { .flasher.go { animation-duration: 1.6s; } }
.audio-banner { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 300; background: var(--warn, #f5a623); color: #1b1300; border: 0; border-radius: 999px; padding: 10px 20px; font: inherit; font-weight: 700; cursor: pointer; box-shadow: 0 6px 24px rgba(0,0,0,.4); animation: pop .3s; }
