:root {
  --navy: #14237a; --blue: #2747d1; --sky: #e6eeff; --bg: #f3f6fc; --card: #fff;
  --ink: #101b40; --muted: #63709a; --line: #dfe5f3;
  --green: #0f7f55; --green-bg: #dff5ea; --amber: #946200; --amber-bg: #fff1c9; --red: #b93425; --red-bg: #fde5e1;
  --link: #2747d1; --chip-ink: #14237a; --soft: #e6eaf5; --field: #c9d2e8; --label: #3b4770; --grey-bg: #eceef4; --grey-ink: #5b6480; --warn-ink: #6b4500;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme=light]) {
  --sky: #22305c; --bg: #0c1224; --card: #161f38; --ink: #e9edfb; --muted: #9ba8cf; --line: #2a3557;
  --green: #5fd6a3; --green-bg: #133a2c; --amber: #f0c257; --amber-bg: #40330f; --red: #ff9384; --red-bg: #4a211c;
  --link: #8fa6ff; --chip-ink: #c9d5ff; --soft: #232d4d; --field: #3a476f; --label: #b9c4e6; --grey-bg: #2a3350; --grey-ink: #aab4d4; --warn-ink: #f3d68a;
  color-scheme: dark;
} }
:root[data-theme=dark] {
  --sky: #22305c; --bg: #0c1224; --card: #161f38; --ink: #e9edfb; --muted: #9ba8cf; --line: #2a3557;
  --green: #5fd6a3; --green-bg: #133a2c; --amber: #f0c257; --amber-bg: #40330f; --red: #ff9384; --red-bg: #4a211c;
  --link: #8fa6ff; --chip-ink: #c9d5ff; --soft: #232d4d; --field: #3a476f; --label: #b9c4e6; --grey-bg: #2a3350; --grey-ink: #aab4d4; --warn-ink: #f3d68a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 Tajawal, "Segoe UI", Tahoma, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }
h1, h2, h3, p { margin: 0; }
small { font-size: .72em; font-weight: 500; opacity: .75; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

.top { position: sticky; top: 0; z-index: 5; background: var(--navy); color: #fff; display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
.top img { height: 38px; background: #fff; border-radius: 10px; padding: 3px 6px; }
.top h1 { font-size: 18px; font-weight: 800; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top button, .top a { background: rgba(255,255,255,.14); color: #fff; border: 0; border-radius: 10px; min-width: 44px; height: 44px; padding: 0 12px; font-size: 15px; display: grid; place-items: center; cursor: pointer; }
main { max-width: 760px; margin: 0 auto; padding: 16px 16px 110px; display: grid; gap: 16px; }

.nav { position: fixed; bottom: 0; inset-inline: 0; z-index: 5; background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; max-width: 150px; text-align: center; padding: 8px 2px 10px; color: var(--muted); font-size: 13px; font-weight: 700; }
.nav a svg { display: block; margin: 0 auto 2px; width: 24px; height: 24px; }
.nav a.on { color: var(--link); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.card > h2, .sec { font-size: 17px; font-weight: 800; }
.row { display: flex; align-items: center; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: 14px; }
.gap { display: grid; gap: 12px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.stat b { display: block; font-size: 22px; font-weight: 800; line-height: 1.3; }
.stat span { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat.main { background: var(--navy); border-color: var(--navy); color: #fff; }
.stat.main span { color: #c5d2ff; }
.stat i { display: block; font-style: normal; font-size: 12px; color: var(--muted); }
.stat.main i { color: #c5d2ff; }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.big { border: 0; border-radius: 16px; padding: 14px 6px; font-weight: 800; font-size: 15px; cursor: pointer; display: grid; gap: 4px; justify-items: center; color: #fff; background: var(--blue); }
.big svg { width: 28px; height: 28px; }
.big.out { background: #8a3b12; }
.big.alt { background: #0f6d63; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 16px; min-height: 44px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.ok { background: #0f7f55; border-color: #0f7f55; color: #fff; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }

.chip { display: inline-block; border-radius: 999px; padding: 1px 10px; font-size: 13px; font-weight: 700; background: var(--sky); color: var(--chip-ink); white-space: nowrap; }
.chip.green { background: var(--green-bg); color: var(--green); }
.chip.amber { background: var(--amber-bg); color: var(--amber); }
.chip.red { background: var(--red-bg); color: var(--red); }
.chip.grey { background: var(--grey-bg); color: var(--grey-ink); }

.bar { height: 14px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.bar > div { height: 100%; background: linear-gradient(90deg, #1a9a6a, #36c08c); border-radius: 999px; min-width: 4px; }
.proj { display: grid; gap: 8px; color: inherit; }
.proj h3 { font-size: 17px; font-weight: 800; }
.proj .line { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); font-weight: 700; }

.list { display: grid; }
.item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); color: inherit; min-height: 56px; cursor: pointer; background: none; border-inline: 0; border-top: 0; width: 100%; text-align: start; }
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item b { font-weight: 700; }
.item .amt { font-weight: 800; text-align: end; white-space: nowrap; }
.item img.th { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--sky); flex: none; }
.pos { color: var(--green); } .neg { color: var(--red); }

.tablewrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: start; white-space: nowrap; }
th { color: var(--muted); font-size: 13px; }
td.n, th.n { text-align: end; font-variant-numeric: tabular-nums; }
td.name { white-space: normal; min-width: 120px; font-weight: 700; }
td.ok { background: var(--green-bg); color: var(--green); font-weight: 800; }
td.credit { background: var(--sky); color: var(--chip-ink); font-weight: 800; }
td.due { background: var(--amber-bg); color: var(--warn-ink); font-weight: 800; }
tr[data-act] { cursor: pointer; }

.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; min-height: 40px; font-weight: 700; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--chip-ink); box-shadow: 0 1px 3px rgba(16,27,64,.15); }

.album { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.album button { border: 0; padding: 0; background: var(--sky); border-radius: 12px; overflow: hidden; aspect-ratio: 1; cursor: pointer; position: relative; }
.album img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album span { position: absolute; bottom: 0; inset-inline: 0; background: rgba(16,27,64,.72); color: #fff; font-size: 11px; padding: 2px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.strip button { flex: none; width: 120px; height: 120px; border: 0; padding: 0; border-radius: 12px; overflow: hidden; background: var(--sky); cursor: pointer; }
.strip img { width: 100%; height: 100%; object-fit: cover; }
.viewer { width: 100%; border-radius: 12px; display: block; }

.plan { position: relative; overflow: auto; border-radius: 12px; border: 1px solid var(--line); background: var(--card); max-height: 70vh; }
.plan .inner { position: relative; }
.plan img { display: block; width: 100%; }
.pin { position: absolute; transform: translate(-50%, -50%); min-width: 30px; height: 30px; padding: 0 5px; border-radius: 999px; border: 2px solid #fff; color: #fff; font-weight: 800; font-size: 13px; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.4); background: #6b7390; }
.pin.green { background: #0f7f55; } .pin.red { background: #b93425; } .pin.move { outline: 3px solid #ffb300; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--muted); font-weight: 700; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-inline-end: 4px; vertical-align: -1px; }

.sheet-bg { position: fixed; inset: 0; background: rgba(10,18,50,.5); z-index: 20; }
.sheet { position: fixed; z-index: 21; inset-inline: 0; bottom: 0; margin: 0 auto; max-width: 620px; max-height: 92vh; background: var(--card); border-radius: 20px 20px 0 0; display: flex; flex-direction: column; }
.sheet header { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet header h3 { flex: 1; font-size: 18px; font-weight: 800; }
.sheet .x { border: 0; background: var(--soft); border-radius: 50%; width: 40px; height: 40px; cursor: pointer; }
.sheet-body { padding: 16px; overflow-y: auto; display: grid; gap: 14px; }
.sheet footer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet footer .btn { width: 100%; min-height: 52px; font-size: 17px; }
@media (min-width: 700px) { .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 20px; } }

label.f { display: grid; gap: 4px; font-weight: 700; font-size: 14px; color: var(--label); }
.f input, .f select, .f textarea, input.in { width: 100%; border: 1.5px solid var(--field); border-radius: 12px; padding: 10px 12px; min-height: 48px; background: var(--card); font-size: 16px; font-weight: 500; }
.f input:focus, .f select:focus, .f textarea:focus, input.in:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: 13.5px; color: var(--muted); font-weight: 500; }
.note { background: var(--amber-bg); color: var(--warn-ink); border-radius: 12px; padding: 10px 12px; font-size: 14px; font-weight: 500; }
.splitrow { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.splitrow input[type=checkbox] { width: 22px; height: 22px; flex: none; }
.splitrow .grow { flex: 1; min-width: 0; font-weight: 700; font-size: 14.5px; }
.splitrow input.in { width: 110px; min-height: 40px; padding: 4px 8px; text-align: center; }
.itemrow { display: grid; grid-template-columns: 1fr 110px; gap: 8px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(180deg, var(--sky), var(--bg) 60%); }
.login .card { width: 100%; max-width: 400px; display: grid; gap: 14px; text-align: center; }
.login img { width: 210px; margin: 0 auto; border-radius: 14px; }
.login form { display: grid; gap: 12px; text-align: start; }
.receipt-img { width: 100%; border-radius: 12px; border: 1px solid var(--line); }
.empty { text-align: center; color: var(--muted); padding: 22px 8px; font-weight: 500; }

#toast { position: fixed; bottom: 96px; inset-inline: 16px; z-index: 40; display: grid; justify-items: center; pointer-events: none; }
#toast div { background: #14213f; color: #fff; padding: 10px 18px; border-radius: 12px; font-weight: 700; max-width: 440px; }
#toast div.err { background: var(--red); }
@media (prefers-reduced-motion: no-preference) { .sheet { animation: up .18s ease-out; } @keyframes up { from { translate: 0 30px; opacity: 0; } } }

img[src='/logo.png'] { background: #fff; border-radius: 12px; }

.clr { position: relative; display: block; }
.clr > input { padding-left: 46px; }
.clr > button { position: absolute; left: 7px; top: 50%; translate: 0 -50%; width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--soft); color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1; }
.clr > input:placeholder-shown + button { display: none; }
.btn svg { width: 20px; height: 20px; flex: none; }
