:root {
  --ink: #141414; --ink-2: #4a4a45; --muted: #7a7a72; --line: #e3e3dc; --bg: #f5f5f0; --card: #fff;
  --olive: #6b7a2a; --olive-d: #4d5a1c; --olive-l: #eef2d9; --black: #111;
  --bad: #b3261e; --bad-l: #fce9e7; --warn: #8a5a00; --warn-l: #fff3d6; --ok: #2f6b2f; --ok-l: #e5f3e1;
  --radius: 10px; --side: 232px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
body.modal-open { overflow: hidden; }
h1 { font-size: 1.6rem; margin: 0; line-height: 1.2; }
h3 { margin: 0 0 .5rem; font-size: 1.05rem; }
h4 { margin: 0 0 .35rem; font-size: .8rem; letter-spacing: .06em; color: var(--ink-2); }
a { color: var(--olive-d); }
.small { font-size: .85rem; } .muted { color: var(--muted); } .right { text-align: right; } .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mt { margin-top: 1rem; } .pad { padding: 1.1rem 1.25rem; } .warn-text { color: var(--warn); font-weight: 600; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--side); background: var(--black); color: #fff; display: flex; flex-direction: column; padding: 1rem .75rem; z-index: 20; }
.brand { display: flex; gap: .65rem; align-items: center; padding: .25rem .5rem 1rem; border-bottom: 1px solid #2a2a2a; margin-bottom: .75rem; }
.brand img { border-radius: 8px; }
.brand b { display: block; font-size: 1rem; } .brand small { color: #a9ad95; font-size: .75rem; }
#nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
#nav a { color: #d7d9cc; text-decoration: none; padding: .6rem .75rem; border-radius: 8px; display: flex; gap: .65rem; align-items: center; font-size: .95rem; }
#nav a:hover { background: #222; }
#nav a.active { background: var(--olive); color: #fff; font-weight: 600; }
#nav .ico { width: 1.3rem; text-align: center; }
.side-user { margin-top: auto; padding: .75rem .5rem; border-top: 1px solid #2a2a2a; font-size: .8rem; color: #c3c6b4; display: grid; gap: .35rem; }
.side-user .link-btn { color: #cfd6a3; text-align: left; padding: 0; width: fit-content; }
.sync { display: flex; align-items: center; gap: .45rem; font-size: .75rem; color: #a9ad95; } .sync i { width: 8px; height: 8px; border-radius: 50%; background: #7fae4a; }
.sync.saving i { background: #e0b341; } .sync.error i, .sync.conflict i { background: #e5584d; }
.side-foot { padding-top: .25rem; padding: .75rem .5rem 0; font-size: .75rem; color: #7d806c; }
.topbar { display: none; position: sticky; top: 0; z-index: 15; background: var(--black); color: #fff; padding: .55rem .75rem; align-items: center; gap: .6rem; padding-top: max(.55rem, env(safe-area-inset-top)); }
.topbar .icon-btn { color: #fff; font-size: 1.4rem; }
.content { margin-left: var(--side); padding: 1.5rem 1.75rem 4rem; max-width: 1180px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.sub { margin: .25rem 0 0; color: var(--muted); }
.back { font-size: .85rem; text-decoration: none; display: inline-block; margin-bottom: .25rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.between { display: flex; justify-content: space-between; align-items: center; gap: .75rem; } .between.wrap { flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem .2rem; }
.card-head h3 { margin: 0; }
.two-col { display: grid; grid-template-columns: 1.25fr 1fr; gap: 1rem; }

/* ---------- controls ---------- */
.btn { font: inherit; border: 1px solid #c9c9bf; background: #fff; color: var(--ink); padding: .5rem .95rem; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; min-height: 38px; }
.btn:hover { background: #f1f1ea; }
.btn.primary { background: var(--olive); border-color: var(--olive); color: #fff; font-weight: 600; } .btn.primary:hover { background: var(--olive-d); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-outline { color: var(--bad); border-color: #e3b5b1; } .btn.danger-outline:hover { background: var(--bad-l); }
.btn.small { padding: .25rem .65rem; min-height: 30px; font-size: .85rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { background: none; border: 0; font-size: 1.35rem; line-height: 1; cursor: pointer; color: var(--ink-2); padding: .25rem .5rem; border-radius: 6px; } .icon-btn:hover { background: #0000000d; }
.link-btn { background: none; border: 0; color: var(--olive-d); cursor: pointer; text-decoration: underline; padding: 0 .25rem; font: inherit; }
input, select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid #c9c9bf; border-radius: 8px; background: #fff; color: var(--ink); width: 100%; min-height: 38px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--olive); outline-offset: 1px; }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--ink-2); font-weight: 600; }
label.inline { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; white-space: nowrap; } label.inline input, label.inline select { width: auto; }
label.check { flex-direction: row; align-items: center; gap: .5rem; align-self: end; min-height: 38px; } label.check input { width: auto; min-height: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .85rem 1rem; } .form-grid .span2 { grid-column: span 2; }
.toolbar { display: flex; gap: .6rem; margin-bottom: .9rem; flex-wrap: wrap; } .toolbar select, .toolbar input[type=search] { width: auto; min-width: 170px; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { font: inherit; border: 0; background: none; padding: .6rem 1rem; cursor: pointer; border-bottom: 3px solid transparent; color: var(--ink-2); white-space: nowrap; }
.tabs button.active { border-color: var(--olive); color: var(--ink); font-weight: 600; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .65rem .85rem; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafaf6; }
table.grid td { padding: .6rem .85rem; border-bottom: 1px solid #efefe8; vertical-align: top; }
table.grid th.num, table.grid td.num { text-align: right; }
table.grid.clickable tbody tr { cursor: pointer; } table.grid.clickable tbody tr:hover { background: var(--olive-l); }
table.grid.compact td, table.grid.compact th { padding: .4rem .7rem; }
table.grid td input, table.grid td select { min-height: 34px; padding: .3rem .5rem; }
table.lines td { padding: .35rem .4rem; }
table.grid tr.total-row td { font-weight: 700; background: #fafaf6; border-top: 2px solid var(--line); }
.empty { text-align: center; color: var(--muted); padding: 1.6rem !important; }
.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px; white-space: nowrap; vertical-align: middle; }
.pill.ok { background: var(--ok-l); color: var(--ok); } .pill.bad { background: var(--bad-l); color: var(--bad); } .pill.warn { background: var(--warn-l); color: var(--warn); } .pill.muted { background: #ececE4; color: var(--ink-2); }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; border-top: 4px solid var(--black); }
.stat span { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; } .stat b { display: block; font-size: 1.45rem; margin: .15rem 0; font-variant-numeric: tabular-nums; } .stat small { color: var(--muted); }
.stat.bad { border-top-color: var(--bad); } .stat.bad b { color: var(--bad); } .stat.ok { border-top-color: var(--olive); }

/* ---------- invoice editor ---------- */
.trip-adder { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; background: var(--olive-l); padding: .6rem .75rem; border-radius: 8px; margin-bottom: .8rem; }
.trip-adder input { width: auto; } .grand-total { font-size: 1.1rem; } .grand-total b { margin-left: .5rem; font-size: 1.3rem; }
.alloc-sum { margin: .6rem 0 0; padding: .55rem .75rem; background: var(--olive-l); border-radius: 8px; } .alloc-sum.bad { background: var(--bad-l); color: var(--bad); }

/* ---------- documents (invoice / statement) ---------- */
.doc-wrap { padding: 1.25rem; overflow-x: auto; }
.doc { background: #fff; color: #000; max-width: 820px; margin: 0 auto; font-size: 13.5px; }
.doc-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 3px solid #111; padding-bottom: .5rem; margin-bottom: 1rem; gap: 1rem; }
.doc-head h2 { margin: 0; font-size: 1.5rem; letter-spacing: .02em; }
.doc-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.25rem; } .doc-cols p { margin: 0; line-height: 1.5; } .doc-cols .small { margin-top: .5rem; }
.doc-table { width: 100%; border-collapse: collapse; margin-bottom: .5rem; }
.doc-table th { background: #111; color: #fff; text-align: left; padding: .4rem .6rem; font-size: .75rem; letter-spacing: .05em; }
.doc-table td { padding: .35rem .6rem; border-bottom: 1px solid #ddd; }
.doc-table .num { text-align: right; } .doc-table tr.muted-row td { background: #f3f3f3; font-style: italic; }
.doc-table.ageing { margin-top: 1rem; } .doc-table.ageing th { background: #e8ecd2; color: #111; text-align: right; }
.doc-totals { margin: .5rem 0 1rem auto; width: 300px; } .doc-totals div { display: flex; justify-content: space-between; padding: .25rem .6rem; }
.doc-totals .grand { background: #dde5b6; font-weight: 700; font-size: 1.05rem; border-top: 2px solid #111; padding: .45rem .6rem; }
.doc-foot { margin-top: 1.25rem; border-top: 1px solid #ccc; padding-top: .75rem; } .doc-foot p { margin: .3rem 0; } .doc-bank p { margin: 0 0 .5rem; line-height: 1.5; }

/* ---------- waybills ---------- */
.dropzone { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; border: 2px dashed #b8bf95; background: #fbfcf4; border-radius: var(--radius); padding: 1.1rem 1.25rem; transition: .15s; }
.dropzone.over { background: var(--olive-l); border-color: var(--olive); } .dropzone.busy { opacity: .6; pointer-events: none; }
.dz-icon { font-size: 1.6rem; color: var(--olive); }
.dropzone > div:nth-child(2) { flex: 1; min-width: 220px; }
.checks { list-style: none; padding: 0; margin: .9rem 0 0; display: grid; gap: .25rem; } .checks li { padding: .3rem .6rem; border-radius: 6px; font-size: .9rem; } .checks li.ok { background: var(--ok-l); color: var(--ok); } .checks li.bad { background: var(--bad-l); color: var(--bad); }
details summary { cursor: pointer; font-weight: 600; color: var(--olive-d); }
.chips { display: flex; gap: .6rem; flex-wrap: wrap; margin: .7rem 0 .4rem; }
.chip { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; padding: .5rem .8rem .6rem; min-width: 150px; background: #fafaf6; }
.chip b { display: block; } .chip span { font-size: .8rem; color: var(--muted); } .chip i { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--olive); }
.chip.over { background: var(--bad-l); border-color: #e3b5b1; } .chip.over i { background: var(--bad); } .chip.warn { background: var(--warn-l); }
.actions-bar { display: flex; gap: .6rem; flex-wrap: wrap; }
.group-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .8rem 1.1rem; background: var(--olive-l); border-radius: var(--radius) var(--radius) 0 0; flex-wrap: wrap; }
.group-head h3 { display: inline; margin-right: .5rem; } .group-head select { min-width: 190px; }

/* ---------- modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: #000a; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 480px; box-shadow: 0 20px 60px #0006; } .modal.wide { max-width: 760px; }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.2rem; border-bottom: 1px solid var(--line); } .modal header h3 { margin: 0; }
.modal-body { padding: 1.1rem 1.2rem; } .modal footer { padding: .8rem 1.2rem; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; }
#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: grid; gap: .5rem; z-index: 200; width: min(92vw, 420px); }
.toast { background: var(--black); color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: 0 6px 20px #0004; transition: .4s; } .toast.ok { background: var(--olive-d); } .toast.warn { background: #7a4b00; } .toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- print ---------- */
#print-area { display: none; }
@media print {
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  .doc { max-width: none; font-size: 12px; } .page-break { page-break-after: always; } .page-break:last-child { page-break-after: auto; }
  .doc-head, .doc-table th, .doc-totals .grand, .doc-table.ageing th, .doc-table tr.muted-row td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { size: A4; margin: 14mm; }
}

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .topbar { display: flex; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; top: 0; padding-top: max(1rem, env(safe-area-inset-top)); }
  .sidebar:has(#nav.open) { transform: none; box-shadow: 0 0 40px #0008; }
  .content { margin-left: 0; padding: 1rem .9rem 4rem; }
  .two-col { grid-template-columns: 1fr; } .doc-cols { grid-template-columns: 1fr; gap: .75rem; }
  .form-grid .span2 { grid-column: auto; } h1 { font-size: 1.35rem; }
  .doc-totals { width: 100%; } .doc-wrap { padding: .6rem; }
  .stats { grid-template-columns: 1fr 1fr; gap: .6rem; } .stat { padding: .75rem .8rem; } .stat b { font-size: 1.1rem; }
  .modal-back { padding: 0; align-items: flex-end; } .modal, .modal.wide { max-width: none; border-radius: 14px 14px 0 0; max-height: 94vh; overflow-y: auto; }
}

/* ---------- sign-in screen ---------- */
body.locked { overflow: hidden; }
#auth-root { position: fixed; inset: 0; z-index: 300; background: radial-gradient(1200px 600px at 20% -10%, #2b3310 0%, #111 55%); display: flex; align-items: center; justify-content: center; padding: 1rem; overflow-y: auto; }
.auth-card { background: #fff; width: 100%; max-width: 400px; border-radius: 16px; padding: 1.75rem 1.5rem 1.5rem; box-shadow: 0 30px 80px #000a; text-align: center; }
.auth-card img { border-radius: 14px; }
.auth-card h1 { font-size: 1.4rem; margin: .6rem 0 .25rem; }
.auth-sub { color: var(--muted); margin: 0 0 1rem; font-size: .92rem; }
.auth-card form { display: grid; gap: .85rem; text-align: left; }
.auth-card small { font-weight: 400; color: var(--muted); }
.auth-card .pw { position: relative; display: block; } .auth-card .pw input { padding-right: 4.2rem; } .auth-card .pw .link-btn { position: absolute; right: .6rem; top: 50%; transform: translateY(-50%); }
.auth-err { color: var(--bad); margin: 0; min-height: 1.2em; font-size: .9rem; }
.auth-warn { background: var(--warn-l); color: var(--warn); border-radius: 8px; padding: .55rem .7rem; font-size: .82rem; text-align: left; margin: 0 0 1rem; }
.wide-btn { width: 100%; justify-content: center; min-height: 44px; font-size: 1rem; }
.user-row { display: flex; justify-content: space-between; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--line); }

.ok-text { color: var(--ok); } .bad-text { color: var(--bad); }
