:root {
  --cream: #f7f2e9; --white: #fffdf9; --blush: #e2cac9; --mauve: #9b6c6a; --mauve-dk: #7a4f4d;
  --ink: #282828; --muted: #5e4f3c; --rule: #d9cdbb; --late: #8f1f1f; --late-bg: #fbe4e1;
  --today: #6d4a00; --today-bg: #fdefc7; --ok: #1f5b34; --ok-bg: #e0f0e4;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 12px; }
body { margin: 0; background: var(--cream); color: var(--ink); font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; overflow-wrap: anywhere; }
body:not(.plain) { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
main { max-width: 680px; margin: 0 auto; padding: 14px; }
h1, h2, h3 { line-height: 1.25; margin: 0.4em 0 0.5em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--mauve-dk); }
:focus-visible { outline: 3px solid #1b5fbf; outline-offset: 2px; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; background: #fff; padding: 10px; z-index: 50; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; background: var(--mauve-dk); color: #fff; }
.top a { color: #fff; font-weight: 700; text-decoration: none; }
.demo { margin: 0; padding: 6px 12px; background: var(--today-bg); color: var(--today); font-weight: 700; font-size: 0.85rem; text-align: center; }
.bottom { position: fixed; inset: auto 0 0 0; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--white); border-top: 1px solid var(--rule); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.bottom a { display: flex; align-items: center; justify-content: center; min-height: 60px; text-decoration: none; font-size: 0.85rem; color: var(--muted); text-align: center; }
.bottom a[aria-current] { color: var(--mauve-dk); font-weight: 700; box-shadow: inset 0 3px 0 var(--mauve-dk); }
.bottom a.add { background: var(--mauve-dk); color: #fff; font-weight: 700; }

.card { background: var(--white); border: 1px solid var(--rule); border-radius: 14px; padding: 14px; margin: 0 0 14px; }
.list, .plainlist, .timeline { list-style: none; margin: 0 0 14px; padding: 0; }
.list > li { margin-bottom: 10px; }
.plainlist > li { border-top: 1px solid var(--rule); padding: 12px 0; }
.timeline li { border-left: 3px solid var(--blush); padding: 0 0 12px 12px; }
.task.overdue { border: 2px solid var(--late); background: #fff6f5; }
.task.today { border-color: #c99b1f; }
.what { font-weight: 600; margin: 6px 0; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0; font-size: 0.92rem; color: var(--muted); }
.ref { font-size: 0.85rem; font-weight: 400; color: var(--muted); white-space: nowrap; }
.qty { font-size: 1.3rem; }
.count { display: inline-block; min-width: 28px; padding: 0 8px; border-radius: 14px; background: var(--blush); font-size: 0.95rem; text-align: center; }
.badge { display: inline-block; overflow-wrap: normal; padding: 2px 10px; border-radius: 20px; background: #eee6d8; color: var(--ink); font-size: 0.82rem; font-weight: 600; }
.badge.late, .badge.warn, .s-cancelled { background: var(--late-bg); color: var(--late); }
.badge.today, .p-partial { background: var(--today-bg); color: var(--today); }
.p-paid, .s-completed { background: var(--ok-bg); color: var(--ok); }
.badge.undated { background: #fff; border: 1px dashed var(--muted); color: var(--muted); }
.hint, .none, .fine { color: var(--muted); font-size: 0.92rem; }
.error, .warnbox, .flash, .pending { border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.error { background: var(--late-bg); color: var(--late); font-weight: 600; }
.warnbox, .pending { background: var(--today-bg); color: var(--today); }
.flash { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.ok { color: var(--ok); font-weight: 600; }
.empty { text-align: center; }

label { display: block; margin: 10px 0; font-weight: 600; font-size: 0.95rem; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; min-height: 48px; padding: 10px 12px; font: inherit; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid #a8977c; border-radius: 10px; }
textarea { line-height: 1.45; }
.check { display: flex; align-items: flex-start; gap: 10px; min-height: 44px; font-weight: 400; padding: 8px 0; }
.check input { width: 24px; height: 24px; min-height: 0; margin: 0; flex: none; accent-color: var(--mauve-dk); }
.pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0 12px; align-items: end; }
button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; margin: 4px 6px 4px 0; padding: 10px 18px; font: inherit; font-weight: 700; text-decoration: none; text-align: center; color: var(--mauve-dk); background: #fff; border: 2px solid var(--mauve-dk); border-radius: 12px; cursor: pointer; }
.primary { background: var(--mauve-dk); color: #fff; }
.big { display: flex; width: 100%; min-height: 60px; font-size: 1.15rem; margin: 0 0 12px; }
.danger { color: var(--late); border-color: var(--late); }
button.link { background: none; border: 0; padding: 8px 0; text-decoration: underline; }
.more { display: block; padding: 8px 0 0; font-size: 0.92rem; }
.js-only { display: none; } .js .js-only { display: inline-flex; }
.buttons { display: flex; flex-wrap: wrap; margin-bottom: 8px; }
.menu .button { width: 100%; }
details { margin: 8px 0; }
summary { min-height: 44px; display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 700; color: var(--mauve-dk); }
summary::before { content: "▸"; } details[open] > summary::before { content: "▾"; }
.cancel summary { color: var(--late); }
.search { display: flex; gap: 8px; margin-bottom: 12px; }
.search input { margin: 0; min-width: 0; } .search button { margin: 0; flex: none; white-space: nowrap; }
button, .button { white-space: normal; }
button:disabled { opacity: 0.6; cursor: wait; }
.summary { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs.wrap { flex-wrap: wrap; }
.tabs a { display: flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 22px; background: var(--white); border: 1px solid var(--rule); text-decoration: none; white-space: nowrap; font-size: 0.92rem; }
.tabs a[aria-current] { background: var(--mauve-dk); color: #fff; border-color: var(--mauve-dk); }
.item { border: 1px solid var(--rule); border-radius: 12px; margin: 0 0 12px; padding: 4px 12px 8px; min-width: 0; }
.item legend { font-weight: 700; padding: 0 6px; }
.savebar { position: sticky; bottom: calc(61px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 14px; padding: 8px 0; background: var(--cream); border-top: 1px solid var(--rule); z-index: 10; }
.savebar button { flex: 1; }
.totals { background: var(--cream); border-radius: 10px; padding: 4px 12px; }
.totals p { margin: 6px 0; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 0; vertical-align: top; border-bottom: 1px solid var(--rule); text-align: left; }
td:last-child { text-align: right; padding-left: 8px; white-space: nowrap; overflow-wrap: normal; }
.lines td, .lines th { overflow-wrap: normal; } .lines td:first-child { overflow-wrap: anywhere; }
.amounts th { font-weight: 400; } .amounts small { display: block; color: var(--muted); }
.amounts .total th, .amounts .total td, .lines .total th, .lines .total td { font-weight: 800; font-size: 1.08rem; }
dl { display: grid; grid-template-columns: minmax(90px, max-content) 1fr; gap: 4px 12px; margin: 0; }
dt { color: var(--muted); } dd { margin: 0; white-space: pre-line; }
.diff { display: block; } .diff dt { margin-top: 8px; font-weight: 700; } del { color: var(--late); } ins { color: var(--ok); text-decoration: none; font-weight: 600; }
.voided { opacity: 0.65; }
.next { border: 2px solid var(--mauve-dk); }
pre, .pre { white-space: pre-wrap; font: inherit; }
pre { background: var(--cream); padding: 10px; border-radius: 8px; font-size: 0.92rem; }
.login { max-width: 360px; margin: 0 auto; text-align: center; }
.login img { margin: 0 auto; max-width: 70%; height: auto; }
.login form { text-align: left; } .login button { width: 100%; }

.paper { background: #fff; border: 1px solid var(--rule); border-radius: 8px; padding: 18px; font-size: 0.95rem; }
.paper header { display: flex; align-items: center; gap: 12px; }
.paper header img { width: 104px; height: auto; }
.paper h1 { font-size: 1.2rem; margin: 0; } .biz { margin: 0; color: var(--mauve-dk); font-weight: 700; }
.paper dl { margin: 12px 0; }
.lines th:not(:first-child), .lines td:not(:first-child) { text-align: right; padding-left: 8px; }
.lines tfoot th { text-align: left !important; padding-left: 0 !important; font-weight: 400; }
.stamp { margin: 0 0 12px; border: 3px dashed var(--late); color: var(--late); padding: 8px; text-align: center; font-weight: 800; }
.lunas { display: inline-block; border: 4px solid var(--ok); color: var(--ok); padding: 4px 24px; font-size: 1.8rem; font-weight: 900; letter-spacing: 0.1em; border-radius: 8px; }

@media print {
  @page { margin: 12mm; }
  body, body:not(.plain) { background: #fff; padding: 0; font-size: 11pt; }
  .no-print, .skip { display: none !important; }
  main { max-width: none; padding: 0; }
  .paper { border: 0; padding: 0; }
  tr { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
