/*
 * Waqfulkhair design system — shared tokens and components (public site, admin, sign-in, receipts).
 * Colours: deep forest green (primary), emerald (secondary), muted royal gold (accent, used sparingly),
 * warm ivory background, white surfaces, dark charcoal text.
 * Layout uses logical properties (margin-inline, inset-inline…) so pages mirror correctly in RTL.
 */
:root {
  /* Brand palette */
  --forest-950: #0a2c21;
  --forest-900: #0f3d2e;
  --forest-800: #144b39;
  --forest-700: #1a5c45;
  --emerald-600: #1f7a5a;
  --emerald-500: #2a8f6b;
  --emerald-200: #bfe0d1;
  --emerald-100: #e4f2eb;
  --emerald-50:  #f2f8f5;
  --gold-600: #96732a;
  --gold-500: #b48f3e;
  --gold-300: #dcc48c;
  --gold-100: #f5edda;
  --ivory: #faf7f0;
  --ivory-deep: #f3eee2;
  --surface: #ffffff;
  --charcoal: #1e2422;
  --charcoal-soft: #4f5a55;
  --charcoal-faint: #78827d;
  --line: #e4dfd2;
  --line-strong: #c9c2b1;

  /* Status */
  --danger: #b42318;
  --danger-bg: #fdecea;
  --danger-line: #f3b9b3;
  --success: #1f7a5a;
  --success-bg: #e6f4ec;
  --success-line: #b7dfc7;
  --info: #1d5b94;
  --info-bg: #eaf2fb;
  --info-line: #bcd4ef;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --warn-line: #f0d79b;

  /* Older names kept so existing screens keep working */
  --green-900: var(--forest-900);
  --green-700: var(--forest-700);
  --green-600: var(--emerald-600);
  --green-100: var(--emerald-100);
  --ink: var(--charcoal);
  --ink-soft: var(--charcoal-soft);
  --bg: var(--surface);
  --bg-soft: var(--ivory);

  /* Type */
  --font: "Plus Jakarta Sans", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-arabic: "Amiri", "Cairo", "Noto Naskh Arabic", "Segoe UI", Tahoma, serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --text-xs: .78rem;
  --text-sm: .875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;

  /* Shape and depth */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 61, 46, .06);
  --shadow: 0 1px 3px rgba(15, 61, 46, .07), 0 1px 2px rgba(15, 61, 46, .04);
  --shadow-lg: 0 12px 32px rgba(15, 61, 46, .12);
  --focus: 0 0 0 3px rgba(180, 143, 62, .45);

  /* Islamic geometric motif (eight-point star from two squares) — very low contrast */
  --pattern-light: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.07' stroke-width='1'%3E%3Crect x='16' y='16' width='32' height='32'/%3E%3Crect x='16' y='16' width='32' height='32' transform='rotate(45 32 32)'/%3E%3Ccircle cx='32' cy='32' r='6'/%3E%3Cpath d='M0 0l16 16M64 0L48 16M0 64l16-16M64 64L48 48'/%3E%3C/g%3E%3C/svg%3E");
  --pattern-dark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%230f3d2e' stroke-opacity='.06' stroke-width='1'%3E%3Crect x='16' y='16' width='32' height='32'/%3E%3Crect x='16' y='16' width='32' height='32' transform='rotate(45 32 32)'/%3E%3Ccircle cx='32' cy='32' r='6'/%3E%3Cpath d='M0 0l16 16M64 0L48 16M0 64l16-16M64 64L48 48'/%3E%3C/g%3E%3C/svg%3E");
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { transition: none !important; animation: none !important; } }
body { margin: 0; font-family: var(--font); color: var(--charcoal); background: var(--surface); line-height: 1.6; font-size: var(--text-base); }
[dir="rtl"] body, body[dir="rtl"] { font-family: var(--font-arabic); line-height: 1.8; }
[dir="rtl"] .num, [dir="rtl"] code, [dir="rtl"] .ltr { direction: ltr; unicode-bidi: isolate; }
img { max-width: 100%; height: auto; }
a { color: var(--forest-700); text-underline-offset: .15em; }
a:hover { color: var(--forest-900); }
h1, h2, h3, h4 { line-height: 1.25; color: var(--forest-900); letter-spacing: -.01em; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3 { letter-spacing: 0; }
code { font-family: var(--font-mono); font-size: .88em; background: var(--ivory); padding: .05em .35em; border-radius: 4px; }
code.wrap { white-space: pre-wrap; word-break: break-all; }
.muted { color: var(--charcoal-soft); }
.small { font-size: var(--text-sm); }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
.skip-link { position: absolute; inset-inline-start: -999px; top: 0; background: var(--forest-900); color: #fff; padding: .5rem 1rem; z-index: 100; border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
.skip-link:focus { inset-inline-start: 1rem; color: #fff; }
:focus-visible { outline: 3px solid var(--gold-500); outline-offset: 2px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .62rem 1.1rem; border: 1px solid var(--line-strong);
       border-radius: var(--radius); background: var(--surface); color: var(--charcoal); font: inherit; font-weight: 600; font-size: .95rem;
       text-decoration: none; cursor: pointer; line-height: 1.2; transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s; }
.btn:hover { background: var(--ivory); color: var(--charcoal); border-color: var(--charcoal-faint); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--forest-800); border-color: var(--forest-800); color: #fff; }
.btn-primary:hover { background: var(--forest-950); border-color: var(--forest-950); color: #fff; }
.btn-secondary { background: var(--emerald-100); border-color: var(--emerald-200); color: var(--forest-900); }
.btn-secondary:hover { background: var(--emerald-200); color: var(--forest-950); border-color: var(--emerald-200); }
.btn-accent { background: var(--gold-500); border-color: var(--gold-500); color: #1f1606; }
.btn-accent:hover { background: var(--gold-600); border-color: var(--gold-600); color: #fff; }
.btn-outline { background: transparent; border-color: rgba(255, 255, 255, .7); color: #fff; }
.btn-outline:hover { background: rgba(255, 255, 255, .12); color: #fff; border-color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--forest-700); }
.btn-ghost:hover { background: var(--emerald-50); border-color: transparent; color: var(--forest-900); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #8e1b12; border-color: #8e1b12; color: #fff; }
.btn-link { background: none; border: 0; color: var(--forest-700); padding: 0; font-weight: 500; text-decoration: underline; text-underline-offset: .15em; }
.btn-link:hover { background: none; color: var(--forest-900); }
.btn-lg { padding: .85rem 1.4rem; font-size: 1.02rem; border-radius: 12px; }
.btn-sm { padding: .32rem .65rem; font-size: .85rem; }
.btn-block { display: flex; width: 100%; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; width: 1.05em; height: 1.05em; border-radius: 50%; border: 2px solid currentColor;
                         border-color: var(--charcoal-soft) transparent var(--charcoal-soft) transparent; animation: spin .8s linear infinite; }
.btn-primary.is-loading::after, .btn-danger.is-loading::after { border-color: #fff transparent #fff transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Forms */
.form .field { margin-bottom: 1.05rem; }
.form label, .label { display: block; font-weight: 600; margin-bottom: .35rem; color: var(--charcoal); }
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea, .filters input, .filters select, .input {
  width: 100%; padding: .62rem .75rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font: inherit; background: var(--surface);
  color: var(--charcoal); transition: border-color .15s, box-shadow .15s;
}
.form input:focus, .form select:focus, .form textarea:focus, .filters input:focus, .filters select:focus, .input:focus {
  outline: none; border-color: var(--emerald-600); box-shadow: 0 0 0 3px rgba(31, 122, 90, .18);
}
.form [aria-invalid="true"] { border-color: var(--danger) !important; }
.form textarea { resize: vertical; }
.help { font-size: var(--text-sm); color: var(--charcoal-soft); margin: .3rem 0 0; }
.field-error { color: var(--danger); font-size: var(--text-sm); margin: .3rem 0 0; font-weight: 500; }
.required::after { content: " *"; color: var(--danger); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; margin: 0 0 1rem; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 700; padding: 0 .3rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400 !important; margin: .4rem 0; }
.check input { margin-top: .32rem; accent-color: var(--forest-700); width: 1.05rem; height: 1.05rem; flex: none; }
.hp { position: absolute; inset-inline-start: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* Alerts and badges */
.alert { padding: .8rem 1rem; border-radius: var(--radius); margin: 1rem 0; border: 1px solid transparent; border-inline-start-width: 4px; }
.alert-success { background: var(--success-bg); border-color: var(--success-line); border-inline-start-color: var(--success); }
.alert-error { background: var(--danger-bg); border-color: var(--danger-line); border-inline-start-color: var(--danger); color: #7a1a12; }
.alert-info { background: var(--info-bg); border-color: var(--info-line); border-inline-start-color: var(--info); }
.alert-warn { background: var(--warn-bg); border-color: var(--warn-line); border-inline-start-color: var(--gold-500); }
.alert > :first-child { margin-top: 0; }
.alert > :last-child { margin-bottom: 0; }
.badge { display: inline-block; font-size: var(--text-xs); font-weight: 600; padding: .12rem .55rem; border-radius: 999px; background: var(--ivory); border: 1px solid var(--line); white-space: nowrap; }
.badge-active, .badge-success { background: var(--success-bg); border-color: var(--success-line); color: #155c43; }
.badge-inactive, .badge-danger { background: var(--danger-bg); border-color: var(--danger-line); color: #7a1a12; }
.badge-pending, .badge-warn { background: var(--warn-bg); border-color: var(--warn-line); color: #6b4600; }
.badge-info { background: var(--info-bg); border-color: var(--info-line); color: #174a78; }
.placeholder { background: var(--warn-bg); border-inline-start: 4px solid var(--gold-500); padding: .6rem .9rem; border-radius: 4px; }

.pagination { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1.25rem 0; flex-wrap: wrap; }
.empty { padding: 2rem 1.25rem; text-align: center; color: var(--charcoal-soft); background: var(--ivory); border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.empty strong { display: block; color: var(--forest-900); margin-bottom: .25rem; }

/* Confirmation dialog (replaces window.confirm; see app.js) */
dialog.modal { border: 0; border-radius: var(--radius-lg); padding: 0; width: min(460px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); color: var(--charcoal); }
dialog.modal::backdrop { background: rgba(10, 44, 33, .45); }
.modal-body { padding: 1.4rem 1.5rem 1rem; }
.modal-body h2 { margin: 0 0 .5rem; font-size: 1.15rem; }
.modal-body p { margin: 0; color: var(--charcoal-soft); white-space: pre-line; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; padding: 1rem 1.5rem 1.25rem; background: var(--ivory); border-top: 1px solid var(--line); flex-wrap: wrap; }

/* Simple bar charts drawn with CSS (no chart library); widths come from data attributes via app.js */
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: .7rem; }
.bars li { display: grid; gap: .25rem; }
.bar-head { display: flex; justify-content: space-between; gap: 1rem; font-size: var(--text-sm); }
.bar-head strong { font-weight: 600; }
.bar-track { height: .6rem; background: var(--ivory-deep); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; width: 0; background: var(--emerald-600); border-radius: 999px; transition: width .6s ease; }
.bar-fill.gold { background: var(--gold-500); }
.bar-fill.forest { background: var(--forest-800); }
