/* دفتر النقد — one sheet. Tokens first; dark mode redefines them. */
:root {
  --bg: #f4f3ef;
  --panel: #ffffff;
  --ink: #1d2320;
  --muted: #5f6964;
  --hair: #dedcd4;
  --brand: #1f5f4a;
  --brand-ink: #ffffff;
  --brand-soft: #e3efe9;
  --in: #1f5f4a;
  --out: #8a3b1e;
  --warn-bg: #fff4dc;
  --warn-ink: #6b4a00;
  --void: #9a9f9b;
  --focus: #2f7dd1;
  --r-panel: 10px;
  --r-field: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --panel: #1c211f;
    --ink: #e7ebe8;
    --muted: #a3ada8;
    --hair: #2e3532;
    --brand: #5fb592;
    --brand-ink: #0d1a14;
    --brand-soft: #22332c;
    --in: #79c9a6;
    --out: #f0a07f;
    --warn-bg: #3a2f14;
    --warn-ink: #f5d68b;
    --void: #6d7571;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/22px 'IBM Plex Sans Arabic', system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
.hidden, [hidden] { display: none !important; }
.field { display: grid; gap: 4px; }
.lbl { font-size: 12px; color: var(--muted); }
.skip { position: absolute; inset-inline-start: -999px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip:focus { inset-inline-start: 8px; top: 8px; background: var(--panel); padding: 6px 10px; z-index: 9; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 22px; line-height: 30px; font-weight: 600; margin: 0; }
h2 { font-size: 16px; line-height: 24px; font-weight: 600; margin: 0 0 12px; }
.num, input[type=number], input[type=date] { direction: ltr; unicode-bidi: plaintext; }

/* the two sheets: the menu comes from the page's start edge (right), the filter from the far edge (left) —
   each from the side its button sits on, three quarters of the screen wide */
dialog.sheet { position: fixed; top: 0; bottom: 0; height: 100dvh; max-height: none; max-width: none;
               width: min(75vw, 480px); min-width: min(280px, 100vw); margin: 0; padding: 20px 16px; border: 0;
               border-radius: 0; background: var(--panel); color: var(--ink); overflow-y: auto; }
dialog.sheet[open] { display: flex; flex-direction: column; gap: 20px; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .35); }
#nav { right: 0; left: auto; border-left: 1px solid var(--hair); }
#filt { left: 0; right: auto; border-right: 1px solid var(--hair); }
@media (max-width: 720px) { dialog.sheet { width: 75vw; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; }
.sheet-foot { display: flex; gap: 8px; justify-content: space-between; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--hair); }
#filt .filters { display: grid; gap: 14px; }
#filt .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { #filt .two { grid-template-columns: 1fr; } }
.brand { display: flex; align-items: baseline; gap: 8px; font-weight: 600; font-size: 16px; }
.brand small { color: var(--muted); font-weight: 400; font-size: 12px; }
.mark { width: 14px; height: 14px; border-radius: 4px; background: var(--brand); align-self: center; }
#tabs { display: grid; gap: 2px; flex: 1; align-content: start; }
#tabs button { border: 0; background: none; color: var(--ink); padding: 10px 12px; border-radius: var(--r-field);
               font: inherit; cursor: pointer; text-align: start; }
#tabs button:hover { background: var(--bg); }
#tabs button[aria-current=page] { background: var(--brand-soft); font-weight: 500; }
.who { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted);
       border-top: 1px solid var(--hair); padding-top: 12px; }
button.icon { display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0; color: var(--ink); }

main { max-width: 1400px; margin: 0 auto; padding: 20px 24px 64px; }
.bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.bar .grow { flex: 1; }
.panel { background: var(--panel); border: 1px solid var(--hair); border-radius: var(--r-panel); box-shadow: var(--shadow); }
.pad { padding: 16px; }

/* buttons and fields */
button, .btn {
  font: inherit; cursor: pointer; border-radius: var(--r-field); padding: 7px 14px; border: 1px solid var(--hair);
  background: var(--panel); color: var(--ink);
}
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 500; }
button.ghost { background: none; border-color: transparent; color: var(--muted); padding: 6px 8px; }
button.ghost:hover { color: var(--ink); background: var(--bg); }
button.danger { color: var(--out); }
button:disabled { opacity: .55; cursor: default; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--panel);
  border: 1px solid var(--hair); border-radius: var(--r-field); padding: 7px 10px; min-width: 0;
}
textarea { resize: vertical; min-height: 64px; }
.shown { margin: -8px 0 12px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink); }

