/* الألوان: فاتح افتراضي، وغامق حسب الجهاز أو اختيار المستخدم (data-theme) */
:root {
  --bg: #f5f6fa;
  --bg-accent: #eef0fb;
  --card: #ffffff;
  --card-2: #fafbfd;
  --fg: #0f172a;
  --fg-2: #334155;
  --muted: #64748b;
  --line: #e6e8ef;
  --line-2: #eef0f5;
  --soft: #f1f3f8;
  --primary: #4f46e5;
  --primary-2: #6366f1;
  --primary-fg: #ffffff;
  --primary-soft: #eef0ff;
  --green: #059669;
  --green-soft: #e7f8f1;
  --amber: #b45309;
  --amber-soft: #fff6e5;
  --red: #dc2626;
  --red-soft: #fdeeee;
  --sky: #0284c7;
  --sky-soft: #e6f4fb;
  --violet: #7c3aed;
  --violet-soft: #f2ecfe;
  --shadow-sm: 0 1px 2px rgb(15 23 42 / .05);
  --shadow: 0 1px 2px rgb(15 23 42 / .04), 0 4px 16px -4px rgb(15 23 42 / .08);
  --shadow-lg: 0 24px 64px -12px rgb(15 23 42 / .28);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0d14;
    --bg-accent: #10142a;
    --card: #11151f;
    --card-2: #151a26;
    --fg: #e8ebf2;
    --fg-2: #c3c9d6;
    --muted: #8a93a6;
    --line: #222838;
    --line-2: #1b2130;
    --soft: #181e2b;
    --primary: #818cf8;
    --primary-2: #a5b4fc;
    --primary-fg: #0a0d14;
    --primary-soft: #1c1f3f;
    --green: #34d399;
    --green-soft: #0b2a22;
    --amber: #fbbf24;
    --amber-soft: #2b2108;
    --red: #f87171;
    --red-soft: #2d1215;
    --sky: #38bdf8;
    --sky-soft: #0b2433;
    --violet: #c4b5fd;
    --violet-soft: #231a3d;
    --shadow-sm: none;
    --shadow: none;
    --shadow-lg: 0 24px 64px -12px rgb(0 0 0 / .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0d14;
  --bg-accent: #10142a;
  --card: #11151f;
  --card-2: #151a26;
  --fg: #e8ebf2;
  --fg-2: #c3c9d6;
  --muted: #8a93a6;
  --line: #222838;
  --line-2: #1b2130;
  --soft: #181e2b;
  --primary: #818cf8;
  --primary-2: #a5b4fc;
  --primary-fg: #0a0d14;
  --primary-soft: #1c1f3f;
  --green: #34d399;
  --green-soft: #0b2a22;
  --amber: #fbbf24;
  --amber-soft: #2b2108;
  --red: #f87171;
  --red-soft: #2d1215;
  --sky: #38bdf8;
  --sky-soft: #0b2433;
  --violet: #c4b5fd;
  --violet-soft: #231a3d;
  --shadow-sm: none;
  --shadow: none;
  --shadow-lg: 0 24px 64px -12px rgb(0 0 0 / .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  background-image: radial-gradient(1200px 380px at 85% -120px, var(--bg-accent), transparent 70%);
  background-repeat: no-repeat;
  color: var(--fg);
  font: 15px/1.6 "Segoe UI", "IBM Plex Sans Arabic", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
h1, h2, h3 { margin: 0; line-height: 1.3; letter-spacing: -.01em; }
h2 { font-size: 19px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 700; }
p { margin: 0; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .9em; }
code { background: var(--soft); border: 1px solid var(--line-2); padding: 0 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.text-danger { color: var(--red); }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* أزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg);
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background .15s, border-color .15s, color .15s, transform .08s;
}
.btn:hover { background: var(--soft); }
.btn:active { transform: scale(.97); }
.btn:focus-visible, .icon-btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: linear-gradient(180deg, var(--primary-2), var(--primary)); border-color: var(--primary); color: var(--primary-fg); box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--primary) 60%, transparent); }
.btn-primary:hover { background: var(--primary); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: var(--red); filter: brightness(1.06); }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--soft); }
.btn-ghost.text-danger:hover { background: var(--red-soft); }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; width: 36px; height: 36px; border-radius: 10px; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--soft); color: var(--fg); }
.icon-btn .ico { width: 18px; height: 18px; }
.chip-btn { border: 1px solid var(--line); background: var(--card); color: var(--fg-2); border-radius: 999px; padding: 3px 11px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; transition: all .15s; }
.chip-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* حقول */
.input, .field input, .field textarea {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg); font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { height: auto; padding: 8px 12px; resize: vertical; }
.input:focus, .field input:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.input::placeholder, .field input::placeholder, .field textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.field input[readonly] { background: var(--soft); color: var(--muted); }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > span { font-weight: 600; font-size: 13.5px; color: var(--fg-2); }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-weight: 600; font-size: 13.5px; color: var(--fg-2); }
.presets { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.form-error { color: var(--red); font-size: 13px; min-height: 1em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.search { position: relative; }
.search .ico { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search .input { padding-inline-start: 36px; }

/* الدخول */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; position: relative; }
.login-theme { position: absolute; top: 16px; inset-inline-end: 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow-lg); text-align: center; }
.login-card .field { text-align: start; margin-top: 24px; }
.login-logo { width: 56px; height: 56px; margin-bottom: 14px; border-radius: 14px; box-shadow: 0 8px 24px -6px rgb(79 70 229 / .5); }
.login-card h1 { font-size: 21px; margin-bottom: 4px; }

/* الشريط العلوي */
.topbar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--card) 82%, transparent); backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--line); }
.topbar-in { display: flex; align-items: center; gap: 20px; height: 64px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand img { width: 36px; height: 36px; border-radius: 10px; }
.brand div { display: grid; line-height: 1.3; }
.brand strong { font-size: 15.5px; }
.tabs { display: flex; gap: 2px; padding: 4px; background: var(--soft); border: 1px solid var(--line-2); border-radius: 12px; }
.tab { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 13.5px; padding: 6px 14px; border-radius: 9px; cursor: pointer; transition: all .15s; white-space: nowrap; }
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); background: var(--card); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.top-actions { display: flex; align-items: center; gap: 4px; margin-inline-start: auto; }

