:root {
  --ink: #11223a;
  --ink-2: #1b3050;
  --ink-3: #2c4468;
  --bg: #f1f3f6;
  --paper: #ffffff;
  --line: #dde2e9;
  --line-soft: #edf0f4;
  --text: #17212f;
  --muted: #5d6b7e;
  --volt: #f5c400;
  --volt-deep: #d9ad00;
  --volt-soft: #fff6cc;
  --blue: #1f5fae;
  --green: #12805c;
  --green-soft: #dff3ea;
  --red: #b42318;
  --red-soft: #fde7e4;
  --amber: #a65b00;
  --amber-soft: #ffeccc;
  --grey-soft: #e8ebf0;
  --blue-soft: #e1ecfa;
  --radius: 6px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin: 0 0 10px; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--ink);
  color: #c9d4e4;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; padding: 4px 8px 18px; font-weight: 650; font-size: 15px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--volt); color: var(--ink); display: grid; place-items: center; flex: none; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  color: #c9d4e4;
  padding: 8px 10px 8px 12px;
  border-radius: var(--radius);
  border-left: 3px solid transparent;
  font-size: 14px;
}
.nav a:hover { background: var(--ink-2); text-decoration: none; color: #fff; }
.nav a.active { background: var(--ink-2); color: #fff; border-left-color: var(--volt); font-weight: 600; }
.nav-group { margin: 16px 12px 4px; font-size: 12.5px; color: #8fa1bb; font-weight: 600; }
.nav-spacer { flex: 1; min-height: 16px; }
.main { min-width: 0; }
.view { max-width: 1240px; margin: 0 auto; padding: 28px 32px 64px; }

.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; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Buttons and form controls */
.btn {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--text);
  padding: 7px 13px;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.3;
}
.btn:hover { background: #f7f8fa; text-decoration: none; border-color: #c9d0da; }
.btn.primary { background: var(--volt); border-color: var(--volt-deep); color: var(--ink); }
.btn.primary:hover { background: #ffd21f; }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: #f0b8b1; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--blue); padding: 2px 4px; font-weight: 500; }
.btn.link:hover { text-decoration: underline; background: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.icon { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; border-radius: 4px; }
.icon:hover { background: var(--grey-soft); color: var(--text); }

label { display: block; font-size: 13px; font-weight: 600; color: #334155; margin-bottom: 4px; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #c8d0db;
  border-radius: var(--radius);
  background: #fff;
  min-height: 36px;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: var(--blue); }
input:disabled, select:disabled { background: #f1f3f6; color: var(--muted); }
.field { margin-bottom: 14px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.inline-field { display: flex; gap: 8px; align-items: stretch; }
.inline-field select { flex: 1; }

/* Cards and tables */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 18px 20px; margin-bottom: 18px; }
.card > h2, .card-head h2 { margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card.flush { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #f8f9fb;
  white-space: nowrap;
}
table.data td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr.click { cursor: pointer; }
table.data tbody tr.click:hover td { background: #f7f9fc; }
table.data tfoot td { font-weight: 650; background: #f8f9fb; border-top: 1px solid var(--line); }
.num { text-align: right; white-space: nowrap; }
th.num { text-align: right; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 15.5px; margin-bottom: 4px; }
.empty .btn { margin-top: 12px; }
.neg { color: var(--red); }
.pos { color: var(--green); }

/* Status badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--grey-soft); color: #435166; white-space: nowrap; }
.badge.s-sent, .badge.s-partially_paid { background: var(--blue-soft); color: #174d8f; }
.badge.s-paid, .badge.s-accepted { background: var(--green-soft); color: #0b6347; }
.badge.s-overdue, .badge.s-rejected, .badge.s-void { background: var(--red-soft); color: #912018; }
.badge.s-expired { background: var(--amber-soft); color: var(--amber); }
.badge.s-converted { background: var(--volt-soft); color: #7a5d00; }

/* Toolbars and filters */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.toolbar .field { margin: 0; }
.toolbar input[type="search"] { min-width: 240px; }
.toolbar .grow { flex: 1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 13px; padding: 4px 11px; border: 1px solid var(--line); background: #fff; border-radius: 999px; cursor: pointer; color: var(--text); }
.chip:hover { border-color: #b8c2d0; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* KPI strip */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 23px; font-weight: 650; margin-top: 4px; letter-spacing: -0.01em; }
.kpi .note { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi.accent { background: var(--ink); border-color: var(--ink); color: #fff; }
.kpi.accent .label, .kpi.accent .note { color: #aebbd0; }
.kpi.accent .value { color: var(--volt); }
.two-col { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.two-col.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--volt); }

/* Charts */
.chart-legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--sans); font-size: 11.5px; fill: #5d6b7e; }

/* Modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(17, 34, 58, 0.55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3); }
.modal.wide { max-width: 760px; }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; }
.modal footer { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: #f8f9fb; border-radius: 0 0 10px 10px; }
.form-error { color: var(--red); font-size: 13.5px; margin-right: auto; font-weight: 500; }

/* Toasts */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); font-weight: 500; max-width: 360px; border-left: 4px solid var(--volt); }
.toast.error { border-left-color: #ff7b6e; }

/* Document editor */
.editor .items { width: 100%; border-collapse: collapse; margin: 6px 0 10px; }
.editor .items th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 6px 6px; border-bottom: 1px solid var(--line); }
.editor .items td { padding: 6px 4px; vertical-align: top; }
.editor .items input, .editor .items select, .editor .items textarea { min-height: 34px; padding: 6px 8px; }
.editor .items textarea { min-height: 34px; height: 34px; }
.editor .items .num input { text-align: right; }
.editor .items .line-total { padding-top: 14px; font-weight: 600; }
.totals-box { margin-left: auto; width: 320px; max-width: 100%; }
.totals-box .row { display: flex; justify-content: space-between; padding: 6px 0; }
.totals-box .row.grand { border-top: 2px solid var(--ink); margin-top: 4px; padding-top: 10px; font-weight: 700; font-size: 17px; }

/* Document sheet (the printable invoice, quotation or proforma) */
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 20px; align-items: start; }
.sheet {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(17, 34, 58, 0.06), 0 8px 24px rgba(17, 34, 58, 0.06);
  padding: 48px 52px 40px;
  font-family: var(--serif);
  font-size: 14.5px;
  color: #1c2430;
  position: relative;
  min-height: 640px;
}
.sheet::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 6px; background: var(--volt); border-radius: 4px 4px 0 0; }
.sheet .sheet-top { display: flex; justify-content: space-between; gap: 32px; margin-bottom: 34px; }
.sheet .co-name { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.sheet .co-lines { color: #4a5668; white-space: pre-line; font-size: 13.5px; line-height: 1.5; }
.sheet .doc-title { text-align: right; }
.sheet .doc-title h1 { font-family: var(--serif); font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.sheet .doc-title .doc-no { font-size: 15px; margin-top: 4px; color: #4a5668; }
.sheet .meta { display: grid; grid-template-columns: 1.3fr 1fr; gap: 32px; margin-bottom: 28px; }
.sheet .bill-label, .sheet .meta-label { font-family: var(--sans); font-size: 12.5px; color: #6b788b; font-weight: 600; margin-bottom: 4px; }
.sheet .bill-name { font-size: 16px; font-weight: 700; }
.sheet .bill-lines { white-space: pre-line; color: #3b4658; font-size: 13.5px; line-height: 1.5; }
.sheet dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 18px; font-size: 13.5px; }
.sheet dt { color: #6b788b; font-family: var(--sans); font-size: 13px; }
.sheet dd { margin: 0; text-align: right; font-weight: 600; }
.sheet table.lines { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.sheet table.lines th { font-family: var(--sans); font-size: 12.5px; font-weight: 600; color: #4a5668; text-align: left; padding: 8px 8px; border-top: 2px solid var(--ink); border-bottom: 1px solid #b9c2cf; }
.sheet table.lines th.num { text-align: right; }
.sheet table.lines td { padding: 9px 8px; border-bottom: 1px solid #e3e7ee; vertical-align: top; }
.sheet table.lines td.desc { width: 42%; }
.sheet .sum { margin-left: auto; width: 290px; max-width: 100%; font-size: 14px; }
.sheet .sum .row { display: flex; justify-content: space-between; padding: 5px 8px; }
.sheet .sum .row.total { border-top: 2px solid var(--ink); font-weight: 700; font-size: 16px; padding-top: 9px; margin-top: 3px; }
.sheet .sum .row.due { background: var(--volt-soft); font-weight: 700; font-size: 16px; border-radius: 3px; margin-top: 6px; padding: 9px 8px; }
.sheet .fx { font-size: 12.5px; color: #6b788b; text-align: right; margin-top: 6px; font-family: var(--sans); }
.sheet .blocks { margin-top: 30px; display: grid; gap: 18px; font-size: 13.5px; }
.sheet .blocks .label { font-family: var(--sans); font-size: 12.5px; color: #6b788b; font-weight: 600; margin-bottom: 3px; }
.sheet .blocks .body { white-space: pre-line; color: #3b4658; }
.stamp { position: absolute; right: 52px; top: 150px; border: 3px solid currentColor; color: var(--green); font-family: var(--sans); font-weight: 800; font-size: 26px; letter-spacing: 0.06em; padding: 2px 14px; transform: rotate(-9deg); border-radius: 4px; opacity: 0.8; pointer-events: none; }
.stamp.void { color: var(--red); }
.side-panel .card { padding: 14px 16px; }
.side-panel h3 { margin-bottom: 8px; }
.side-panel .stack { display: grid; gap: 8px; }
.side-panel .btn { justify-content: center; width: 100%; }
.pay-row { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: 13.5px; }
.pay-row:last-child { border-bottom: 0; }
.link-row { font-size: 13.5px; margin-bottom: 6px; }

.pnl td, .pnl th { padding: 8px 12px; }
.pnl .section td { font-weight: 650; background: #f4f6f9; }
.pnl .indent td:first-child { padding-left: 28px; }
.pnl .total td { font-weight: 700; border-top: 1px solid #b9c2cf; }
.pnl .net td { font-weight: 700; background: var(--volt-soft); border-top: 2px solid var(--ink); }
.pnl td.num, .pnl th.num { min-width: 96px; }
.range-note { font-size: 13px; color: var(--muted); margin: -6px 0 14px; }

.loading { padding: 60px; text-align: center; color: var(--muted); }
.error-box { background: var(--red-soft); color: #912018; border: 1px solid #f0b8b1; padding: 14px 16px; border-radius: 8px; }

@media (max-width: 1000px) {
  .doc-layout, .two-col, .two-col.even { grid-template-columns: 1fr; }
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: column; padding: 10px; }
  .brand { padding-bottom: 8px; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav a { border-left: 0; border-bottom: 3px solid transparent; padding: 6px 9px; font-size: 13.5px; }
  .nav a.active { border-bottom-color: var(--volt); }
  .nav-group, .nav-spacer { display: none; }
  .view { padding: 18px 14px 48px; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .sheet { padding: 28px 18px; }
  .sheet .sheet-top, .sheet .meta { grid-template-columns: 1fr; flex-direction: column; }
  .sheet .doc-title { text-align: left; }
  .stamp { right: 16px; top: 100px; font-size: 20px; }
}

@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 12px; }
  .sidebar, .no-print, .toasts, .page-head .actions, .side-panel, .tabs, .toolbar, .modal-wrap { display: none !important; }
  .shell { display: block; }
  .view { max-width: none; padding: 0; }
  .doc-layout { display: block; }
  .sheet { border: 0; box-shadow: none; padding: 0; min-height: 0; }
  .sheet::before { display: none; }
  .card { border: 0; padding: 0; }
  .card.flush { overflow: visible; }
  table.data th { background: #fff; }
  .pnl .net td, .sheet .sum .row.due { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (prefers-reduced-motion: no-preference) {
  .modal { animation: pop 0.14s ease-out; }
  @keyframes pop { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

table.data td:first-child a[href^="#/doc/"] { white-space: nowrap; }
.pay-row > div { min-width: 0; }
.pay-row strong { white-space: nowrap; }
.pay-row .btn.link { align-self: flex-start; flex: none; }
.pnl th:first-child, .pnl td:first-child { position: sticky; left: 0; white-space: nowrap; min-width: 210px; z-index: 1; background: #fff; }
.pnl thead th:first-child { background: #f8f9fb; }
.pnl .section td:first-child { background: #f4f6f9; }
.pnl .net td:first-child { background: var(--volt-soft); }

table.data th.num { text-align: right; }
