:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #1d2433; --muted: #667085; --line: #e3e7ee;
  --brand: #1f5fa8; --brand-ink: #fff; --brand-soft: #e8f0fa;
  --green: #18794e; --green-soft: #e3f5ea; --red: #c4320a; --red-soft: #fdebe6;
  --amber: #a15c07; --amber-soft: #fdf3dc; --grey-soft: #eef0f3;
  --side: #14213a; --side-ink: #c9d3e3;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
small, .muted { color: var(--muted); }

/* layout */
.sidebar { position: fixed; inset: 0 auto 0 0; width: 236px; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; z-index: 20; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand b { color: #fff; display: block; font-size: 14px; }
.brand small { color: var(--side-ink); font-size: 12px; }
.logo { background: var(--brand); color: #fff; font-weight: 700; border-radius: 6px; width: 34px; height: 34px; display: grid; place-items: center; }
.sidebar nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; color: var(--side-ink); padding: 8px 10px; border-radius: 6px; margin-bottom: 2px; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.ico { width: 18px; text-align: center; }
.me { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.me b { color: #fff; display: block; }
.me small { display: block; margin-bottom: 6px; color: var(--side-ink); }
.me a { color: #9cc3f0; }
.main { margin-left: 236px; min-height: 100vh; }
.main.solo { margin-left: 0; }
.topbar { position: sticky; top: 0; z-index: 10; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 14px; padding: 12px 24px; }
.topbar h1 { flex: 1; }
.fy-form label { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.menu-btn { display: none; }
.content { padding: 20px 24px 40px; max-width: 1600px; }

/* components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.kpi .value { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.warn .value { color: var(--red); }
.kpi a { color: inherit; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 7px 12px; border-radius: 6px; cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--grey-soft); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: #184d8a; }
.btn-danger { color: var(--red); border-color: #f1c4b6; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

table { border-collapse: collapse; width: 100%; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.tbl th, .tbl td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { background: #f8fafc; font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
.tbl tr:hover td { background: #fafbfd; }
.tbl td.n, .tbl th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl td.nowrap { white-space: nowrap; }
.tbl tfoot td { font-weight: 650; background: #f8fafc; border-top: 2px solid var(--line); }
.tbl .desc { min-width: 220px; }
.tbl.compact th, .tbl.compact td { padding: 5px 8px; }
td.missing { background: var(--red-soft) !important; }
tr.row-diff td { background: var(--red-soft); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-green { background: var(--green-soft); color: var(--green); }
.b-red { background: var(--red-soft); color: var(--red); }
.b-amber { background: var(--amber-soft); color: var(--amber); }
.b-grey { background: var(--grey-soft); color: var(--muted); }
.b-blue { background: var(--brand-soft); color: var(--brand); }
.issue-dot, .ok-dot { display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 10px; font-size: 11px; font-weight: 700; padding: 0 5px; cursor: help; }
.ok-dot { background: var(--green-soft); color: var(--green); }
.sev-high { background: var(--red); color: #fff; }
.sev-medium { background: #f5b83d; color: #3d2600; }
.sev-low { background: var(--grey-soft); color: var(--muted); }
.diff-neg, .text-red { color: var(--red); font-weight: 600; }
.text-green { color: var(--green); font-weight: 600; }

/* forms */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=email], input[type=search], select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid #cfd5df; border-radius: 6px; padding: 6px 9px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b5d0f0; border-color: var(--brand); }
textarea { width: 100%; min-height: 64px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.form-grid .wide { grid-column: span 2; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; font-weight: 600; color: #475467; }
.field input, .field select, .field textarea { width: 100%; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 16px; margin: 0 0 16px; background: var(--panel); }
legend { font-weight: 650; padding: 0 6px; }
.calc { display: flex; gap: 22px; flex-wrap: wrap; background: var(--brand-soft); border-radius: 6px; padding: 10px 14px; margin-top: 12px; font-variant-numeric: tabular-nums; }
.calc b { display: block; font-size: 16px; }
.calc span { font-size: 12px; color: var(--muted); }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.flash-ok { background: var(--green-soft); border-color: #b6e3c8; color: var(--green); }
.flash-err { background: var(--red-soft); border-color: #f4c3b4; color: var(--red); }
.flash-info { background: var(--brand-soft); border-color: #c4d8f1; color: var(--brand); }

/* bars */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 160px 1fr 110px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--grey-soft); border-radius: 4px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); border-radius: 4px; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; }
.cols { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding-top: 18px; }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 28px; }
.col .stick { width: 70%; max-width: 46px; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.col .cap { font-size: 11px; color: var(--muted); margin-top: 6px; white-space: nowrap; }
.col .amt { font-size: 11px; margin-bottom: 4px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.issue-list { list-style: none; padding: 0; margin: 0; }
.issue-list li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.login-box { max-width: 380px; margin: 10vh auto; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.pager { display: flex; gap: 6px; margin-top: 12px; align-items: center; }
.changes { font-size: 12px; color: var(--muted); }
.changes b { color: var(--ink); font-weight: 600; }
.sign-table td { padding: 10px; }

@media (max-width: 1000px) {
  .g2, .g3 { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
}
@media (max-width: 800px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-block; background: none; border: 1px solid var(--line); border-radius: 6px; font-size: 18px; padding: 2px 9px; }
  .content { padding: 14px 16px 30px; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .bar-row { grid-template-columns: 100px 1fr 90px; }
}
@media print {
  .sidebar, .topbar, .no-print, .filters, .btn { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  .card, .table-wrap { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  body { background: #fff; font-size: 11px; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* invoice upload */
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 6px; border: 2px dashed #b9c6d8; border-radius: var(--radius); padding: 34px 16px; text-align: center; cursor: pointer; background: #fafcff; }
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dz-ico { font-size: 34px; }
.scan-layout { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 18px; align-items: start; }
.scan-preview { position: sticky; top: 70px; }
.scan-preview iframe, .scan-preview img { width: 100%; height: calc(100vh - 170px); min-height: 420px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.scan-preview img { height: auto; max-height: calc(100vh - 170px); object-fit: contain; }
.scan-lines input, .scan-lines select { padding: 4px 6px; }
.scan-lines tr.off td { opacity: .45; }
@media (max-width: 1100px) { .scan-layout { grid-template-columns: 1fr; } .scan-preview { position: static; } .scan-preview iframe { height: 60vh; } }

/* inline editing */
.qe { border: 1px solid transparent; background: transparent; border-radius: 4px; padding: 3px 5px; font: inherit; color: inherit; transition: background .3s, border-color .3s; max-width: 100%; }
.qe:hover { border-color: #cfd5df; background: #fff; }
.qe:focus { border-color: var(--brand); background: #fff; outline: 2px solid #b5d0f0; }
.qe-n { text-align: right; }
select.qe { padding: 2px 2px; }
input.qe[type=date] { width: 128px; font-size: 12px; }
.qe-missing { background: var(--red-soft); border-color: #f4c3b4; }
.qe-saving { background: #fff8e1 !important; }
.qe-ok { background: var(--green-soft) !important; border-color: #8fd3ad !important; }
.qe-err { background: var(--red-soft) !important; border-color: var(--red) !important; }
.qe-toast { position: fixed; right: 20px; bottom: 20px; background: #1d2433; color: #fff; padding: 9px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); opacity: 0; transform: translateY(8px); transition: all .2s; pointer-events: none; z-index: 50; }
.qe-toast.show { opacity: 1; transform: none; }
.qe-toast.bad { background: var(--red); }
@media print { .qe { border: 0; background: none; -webkit-appearance: none; appearance: none; } }
.ocr-text summary { cursor: pointer; font-weight: 600; }
.ocr-text pre { white-space: pre-wrap; font-size: 12px; max-height: 360px; overflow: auto; background: #f8fafc; padding: 10px; border-radius: 6px; margin: 10px 0 0; }
.pw-mask { font-family: Consolas, "Courier New", monospace; background: var(--grey-soft); padding: 2px 6px; border-radius: 4px; min-width: 80px; display: inline-block; user-select: all; }
tr.muted td { opacity: .55; }

/* expiry warnings (Email & Passwords) */
.exp { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.exp-yellow { background: #fde68a; color: #6b4b00; }
.exp-green { background: #bbf7d0; color: #0f5132; }
.exp-red { background: #dc2626; color: #fff; }
.exp-ok { background: var(--grey-soft); color: var(--muted); font-weight: 500; }
tr.exp-row-yellow td { background: #fffbeb; }
tr.exp-row-green td { background: #f0fdf4; }
tr.exp-row-red td { background: #fef2f2; }
tr.exp-row-red td:first-child { box-shadow: inset 4px 0 0 #dc2626; }
tr.exp-row-green td:first-child { box-shadow: inset 4px 0 0 #22c55e; }
tr.exp-row-yellow td:first-child { box-shadow: inset 4px 0 0 #f59e0b; }
.nav-badge { margin-left: auto; min-width: 20px; height: 20px; border-radius: 10px; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; padding: 0 6px; }
.nav-badge.exp-red { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.exp-alert { border-left: 5px solid; }
.exp-alert.lvl-red { border-left-color: #dc2626; }
.exp-alert.lvl-green { border-left-color: #22c55e; }
.exp-alert.lvl-yellow { border-left-color: #f59e0b; }
.type-counts { margin: 0 0 12px; font-size: 13px; }
.type-counts a { white-space: nowrap; }
.qr-box { display: flex; justify-content: center; margin: 8px 0 12px; }
.qr-box svg { width: 220px; height: 220px; background: #fff; padding: 6px; border-radius: 8px; border: 1px solid var(--line); }
.totp-key { font-size: 15px; letter-spacing: 1px; background: var(--grey-soft); padding: 4px 8px; border-radius: 4px; user-select: all; }
.code-input { font-size: 20px !important; letter-spacing: 6px; width: 150px; text-align: center; font-family: Consolas, monospace; }
#vault-page { position: relative; }
.vault-cover { display: none; }
#vault-page.vault-hidden > :not(.vault-cover):not(dialog) { filter: blur(9px); pointer-events: none; user-select: none; }
#vault-page.vault-hidden .vault-cover { display: block; position: sticky; top: 90px; z-index: 30; margin: 0 auto 12px; max-width: 520px; text-align: center; background: #1d2433; color: #fff; padding: 14px 18px; border-radius: 10px; cursor: pointer; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.mask-login { cursor: pointer; border-bottom: 1px dashed var(--muted); }
.mask-login.shown { border-bottom-color: transparent; }
#reason-dlg { border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
#reason-dlg::backdrop { background: rgba(16,24,40,.45); }
#reason-dlg input { width: 100%; }
