:root {
  --primary: #4F46E5; --primary-dark: #3730A3; --primary-soft: #EEF2FF; --accent: #06B6D4;
  --ink: #0F172A; --ink-2: #334155; --muted: #64748B; --line: #E2E8F0; --line-2: #CBD5E1;
  --bg: #F1F5F9; --card: #FFFFFF; --nav: #0F172A; --nav-2: #1E293B;
  --pos: #047857; --pos-bg: #D1FAE5; --neg: #B91C1C; --neg-bg: #FEE2E2; --warn: #B45309; --warn-bg: #FEF3C7; --info-bg: #E0E7FF;
  --radius: 10px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.05);
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; } a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; } h2 { font-size: 15px; margin: 0 0 12px; } h3 { font-size: 13px; margin: 0 0 8px; color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* login */
#login { min-height: 100%; display: grid; place-items: center; background: linear-gradient(135deg, #0F172A 0%, #1E293B 55%, #312E81 100%); padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-card img { height: 34px; margin-bottom: 18px; }
.login-card h1 { margin-bottom: 4px; } .login-card p { margin: 0 0 20px; color: var(--muted); }

/* shell */
#app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--nav); color: #CBD5E1; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.side .brand { padding: 4px 10px 18px; } .side .brand img { height: 28px; display: block; }
.side .brand small { display: block; color: #94A3B8; margin-top: 6px; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
.side nav a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; color: #CBD5E1; font-weight: 500; margin: 1px 0; }
.side nav a:hover { background: var(--nav-2); text-decoration: none; color: #fff; }
.side nav a.on { background: var(--primary); color: #fff; }
.side nav .grp { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: #64748B; margin: 16px 10px 4px; }
.side nav svg { width: 17px; height: 17px; flex: none; opacity: .9; }
.side .who { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--nav-2); font-size: 12px; }
.side .who b { color: #fff; display: block; } .side .who button { margin-top: 8px; }
main { padding: 24px 28px 60px; min-width: 0; max-width: 1400px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* cards / grids */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 14px; } .g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mt { margin-top: 14px; } .mt2 { margin-top: 22px; }

/* buttons + forms */
.btn { border: 1px solid var(--line-2); background: #fff; padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 550; display: inline-flex; gap: 6px; align-items: center; }
.btn:hover { background: #F8FAFC; } .btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; } .btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--neg); border-color: #FCA5A5; } .btn.sm { padding: 4px 9px; font-size: 12px; } .btn.ghost { border-color: transparent; background: transparent; }
.side .btn { background: var(--nav-2); border-color: #334155; color: #E2E8F0; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], input[type=email], select, textarea {
  width: 100%; border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 10px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #A5B4FC; border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 10px; }
label.f > span { display: block; margin-bottom: 4px; } label.f small { font-weight: 400; color: var(--muted); }
label.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; } label.chk input { width: auto; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.filters > * { flex: 0 1 auto; } .filters .grow { flex: 1 1 220px; } .filters input, .filters select { width: auto; min-width: 130px; } .filters .grow input { width: 100%; }
.filters label { font-size: 11px; color: var(--muted); font-weight: 600; display: block; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; background: #fff; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; font-weight: 550; color: var(--ink-2); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; } .seg button.on { background: var(--primary); color: #fff; }

/* tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 9px 12px; background: #F8FAFC; border-bottom: 1px solid var(--line); white-space: nowrap; }
th.num { text-align: right; }
td { padding: 9px 12px; border-bottom: 1px solid #F1F5F9; vertical-align: middle; }
tr:last-child td { border-bottom: 0; } tbody tr:hover td { background: #FAFBFF; } tr.click { cursor: pointer; }
td.desc { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
tfoot td { font-weight: 650; background: #F8FAFC; border-top: 1px solid var(--line); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; }

/* chips */
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #F1F5F9; color: var(--ink-2); white-space: nowrap; }
.chip.client { background: #DBEAFE; color: #1D4ED8; } .chip.supplier { background: #FCE7F3; color: #BE185D; } .chip.rep { background: #FEF3C7; color: #B45309; } .chip.related { background: #EDE9FE; color: #6D28D9; }
.chip.ok, .chip.paid, .chip.active, .chip.completed { background: var(--pos-bg); color: var(--pos); } .chip.overdue, .chip.lost, .chip.void { background: var(--neg-bg); color: var(--neg); }
.chip.open, .chip.partial, .chip.lead, .chip.accrued, .chip.draft { background: var(--warn-bg); color: var(--warn); } .chip.qualified, .chip.sent { background: var(--info-bg); color: var(--primary-dark); }
.chip.inactive { background: #E2E8F0; color: var(--muted); }
.toggle-chip { cursor: pointer; border: 1px dashed var(--line-2); background: #fff; color: var(--muted); }
.toggle-chip.on.client { border-style: solid; } .toggle-chip.on { border-style: solid; }

/* modal + toast */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: grid; place-items: start center; padding: 6vh 16px; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 24px 70px rgba(0,0,0,.4); }
.modal.wide { max-width: 820px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; font-size: 16px; } .modal .body { padding: 18px 20px; } .modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #F8FAFC; border-radius: 0 0 12px 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } .row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.err { background: var(--neg-bg); color: var(--neg); padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; font-weight: 500; }
#toast { position: fixed; bottom: 22px; right: 22px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transform: translateY(8px); transition: .2s; z-index: 99; pointer-events: none; max-width: 380px; }
#toast.show { opacity: 1; transform: none; }
.pick-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 10px; }
.pick-list div { padding: 8px 12px; border-bottom: 1px solid #F1F5F9; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; } .pick-list div:hover { background: var(--primary-soft); }
.picker-btn { width: 100%; text-align: left; justify-content: space-between; }

/* bars + chart */
.bar { height: 8px; background: #E2E8F0; border-radius: 4px; overflow: hidden; min-width: 60px; } .bar i { display: block; height: 100%; background: var(--primary); border-radius: 4px; } .bar.neg i { background: #F43F5E; }
.chart svg { width: 100%; height: auto; display: block; } .legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 6px; } .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.note { background: var(--warn-bg); color: #78350F; padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.note.info { background: var(--info-bg); color: #312E81; }
dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0; } dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }

/* process map */
.flow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 34px 26px; position: relative; }
.step { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px; position: relative; box-shadow: var(--shadow); }
.step .n { width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; position: absolute; top: -13px; left: 14px; }
.step h3 { margin: 6px 0 4px; color: var(--ink); font-size: 14px; } .step p { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; }
.step .stat { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; } .step .stat small { display: block; font-size: 11.5px; font-weight: 500; color: var(--muted); }
.step:not(:nth-child(4n))::after { content: ''; position: absolute; right: -27px; top: 50%; width: 26px; border-top: 2px solid var(--primary); }
.step:not(:nth-child(4n))::before { content: ''; position: absolute; right: -28px; top: calc(50% - 5px); border: 5px solid transparent; border-left: 8px solid var(--primary); border-right: 0; }

@media (max-width: 1000px) { #app { grid-template-columns: 1fr; } .side { position: static; height: auto; } .g4 { grid-template-columns: repeat(2, 1fr); } .g3, .g2 { grid-template-columns: 1fr; } .flow { grid-template-columns: 1fr 1fr; } .step::after, .step::before { display: none !important; } main { padding: 16px; } }
@media print {
  .side, .actions, .filters, .no-print, .pager button { display: none !important; } #app { display: block; } main { padding: 0; max-width: none; } body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; } .step { break-inside: avoid; }
}
body.ro .w-only { display: none !important; }
.filters label.chk { display: flex; font-size: 13px; color: var(--ink); font-weight: 500; }

#menu-btn { display: none; }
@media (max-width: 1000px) {
  .side { padding: 10px 12px; } .side .brand { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px; } .side .brand small { display: none; }
  #menu-btn { display: inline-flex; } .side nav, .side .who { display: none; } .side.open nav { display: block; } .side.open .who { display: block; margin-top: 10px; }
  .side { height: auto; }
  .page-head h1 { font-size: 19px; } .kpi .value { font-size: 20px; }
}
.chip.staff { background: #CFFAFE; color: #0E7490; }

/* printable documents */
.doc { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 28px 32px; margin: 0 0 18px; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 14px; }
.doc-co { font-size: 12.5px; color: var(--ink-2); line-height: 1.5; } .doc-co b { font-size: 15px; color: var(--ink); }
.doc-title { text-align: right; } .doc-title h1 { font-size: 20px; letter-spacing: .02em; text-transform: uppercase; }
.doc-party { margin: 6px 0 16px; padding: 10px 14px; background: #F8FAFC; border-radius: 8px; line-height: 1.55; }
.doc-tbl th, .doc-tbl td { padding: 6px 8px; font-size: 12.5px; } .doc-tbl tfoot td { font-size: 13px; }
.vgrid { display: grid; gap: 14px; }
.voucher { background: #fff; border: 1px solid var(--line-2); border-radius: 8px; padding: 16px 20px; break-inside: avoid; page-break-inside: avoid; }
.voucher .doc-head { margin-bottom: 8px; } .voucher .doc-title h1 { font-size: 16px; }
.kvt { width: 100%; font-size: 12.5px; } .kvt th { width: 90px; text-align: left; text-transform: none; letter-spacing: 0; background: none; color: var(--muted); padding: 5px 8px 5px 0; vertical-align: top; } .kvt td { padding: 5px 8px; vertical-align: top; border-bottom: 1px solid #F1F5F9; }
.kvt .amt { font-size: 18px; font-weight: 700; }
.sign { display: flex; justify-content: space-between; margin: 18px 0 8px; font-size: 12px; color: var(--ink-2); }
@media print {
  .pb { page-break-after: always; border: 0; padding: 0; } .pb:last-child { page-break-after: auto; }
  .doc { border: 0; box-shadow: none; } .voucher { border: 1px solid #999; margin-bottom: 10px; } .vgrid { gap: 10px; }
  .no-print { display: none !important; } main { padding: 0 !important; }
}
