:root {
  --bg: #f4f5f7;
  --panel: #fff;
  --ink: #1b1f24;
  --muted: #5f6b7a;
  --line: #dde1e6;
  --accent: #0b5cad;
  --accent-ink: #fff;
  --ok: #1f7a3d;
  --warn: #a35b00;
  --bad: #b3261e;
  --chip: #eef1f4;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; color: var(--ink); text-decoration: none; font-size: 17px; }
.brand span { color: var(--muted); font-weight: 500; }
nav { display: flex; gap: 6px; align-items: center; }
nav a { padding: 7px 12px; border-radius: 7px; text-decoration: none; color: var(--ink); }
nav a.active:not(.btn) { background: var(--chip); font-weight: 600; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 24px 60px; }
/* Pages with a PDF beside the form use the whole window width. */
main:has(.split) { max-width: none; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

.btn {
  display: inline-block; padding: 8px 14px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: #b9c0c8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { padding: 6px 11px; border-radius: 999px; background: var(--chip); border: 1px solid transparent; cursor: pointer; font: inherit; font-size: 13px; }
.chip.on { background: var(--panel); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip .n { color: var(--muted); margin-left: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: #f8f9fb; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--chip); color: var(--muted); white-space: nowrap; }
.badge.draft { background: #eef1f4; color: #44505c; }
.badge.open { background: #e6f0fb; color: var(--accent); }
.badge.soon { background: #fff2df; color: var(--warn); }
.badge.ready { background: #fde8e6; color: var(--bad); }
.badge.arrangement { background: #f1e9fb; color: #6a3fa0; }
.badge.settled, .badge.paid_in_full { background: #e5f4ea; color: var(--ok); }
.badge.collections { background: #2b333d; color: #fff; }
.badge.closed { background: #eef1f4; color: var(--muted); }

form .grid, .grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.c2 { grid-column: span 2; } label.c3 { grid-column: span 3; } label.c4 { grid-column: span 4; } label.c6 { grid-column: span 6; } label.c1 { grid-column: span 1; }
input, select, textarea {
  width: 100%; min-width: 0;
  font: inherit; color: var(--ink); padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b5d3f3; border-color: var(--accent); }
input[readonly] { background: #f6f7f9; }
.section-title { grid-column: span 6; font-weight: 600; font-size: 13px; color: var(--ink); margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.section-title:first-child { border-top: 0; margin-top: 0; padding-top: 0; }

/* The form keeps a readable width (it can shrink a little on smaller laptops);
   the PDF gets everything else, so it grows with the window. */
.split { display: grid; grid-template-columns: clamp(400px, 34vw, 560px) minmax(0, 1fr); gap: 16px; align-items: start; }
.pdf { width: 100%; height: calc(100vh - 96px); min-height: 560px; border: 1px solid var(--line); border-radius: 10px; background: #fff; position: sticky; top: 76px; }

.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; }
.fig { background: #f8f9fb; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.fig .k { font-size: 12px; color: var(--muted); }
.fig .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.fig.offer { border-color: var(--accent); background: #f2f7fd; }

.drop { border: 2px dashed #b9c0c8; border-radius: 12px; padding: 48px 20px; text-align: center; background: var(--panel); cursor: pointer; }
.drop.over { border-color: var(--accent); background: #f2f7fd; }
.drop input { display: none; }

.history { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.history li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; }
.history .when { color: var(--muted); white-space: nowrap; min-width: 140px; }

.notice { padding: 10px 12px; border-radius: 8px; background: #fff7e6; border: 1px solid #f1d39a; font-size: 14px; margin-bottom: 12px; }
.notice.info { background: #eef5fd; border-color: #c4dbf3; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(460px, 92vw); }
dialog::backdrop { background: rgba(20, 24, 30, .35); }
dialog .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
dialog label.c2 { grid-column: span 2; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); padding: 10px 16px; border-radius: 8px; background: #22282f; color: #fff; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }
#toast.error { background: var(--bad); }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  /* Stacked: the PDF is full width below the form, about a page tall. */
  .pdf { position: static; height: 85vh; }

  main { padding: 16px; }
  .top { padding: 10px 16px; }
}
input[type=checkbox] { width: auto; }
#q { width: min(300px, 100%); }
#agency { width: min(320px, 70vw); }

/* Needs attention, at the top of the accounts screen */
.attention { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-bottom: 18px; align-items: start; }
.att-card { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 10px; padding: 14px 16px; }
.att-card.soon { border-left-color: var(--warn); }
.att-card.ready { border-left-color: var(--bad); }
.att-card.draft { border-left-color: var(--accent); }
.att-card h2 { font-size: 15px; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.att-card h2 .n { background: var(--chip); border-radius: 999px; padding: 1px 8px; font-size: 12px; color: var(--muted); }
.att-card ul { list-style: none; margin: 0 0 4px; padding: 0; }
.att-card li { padding: 7px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.att-card li:first-child { border-top: 0; }
.att-card li a { text-decoration: none; color: var(--ink); }
.att-card li a:hover strong { color: var(--accent); }
.att-card .btn { margin-top: 6px; font-size: 13px; padding: 6px 10px; }
.attention-clear { color: var(--ok); font-weight: 600; }

/* Sign-in and not-configured pages */
body.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate-box { width: min(380px, 100%); padding: 0; }
.gate-box .brand { display: block; text-align: center; margin-bottom: 14px; font-size: 18px; }
.gate-box form, .gate-box .panel { display: flex; flex-direction: column; gap: 12px; }
.gate-box h1 { margin: 0; font-size: 20px; }
nav form { margin: 0; }
.btn.destroy { background: var(--bad); border-color: var(--bad); color: #fff; }

/* Payment arrangement summary on the account page */
.arr-box { background: #f1e9fb; border: 1px solid #d9c6f0; border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px; line-height: 1.5; }
.arr-box.late { background: #fde8e6; border-color: #f2b8b2; }

/* Storage over the statutory limit */
.notice.bad { background: #fde8e6; border-color: #f2b8b2; }
.storage-note { grid-column: span 4; align-self: end; color: var(--bad); font-size: 13px; font-weight: 600; padding-bottom: 9px; }
td .badge + .badge { margin-left: 4px; }

/* PDF viewer over the page */
dialog.viewer { width: min(1400px, 96vw); height: 94vh; max-width: none; max-height: none; padding: 0; overflow: hidden; }
dialog.viewer[open] { display: flex; flex-direction: column; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.viewer-bar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
dialog.viewer iframe { flex: 1; width: 100%; border: 0; background: #525659; }
/* Replace-invoice comparison */
table.changes { margin: 6px 0 10px; font-size: 14px; }
table.changes td, table.changes th { padding: 6px 8px; }
dialog:has(table.changes) { width: min(560px, 92vw); }

/* Supporting documents */
.doc-list { list-style: none; padding: 0; margin: 0 0 12px; }
.doc-list li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.doc-list li .muted { flex: 1; min-width: 160px; }
.small-btn { padding: 4px 9px; font-size: 12px; }
.doc-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.doc-form .small-drop { grid-column: span 2; padding: 18px 12px; font-size: 14px; }
/* With the agency */
.bad-num { color: var(--bad); font-weight: 700; }
.table-scroll { overflow-x: auto; }
tfoot td { border-top: 2px solid var(--line); border-bottom: 0; }
.placement-box { background: #f2f7fd; border: 1px solid #c4dbf3; border-radius: 8px; padding: 12px; margin-bottom: 14px; }
.placement-box table { font-size: 14px; }
.placement-box td { padding: 5px 8px; }
.placement-box .row { margin-top: 8px; }
/* Saved signature preview */
.sig-preview { background: #fff; border: 1px dashed var(--line); border-radius: 8px; padding: 10px; display: inline-block; margin-bottom: 6px; }
.sig-preview img { max-width: 320px; max-height: 90px; display: block; }
