:root {
  --bg: #f4f6f8; --panel: #ffffff; --ink: #1d2733; --muted: #66727f; --line: #e2e7ec; --line2: #eef1f4;
  --brand: #0b7a65; --brand-ink: #ffffff; --brand-soft: #e3f3ef; --side: #10283a; --side-ink: #c9d6e0; --side-active: #1b3d55;
  --ok: #157a3c; --ok-soft: #e4f4ea; --bad: #c0262d; --bad-soft: #fbe9ea; --warn: #9a6200; --warn-soft: #fdf2dc; --info: #1f5fae; --info-soft: #e6eefa;
  --radius: 8px; --shadow: 0 1px 2px rgba(16, 40, 58, .06), 0 1px 6px rgba(16, 40, 58, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; display: flex; min-height: 100vh; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
h2 { font-size: 18px; margin: 0; font-weight: 600; }
h3 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.neg { color: var(--bad); }
.pos { color: var(--ok); }

/* sidebar */
#sidebar { width: 228px; background: var(--side); color: var(--side-ink); flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 14px; }
.logo { width: 36px; height: 36px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 20px; font-weight: 700; }
.brand-name { color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-sub { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; opacity: .7; }
#sidebar nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; flex: 1; }
#sidebar nav a { color: var(--side-ink); display: flex; gap: 11px; align-items: center; padding: 8px 10px; border-radius: 6px; font-size: 14px; }
#sidebar nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
#sidebar nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 #3fd1ad; }
.side-foot { font-size: 11px; padding: 14px 18px; opacity: .75; border-top: 1px solid rgba(255, 255, 255, .08); }
.side-foot a { color: #7fe3c9; }

/* top bar */
#wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 14px; background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 24px; position: sticky; top: 0; z-index: 20; }
.search { flex: 1; max-width: 520px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 20px; background: var(--bg); font: inherit; }
.company-name { margin-left: auto; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-toggle { display: none; }
#main { padding: 22px 28px 60px; }
.page { max-width: 1320px; margin: 0 auto; }
.muted-side { opacity: .7; }
.warn-side { color: #ffcf7a; }
.att-block { margin-top: 18px; border-top: 1px solid var(--line2); padding-top: 4px; }
.att-block .section-title { margin-top: 12px; }
label.btn input[type=file] { display: none; }
.user-wrap .menu { left: auto; right: 0; min-width: 240px; }
.user-btn { font-weight: 600; }
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line2); margin-bottom: 4px; font-weight: 600; }
/* viewer accounts: hide everything that changes data */
body.readonly .form-bar > div:last-child, body.readonly .form-bar .menu-wrap, body.readonly .line-actions, body.readonly .att-block label.btn,
body.readonly [data-act="add"], body.readonly [data-act="edit"], body.readonly [data-act="del"], body.readonly [data-act="delAtt"], body.readonly [data-act="unlinkAtt"],
body.readonly [data-act="delLine"], body.readonly label.btn.primary, body.readonly .page-head .actions a.btn[href^="#/txn/new"], body.readonly td.act a[href^="#/txn/new"],
body.readonly [data-act="newAccount"], body.readonly [data-act="start"], body.readonly [data-act="finish"], body.readonly [data-act="undo"] { display: none !important; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* menus */
.menu-wrap { position: relative; display: inline-block; }
.menu { display: none; position: absolute; top: calc(100% + 6px); left: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(16, 40, 58, .16); z-index: 50; min-width: 200px; padding: 6px; }
.menu.open { display: block; }
.menu a { display: block; padding: 7px 10px; border-radius: 5px; color: var(--ink); cursor: pointer; white-space: nowrap; }
.menu a:hover { background: var(--brand-soft); text-decoration: none; }
.new-menu.open { display: flex; gap: 8px; padding: 14px; }
.menu-col h4 { margin: 0 0 6px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.menu-wrap.up .menu { top: auto; bottom: calc(100% + 6px); }
.danger-text { color: var(--bad) !important; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid #c8d0d8; background: var(--panel); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f2f5f7; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #096a58; }
.btn.danger { color: var(--bad); border-color: #e6b3b6; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 18px; padding: 4px 8px; border-radius: 5px; color: var(--muted); }
.icon-btn:hover { background: var(--line2); }
input, select, textarea { font: inherit; color: var(--ink); padding: 7px 9px; border: 1px solid #c8d0d8; border-radius: 6px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(11, 122, 101, .35); border-color: var(--brand); }
input:disabled, select:disabled, textarea:disabled { background: #f3f5f7; color: #555; }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; }
.fld { display: flex; flex-direction: column; gap: 4px; }
.fld > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.fld.span2 { grid-column: span 2; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px 16px; }
.actions-row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* cards & layout */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card.narrow { max-width: 560px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); color: var(--ink); display: block; }
a.kpi:hover { text-decoration: none; border-color: var(--brand); }
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.kpi-val { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-val.neg { color: var(--bad); }
.big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-line { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line2); }
.stat-line b { font-variant-numeric: tabular-nums; }
.stat-line.bad b { color: var(--bad); }
.stat-line.ok b { color: var(--ok); }
.card-links { display: flex; gap: 16px; margin-top: 12px; flex-wrap: wrap; font-weight: 600; }
.setup ol { margin: 0; padding-left: 20px; line-height: 2; }
.section-title { margin: 22px 0 10px; font-size: 16px; }
.list-link { display: block; padding: 7px 0; border-bottom: 1px solid var(--line2); }
.report-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; align-items: start; }
.bank-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.bank-card.inactive { opacity: .6; }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.summary-bar { display: flex; gap: 24px; flex-wrap: wrap; padding: 10px 2px; color: var(--muted); }
.summary-bar b { color: var(--ink); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.data-actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-top: 16px; }
.danger-zone { border-color: #eec4c6; }

/* filters */
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; font-weight: 600; color: var(--muted); }
.filters input, .filters select { width: auto; min-width: 140px; }
.filters.inline { margin: 0; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .table-wrap, .report-card .table-wrap { border: 0; box-shadow: none; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line2); vertical-align: top; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl.compact td { padding: 7px 4px; }
.tbl.hover tbody tr[data-go], tr.clickable { cursor: pointer; }
.tbl.hover tbody tr[data-go]:hover, tr.clickable:hover { background: #f3faf8; }
.tbl td.act { white-space: nowrap; text-align: right; }
.tbl td.memo { max-width: 280px; color: var(--muted); }
.tbl td.empty { text-align: center; color: var(--muted); padding: 28px; }
.tbl tfoot th { background: #fafbfc; }
.link { font-weight: 600; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: var(--line2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }

/* reports */
.report-card { padding: 22px 24px; }
.report-title { text-align: center; margin-bottom: 16px; }
.report-title .co { font-weight: 600; color: var(--muted); }
.report-title h2 { font-size: 20px; margin: 2px 0; }
.tbl.report td { padding: 6px 10px; }
.tbl.report tr.sec td { font-weight: 700; padding-top: 14px; border-bottom: 0; }
.tbl.report tr.sec2 td { font-weight: 600; border-bottom: 0; }
.tbl.report tr.sub td { font-weight: 600; border-top: 1px solid var(--line); }
.tbl.report tr.tot td { font-weight: 700; border-top: 1px solid #c8d0d8; background: #fafbfc; }
.tbl.report tr.grand td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 3px double var(--ink); }
.lvl1 { padding-left: 26px !important; }
.lvl2 { padding-left: 44px !important; }

/* alerts */
.alert { padding: 11px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }
.alert.bad { background: var(--bad-soft); border-color: #f0c4c6; color: #8c1c21; }
.alert.ok { background: var(--ok-soft); border-color: #bfe2cc; color: var(--ok); }
.alert.warn { background: var(--warn-soft); border-color: #f1d9a6; color: #6e4700; }
.alert.info { background: var(--info-soft); border-color: #c6d8f2; color: #1b4a85; }

/* transaction forms */
.form-page .page-head { align-items: center; }
.big-total { text-align: right; }
.big-total span { display: block; font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 600; letter-spacing: .5px; }
.big-total b { font-size: 28px; font-variant-numeric: tabular-nums; }
.form-card { padding: 20px; }
.form-grid.hdr { margin-bottom: 18px; }
.party-info > div { font-size: 13px; }
.lines-wrap { border: 1px solid var(--line); box-shadow: none; }
.tbl.lines { min-width: 880px; }
.tbl.lines td { padding: 5px 6px; vertical-align: middle; }
.tbl.lines td.ln { color: var(--muted); width: 32px; text-align: center; }
.tbl.lines textarea { min-height: 34px; padding: 6px 8px; }
.tbl.lines input.num { text-align: right; }
.w-item { min-width: 200px; width: 22%; }
.w-qty { width: 80px; }
.w-rate { width: 110px; }
.w-amt { width: 130px; }
.w-tax { width: 140px; }
.line-actions { display: flex; gap: 8px; margin: 10px 0 4px; }
.form-bottom { display: grid; grid-template-columns: 1fr 360px; gap: 24px; margin-top: 18px; }
.notes { display: flex; flex-direction: column; gap: 12px; }
.totals > div { display: flex; justify-content: space-between; padding: 6px 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 1px solid var(--line); font-size: 16px; font-weight: 700; padding-top: 10px; }
.totals .neg b { color: var(--bad); }
.totals .pos b { color: var(--ok); }
.form-bar { position: sticky; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--side); padding: 10px 16px; border-radius: var(--radius); margin-top: 16px; z-index: 10; flex-wrap: wrap; }
.form-bar > div { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form-bar .btn.ghost { color: #fff; }
.form-bar .btn.ghost:hover { background: rgba(255, 255, 255, .1); }

/* reconcile */
.rec-sum { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.rec-sum > div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.rec-sum span { display: block; font-size: 12px; color: var(--muted); }
.rec-sum b { font-size: 18px; font-variant-numeric: tabular-nums; }
.rec-sum .neg b { color: var(--bad); }
.rec-sum .pos b { color: var(--ok); }

/* modal */
.modal { display: none; position: fixed; inset: 0; background: rgba(16, 40, 58, .45); z-index: 100; padding: 40px 16px; overflow-y: auto; }
.modal.open { display: block; }
.modal-box { background: var(--panel); max-width: 560px; margin: 0 auto; border-radius: 10px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal-box.wide { max-width: 820px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px 20px; }
.modal-errors .alert { margin: 14px 20px 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.modal-foot .danger { margin-right: auto; order: -1; }

/* toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--side); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 200; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); transition: opacity .4s; }
.toast.bad { background: var(--bad); }
.toast.out { opacity: 0; }

/* printable documents */
.print-bar { display: flex; gap: 10px; align-items: flex-end; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.doc { background: #fff; max-width: 860px; margin: 0 auto; padding: 44px 48px; border: 1px solid var(--line); box-shadow: var(--shadow); position: relative; color: #111; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; border-bottom: 3px solid var(--brand); padding-bottom: 18px; }
.doc-co { font-size: 20px; font-weight: 700; color: var(--brand); }
.doc-title { text-align: right; }
.doc-title h2 { font-size: 26px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
.doc-title table { margin-left: auto; }
.doc-title td { padding: 1px 0 1px 14px; }
.doc-title td:first-child { color: #666; }
.doc-to { margin: 20px 0; }
.doc-lines { width: 100%; border-collapse: collapse; margin-top: 10px; }
.doc-lines th { background: var(--brand); color: #fff; text-align: left; padding: 8px; font-size: 12px; }
.doc-lines td { padding: 8px; border-bottom: 1px solid #e5e5e5; vertical-align: top; }
.doc-lines .num { text-align: right; white-space: nowrap; }
.doc-lines.aging { margin-top: 24px; }
.doc-foot { display: flex; justify-content: space-between; gap: 30px; margin-top: 20px; }
.doc-notes { flex: 1; color: #444; }
.doc-totals { min-width: 300px; border-collapse: collapse; }
.doc-totals td { padding: 5px 8px; }
.doc-totals .num { text-align: right; }
.doc-totals .grand td { font-weight: 700; border-top: 2px solid #111; }
.void-stamp { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-20deg); font-size: 110px; font-weight: 800; color: rgba(192, 38, 45, .18); pointer-events: none; }

/* responsive */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .rec-sum { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  #sidebar { position: fixed; left: -240px; z-index: 60; transition: left .2s; }
  body.nav-open #sidebar { left: 0; }
  .nav-toggle { display: inline-block; }
  #topbar { padding: 10px 16px; }
  #main { padding: 16px; }
  .grid2, .grid3, .kpis { grid-template-columns: 1fr; }
  .form-bottom { grid-template-columns: 1fr; }
  .company-name { display: none; }
  .fld.span2 { grid-column: auto; }
  .new-menu.open { flex-direction: column; max-height: 70vh; overflow-y: auto; }
  .doc { padding: 20px; }
  .doc-head, .doc-foot { flex-direction: column; }
}

@media print {
  body { background: #fff; display: block; }
  .no-print, #sidebar, #topbar, .form-bar, .page-head .actions, .print-bar, .filters { display: none !important; }
  #main { padding: 0; }
  .doc { border: 0; box-shadow: none; padding: 0; max-width: none; }
  .card, .table-wrap { box-shadow: none; border: 0; }
  .doc-lines th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: inherit; }
}
