/* QuickFA-Web — modern UI */
:root {
  --bg: #f1f4f9;
  --panel: #ffffff;
  --ink: #1a2233;
  --muted: #67718a;
  --line: #e3e8f0;
  --accent: #3b5bdb;
  --accent-2: #2b4acb;
  --accent-soft: #e7ecff;
  --green: #0c8a4d;
  --red: #ce2d4f;
  --amber: #b97509;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 60, .08), 0 8px 24px -12px rgba(20, 30, 60, .12);
  --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--ink);
}
#app { height: 100%; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; grid-template-rows: 52px 1fr; height: 100vh; }
.topbar {
  grid-column: 1 / 3; display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: linear-gradient(90deg, #1d2c5e, #2b4acb); color: #fff; box-shadow: var(--shadow); z-index: 5;
}
.topbar .brand { font-weight: 700; font-size: 16px; letter-spacing: .4px; display: flex; gap: 8px; align-items: center; }
.topbar .brand small { opacity: .7; font-weight: 400; }
.topbar .grow { flex: 1; }
.topbar select, .topbar .chip {
  background: rgba(255,255,255,.13); color: #fff; border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px; padding: 5px 10px; font-size: 13px;
}
.topbar select option { color: #1a2233; }
.topbar .chip { display: inline-flex; gap: 6px; align-items: center; }
.topbar button.link { background: none; border: none; color: #cfd8ff; cursor: pointer; font-size: 13px; }
.topbar button.link:hover { color: #fff; }

.sidebar {
  background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 10px 8px 30px;
}
.sidebar .group { margin-top: 10px; }
.sidebar .group > .gtitle {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted);
  padding: 6px 10px 4px; font-weight: 700;
}
.sidebar a {
  display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 8px;
  color: var(--ink); text-decoration: none; font-size: 13.5px; margin: 1px 0;
}
.sidebar a:hover { background: #f2f5fb; }
.sidebar a.active { background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }
.sidebar a .ico { width: 18px; text-align: center; opacity: .75; }

.main { overflow-y: auto; padding: 18px 22px 60px; }
.page-title { display: flex; align-items: center; gap: 12px; margin: 2px 0 14px; flex-wrap: wrap; }
.page-title h1 { font-size: 20px; margin: 0; font-weight: 650; }
.page-title .sub { color: var(--muted); font-size: 13px; }
.page-title .spacer { flex: 1; }

/* ---------- cards / panels ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-h { padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; align-items: center; gap: 10px; }
.card .card-b { padding: 14px 16px; }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: 1fr 1fr; }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid.c4 { grid-template-columns: 1fr 1fr; } .grid.c3 { grid-template-columns: 1fr; } }

.kpi { padding: 14px 16px; }
.kpi .lbl { color: var(--muted); font-size: 12.5px; }
.kpi .val { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .val.green { color: var(--green); } .kpi .val.red { color: var(--red); }

/* ---------- forms ---------- */
label.f { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid #cdd5e1; border-radius: 8px;
  font: inherit; background: #fff; color: var(--ink); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,91,219,.15); }
input[type=checkbox] { width: auto; }
input.num, td.num input { text-align: right; font-variant-numeric: tabular-nums; }
.frow { display: grid; gap: 10px; margin-bottom: 10px; }
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 14px; border-radius: 8px;
  border: 1px solid #cdd5e1; background: #fff; color: var(--ink); cursor: pointer; font: inherit; font-weight: 600;
}
.btn:hover { background: #f4f6fb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--red); border-color: #f3c2cd; }
.btn.danger:hover { background: #fdf0f3; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- tables ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.2px; }
.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); background: #fafbfe;
  position: sticky; top: 0;
}
.tbl td { padding: 7px 10px; border-bottom: 1px solid var(--line); }
.tbl tr:hover td { background: #f7f9fd; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr.total td { font-weight: 700; background: #f4f6fb; border-top: 2px solid var(--line); }
.tbl tr.clickable { cursor: pointer; }
.tbl .dr { color: var(--ink); } .tbl .cr { color: var(--red); }
.scroll { overflow: auto; max-height: calc(100vh - 240px); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 700; }
.badge.green { background: #e2f6ec; color: var(--green); }
.badge.red { background: #fdeaee; color: var(--red); }
.badge.blue { background: var(--accent-soft); color: var(--accent-2); }
.badge.gray { background: #eef1f6; color: var(--muted); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 9px; align-items: flex-end; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .fld { min-width: 130px; }
.toolbar .fld.w { min-width: 230px; }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex;
  align-items: flex-start; justify-content: center; padding: 4vh 16px; z-index: 50; overflow-y: auto;
}
.modal {
  background: var(--panel); border-radius: 14px; box-shadow: 0 24px 64px rgba(0,0,0,.25);
  width: 640px; max-width: 96vw; animation: pop .14s ease-out;
}
.modal.wide { width: 1080px; }
.modal .m-h { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 15.5px; display: flex; align-items: center; }
.modal .m-h .x { margin-left: auto; cursor: pointer; border: 0; background: none; font-size: 18px; color: var(--muted); }
.modal .m-b { padding: 16px 18px; }
.modal .m-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 9px; justify-content: flex-end; }
@keyframes pop { from { transform: scale(.97); opacity: .4; } }

/* ---------- toast ---------- */
#toast-root { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 99; }
.toast {
  background: #16213e; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 13.5px; animation: pop .15s;
}
.toast.err { background: #8e1f3a; }

/* ---------- autocomplete ---------- */
.ac { position: relative; }
.ac-list {
  position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); max-height: 260px; overflow-y: auto; z-index: 60;
}
.ac-list div { padding: 7px 10px; cursor: pointer; font-size: 13px; }
.ac-list div:hover, .ac-list div.sel { background: var(--accent-soft); }
.ac-list .meta { color: var(--muted); font-size: 11.5px; }

/* ---------- login ---------- */
.login-wrap { height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1000px 500px at 20% 0%, #2b4acb22, transparent), var(--bg); }
.login-card { width: 420px; }
.login-card .logo { text-align: center; font-size: 34px; }
.login-card h2 { text-align: center; margin: 4px 0 2px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 16px; }

/* ---------- voucher entry grid ---------- */
.vgrid td { padding: 4px 6px; }
.vgrid input, .vgrid select { padding: 5px 7px; border-radius: 6px; }
.vgrid td.rm { width: 30px; text-align: center; cursor: pointer; color: var(--red); }

.totbar { display: flex; gap: 26px; justify-content: flex-end; align-items: center; padding: 10px 6px; font-size: 14px; flex-wrap: wrap; }
.totbar > span { display: inline-flex; align-items: center; gap: 6px; }
.totbar b { font-variant-numeric: tabular-nums; }
.totbar .big { font-size: 17px; color: var(--accent-2); }
.totbar input { padding: 4px 7px; }

/* ---------- print ---------- */
.print-doc { background: #fff; padding: 26px 30px; max-width: 880px; margin: 0 auto; border: 1px solid var(--line); border-radius: 8px; }
.print-doc h2 { margin: 0; }
.print-doc table { width: 100%; border-collapse: collapse; font-size: 13px; }
.print-doc th, .print-doc td { border: 1px solid #9aa4b8; padding: 5px 8px; }
.print-doc .nohead td { border: none; padding: 2px 0; }
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; left: 0; top: 0; width: 100%; }
  .sidebar, .topbar, .toolbar, .no-print { display: none !important; }
  .main { padding: 0; overflow: visible; }
  .scroll { max-height: none; overflow: visible; }
  .card { box-shadow: none; border: none; }
  .tbl th { position: static; }
}
/* ---------- invoice replica (original QUICKFA bill format) ---------- */
.inv {
  background: #fff; color: #000; width: 720px; margin: 0 auto;   /* A4 printable width @96dpi */
  border: 1.6px solid #000; font: 13px/1.35 Arial, Helvetica, sans-serif;
}
/* auto-fit-to-one-page: JS adds .c1/.c2 to compress row spacing when many items */
.inv.c1 .inv-items td { padding-top: 1px; padding-bottom: 1px; font-size: 11.5px; }
.inv.c1 .inv-items .sm { font-size: 9.5px; line-height: 1.15; }
.inv.c2 .inv-items td { padding-top: 0; padding-bottom: 0; font-size: 10.5px; line-height: 1.12; }
.inv.c2 .inv-items .sm { font-size: 9px; line-height: 1.05; }
.inv.c2 .inv-items th { padding-top: 1px; padding-bottom: 1px; }
.inv-fill td { padding: 0 !important; }
.inv .c { text-align: center; }
.inv .rt { text-align: right; }
.inv .b { font-weight: 700; }
.inv .sm { font-size: 10.5px; }
.inv .r3 { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: start; }
.inv .r2 { display: flex; justify-content: space-between; gap: 8px; }
.inv-head { padding: 6px 10px 4px; }
.inv-name { text-align: center; font-size: 30px; font-weight: 800; font-style: italic; font-family: Arial, sans-serif; margin: 2px 0 6px; }
.inv-party { display: grid; grid-template-columns: 53% 47%; border-top: 1.4px solid #000; }
.inv-party .lft { padding: 5px 10px; border-right: 1.4px solid #000; }
.inv-party .lft > div, .inv-party .rgt > div { margin: 3px 0; }
.inv-party .rgt { padding: 5px 10px; }
.inv-party .rgt > div { border-bottom: 1px solid #000; padding-bottom: 4px; }
.inv-party .rgt > div:last-child { border-bottom: none; }
/* shift the right-side date fields (Dated / Dt) one inch left of the edge */
.inv-party .rgt .r2 > span:last-child { padding-right: 1in; }
.inv-party .strow { display: flex; gap: 0; align-items: center; }
.inv-party .strow span:first-child { flex: 1; }
.inv-party .stbox { border: 1px solid #000; padding: 1px 14px; font-weight: 700; text-align: center; }
.inv-party .stbox.w { min-width: 150px; }
.inv-items { width: 100%; border-collapse: collapse; border-top: 1.4px solid #000; }
.inv-items th {
  border: 1px solid #000; border-top: none; padding: 3px 4px; font-size: 11.5px; text-align: center; font-weight: 700;
}
.inv-items th .split { display: flex; justify-content: space-between; padding: 0 4px; font-size: 10.5px; }
.inv-items td { border-left: 1px solid #000; border-right: 1px solid #000; padding: 2px 5px; font-size: 12px; vertical-align: top; }
.inv-items tbody tr:first-child td { padding-top: 5px; }
.inv-items tfoot td { border: 1px solid #000; padding: 4px 5px; }
.inv-foot { display: grid; grid-template-columns: 60% 40%; border-top: 1.4px solid #000; }
.inv-foot .lft { border-right: 1.4px solid #000; }
.inv-foot .rc { padding: 4px 10px; border-bottom: 1px solid #000; }
.inv-foot .bank { padding: 5px 10px; line-height: 1.45; }
.inv-foot .sums { width: 100%; border-collapse: collapse; height: 100%; }
.inv-foot .sums td { padding: 4px 8px; border-bottom: 1px solid #000; }
.inv-foot .sums tr.gt td { border-bottom: none; border-top: 1.4px solid #000; font-size: 14px; }
.inv-words { border-top: 1.4px solid #000; padding: 5px 10px; }
.inv-sign { display: grid; grid-template-columns: 1fr auto; border-top: 1.4px solid #000; padding: 5px 10px 4px; }
.inv-sign .mt8 { margin-top: 8px; }
.inv-sign .eoe { margin-top: 14px; }
.inv-sign .rgt { text-align: right; display: flex; flex-direction: column; justify-content: space-between; }
.inv-sign .forco { font-size: 15px; }
.inv-sign .authsig { margin-top: 30px; font-size: 14px; }
.inv-mail { border-top: 1.4px solid #000; padding: 3px 10px 5px; }
.inv-page { margin: 0 auto 26px; }                 /* batch: gap between bills on screen */
@media print {
  .inv { width: 720px; border-width: 1.2px; }      /* keep fixed width so fit matches screen */
  @page { size: A4 portrait; margin: 8mm; }
  .inv-page { margin: 0; }
  .inv-page { break-after: page; page-break-after: always; }
  .inv-page:last-child { break-after: auto; page-break-after: auto; }
}

/* ---------- account statement (ledger print, FoxPro layout) ---------- */
.stmt { padding: 14px 18px 6px; color: #000; }
.stmt-co { text-align: center; line-height: 1.4; }
.stmt-co .co-name { font-size: 18px; font-weight: 700; }
.stmt-co .co-period { margin-top: 4px; }
.stmt-party { margin: 10px 0 6px; line-height: 1.4; }
.stmt-tbl { width: 100%; }
.stmt-tbl th { background: #f2f2f2; border-top: 1px solid #000; border-bottom: 1px solid #000; }
/* keep date / vch / amounts on one line (only Particulars may wrap) — matches FoxPro */
.stmt-tbl th, .stmt-tbl td { white-space: nowrap; }
.stmt-tbl th:nth-child(3), .stmt-tbl td:nth-child(3) { white-space: normal; }
.stmt-foot { text-align: center; font-weight: 700; margin-top: 22px;
  border-top: 1px solid #000; padding-top: 8px; }
@media print {
  .stmt-tbl th { background: #f2f2f2 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

.muted { color: var(--muted); }
.right { text-align: right; }
.mt { margin-top: 12px; }
.empty { text-align: center; color: var(--muted); padding: 36px 0; }
