/* Cashbook v2 — mobile-first app shell. Minimal, functional. */
:root {
  --ink: #1b1f23; --muted: #6b7178; --line: #e3e5e8; --bg: #f3f4f6; --card: #fff;
  --accent: #1f5f8b; --accent-ink: #fff; --in: #0a7a3d; --out: #b42318; --warn: #9a6700;
  --in-bg: #ecf8f0; --out-bg: #fdeceb; --warn-bg: #fff7e0;
  --radius: 14px; --tab-h: 64px; --bar-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body { font-family: system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Naskh Arabic", Arial, sans-serif;
  font-size: 16px; line-height: 1.5; color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }

/* ---------- app bar ---------- */
.appbar { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line);
  height: calc(var(--bar-h) + var(--safe-t)); padding: var(--safe-t) 8px 0; display: flex; align-items: center; gap: 6px; }
.appbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .sub { font-size: 12px; color: var(--muted); font-weight: 400; display: block; line-height: 1.2; }
.iconbtn { width: 42px; height: 42px; border: 0; background: none; border-radius: 50%; display: grid; place-items: center;
  color: var(--ink); cursor: pointer; padding: 0; }
.iconbtn:active { background: var(--bg); }
.iconbtn svg { width: 24px; height: 24px; }

main { max-width: 760px; margin: 0 auto; padding: 14px 14px calc(var(--tab-h) + var(--safe-b) + 24px); }
main.wide { max-width: 1200px; }
h2 { font-size: 15px; color: var(--muted); font-weight: 600; margin: 20px 4px 8px; }

/* ---------- bottom tabs ---------- */
.tabs { position: fixed; inset-inline: 0; bottom: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line);
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b); display: flex; justify-content: space-around; }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11.5px; position: relative; max-width: 120px; }
.tabs a svg { width: 24px; height: 24px; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs a.plus span.circle { width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; margin-top: -18px; box-shadow: 0 4px 12px rgba(31,95,139,.35); }
.tabs a.plus svg { width: 28px; height: 28px; }
.dot { position: absolute; top: 6px; inset-inline-start: calc(50% + 6px); min-width: 18px; height: 18px; border-radius: 9px;
  background: var(--out); color: #fff; font-size: 11px; line-height: 18px; text-align: center; padding: 0 5px; font-weight: 700; }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; border: 1px solid var(--line); }
.card.tight { padding: 0; overflow: hidden; }
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: var(--ink); min-height: 56px; }
a.row:active { background: var(--bg); }
.row .main { flex: 1; min-width: 0; }
.row .t, .row .s { display: block; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; white-space: nowrap; }
.row .chev { color: var(--muted); }
.ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; font-weight: 700; }
.ic.in { background: var(--in-bg); color: var(--in); } .ic.out { background: var(--out-bg); color: var(--out); }
.ic.warn { background: var(--warn-bg); color: var(--warn); } .ic.n { background: var(--bg); color: var(--muted); }
.ic svg { width: 20px; height: 20px; }

