:root {
  --bg: #FBFBF9;
  --card: #FFFFFF;
  --ink: #2E3A56;
  --slate: #5C6B94;
  --powder: #BFDCF2;
  --soft: #EAF3FB;
  --deep: #33436F;
  --green: #2E7D5B;
  --red: #B2453F;
  --line: #E3E8F2;
  --serif: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --sans: Manrope, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --gutter: 16px;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Layout ---------- */
.top, #banner, main {
  max-width: 560px;
  margin: 0 auto;
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}
.top { padding-top: calc(env(safe-area-inset-top) + 18px); padding-bottom: 4px; }
.title { font-family: var(--serif); font-size: 27px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
main { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); }
#banner { margin-top: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin: 12px 0;
  box-shadow: 0 1px 2px rgba(46, 58, 86, .04), 0 6px 20px rgba(46, 58, 86, .04);
}
h2 { font-size: 17px; font-weight: 800; margin: 0 0 12px; }
.serif { font-family: var(--serif); font-weight: 700; font-size: 20px; }
.muted { color: var(--slate); font-size: 13px; margin: 0; }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* ---------- Forms ---------- */
label, .field-label { display: block; font-size: 13px; font-weight: 700; color: var(--slate); margin-bottom: 12px; }
.field-label { margin-bottom: 6px; }
input, select {
  display: block;
  width: 100%;
  min-width: 0;
  margin-top: 6px;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: 500 16px var(--sans);
  -webkit-appearance: none;
  appearance: none;
}
input[type=date] { line-height: 46px; }
input[type=date]::-webkit-date-and-time-value { text-align: left; }
select {
  padding-right: 38px;
  text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%235C6B94' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
input::placeholder { color: #A3ADC6; }
input:focus, select:focus { outline: none; border-color: var(--slate); box-shadow: 0 0 0 3px var(--soft); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 13px; font-weight: 600; color: var(--slate); min-height: 19px; margin: -4px 0 12px; }

.btn {
  display: block;
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  background: var(--deep);
  color: #fff;
  font: 700 16px var(--sans);
  padding: 0 16px;
  transition: transform .1s, opacity .1s;
}
.btn:active { transform: scale(.985); opacity: .92; }
.btn.ghost { background: var(--soft); color: var(--deep); }
.btn.small { min-height: 44px; font-size: 15px; width: auto; }
.btn + .btn { margin-top: 10px; }
.link-btn { border: 0; background: none; color: var(--red); font: 600 14px var(--sans); min-height: 44px; padding: 0 4px; }

.photo-row { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.photo-preview {
  width: 84px; height: 84px; flex: none;
  border-radius: 14px; background: var(--soft);
  display: grid; place-items: center; font-size: 34px; overflow: hidden;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }

/* ---------- Lists ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile { background: var(--soft); border-radius: 14px; padding: 12px 14px; }
main > section > .tiles .tile { background: var(--card); border: 1px solid var(--line); border-radius: 16px; }
.tile .k { font-size: 12px; font-weight: 700; color: var(--slate); }
.tile .v { font-size: 20px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; padding-top: 2px; }
.thumb { width: 48px; height: 48px; border-radius: 12px; object-fit: cover; flex: none; background: var(--soft); display: block; }
.thumb.ph { display: grid; place-items: center; font-size: 24px; }
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 700; font-size: 15px; line-height: 1.3; }
.item-sub { font-size: 13px; color: var(--slate); margin-top: 2px; }
.item-amt { font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.item.archived { opacity: .55; }
.subhead { font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--slate); margin: 18px 0 4px; }
.total-row { display: flex; justify-content: space-between; font-weight: 800; padding-top: 12px; border-top: 1px solid var(--line); margin-top: 4px; }
.empty { color: var(--slate); font-size: 14px; text-align: center; padding: 14px 0 6px; margin: 0; }

.icon-btn {
  flex: none;
  width: 44px; height: 44px;
  border: 0; border-radius: 12px;
  background: transparent;
  color: var(--slate);
  font-size: 18px;
  display: grid; place-items: center;
}
.icon-btn:active { background: var(--soft); }
.icon-btn:disabled { opacity: .3; }
.icon-btn.big { font-size: 30px; line-height: 1; color: var(--deep); }
.item .icon-btn { margin-right: -8px; }
.item .icon-btn + .icon-btn { margin-left: -8px; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--red); margin-right: 6px; vertical-align: 2px; }
.list-note { font-size: 13px; font-weight: 600; color: var(--red); margin: -4px 0 8px; }

/* ---------- Bulk costs ---------- */
.bulk-open { margin-top: 12px; }
.bulk-note { margin: -6px 0 8px; }
.bulk-row { padding: 12px 0; border-top: 1px solid var(--line); }
.bulk-row:first-child { border-top: 0; padding-top: 2px; }
.bulk-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.bulk-inputs label { margin: 0; font-size: 12px; }
.bulk-row input { margin-top: 4px; text-align: right; font-weight: 700; }
.bulk-row input::placeholder { font-weight: 500; }
.bulk-row input.invalid { border-color: var(--red); box-shadow: 0 0 0 3px #F6E3E2; }
.bulk-row.archived .item-main { opacity: .55; }
.item-stock { font-size: 13px; color: var(--slate); margin-top: 2px; }
.item-stock b { font-weight: 800; white-space: nowrap; }
.item.soldout { opacity: .5; }
.hint.neg { color: var(--red); }
#bulk-list { margin-bottom: 14px; }

/* ---------- Debts ---------- */
.debt-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.debt-tiles .tile { background: var(--card); border: 1px solid var(--line); border-radius: 16px; }
.debt-tiles .tile-debt { grid-column: 1 / -1; padding: 14px 16px; }
.tile-debt .v { font-family: var(--serif); font-size: 34px; font-weight: 700; line-height: 1.15; }
.purchase-head { display: flex; align-items: flex-start; gap: 8px; }
.purchase-head .icon-btn { margin: -10px -10px 0 0; }
.purchase-sums { font-size: 14px; font-weight: 600; margin: 8px 0 10px; font-variant-numeric: tabular-nums; }
.purchase-sums span { font-weight: 800; white-space: nowrap; }
.debt-amt { font-weight: 800; }
.debt-amt.neg { color: var(--red); }
.debt-amt.pos { color: var(--green); }
.progress { height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--powder); border-radius: 3px; }
.purchase.closed .progress span { background: var(--powder); }
.closed-badge { color: var(--green); font-weight: 800; }
.pay-list { margin-top: 12px; }
.pay-title { font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--slate); margin-bottom: 2px; }
.pay-row { display: flex; align-items: center; gap: 8px; font-size: 14px; border-top: 1px solid var(--line); min-height: 44px; }
.pay-row:first-of-type { border-top: 0; }
.pay-row span:first-child { flex: 1; color: var(--slate); }
.pay-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.pay-row .icon-btn { margin-right: -10px; font-size: 15px; }
.pay-none { margin-top: 10px; }
.pay-open { margin-top: 12px; }
.pay-form { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.link-btn.plain { color: var(--deep); margin: -6px 0 8px; }
.closed-wrap > summary { list-style: none; cursor: pointer; font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--slate); padding: 14px 0 4px; min-height: 44px; }
.closed-wrap > summary::-webkit-details-marker { display: none; }
.closed-wrap > summary::before { content: '▸ '; }
.closed-wrap[open] > summary::before { content: '▾ '; }
.purchase.closed { opacity: .85; }
.d-hint { text-align: center; padding: 8px 8px 0; font-size: 12px; }

/* suppliers */
.supplier-head {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: none; padding: 0 0 10px; text-align: left; color: var(--ink); min-height: 44px;
}
.supplier-head .item-main { display: block; }
.supplier-head .item-name { display: block; font-size: 16px; }
.supplier-head .purchase-sums { display: block; margin: 4px 0 0; }
.chev { flex: none; font-size: 16px; color: var(--slate); width: 24px; text-align: center; }
.supplier.paid-up .progress span { background: var(--powder); }
.supplier-body { margin-top: 12px; }
.supplier-body .purchase { padding: 14px 0; border-top: 1px solid var(--line); }
.supplier-body .purchase.closed { opacity: .85; }
.closed-wrap.inner > summary { padding-top: 10px; border-top: 1px solid var(--line); }
.supplier-actions { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px; margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); }
.supplier-actions .link-btn.plain { margin: 0; }

/* purchase items */
.pi-row { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px 0; margin-bottom: 10px; }
.pi-top { display: flex; align-items: center; gap: 6px; }
.pi-top select { margin-top: 0; }
.pi-top .icon-btn { margin-right: -6px; }
.pi-other { margin-top: 8px; }
.pi-row .row2 { margin-top: 10px; }
.add-item { margin-bottom: 8px; }
.items-sum { font-size: 14px; font-weight: 700; margin: 4px 0 12px; }
.total-diff { margin: -4px 0 12px; font-size: 13px; }
label.check { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); font-size: 15px; font-weight: 600; margin-bottom: 12px; }
label.check input[type=checkbox] {
  width: 22px; height: 22px; margin: 0; padding: 0; flex: none;
  -webkit-appearance: checkbox; appearance: auto; accent-color: var(--deep);
}
.p-items { margin-top: 10px; }
.p-item { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; padding: 5px 0; }
.p-item span:last-child { white-space: nowrap; color: var(--slate); font-variant-numeric: tabular-nums; }
.supplier-products { display: block; font-size: 13px; font-weight: 500; color: var(--slate); margin-top: 4px; }
.p-supplier { margin: -6px 0 12px; }
.item-supplier { font-size: 12px; color: var(--slate); margin-top: 2px; }

