:root {
  --blue: #0599e3;
  --blue-dark: #0274b3;
  --blue-soft: #e6f4fc;
  --orange: #f7941d;
  --ink: #17212b;
  --muted: #5d6b7a;
  --line: #e2e7ee;
  --bg: #f3f5f9;
  --card: #fff;
  --good: #14804a;
  --good-soft: #e3f5ea;
  --bad: #c0362c;
  --bad-soft: #fdecea;
  --warn-soft: #fff3df;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(23, 33, 43, .05), 0 4px 14px rgba(23, 33, 43, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
h1 { font-size: 26px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 13px/1.4 Consolas, "Courier New", monospace; background: #eef1f5; padding: 2px 6px; border-radius: 5px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; width: 100%; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.bad { color: var(--bad); }
.good { color: var(--good); }
.big { font-size: 22px; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--card); border-right: 1px solid var(--line);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand img { display: block; width: 150px; height: auto; margin: 0 auto; }
.side nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.side nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 9px;
  color: var(--ink); font-weight: 500;
}
.side nav a:hover { background: var(--bg); text-decoration: none; }
.side nav a.on { background: var(--blue-soft); color: var(--blue-dark); font-weight: 600; }
.side-foot { margin-top: auto; padding: 12px 6px 0; border-top: 1px solid var(--line); }
.who { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.main { padding: 28px clamp(16px, 3vw, 40px) 60px; max-width: 1280px; width: 100%; }
.bare { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.narrow { max-width: 780px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; gap: 8px; }
  .brand img { width: 96px; }
  .side .btn-block { width: auto; }
  .side nav { flex-direction: row; flex-wrap: wrap; margin: 0; width: 100%; order: 5; }
  .side nav a { padding: 7px 9px; font-size: 14px; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .who { display: none; }
}

/* ---------- buttons, forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 15px; border-radius: 999px; border: 1px solid #c9d2dd; background: #fff;
  color: var(--ink); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f6f8fb; text-decoration: none; border-color: #aab6c4; }
.btn-primary { background: var(--blue-dark); border-color: var(--blue-dark); color: #fff; }
.btn-primary:hover { background: #025f93; border-color: #025f93; }
.btn-block { display: flex; width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--blue-dark); font: inherit; font-size: 14px; cursor: pointer; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--bad); }
.link.armed { font-weight: 700; }
.icon { background: none; border: 0; cursor: pointer; font-size: 18px; line-height: 1; color: var(--muted); padding: 4px 6px; border-radius: 6px; }
.icon:hover { background: var(--bg); color: var(--ink); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

label { display: block; font-size: 13px; font-weight: 600; color: #3a4654; margin-bottom: 12px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid #c5ced9; border-radius: 8px; padding: 8px 10px; width: 100%; margin-top: 4px;
}
label.inline input, label.check input, .filters input, .filters select { width: auto; margin-top: 0; }
input[type=checkbox] { width: 16px; height: 16px; }
input[type=file] { padding: 6px; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: var(--blue); }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
.hint { display: block; font-size: 12.5px; font-weight: 400; color: var(--muted); margin: 4px 0 0; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
@media (max-width: 640px) { .row-2, .row-3 { grid-template-columns: 1fr; } }
.stack > * { margin-bottom: 10px; }
.stack > *:last-child { margin-bottom: 0; }

/* ---------- common blocks ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden; }
.pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; }
.card-head a { font-size: 13px; font-weight: 600; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.back { display: inline-block; font-size: 13px; margin-bottom: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions.end { justify-content: flex-end; }
.empty { text-align: center; padding: 34px 20px; color: var(--muted); }
.flash { padding: 11px 15px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.flash ul { margin: 6px 0 0; padding-left: 20px; font-weight: 400; }
.flash-ok { background: var(--good-soft); color: #0d5c34; border: 1px solid #b9e3c9; }
.flash-err { background: var(--bad-soft); color: #8f241c; border: 1px solid #f3c4bf; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; max-width: 420px; background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); margin-top: 8px; }
.toast-err { background: #8f241c; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.badge-draft, .badge-unsent { background: #eceff3; color: #47525f; }
.badge-sent { background: var(--blue-soft); color: #02588a; }
.badge-partial { background: var(--warn-soft); color: #8a5300; }
.badge-paid { background: var(--good-soft); color: #0d5c34; }
.badge-overdue { background: var(--bad-soft); color: #8f241c; }
.pill { display: inline-block; min-width: 22px; text-align: center; padding: 0 7px; border-radius: 999px; background: rgba(23, 33, 43, .09); font-size: 12px; font-weight: 700; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid #eef1f5; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-link tbody tr { cursor: pointer; }
.table-link td { white-space: nowrap; }
.table-link td.wrap { white-space: normal; }
.table-link tbody tr:hover { background: #f7f9fc; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 14px; border-top: 1px solid var(--line); }

/* ---------- dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { display: flex; flex-direction: column; gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; color: var(--ink); border-top: 3px solid var(--blue); }
a.kpi:hover { text-decoration: none; border-color: #c9d6e4; border-top-color: var(--blue); transform: translateY(-1px); }
.kpi-bad { border-top-color: var(--bad); }
.kpi-bad .kpi-value { color: var(--bad); }
.kpi-good { border-top-color: var(--good); }
.kpi-label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.kpi-value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.25; }
.kpi-sub { font-size: 13px; color: var(--muted); }
@media (max-width: 1000px) { .kpis, .kpis-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .kpis, .kpis-3 { grid-template-columns: 1fr; } }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.grid-2 + .grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 1280px) { .grid-2 + .grid-2 { grid-template-columns: 1fr; gap: 0; } }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; gap: 0; } }

.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: #e8ecf1; stroke-width: 1; }
.chart .axis { font-size: 11px; fill: var(--muted); }
.chart .bar-a { fill: var(--blue); }
.chart .bar-b { fill: var(--orange); }
.chart g:hover .bar-a, .chart g:hover .bar-b { opacity: .8; }
.legend { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 8px; }
.dot-a { background: var(--blue); }
.dot-b { background: var(--orange); }

.owes { list-style: none; margin: 0; padding: 6px 0; }
.owes a { display: block; padding: 10px 20px; color: var(--ink); }
.owes a:hover { background: #f7f9fc; text-decoration: none; }
.owes-top { display: flex; justify-content: space-between; gap: 10px; font-variant-numeric: tabular-nums; }
.owes-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.owes-sub { font-size: 12.5px; color: var(--muted); }
.meter { position: relative; display: block; height: 7px; background: #edf0f4; border-radius: 99px; margin: 6px 0 4px; overflow: hidden; }
.meter-fill, .meter-over { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; }
.meter-fill { background: var(--blue); }
.meter-over { background: var(--bad); }

/* ---------- invoices list ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters select { max-width: 260px; }
.tabs { display: inline-flex; gap: 2px; background: #e6eaf0; border-radius: 999px; padding: 4px; margin-bottom: 14px; }
.tabs a { padding: 6px 16px; border-radius: 999px; color: var(--ink); font-weight: 600; font-size: 14px; }
.tabs a:hover { text-decoration: none; background: rgba(255, 255, 255, .55); }
.tabs a.on { background: #fff; box-shadow: 0 1px 3px rgba(23, 33, 43, .15); color: var(--blue-dark); }

/* ---------- invoice editor ---------- */
.form-top { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 30px; }
@media (max-width: 760px) { .form-top { grid-template-columns: 1fr; gap: 6px; } }
.billto { font-size: 14px; line-height: 1.45; margin: 2px 0 8px; min-height: 20px; }
.items td { vertical-align: top; padding: 8px 6px; }
.items th { padding: 10px 6px; }
.items input, .items select { margin-top: 0; }
.items .col-drag { width: 34px; padding-left: 12px; }
.items .col-qty { width: 96px; min-width: 96px; }
.items .col-price { width: 122px; min-width: 122px; }
.items .col-tax { width: 128px; min-width: 128px; }
.items .col-amt { width: 112px; padding-top: 16px; padding-right: 10px; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.items td:nth-child(2) { min-width: 200px; }
.items td:nth-child(3) { min-width: 180px; }
.items-foot { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; border-top: 1px solid var(--line); }
.totals { min-width: 290px; margin-left: auto; }
.totals > div { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 5px 0; font-variant-numeric: tabular-nums; }
.totals label { margin: 0; font-weight: 400; font-size: 15px; color: var(--ink); }
.totals input { width: 120px; margin: 0; }
.totals .grand { border-top: 2px solid var(--line); margin-top: 6px; padding-top: 10px; font-size: 18px; }

/* ---------- invoice page ---------- */
.summary { display: flex; flex-wrap: wrap; gap: 14px 46px; align-items: flex-start; }
.summary .kpi-label { margin-bottom: 3px; }
.invoice-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1100px) { .invoice-layout { grid-template-columns: 1fr; } }
.step h2 { margin-bottom: 6px; }
.plain { list-style: none; margin: 0 0 12px; padding: 0; }
.payments li { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid #eef1f5; word-break: break-word; }
.dialog { border: 0; border-radius: 14px; padding: 22px 24px; width: min(560px, calc(100vw - 28px)); box-shadow: 0 20px 60px rgba(23, 33, 43, .3); color: var(--ink); }
.dialog::backdrop { background: rgba(23, 33, 43, .45); }
.send-options { display: flex; gap: 8px; flex-wrap: wrap; }

/* The invoice as it looks on paper. Sized in em so it scales with its container. */
.invoice-paper-wrap { overflow-x: auto; }
.paper { background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); width: 100%; min-width: 620px; max-width: 850px; margin: 0 auto 18px; padding: 34px 0 44px; font-size: 14px; line-height: 1.38; color: #000; }
.paper-top { display: flex; justify-content: space-between; gap: 20px; padding: 0 30px 22px 40px; border-bottom: 1px solid #dfe2e5; }
.paper-logo { width: 245px; height: auto; align-self: flex-start; }
.paper-biz { text-align: right; }
.paper-title { font-size: 42px; line-height: 1; letter-spacing: .01em; }
.paper-sub { color: #8d9499; margin-top: 4px; }
.paper-bizname { font-weight: 700; margin-top: 18px; }
.paper-phone { margin-top: 16px; }
.paper-meta { display: flex; justify-content: space-between; gap: 20px; padding: 22px 30px 26px; }
.paper-label { color: #8d9499; }
.paper-facts { border-collapse: collapse; align-self: flex-start; }
.paper-facts th { text-align: right; padding: 3px 12px 3px 20px; font-weight: 700; white-space: nowrap; }
.paper-facts td { padding: 3px 0; min-width: 150px; }
.paper-due th, .paper-due td { background: #f3f5f5; padding-top: 4px; padding-bottom: 4px; }
.paper-items { width: 100%; border-collapse: collapse; border-bottom: 2px solid #dfe2e5; }
.paper-items th { background: var(--blue); color: #fff; text-align: left; padding: 10px 30px; font-weight: 700; }
.paper-items td { padding: 10px 30px 4px; vertical-align: top; }
.paper-items tr:last-child td { padding-bottom: 10px; }
.paper-items .c { text-align: center; }
.paper-items .r { text-align: right; white-space: nowrap; }
.paper-tax { color: #5d6468; font-size: 13px; }
.paper-totals { margin: 18px 30px 0 auto; border-collapse: collapse; }
.paper-totals th { text-align: right; font-weight: 400; padding: 5px 40px 5px 20px; }
.paper-totals td { text-align: right; padding: 5px 0; min-width: 110px; }
.paper-totals tr:first-child th, .paper-grand th { font-weight: 700; }
.paper-grand th, .paper-grand td { border-top: 2px solid #dfe2e5; padding-top: 12px; font-weight: 700; }
.paper-notes { padding: 44px 30px 0; color: #5d6468; line-height: 1.6; }
.paper-notes b { color: #4b5357; }
.paper-footer { padding: 30px 30px 0; text-align: center; color: #5d6468; font-size: 13px; }

/* ---------- settings ---------- */
.tax-row { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.tax-row input { margin: 0; width: 220px; }
.suffix { display: inline-flex; align-items: center; gap: 6px; }
.suffix input { width: 90px; }
.sub { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }

/* ---------- sign in / setup ---------- */
.auth { width: min(430px, 100%); }
.auth h1 { font-size: 22px; margin-bottom: 8px; }
.auth form { margin-top: 14px; }
.auth-logo { display: block; width: 190px; margin: 0 auto 14px; }
.code-input { font-size: 24px; letter-spacing: .28em; text-align: center; font-variant-numeric: tabular-nums; }
.qr { display: grid; place-items: center; margin: 10px 0 12px; }
.qr canvas { border: 1px solid var(--line); border-radius: 8px; max-width: 100%; height: auto; }
.steps { padding-left: 20px; margin: 10px 0; }
.codes { font: 17px/1.7 Consolas, "Courier New", monospace; background: #f3f5f9; border: 1px dashed #b9c3cf; border-radius: 10px; padding: 14px 18px; columns: 2; margin: 12px 0 16px; }

/* ---------- customer link page ---------- */
.public { background: var(--bg); }
.public-bar { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; max-width: 850px; margin: 0 auto; padding: 18px 12px; }
.public-paper { padding: 0 12px; }
.public-attachments { max-width: 850px; margin: 0 auto 40px; padding: 0 12px; display: flex; gap: 12px; flex-wrap: wrap; }

@media print {
  .side, .page-head, .invoice-side, .summary, .public-bar, .flash, .public-attachments { display: none !important; }
  .shell, .invoice-layout { display: block; }
  .main { padding: 0; }
  .paper { border: 0; box-shadow: none; }
}

.th-select { width: auto; margin: 0; padding: 3px 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
