/* Menu down the left, content filling the rest.
   --brand comes from the reseller (white label), set inline on <body>. */
:root {
  --brand: #F87C18;
  --ink: #172333;
  --nav: #151D2C;
  --nav-text: #C2CBDA;
  --nav-line: #2B3648;
  --bg: #F5F7F9;
  --surface: #FFFFFF;
  --line: #E0E4E8;
  --copy: #4C5766;
  --muted: #7B8594;
  --ok: #1E6B2C; --ok-bg: #E9F5EA;
  --warn: #8A4408; --warn-bg: #FFF1E3;
  --bad: #9A2E1F; --bad-bg: #FBEDEA;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; color: var(--copy); background: var(--bg); }
a { color: var(--ink); }
h1, h2, h3 { color: var(--ink); margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
h3 { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
code { font-family: var(--mono); font-size: 12px; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.nav { width: 230px; flex-shrink: 0; background: var(--nav); color: var(--nav-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.nav .brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 15px; }
.nav .brand img { max-height: 28px; max-width: 150px; }
.nav .brand .dot { width: 22px; height: 22px; border-radius: 6px; background: var(--brand); flex-shrink: 0; }
.nav .org { margin: 0 12px 10px; padding: 9px 10px; border: 1px solid var(--nav-line); border-radius: var(--radius); color: #fff; text-decoration: none; display: block; font-size: 13px; }
.nav .org small { display: block; color: var(--nav-text); font-size: 11px; }
.nav .org:hover { border-color: var(--brand); }
.nav .group { padding: 12px 18px 4px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: #8590A3; }
.nav a.item { display: block; padding: 7px 18px 7px 22px; color: var(--nav-text); text-decoration: none; font-size: 13.5px; border-left: 3px solid transparent; }
.nav a.item:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav a.item.on { color: #fff; background: rgba(255,255,255,.08); border-left-color: var(--brand); }
.nav .bottom { margin-top: auto; border-top: 1px solid var(--nav-line); padding: 10px 0 14px; }
.nav .bottom form { margin: 0; }
.nav .bottom button { background: none; border: 0; color: var(--nav-text); padding: 7px 18px 7px 22px; font: inherit; font-size: 13px; cursor: pointer; width: 100%; text-align: left; }
.nav .bottom button:hover { color: #fff; }
.nav .who { padding: 4px 22px; font-size: 12px; color: #8590A3; word-break: break-all; }
.main { flex: 1; min-width: 0; padding: 26px 34px 60px; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head .sub { color: var(--muted); margin-top: 4px; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 20px 0; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; display: block; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat .n { font-size: 22px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); }
.stat .s.bad { color: var(--bad); }
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: #CFE9D2; }
.flash.error { background: var(--bad-bg); color: var(--bad); border-color: #F2CFC8; }
.note { font-size: 12.5px; color: var(--muted); }
.muted { color: var(--muted); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- tables ---------- */
table.t { width: 100%; border-collapse: collapse; background: var(--surface); }
table.t th, table.t td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.t th { font-size: 12px; font-weight: 600; color: var(--muted); background: #FAFBFC; white-space: nowrap; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover td { background: #FAFBFC; }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tr.total td { font-weight: 600; color: var(--ink); border-top: 2px solid var(--line); background: #FAFBFC; }
table.t tr.sub td { font-weight: 600; color: var(--ink); }
table.t tr.section td { background: #FAFBFC; font-weight: 600; color: var(--ink); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
table.t td.indent { padding-left: 28px; }
table.t a { text-decoration: none; }
table.t a:hover { text-decoration: underline; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 13.5px; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
.tabs a .c { font-size: 11px; background: #EEF0F3; border-radius: 10px; padding: 1px 7px; margin-left: 4px; }

/* ---------- badges ---------- */
.badge { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 10px; border: 1px solid var(--line); background: #F3F5F7; color: var(--copy); white-space: nowrap; }
.badge.draft { background: #F3F5F7; }
.badge.approved { background: var(--warn-bg); color: var(--warn); border-color: #F3D9BC; }
.badge.overdue, .badge.failed, .badge.void { background: var(--bad-bg); color: var(--bad); border-color: #F2CFC8; }
.badge.paid, .badge.ok, .badge.posted { background: var(--ok-bg); color: var(--ok); border-color: #CFE9D2; }
.badge.running { background: var(--warn-bg); color: var(--warn); }
.badge.void { text-decoration: line-through; }

/* ---------- forms ---------- */
.btn { display: inline-block; font: inherit; font-weight: 600; font-size: 13.5px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--brand); background: var(--brand); color: #fff; text-decoration: none; cursor: pointer; line-height: 1.3; }
.btn:hover { filter: brightness(1.05); }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { border-color: #C5CBD3; }
.btn.danger { background: var(--surface); color: var(--bad); border-color: #F2CFC8; }
.btn.small { padding: 4px 9px; font-size: 12.5px; font-weight: 500; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  font: inherit; font-size: 14px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: 6px; font-weight: 500; }
.check input { width: auto; }
.form-grid { display: grid; gap: 14px 18px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }
.field { margin-bottom: 14px; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin: 0; }
.inline-form input, .inline-form select { width: auto; }
fieldset { border: 0; padding: 0; margin: 0; }

/* ---------- document editor ---------- */
table.lines { width: 100%; border-collapse: collapse; }
table.lines th { font-size: 12px; color: var(--muted); text-align: left; padding: 6px 4px; font-weight: 600; }
table.lines td { padding: 4px; vertical-align: top; }
table.lines input, table.lines select { padding: 6px 8px; font-size: 13.5px; }
table.lines td.amt { text-align: right; padding-top: 10px; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink); }
table.lines .rm { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 6px; }
table.lines .rm:hover { color: var(--bad); }
.totals { margin-left: auto; width: 320px; max-width: 100%; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 17px; font-weight: 700; color: var(--ink); border-top: 2px solid var(--line); padding-top: 8px; margin-top: 4px; }
.doc-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px 24px; }
.doc-meta .k { font-size: 12px; color: var(--muted); }
.doc-meta .v { color: var(--ink); font-weight: 500; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--nav); }
.login .box { background: var(--surface); width: 360px; max-width: 100%; border-radius: 12px; padding: 30px 28px; }
.login .mark { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); margin-bottom: 14px; }
.login h1 { margin-bottom: 18px; }
.login .btn { width: 100%; padding: 10px; }

pre.log { background: #14201B; color: #D7E7DD; font-family: var(--mono); font-size: 12px; padding: 12px 14px; border-radius: 6px; max-height: 340px; overflow: auto; white-space: pre-wrap; word-break: break-word; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .nav { width: 100%; height: auto; position: static; }
  .main { padding: 18px 14px 40px; }
  table.lines thead { display: none; }
  table.lines tr { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); padding: 6px 0; }
  table.lines td:first-child { grid-column: 1 / -1; }
}
@media print {
  .nav, .actions, .no-print { display: none !important; }
  .main { padding: 0; }
  .card { border: 0; }
  body { background: #fff; }
}
