:root {
  --bg: #fbf7f2; --card: #fff; --ink: #2a1d12; --muted: #7d6a5a; --line: #eadfd3;
  --brand: #7a3e12; --brand-ink: #fff; --ok: #1d7a46; --warn: #a15c00; --bad: #b3261e;
  --radius: 12px; --tap: 44px;
  font-family: system-ui, "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif; font-size: 16px; color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #17120e; --card: #221a14; --ink: #f2e9df; --muted: #b5a291; --line: #3a2e24; --brand: #e0a060; --brand-ink: #1a0f06; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
h1 { font-size: 1.4rem; margin: 0; } h2 { font-size: 1.25rem; margin: .5rem 0 1rem; } h3 { font-size: 1.05rem; margin: 0 0 .75rem; }
button, select, input, textarea { font: inherit; min-height: var(--tap); border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: .4rem .8rem; }
button { cursor: pointer; } button:disabled { opacity: .5; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.muted { color: var(--muted); }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; } .between { justify-content: space-between; } .spacer { flex: 1; }
.filters { margin-bottom: .75rem; } .filters label { display: flex; gap: .4rem; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.form { display: grid; gap: .6rem; } .field { display: grid; gap: .25rem; } .field label { font-size: .9rem; color: var(--muted); }
.check { display: flex; gap: .5rem; align-items: center; min-height: var(--tap); } .check input { min-height: auto; width: 1.3rem; height: 1.3rem; }
fieldset { border: 1px solid var(--line); border-radius: 8px; }
.lines .line { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: .5rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; }
.stat-l { font-size: .85rem; color: var(--muted); }
.stat-v { font-size: 1.2rem; font-weight: 700; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.stat.warn { border-color: var(--warn); } .stat.warn .stat-v { color: var(--warn); } .stat.ok .stat-v { color: var(--ok); }
.result .big { font-size: 2rem; font-weight: 800; margin: .3rem 0 .8rem; font-variant-numeric: tabular-nums; }
.neg { color: var(--bad); }
.legend { font-size: .85rem; color: var(--muted); border-inline-start: 3px solid var(--line); padding-inline-start: .6rem; }
.alert { background: #fff4e0; color: #6b3d00; border: 1px solid #f0c27a; border-radius: 8px; padding: .6rem .8rem; margin: .5rem 0; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: start; padding: .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; }
.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
td button { min-height: 38px; margin: 2px; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .8rem; background: var(--line); }
.b-RECEIVED, .b-PAID, .b-CONFIRMED, .b-APPROVED, .b-RESOLVED { background: #d8f0e2; color: #0f5130; }
.b-DISCREPANCY, .b-UNPAID, .b-REJECTED { background: #fbe0de; color: #7d1a14; }
.b-DISPATCHED, .b-PENDING, .b-PARTIALLY_PAID, .b-POSTED { background: #fdebc8; color: #6b3d00; }
.toast { position: fixed; inset-inline: 1rem; bottom: 5.5rem; margin-inline: auto; max-width: 480px; background: var(--ink); color: var(--bg); padding: .8rem 1rem; border-radius: 10px; z-index: 50; }
.toast.bad { background: var(--bad); color: #fff; }
dialog { border: none; border-radius: var(--radius); padding: 1rem; width: min(480px, 92vw); background: var(--card); color: var(--ink); }
dialog::backdrop { background: #0006; }
pre { white-space: pre-wrap; font-size: .75rem; max-width: 40ch; }

/* layout */
.top { position: sticky; top: 0; z-index: 10; display: flex; gap: .6rem; align-items: center; padding: .5rem 1rem; background: var(--brand); color: var(--brand-ink); flex-wrap: wrap; }
.top button { min-height: 36px; background: transparent; color: inherit; border-color: currentColor; }
.branch { background: #0002; padding: .2rem .6rem; border-radius: 99px; font-weight: 600; }
#main { padding: 1rem; max-width: 1200px; margin-inline: auto; padding-bottom: 6rem; }
nav.side { display: none; }
nav.bottom { position: fixed; bottom: 0; inset-inline: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); z-index: 10; padding-bottom: env(safe-area-inset-bottom); }
nav button { border: none; background: none; display: flex; flex-direction: column; align-items: center; gap: .1rem; font-size: .75rem; flex: 1; border-radius: 0; }
nav button.on { color: var(--brand); font-weight: 700; box-shadow: inset 0 3px 0 var(--brand); }
.more { flex: 1; position: relative; }
.more summary { list-style: none; display: flex; align-items: center; justify-content: center; height: 100%; font-size: .8rem; cursor: pointer; min-height: 56px; }
.more > div { position: absolute; bottom: 100%; inset-inline-end: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); min-width: 220px; padding: .3rem; }
.more > div button { flex-direction: row; justify-content: flex-start; font-size: .95rem; width: 100%; min-height: var(--tap); gap: .6rem; }
.install { position: fixed; bottom: 5rem; inset-inline-end: 1rem; z-index: 20; }
.login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login > .card { width: min(420px, 100%); }
.printonly { display: none; }

@media (min-width: 900px) {
  #app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: auto auto 1fr; }
  .top, #offline { grid-column: 1 / -1; }
  nav.side { display: flex; flex-direction: column; padding: .5rem; gap: .2rem; border-inline-end: 1px solid var(--line); min-height: calc(100vh - 52px); }
  nav.side button { flex-direction: row; justify-content: flex-start; font-size: .95rem; gap: .6rem; flex: none; border-radius: 8px; padding: .5rem .8rem; }
  nav.side button.on { box-shadow: none; background: var(--line); }
  nav.bottom { display: none; }
  #main { padding-bottom: 2rem; width: 100%; }
  .login { grid-column: 1 / -1; }
}
@media (max-width: 600px) {
  .lines .line { grid-template-columns: 1fr 1fr; }
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem; padding: .3rem .5rem; }
  td { border: none; display: flex; justify-content: space-between; gap: 1rem; padding: .3rem 0; text-align: end; }
  td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: start; }
}
@media print {
  .noprint, nav, .top, form.card, .install, .toast { display: none !important; }
  .printonly { display: block; }
  #app { display: block; } body { background: #fff; }
  #main { padding: 0; max-width: none; }
  .card { break-inside: avoid; border-color: #ccc; }
}
.top .muted { color: inherit; opacity: .9; }
