/* ===== التحكّم عن بُعد — واجهة حديثة (داكنة، RTL) ===== */
:root {
  --bg: #0b1020;
  --bg2: #0e1430;
  --card: rgba(22, 28, 54, 0.72);
  --card-solid: #141a36;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef1fb;
  --muted: #9aa4c7;
  --accent: #6d8bff;
  --accent2: #9b6dff;
  --accent-grad: linear-gradient(135deg, #6d8bff, #9b6dff);
  --ok: #37d39a;
  --err: #ff6b7d;
  --warn: #ffcf6b;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: 'Tajawal', system-ui, 'Segoe UI', Tahoma, sans-serif;
  background: radial-gradient(1200px 700px at 80% -10%, #16205a 0%, transparent 55%),
              radial-gradient(900px 600px at 0% 0%, #2a1550 0%, transparent 45%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* توهّج خلفي متحرّك خفيف */
.aurora {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(600px 300px at 20% 110%, rgba(109,139,255,.18), transparent 60%),
              radial-gradient(500px 300px at 90% 100%, rgba(155,109,255,.15), transparent 60%);
  filter: blur(4px);
}

/* شريط علوي */
.appbar {
  display: flex; align-items: center; justify-content: center;
  padding: 18px 16px; position: sticky; top: 0; z-index: 10;
  background: linear-gradient(to bottom, rgba(11,16,32,.85), rgba(11,16,32,0));
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent-grad); color: #fff; font-size: 22px; font-weight: 800;
  box-shadow: 0 8px 24px rgba(109,139,255,.45);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 18px; font-weight: 800; }
.brand-text span { font-size: 12px; color: var(--muted); }

/* الحاوية */
.wrap { max-width: 880px; margin: 8px auto 60px; padding: 0 16px; }

/* البطاقات */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  padding: 22px; margin: 16px 0;
  animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.card.auth { max-width: 420px; margin-inline: auto; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h2 { margin: 0; font-size: 19px; font-weight: 800; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

h1 { font-weight: 800; }
.hint, .sub { color: var(--muted); font-size: 13px; margin: 8px 0; }

/* التبويبات (دخول/حساب جديد) */
.seg {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 18px;
  background: rgba(0,0,0,.25); border: 1px solid var(--border); border-radius: 12px;
}
.seg-btn {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 10px; border-radius: 9px; font: inherit; font-weight: 700; cursor: pointer;
  transition: .2s;
}
.seg-btn.active { background: var(--accent-grad); color: #fff; box-shadow: 0 6px 18px rgba(109,139,255,.4); }

/* الحقول */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field.inline { display: flex; gap: 8px; align-items: center; }
.field.inline input { flex: 1; }

input, select {
  width: 100%; padding: 12px 14px; font: inherit; color: var(--text);
  background: rgba(0,0,0,.28); border: 1px solid var(--border-strong);
  border-radius: 11px; outline: none; transition: .2s;
}
input::placeholder { color: #6b74a0; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109,139,255,.22); }
select { cursor: pointer; }
option { background: var(--card-solid); }

/* الأزرار */
button { font-family: inherit; }
.btn-primary {
  width: 100%; border: 0; cursor: pointer; color: #fff; font-weight: 800; font-size: 15px;
  padding: 13px 18px; border-radius: 12px; background: var(--accent-grad);
  box-shadow: 0 10px 26px rgba(109,139,255,.4); transition: transform .12s, filter .2s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary.sm, .ghost.sm, .danger.sm { width: auto; padding: 9px 14px; font-size: 13px; border-radius: 10px; }
a.btn-primary { display: inline-flex; align-items: center; text-decoration: none; }

.ghost {
  border: 1px solid var(--border-strong); background: rgba(255,255,255,.04); color: var(--text);
  padding: 11px 16px; border-radius: 11px; cursor: pointer; font-weight: 600; transition: .15s;
}
.ghost:hover { background: rgba(255,255,255,.1); border-color: var(--accent); }
.ghost:disabled { opacity: .45; cursor: not-allowed; }

.danger {
  border: 1px solid rgba(255,107,125,.5); background: rgba(255,107,125,.14); color: #ffd9de;
  padding: 11px 16px; border-radius: 11px; cursor: pointer; font-weight: 700; transition: .15s;
}
.danger:hover { background: rgba(255,107,125,.25); }

.auth-foot { text-align: center; margin-top: 12px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* الرسائل */
.msg { margin-top: 12px; font-size: 14px; min-height: 18px; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--err); }

/* الألواح الداخلية */
.panel {
  margin-top: 16px; padding: 16px; border: 1px solid var(--border);
  border-radius: 13px; background: rgba(0,0,0,.18);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; margin-bottom: 10px; }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  background: rgba(255,255,255,.08); color: var(--muted);
}
.chip.on { background: rgba(55,211,154,.18); color: var(--ok); }
.chip.off { background: rgba(255,207,107,.16); color: var(--warn); }

/* إعداد 2FA */
.twofa-setup { margin-top: 14px; }
.twofa-setup .qr { margin: 10px 0; }
.twofa-setup .qr img { background: #fff; padding: 10px; border-radius: 12px; width: 180px; height: 180px; }
.secret { font-size: 13px; color: var(--muted); margin: 8px 0; }
.secret code {
  background: rgba(0,0,0,.35); padding: 4px 8px; border-radius: 7px; color: var(--text);
  user-select: all; font-size: 13px; letter-spacing: 1px;
}

/* قائمة الأجهزة */
.device {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; margin: 10px 0; border: 1px solid var(--border);
  border-radius: 13px; background: rgba(255,255,255,.03); transition: .15s;
}
.device:hover { border-color: var(--border-strong); background: rgba(255,255,255,.05); }
.device > span:first-child { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 4px rgba(255,255,255,.04); }
.dot.on { background: var(--ok); box-shadow: 0 0 10px var(--ok), 0 0 0 4px rgba(55,211,154,.15); }
.dot.off { background: #6b7299; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions button { padding: 9px 14px; border-radius: 10px; font-size: 13px; }

/* سجلّ الجلسات */
.session-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.session-row:last-child { border-bottom: 0; }
.session-name { font-weight: 700; }
.session-when { color: var(--muted); font-size: 12px; }
.session-dur { color: var(--muted); font-variant-numeric: tabular-nums; }
.session-dur.ongoing { color: var(--ok); font-weight: 700; }

/* جلسة التحكّم */
.sess-title { display: flex; align-items: baseline; gap: 10px; }
.sess-title strong { font-size: 17px; font-weight: 800; }
.session-timer { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.session-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.quality-sel { width: auto; padding: 8px 12px; font-size: 13px; }

#stage {
  position: relative; margin: 14px 0 10px; border-radius: 14px; overflow: hidden;
  background: #05070f; border: 1px solid var(--border);
  min-height: 160px; display: grid; place-items: center;
}
#remoteScreen { display: block; max-width: 100%; max-height: 72vh; width: auto; height: auto; }
.badge {
  position: absolute; top: 10px; inset-inline-start: 10px; z-index: 2;
  background: rgba(0,0,0,.6); color: #fff; padding: 7px 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; backdrop-filter: blur(4px);
  border: 1px solid var(--border-strong); max-width: calc(100% - 20px);
}
.stats { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.devinfo { font-size: 12.5px; color: var(--muted); margin: 6px 0; line-height: 1.9; }

/* أشرطة الأدوات */
.navbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.navbar .ghost { padding: 10px 14px; font-size: 13px; }
#navbar2 .ghost, #navbar3 .ghost { background: rgba(255,255,255,.02); }

#recBtn.recording { color: #fff; background: #c0392b; border-color: #c0392b; animation: recPulse 1.2s ease-in-out infinite; }
@keyframes recPulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

.kb-input { position: absolute; opacity: 0; height: 1px; width: 1px; pointer-events: none; }

.hidden { display: none !important; }

/* موبايل */
@media (max-width: 640px) {
  .wrap { padding: 0 12px; }
  .card { padding: 16px; }
  .head-actions { width: 100%; }
  .head-actions > * { flex: 1 1 auto; justify-content: center; text-align: center; }
  .navbar .ghost { flex: 1 1 auto; min-height: 46px; }
  .session-controls { width: 100%; }
  .session-controls .quality-sel { flex: 1 1 auto; }
  button, input, select { min-height: 46px; }
  .session-row { grid-template-columns: 1fr auto; }
  .session-when { display: none; }
}

/* شريط الإحصاءات + المخطّط */
.statsbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stat-graph { height: 38px; max-width: 240px; opacity: .9; }
.ghost.active { background: var(--accent-grad); color: #fff; border-color: transparent; }
#stage.zooming { cursor: grab; }
#stage.zooming:active { cursor: grabbing; }
#remoteScreen { transition: transform .05s linear; will-change: transform; }

/* ضيف «عرض فقط»: أخفِ أدوات التحكّم */
body.guest-view #navbar,
body.guest-view #navbar2,
body.guest-view #navbar3,
body.guest-view #qualitySel { display: none !important; }
body.guest .card-head .session-controls #endBtn { display: inline-flex; }
