/* المراقب الإبداعي — التصميم الرئيسي */
:root {
  --brand: #4A248E;
  --brand-2: #5B2C9D;
  --brand-3: #7B4BC4;
  --brand-soft: #F0E8FA;
  --brand-soft-2: #E8D9F8;
  --ink: #1F1635;
  --muted: #6B6480;
  --line: #E8E4F0;
  --bg: #F5F3F9;
  --card: #FFFFFF;
  --success: #1FA97A;
  --success-bg: #E8F8F1;
  --warning: #E8A317;
  --warning-bg: #FFF6E0;
  --danger: #E0455F;
  --danger-bg: #FDECEE;
  --info: #3B82F6;
  --info-bg: #EAF2FF;
  --orange: #F97316;
  --sidebar-w: 280px;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 8px 24px rgba(74, 36, 142, 0.06);
  --shadow-sm: 0 2px 10px rgba(31, 22, 53, 0.05);
  --font: "IBM Plex Sans Arabic", "Tahoma", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(123, 75, 196, 0.12), transparent 55%),
    radial-gradient(900px 500px at 0% 100%, rgba(74, 36, 142, 0.08), transparent 50%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.6;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
img { max-width: 100%; display: block; }
svg { width: 1.15em; height: 1.15em; display: block; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, #3B1A75 0%, #4A248E 45%, #5B2C9D 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}
.brand { display: flex; gap: .85rem; align-items: center; padding: .5rem .65rem 1.25rem; }
.brand-logo {
  width: 46px; height: 46px; border-radius: 14px;
  background: rgba(255,255,255,.14);
  display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
.brand-logo svg { width: 26px; height: 26px; color: #fff; }
.brand strong { display: block; font-size: .95rem; line-height: 1.35; }
.brand small { opacity: .7; font-size: .75rem; }

.side-nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; overflow: auto; }
.nav-link {
  display: flex; align-items: center; gap: .75rem;
  padding: .78rem .9rem; border-radius: 12px;
  color: rgba(255,255,255,.82); transition: .2s ease;
}
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 #fff; }
.nav-ico { width: 22px; display: grid; place-items: center; opacity: .95; }
.side-footer { margin-top: auto; padding-top: 1rem; display: grid; gap: .75rem; }
.cta-card {
  display: flex; align-items: center; gap: .6rem; justify-content: center;
  background: rgba(255,255,255,.12); border-radius: 14px; padding: .9rem;
  font-weight: 600;
}
.cta-card.solid { display: block; text-align: center; background: rgba(255,255,255,.14); }
.cta-card.solid p { margin: 0 0 .6rem; font-size: .9rem; }
.nav-link.logout { opacity: .85; }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.5rem; position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(245, 243, 249, .85);
  border-bottom: 1px solid rgba(232, 228, 240, .8);
}
.topbar-search {
  flex: 1; max-width: 420px; position: relative;
}
.topbar-search input {
  width: 100%; border: 1px solid var(--line); background: #fff;
  border-radius: 999px; padding: .7rem 1rem .7rem 2.6rem; outline: none;
}
.topbar-search input:focus { border-color: var(--brand-3); box-shadow: 0 0 0 3px rgba(123,75,196,.15); }
.search-icon { position: absolute; right: 1rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: .65rem; margin-inline-start: auto; }
.select-pill {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: .55rem .9rem; color: var(--ink); cursor: pointer;
}
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; display: grid; place-items: center; cursor: pointer; position: relative; color: var(--ink);
}
.icon-btn .dot {
  position: absolute; top: -4px; left: -4px;
  background: var(--danger); color: #fff; font-size: .65rem; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 999px; display: grid; place-items: center;
}
.user-chip { display: flex; align-items: center; gap: .65rem; }
.user-chip img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; box-shadow: var(--shadow-sm); }
.user-chip strong { display: block; font-size: .88rem; line-height: 1.2; }
.user-chip small { color: var(--muted); font-size: .72rem; }
.mobile-menu { display: none; }
.sidebar-backdrop { display: none; }

.page-content { padding: 1.25rem 1.5rem 2rem; }

.page-head { margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; font-size: 1.55rem; }
.page-head p { margin: .35rem 0 0; color: var(--muted); }

