:root {
  --navy: #0B1F3A; --navy-2: #163A66; --gold: #C8A45A; --gold-ink: #A9843A;
  --bg: #F4F5F8; --card: #fff; --line: #E2E6EC; --muted: #5F6B7D; --ink: #0B1F3A;
  --good: #1E7B4F; --bad: #B3261E; --warn: #9A6B00;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* otherwise "display: grid" on form labels would show hidden fields */
html, body { margin: 0; }
body { font-family: Montserrat, Arial, sans-serif; font-size: 14px; color: var(--ink); background: var(--bg); }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; color: var(--muted); }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #fff; padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 800; letter-spacing: .06em; font-size: 13px; }
.side .brand b { color: var(--gold); }
.side a { text-decoration: none; padding: 10px 12px; border-radius: 8px; font-weight: 600; color: #C9D3E2; }
.side a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side a.on { background: var(--navy-2); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.side .me { margin-top: auto; font-size: 12px; color: #9FB0C8; padding: 8px 12px; border-top: 1px solid rgba(255,255,255,.08); }
.side .me b { display: block; color: #fff; font-size: 13px; }
.main { padding: 24px 28px 60px; min-width: 0; }
.back-link { border: 0; background: none; padding: 4px 0; margin: -6px 0 8px; font-weight: 700; font-size: 13px; color: var(--muted); cursor: pointer; }
.back-link:hover { color: var(--navy); text-decoration: underline; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top h1 { font-size: 22px; margin: 0; font-weight: 800; }
.top .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; z-index: 5; height: auto; flex-direction: row; overflow-x: auto; padding: 8px; gap: 2px; }
  .side .brand, .side .me { display: none; }
  .side a { white-space: nowrap; padding: 8px 10px; font-size: 13px; }
  .main { padding: 16px; }
}

/* Cards and stats */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card h2 { font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; font-weight: 800; }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.stat small { display: block; font-size: 11px; font-weight: 800; letter-spacing: .14em; color: var(--muted); text-transform: uppercase; }
.stat b { display: block; font-size: 24px; font-weight: 800; margin-top: 6px; }
.stat span { font-size: 12px; color: var(--muted); }

/* Reports: the four everyday reports */
.reports-more { margin-bottom: 16px; }
.reports-more > .card { min-width: 0; }
.two > .card { min-width: 0; overflow-x: auto; }   /* a wide table scrolls inside its card, never the whole page */
.report-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 6px; }
.report-head h2 { margin: 0; }
.report-head .btn { white-space: nowrap; flex: none; }
.report-note { font-size: 12px; margin: 0 0 10px; }
.table-scroll { overflow-x: auto; }
.warn-text { color: var(--warn); }
.cash-sum { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.cash-sum > div { background: #FAFBFC; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.cash-sum small { display: block; font-size: 10.5px; font-weight: 800; letter-spacing: .1em; color: var(--muted); text-transform: uppercase; }
.cash-sum b { display: block; font-size: 17px; margin-top: 3px; font-variant-numeric: tabular-nums; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 800; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #FAFBFC; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: #F8F9FB; }
tr.void td { color: #A0A8B4; text-decoration: line-through; }
td.n, th.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.d { white-space: nowrap; }
tfoot td { font-weight: 800; background: #FAFBFC; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pos { color: var(--bad); }
.neg { color: var(--good); }
.muted { color: var(--muted); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: #EEF1F5; color: var(--muted); text-transform: capitalize; }
.tag.warn { background: #FFF3D6; color: var(--warn); }
.clip { font-size: 12px; color: var(--gold-ink); font-weight: 700; }
/* Lines merged for the client (sales.client_line) */
.merge-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 10px; }
.pick { display: none; margin: 0 8px 0 0; vertical-align: middle; }
.picking .pick { display: inline-block; }
.picking tbody tr { cursor: default; }
.picking tbody tr:has(.pick) { cursor: pointer; }
tr.merged .arrow { display: inline-block; color: var(--muted); transition: transform .15s; }
tr.merged.open .arrow { transform: rotate(90deg); }
tr.part td { background: #FAFBFC; font-size: 13px; color: var(--muted); }
.check-line { display: flex; gap: 8px; align-items: center; margin: 0 0 12px; font-weight: 600; }

/* Buttons and forms */
.btn { border: 1px solid var(--line); background: #fff; padding: 9px 14px; border-radius: 8px; font-weight: 700; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: #C9D0DA; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters label { font-size: 11px; font-weight: 700; color: var(--muted); display: grid; gap: 4px; }
input, select, textarea { border: 1px solid #CDD4DE; border-radius: 8px; padding: 9px 10px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
textarea { min-height: 70px; resize: vertical; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form label { display: grid; gap: 5px; font-size: 12px; font-weight: 700; color: var(--muted); }
.form label.wide, .form p.wide { grid-column: 1 / -1; }
.form .hint { font-weight: 500; font-size: 12px; color: var(--muted); }
.form .calc { grid-column: 1 / -1; background: #F6F3EC; border-radius: 8px; padding: 10px 12px; font-weight: 700; }
@media (max-width: 560px) { .form { grid-template-columns: 1fr; } }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(11,31,58,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 20; }
.modal { background: #fff; border-radius: 14px; width: min(720px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; font-size: 17px; }
.modal .body { padding: 18px 20px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.err { color: var(--bad); font-weight: 700; margin-top: 10px; }
dl.info { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0 0 16px; }
dl.info dt { color: var(--muted); font-weight: 700; font-size: 12px; }
dl.info dd { margin: 0; font-weight: 600; }

/* Attachments */
.files { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.file { width: 120px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-size: 11px; background: #fff; text-decoration: none; position: relative; }
.file img { width: 100%; height: 90px; object-fit: cover; display: block; background: #EEF1F5; }
.file .pdf { height: 90px; display: grid; place-items: center; background: #F6F3EC; font-weight: 800; color: var(--gold-ink); }
.file span { display: block; padding: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file button { position: absolute; top: 4px; right: 4px; border: 0; border-radius: 6px; background: rgba(255,255,255,.9); cursor: pointer; font-size: 11px; padding: 2px 6px; color: var(--bad); }
.drop { border: 2px dashed #CDD4DE; border-radius: 10px; padding: 14px; text-align: center; color: var(--muted); font-weight: 600; cursor: pointer; display: block; }
.form .dropzone { grid-column: 1 / -1; display: grid; gap: 5px; }
.dz-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.dz-box { border: 2px dashed #CDD4DE; border-radius: 10px; padding: 14px; text-align: center; display: grid; gap: 10px; justify-items: center; transition: background .15s, border-color .15s; }
.dropzone.over .dz-box { border-color: var(--gold); background: #F6F3EC; }
.dz-hint { color: var(--muted); font-weight: 600; font-size: 13px; }
.dz-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.form .dz-btns label.btn { display: inline-flex; font-size: inherit; color: inherit; cursor: pointer; }
.dz-list { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.dz-list:empty { display: none; }
.dz-file { background: #F4F6F9; border-radius: 6px; padding: 4px 8px; font-size: 12px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dz-file button { border: 0; background: none; color: var(--bad); cursor: pointer; font-size: 14px; padding: 0 0 0 4px; }

.checks { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 6px; font-size: 13px; }
.checks li { padding: 8px 10px; border-radius: 8px; background: #F4F6F9; }
.checks li.ok { background: #EAF6EF; color: var(--good); }
.checks li.warn { background: #FFF6E0; color: #6B4B00; font-weight: 600; }
.modal td input, .modal td select { padding: 6px 8px; }

.backup-warn { background: #FFF6E0; border-color: #F0D58C; color: #6B4B00; margin-bottom: 16px; }
.backup-ok { color: var(--good); font-size: 12px; font-weight: 600; margin: 0; }
.backup-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: -8px 0 14px; }
.backup-warn.backup-row { margin: 0 0 16px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 99px; font-weight: 700; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 30; }
#toast.show { opacity: 1; }

/* Printable statement (same look as the PDF statements) */
.statement { background: #fff; width: 210mm; min-height: 297mm; margin: 0 auto; padding: 18mm 16mm 26mm; position: relative; font-size: 9.5pt; box-shadow: 0 6px 30px rgba(0,0,0,.12); }
.statement header { display: flex; justify-content: space-between; align-items: flex-end; padding-bottom: 6mm; border-bottom: .6mm solid var(--navy); }
.statement header img { height: 13mm; }
.statement header h1 { font-size: 17pt; font-weight: 800; letter-spacing: .04em; margin: 0; text-align: right; }
.statement header p { font-size: 9pt; font-weight: 700; color: var(--gold-ink); letter-spacing: .2em; margin: 1mm 0 0; text-align: right; }
.statement .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8mm; margin: 7mm 0 6mm; }
.statement .meta > div { background: #F5F6F8; border-radius: 2mm; padding: 4mm 5mm; }
.statement .meta small { display: block; font-size: 7pt; font-weight: 700; letter-spacing: .18em; color: var(--muted); margin-bottom: 1mm; }
.statement .meta b { font-size: 11pt; font-weight: 800; text-transform: uppercase; }
.statement .meta dl { display: grid; grid-template-columns: auto 1fr; gap: 1mm 4mm; margin: 0; font-size: 9pt; }
.statement .meta dt { color: var(--muted); font-weight: 600; }
.statement .meta dd { margin: 0; font-weight: 700; }
.statement th { background: var(--navy); color: #fff; font-size: 7.5pt; padding: 3mm; }
.statement td { padding: 2mm 3mm; font-weight: 500; }
.statement td.desc { font-weight: 600; overflow-wrap: anywhere; } /* a very long name wraps instead of pushing Balance off the page */
.statement tbody tr:nth-child(even) td { background: #FAFAFB; }
.statement tfoot td { border-top: .6mm solid var(--navy); background: #fff; padding-top: 4mm; }
.statement .due { margin-top: 6mm; display: flex; justify-content: flex-end; }
.statement .due div { background: var(--navy); color: #fff; border-radius: 2mm; padding: 4mm 6mm; min-width: 80mm; display: flex; justify-content: space-between; align-items: center; gap: 8mm; }
.statement .due small { font-size: 7.5pt; font-weight: 700; letter-spacing: .18em; color: #D9BC78; }
.statement .due b { font-size: 14pt; font-weight: 800; }
.statement footer { position: absolute; left: 16mm; right: 16mm; bottom: 12mm; display: flex; justify-content: space-between; font-size: 7.5pt; color: var(--muted); border-top: .25mm solid var(--line); padding-top: 3mm; }
.print-bar { display: flex; justify-content: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
/* While "Save as PDF" captures the page: no shadow, and exactly one A4 page tall when it fits */
.statement.pdf-export { box-shadow: none; margin: 0; min-height: 296mm; }
/* Added only while a multi-page PDF is made: blank space that pushes a row / box to the next page, and the repeated column headings */
.statement tr.pdf-gap td { padding: 0 !important; border: 0 !important; background: #fff !important; }
.statement div.pdf-gap { width: 100%; }
td.ref { color: var(--muted); font-size: 11px; font-weight: 600; }
.statement td.ref { font-size: 7.5pt; }

/* Invoice and receipt pages (same look as the statement) */
.statement footer span:first-child { max-width: 80%; }
.doc .meta .contact { margin: 1mm 0 0; font-size: 8.5pt; color: var(--muted); }
.doc .words { text-align: right; font-size: 8.5pt; font-style: italic; color: var(--muted); margin: 3mm 0 0; }
.doc .sum { margin: 10mm 0; padding: 7mm 8mm; border: .4mm solid var(--line); border-radius: 2mm; }
.doc .sum small { display: block; font-size: 7.5pt; font-weight: 700; letter-spacing: .18em; color: var(--muted); }
.doc .sum b { display: block; font-size: 20pt; font-weight: 800; margin: 2mm 0; }
.doc .sum .words { text-align: left; font-size: 10pt; color: var(--ink, #0B1F3A); }
.doc .sign { display: grid; grid-template-columns: 1fr 1fr; gap: 20mm; margin-top: 30mm; }
.doc .sign div { border-top: .3mm solid var(--navy); padding-top: 2mm; font-size: 8.5pt; color: var(--muted); font-weight: 600; }
.void-stamp { position: absolute; top: 70mm; left: 50%; transform: translateX(-50%) rotate(-14deg); border: 1.2mm solid #C0392B; color: #C0392B; border-radius: 3mm;
  padding: 3mm 10mm; font-size: 40pt; font-weight: 900; letter-spacing: .2em; text-align: center; background: #fff; z-index: 2; }
.void-stamp small { display: block; font-size: 9pt; letter-spacing: 0; font-weight: 600; max-width: 110mm; }

@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .side, .print-bar, .top { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .statement { box-shadow: none; margin: 0; }
}