main.wrap { padding-top: 24px; padding-bottom: 56px; }

/* تنبيهات */
.alert { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; border-radius: 12px; padding: 11px 14px; margin-bottom: 12px; border: 1px solid; font-size: 14px; }
.alert .ico { width: 18px; height: 18px; }
.alert > span { flex: 1; min-width: 200px; }
.alert-warn { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.alert-warn .ico { color: var(--amber); }
.alert-error { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.alert-error .ico { color: var(--red); }
.alert-info { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }
.alert-info .ico { color: var(--primary); }
.dialog .alert { display: block; }

/* المؤشرات */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 28px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: flex-start; }
.kpi-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: none; }
.kpi-icon .ico { width: 20px; height: 20px; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.25; margin-top: 2px; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tone-indigo { background: var(--primary-soft); color: var(--primary); }
.tone-green { background: var(--green-soft); color: var(--green); }
.tone-sky { background: var(--sky-soft); color: var(--sky); }
.tone-violet { background: var(--violet-soft); color: var(--violet); }
.tone-amber { background: var(--amber-soft); color: var(--amber); }
.tone-red { background: var(--red-soft); color: var(--red); }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head p { margin-top: 2px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar .search { width: 260px; }

/* كروت الجمعيات */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: grid; grid-template-rows: 1fr auto; transition: border-color .15s; overflow: hidden; }
.card:hover { border-color: color-mix(in srgb, var(--primary) 35%, var(--line)); }
.card.off .card-main { opacity: .6; }
.card-main { padding: 18px 18px 14px; display: grid; gap: 14px; align-content: start; }
.card-head { display: flex; align-items: center; gap: 12px; }
.avatar { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-size: 18px; flex: none; }
.card-title { flex: 1; min-width: 0; }
.card-title strong { display: block; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title .sub { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; margin-top: 2px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-green .dot { box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 25%, transparent); }
.pill-green { background: var(--green-soft); color: var(--green); }
.pill-amber { background: var(--amber-soft); color: var(--amber); }
.pill-grey { background: var(--soft); color: var(--muted); }
.pill-red { background: var(--red-soft); color: var(--red); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; border-radius: 8px; padding: 3px 9px; font-weight: 600; }
.chip .ico { width: 13px; height: 13px; }
.chip-more { color: var(--muted); font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card-2); border: 1px solid var(--line-2); border-radius: 12px; }
.stats > div { padding: 9px 4px; text-align: center; }
.stats > div + div { border-inline-start: 1px solid var(--line-2); }
.stats b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stats span { color: var(--muted); font-size: 11.5px; }
.trend { display: grid; gap: 4px; }
.trend-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 11.5px; }
.spark { width: 100%; height: 40px; display: block; overflow: visible; }
.spark .area { fill: var(--primary); opacity: .12; }
.spark .line { fill: none; stroke: var(--primary); stroke-width: 1.8; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark-empty { height: 40px; display: grid; place-items: center; color: var(--muted); font-size: 12px; border: 1px dashed var(--line); border-radius: 10px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 12px; }
.meta span { display: inline-flex; align-items: center; gap: 5px; }
.meta .ico { width: 13px; height: 13px; }
.notes { font-size: 13px; color: var(--fg-2); background: var(--soft); border-radius: 10px; padding: 8px 11px; white-space: pre-wrap; border-inline-start: 3px solid var(--line); }
.card-actions { display: flex; gap: 6px; align-items: center; padding: 10px 14px; background: var(--card-2); border-top: 1px solid var(--line-2); }
.card-actions .grow { flex: 1; }
.empty { grid-column: 1 / -1; text-align: center; padding: 56px 16px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty .kpi-icon { margin: 0 auto 12px; width: 48px; height: 48px; }
.empty strong { display: block; color: var(--fg); font-size: 16px; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }

/* مفتاح التشغيل (RTL: الدايرة يمين = مقفول، شمال = شغال) */
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: color-mix(in srgb, var(--muted) 35%, transparent); border-radius: 999px; transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; right: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s cubic-bezier(.3,.7,.4,1); box-shadow: 0 1px 3px rgb(0 0 0 / .25); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(-18px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* لوحات الإعدادات */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.panel-head h2 { font-size: 17px; margin-bottom: 2px; }
.panel-head p { font-size: 14px; }
.row-form { display: flex; gap: 8px; }
.row-form .input { max-width: 440px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 10px; }
.facts { display: grid; grid-template-columns: max-content 1fr; margin: 0; font-size: 14px; }
.facts dt, .facts dd { padding: 10px 0; border-bottom: 1px solid var(--line-2); margin: 0; }
.facts dt { color: var(--muted); padding-inline-end: 24px; }
.facts > :nth-last-child(-n+2) { border-bottom: 0; }

.table-wrap { overflow-x: auto; margin: 0 -20px -20px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: start; padding: 11px 20px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--card-2); border-top: 1px solid var(--line-2); }
.table tbody tr:hover { background: var(--card-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.wrap-cell { white-space: normal; }
.badge { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13px; }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-green { background: var(--green); }
.dot-red { background: var(--red); }
.dot-amber { background: var(--amber); }
.dot-indigo { background: var(--primary); }
.dot-grey { background: var(--muted); }

/* الحوارات */
.dialog { border: 1px solid var(--line); padding: 0; border-radius: 20px; background: var(--card); color: var(--fg); width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: var(--shadow-lg); }
.dialog-sm { width: min(460px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgb(8 11 20 / .5); backdrop-filter: blur(3px); }
.dialog[open] { animation: pop .18s cubic-bezier(.3,.7,.4,1); }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px 10px; }
.dialog-body { padding: 8px 22px; overflow-y: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; margin-top: 8px; border-top: 1px solid var(--line-2); background: var(--card-2); }
.features { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.feature { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; cursor: pointer; transition: border-color .15s, background .15s, box-shadow .15s; }
.feature:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); }
.feature:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary) inset; }
.feature input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--primary); flex: none; }
.feature b { display: block; font-size: 14px; }
.feature small { color: var(--muted); font-size: 12px; line-height: 1.5; display: block; margin-top: 2px; }
.advanced { margin-bottom: 16px; border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 12px 0; }
.advanced summary { cursor: pointer; color: var(--fg-2); font-size: 13.5px; font-weight: 600; margin-bottom: 10px; }
.secret { display: flex; gap: 8px; align-items: stretch; margin: 14px 0; }
.secret pre { flex: 1; margin: 0; padding: 14px; background: #0f172a; color: #e2e8f0; border: 1px solid #1e293b; border-radius: 12px; font-size: 13px; line-height: 1.8; overflow-x: auto; white-space: pre; user-select: all; text-align: left; }
.secret .btn { height: auto; min-width: 84px; }
.steps { padding-inline-start: 20px; margin: 0 0 16px; font-size: 14px; display: grid; gap: 6px; color: var(--fg-2); }

/* إشعارات */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; align-items: center; gap: 10px; background: var(--card); color: var(--fg); border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); animation: pop .18s ease-out; }
.toast .ico { color: var(--green); width: 18px; height: 18px; }
.toast.error .ico { color: var(--red); }

@media (max-width: 960px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .topbar-in { flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 10px; gap: 10px; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; }
  .features { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .toolbar, .toolbar .search { width: 100%; }
  .toolbar .btn { flex: 1; }
  .row-form { flex-direction: column; }
  .kpis { gap: 10px; }
  .kpi { padding: 14px; flex-direction: column; gap: 10px; }
  .kpi .value { font-size: 22px; }
  .brand .small { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
