:root {
  --bg-0: #0b1020;
  --bg-1: #131a33;
  --card: rgba(255, 255, 255, 0.055);
  --card-border: rgba(255, 255, 255, 0.1);
  --text: #f1f5ff;
  --muted: #9aa3c0;
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --danger: #f87171;
  --ok: #34d399;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(2, 6, 23, 0.55);
}

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

html, body { min-height: 100%; }

body {
  font-family: "Tajawal", "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 85% -10%, #1e1b4b 0%, transparent 55%),
    radial-gradient(1000px 700px at -10% 110%, #0c4a6e 0%, transparent 50%), var(--bg-0);
  color: var(--text);
  min-height: 100vh;
}

.bg-glow {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(600px 400px at 50% 0%, rgba(139, 92, 246, 0.14), transparent 70%);
}

.container { max-width: 980px; margin: 0 auto; padding: 28px 18px 90px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; gap: 12px; flex-wrap: wrap;
  background: rgba(11, 16, 32, 0.72);
  border-bottom: 1px solid var(--card-border);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { display: grid; place-items: center; filter: drop-shadow(0 4px 14px rgba(139,92,246,.5)); }
.brand-name { font-size: 1.25rem; font-weight: 800; letter-spacing: 0.2px; }
.brand-name b { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.top-actions { display: flex; gap: 10px; }

/* ---------- Buttons ---------- */
.btn {
  border: 0; cursor: pointer; border-radius: 12px;
  padding: 10px 18px; font-family: inherit; font-size: 0.95rem; font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  box-shadow: 0 10px 26px rgba(124, 58, 237, 0.4);
}
.btn-primary:hover { box-shadow: 0 14px 32px rgba(124, 58, 237, 0.55); }
.btn-ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--card-border);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.14); }
.btn-danger { background: rgba(248, 113, 113, 0.15); color: var(--danger); border: 1px solid rgba(248,113,113,.3); }
.btn-danger:hover { background: rgba(248, 113, 113, 0.25); }
.btn-sm { padding: 7px 13px; font-size: 0.85rem; border-radius: 10px; }
.btn-block { width: 100%; margin-top: 6px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- Views & Cards ---------- */
.view { animation: fadeUp 0.35s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.login-card { max-width: 400px; margin: 9vh auto 0; padding: 34px; display: grid; gap: 14px; }
.login-card h1 { font-size: 1.6rem; font-weight: 900; }
.muted { color: var(--muted); font-size: 0.95rem; line-height: 1.7; }
code { background: rgba(255,255,255,.08); padding: 2px 7px; border-radius: 6px; font-size: 0.85em; direction: ltr; display: inline-block; }

input, textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.22);
}
textarea { resize: vertical; }

.error { color: var(--danger); font-size: 0.9rem; }

.login-hint,
.edit-note {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px dashed var(--card-border);
  border-radius: 12px;
  background: rgba(139, 92, 246, 0.08);
  font-size: 0.85rem;
  color: var(--muted);
}
.login-hint code,
.edit-note code {
  font-family: ui-monospace, Consolas, monospace;
  direction: ltr;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
}
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.hidden { display: none !important; }

/* ---------- Upload panel ---------- */
#upload-panel { margin-bottom: 26px; padding: 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-head h2 { font-size: 1.25rem; font-weight: 800; }

.upload-form { display: grid; gap: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 6px; }
.field span { font-size: 0.82rem; font-weight: 700; color: var(--muted); }

.dropzone {
  display: grid; place-items: center; gap: 6px;
  border: 1.5px dashed rgba(139, 92, 246, 0.5);
  border-radius: 14px;
  padding: 18px 10px;
  cursor: pointer;
  text-align: center;
  min-height: 96px;
  background: rgba(139, 92, 246, 0.06);
  transition: border 0.15s, background 0.15s;
}
.dropzone:hover { border-color: var(--accent-2); background: rgba(34, 211, 238, 0.07); }
.dropzone input[type="file"] { display: none; }
.dz-icon { font-size: 1.7rem; }
.dz-icon img { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; box-shadow: 0 6px 18px rgba(0,0,0,.4); }
.dz-text { font-size: 0.85rem; color: var(--muted); font-weight: 600; }

