/* B — design tokens, reset and shared components. RTL-first. */
:root {
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  --font-quran: "Amiri Quran", "Amiri", "Scheherazade New", serif;
  --r-sm: 10px; --r: 16px; --r-lg: 22px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --shadow: 0 1px 2px rgba(6, 20, 27, .05), 0 6px 20px -8px rgba(6, 20, 27, .12);
  --shadow-lg: 0 24px 60px -20px rgba(6, 20, 27, .35);
  /* home (cream & green) is the default palette */
  --bg: #F7F5EF; --surface: #FFFFFF; --surface-2: #EFEDE4; --ink: #18241D; --muted: #5D6B6B;
  --line: rgba(27, 69, 50, .11); --accent: var(--accent-override, #1B4532); --accent-2: #9CAF88; --accent-ink: #F7F5EF;
  --accent-soft: rgba(27, 69, 50, .08); --ok: #1B4532; --warn: #8a5a12; --bad: #9b2c2c; --warn-bg: #f6ead4; --bad-bg: #f7e1df; --ok-bg: #e3eadc;
  --focus: #10333D;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 88px; }
body { margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.65; color: var(--ink); background: var(--bg); min-height: 100dvh; overflow-x: hidden; }
body.has-dialog { overflow: hidden; }
h1, h2, h3, h4 { line-height: 1.35; margin: 0; font-weight: 650; letter-spacing: 0; }
p { margin: 0 0 var(--sp-2); }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; inset-inline-start: 12px; top: -60px; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 10px; z-index: 100; }
.skip:focus { top: 12px; }
.muted { color: var(--muted); } .small { font-size: .875rem; } .tiny { font-size: .78rem; } .lg { font-size: 1.15rem; }
.pos { color: var(--ok); } .neg { color: var(--bad); } .warn { color: var(--warn); }
.error-text { color: var(--bad); } .ok-text { color: var(--ok); display: flex; gap: 6px; align-items: center; }
.spacer { flex: 1; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
.ic { width: 1.2em; height: 1.2em; flex: none; vertical-align: -0.2em; }

/* wordmark */
.wordmark { font-weight: 700; font-size: 1.6rem; line-height: 1; color: var(--accent); letter-spacing: -.02em; font-family: "IBM Plex Sans Arabic", system-ui, sans-serif; display: inline-flex; align-items: baseline; }
.wordmark::after { content: ""; width: .22em; height: .22em; border-radius: 50%; background: var(--accent-2); margin-inline-start: .08em; }
.wordmark.xl { font-size: 4rem; } .wordmark.hero { font-size: clamp(5rem, 16vw, 9rem); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; font-size: .95rem; text-decoration: none; transition: background .2s, border-color .2s, transform .12s, box-shadow .2s; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { box-shadow: 0 6px 18px -8px var(--accent); }
.btn.soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: .875rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[aria-busy=true] { position: relative; color: transparent !important; }
.btn[aria-busy=true]::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-color: var(--accent-ink) transparent var(--accent-ink) transparent; animation: spin .8s linear infinite; }
.btn:not(.primary):not(.danger)[aria-busy=true]::after { border-color: var(--accent) transparent var(--accent) transparent; }
.icon-btn { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; border: 1px solid transparent; background: transparent; color: var(--ink); position: relative; transition: background .2s; }
.icon-btn:hover:not(:disabled) { background: var(--accent-soft); }
.icon-btn:disabled { opacity: .35; }
.icon-btn.sm { width: 34px; height: 34px; border-radius: 10px; } .icon-btn.xs { width: 26px; height: 26px; border-radius: 8px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-align: start; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .78rem; font-style: normal; font-weight: 600; white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); } .chip.warn { background: var(--warn-bg); color: var(--warn); } .chip.hot { background: var(--accent); color: var(--accent-ink); } .chip.muted { opacity: .8; }
.chip-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: .9rem; white-space: nowrap; }
.chip-btn small { color: var(--muted); font-weight: 500; }
.chip-btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip-btn.on small { color: inherit; opacity: .8; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--surface-2); flex-wrap: wrap; }
.seg button, .seg .seg-opt span { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 9px; border: 0; background: transparent; font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer; }
.seg button small { opacity: .7; }
.seg button.on, .seg .seg-opt input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg .seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg .seg-opt input:focus-visible + span { outline: 3px solid var(--focus); }
.seg.sm button { min-height: 30px; padding: 0 10px; font-size: .82rem; }
.seg.icons button { padding: 0 8px; }