/* zakat */
.z-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.z-label { font-size: 14px; font-weight: 700; }
.z-note { font-size: 12px; margin-top: 2px; }
.z-val { font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.z-base { font-size: 16px; font-weight: 800; border-top: 1px solid var(--ink); border-bottom: 0; padding-top: 12px; }
.z-base div:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.z-pill { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--deep); color: #fff; border-radius: 14px; padding: 14px 16px; font-weight: 800; margin-bottom: 12px; }
.z-pill span:last-child { font-family: var(--serif); font-size: 24px; white-space: nowrap; }
.z-ok { background: #EAF4EF; color: var(--green); border-radius: 14px; padding: 12px 14px; font-weight: 700; font-size: 14px; margin-bottom: 12px; }
.z-date { margin-top: 8px; font-size: 12px; }
.z-disclaimer { font-size: 12px; margin-top: 8px; }
.zakat input.invalid { border-color: var(--red); box-shadow: 0 0 0 3px #F6E3E2; }
.zakat h2.serif { font-size: 22px; margin-bottom: 8px; }
.z-grow { flex: 1; min-width: 0; }
.z-breakdown > summary { list-style: none; cursor: pointer; font-size: 12px; font-weight: 700; color: var(--deep); min-height: 32px; display: flex; align-items: center; }
.z-breakdown > summary::-webkit-details-marker { display: none; }
.z-breakdown > summary::after { content: '▸'; margin-left: 4px; }
.z-breakdown[open] > summary::after { content: '▾'; }
.z-bd { font-size: 13px; color: var(--slate); padding: 2px 0 4px; }
.z-bd div { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; font-variant-numeric: tabular-nums; }
.z-warn { font-size: 12px; font-weight: 700; color: var(--red); margin-top: 4px; }
.z-recv { margin-bottom: 12px; }
.z-recv > summary { list-style: none; cursor: pointer; color: var(--deep); font-size: 14px; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
.z-recv > summary::-webkit-details-marker { display: none; }
.z-recv[open] > summary { min-height: 32px; }
.z-hint { font-weight: 500; color: var(--slate); opacity: .85; }
.z-gold { display: inline-flex; align-items: center; min-height: 44px; margin: -10px 0 6px; font-size: 13px; font-weight: 700; color: var(--deep); text-decoration: none; }

/* expense chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: 600 14px var(--sans); white-space: nowrap;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.chip:active { transform: scale(.97); }
.chip[aria-pressed=true] { background: var(--slate); border-color: var(--slate); color: #fff; }
.chip.add { color: var(--deep); border-style: dashed; }
.chip.custom { border-color: var(--powder); }
.chips-special { padding-top: 10px; border-top: 1px dashed var(--line); margin-bottom: 14px; }
.chip.special { border-color: var(--deep); color: var(--deep); }
.chip.special[aria-pressed=true] { background: var(--deep); color: #fff; }
.draw-note { margin: -4px 0 12px; }
.draws-hint { margin: -8px 0 8px; font-size: 12px; }
.r-draws { text-align: right; margin-top: 6px; font-size: 12px; }

/* write-offs */
.wo-card > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 10px; min-height: 32px; }
.wo-card > summary::-webkit-details-marker { display: none; }
.wo-card > summary h2 { margin: 0; }
.wo-card[open] > summary { margin-bottom: 12px; }
.wo-line { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px dashed var(--line); font-size: 14px; }
.wo-line .wo-text { flex: 1; min-width: 0; }
.wo-line .wo-cost { color: var(--slate); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.wo-sub { font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--slate); margin: 14px 0 2px; }
.wo-reasons { font-size: 13px; color: var(--slate); margin-bottom: 6px; }
.wo-reasons span { white-space: nowrap; }

/* ---------- Report ---------- */
.month-switch { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.month-label { font-weight: 800; font-size: 17px; }
.report-head { margin-bottom: 10px; }
.report-head h2 { margin-bottom: 2px; }
.r-empty { padding: 4px 0 10px; text-align: left; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.pl td { padding: 10px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.pl .num { text-align: right; white-space: nowrap; padding-left: 12px; }
.pl .strong td { font-weight: 800; }
.pl .indent td { font-size: 14px; color: var(--slate); padding: 7px 0; border-bottom: 1px dashed var(--line); }
.pl .indent td:first-child { padding-left: 14px; }
.pl .note { display: block; font-size: 12px; font-weight: 600; color: var(--slate); }
.pl .net td { border-top: 3px double var(--ink); border-bottom: 0; padding-top: 14px; font-weight: 800; letter-spacing: .02em; }
.pl .net .num { font-family: var(--serif); font-size: 26px; font-weight: 700; line-height: 1.1; letter-spacing: 0; }
.delta { text-align: right; font-size: 13px; font-weight: 700; margin-top: 4px; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.flat { color: var(--slate); }

.data th { font-size: 12px; font-weight: 700; color: var(--slate); text-align: right; padding: 0 0 8px 10px; border-bottom: 1px solid var(--line); }
.data td { font-size: 14px; text-align: right; padding: 9px 0 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data th:first-child, .data td:first-child { text-align: left; padding-left: 0; }
.data td:first-child { white-space: normal; font-weight: 600; }
.data tfoot td { font-weight: 800; border-bottom: 0; }

/* ---------- Chrome ---------- */
.banner {
  display: flex; gap: 10px; align-items: center;
  border: 1px solid var(--powder); background: var(--soft); color: var(--deep);
  border-radius: 14px; padding: 8px 8px 8px 14px;
  font: 700 13px/1.35 var(--sans);
}
.banner-text { flex: 1; min-width: 0; }
.banner-btn {
  flex: none; min-height: 44px; padding: 0 14px;
  border: 0; border-radius: 11px;
  background: var(--deep); color: #fff; font: 700 14px var(--sans);
}
.banner-btn:disabled { opacity: .6; }
.banner.overdue { background: #FBEDEC; border-color: #EBC3C0; color: var(--red); }
.banner.overdue .banner-btn { background: var(--red); }

/* ---------- Backup prompt ---------- */
.modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(46, 58, 86, .38); }
.sheet {
  position: relative; width: 100%; max-width: 560px;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 22px max(20px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  box-shadow: 0 -8px 30px rgba(46, 58, 86, .16);
  animation: sheet-up .22s ease-out;
}
.sheet-icon { font-size: 34px; line-height: 1; margin-bottom: 10px; }
.sheet h2 { font-family: var(--serif); font-size: 21px; font-weight: 700; line-height: 1.25; margin-bottom: 8px; }
.sheet p { font-size: 14px; margin-bottom: 18px; }
.sheet .btn:first-of-type { min-height: 56px; font-size: 17px; }
@keyframes sheet-up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 0;
  background: rgba(251, 251, 249, .94);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px max(4px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
}
.tabbar button {
  border: 0; background: none;
  min-height: 52px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font: 700 10.5px var(--sans); color: var(--slate); letter-spacing: -0.01em;
  min-width: 0; padding: 0 1px; white-space: nowrap;
}
.tabbar .ico { font-size: 20px; line-height: 1; filter: grayscale(.5); opacity: .75; }
.tabbar button[aria-current=page] { color: var(--deep); background: var(--soft); }
.tabbar button[aria-current=page] .ico { filter: none; opacity: 1; }

.toast {
  position: fixed; left: 50%; z-index: 20;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff;
  padding: 11px 16px; border-radius: 12px;
  font: 700 14px var(--sans); max-width: calc(100vw - 32px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
