:root {
  --bg: #f7f6f2; --card: #ffffff; --line: #e9e6df; --line2: #f0ede6;
  --ink: #1f2328; --muted: #7a7770; --soft: #8a877f;
  --accent: #c9771a; --accent-bg: #fff4e0; --accent-line: #f0a43a;
  --green: #1f7a3d; --green-bg: #e4f5e9; --red: #b3261e; --red-bg: #fde6e3;
  --dark: #1f2328;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { background: var(--bg); color: var(--ink); }
body { font-family: "Tajawal", "Segoe UI", Tahoma, sans-serif; font-size: 15px; line-height: 1.5; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.appbar { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.appbar h1 { font-size: 20px; font-weight: 800; }
.appbar .sub { font-size: 12px; color: var(--muted); }
.pill { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 12.5px; white-space: nowrap; cursor: pointer; }
.pill.on { background: var(--accent-bg); border-color: var(--accent-line); color: var(--accent); font-weight: 700; }
.sync-btn { background: var(--green-bg); color: var(--green); border: 1px solid transparent; border-radius: 999px; padding: 6px 10px; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.sync-btn.stale { background: var(--accent-bg); color: var(--accent); border-color: var(--accent-line); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--dark); color: #fff; display: grid; place-items: center; font-weight: 800; border: 0; cursor: pointer; flex: none; }

main { flex: 1; padding: 0 16px 100px; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; background: var(--card); border-top: 1px solid var(--line); }
.tabs .inner { max-width: 560px; margin: 0 auto; display: flex; justify-content: space-around; padding: 8px 4px calc(10px + env(safe-area-inset-bottom)); }
.tabs a { flex: 1; text-align: center; color: var(--soft); font-size: 11.5px; padding: 2px 0; }
.tabs a i { display: block; font-style: normal; font-size: 20px; line-height: 1.2; }
.tabs a.on { color: var(--accent); font-weight: 700; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px; margin-bottom: 12px; }
.card.flat { padding: 0; overflow: hidden; }
.card h3 { font-size: 15px; font-weight: 800; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card h3 small { font-weight: 500; color: var(--muted); font-size: 12px; }
.section-title { font-size: 14.5px; font-weight: 800; margin: 14px 2px 8px; display: flex; justify-content: space-between; align-items: center; }
.section-title a, .section-title button { font-size: 12.5px; font-weight: 700; color: var(--accent); background: none; border: 0; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.big { font-size: 26px; font-weight: 800; letter-spacing: -.3px; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; min-width: 0; }
.kpi small { color: var(--muted); font-size: 12px; display: block; }
.kpi b { display: block; font-size: 19px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.dark { background: var(--dark); border-color: var(--dark); color: #fff; }
.kpi.dark small { color: #b8bcc2; }
.kpi.wide { grid-column: span 2; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.tile { background: var(--card); border: 1.5px solid var(--line); border-radius: 15px; padding: 12px 6px; text-align: center; font-weight: 700; font-size: 14px; cursor: pointer; user-select: none; min-height: 68px; display: flex; flex-direction: column; justify-content: center; transition: transform .08s; }
.tile:active { transform: scale(.96); }
.tile small { display: block; color: var(--soft); font-weight: 500; font-size: 12px; margin-top: 2px; }
.tile.present { border-color: var(--accent-line); background: var(--accent-bg); }
.tile.paid { border-color: #8fd1a5; background: var(--green-bg); }
.tile.paid small { color: var(--green); font-weight: 700; }
.tile.add { border-style: dashed; color: var(--accent); }

.list .item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line2); cursor: pointer; }
.list .item:last-child { border-bottom: 0; }
.list .item .t { font-weight: 700; }
.list .item .s { font-size: 12px; color: var(--muted); }
.list .item.off { opacity: .5; }
.x { background: none; border: 0; color: var(--red); font-size: 18px; padding: 2px 8px; cursor: pointer; }

.tag { border-radius: 8px; padding: 2px 8px; font-size: 12px; font-weight: 700; white-space: nowrap; display: inline-block; }
.tag.g { background: var(--green-bg); color: var(--green); }
.tag.r { background: var(--red-bg); color: var(--red); }
.tag.o { background: var(--accent-bg); color: var(--accent); }
.tag.n { background: #efede8; color: var(--muted); }

.btn { display: block; width: 100%; border: 0; border-radius: 16px; padding: 14px; font-weight: 800; font-size: 16px; text-align: center; cursor: pointer; background: var(--dark); color: #fff; }
.btn.accent { background: var(--accent); }
.btn.light { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--card); color: var(--red); border: 1px solid #f3c7c2; }
.btn.small { padding: 9px; font-size: 14px; border-radius: 12px; }
.btn:disabled { opacity: .5; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stack > * + * { margin-top: 8px; }

label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.input, select.input, textarea.input { width: 100%; background: #fff; border: 1.5px solid var(--line); border-radius: 13px; padding: 11px 12px; font-size: 17px; outline: none; }
.input:focus { border-color: var(--accent-line); }
.input.money { font-weight: 800; font-size: 22px; text-align: center; direction: ltr; }
.fields2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0 12px; font-weight: 700; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.seg { display: flex; background: #ecebe6; border-radius: 13px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 10px; font-weight: 700; color: var(--muted); cursor: pointer; font-size: 14px; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.datebar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.datebar button { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 18px; cursor: pointer; }
.datebar .lbl { font-weight: 800; text-align: center; flex: 1; }
.datebar .lbl small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 110px; padding-top: 6px; }
.bars .b { flex: 1; min-width: 3px; background: #eadfcf; border-radius: 5px 5px 2px 2px; position: relative; }
.bars .b.neg { background: #f3c7c2; }
.bars .b.on { background: var(--accent); }
.bars-l { display: flex; gap: 3px; font-size: 10px; color: var(--soft); margin-top: 4px; }
.bars-l span { flex: 1; text-align: center; overflow: hidden; white-space: nowrap; }

table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: right; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 12px; }
table.t td { padding: 7px 4px; border-bottom: 1px solid var(--line2); }
table.t td.n, table.t th.n { text-align: left; font-variant-numeric: tabular-nums; }
table.t tr:last-child td { border-bottom: 0; }
.scroll-x { overflow-x: auto; }

.mrow { padding: 8px 0; border-bottom: 1px solid var(--line2); font-size: 14px; }
.mrow:last-child { border-bottom: 0; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty .ic { font-size: 40px; }
.warn { background: var(--accent-bg); border: 1px solid var(--accent-line); border-radius: 14px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.loading { text-align: center; color: var(--muted); padding: 40px; }

/* net cash fields (manager) */
.cash-tile { border-radius: 18px; padding: 14px 16px; margin-bottom: 8px; color: #fff; cursor: pointer; }
.cash-tile .lbl { font-size: 13.5px; font-weight: 700; opacity: .92; }
.cash-tile .amt { font-size: 30px; font-weight: 800; letter-spacing: -.3px; margin: 2px 0; }
.cash-tile .sub { font-size: 12px; opacity: .85; }
.cash-tile .tag { background: rgba(255,255,255,.92); }
.cash-morning { background: linear-gradient(135deg, #f0a43a, #c9661a); }
.cash-evening { background: linear-gradient(135deg, #4a5bb0, #26306e); }
.cash-elec { background: linear-gradient(135deg, #8a63d2, #5b3aa6); cursor: default; }
.cash-total { background: linear-gradient(135deg, #23914a, #145c2c); cursor: default; margin-bottom: 12px; }
.cash-total .amt { font-size: 34px; }
.cash-tile.off { opacity: .45; cursor: default; }
.cash-coal { background: linear-gradient(135deg, #5a4a42, #2a211d); cursor: default; }
.cash-tile .acts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.cash-tile .acts button { border: 0; border-radius: 12px; padding: 10px 4px; font-weight: 800; font-size: 13.5px; cursor: pointer; background: rgba(255,255,255,.16); color: #fff; }
.cash-tile .acts button.main { background: #fff; color: #2a211d; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin: -4px 0 10px; }
.quick button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 6px 10px; font-size: 13px; font-weight: 700; cursor: pointer; color: var(--ink); }
.ledger-sum { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: 13.5px; }
.ledger-sum b { text-align: left; }

/* sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(20,20,18,.38); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 10px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; animation: up .18s ease-out; }
.sheet .grab { width: 40px; height: 4px; background: #d8d5cd; border-radius: 4px; margin: 0 auto 10px; }
.sheet h2 { font-size: 18px; font-weight: 800; margin-bottom: 12px; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

#toast { position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 40; pointer-events: none; }
#toast div { background: var(--dark); color: #fff; border-radius: 14px; padding: 10px 16px; font-weight: 700; font-size: 14px; margin-bottom: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.18); animation: up .2s; max-width: 90vw; }
#toast div.err { background: var(--red); }

/* login */
.login { padding: calc(40px + env(safe-area-inset-top)) 20px 30px; }
.login .logo { width: 64px; height: 64px; border-radius: 20px; background: var(--dark); color: #fff; display: grid; place-items: center; font-size: 30px; margin-bottom: 14px; }
.login h1 { font-size: 26px; font-weight: 800; }
.login p { color: var(--muted); margin-bottom: 22px; }
.login .grid { grid-template-columns: 1fr 1fr; }
.login .tile { min-height: 84px; font-size: 16px; }
