/* Advocate PMS: plain, mobile-first. No sideways scroll at 360 px. */
:root {
  --ink: #1d232b;
  --muted: #5d6773;
  --line: #d5dae0;
  --bg: #f4f6f8;
  --card: #ffffff;
  --accent: #1f4e79;
  --danger: #a61b1b;
  --ok: #1d6b3a;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-wrap: anywhere;
}
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: .5rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
code { font-size: .9em; }

.topbar {
  display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between;
  padding: .6rem 16px; background: var(--accent); color: #fff;
}
.topbar a, .topbar .link { color: #fff; }
.brand { font-weight: 700; text-decoration: none; }
.topbar nav { display: flex; flex-wrap: wrap; gap: .25rem 1rem; align-items: center; }
.inline { display: inline; margin: 0; }
.link { background: none; border: 0; padding: 0; font: inherit; text-decoration: underline; cursor: pointer; }

.wrap { max-width: 860px; margin: 0 auto; padding: 1rem 16px 3rem; }
.muted { color: var(--muted); font-size: .92rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem; }
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.stack { display: grid; gap: .75rem; }
.row { display: flex; flex-wrap: wrap; gap: .75rem; }
.row label { flex: 1 1 140px; }
label { display: grid; gap: .25rem; font-weight: 600; }
input, select, button { font: inherit; max-width: 100%; }
input[type=date], input:not([type]), input[type=password], select {
  width: 100%; padding: .5rem; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.checklist label { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; }
.checklist input { margin-top: .3rem; min-width: 1.1rem; min-height: 1.1rem; }

.btn {
  display: inline-block; padding: .6rem 1.1rem; min-height: 44px; border: 0; border-radius: 6px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
.btn-alt { background: #5b6b7c; }
.btn-danger { background: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.actions form { margin: 0; }

.msg { padding: .6rem .8rem; border-radius: 6px; background: #e8f0fb; border: 1px solid #c4d6ef; }
.msg-error { background: #fbeaea; border-color: #efc4c4; }
.msg-success { background: #e8f6ed; border-color: #bfe3cc; }
.status { margin: .5rem 0 1rem; font-size: .95rem; }
.status-cancelled, .status-superseded { color: var(--danger); }
.status-approved, .status-sent { color: var(--ok); }

/* Bill letter */
.letter {
  background: #fff; border: 1px solid var(--line); padding: 1rem;
  font-family: Georgia, "Times New Roman", serif; font-size: .95rem;
}
.letterhead { text-align: center; border-bottom: 2px solid var(--ink); padding-bottom: .5rem; margin-bottom: .75rem; }
.lh-name { font-size: 1.3rem; font-weight: 700; }
.lh-small { font-size: .85rem; }
.refline { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem 1rem; }
.stagebox { display: inline-block; border: 2px solid var(--ink); padding: .2rem .6rem; margin: .6rem 0; font-weight: 700; }
.addressee { margin: .5rem 0 1rem; }
table.bill { width: 100%; border-collapse: collapse; table-layout: fixed; margin: .75rem 0; }
table.bill th, table.bill td { border: 1px solid var(--ink); padding: .35rem .4rem; vertical-align: top; }
table.bill .sl { width: 3.2rem; text-align: center; }
table.bill .amt { width: 6.2rem; text-align: right; }
table.bill td.amt { white-space: nowrap; }
table.bill th { overflow-wrap: normal; word-break: normal; }
table.bill .right { text-align: right; }
.words { margin: .5rem 0 1rem; }
.sign { text-align: right; margin: 1.5rem 0 1rem; }
.prereceipted { font-weight: 700; text-decoration: underline; margin-bottom: 2.5rem; }
.bank { font-size: .9rem; border-top: 1px dashed var(--line); padding-top: .6rem; }

/* Money pages (receipts, ledger, outstanding) */
.scrollbox { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 8px; background: var(--card); margin: .5rem 0 1rem; }
.scrollbox:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
table.money { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.money th, table.money td { padding: .4rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.money thead th { background: #eef1f4; overflow-wrap: normal; }
table.money .amt { text-align: right; white-space: nowrap; }
table.money .right { text-align: right; }
table.money tfoot th { border-top: 2px solid var(--ink); border-bottom: 0; }
table.money .nowrap { white-space: nowrap; }
table.ledger td:nth-child(2) { min-width: 12rem; }
table.money tr.void td, .card.void { color: var(--muted); text-decoration: line-through; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: .5rem 0 1rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; }
.errlist { margin: .3rem 0 0; padding-left: 1.2rem; }
.focus { border-color: var(--accent); box-shadow: 0 0 0 2px #c4d6ef; }
.asof { align-items: flex-end; margin-bottom: .5rem; }
.asof label { flex: 0 1 220px; }
.voidform { margin-top: .5rem; align-items: flex-end; }
.sentform { margin-top: 1rem; }
.sentform h2 { margin: 0; }
a.btn { text-decoration: none; text-align: center; }
.pay-paid { color: var(--ok); }
.pay-unpaid { color: var(--danger); }

@media (max-width: 420px) {
  .letter { padding: .6rem; font-size: .88rem; }
  table.bill .sl { width: 2.4rem; }
  table.bill .amt { width: 5rem; }
  table.bill th, table.bill td { padding: .3rem .25rem; }
}

@media print {
  .topbar, .actions, .status, .wrap > p:first-child, .payments, .sentform { display: none; }
  body { background: #fff; }
  .letter { border: 0; }
}

/* ledger and outstanding as stacked cards on phones: each entry shows its amounts without sideways swiping */
@media (max-width: 600px) {
  table.ledger thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.ledger, table.ledger tbody, table.ledger tr, table.ledger td { display: block; width: 100%; }
  table.ledger tbody tr { border-bottom: 1px solid var(--line); padding: .5rem .6rem; }
  table.ledger tbody td { border: 0; padding: .1rem 0; min-width: 0 !important; }
  table.ledger tbody td.amt { display: flex; justify-content: space-between; text-align: right; }
  table.ledger tbody td.amt:empty { display: none; }
  table.ledger tbody td[data-label]::before { content: attr(data-label); color: var(--muted); font-weight: 400; margin-right: .75rem; text-align: left; }
  table.ledger tbody td.nowrap::before { display: none; }
  table.ledger tbody td.nowrap { font-weight: 600; }
  table.ledger tfoot, table.ledger tfoot tr { display: flex; justify-content: space-between; width: 100%; }
  table.ledger tfoot th { display: block; border-top: 2px solid var(--ink); padding: .5rem .6rem; }
  table.ledger tfoot th[colspan] { flex: 1; }
}

@media (max-width: 600px) {
  table.cards-sm thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.cards-sm, table.cards-sm tbody, table.cards-sm tr, table.cards-sm td { display: block; width: 100%; }
  table.cards-sm tbody tr { border-bottom: 1px solid var(--line); padding: .5rem .6rem; }
  table.cards-sm tbody td { border: 0; padding: .1rem 0; }
  table.cards-sm tbody td:first-child { font-weight: 600; }
  table.cards-sm tbody td.amt { display: flex; justify-content: space-between; text-align: right; }
  table.cards-sm tbody td[data-label]::before { content: attr(data-label); color: var(--muted); margin-right: .75rem; text-align: left; }
  table.cards-sm tbody td.net { border-top: 1px dashed var(--line); margin-top: .2rem; padding-top: .3rem; }
  table.cards-sm tfoot { display: block; }
  table.cards-sm tfoot tr { display: flex; justify-content: space-between; padding: .5rem .6rem; border-top: 2px solid var(--ink); }
  table.cards-sm tfoot th { display: none; border: 0; padding: 0; }
  table.cards-sm tfoot th:first-child, table.cards-sm tfoot th:last-child { display: block; }
  table.cards-sm tfoot th:first-child::after { content: " net due"; }
}
