:root {
  --navy: #1f3864; --navy2: #2e4a7d; --bg: #f4f6fa; --card: #fff; --text: #1d2433; --muted: #667085;
  --line: #e3e7ee; --green: #1a7f37; --red: #c62828; --amber: #b26a00; --blue: #1d4ed8;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
header { background: var(--navy); color: #fff; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; }
.who { display: flex; align-items: center; gap: 8px; font-size: 13px; }
nav { background: var(--navy2); display: flex; overflow-x: auto; padding: 0 8px; }
nav a { color: #dbe4f5; text-decoration: none; padding: 10px 14px; white-space: nowrap; border-bottom: 3px solid transparent; }
nav a.active { color: #fff; border-bottom-color: #ffd54f; font-weight: 600; }
main { max-width: 1250px; margin: 0 auto; padding: 16px; }
h1 { font-size: 20px; margin: 4px 0 14px; }
h2 { font-size: 16px; margin: 22px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.loading { padding: 30px; text-align: center; color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.card .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card.hl { border-color: var(--navy); box-shadow: inset 4px 0 0 var(--navy); }
.card.warn { box-shadow: inset 4px 0 0 var(--amber); }
.card.alert { box-shadow: inset 4px 0 0 var(--red); }
.card a { color: inherit; text-decoration: none; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }

form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 12px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea { width: 100%; padding: 9px 10px; border: 1px solid #cfd6e2; border-radius: 8px; font: inherit; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d7f7; border-color: var(--blue); }
input[readonly] { background: #f1f3f7; }
.radio-group { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-group label { display: flex; align-items: center; gap: 6px; border: 1px solid #cfd6e2; border-radius: 8px; padding: 9px 12px;
  color: var(--text); font-weight: 500; font-size: 14px; margin: 0; cursor: pointer; background: #fff; }
.radio-group input { width: auto; }
.radio-group label:has(input:checked) { border-color: var(--navy); background: #eef3fc; font-weight: 700; }

.btn { background: var(--navy); color: #fff; border: 0; border-radius: 8px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-green { background: var(--green); } .btn-red { background: var(--red); } .btn-amber { background: var(--amber); }
.btn-ghost { background: transparent; border: 1px solid rgba(255,255,255,.5); }
.btn-light { background: #e9edf5; color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.filters > div { min-width: 130px; flex: 0 1 170px; }
.table-tools { display: flex; justify-content: space-between; align-items: center; margin: 8px 0; gap: 8px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; vertical-align: top; }
th { background: #f7f9fc; font-size: 12px; color: var(--muted); position: sticky; top: 0; }
td.num, th.num { text-align: right; }
tr.total td { font-weight: 700; background: #f7f9fc; }
tr.low td { background: #fff4e5; }
tr.voided td { color: #999; text-decoration: line-through; }
tr.voided td.keep { text-decoration: none; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 8px; }
.summary { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; margin: 6px 0; }
.summary b { font-size: 15px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: #e9edf5; color: #344054; }
.b-green { background: #dcfce7; color: #166534; } .b-red { background: #fee2e2; color: #991b1b; }
.b-amber { background: #fef3c7; color: #92400e; } .b-blue { background: #dbeafe; color: #1e40af; }
.b-grey { background: #eceff3; color: #475467; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { background: #e9edf5; border: 0; border-radius: 999px; padding: 7px 14px; font: inherit; cursor: pointer; }
.tabs button.active { background: var(--navy); color: #fff; }

.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 12px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; padding: 20px; }
.modal h3 { margin: 0 0 14px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.confirm-table td { white-space: normal; }
.confirm-table td:first-child { color: var(--muted); width: 40%; }
.big-total { font-size: 26px; font-weight: 800; color: var(--navy); }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 6px; }
.toast { background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: 90vw; }
.toast.error { background: var(--red); } .toast.ok { background: var(--green); }

.login { max-width: 380px; margin: 60px auto; }
.login h1 { text-align: center; }
details summary { cursor: pointer; color: var(--blue); }
pre.json { white-space: pre-wrap; font-size: 11px; max-width: 520px; background: #f7f9fc; padding: 6px; border-radius: 6px; }

@media (max-width: 600px) {
  main { padding: 12px; }
  .card .value { font-size: 19px; }
}
@media print {
  header, nav, .filters, .table-tools button, .pager, .actions, .no-print { display: none !important; }
  body { background: #fff; } .table-wrap { border: 0; } th { position: static; }
}

/* ---- v2: language, charts, reports ---- */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; background: #e9edf5; border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; font: inherit; cursor: pointer; color: var(--text); }
.seg button.active { background: var(--navy); color: #fff; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; margin: 12px 0 18px; }
.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.chart-title { font-weight: 700; font-size: 14px; }
.chart-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chart-wrap { position: relative; height: 260px; margin-top: 10px; }
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; border-bottom: 2px solid var(--navy); padding-bottom: 8px; margin: 6px 0 6px; }
.report-head h2 { margin: 2px 0; font-size: 20px; }
.report-co { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.err { color: var(--red); }
.tabs .count { background: var(--red); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 11px; margin-inline-start: 4px; }
.login-lang { display: flex; justify-content: flex-end; margin-bottom: 8px; }
th, td { text-align: start; }
td.num, th.num { text-align: end; }
[dir=rtl] body { font-family: "Segoe UI", Tahoma, Arial, sans-serif; }
[dir=rtl] .card .label { letter-spacing: 0; }
@media (max-width: 600px) { .chart-grid { grid-template-columns: 1fr; } .chart-wrap { height: 220px; } }
@media print { .chart-grid { grid-template-columns: 1fr 1fr; } .chart-card { break-inside: avoid; } .report-head { margin-top: 0; } }

/* ---- v3: merchant highlight, table footers ---- */
tr.merchant td { background: #eef5ff; }
tr.merchant.voided td { background: #f4f6fa; }
tfoot tr.total td { font-weight: 700; background: #f0f3f8; border-top: 2px solid #c9d2e0; }
.legend-merchant { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend-merchant::before { content: ""; width: 14px; height: 14px; border-radius: 3px; background: #eef5ff; border: 1px solid #b9cff3; }
@media print { tr.merchant td { background: #eef5ff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* ---- v5: grouped menu, day book, journal voucher ---- */
nav { overflow: visible; flex-wrap: wrap; position: relative; z-index: 20; }
.nav-group { position: relative; display: flex; }
.nav-top { background: none; border: 0; border-bottom: 3px solid transparent; color: #dbe4f5; font: inherit; padding: 10px 14px; cursor: pointer; white-space: nowrap; }
.nav-top:hover, nav a:hover { color: #fff; }
.nav-top .caret { font-size: 10px; opacity: .8; }
.nav-group.active > .nav-top { color: #fff; border-bottom-color: #ffd54f; font-weight: 600; }
.nav-menu { display: none; position: absolute; top: 100%; inset-inline-start: 0; min-width: 230px; background: #fff; border: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 10px 24px rgba(16, 24, 40, .16); padding: 6px 0; z-index: 30; }
.nav-group.open .nav-menu { display: block; }
.nav-menu a { display: block; color: var(--text); padding: 9px 16px; border: 0; white-space: nowrap; }
.nav-menu a:hover { background: #f1f4fa; color: var(--navy); }
.nav-menu a.active { background: #eef3fc; color: var(--navy); font-weight: 700; border: 0; }
@media (hover: hover) and (min-width: 700px) { .nav-group:hover .nav-menu { display: block; } }
@media (max-width: 699px) { .nav-menu { position: fixed; top: auto; left: 8px; right: 8px; min-width: 0; border-radius: var(--radius); } }
.jv-table td { vertical-align: middle; } .jv-table select { min-width: 220px; } .jv-table input { width: 130px; text-align: end; }
.jv-lines { margin: 6px 0 12px; } .jv-lines [data-jv=diff] { margin-top: 6px; font-weight: 600; }
.ok-text { color: var(--green); } .err-text { color: var(--red); }
.vh { border-top: 1px solid var(--line); padding: 8px 0; } .vh .small { margin-top: 3px; }
tr.edited td:first-child { border-inline-start: 3px solid var(--amber); }
input[dir=rtl] { text-align: right; }
td .actions { flex-wrap: nowrap; }
.wrap-cell { display: inline-block; white-space: normal; min-width: 160px; max-width: 320px; }
a.vref { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--muted); }

/* ---- v6: sorting, printing, read-only login, split payment, store checkboxes ---- */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--navy); }
th.sortable.asc::after { content: ' ▲'; font-size: 9px; } th.sortable.desc::after { content: ' ▼'; font-size: 9px; }
body.ro .ro-hide { display: none !important; }
.small-total { font-size: 20px; }
.store-checks { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.store-checks > div { flex-basis: 100%; }
label.chk { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; color: var(--text); font-size: 14px; margin: 0; cursor: pointer; }
label.chk input { width: auto; }
.store-pick { border-inline-start: 4px solid var(--amber); }
#printArea { display: none; }
.print-doc { font-size: 14px; color: #000; }
.print-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 12px; }
.print-head h2 { margin: 4px 0 0; font-size: 20px; } .print-co { font-weight: 800; font-size: 16px; }
.sign-row { display: flex; gap: 24px; margin-top: 60px; } .sign-row > div { flex: 1; border-top: 1px solid #000; padding-top: 6px; text-align: center; font-size: 12px; }
@media print {
  body.printing-doc > *:not(#printArea) { display: none !important; }
  body.printing-doc #printArea { display: block !important; padding: 0; }
  details:not([open]) > *:not(summary) { display: none; }
}

/* ---- v7: voucher colours, live stock, drafts, print options, table zoom ---- */
.vform { border-top-width: 6px; border-top-style: solid; }
.vbanner { margin: -6px 0 12px; font-size: 15px; display: flex; gap: 10px; align-items: center; }
.vbanner span { font-size: 11px; font-weight: 800; letter-spacing: .06em; padding: 2px 8px; border-radius: 999px; color: #fff; }
.v-in { border-top-color: var(--green); background: #f3fbf5; }   .v-in .vbanner { color: var(--green); }   .v-in .vbanner span { background: var(--green); }
.v-out { border-top-color: var(--red); background: #fdf4f4; }    .v-out .vbanner { color: var(--red); }    .v-out .vbanner span { background: var(--red); }
.v-move { border-top-color: var(--blue); background: #f3f7ff; }  .v-move .vbanner { color: var(--blue); }
.v-move2 { border-top-color: var(--amber); background: #fffaf0; } .v-move2 .vbanner { color: var(--amber); }
.v-jv { border-top-color: #667085; background: #f8f9fb; }
.modal form.vform { padding: 12px; border-radius: var(--radius); border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stock-live { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; background: #f7f9fc; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin: 4px 0 14px; }
.stock-live span.muted { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.stock-live b { font-size: 18px; } .stock-live .arrow { font-size: 20px; color: var(--muted); }
.stock-live .neg b { color: var(--red); }
.store-now { font-size: 15px; margin-bottom: 2px; }
.zoom-btns { display: inline-flex; gap: 2px; margin-inline-end: 6px; }
.table-wrap table { zoom: var(--tz, 1); }
.col-checks { margin-bottom: 8px; }
.print-line { font-size: 13px; margin-top: 2px; }
.print-body.wrap td, .print-body.wrap th { white-space: normal; }
.print-body .table-wrap { overflow: visible; border: 0; } .print-body .table-wrap table { zoom: 1; }
.print-body th, .print-body td { padding: 4px 6px; border: 1px solid #999; } .print-body th { background: #eee; color: #000; }
.print-body .summary { margin: 6px 0; display: flex; gap: 16px; flex-wrap: wrap; }
@media print {
  .zoom-btns { display: none !important; }
  main { max-width: none; padding: 0; }
  .table-wrap { overflow: visible !important; }
  thead { display: table-header-group; } tr { break-inside: avoid; }
}

/* v8: grouped tables (chart of accounts, trial balance, P&L, balance sheet), watch cards, journal lines */
table.gtable tr.grp td { font-weight: 700; background: #e9eef6; color: var(--navy); border-top: 2px solid #c9d2e0; }
table.gtable tr.grp1 td { background: #f3f6fb; font-weight: 600; padding-inline-start: 22px; border-top: 1px solid #dde3ec; }
table.gtable tr.grp2 td { background: #fafbfd; font-weight: 600; padding-inline-start: 36px; }
table.gtable tr.total.sub1 td, table.gtable tr.total.sub2 td { background: #fbfcfe; font-weight: 600; color: #47546b; }
table.gtable tr.total.sub0 td { background: #f0f3f8; }
table.gtable tr.total.grand td { background: var(--navy); color: #fff; font-size: 1.02em; }
table.gtable tr.total.grand.neg td { background: #a12b2b; }
table.gtable td a[data-led] { color: inherit; text-decoration: none; border-bottom: 1px dotted #8a96aa; }
.card.ok { box-shadow: inset 4px 0 0 #1f8a4c; }
.card.watch .label { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.card.watch a { color: inherit; text-decoration: none; display: block; }
.card .x { border: 0; background: none; color: #9aa4b5; cursor: pointer; font-size: 13px; padding: 0 2px; }
.card .x:hover { color: #c0392b; }
.jl { white-space: nowrap; }
.jl.cr { padding-inline-start: 22px; color: #47546b; }
@media print { table.gtable tr.total.grand td { background: #ddd !important; color: #000 !important; } .card .x { display: none; } }

/* v9: opening / closing balance rows of a ledger */
tr.total.ledger-bal td { background: #eef3fb; border-top: 1px solid #c9d2e0; border-bottom: 1px solid #c9d2e0; }

/* v11: both languages at once — Arabic line above the English line; amounts stay in one cell */
.bi { display: inline-flex; flex-direction: column; align-items: flex-start; line-height: 1.25; vertical-align: middle; gap: 1px; }
.bi-ar { direction: rtl; unicode-bidi: isolate; font-weight: inherit; }
.bi-en { font-size: .86em; opacity: .8; }
td.num .bi, th.num .bi { align-items: flex-end; }
th .bi-en { text-transform: none; }
body.lang-bi table td, body.lang-bi table th, .print-bi table td, .print-bi table th { padding-top: 7px; padding-bottom: 7px; }
/* short controls: one line "عربي / English" */
.btn .bi, .tabs .bi, .badge .bi, #nav .bi, .nav-top .bi, label.chk .bi, .toast .bi, .seg .bi { flex-direction: row; align-items: baseline; gap: .35em; }
.btn .bi-en::before, .tabs .bi-en::before, .badge .bi-en::before, #nav .bi-en::before, label.chk .bi-en::before, .seg .bi-en::before { content: '/ '; }
.btn .bi-en, .tabs .bi-en, .badge .bi-en, #nav .bi-en { font-size: inherit; }
.lang-bi-btn.active { background: #fff; color: var(--navy); }
.print-doc[dir=rtl] { text-align: right; }
.print-bi .bi-en { opacity: .9; }
.bi-ar bdi { margin: 0 .15em; }
.card .label .bi { gap: 2px; }
