/* =====================================================================
   App UI styles (the printable documents live in doc.css)
   ===================================================================== */
@font-face { font-family: 'Poppins'; font-weight: 400; font-style: normal; font-display: swap; src: url('../assets/fonts/Poppins-Regular.ttf') format('truetype'); }
@font-face { font-family: 'Poppins'; font-weight: 500; font-style: normal; font-display: swap; src: url('../assets/fonts/Poppins-Medium.ttf') format('truetype'); }
@font-face { font-family: 'Poppins'; font-weight: 700; font-style: normal; font-display: swap; src: url('../assets/fonts/Poppins-Bold.ttf') format('truetype'); }

:root {
  --ink: #141010;
  --ink-2: #4a4545;
  --mute: #8a8585;
  --line: #e5e2e2;
  --line-2: #d3cfcf;
  --bg: #f4f3f3;
  --card: #fff;
  --brand: #221717;
  --ok: #17803d;
  --ok-bg: #e4f5ea;
  --warn: #9a6100;
  --warn-bg: #fdf0d3;
  --bad: #b3261e;
  --bad-bg: #fce6e4;
  --info: #1b5fa8;
  --info-bg: #e3eefa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 16, 16, .06), 0 4px 14px rgba(20, 16, 16, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; font-size: 14px; line-height: 1.5; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.2px; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--mute); }
.sm { font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.side { width: 232px; flex: none; background: var(--brand); color: #fff; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.side .brand { padding: 4px 8px 18px; }
.side .brand img { width: 168px; filter: invert(1); display: block; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #d9d3d3; text-decoration: none; font-weight: 500; font-size: 13.5px; }
.side nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side nav a.on { background: #fff; color: var(--ink); }
.side nav svg { width: 18px; height: 18px; flex: none; }
.side .sep { height: 1px; background: rgba(255,255,255,.12); margin: 10px 8px; }
.side .foot { margin-top: auto; padding: 10px 8px 0; font-size: 12px; color: #b8b0b0; }
.side .foot button { background: none; border: 0; color: #fff; text-decoration: underline; cursor: pointer; padding: 0; font-size: 12px; }
.side .foot .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { flex: 1; min-width: 0; padding: 28px 32px 70px; max-width: 1280px; }
.side .demo-note { background: #fff4cc; color: #6b4e00; border-radius: 8px; padding: 8px 10px; font-size: 11.5px; line-height: 1.4; margin-bottom: 10px; }
.side .demo-note a { color: inherit; }
@media (max-width: 860px) { .side .demo-note { display: none; } }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 8px 10px; gap: 8px; overflow-x: auto; }
  .side .brand { padding: 0 8px 0 4px; }
  .side .brand img { width: 96px; }
  .side nav { flex-direction: row; }
  .side nav a { padding: 7px 10px; white-space: nowrap; }
  .side nav a span { display: none; }
  .side nav a.on span { display: inline; }
  .side .sep, .side .foot .who { display: none; }
  .side .foot { margin: 0 0 0 auto; padding: 0; }
  main { padding: 18px 14px 50px; }
}

/* ---------- page header ---------- */
.ph { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.ph .titles { flex: 1; min-width: 200px; }
.ph .crumb { font-size: 12.5px; color: var(--mute); }
.ph .crumb a { text-decoration: none; }
.ph .crumb a:hover { text-decoration: underline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-2); background: #fff; cursor: pointer; font-weight: 500; font-size: 13.5px; text-decoration: none; line-height: 1.3; white-space: nowrap; }
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #000; }
.btn.danger { color: var(--bad); border-color: #e8b9b5; }
.btn.danger:hover { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { border: 0; background: none; cursor: pointer; width: 30px; height: 30px; border-radius: 6px; font-size: 14px; color: var(--ink-2); }
.icon-btn:hover { background: rgba(0,0,0,.07); color: var(--ink); }

label.f { display: block; font-size: 12px; font-weight: 500; color: var(--ink-2); margin-bottom: 4px; }
.in, select.in, textarea.in { width: 100%; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; font-size: 14px; }
.in:focus { outline: 2px solid rgba(34, 23, 23, .18); border-color: var(--brand); }
textarea.in { resize: vertical; min-height: 38px; line-height: 1.45; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.field { margin-bottom: 12px; }
.hint { font-size: 11.5px; color: var(--mute); margin-top: 3px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.err { color: var(--bad); font-size: 13px; margin: 8px 0; }

/* ---------- cards & tables ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px 20px; }
.card h3 + * { margin-top: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
@media (max-width: 1000px) { .grid4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .grid4 { grid-template-columns: 1fr; } }
.stat { padding: 16px 18px; }
.stat .k { font-size: 12px; color: var(--mute); font-weight: 500; text-transform: uppercase; letter-spacing: .4px; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.5px; margin-top: 2px; }
.stat .s { font-size: 12px; color: var(--mute); }
.stat.bad .v { color: var(--bad); }

.tablewrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--mute); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.click:hover td { background: #faf9f9; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t .docno { font-weight: 600; }
table.t tfoot td { font-weight: 600; background: #faf9f9; }
.empty { padding: 44px 20px; text-align: center; color: var(--mute); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.toolbar .in { max-width: 280px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-2); background: #fff; padding: 4px 11px; border-radius: 99px; font-size: 12.5px; cursor: pointer; font-weight: 500; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.b-draft { background: #eceaea; color: #565050; }
.b-sent { background: var(--info-bg); color: var(--info); }
.b-accepted, .b-paid { background: var(--ok-bg); color: var(--ok); }
.b-declined, .b-void { background: #eceaea; color: #7a7373; text-decoration: line-through; }
.b-unpaid { background: var(--warn-bg); color: var(--warn); }
.b-partial { background: #e7f0fb; color: var(--info); }
.b-overdue, .b-partial-overdue { background: var(--bad-bg); color: var(--bad); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--brand); }
.login .card { width: 100%; max-width: 380px; padding: 30px 28px; }
.login img { width: 200px; display: block; margin: 0 auto 18px; }
.login h2 { text-align: center; margin-bottom: 18px; }
.login .btn { width: 100%; justify-content: center; padding: 10px; }
.login .tiny { text-align: center; margin-top: 14px; font-size: 12.5px; }

/* ---------- document view / preview ---------- */
.docgrid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 22px; align-items: start; }
@media (max-width: 1100px) { .docgrid { grid-template-columns: 1fr; } }
.previewbox { background: #d9d6d6; border-radius: var(--radius); padding: 18px; overflow: hidden; }
.previewbox .scaler { transform-origin: top left; width: 794px; }
.previewbox .sheet { margin-bottom: 14px; box-shadow: 0 2px 12px rgba(0,0,0,.18); }
.sidecard + .sidecard { margin-top: 14px; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 13px; }
.kv span:first-child { color: var(--mute); }
.paylist { list-style: none; margin: 0; padding: 0; }
.paylist li { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 13px; }
.paylist li:first-child { border-top: 0; }
.paylist .amt { font-weight: 600; }

/* ---------- editor ---------- */
.edgrid { display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 1200px) { .edgrid { grid-template-columns: 1fr; } .edgrid .previewcol { display: none; } }
.previewcol { position: sticky; top: 16px; }
.sect { padding: 18px 20px; margin-bottom: 16px; }
.sect > h3 { margin-bottom: 14px; }
.item { border: 1px solid var(--line-2); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: #fcfbfb; }
.item .top { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.item .top .in { font-weight: 600; text-transform: uppercase; }
.item .nums { display: grid; grid-template-columns: 1fr 90px 1fr; gap: 10px; margin-top: 8px; align-items: end; }
.item .lt { text-align: right; font-weight: 600; padding-bottom: 8px; font-variant-numeric: tabular-nums; }
.item.disc { background: #fffaf0; border-color: #ecd9a4; }
.addrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.addrow select { max-width: 260px; }
.totalbar { display: flex; justify-content: space-between; align-items: center; background: var(--brand); color: #fff; border-radius: 10px; padding: 12px 16px; margin-top: 14px; font-weight: 600; }
.totalbar b { font-size: 20px; }
.savebar { position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 70%, transparent); padding: 14px 0 6px; display: flex; gap: 10px; flex-wrap: wrap; z-index: 5; }

/* ---------- modal & toast ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(20, 16, 16, .5); display: grid; place-items: center; padding: 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal.wide { max-width: 720px; }
.modal.small { max-width: 400px; padding: 22px; }
.modal.small p { margin: 0 0 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.modal-body { padding: 14px 20px 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 13.5px; box-shadow: 0 6px 20px rgba(0,0,0,.25); transition: opacity .35s; max-width: 380px; }
.toast.err { background: var(--bad); }
.toast.out { opacity: 0; }
.spin { display: grid; place-items: center; padding: 60px; color: var(--mute); }

/* ---------- print: show only the document ---------- */
@media print {
  html, body { background: #fff !important; }
  .no-print, .side, #toasts, .modal-wrap, .ph { display: none !important; }
  .shell { display: block; }
  main { padding: 0 !important; max-width: none !important; }
  .docgrid { display: block; }
  .previewbox { background: none; padding: 0; border-radius: 0; overflow: visible; height: auto !important; }
  .previewbox .scaler { transform: none !important; width: auto; }
  .previewbox .sheet { margin: 0; box-shadow: none; }
}
