/* InvoiceDesk. One visual system: radius 4 (controls) / 6 (boxes) / 10 (pop-ups), one border colour for boxes. */
@font-face { font-family: "Inter"; src: url("../fonts/Inter-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Inter"; src: url("../fonts/Inter-Medium.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Inter"; src: url("../fonts/Inter-SemiBold.ttf") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Inter"; src: url("../fonts/Inter-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --ink: #1f2328; --ink-2: #3b4148; --muted: #6b7280; --faint: #9aa1ab;
  --bg: #ffffff; --panel: #f7f7f8; --hover: #f2f3f5;
  --line: #e6e7ea; --line-strong: #cfd2d7;
  --accent: #b3261e; --accent-soft: #fbeceb; --accent-line: #f0c9c6;
  --ok: #1a7f4b; --ok-soft: #e8f5ee; --ok-line: #bfe3cf;
  --warn: #9a6200; --warn-soft: #fdf4e1; --warn-line: #f1dba6;
  --info: #1d4f91; --info-soft: #e9f0fa; --info-line: #c5d7ef;
  --radius-sm: 4px; --radius: 6px; --radius-lg: 10px;
  --shadow-pop: 0 12px 40px rgba(20, 24, 31, .18);
  --sidebar: 236px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 14px; line-height: 1.5;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; font-feature-settings: "tnum" 1, "cv11" 1; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; line-height: 1.25; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }
.hidden { display: none !important; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; padding: 18px 12px 12px; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 16px; text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: var(--radius); background: var(--ink); color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; letter-spacing: -.02em; position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; right: -3px; bottom: -3px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel); }
.brand-name { font-weight: 700; font-size: 15.5px; letter-spacing: -.01em; }
.nav { display: flex; flex-direction: column; gap: 1px; margin-top: 14px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm); text-decoration: none; color: var(--ink-2);
  font-size: 13.5px; font-weight: 500; white-space: nowrap; }