.in { color: var(--in); } .out { color: var(--out); } .warn { color: var(--warn); } .muted { color: var(--muted); font-size: 13px; }
.kpi { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; text-align: start; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpis .card { margin: 0; }
.kpis .lbl { font-size: 12.5px; color: var(--muted); }
.kpis .val { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; text-align: start; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- status pills ---------- */
.pill { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--in-bg); color: var(--in); } .pill.bad { background: var(--out-bg); color: var(--out); }
.pill.wait { background: var(--warn-bg); color: var(--warn); }
.s-approved { background: var(--in-bg); color: var(--in); } .s-submitted { background: var(--warn-bg); color: var(--warn); }
.s-returned, .s-removed { background: var(--out-bg); color: var(--out); } .s-voided { text-decoration: line-through; }

/* ---------- forms ---------- */
label, .lbl { display: block; font-size: 13px; color: var(--muted); margin: 0 2px 5px; }
.field { margin-bottom: 14px; }
input, select, textarea { font: inherit; font-size: 16px; width: 100%; padding: 12px; border: 1px solid #c9cdd2; border-radius: 12px;
  background: #fff; color: var(--ink); min-height: 48px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
.amount-input { font-size: 34px; font-weight: 800; text-align: center; direction: ltr; padding: 14px; min-height: 72px; letter-spacing: .5px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--ink); margin: 6px 2px 14px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.seg input { display: none; }
.seg label { margin: 0; text-align: center; padding: 11px 6px; border-radius: 9px; font-size: 15px; font-weight: 700; color: var(--muted); cursor: pointer; }
.seg input:checked + label.in { background: var(--in); color: #fff; }
.seg input:checked + label.out { background: var(--out); color: #fff; }

.chips { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 14px; }
.chips input { display: none; }
.chips label { margin: 0; padding: 12px 10px; min-height: 52px; border: 1px solid var(--line); background: #fff; border-radius: 12px;
  color: var(--ink); font-size: 14.5px; display: flex; align-items: center; cursor: pointer; line-height: 1.3; }
.chips input:checked + label { border-color: var(--accent); background: #eaf2f8; color: var(--accent); font-weight: 700; box-shadow: inset 0 0 0 1px var(--accent); }

button, .btn { font: inherit; font-size: 16px; font-weight: 700; padding: 12px 16px; min-height: 48px; border-radius: 12px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn-block { width: 100%; }
button.sec, .btn.sec { background: #fff; color: var(--accent); }
button.danger, .btn.danger { background: var(--out); border-color: var(--out); color: #fff; }
button.ok, .btn.ok { background: var(--in); border-color: var(--in); color: #fff; }
button.ghost { background: none; border-color: var(--line); color: var(--ink); }
button.small, .btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.actions.row2 { flex-direction: row; } .actions.row2 > * { flex: 1; }
.sticky-submit { position: sticky; bottom: calc(var(--tab-h) + var(--safe-b) + 8px); z-index: 5; }

details.more { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
details.more > summary { list-style: none; padding: 14px; font-weight: 600; cursor: pointer; display: flex; justify-content: space-between; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after { content: "▾"; color: var(--muted); }
details.more[open] > summary::after { content: "▴"; }
details.more > .body { padding: 0 14px 14px; }

/* ---------- toasts ---------- */
.toasts { position: sticky; top: calc(var(--bar-h) + var(--safe-t)); z-index: 15; padding: 8px 14px 0; max-width: 760px; margin: 0 auto; }
.flash { padding: 12px 14px; border-radius: 12px; margin-bottom: 8px; font-size: 14.5px; border: 1px solid; }
.flash.ok { background: var(--in-bg); border-color: #9fd8b3; color: #064e27; }
.flash.err { background: var(--out-bg); border-color: #f2b2ac; color: #7a1610; }
.flash.warn { background: var(--warn-bg); border-color: #f0d07a; color: #5c3d00; }

/* ---------- key/value ---------- */
dl.kv { margin: 0; }
dl.kv > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
dl.kv > div:last-child { border-bottom: 0; }
dl.kv dt { color: var(--muted); font-size: 14px; } dl.kv dd { margin: 0; text-align: end; font-weight: 600; }

/* ---------- tables (reports, admin) ---------- */
.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border-bottom: 1px solid var(--line); padding: 9px 10px; text-align: start; vertical-align: top; white-space: nowrap; }
th { background: #f7f8f9; font-weight: 600; font-size: 12.5px; color: var(--muted); }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; direction: ltr; }
td.wrap { white-space: normal; min-width: 180px; }
tr.total td { font-weight: 700; background: #f7f8f9; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filters .full { grid-column: 1 / -1; }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.login { max-width: 400px; margin: 0 auto; padding: 12vh 18px 24px; }
.login .logo { width: 64px; height: 64px; border-radius: 18px; margin-bottom: 10px; }

.sev-high { border-inline-start: 4px solid var(--out); } .sev-med { border-inline-start: 4px solid #e0a100; } .sev-low { border-inline-start: 4px solid #a0a6ad; }
pre.msg { white-space: pre-wrap; font-family: inherit; font-size: 14px; background: #f7f8f9; padding: 12px; border-radius: 12px; margin: 0; }

@media (min-width: 700px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .chips { grid-template-columns: repeat(3, 1fr); }
  .filters { grid-template-columns: repeat(4, 1fr); }
}
@media print {
  .appbar, .tabs, .toasts, .noprint { display: none !important; }
  body { background: #fff; } main { padding: 0; max-width: none; }
  .tablewrap { border: 0; overflow: visible; }
}
details > summary.row { list-style: none; cursor: pointer; }
details > summary.row::-webkit-details-marker { display: none; }
details[open] > summary.row { background: #f7f8f9; }
/* v2 fixes */
.btn svg, button svg, summary svg, .flash svg { width: 20px; height: 20px; flex: none; vertical-align: -4px; }
.amt, .kpi, .val, td.num, dd { unicode-bidi: isolate; }
.amt, .kpi, .val, td.num { direction: ltr; }
.sticky-submit { background: var(--bg); padding: 10px 0 4px; box-shadow: 0 -8px 12px -8px rgba(0,0,0,.08); }
