/* حِسبة — dark purple design with a light alternative. */
:root, [data-theme="dark"] {
  --bg: #0B0916; --bar: #06050C; --surface: #1B1338; --surface2: #251A4D; --surface3: #2F2260;
  --line: rgba(255,255,255,.07); --line2: rgba(255,255,255,.15);
  --text: #FFFFFF; --muted: #ABA4CC; --faint: #7F79A3;
  --primary: #7B5CFA; --primary2: #9C85FF; --onprimary: #FFFFFF; --tabbar: #6A4BE8;
  --up: #3FD08A; --down: #FF6B81; --warn: #FFC46B; --warnbg: rgba(255,181,71,.10); --warnline: rgba(255,181,71,.28);
  --gold: #F2C94C; --track: rgba(255,255,255,.10); --tint: rgba(255,255,255,.06);
  --shadow: 0 24px 50px rgba(0,0,0,.45); --scrim: rgba(4,2,12,.62);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #F3F1FA; --bar: #FFFFFF; --surface: #FFFFFF; --surface2: #EFEBFC; --surface3: #E4DEFA;
  --line: rgba(26,20,51,.08); --line2: rgba(26,20,51,.16);
  --text: #1A1433; --muted: #5F5880; --faint: #8A84A6;
  --primary: #6A4BE8; --primary2: #6A4BE8; --onprimary: #FFFFFF; --tabbar: #6A4BE8;
  --up: #13915A; --down: #D6334A; --warn: #A3600C; --warnbg: #FEF2DE; --warnline: #F2D3A4;
  --gold: #C99A14; --track: rgba(26,20,51,.08); --tint: #EFEBFC;
  --shadow: 0 20px 44px rgba(26,20,51,.18); --scrim: rgba(20,14,40,.45);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-family: 'Readex Pro', -apple-system, 'Geeza Pro', system-ui, sans-serif; font-size: 15px; line-height: 1.5; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.num { font-family: 'Rubik', 'Readex Pro', system-ui, sans-serif; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .up { color: var(--up); } .down { color: var(--down); } .warn { color: var(--warn); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--primary2); outline-offset: 2px; }
.tap { transition: transform .15s ease, background-color .2s ease, opacity .2s; } .tap:active { transform: scale(.96); }

/* ---- shell ---- */
#app { min-height: 100%; }
.topbar { position: fixed; inset: 0 0 auto 0; z-index: 20; background: var(--bar); border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 8px) 12px 10px; display: flex; align-items: center; gap: 6px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.spacer { flex: 1; }
.iconbtn { width: 42px; height: 42px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); position: relative; }
.iconbtn.solid { background: var(--primary); color: #fff; }
.iconbtn.soft { background: var(--surface2); color: var(--text); }
.badge { position: absolute; top: 3px; left: 3px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: #F0405B; color: #fff; font-size: 10px; font-weight: 600; display: flex; align-items: center; justify-content: center; border: 2px solid var(--bar); }
main.page { padding: calc(env(safe-area-inset-top) + 74px) 14px calc(env(safe-area-inset-bottom) + 100px); display: flex; flex-direction: column; gap: 12px; max-width: 640px; margin: 0 auto; animation: fadeUp .3s cubic-bezier(.2,.8,.2,1); }
main.page.full { padding-top: calc(env(safe-area-inset-top) + 16px); }
.tabbar { position: fixed; inset: auto 0 0 0; z-index: 20; background: var(--tabbar); border-radius: 22px 22px 0 0;
  padding: 6px 6px calc(env(safe-area-inset-bottom) + 8px); display: grid; grid-template-columns: repeat(5, 1fr); }
.tab { min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; color: rgba(255,255,255,.75); }
.tab[aria-current="page"] { color: #fff; font-weight: 600; }
.tab .avatar { width: 24px; height: 24px; border-radius: 12px; background: var(--gold); color: #3A2A00; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

/* ---- blocks ---- */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; padding: 2px; }
.head h1 { margin: 0; font-size: 20px; font-weight: 600; }
.head p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.card h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card .sub { font-size: 12px; color: var(--muted); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
.kpi { text-align: right; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 6px; min-height: 104px; }
.kpi .label { font-size: 12px; color: var(--muted); } .kpi .value { font-size: 19px; font-weight: 600; } .kpi .delta { font-size: 11px; font-weight: 500; }
.action { background: var(--surface2); border-radius: 14px; padding: 12px 4px; display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 12px; }
.action .ic { width: 46px; height: 46px; border-radius: 14px; display: flex; align-items: center; justify-content: center; color: #fff; }
.banner { display: flex; align-items: center; gap: 12px; text-align: right; width: 100%; border-radius: 16px; padding: 14px; background: var(--warnbg); border: 1px solid var(--warnline); }
.banner.info { background: var(--surface2); border-color: var(--line2); }
.banner .t { font-size: 14px; font-weight: 500; } .banner .b { font-size: 12px; color: var(--muted); }
.list { padding: 2px 14px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 0; width: 100%; text-align: right; }
.item + .item { border-top: 1px solid var(--line); }
.item .tile { width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; background: var(--tint); }
.item .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item .title { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { font-size: 11.5px; color: var(--muted); }
.item .amt { font-size: 14px; font-weight: 600; }
.daylabel { font-size: 12px; color: var(--muted); padding: 10px 4px 0; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px; }
.stat { display: flex; align-items: center; gap: 10px; }
.stat .ic { width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat .l { font-size: 11px; color: var(--muted); } .stat .v { font-size: 16px; font-weight: 600; }

/* ---- controls ---- */
.btn { min-height: 52px; border-radius: 14px; padding: 0 18px; font-size: 15px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--primary); color: var(--onprimary); }
.btn.ghost { border: 1px solid var(--line2); }
.btn.danger { color: var(--down); border: 1px solid var(--line2); }
.btn.block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { background: var(--surface2); color: var(--faint); }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.link { color: var(--primary2); font-size: 13px; min-height: 36px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 2px 14px; }
.chips::-webkit-scrollbar { display: none; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 10px; font-size: 12.5px; white-space: nowrap; border: 1px solid var(--line2); display: inline-flex; align-items: center; gap: 6px; }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .dot { width: 8px; height: 8px; border-radius: 4px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { min-height: 34px; padding: 0 12px; border-radius: 9px; font-size: 12.5px; color: var(--muted); }
.seg button[aria-selected="true"] { background: var(--primary); color: #fff; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; min-height: 46px; border-radius: 12px; border: 1px solid var(--line2); background: var(--bg); padding: 10px 12px; font-size: 16px; }
textarea.input { min-height: 84px; resize: vertical; line-height: 1.7; }
.input.big { font-size: 30px; font-weight: 600; text-align: center; min-height: 64px; }
.switch { width: 50px; height: 30px; border-radius: 15px; padding: 3px; background: var(--track); display: flex; flex-shrink: 0; transition: background .2s; }
.switch::after { content: ''; width: 24px; height: 24px; border-radius: 12px; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); transition: transform .2s; }
.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"]::after { transform: translateX(-20px); }
.setrow { display: flex; align-items: center; gap: 12px; padding: 14px 0; }
.setrow + .setrow { border-top: 1px solid var(--line); }
.setrow .txt { flex: 1; display: flex; flex-direction: column; gap: 2px; } .setrow .txt b { font-weight: 400; font-size: 14px; } .setrow .txt small { font-size: 11.5px; color: var(--muted); }

/* ---- review rows ---- */
.ritem { padding: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.ritem + .ritem { border-top: 1px solid var(--line); }
.ritem.flag { background: var(--warnbg); border: 1px solid var(--warnline); border-radius: 12px; padding: 12px; margin: 6px -6px; }
.ritem .nums { display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 6px; }
.ritem .nums .input { font-size: 15px; min-height: 40px; padding: 6px 8px; text-align: left; }
.ritem .note { font-size: 12px; color: var(--warn); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check .mk { width: 22px; height: 22px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; }

/* ---- overlays ---- */
.scrim { position: fixed; inset: 0; z-index: 40; background: var(--scrim); display: flex; animation: fadeIn .2s ease; }
.sheet { margin-top: auto; width: 100%; max-height: 92vh; overflow-y: auto; background: var(--surface); border-top: 1px solid var(--line2); border-radius: 24px 24px 0 0; padding: 10px 16px calc(env(safe-area-inset-bottom) + 18px); display: flex; flex-direction: column; gap: 12px; animation: sheetUp .32s cubic-bezier(.2,.8,.2,1); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line2); align-self: center; }
.sheet h2 { margin: 0; font-size: 17px; font-weight: 600; text-align: center; }
.drawer { width: 292px; max-width: 84vw; height: 100%; overflow-y: auto; background: var(--bar); border-left: 1px solid var(--line); padding: calc(env(safe-area-inset-top) + 12px) 14px calc(env(safe-area-inset-bottom) + 20px); display: flex; flex-direction: column; gap: 4px; animation: drawerIn .3s cubic-bezier(.2,.8,.2,1); }
.navitem { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 14px; border-radius: 12px; font-size: 14px; text-align: right; width: 100%; }
.navitem[aria-current="page"] { background: var(--primary); color: #fff; }
.navhead { font-size: 13px; font-weight: 600; margin: 14px 6px 4px; }
.popover { position: fixed; top: calc(env(safe-area-inset-top) + 66px); left: 10px; width: min(320px, calc(100vw - 20px)); z-index: 45; background: var(--surface); border: 1px solid var(--line2); border-radius: 18px; padding: 8px; box-shadow: var(--shadow); animation: pop .2s ease; max-height: 70vh; overflow-y: auto; }
.toast { position: fixed; top: calc(env(safe-area-inset-top) + 70px); left: 50%; transform: translateX(-50%); z-index: 60; background: var(--primary); color: #fff; padding: 11px 18px; border-radius: 12px; font-size: 13.5px; box-shadow: var(--shadow); animation: toast .35s ease; max-width: calc(100vw - 32px); text-align: center; }
.toast.err { background: #C93850; }
.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; min-height: 60vh; text-align: center; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 4px solid var(--surface3); border-top-color: var(--primary2); animation: spin .9s linear infinite; }
.orb { width: 128px; height: 128px; border-radius: 64px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; }
.orb.live { animation: pulse 1.6s ease-out infinite; }
.wave { display: flex; align-items: center; gap: 5px; height: 44px; }
.wave span { width: 4px; border-radius: 2px; background: var(--primary2); animation: wave 1.1s ease-in-out infinite; }
.thumb { width: 100%; max-height: 240px; object-fit: contain; border-radius: 12px; background: #000; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes drawerIn { from { transform: translateX(100%); } to { transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
@keyframes toast { from { opacity: 0; transform: translate(-50%, -12px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes wave { 0%,100% { transform: scaleY(.25); } 50% { transform: scaleY(1); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(123,92,250,.45); } 100% { box-shadow: 0 0 0 34px rgba(123,92,250,0); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---- charts ---- */
.chart { display: flex; gap: 6px; margin-top: 8px; }
.yaxis { display: flex; flex-direction: column; justify-content: space-between; height: 140px; font-size: 10px; color: var(--faint); width: 30px; text-align: right; }
.plot { position: relative; flex: 1; height: 140px; }
.plot svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.cdot { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: var(--primary2); transform: translate(-50%,-50%); pointer-events: none; opacity: .8; }
.cdot.on { width: 12px; height: 12px; background: #fff; border: 3px solid var(--primary); opacity: 1; }
.ctip { position: absolute; transform: translate(-50%,-100%); background: var(--primary); color: #fff; font-size: 11px; padding: 3px 8px; border-radius: 8px; white-space: nowrap; pointer-events: none; }
.hits { position: absolute; inset: 0; display: flex; }
.xaxis { display: flex; padding-right: 36px; font-size: 10px; color: var(--faint); margin-top: 4px; }
.donut-wrap { position: relative; width: 200px; height: 200px; margin: 0 auto; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; pointer-events: none; text-align: center; padding: 0 40px; }
.bar { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; }