/* ---------- App list ---------- */
.app-list { display: grid; gap: 14px; }
.app-card {
  display: grid; grid-template-columns: auto 1fr auto; gap: 16px;
  align-items: center;
  padding: 16px 18px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
  animation: fadeUp 0.3s ease;
}
.app-card:hover { transform: translateY(-2px); border-color: rgba(139, 92, 246, 0.45); background: rgba(255, 255, 255, 0.075); }
.app-icon {
  width: 62px; height: 62px; border-radius: 15px; object-fit: cover;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
}
.app-info { min-width: 0; }
.app-info h3 { font-size: 1.08rem; font-weight: 800; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge {
  font-size: 0.7rem; font-weight: 800; padding: 2px 9px; border-radius: 999px;
  background: rgba(139, 92, 246, 0.18); color: #c4b5fd; white-space: nowrap;
}
.app-meta { margin-top: 5px; font-size: 0.83rem; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }
.app-desc {
  margin-top: 8px; font-size: 0.88rem; color: #c6cce0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.app-actions { display: flex; flex-direction: column; gap: 8px; }
.app-actions .row { display: flex; gap: 8px; justify-content: flex-end; }

.empty-state { text-align: center; padding: 70px 20px; }
.empty-icon { font-size: 3.4rem; margin-bottom: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #e2e8f0;
  padding: 13px 26px; border-radius: 14px;
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  font-weight: 700; z-index: 50;
  animation: fadeUp 0.25s ease;
}

@media (max-width: 640px) {
  .field-row { grid-template-columns: 1fr; }
  .app-card { grid-template-columns: auto 1fr; }
  .app-actions { grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; }
}

/* ---------- التبويبات ---------- */
.tabs { display: flex; gap: 8px; margin: 4px 0 18px; }
.tab {
  background: rgba(148, 163, 184, 0.08); color: var(--muted);
  border: 1px solid var(--card-border); border-radius: 12px;
  padding: 9px 20px; font: inherit; font-weight: 700; cursor: pointer;
  transition: all 0.15s ease;
}
.tab:hover { color: #e2e8f0; border-color: rgba(139, 92, 246, 0.5); }
.tab.active {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.25), rgba(34, 211, 238, 0.18));
  color: #fff; border-color: rgba(139, 92, 246, 0.6);
}

/* ---------- تحذير SMTP ---------- */
.smtp-warning {
  background: rgba(251, 191, 36, 0.12); border: 1px solid rgba(251, 191, 36, 0.35);
  color: #fde68a; border-radius: 14px; padding: 13px 18px;
  font-size: 0.92rem; line-height: 1.8; margin-bottom: 18px;
}
.smtp-warning code { color: #fff; background: rgba(0,0,0,.3); padding: 2px 7px; border-radius: 7px; font-size: 0.82rem; }

/* ---------- بطاقات الإحصاء ---------- */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card {
  background: rgba(148, 163, 184, 0.06); border: 1px solid var(--card-border);
  border-radius: 16px; padding: 16px 14px; text-align: center;
}
.stat-num { display: block; font-size: 1.9rem; font-weight: 900; color: #fff; }
.stat-label { font-size: 0.8rem; color: var(--muted); margin-top: 3px; }
.stat-card.ok .stat-num { color: #4ade80; }
.stat-card.warn .stat-num { color: #fbbf24; }
.stat-card.bad .stat-num { color: #f87171; }

/* ---------- جدول الأجهزة ---------- */
.table-wrap { overflow-x: auto; background: rgba(148, 163, 184, 0.05); border: 1px solid var(--card-border); border-radius: 16px; }
.dev-table { width: 100%; border-collapse: collapse; min-width: 820px; }
.dev-table th, .dev-table td {
  padding: 12px 14px; text-align: right; font-size: 0.85rem; vertical-align: middle;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}
.dev-table thead th {
  font-size: 0.78rem; color: var(--muted); font-weight: 800;
  background: rgba(148, 163, 184, 0.06); white-space: nowrap;
}
.dev-table tbody tr:last-child td { border-bottom: none; }
.dev-table tbody tr:hover { background: rgba(139, 92, 246, 0.06); }
.mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 0.72rem; direction: ltr; }

.badge-ok { background: rgba(34, 197, 94, 0.16); color: #4ade80; }
.badge-warn { background: rgba(251, 191, 36, 0.16); color: #fbbf24; }
.badge-bad { background: rgba(248, 113, 113, 0.16); color: #f87171; }

.btn-ok {
  background: rgba(34, 197, 94, 0.14); color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.35);
}
.btn-ok:hover { background: rgba(34, 197, 94, 0.24); }
.btn-warn {
  background: rgba(251, 191, 36, 0.14); color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.35);
}
.btn-warn:hover { background: rgba(251, 191, 36, 0.24); }

.dl-details summary { cursor: pointer; color: #67e8f9; font-weight: 700; white-space: nowrap; }
.dl-list { margin: 8px 0 2px; padding: 0 0 0 0; list-style: none; font-size: 0.82rem; color: #c6cce0; }
.dl-list li { padding: 4px 8px; border-right: 2px solid rgba(139, 92, 246, 0.5); margin-bottom: 4px; background: rgba(148,163,184,.06); border-radius: 6px; }

.center-pad { text-align: center; padding: 30px; }