/* forms */
.form { display: grid; gap: var(--sp-4); }
.field { display: grid; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-size: .875rem; font-weight: 600; color: var(--muted); }
.field.inline { display: inline-grid; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 16px; transition: border-color .2s, box-shadow .2s; }
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:invalid:not(:placeholder-shown):not(:focus) { border-color: var(--bad); }
input[type=time], input[type=date], input[type=month], input[type=number] { direction: ltr; text-align: end; }
.row2, .row3, .row4 { display: grid; gap: var(--sp-3); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .row4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.form-error { color: var(--bad); font-size: .875rem; min-height: 0; margin: 0; }
.form-error:empty { display: none; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.switch input { appearance: none; width: 44px; height: 26px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); position: relative; flex: none; transition: background .2s; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: inset-inline-start .2s var(--ease); }
.switch input:checked { background: var(--accent); border-color: var(--accent); }
.switch input:checked::after { inset-inline-start: 20px; }
.switch.sm { font-size: .875rem; } .switch.sm input { width: 38px; height: 22px; } .switch.sm input::after { width: 16px; height: 16px; } .switch.sm input:checked::after { inset-inline-start: 18px; }
.save-inline { color: var(--accent); font-weight: 600; }

/* cards, sections */
.card { background: var(--surface); border-radius: var(--r-lg); padding: var(--sp-5); box-shadow: var(--shadow); border: 1px solid var(--line); min-width: 0; }
.sec-head { display: flex; align-items: center; gap: 10px; margin-bottom: var(--sp-4); flex-wrap: wrap; }
.sec-head h2 { font-size: 1.08rem; flex: 1; min-width: 0; outline: none; }
.sec-icon { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); flex: none; }
.sec-actions { display: flex; gap: 6px; }
.sub { font-size: .92rem; color: var(--muted); font-weight: 650; margin: var(--sp-4) 0 var(--sp-2); }
.sec.flash { animation: flash 1.2s var(--ease); }
@keyframes flash { 0% { box-shadow: 0 0 0 0 var(--accent); } 30% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 35%, transparent); } 100% { box-shadow: var(--shadow); } }
.empty { display: grid; justify-items: center; gap: 6px; text-align: center; padding: var(--sp-5) var(--sp-3); color: var(--muted); }
.empty .ic { width: 28px; height: 28px; opacity: .7; }
.empty p { margin: 0; }
.empty.big { padding: 60px 20px; }
.notice { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); text-decoration: none; font-weight: 600; margin: var(--sp-3) 0; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice > span { flex: 1; }
.sk-lines { display: grid; gap: 10px; } .sk-lines span { height: 14px; border-radius: 8px; background: linear-gradient(90deg, var(--surface-2), color-mix(in srgb, var(--surface-2) 40%, var(--surface)), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
.sk-lines span:nth-child(2) { width: 75%; } .sk-lines span:nth-child(3) { width: 55%; }
.sk-lines.page { padding: 24px; }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
.kv { display: grid; gap: 8px; margin: 0; } .kv > div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); } .kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 600; text-align: end; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: inherit; transition: width .6s var(--ease); }

/* avatars */
.avatar { position: relative; display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none; overflow: hidden; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar b { font-size: 1.05rem; }
.avatar.sm { width: 34px; height: 34px; } .avatar.sm b { font-size: .8rem; }
.avatar.md { width: 48px; height: 48px; }
.avatar.lg { width: 76px; height: 76px; } .avatar.lg b { font-size: 1.5rem; }

/* tables */
.table-wrap { overflow: auto; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); max-width: 100%; -webkit-overflow-scrolling: touch; }
.table-wrap table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem; }
.table-wrap th, .table-wrap td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table-wrap thead th { background: var(--surface-2); font-weight: 650; font-size: .82rem; color: var(--muted); }
.sticky-grid { max-height: 70vh; }
.sticky-grid thead th { position: sticky; top: 0; z-index: 2; }
.sticky-grid .sticky-col { position: sticky; inset-inline-start: 0; z-index: 1; background: var(--surface); box-shadow: -1px 0 0 var(--line) inset; }
.sticky-grid thead .sticky-col { z-index: 3; background: var(--surface-2); }
.is-today { background: color-mix(in srgb, var(--accent) 7%, transparent) !important; }

