html, body { margin: 0; min-height: 100%; background: #0f1115; color: #e8ecf1; font-family: system-ui, sans-serif; }
* { box-sizing: border-box; }
#app { max-width: 1100px; margin: 0 auto; padding: 20px; }
a { color: #7aa7ff; }
h1, h2, h3 { margin: 0; }
.top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.tabs { display: flex; gap: 4px; background: #181b22; padding: 4px; border-radius: 10px; flex-wrap: wrap; }
.tab { background: none; border: 0; color: #9aa4b2; padding: 8px 16px; border-radius: 8px; cursor: pointer; font: inherit; }
.tab.active { background: #2a3140; color: #fff; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 160px; }
.muted { color: #8b95a5; font-size: 14px; }
.pre { white-space: pre-line; }
.err { color: #ff7b7b; font-size: 14px; min-height: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat .big { font-size: 20px; font-weight: 700; margin-top: 4px; word-break: break-word; }
.big.good { color: #5fd88a; } .big.bad { color: #ff8585; }
.empty { text-align: center; padding: 36px 16px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.tablewrap { overflow-x: auto; }
.fx-table { width: 100%; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { white-space: nowrap; text-align: right; }
.actions .fx-btn { padding: 4px 8px; font-size: 13px; }
.st-paid { background: #1d4d33 !important; color: #8bf0b3 !important; }
.st-unpaid { background: #4d4220 !important; color: #f5d06f !important; }
.st-partial { background: #1f3f5a !important; color: #8cc8ff !important; }
.st-overdue { background: #5a2323 !important; color: #ff9a9a !important; }
.st-draft { background: #2c3340 !important; color: #b8c2d0 !important; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.field span { color: #9aa4b2; }
.field small { color: #6f7a8a; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.fx-input { width: 100%; }
input[type="checkbox"] { width: auto; }
.items { display: flex; flex-direction: column; gap: 8px; }
.irow { display: grid; grid-template-columns: 1fr 70px 100px 130px 110px 40px; gap: 8px; align-items: center; }
.ihead { color: #8b95a5; font-size: 13px; }
.totals { align-self: flex-end; width: min(340px, 100%); }
.tline { display: flex; justify-content: space-between; padding: 4px 0; }
.tline.bold { font-weight: 700; }
.tline.grand { border-top: 1px solid #333b4a; margin-top: 6px; padding-top: 8px; font-size: 20px; font-weight: 700; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { width: min(460px, 100%); max-height: 90vh; overflow: auto; }
.modal h2 { margin-bottom: 12px; }
.snack { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #222836; border: 1px solid #3a4457; padding: 8px 14px; border-radius: 10px; display: flex; align-items: center; gap: 12px; z-index: 60; }

.sheet { background: #fff; color: #1b1f27; padding: 40px; border-radius: 6px; max-width: 800px; width: 100%; margin: 0 auto; }
.sheet-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #1b1f27; padding-bottom: 16px; }
.sheet-head h1 { letter-spacing: 3px; margin-bottom: 8px; }
.sheet-head .right { text-align: right; }
.sheet .logo { display: block; max-height: 64px; max-width: 200px; margin-bottom: 10px; object-fit: contain; }
.sheet .big { font-size: 20px; font-weight: 700; }
.stamp { display: inline-block; border: 2px solid; padding: 1px 8px; margin: 6px 0; font-weight: 700; font-size: 13px; border-radius: 4px; }
.sheet .st-paid { background: none !important; color: #1a8f4a !important; }
.sheet .st-unpaid { background: none !important; color: #b07a00 !important; }
.sheet .st-partial { background: none !important; color: #1565c0 !important; }
.sheet .st-overdue { background: none !important; color: #c62828 !important; }
.sheet .st-draft { background: none !important; color: #666 !important; }
.billto { margin: 24px 0; display: flex; flex-direction: column; gap: 2px; }
.billto small, .sheet-pay small { color: #777; }
.sheet-pay { margin-top: 24px; }
.sheet-table { width: 100%; border-collapse: collapse; }
.sheet-table th { text-align: left; border-bottom: 1px solid #1b1f27; padding: 8px 4px; }
.sheet-table th.num { text-align: right; }
.sheet-table td { padding: 8px 4px; border-bottom: 1px solid #e3e6eb; }
.sheet .fx-btn { color: #333; }
.sheet-totals { margin: 20px 0 0 auto; width: min(320px, 100%); }
.sheet-totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.sheet-totals .grand { border-top: 2px solid #1b1f27; font-weight: 700; font-size: 18px; margin-top: 6px; padding-top: 8px; }
.sheet-notes { margin-top: 24px; color: #555; font-size: 14px; border-top: 1px solid #e3e6eb; padding-top: 12px; }

@media (max-width: 700px) {
  .hide-sm { display: none; }
  .irow { grid-template-columns: 1fr 1fr 1fr; }
  .irow > :first-child { grid-column: 1 / -1; }
  .ihead { display: none; }
  .sheet { padding: 20px; }
  .sheet-head { flex-direction: column; }
  .sheet-head .right { text-align: left; }
}

@page { margin: 14mm; }

@media print {
  html, body { background: #fff; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .no-print, .snack, .backdrop { display: none !important; }
  #app { padding: 0; max-width: none; }
  .sheet { box-shadow: none; padding: 0; max-width: none; border-radius: 0; }
  .sheet-table tr, .sheet-totals { break-inside: avoid; }
}