/* the sums */
.sums { display: grid; grid-template-columns: minmax(0, 560px); gap: 16px; margin-bottom: 16px; }
.sum { padding: 14px 16px; }
.sum .cur { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.sum dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.sum dt { font-size: 12px; color: var(--muted); }
.sum dd { margin: 0; font-size: 20px; line-height: 28px; font-weight: 600; direction: ltr; text-align: end; }
.sum dd.neg { color: var(--out); }

/* the table */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { font-size: 12px; font-weight: 500; color: var(--muted); text-align: start; padding: 10px 12px; border-bottom: 1px solid var(--hair);
     position: sticky; top: 0; background: var(--panel); white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid var(--hair); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.amt { direction: ltr; text-align: left; white-space: nowrap; font-weight: 500; }
td.nowrap { white-space: nowrap; }
tr.void td { color: var(--void); }
tr.void td.amt { text-decoration: line-through; }
.tag { display: inline-block; font-size: 12px; line-height: 18px; padding: 1px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.tag.in { color: var(--in); background: var(--brand-soft); }
.tag.out { color: var(--out); background: color-mix(in srgb, var(--out) 12%, transparent); }
.said { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.row-actions { white-space: nowrap; }
.more { display: flex; justify-content: center; padding: 12px; }

/* lists (categories, people) */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--hair); }
.list li:last-child { border-bottom: 0; }
.list li .grow { flex: 1; }
.list li.off .grow { color: var(--void); }
.code { font-size: 22px; font-weight: 600; letter-spacing: 0; direction: ltr; display: inline-block; padding: 4px 10px;
        background: var(--brand-soft); border-radius: var(--r-field); }
.note { color: var(--muted); font-size: 13px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--r-field); padding: 8px 12px; font-size: 13px; }

/* the dialog */
dialog { border: 1px solid var(--hair); border-radius: var(--r-panel); padding: 0; width: min(520px, calc(100vw - 32px));
         background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog form { display: grid; gap: 14px; padding: 20px; }
dialog .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
dialog .seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--hair); border-radius: var(--r-field); overflow: hidden; }
dialog .seg label { display: block; color: var(--ink); font-size: 14px; }
dialog .seg input { position: absolute; opacity: 0; pointer-events: none; }
dialog .seg span { display: block; text-align: center; padding: 8px; cursor: pointer; }
dialog .seg input:checked + span { background: var(--brand-soft); font-weight: 500; }
dialog .seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -2px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; }
.err { color: var(--out); font-size: 12px; min-height: 0; }

/* sign in */
#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
#login form { width: min(380px, 100%); display: grid; gap: 14px; padding: 28px; }
#login .brand { margin-bottom: 4px; }

#toast { position: fixed; inset-inline-start: 16px; bottom: 16px; background: var(--ink); color: var(--bg); padding: 10px 14px;
         border-radius: var(--r-field); opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20; }
#toast.on { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

@media (max-width: 720px) {
  main { padding: 16px 16px 48px; }
  .sum dd { font-size: 17px; }
  dialog .two { grid-template-columns: 1fr; }
  /* the first row stays one row: its buttons tighten, the menu keeps the far end */
  #app > .bar:first-child { flex-wrap: nowrap; gap: 6px; }
  #app > .bar:first-child > .grow { flex: 1 0 0; min-width: 0; }
  #app > .bar:first-child > button:not(.icon) { padding: 7px 10px; white-space: nowrap; }
  /* the table becomes cards */
  table.lines thead { display: none; }
  table.lines tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 12px; border-bottom: 1px solid var(--hair); }
  table.lines td { padding: 0; border: 0; }
  table.lines td.c-day { grid-column: 1; color: var(--muted); font-size: 12px; }
  table.lines td.amt { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: 15px; }
  table.lines td.c-what { grid-column: 1; }
  table.lines td.c-kind, table.lines td.c-by { grid-column: 1; font-size: 12px; }
  table.lines td.row-actions { grid-column: 1 / -1; }
}