/* dialogs & sheets */
.dlg-wrap { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.dlg-backdrop { position: absolute; inset: 0; background: rgba(6, 20, 27, .45); opacity: 0; transition: opacity .2s; }
.dlg { position: relative; width: min(520px, 100%); max-height: min(88dvh, 900px); overflow: auto; background: var(--surface); color: var(--ink); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); transform: translateY(12px) scale(.98); opacity: 0; transition: transform .22s var(--ease), opacity .2s; overscroll-behavior: contain; }
.dlg-wide { width: min(980px, 100%); }
.dlg-wrap.in .dlg-backdrop { opacity: 1; } .dlg-wrap.in .dlg { transform: none; opacity: 1; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 0; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.dlg-head h2 { font-size: 1.1rem; }
.dlg-body { padding: 16px 20px 20px; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: var(--sp-4); }
.dlg-actions.col { flex-direction: column; align-items: stretch; }
@media (max-width: 640px) {
  .dlg-wrap { place-items: end stretch; padding: 0; }
  .dlg { width: 100%; max-height: 92dvh; border-radius: 22px 22px 0 0; transform: translateY(40px); padding-bottom: env(safe-area-inset-bottom); }
  .dlg-wide { width: 100%; }
  .row3, .row4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 420px) { .row2 { grid-template-columns: 1fr; } }

/* toasts */
#toasts { position: fixed; inset-inline: 0; bottom: max(16px, env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 8px; z-index: 80; pointer-events: none; padding: 0 12px; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; max-width: 520px; padding: 12px 16px; border-radius: 14px; background: #10333D; color: #F7F5EF; box-shadow: var(--shadow-lg); font-weight: 500; transform: translateY(12px); opacity: 0; transition: transform .25s var(--ease), opacity .25s; }
.toast.in { transform: none; opacity: 1; }
.toast-error { background: #6b1f1f; } .toast-success { background: #1B4532; }
.toast-action { background: rgba(255,255,255,.15); border: 0; color: inherit; padding: 4px 10px; border-radius: 8px; font-weight: 600; }

/* splash */
.splash { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 16px; text-align: center; padding: 24px; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }

/* charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 13px; font-family: var(--font); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: .08; }
.chart .dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart .bar { fill: var(--accent); opacity: .85; } .chart .bar.over { fill: var(--bad); }
.chart .goal { stroke: var(--accent-2); stroke-dasharray: 5 5; stroke-width: 1.5; }
.chart-empty { color: var(--muted); font-size: .875rem; padding: 24px 0; text-align: center; }
.chart-box { min-height: 120px; }
.ring-bg { fill: none; stroke: var(--surface-2); stroke-width: 10; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; transition: stroke-dasharray .8s var(--ease); }
.ring-fg.over { stroke: var(--bad); }
figure { margin: 0; } figcaption { font-weight: 650; font-size: .9rem; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
figcaption select { width: auto; min-height: 34px; padding: 4px 10px; font-size: .85rem; }

/* status pills */
.net-pill { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.net-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.net-pill.ok { color: var(--ok); } .net-pill.warn { color: var(--warn); } .net-pill.bad { color: var(--bad); }
.save-pill { border: 0; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 4px 12px; font-size: .78rem; font-weight: 600; }
.save-pill.ok { background: var(--ok-bg); color: var(--ok); } .save-pill.bad { background: var(--bad-bg); color: var(--bad); cursor: pointer; }
.bell .badge { position: absolute; top: 4px; inset-inline-end: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #9b2c2c; color: #fff; font-size: .7rem; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--surface); line-height: 1; }
.bell .badge.err { background: var(--warn); }
.bell.ring .ic { animation: ring .9s var(--ease); transform-origin: 50% 10%; }
@keyframes ring { 0%,100% { transform: rotate(0); } 20% { transform: rotate(14deg); } 40% { transform: rotate(-12deg); } 60% { transform: rotate(8deg); } 80% { transform: rotate(-4deg); } }
.nt-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.nt-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.nt { display: flex; align-items: flex-start; gap: 4px; border-radius: 14px; }
.nt.unread { background: var(--accent-soft); }
.nt-main { flex: 1; display: flex; gap: 10px; text-align: start; padding: 12px; background: none; border: 0; border-radius: 14px; min-width: 0; }
.nt-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 8px; flex: none; background: transparent; }
.nt.unread .nt-dot { background: #9b2c2c; }
.nt-text { display: grid; gap: 2px; min-width: 0; } .nt-text b { font-weight: 650; } .nt-text span { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.nt .icon-btn { margin-top: 8px; }

/* motion */
.m-stagger { animation: rise .55s var(--ease) both; animation-delay: var(--d, 0ms); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.m-reveal { opacity: 0; transform: translateY(18px); transition: opacity .5s var(--ease), transform .5s var(--ease); }
.m-reveal.m-in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .m-reveal { opacity: 1; transform: none; }
}