.nav a svg { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; opacity: .75; }
.nav a:hover { background: var(--hover); }
.nav a.on { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); font-weight: 600; }
.nav a.on svg { opacity: 1; color: var(--accent); }
.nav .sep { height: 1px; background: var(--line); margin: 8px 6px; }
.side-foot { margin-top: auto; padding: 12px 8px 2px; border-top: 1px solid var(--line); font-size: 12.5px; }
.side-foot .who { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot form { margin-top: 8px; display: flex; gap: 6px; }
.main { min-width: 0; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(20, 24, 31, .4); z-index: 25; }
.topbar { display: none; }
.page { padding: 26px 32px 60px; max-width: 1320px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; max-width: 70ch; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.crumb a { text-decoration: none; }
.crumb a:hover { text-decoration: underline; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink); font: inherit; font-size: 13.5px; font-weight: 500;
  text-decoration: none; cursor: pointer; white-space: nowrap; flex: none; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #000; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: #99201a; }
.btn.danger { color: var(--accent); border-color: var(--accent-line); }
.btn.danger:hover { background: var(--accent-soft); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--ink); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; white-space: nowrap; }
.link.danger { color: var(--accent); }
.inline { display: inline; }

/* ---- boxes ---- */
.card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.card > .card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card > .card-body { padding: 18px; }
.card > .card-foot { padding: 12px 18px; border-top: 1px solid var(--line); background: var(--panel); border-radius: 0 0 var(--radius) var(--radius); }
.step-no { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 11.5px; font-weight: 600; margin-right: 8px; flex: none; }
.cols { display: grid; gap: 16px; }
.cols.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols.side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; background: #fff; min-width: 0; text-decoration: none; display: block; }
.stat .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 23px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.alert .value { color: var(--accent); }
a.stat:hover { border-color: var(--line-strong); }

/* ---- messages ---- */
.flash { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; background: var(--panel); }
.flash.ok { background: var(--ok-soft); border-color: var(--ok-line); color: #0f5a33; }
.flash.error { background: var(--accent-soft); border-color: var(--accent-line); color: #7d1a15; }
.flash.warn { background: var(--warn-soft); border-color: var(--warn-line); color: #6d4500; }
.flash.info { background: var(--info-soft); border-color: var(--info-line); color: #163d70; }
.flash ul { margin: 4px 0 0; padding-left: 18px; }
.flash li + li { margin-top: 2px; }

/* ---- pills ---- */
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--panel); color: var(--ink-2); border: 1px solid var(--line); }
.pill.draft { background: #fff; color: var(--muted); border-style: dashed; border-color: var(--line-strong); }
.pill.issued, .pill.sent { background: var(--info-soft); color: var(--info); border-color: var(--info-line); }
.pill.partially_paid { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.pill.paid, .pill.yes { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.pill.overdue, .pill.no { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.pill.cancelled { background: var(--panel); color: var(--faint); text-decoration: line-through; }
.pill.check { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }

/* ---- tables ---- */
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; background: #fff; -webkit-overflow-scrolling: touch; }
.card .table-wrap { border: 0; border-radius: 0; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); white-space: nowrap; }
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #fcfcfd; }
table.data th.num, table.data td.num { text-align: right; }
table.data tfoot td { font-weight: 600; background: var(--panel); border-top: 1px solid var(--line-strong); border-bottom: 0; }
table.data td a.main { font-weight: 600; text-decoration: none; }
table.data td a.main:hover { text-decoration: underline; }
table.data .sub { color: var(--muted); font-size: 12.5px; }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); }
.empty .btn { margin-top: 12px; }

/* ---- forms ---- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .help { font-size: 12px; color: var(--muted); }
.field .err { font-size: 12px; color: var(--accent); font-weight: 500; }
.field.bad input, .field.bad select, .field.bad textarea { border-color: var(--accent); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month], input[type=search], select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; color: var(--ink);
  font: inherit; font-size: 14px; min-width: 0; }
textarea { height: auto; padding: 8px 10px; resize: vertical; min-height: 72px; line-height: 1.45; }
select { appearance: none; -webkit-appearance: none; padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' stroke='%236b7280' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
input[readonly] { background: var(--panel); color: var(--muted); }
input[type=color] { width: 44px; height: 36px; padding: 2px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; }
input[type=file] { font: inherit; font-size: 13px; max-width: 100%; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 13.5px; cursor: pointer; }
.check input { margin-top: 3px; width: 15px; height: 15px; accent-color: var(--ink); flex: none; }
.choice { display: flex; gap: 8px; flex-wrap: wrap; }
.choice label { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13.5px; font-weight: 500; white-space: nowrap; }
.choice input { accent-color: var(--ink); }
.choice label:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.fgrid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px 16px; }
.fgrid > .s12 { grid-column: span 12; } .fgrid > .s8 { grid-column: span 8; } .fgrid > .s6 { grid-column: span 6; }
.fgrid > .s4 { grid-column: span 4; } .fgrid > .s3 { grid-column: span 3; } .fgrid > .s2 { grid-column: span 2; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.note { border-left: 3px solid var(--line-strong); padding: 2px 0 2px 12px; color: var(--muted); font-size: 13px; }

/* ---- filters and tabs ---- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters select, .filters input { width: auto; height: 34px; font-size: 13.5px; }
.filters input[type=search] { width: 220px; }
.tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 9px 0; font-size: 13.5px; font-weight: 500; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a .count { color: var(--faint); font-weight: 500; margin-left: 4px; }

/* ---- definition lists ---- */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 20px; }
.facts .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.facts .v { margin-top: 2px; overflow-wrap: anywhere; white-space: pre-line; }

/* ---- charts ---- */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 190px) minmax(0, 1fr) auto; gap: 12px; align-items: center; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--panel); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--ink); border-radius: 999px; min-width: 2px; }
.bar-fill.zero { background: transparent; min-width: 0; }
.trend { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; align-items: end; height: 150px; }
.trend .col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; min-width: 0; }
.trend .pair { display: flex; align-items: flex-end; gap: 3px; height: 100%; width: 100%; justify-content: center; }
.trend .b { width: 38%; max-width: 16px; background: var(--ink); border-radius: 2px 2px 0 0; min-height: 2px; }
.trend .b.c { background: var(--accent); opacity: .8; }
.trend .m { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; background: var(--ink); margin-right: 5px; }
.legend i.c { background: var(--accent); opacity: .8; }

