@font-face {
  font-family: "Diodrum Arabic";
  src: local("Diodrum Arabic"), local("DiodrumArabic-Regular"), local("DiodrumArabic");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --purple-950: #21164f;
  --purple-900: #2a206a;
  --purple-800: #39277f;
  --purple-700: #5634a7;
  --purple-100: #eeeafd;
  --purple-50: #f8f6ff;
  --teal-700: #008c99;
  --teal-600: #00a7b5;
  --teal-500: #00b8c6;
  --teal-100: #dff9fb;
  --green: #218a67;
  --green-bg: #e7f6ef;
  --gold: #b27d18;
  --gold-bg: #fff5d8;
  --red: #b63b55;
  --red-bg: #fde9ee;
  --orange: #c76b31;
  --orange-bg: #fff0e7;
  --blue: #3d64bd;
  --blue-bg: #eaf0ff;
  --bg: #f5f5fa;
  --panel: #ffffff;
  --text: #292443;
  --muted: #77718c;
  --border: #e4e1ed;
  --shadow: 0 15px 42px rgba(42, 32, 106, .09);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Diodrum Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.loading-screen {
  position: fixed; inset: 0; z-index: 2000;
  display: grid; place-content: center; justify-items: center; gap: 18px;
  background: linear-gradient(145deg, #fff 0%, var(--purple-50) 55%, var(--teal-100) 140%);
  color: var(--purple-900);
}
.loading-screen img { width: min(310px, 70vw); height: auto; }
.loading-screen p { margin: 0; font-size: 17px; }
.spinner { width: 42px; height: 42px; border: 4px solid #ddd7f3; border-top-color: var(--teal-600); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth-gate {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(circle at 12% 12%, rgba(0,184,198,.18), transparent 28%),
    radial-gradient(circle at 90% 90%, rgba(86,52,167,.18), transparent 32%),
    linear-gradient(150deg, #fff, #f5f2ff);
}
.auth-card {
  width: min(520px, 100%); background: rgba(255,255,255,.96); border: 1px solid rgba(255,255,255,.8);
  border-radius: 26px; box-shadow: 0 28px 90px rgba(42,32,106,.18); padding: 34px;
}
.auth-logo { display: block; width: min(300px, 82%); margin: 0 auto 24px; }
.auth-card h2 { margin: 0 0 8px; color: var(--purple-900); font-size: 26px; text-align: center; }
.auth-card .lead { color: var(--muted); margin: 0 auto 24px; text-align: center; line-height: 1.8; }
.auth-note { margin-top: 18px; background: var(--purple-50); border: 1px solid #ded8f5; padding: 13px 15px; border-radius: 13px; color: #645d7b; font-size: 13px; line-height: 1.7; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  min-height: 92px; padding: 15px clamp(18px, 4vw, 54px);
  background: rgba(255,255,255,.95); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 20px; min-width: 0; }
.brand img { width: 190px; height: auto; flex: 0 0 auto; }
.brand h1 { margin: 0; color: var(--purple-900); font-size: 22px; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
.user-badge { padding: 9px 14px; border-radius: 999px; background: var(--purple-100); color: var(--purple-800); font-weight: 700; white-space: nowrap; }
.live-badge { display: flex; align-items: center; gap: 7px; color: var(--green); font-size: 13px; font-weight: 700; padding: 8px 12px; border-radius: 999px; background: var(--green-bg); }
.live-badge span { width: 8px; height: 8px; border-radius: 50%; background: #22a978; box-shadow: 0 0 0 5px rgba(34,169,120,.12); }

.main-nav {
  display: flex; gap: 8px; overflow-x: auto; padding: 13px clamp(18px, 4vw, 54px);
  background: var(--purple-900); scrollbar-width: thin;
}
.nav-item {
  border: 0; color: rgba(255,255,255,.75); background: transparent; padding: 11px 16px; border-radius: 11px;
  white-space: nowrap; transition: .18s ease; font-weight: 700;
}
.nav-item:hover { background: rgba(255,255,255,.11); color: #fff; }
.nav-item.active { color: var(--purple-900); background: #fff; box-shadow: 0 8px 24px rgba(14,8,46,.18); }
.nav-item span { margin-left: 6px; }

.main-content { width: min(1540px, calc(100% - 36px)); margin: 28px auto 42px; min-height: calc(100vh - 210px); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.page-head h2 { margin: 0 0 5px; color: var(--purple-900); font-size: 27px; }
.page-head p { margin: 0; color: var(--muted); line-height: 1.65; }
.page-actions { display: flex; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }

.btn { border: 1px solid transparent; border-radius: 11px; padding: 10px 15px; font-weight: 700; transition: .16s ease; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: linear-gradient(135deg, var(--purple-900), var(--purple-700)); color: #fff; box-shadow: 0 8px 20px rgba(86,52,167,.2); }
.btn-teal { background: linear-gradient(135deg, var(--teal-700), var(--teal-500)); color: #fff; }
.btn-outline { background: #fff; border-color: #cfc9e2; color: var(--purple-800); }
.btn-ghost { background: var(--purple-50); color: var(--purple-800); border-color: #e3def4; }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: #f5ccd6; }
.btn-sm { padding: 7px 11px; font-size: 13px; border-radius: 9px; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 10px; background: var(--purple-50); color: var(--purple-900); font-size: 24px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 15px; margin-bottom: 20px; }
.kpi-card { position: relative; overflow: hidden; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-height: 135px; }
.kpi-card::after { content: ""; position: absolute; width: 105px; height: 105px; border-radius: 50%; left: -34px; bottom: -50px; background: var(--accent-soft, var(--purple-100)); }
.kpi-top { display: flex; justify-content: space-between; gap: 12px; }
.kpi-title { color: var(--muted); font-size: 14px; }
.kpi-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: var(--accent-soft, var(--purple-100)); color: var(--accent, var(--purple-700)); font-size: 20px; }
.kpi-value { margin: 12px 0 2px; font-size: 30px; line-height: 1; color: var(--purple-900); font-weight: 800; }
.kpi-sub { color: var(--muted); font-size: 12px; }

.grid-2 { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; margin-bottom: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 18px; margin-bottom: 20px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head h3 { margin: 0; color: var(--purple-900); font-size: 18px; }
.panel-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

.bar-list { display: grid; gap: 13px; }
.bar-row { display: grid; grid-template-columns: minmax(100px, 190px) 1fr 52px; align-items: center; gap: 12px; }
.bar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #554f6c; }
.bar-track { height: 10px; border-radius: 999px; background: #eeeaf7; overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal-500), var(--purple-700)); min-width: 2px; }
.bar-value { text-align: left; color: var(--purple-800); font-weight: 800; }
.empty { min-height: 170px; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 20px; }
.empty strong { display: block; color: var(--purple-800); margin-bottom: 5px; }

.toolbar { display: grid; grid-template-columns: minmax(220px, 1.6fr) repeat(2,minmax(150px,.7fr)) auto; gap: 10px; margin-bottom: 15px; }
.field { display: grid; gap: 6px; }
.field label { color: #5f5976; font-size: 13px; font-weight: 700; }
.input, .field input, .field select, .field textarea {
  width: 100%; border: 1px solid #dcd8e8; border-radius: 11px; background: #fff; color: var(--text); padding: 11px 12px; outline: 0;
}
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--teal-500); box-shadow: 0 0 0 3px rgba(0,184,198,.12); }
.field textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }

.table-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 17px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.table-scroll { overflow: auto; max-height: 590px; }
table { width: 100%; border-collapse: collapse; min-width: 940px; }
th { position: sticky; top: 0; z-index: 2; background: var(--purple-900); color: #fff; padding: 12px 13px; text-align: right; white-space: nowrap; font-size: 13px; }
td { padding: 11px 13px; border-bottom: 1px solid #eeebf4; white-space: nowrap; color: #49435f; font-size: 13px; }
tbody tr:hover { background: #fbfaff; }
.table-actions { display: flex; gap: 6px; }
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 800; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-gold { background: var(--gold-bg); color: var(--gold); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-purple { background: var(--purple-100); color: var(--purple-700); }
.badge-gray { background: #f0eef4; color: #6e687d; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 14px; border-top: 1px solid var(--border); }
.pagination button { min-width: 36px; height: 34px; border: 1px solid #ddd8e8; background: #fff; border-radius: 9px; color: var(--purple-800); }
.pagination button.active { background: var(--purple-900); color: #fff; border-color: var(--purple-900); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

.module-strip { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; margin-bottom: 20px; }
.module-tile { border: 1px solid var(--border); background: #fff; border-radius: 16px; padding: 17px; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow); }
.module-tile .icon { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 15px; background: var(--purple-100); font-size: 25px; }
.module-tile strong { display: block; color: var(--purple-900); font-size: 17px; }
.module-tile span { color: var(--muted); font-size: 13px; }

.manage-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; margin-bottom: 20px; }
.manage-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.manage-card h3 { margin: 0 0 5px; color: var(--purple-900); }
.manage-card p { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.6; min-height: 42px; }
.manage-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sector-list { display: grid; gap: 10px; }
.sector-row { display: grid; grid-template-columns: minmax(180px,1fr) minmax(210px,1fr) auto auto; gap: 10px; align-items: center; padding: 12px; border: 1px solid var(--border); border-radius: 13px; background: #fcfbff; }
.sector-info strong { display: block; color: var(--purple-900); }
.sector-info span { color: var(--muted); font-size: 12px; }
.switch { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.audit-list { display: grid; gap: 8px; max-height: 390px; overflow: auto; }
.audit-row { display: flex; justify-content: space-between; gap: 12px; padding: 11px 12px; border-radius: 11px; background: var(--purple-50); }
.audit-row strong { color: var(--purple-800); }
.audit-row small { color: var(--muted); }

.modal-backdrop { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 22px; background: rgba(22,16,50,.55); backdrop-filter: blur(5px); }
.modal-card { width: min(850px,100%); max-height: min(900px, 92vh); display: flex; flex-direction: column; background: #fff; border-radius: 22px; box-shadow: 0 35px 100px rgba(18,10,52,.35); overflow: hidden; }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; color: var(--purple-900); }
.modal-header p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.modal-body { padding: 21px 22px; overflow: auto; }
.modal-footer { display: flex; justify-content: flex-start; gap: 9px; padding: 15px 22px; border-top: 1px solid var(--border); background: #fbfaff; }

.toast-container { position: fixed; z-index: 3000; left: 22px; bottom: 22px; display: grid; gap: 9px; }
.toast { min-width: 290px; max-width: 440px; padding: 13px 15px; border-radius: 12px; box-shadow: 0 16px 45px rgba(22,16,50,.22); color: #fff; animation: toastIn .22s ease; }
.toast-success { background: #17785a; }
.toast-error { background: #a72f49; }
.toast-info { background: var(--purple-800); }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } }
.footer { padding: 18px; color: var(--muted); text-align: center; font-size: 12px; }

.notice { border-radius: 13px; padding: 13px 15px; background: var(--teal-100); color: #16636c; border: 1px solid #b9eff2; line-height: 1.7; }
.danger-notice { background: var(--red-bg); color: #8f3047; border-color: #f2cdd6; }

@media (max-width: 1150px) {
  .topbar { align-items: flex-start; }
  .topbar-actions { max-width: 520px; }
  .kpi-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .manage-grid, .module-strip { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .topbar { position: static; flex-direction: column; }
  .brand img { width: 160px; }
  .topbar-actions { justify-content: flex-start; max-width: none; }
  .live-badge { order: -1; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar .search-field { grid-column: span 2; }
  .sector-row { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .main-content { width: min(100% - 20px, 1540px); margin-top: 18px; }
  .auth-card { padding: 25px 20px; }
  .brand { align-items: flex-start; }
  .brand h1 { font-size: 18px; }
  .brand p { display: none; }
  .kpi-grid { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
  .page-actions { justify-content: flex-start; }
  .toolbar { grid-template-columns: 1fr; }
  .toolbar .search-field { grid-column: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .toast-container { left: 10px; right: 10px; bottom: 10px; }
  .toast { min-width: 0; width: 100%; }
}

@media print {
  .topbar-actions, .main-nav, .page-actions, .toolbar, .pagination, .footer, .table-actions { display: none !important; }
  .topbar { position: static; border: 0; }
  .main-content { width: 100%; margin: 0; }
  .panel, .kpi-card, .table-card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}

/* Dashboard analytics charts */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 20px;
}
.chart-panel { min-height: 330px; }
.chart-panel .panel-head { margin-bottom: 18px; }
.donut-layout {
  display: grid;
  grid-template-columns: minmax(180px, .78fr) minmax(220px, 1.22fr);
  align-items: center;
  gap: 18px;
  min-height: 230px;
}
.donut-wrap { position: relative; width: min(230px, 100%); aspect-ratio: 1; margin: auto; }
.donut-chart { width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 9px 15px rgba(42,32,106,.08)); }
.donut-bg { stroke: #eeeaf7; }
.donut-segment { transition: opacity .18s ease, stroke-width .18s ease; cursor: default; }
.donut-segment:hover { opacity: .82; stroke-width: 25; }
.donut-center {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: 45%;
  text-align: center;
  pointer-events: none;
}
.donut-center strong { display: block; color: var(--purple-900); font-size: 29px; line-height: 1.05; }
.donut-center span { display: block; color: var(--muted); font-size: 11px; margin-top: 5px; line-height: 1.35; }
.chart-legend { display: grid; gap: 9px; min-width: 0; }
.chart-legend-row {
  display: grid;
  grid-template-columns: 11px minmax(0,1fr) auto 52px;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #faf9fe;
  border: 1px solid #efecf6;
}
.chart-swatch { width: 10px; height: 10px; border-radius: 50%; }
.chart-legend-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #554f6c; }
.chart-legend-row strong { color: var(--purple-900); text-align: left; }
.chart-legend-row small { color: var(--muted); text-align: left; }
.hbar-chart { display: grid; gap: 15px; min-height: 225px; align-content: center; }
.hbar-item { display: grid; gap: 7px; }
.hbar-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hbar-meta > span { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: #554f6c; }
.hbar-meta strong { color: var(--purple-900); white-space: nowrap; }
.hbar-meta small { color: var(--muted); font-weight: 600; margin-inline-start: 4px; }
.hbar-track { height: 12px; border-radius: 999px; background: #eeeaf7; overflow: hidden; }
.hbar-fill { display: block; height: 100%; min-width: 3px; border-radius: inherit; box-shadow: 0 4px 9px rgba(42,32,106,.10); transition: width .25s ease; }
.column-chart {
  display: grid;
  grid-template-columns: repeat(var(--chart-columns), minmax(48px, 1fr));
  align-items: end;
  gap: clamp(8px, 1.5vw, 18px);
  min-height: 245px;
  padding: 10px 4px 0;
  overflow-x: auto;
}
.column-item { min-width: 48px; display: grid; grid-template-rows: 24px 170px 42px; justify-items: center; gap: 6px; }
.column-value { color: var(--purple-900); font-size: 13px; }
.column-track { width: min(54px, 72%); height: 170px; display: flex; align-items: flex-end; border-radius: 12px 12px 7px 7px; background: linear-gradient(180deg, #fbfaff, #eeeaf7); overflow: hidden; }
.column-fill { display: block; width: 100%; min-height: 5px; border-radius: 10px 10px 5px 5px; box-shadow: 0 -5px 14px rgba(42,32,106,.12); transition: height .25s ease; }
.column-label { max-width: 110px; text-align: center; color: #625b77; font-size: 11px; line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chart-empty { min-height: 235px; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); gap: 6px; }
.chart-empty > span { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 50%; background: var(--purple-50); color: var(--purple-700); font-size: 34px; }
.chart-empty strong { color: var(--purple-800); }
.chart-empty small { max-width: 280px; line-height: 1.6; }
.insight-panel { min-height: 330px; }
.insight-list { display: grid; gap: 9px; }
.insight-list .audit-row { border: 1px solid #ebe7f5; background: linear-gradient(135deg, #fbfaff, #f7fbfc); }
.insight-list .audit-row span { color: var(--purple-900); font-weight: 800; }

@media (max-width: 980px) {
  .donut-layout { grid-template-columns: 1fr; }
  .donut-wrap { width: 190px; }
  .chart-panel { min-height: auto; }
}
@media (max-width: 820px) {
  .analytics-grid { grid-template-columns: 1fr; }
  .donut-layout { grid-template-columns: minmax(170px,.7fr) minmax(210px,1.3fr); }
}
@media (max-width: 560px) {
  .donut-layout { grid-template-columns: 1fr; }
  .donut-wrap { width: 180px; }
  .chart-legend-row { grid-template-columns: 10px minmax(0,1fr) auto 48px; padding: 7px 8px; }
  .column-chart { grid-template-columns: repeat(var(--chart-columns), minmax(54px, 1fr)); }
}
@media print {
  .analytics-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .chart-panel { min-height: 300px; }
  .donut-segment { filter: none; }
}