.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow-sm); border: 1px solid rgba(232,228,240,.8);
  display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start;
  transition: transform .2s ease, box-shadow .2s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card .label { color: var(--muted); font-size: .85rem; margin: 0 0 .35rem; }
.stat-card .value { font-size: 1.55rem; font-weight: 700; margin: 0; line-height: 1.2; }
.stat-card .meta { color: var(--muted); font-size: .78rem; margin-top: .35rem; }
.stat-card .delta { font-size: .78rem; font-weight: 600; margin-top: .35rem; }
.stat-card .delta.up { color: var(--success); }
.stat-card .delta.down { color: var(--orange); }
.stat-ico {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; flex-shrink: 0;
}
.stat-ico.purple { background: var(--brand-soft); color: var(--brand); }
.stat-ico.green { background: var(--success-bg); color: var(--success); }
.stat-ico.orange { background: #FFF0E6; color: var(--orange); }
.stat-ico.blue { background: var(--info-bg); color: var(--info); }
.stat-ico.pink { background: #FDE8F2; color: #D946A6; }
.stat-link { display: inline-block; margin-top: .5rem; color: var(--brand-2); font-size: .8rem; font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1.1fr 1.4fr; gap: 1rem; margin-bottom: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.grid-aside { display: grid; grid-template-columns: 1.7fr .9fr; gap: 1rem; margin-bottom: 1rem; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 1.15rem;
  box-shadow: var(--shadow-sm); border: 1px solid rgba(232,228,240,.8);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-bottom: 1rem;
}
.card-head h2, .card-head h3 { margin: 0; font-size: 1.05rem; }
.card-head .muted { color: var(--muted); font-size: .82rem; }

.tabs { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tab {
  padding: .7rem 1rem; color: var(--muted); border: 0; background: transparent;
  cursor: pointer; position: relative; font-weight: 500;
}
.tab.active { color: var(--brand); font-weight: 700; }
.tab.active::after {
  content: ""; position: absolute; right: .6rem; left: .6rem; bottom: -1px;
  height: 3px; border-radius: 999px; background: var(--brand);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border: 0; border-radius: 12px; padding: .7rem 1.1rem; cursor: pointer;
  font-weight: 600; transition: .15s ease;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-light { background: #fff; color: var(--brand); }
.btn-ghost { background: var(--brand-soft); color: var(--brand); }
.btn-outline { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn-sm { padding: .45rem .8rem; font-size: .85rem; border-radius: 10px; }
.btn-block { width: 100%; }

.badge {
  display: inline-flex; align-items: center; padding: .28rem .65rem;
  border-radius: 999px; font-size: .75rem; font-weight: 700;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: #B47A00; }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-purple { background: var(--brand-soft); color: var(--brand); }
.badge-muted { background: #F1F0F5; color: var(--muted); }

.table-wrap { overflow: auto; }
table.data {
  width: 100%; border-collapse: collapse; min-width: 640px;
}
table.data th, table.data td {
  padding: .85rem .7rem; text-align: right; border-bottom: 1px solid var(--line);
  font-size: .9rem;
}
table.data th { color: var(--muted); font-weight: 600; background: #FAF8FC; }
table.data tr:hover td { background: #FCFAFF; }

.list-rank { list-style: none; margin: 0; padding: 0; display: grid; gap: .7rem; }
.list-rank li {
  display: flex; align-items: center; gap: .8rem; padding: .55rem;
  border-radius: 12px; background: #FAF8FC;
}
.rank-num {
  width: 28px; height: 28px; border-radius: 50%; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-size: .8rem; font-weight: 700;
}
.list-rank img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.list-rank .info { flex: 1; min-width: 0; }
.list-rank .info strong { display: block; font-size: .9rem; }
.list-rank .info small { color: var(--muted); }
.list-rank .score { font-weight: 700; color: var(--brand); }

.alert-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .7rem; }
.alert-item {
  display: flex; gap: .75rem; align-items: flex-start; padding: .7rem;
  border-radius: 12px; background: #FAF8FC;
}
.alert-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: .4rem; flex-shrink: 0; }
.alert-dot.red { background: var(--danger); }
.alert-dot.orange { background: var(--orange); }
.alert-dot.green { background: var(--success); }
.alert-item strong { display: block; font-size: .9rem; }
.alert-item small { color: var(--muted); }

.summary-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .85rem; }
.summary-list li {
  display: flex; justify-content: space-between; gap: 1rem;
  padding-bottom: .75rem; border-bottom: 1px dashed var(--line); font-size: .9rem;
}
.summary-list li:last-child { border: 0; padding: 0; }
.summary-list span { color: var(--muted); }
.summary-list strong { color: var(--ink); }

.chart-box { position: relative; height: 240px; }
.chart-box.sm { height: 200px; }

.badges-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .9rem;
}
.badge-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 1rem; text-align: center; transition: .2s ease;
}
.badge-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--brand-soft-2); }
.badge-shield {
  width: 56px; height: 64px; margin: 0 auto .75rem; border-radius: 12px 12px 18px 18px;
  display: grid; place-items: center; color: #fff;
}
.badge-shield.purple { background: linear-gradient(160deg, #7B4BC4, #4A248E); }
.badge-shield.blue { background: linear-gradient(160deg, #60A5FA, #2563EB); }
.badge-shield.green { background: linear-gradient(160deg, #34D399, #059669); }
.badge-shield.red { background: linear-gradient(160deg, #FB7185, #E11D48); }
.badge-shield.orange { background: linear-gradient(160deg, #FDBA74, #EA580C); }
.badge-shield.pink { background: linear-gradient(160deg, #F9A8D4, #DB2777); }
.badge-shield.teal { background: linear-gradient(160deg, #5EEAD4, #0D9488); }
.badge-shield.indigo { background: linear-gradient(160deg, #A5B4FC, #4F46E5); }
.badge-card h4 { margin: 0 0 .35rem; font-size: .92rem; }
.badge-card p { margin: 0; color: var(--muted); font-size: .78rem; min-height: 2.4em; }
.badge-meta { display: flex; justify-content: space-between; margin-top: .75rem; font-size: .75rem; color: var(--muted); }
.badge-meta b { color: var(--brand); }

.honor-strip {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(200px, 1fr);
  gap: .85rem; overflow: auto; padding-bottom: .25rem;
}
.honor-card {
  display: flex; gap: .7rem; align-items: center; background: #FAF8FC;
  border-radius: 14px; padding: .75rem; border: 1px solid var(--line);
}
.honor-card img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
.honor-card strong { display: block; font-size: .88rem; }
.honor-card small { color: var(--muted); font-size: .75rem; }

.filters {
  display: flex; flex-wrap: wrap; gap: .65rem; align-items: center;
  margin-bottom: 1rem; background: var(--card); padding: .85rem 1rem;
  border-radius: var(--radius); border: 1px solid var(--line);
}
.filters select, .filters input {
  border: 1px solid var(--line); border-radius: 10px; padding: .55rem .8rem; background: #fff;
}

.form-grid { display: grid; gap: .85rem; }
.form-group label { display: block; margin-bottom: .35rem; font-weight: 600; font-size: .88rem; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: .7rem .9rem; background: #fff; outline: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--brand-3); box-shadow: 0 0 0 3px rgba(123,75,196,.15);
}
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.attach-box {
  border: 1.5px dashed var(--line); border-radius: 12px; padding: 1rem;
  text-align: center; color: var(--muted); background: #FAF8FC;
}

.message-feed { list-style: none; margin: 0; padding: 0; display: grid; gap: .65rem; }
.message-item {
  display: flex; gap: .8rem; padding: .85rem; border-radius: 12px;
  border: 1px solid var(--line); background: #fff;
}
.message-item .ico {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); flex-shrink: 0;
}
.message-item strong { display: block; font-size: .9rem; }
.message-item p { margin: .2rem 0 0; color: var(--muted); font-size: .82rem; }
.message-item time { color: var(--muted); font-size: .75rem; white-space: nowrap; }

.bar-list { display: grid; gap: .7rem; }
.bar-row { display: grid; gap: .3rem; }
.bar-row .top { display: flex; justify-content: space-between; font-size: .85rem; }
.bar-track { height: 8px; background: #EEEAF5; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--brand-3), var(--brand)); border-radius: 999px; }

.criteria-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.criteria-list li {
  padding: .7rem .85rem; border-radius: 12px; background: #FAF8FC;
  border: 1px solid var(--line); font-size: .88rem; font-weight: 600;
}

.create-panel {
  background: linear-gradient(160deg, #5B2C9D, #4A248E);
  color: #fff; border-radius: var(--radius); padding: 1.25rem; text-align: center;
  margin-bottom: 1rem;
}
.create-panel p { margin: 0 0 1rem; opacity: .9; font-size: .9rem; }

/* Login */
.auth-page {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    linear-gradient(145deg, rgba(74,36,142,.92), rgba(91,44,157,.85)),
    radial-gradient(800px 500px at 20% 20%, rgba(255,255,255,.18), transparent);
}
.auth-card {
  width: min(440px, 100%); background: #fff; border-radius: 22px;
  padding: 2rem 1.6rem; box-shadow: 0 24px 60px rgba(20, 8, 50, .25);
}
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-brand .logo {
  width: 64px; height: 64px; margin: 0 auto .8rem; border-radius: 18px;
  background: linear-gradient(160deg, #7B4BC4, #4A248E); color: #fff;
  display: grid; place-items: center;
}
.auth-brand .logo svg { width: 34px; height: 34px; }
.auth-brand h1 { margin: 0; font-size: 1.35rem; }
.auth-brand p { margin: .35rem 0 0; color: var(--muted); font-size: .9rem; }
.auth-error {
  background: var(--danger-bg); color: var(--danger); padding: .75rem 1rem;
  border-radius: 12px; margin-bottom: 1rem; font-size: .88rem;
}
.auth-hint {
  margin-top: 1rem; padding: .85rem; background: var(--brand-soft);
  border-radius: 12px; font-size: .82rem; color: var(--brand); text-align: center;
}
.security-badges {
  display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; margin-top: 1.25rem;
}
.security-badges span {
  font-size: .72rem; background: #F5F3F9; color: var(--muted);
  padding: .35rem .6rem; border-radius: 999px;
}

/* Settings */
.settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.switch-row {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .85rem 0; border-bottom: 1px solid var(--line);
}
.switch-row:last-child { border: 0; }

@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-3, .grid-2, .grid-aside { grid-template-columns: 1fr; }
  .badges-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; right: 0; left: auto;
    transform: translateX(105%); transition: transform .25s ease;
  }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; border: 0; background: rgba(20,10,40,.45);
    opacity: 0; pointer-events: none; transition: .2s; z-index: 35;
  }
  .app-shell.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .mobile-menu { display: grid; }
  .topbar-search { display: none; }
  .user-chip div { display: none; }
  .select-pill { display: none; }
  .page-content { padding: 1rem; }
}
@media (max-width: 560px) {
  .stats-grid, .badges-grid { grid-template-columns: 1fr; }
  .topbar { padding: .85rem 1rem; }
}

/* Toast & Modal */
.toast-host {
  position: fixed; top: 1rem; left: 50%; transform: translateX(-50%);
  z-index: 1000; display: grid; gap: .5rem; width: min(420px, calc(100% - 2rem));
  pointer-events: none;
}
.toast {
  background: #1F1635; color: #fff; padding: .85rem 1.1rem; border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,.2); opacity: 0; transform: translateY(-8px);
  transition: .25s ease; font-weight: 600; font-size: .9rem; text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: #1FA97A; }
.toast.error { background: #E0455F; }
.toast#serverFlash { position: relative; margin-bottom: 1rem; pointer-events: auto; }

.modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 1rem; }
.modal[hidden] { display: none !important; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20,10,40,.5); border: 0; cursor: pointer; }
.modal-dialog {
  position: relative; z-index: 1; width: min(480px, 100%); background: #fff;
  border-radius: 18px; padding: 1.25rem; box-shadow: 0 24px 60px rgba(20,8,50,.25);
  max-height: min(90vh, 720px); overflow: auto;
}
.modal-dialog h3 { margin: 0 0 1rem; font-size: 1.15rem; }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-start; margin-top: 1rem; flex-wrap: wrap; }
body.modal-open { overflow: hidden; }

.static-pill { display: inline-flex; align-items: center; }
.user-chip { text-decoration: none; color: inherit; }
.status-select {
  border: 1px solid var(--line); border-radius: 999px; padding: .35rem .7rem;
  background: #fff; font-size: .8rem; font-weight: 600; cursor: pointer;
}
.table-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.btn:disabled { opacity: .6; cursor: wait; }
a.icon-btn { text-decoration: none; }