/* ---- checklist ---- */
.todo { display: flex; flex-direction: column; }
.todo .item { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.todo .item:last-child { border-bottom: 0; }
.todo .tick { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--line-strong); flex: none; display: grid; place-items: center; font-size: 12px; color: #fff; }
.todo .done .tick { background: var(--ok); border-color: var(--ok); }
.todo .done .t { color: var(--muted); }
.todo .t { font-weight: 600; }

/* ---- invoice editor ---- */
.lines { width: 100%; border-collapse: collapse; min-width: 860px; }
.lines th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 0 6px 6px; white-space: nowrap; }
.lines td { padding: 4px 6px 10px; vertical-align: top; }
.lines td:first-child, .lines th:first-child { padding-left: 0; }
.lines input, .lines select, .lines textarea { font-size: 13.5px; }
.lines textarea { min-height: 36px; height: 36px; }
.lines .num input { text-align: right; }
.lines .out { height: 36px; display: flex; align-items: center; justify-content: flex-end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lines .rm { height: 36px; width: 30px; border: 0; background: none; color: var(--faint); cursor: pointer; font-size: 18px; border-radius: var(--radius-sm); }
.lines .rm:hover { background: var(--accent-soft); color: var(--accent); }
.line { padding: 14px 0; border-bottom: 1px solid var(--line); }
.line:first-child { padding-top: 0; }
.line:last-child { border-bottom: 0; padding-bottom: 0; }
.line .field > label { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.line .l-top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 12px; }
.line .l-bot { display: grid; grid-template-columns: 82px 70px 84px minmax(0, 1.5fr) minmax(0, 1fr) 84px minmax(0, 1.1fr) 30px; gap: 12px; margin-top: 10px; align-items: start; }
.line textarea { min-height: 36px; height: 36px; }
.line input[type=number] { text-align: right; }
.line input[type=number]::-webkit-outer-spin-button, .line input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.line input[type=number] { -moz-appearance: textfield; appearance: textfield; padding: 0 8px; }
.line .l-out { text-align: right; }
.line .out { height: 36px; display: flex; align-items: center; justify-content: flex-end; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.line-x { height: 36px; width: 30px; margin-top: 22px; border: 0; background: none; color: var(--faint); cursor: pointer; font-size: 18px; border-radius: var(--radius-sm); }
.line-x:hover { background: var(--accent-soft); color: var(--accent); }
.sum { display: flex; flex-direction: column; gap: 7px; font-size: 13.5px; }
.sum .r { display: flex; justify-content: space-between; gap: 12px; }
.sum .r span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.sum .r.total { border-top: 1px solid var(--ink); padding-top: 10px; margin-top: 4px; font-size: 18px; font-weight: 700; }
.sum .words { font-size: 12.5px; color: var(--muted); }
.sticky { position: sticky; top: 16px; }

/* ---- document preview (mirrors the PDF) ---- */
/* The on-screen invoice: laid out like the printed A4 page (see pdfgen.py). */
.doc { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; position: relative; overflow: clip; display: flex; flex-direction: column; aspect-ratio: 210 / 297; --doc-accent: var(--accent); }
.doc .mark { position: absolute; inset: 0; display: grid; place-items: center; font-size: 92px; font-weight: 700; color: rgba(31, 35, 40, .06); transform: rotate(-28deg); pointer-events: none; letter-spacing: .04em; z-index: 1; }
.doc-head { padding: 34px 38px 0; }
.doc.modern .doc-head { background: #1F2328; color: #fff; padding: 34px 38px 30px; border-bottom: 4px solid var(--doc-accent); }
.doc-top { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
.doc-top .t { font-size: 22px; font-weight: 700; letter-spacing: .01em; text-align: right; }
.doc-top img { max-height: 46px; max-width: 200px; display: block; margin-bottom: 10px; }
.doc.modern .doc-top img { max-height: 40px; }
.doc .issuer-name { font-size: 17px; font-weight: 700; }
.doc .legal { color: var(--muted); } .doc.modern .legal { color: #C9CDD3; }
.doc .rule { width: 56px; height: 3px; background: var(--doc-accent); margin-bottom: 14px; }
.doc-body { padding: 0 38px; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr 1.05fr; gap: 22px; margin: 28px 0 30px; font-size: 13px; }
.doc .lbl { font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.doc .pre { white-space: pre-line; overflow-wrap: anywhere; }
.doc-facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; font-size: 13px; align-content: start; }
.doc-facts dt { color: var(--muted); white-space: nowrap; } .doc-facts dd { margin: 0; text-align: right; }
.doc-facts dd.strong { white-space: nowrap; }
.doc table { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc table th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: left; padding: 9px 8px; border-top: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink); white-space: nowrap; }
.doc table th.num { text-align: right; }
.doc.modern table thead { background: #1F2328; }
.doc.modern table th { background: #1F2328; color: #fff; border: 0; padding: 11px 8px; }
.doc table td { padding: 11px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.doc .doc-bottom { display: grid; grid-template-columns: 1.3fr 1fr; gap: 26px; margin-top: 22px; align-items: start; }
.doc .doc-bottom .sum .total { background: #F5F6F7; padding: 10px 8px; margin: 6px -8px 0; }
.doc .doc-scroll { overflow-x: auto; }
.doc-foot { margin-top: auto; padding: 34px 38px 22px; }
.doc-pay { display: grid; grid-template-columns: 1.5fr 1fr; gap: 26px; border-top: 1px solid var(--line); padding: 20px 0; }
.doc-bank { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; font-size: 13px; margin: 4px 0 0; }
.doc-bank dt { color: var(--muted); font-size: 12px; } .doc-bank dd { margin: 0; overflow-wrap: anywhere; }
.doc-sign { text-align: right; align-self: end; }
.doc-sign img { max-height: 54px; margin: 6px 0 2px auto; display: block; }
.doc-terms { border-top: 1px solid var(--line); padding-top: 16px; }
.doc-line { display: flex; justify-content: space-between; gap: 16px; margin-top: 22px; font-size: 11px; color: var(--muted); }
.doc-line span:last-child { white-space: nowrap; }

/* ---- dialogs ---- */
dialog { border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 0; box-shadow: var(--shadow-pop); width: min(560px, calc(100vw - 28px)); color: var(--ink); max-height: calc(100vh - 40px); }
dialog::backdrop { background: rgba(20, 24, 31, .45); }
dialog .d-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
dialog .d-body { padding: 18px 20px; }
dialog .d-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: var(--panel); border-radius: 0 0 var(--radius-lg) var(--radius-lg); flex-wrap: wrap; }
.x { border: 0; background: none; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: var(--radius-sm); }
.x:hover { background: var(--hover); }
details.more > summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2); list-style: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "+"; display: inline-grid; place-items: center; width: 16px; height: 16px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font-size: 12px; line-height: 1; }
details.more[open] > summary::before { content: "\2212"; }
details.more > .inner { margin-top: 14px; }
details.more > form.inner { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; white-space: normal; }
details.more > form.inner > * { margin-top: 0; }
details.more > form.inner > .btn { align-self: flex-start; }
td.num details.more > form.inner { margin-left: auto; max-width: 220px; }
/* Row actions: icon buttons (pencil, bin). Each opens a form in a hidden row right under its row. */
.acts { display: inline-flex; gap: 6px; justify-content: flex-end; align-items: center; vertical-align: middle; }
.ic { width: 30px; height: 30px; flex: none; display: inline-grid; place-items: center; padding: 0; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; color: var(--ink-2); cursor: pointer; }
.ic svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ic:hover { background: var(--hover); }
.ic.on, .ic.on:hover { background: var(--ink); border-color: var(--ink); color: #fff; }
.ic.del { color: var(--accent); border-color: var(--accent-line); }
.ic.del:hover { background: var(--accent-soft); }
.ic.del.on, .ic.del.on:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
table.data tr.act-row > td { background: var(--panel); padding: 10px 14px; white-space: normal; }
.act-form { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }
.act-form input[type=date] { width: 160px; flex: none; }
.act-form input[type=text] { flex: 0 1 260px; min-width: 0; width: 260px; }
.act-form .btn { flex: none; white-space: nowrap; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.token { display: block; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow-wrap: anywhere; }

/* ---- sign-in ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--panel); }
.auth-box { width: min(440px, 100%); background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 30px 30px 26px; }
.auth-box h1 { margin: 18px 0 4px; }
.auth-box .stack { margin-top: 20px; }

/* ---- small screens ---- */
@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols.side { grid-template-columns: minmax(0, 1fr); }
  .sticky { position: static; }
}
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(280px, 86vw); transform: translateX(-102%); transition: transform .18s ease; box-shadow: var(--shadow-pop); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 20; }
  .topbar .brand { padding: 0; }
  .page { padding: 18px 16px 48px; }
  .cols.c2, .cols.c3 { grid-template-columns: minmax(0, 1fr); }
  .fgrid > .s2, .fgrid > .s3, .fgrid > .s4 { grid-column: span 6; }
  .fgrid > .s8 { grid-column: span 12; }
  .doc { aspect-ratio: auto; }
  .doc-head, .doc.modern .doc-head { padding-left: 18px; padding-right: 18px; padding-top: 22px; }
  .doc-body { padding: 0 18px; }
  .doc-foot { padding: 26px 18px 18px; }
  .doc-parties { grid-template-columns: 1fr 1fr; }
  .doc-parties > :last-child { grid-column: span 2; }
  .doc .doc-bottom { grid-template-columns: 1fr; }
  .page-head .actions { width: 100%; }
}
@media (max-width: 760px) {
  .line .l-top { grid-template-columns: minmax(0, 1fr); }
  .line .l-bot { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .line .l-out { grid-column: span 2; }
  .line-x { justify-self: end; }
}
@media (max-width: 560px) {
  h1 { font-size: 19px; }
  .stats { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  .stat { padding: 12px 12px; }
  .stat .value { font-size: 17px; white-space: normal; overflow-wrap: anywhere; }
  .fgrid > .s2, .fgrid > .s3, .fgrid > .s4, .fgrid > .s6 { grid-column: span 12; }
  .filters select, .filters input, .filters input[type=search] { width: 100%; }
  .filters .btn { flex: 1 1 auto; }
  .bar-row { grid-template-columns: minmax(0, 1fr) auto; }
  .bar-row .bar-track { grid-column: 1 / -1; order: 3; }
  .doc-parties { grid-template-columns: 1fr; }
  .doc-parties > :last-child { grid-column: auto; }
  .doc-top { flex-direction: column; align-items: flex-start; }
  .doc-pay { grid-template-columns: 1fr; }
  .doc-sign { text-align: left; }
  .doc-sign img { margin-left: 0; }
  .doc-bank { grid-template-columns: 110px 1fr; }
  .doc-top .t { text-align: left; }
  .doc .mark { font-size: 54px; }
  .page-head .actions .btn { flex: 1 1 auto; }
  .card > .card-body { padding: 14px; }
  .card > .card-head { padding: 12px 14px; }
  .trend { gap: 3px; }
  .trend .m { font-size: 9.5px; }
}
@media print {
  .sidebar, .topbar, .page-head .actions, .filters, .flash { display: none !important; }
  .shell { display: block; }
  .page { padding: 0; max-width: none; }
}
