/* ============================================================
   نظام الكشوفات — التنسيق العام (RTL / عربي)
   ============================================================ */
:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --card: #1e293bcc;
  --card-solid: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-d: #4f46e5;
  --success: #22c55e;
  --success-d: #16a34a;
  --danger: #ef4444;
  --warning: #f59e0b;
  --gold: #fbbf24;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: "Tajawal", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 100% -10%, #312e81 0%, transparent 50%),
              radial-gradient(900px 500px at -10% 110%, #134e4a 0%, transparent 45%),
              var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body { display: flex; flex-direction: column; min-height: 100vh; }

a { color: var(--primary); text-decoration: none; }

/* -------- الهيدر -------- */
.appbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px;
  background: #0f172acc; backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.appbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.appbar .brand .logo {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), #0ea5e9);
  display: grid; place-items: center; font-size: 20px; box-shadow: var(--shadow);
}
.appbar .sub { color: var(--muted); font-size: .78rem; font-weight: 500; }

/* -------- الحاوية -------- */
.container { width: 100%; max-width: 920px; margin: 0 auto; padding: 18px; flex: 1; }
.center-screen { display: grid; place-items: center; min-height: 100vh; padding: 18px; }

/* -------- البطاقات -------- */
.card {
  background: var(--card); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card h2 { font-size: 1.1rem; margin-bottom: 4px; }
.card .hint { color: var(--muted); font-size: .85rem; margin-bottom: 16px; }

/* -------- النماذج -------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 13px 14px; font-family: inherit; font-size: 1rem;
  color: var(--text); background: #0f172a; border: 1px solid var(--border);
  border-radius: 12px; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .2);
}
textarea { resize: vertical; min-height: 70px; }

/* -------- الأزرار -------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; font-family: inherit; font-size: .98rem; font-weight: 700;
  border: none; border-radius: 12px; cursor: pointer; color: #fff;
  background: var(--primary); transition: transform .08s, filter .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.success { background: var(--success); }
.btn.danger  { background: var(--danger); }
.btn.warning { background: var(--warning); color: #1f2937; }
.btn.ghost   { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.sm { padding: 8px 12px; font-size: .85rem; border-radius: 10px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* -------- الشارات والحالات -------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700;
}
.badge.green  { background: #052e16; color: #4ade80; }
.badge.gray   { background: #1f2937; color: #9ca3af; }
.badge.amber  { background: #422006; color: #fbbf24; }
.badge.blue   { background: #172554; color: #60a5fa; }
.badge.red    { background: #450a0a; color: #f87171; }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.on  { background: var(--success); box-shadow: 0 0 8px var(--success); }
.dot.off { background: var(--muted); }

/* -------- شبكة الإحصائيات -------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat {
  background: var(--card-solid); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; text-align: center;
}
.stat .num { font-size: 1.8rem; font-weight: 800; color: #fff; }
.stat .lbl { color: var(--muted); font-size: .8rem; margin-top: 4px; }

/* -------- قائمة الكشوفات -------- */
.survey {
  background: var(--card-solid); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; margin-bottom: 14px;
}
.survey .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.survey .title { font-weight: 800; font-size: 1.05rem; }
.survey .meta { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 12px 0; color: var(--muted); font-size: .88rem; }
.survey .meta b { color: var(--text); font-weight: 700; }

/* -------- قائمة الترتيب (السباق) -------- */
.queue { list-style: none; }
.queue li {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border: 1px solid var(--border); border-radius: 12px;
  margin-bottom: 8px; background: #0f172a;
}
.queue li.leader { border-color: var(--gold); background: #1c1917; }
.queue .rank {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: .85rem; background: var(--bg-soft); color: var(--muted); flex-shrink: 0;
}
.queue li.leader .rank { background: var(--gold); color: #1f2937; }
.queue .who { flex: 1; min-width: 0; }
.queue .who .nm { font-weight: 700; }
.queue .who .sm { color: var(--muted); font-size: .78rem; }

/* -------- العدّاد -------- */
.countdown { font-variant-numeric: tabular-nums; font-weight: 800; }

/* -------- الإشعار العائم (toast) -------- */
.toast-wrap {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 10px; width: calc(100% - 36px); max-width: 420px;
}
.toast {
  background: var(--card-solid); border: 1px solid var(--border); border-right: 4px solid var(--primary);
  border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow);
  animation: slideUp .3s ease;
}
.toast.success { border-right-color: var(--success); }
.toast.error   { border-right-color: var(--danger); }
.toast .t { font-weight: 700; margin-bottom: 2px; }
.toast .d { color: var(--muted); font-size: .85rem; }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

/* -------- النوافذ المنبثقة -------- */
.modal-bg {
  position: fixed; inset: 0; background: #000a; backdrop-filter: blur(4px);
  display: none; place-items: center; z-index: 90; padding: 18px;
}
.modal-bg.open { display: grid; }
.modal { width: 100%; max-width: 460px; max-height: 88vh; overflow: auto; }

/* -------- التبويبات -------- */
.tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.tab {
  padding: 10px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); cursor: pointer; font-family: inherit; font-weight: 700; font-size: .9rem;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* -------- مساعدات -------- */
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty .ico { font-size: 2.5rem; opacity: .5; }
.hidden { display: none !important; }
.spinner {
  width: 40px; height: 40px; border: 4px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 1s linear infinite; margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.install-banner {
  display: none; align-items: center; gap: 12px; justify-content: space-between;
  background: var(--card-solid); border: 1px solid var(--primary); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 16px;
}
.install-banner.show { display: flex; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 10px; text-align: right; border-bottom: 1px solid var(--border); font-size: .9rem; }
th { color: var(--muted); font-weight: 700; font-size: .82rem; }
.table-wrap { overflow-x: auto; }

@media (max-width: 560px) {
  .card { padding: 16px; }
  .survey .top { flex-direction: column; }
}
