:root {
  --navy: #0b3d5c; --navy-2: #124a6e; --accent: #1f8a70; --bg: #f4f6f8; --card: #ffffff; --text: #1d2730; --muted: #5f6b76;
  --line: #dde3e8; --amber: #b7791f; --amber-bg: #fff6e0; --red: #b42318; --red-bg: #fde8e6; --green: #1f7a3d; --green-bg: #e3f5e8;
  --blue: #1f5fa8; --blue-bg: #e6eef9; --grey: #5f6b76; --grey-bg: #eef1f4; --purple: #6b3fa0; --purple-bg: #efe8f8;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 15px; color: var(--text); background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 14px; font-weight: 650; }
h2 { font-size: 17px; margin: 0 0 10px; font-weight: 650; }
h3 { font-size: 15px; margin: 0 0 8px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
header.top { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 50; }
header .bar { display: flex; align-items: center; gap: 14px; padding: 0 16px; height: 52px; }
header .brand { font-weight: 700; letter-spacing: .04em; white-space: nowrap; color: #fff; }
header .brand span { color: #9fd3c7; font-weight: 500; }
nav.main { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
nav.main::-webkit-scrollbar { display: none; }
nav.main a { color: #d8e4ec; padding: 8px 10px; border-radius: 6px; white-space: nowrap; font-size: 14px; }
nav.main a.active, nav.main a:hover { background: var(--navy-2); color: #fff; text-decoration: none; }
header .user { font-size: 13px; color: #c9d6df; white-space: nowrap; }
header .user a { color: #fff; }
main { max-width: 1400px; margin: 0 auto; padding: 18px 16px 60px; }
.flash { padding: 10px 14px; border-radius: 8px; margin: 0 0 12px; border: 1px solid; }
.flash.ok { background: var(--green-bg); border-color: #b7e0c3; color: var(--green); }
.flash.error { background: var(--red-bg); border-color: #f3b9b4; color: var(--red); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; display: block; color: var(--text); }
.tile:hover { text-decoration: none; outline: 2px solid #c6d8e6; }
.tile .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 20px; font-weight: 700; margin-top: 4px; }
.tile .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.warn .v { color: var(--red); }
.tile.amber .v { color: var(--amber); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; position: sticky; top: 52px; z-index: 1; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr:hover td { background: #f7fafc; }
tr.overdue td:first-child { border-left: 3px solid var(--red); }
tr.soon td:first-child { border-left: 3px solid var(--amber); }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tablewrap table { min-width: 720px; }
.tablewrap th { position: static; }
.inline-fields > select, .inline-fields > input[type=text], .inline-fields > input[type=date] { width: auto; }
.tablewrap.sticky td:first-child, .tablewrap.sticky th:first-child { position: sticky; left: 0; background: #fff; z-index: 2; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.grey { background: var(--grey-bg); color: var(--grey); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.purple { background: var(--purple-bg); color: var(--purple); }
.conf-high { background: var(--green-bg); color: var(--green); }
.conf-medium { background: var(--amber-bg); color: var(--amber); }
.conf-low, .conf-none { background: var(--red-bg); color: var(--red); }
.btn { display: inline-block; padding: 7px 13px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); font-size: 14px; cursor: pointer; font-family: inherit; line-height: 1.3; }
.btn:hover { background: #f1f4f7; text-decoration: none; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.btn.good { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--red); border-color: #f3b9b4; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
form.inline { display: inline; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .03em; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=email], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #c9d2da; border-radius: 8px; font-size: 15px; font-family: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #9ec5e8; border-color: #9ec5e8; }
textarea { min-height: 70px; }
.field { margin-bottom: 12px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 16px; }
.fields .wide { grid-column: 1 / -1; }
.fields .w2 { grid-column: span 2; }
.inline-fields { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.inline-fields .field { margin: 0; min-width: 150px; flex: 1; }
.help { display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; border-radius: 50%; background: #d7e3ec; color: var(--navy); font-size: 11px; font-weight: 700; cursor: pointer; margin-left: 4px; vertical-align: middle; user-select: none; text-transform: none; letter-spacing: 0; }
.help:hover { background: var(--navy); color: #fff; }
.popover { position: fixed; z-index: 100; max-width: 340px; background: #1d2730; color: #fff; padding: 10px 12px; border-radius: 8px; font-size: 13px; line-height: 1.45; box-shadow: 0 8px 24px rgba(0,0,0,.25); display: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.pdfframe { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: 8px; background: #eee; }
.dropzone { border: 2px dashed #9fb3c2; border-radius: 12px; padding: 36px 20px; text-align: center; color: var(--muted); background: #fbfcfd; }
.dropzone.over { background: #eaf3fb; border-color: var(--blue); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--line); font-size: 13px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 11px; width: 8px; height: 8px; border-radius: 50%; background: var(--navy); }
.timeline .ts { color: var(--muted); }
.progress { display: flex; gap: 4px; flex-wrap: wrap; margin: 6px 0 12px; }
.progress span { padding: 3px 9px; border-radius: 6px; background: var(--grey-bg); color: var(--muted); font-size: 12px; }
.progress span.done { background: var(--green-bg); color: var(--green); }
.progress span.now { background: var(--navy); color: #fff; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.filters .field { margin: 0; min-width: 120px; }
.filters input, .filters select { padding: 6px 8px; font-size: 14px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 6px 12px; border-radius: 999px; background: #e9eef3; color: var(--text); font-size: 14px; }
.tabs a.active { background: var(--navy); color: #fff; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--text); }
.check input { width: auto; }
.login { max-width: 380px; margin: 60px auto; }
.login .brand { font-size: 24px; font-weight: 700; color: var(--navy); margin-bottom: 4px; }
.sum { font-weight: 700; }
.fc td.neg { color: var(--red); }
.fc td.pos { color: var(--green); }
.fc tr.total td { font-weight: 700; border-top: 2px solid var(--navy); }
.fc tr.balance td { background: #f1f6fa; font-weight: 700; }
.sticky-actions { position: sticky; bottom: 0; background: #fff; padding: 10px 0; border-top: 1px solid var(--line); }
details summary { cursor: pointer; color: var(--blue); }
.notice { background: var(--amber-bg); border: 1px solid #f0d9a6; color: #7a5208; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.pill-row { display: flex; flex-wrap: wrap; gap: 6px; }
@media (max-width: 900px) {
  header .bar { flex-wrap: wrap; height: auto; padding: 6px 10px 4px; gap: 6px 10px; }
  header .brand { flex: 1; }
  nav.main { order: 3; width: 100%; flex: none; padding-bottom: 4px; }
  nav.main a { padding: 6px 9px; font-size: 14px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .split { grid-template-columns: 1fr; }
  .pdfframe { height: 60vh; }
  th { top: 0; }
  body { font-size: 15px; }
  header .user .name { display: none; }
  main { padding: 12px 10px 70px; }
  .card { padding: 12px; }
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fields .w2 { grid-column: 1 / -1; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dt { margin-top: 6px; }
}
@media (max-width: 520px) {
  .fields { grid-template-columns: 1fr; }
  h1 { font-size: 19px; }
  .tile .v { font-size: 18px; }
}
@media print { header.top, .actions, .filters, .btn { display: none !important; } main { padding: 0; } .card { box-shadow: none; } }

input.invalid { border-color: var(--red); background: #fff5f5; }
