:root {
  --bg: #eef1f4; --surface: #ffffff; --ink: #17232d; --muted: #5d6c78; --line: #d8dee4;
  --accent: #0f5c63; --accent-ink: #ffffff; --accent-soft: #dcecee;
  --good: #1d7a46; --good-soft: #def2e6; --bad: #b3372f; --bad-soft: #f8e1df; --warn-soft: #fbf0d3;
  --font-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --font-display: "Reem Kufi", "IBM Plex Sans Arabic", Tahoma, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #101a21; --surface: #18262f; --ink: #e6edf2; --muted: #9bacb8; --line: #2b3b46;
    --accent: #5fc0c8; --accent-ink: #08272b; --accent-soft: #19393e;
    --good: #5cc98a; --good-soft: #17382a; --bad: #f08a82; --bad-soft: #432523; --warn-soft: #3d3419;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 16px; line-height: 1.5; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 16px 48px; }
h1, h2, h3 { text-wrap: balance; margin: 0; }
h1 { font-family: var(--font-display); font-size: 28px; font-weight: 600; }
h2 { font-size: 18px; font-weight: 700; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.top { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tab { border: 0; background: transparent; border-radius: 8px; padding: 8px 14px; font-weight: 600; color: var(--muted); }
.tab[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.tab:not([aria-current="page"]):hover { background: var(--accent-soft); color: var(--ink); }

.bar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.month-nav { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px; }
.month-nav button { width: 40px; height: 40px; border: 0; border-radius: 8px; background: transparent; font-size: 20px; }
.month-nav button:hover { background: var(--accent-soft); }
.month-nav .label { min-width: 130px; text-align: center; font-weight: 700; font-size: 17px; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 14px; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.small { padding: 5px 12px; font-size: 14px; }
.btn.danger { color: var(--bad); }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; border-inline-start: 5px solid var(--accent); }
.tile .k { color: var(--muted); font-size: 14px; }
.tile .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .s { color: var(--muted); font-size: 13px; }
.tile.out { border-inline-start-color: var(--bad); }
.tile.pos { border-inline-start-color: var(--good); } .tile.pos .v { color: var(--good); }
.tile.neg { border-inline-start-color: var(--bad); } .tile.neg .v { color: var(--bad); }
.cur { font-size: 14px; font-weight: 500; color: var(--muted); margin-inline-start: 4px; }

.panels { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head .tot { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.panel.exp .panel-head .tot { color: var(--bad); }
.row { display: grid; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.row:last-child { border-bottom: 0; }
.row.pay { grid-template-columns: 76px 1fr 1fr 70px 78px; }
.row.ex { grid-template-columns: 1fr auto 78px; }
.row.cols { padding-block: 6px; background: var(--bg); color: var(--muted); font-size: 13px; }
.apt, .exlabel { font-weight: 600; }
.amt { font-weight: 500; }
.dt, .exnote { color: var(--muted); font-size: 14px; }
.exnote { grid-column: 1 / -1; margin-top: -4px; }
.pill { font-size: 12px; font-weight: 600; text-align: center; border-radius: 999px; padding: 3px 0; }
.pill.yes { background: var(--good-soft); color: var(--good); }
.pill.no { background: var(--bad-soft); color: var(--bad); }

.foot { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 12px; }

.box { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.controls label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
select, input[type="number"], input[type="date"], input[type="text"], textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
.scroll { overflow-x: auto; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

table.rep, table.log { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rep th, .rep td, .log th, .log td { border: 1px solid var(--line); padding: 6px 8px; text-align: start; font-size: 14px; vertical-align: top; }
.rep th, .log th { background: var(--bg); font-weight: 600; white-space: nowrap; }
.rep tfoot td, .rep tr.total td { font-weight: 700; background: var(--bg); }
.rep td.n { text-align: end; }
.kind { font-weight: 600; }
.kind.k-add { color: var(--good); } .kind.k-edit { color: var(--accent); } .kind.k-del { color: var(--bad); }
.rep-title { margin-bottom: 4px; }
.rep-sub { color: var(--muted); font-size: 14px; margin-bottom: 12px; }
.rep-block { margin-top: 18px; }
.rep-block h3 { margin-bottom: 6px; font-size: 16px; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 20px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 20, 28, .55); }
dialog h2 { margin-bottom: 12px; }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
dialog label input, dialog label textarea { color: var(--ink); font-size: 16px; }
dialog textarea { min-height: 72px; resize: vertical; }
.dlg-msg { font-size: 14px; color: var(--muted); }
.dlg-err { color: var(--bad); font-size: 14px; min-height: 1.2em; }
.dlg-btns { display: flex; gap: 8px; justify-content: flex-start; flex-wrap: wrap; }

#toast { position: fixed; inset-inline: 16px; bottom: 16px; margin-inline: auto; max-width: 420px; background: var(--ink); color: var(--bg); border-radius: 10px; padding: 10px 14px; text-align: center; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }

#print-area { display: none; }

@media (max-width: 760px) {
  .panels, .tiles { grid-template-columns: 1fr; }
  .row.pay { grid-template-columns: 62px 1fr 1fr 74px; padding-inline: 12px; gap: 6px; }
  .row.pay .pill { display: none; }
  h1 { font-size: 24px; }
  .tab { padding: 8px 10px; font-size: 14px; }
}

@media print {
  body { background: #fff; color: #000; font-size: 12px; }
  .wrap, dialog, #toast { display: none !important; }
  #print-area { display: block; }
  #print-area table { width: 100%; border-collapse: collapse; }
  #print-area th, #print-area td { border: 1px solid #444; padding: 3px 5px; font-size: 11px; color: #000; background: transparent; }
  #print-area th, #print-area tfoot td, #print-area tr.total td { background: #e8e8e8; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #print-area h2 { font-size: 18px; color: #000; }
  #print-area h3 { font-size: 14px; color: #000; }
  #print-area .rep-sub { color: #333; }
  #print-area .rep-block { break-inside: avoid; }
  #print-area tr { break-inside: avoid; }
}
