:root {
  --ink: #1d2733; --muted: #5d6b7a; --line: #d9e0e7; --bg: #f5f7f9; --card: #fff;
  --accent: #1f5fa8; --accent-dark: #174a84; --ok: #1d7a46; --bad: #b3261e; --bad-bg: #fdecea; --ok-bg: #e7f5ec;
  font-size: 16px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); line-height: 1.5; }
a { color: var(--accent); }
main { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.2rem; margin-top: 2rem; }

.top { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; padding: .7rem 1.2rem; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; }
.top nav { display: flex; gap: .3rem; flex-wrap: wrap; }
.top nav a { padding: .35rem .7rem; border-radius: 6px; text-decoration: none; color: var(--ink); }
.top nav a.active { background: var(--bg); font-weight: 600; }
.top nav a:hover { background: var(--bg); }
.logout { margin-left: auto; }

button, .button { display: inline-block; font: inherit; padding: .55rem 1.1rem; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; text-decoration: none; }
button:hover, .button:hover { background: var(--accent-dark); }
button.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
button.link { background: none; color: var(--accent); padding: 0; text-decoration: underline; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid #8db4e8; outline-offset: 1px; }

.form { display: flex; flex-direction: column; gap: .9rem; max-width: 420px; }
.form.wide { max-width: 760px; }
.form label { display: flex; flex-direction: column; gap: .25rem; font-weight: 500; }
.form input:not([type=radio]):not([type=checkbox]), .form select, .form textarea {
  font: inherit; padding: .5rem .6rem; border: 1px solid #b9c4cf; border-radius: 6px; background: #fff; width: 100%; }
.form [aria-invalid=true] { border-color: var(--bad); background: #fffafa; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.form label.choice { flex-direction: row; align-items: flex-start; gap: .5rem; font-weight: 400; }
.form label.choice input { margin-top: .3rem; }
.form button { align-self: flex-start; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.1rem; background: var(--card); display: flex; flex-direction: column; gap: .9rem; margin: 0; }
legend { font-weight: 700; padding: 0 .3rem; }
.upper { text-transform: uppercase; }
.field-error { color: var(--bad); font-weight: 400; font-size: .92rem; }
.error-box { background: var(--bad-bg); color: var(--bad); padding: .7rem 1rem; border-radius: 6px; }
.flash { background: var(--ok-bg); color: var(--ok); padding: .7rem 1rem; border-radius: 6px; }
.muted { color: var(--muted); }
.narrow { max-width: 440px; margin: 2rem auto; background: var(--card); padding: 1.5rem 1.8rem; border-radius: 10px; border: 1px solid var(--line); }
.qr img { display: block; margin: 0 auto; background: #fff; }
code { background: var(--bg); padding: .1rem .3rem; border-radius: 4px; word-break: break-all; }

.title-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.search { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.search input { font: inherit; padding: .5rem .6rem; border: 1px solid #b9c4cf; border-radius: 6px; flex: 1; max-width: 420px; }
table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
table.list th, table.list td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { background: var(--bg); font-weight: 600; font-size: .92rem; }
table.list .num { text-align: right; white-space: nowrap; }
form.inline { display: inline; }

.cards { display: flex; gap: 1rem; flex-wrap: wrap; }
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.4rem; min-width: 160px; text-decoration: none; color: var(--ink); }
.card strong { font-size: 1.8rem; display: block; }
.checklist { list-style: none; padding: 0; }
.checklist li { padding: .2rem 0; }
.checklist li.done { color: var(--muted); }

dl.details { display: grid; grid-template-columns: 10rem 1fr; gap: .4rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.2rem; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; }
.pre { white-space: pre-line; }
.tag { font-size: .8rem; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: .1rem .4rem; vertical-align: middle; font-weight: 400; }
.picture { display: flex; flex-direction: column; gap: .5rem; padding-bottom: .6rem; border-bottom: 1px solid var(--line); }
.picture img { max-width: 260px; max-height: 120px; object-fit: contain; border: 1px dashed var(--line); padding: .3rem; background: #fff; }

@media (max-width: 640px) {
  .form .row { grid-template-columns: 1fr; }
  dl.details { grid-template-columns: 1fr; }
  table.list th:nth-child(3), table.list td:nth-child(3), table.list th:nth-child(4), table.list td:nth-child(4) { display: none; }
}

/* Quotes, invoices, credit notes */
.small { font-size: .88rem; }
.note { background: #fff7e0; color: #6b4e00; padding: .7rem 1rem; border-radius: 6px; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin: 1rem 0; }
a.button.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
button.danger { color: var(--bad); }
.pdf-preview { width: 100%; height: 900px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table.lines { width: 100%; border-collapse: collapse; }
table.lines th { text-align: left; font-size: .85rem; color: var(--muted); padding: .3rem; }
table.lines td { padding: .3rem; vertical-align: top; border-top: 1px solid var(--line); }
table.lines .num { text-align: right; }
table.lines select, table.lines textarea, table.lines input { font: inherit; padding: .4rem; border: 1px solid #b9c4cf; border-radius: 6px; width: 100%; background: #fff; }
table.lines textarea { margin-top: .3rem; }
table.lines .w-sac { width: 6.5rem; }
table.lines .w-qty { width: 4.5rem; }
table.lines .w-unit { width: 5.5rem; }
table.lines .w-rate { width: 8rem; }
table.lines input.num { text-align: right; }
.line-amount { white-space: nowrap; padding-top: .7rem !important; }
.doc-subtotal { text-align: right; }
.form.doc-form { max-width: 1000px; }
[hidden] { display: none !important; }
@media (max-width: 800px) {
  table.lines thead { display: none; }
  table.lines tr.line { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem; border-top: 1px solid var(--line); padding: .5rem 0; }
  table.lines tr.line td { border: 0; }
  table.lines tr.line td:first-child { grid-column: 1 / -1; }
  table.lines .w-sac, table.lines .w-qty, table.lines .w-unit, table.lines .w-rate { width: 100%; }
}

/* Payments */
.pdf-preview.short { height: 640px; }
table.alloc input { font: inherit; padding: .4rem; border: 1px solid #b9c4cf; border-radius: 6px; width: 9rem; text-align: right; }
.tag.late { background: var(--bad-bg); color: var(--bad); border-color: #f1c4c0; }
.pay-tools { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin: 0; }
.danger-zone { margin-top: 2.5rem; }
.danger-zone summary { cursor: pointer; color: var(--muted); }
.danger-zone .form { margin-top: .8rem; }
.cards .card.owed strong { color: var(--accent); }
.cards .card.late strong { color: var(--bad); }
.money-row td.neg { color: var(--ok); }
.big-line { font-size: 1.1rem; }
pre.summary { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; white-space: pre-wrap; font: inherit; font-size: .92rem; }

/* Reports */
nav.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
nav.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--ink); border-radius: 6px 6px 0 0; }
nav.tabs a.active { background: var(--card); border: 1px solid var(--line); border-bottom-color: var(--card); margin-bottom: -1px; font-weight: 600; }
table.report { font-size: .92rem; }
table.report tr.group td { background: #f9fbfc; border-top: 2px solid var(--line); }
table.report tr.sub td { border-bottom: 0; padding-top: .25rem; padding-bottom: .25rem; }
table.report tr.sub td:first-child { padding-left: 1.6rem; }
table.report tfoot th { background: var(--bg); text-align: left; }
table.report tfoot th.num { text-align: right; }
table.report td.bars { width: 18%; min-width: 90px; }
.bar { display: block; height: 6px; border-radius: 3px; margin: 3px 0; }
.bar.billed { background: var(--accent); }
.bar.received { background: var(--ok); }
.legend .bar { display: inline-block; width: 14px; vertical-align: middle; margin: 0 .2rem 0 .6rem; }
@media (max-width: 800px) { table.report { display: block; overflow-x: auto; } }

/* Bar widths in 5% steps (inline styles are blocked by the security rules) */
.bar.w0 { display: none; }
.bar.w5 { width: 5%; }
.bar.w10 { width: 10%; }
.bar.w15 { width: 15%; }
.bar.w20 { width: 20%; }
.bar.w25 { width: 25%; }
.bar.w30 { width: 30%; }
.bar.w35 { width: 35%; }
.bar.w40 { width: 40%; }
.bar.w45 { width: 45%; }
.bar.w50 { width: 50%; }
.bar.w55 { width: 55%; }
.bar.w60 { width: 60%; }
.bar.w65 { width: 65%; }
.bar.w70 { width: 70%; }
.bar.w75 { width: 75%; }
.bar.w80 { width: 80%; }
.bar.w85 { width: 85%; }
.bar.w90 { width: 90%; }
.bar.w95 { width: 95%; }
.bar.w100 { width: 100%; }
