:root {
  --bg-grad-a: #f6f6fd;
  --bg-grad-b: #eceaf8;
  --card: #ffffff;
  --ink: #1e1b3a;
  --muted: #6b6890;
  --faint: #9d9ac0;
  --brand: #4338ca;
  --brand-2: #6d5ae6;
  --brand-3: #a78bfa;
  --border: #e8e6f5;
  --border-strong: #d6d2ee;
  --field: #f7f6fd;
  --danger: #e23b4e;
  --ok: #1e8449;
  --shadow-md: 0 8px 24px -10px rgba(40, 30, 90, .2);
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 500px at 80% -10%, rgba(167, 139, 250, .18), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(99, 102, 241, .12), transparent 55%),
    linear-gradient(180deg, var(--bg-grad-a), var(--bg-grad-b));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 18px 28px; color: #fff;
  background: linear-gradient(120deg, #362aa6 0%, #4338ca 45%, #6d5ae6 100%);
  box-shadow: 0 10px 30px -16px rgba(67, 56, 202, .8);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.28); font-weight: 800; font-size: 16px; }
.brand-text h1 { font-size: 18px; margin: 0; font-weight: 700; }
.brand-text span { font-size: 12.5px; opacity: .85; }
.tabs { display: flex; gap: 8px; }
.tab { display: inline-flex; align-items: center; gap: 7px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.22); color: #fff; padding: 9px 16px; border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 500; font-family: inherit; transition: transform .12s ease, background .15s ease; }
.tab:hover { background: rgba(255,255,255,.2); transform: translateY(-1px); }
.tab.active { background: #fff; color: var(--brand); font-weight: 700; }

main { max-width: 880px; margin: 30px auto 60px; padding: 0 18px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px 28px; margin-bottom: 22px; box-shadow: var(--shadow-md); animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.card-head { margin-bottom: 18px; }
.card-head h2 { margin: 0 0 4px; font-size: 19px; font-weight: 700; }
.card-head p { margin: 0; color: var(--muted); font-size: 13.5px; }

.section { margin-top: 22px; }
.section > h3 { margin: 0 0 12px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px; color: var(--brand); display: flex; align-items: center; gap: 8px; }
.section > h3::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid.three { grid-template-columns: 1fr 1fr 1fr; }
.grid .full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 6px; }
.lbl { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.lbl em { text-transform: none; font-style: normal; color: var(--faint); font-weight: 500; letter-spacing: 0; }
input[type="text"], input[type="date"], input[type="number"] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 10px;
  font-size: 14.5px; font-family: inherit; color: var(--ink); background: var(--field);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input:hover { border-color: #c3bce8; }
input:focus { outline: none; border-color: var(--brand-3); background: #fff; box-shadow: 0 0 0 4px rgba(167, 139, 250, .25); }

.recon { margin-top: 14px; display: flex; gap: 18px; flex-wrap: wrap; background: #f4f3fd; border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; }
.recon .item { display: flex; flex-direction: column; }
.recon .k { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
.recon .v { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.v.pos { color: var(--ok); } .v.neg { color: var(--danger); } .v.zero { color: var(--faint); }

.btn-primary, .btn-ghost { border: none; border-radius: 10px; padding: 11px 20px; font-size: 14px; cursor: pointer; font-weight: 600; font-family: inherit; transition: transform .12s ease, box-shadow .15s ease, background .15s ease, filter .15s ease; }
.btn-primary { background: linear-gradient(120deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 10px 22px -10px rgba(67, 56, 202, .8); }
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.07); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn-ghost { background: #efeefb; color: var(--ink); font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; font-size: 13px; }
.btn-ghost:hover { background: #e5e3f7; }
.actions { display: flex; align-items: center; gap: 14px; margin-top: 22px; flex-wrap: wrap; }
.msg { font-size: 13.5px; font-weight: 500; } .msg.ok { color: var(--ok); } .msg.err { color: var(--danger); }
.hidden { display: none; }

.table-wrap { border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.history-table { min-width: 560px; }
.history-table thead th { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); background: #f1f0fb; padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.history-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.history-table tbody tr:last-child td { border-bottom: none; }
.history-table tbody tr:hover { background: #fafafe; }
.history-table td:first-child { font-weight: 600; color: var(--brand); }
.history-table .empty { color: var(--faint); text-align: center; padding: 30px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions button, .row-actions a { font-size: 12.5px; padding: 7px 11px; }

/* Document */
.document { color: #1e1b3a; padding: 32px 36px; }
.doc-toolbar { display: flex; gap: 10px; margin-bottom: 22px; flex-wrap: wrap; }
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding-bottom: 16px; margin-bottom: 22px; border-bottom: 3px solid var(--brand); }
.doc-title h2 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: 1px; color: var(--brand); }
.doc-title .sub { font-size: 12px; color: var(--faint); letter-spacing: 2px; text-transform: uppercase; }
.doc-badge { display: inline-block; margin-top: 10px; background: #eeebfb; color: var(--brand); border: 1px solid #d6cff3; padding: 4px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 700; }
.doc-meta { font-size: 13px; line-height: 1.9; text-align: right; }
.doc-meta .row { display: flex; gap: 8px; justify-content: flex-end; }
.doc-meta b { color: var(--muted); font-weight: 600; }
.doc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.doc-block h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--brand); }
.doc-table { width: 100%; border-collapse: collapse; }
.doc-table td { border: 1px solid #ddd9f0; padding: 8px 11px; font-size: 13px; }
.doc-table td.k { background: #f6f5fd; font-weight: 600; color: var(--muted); width: 60%; }
.doc-table td.v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.doc-table tr.total td { background: #eeebfb; font-weight: 800; }
.doc-table tr.var td.v.neg { color: var(--danger); } .doc-table tr.var td.v.pos { color: var(--ok); }
.doc-notes { margin-top: 18px; font-size: 13px; background: #f6f5fd; border-left: 3px solid var(--brand-3); padding: 10px 14px; border-radius: 0 8px 8px 0; }
.doc-signoff { display: flex; justify-content: space-between; gap: 24px; margin-top: 50px; }
.doc-signoff .sign { text-align: center; flex: 1; }
.doc-signoff .line { border-top: 1.5px solid #8b87ad; margin-top: 44px; padding-top: 6px; font-size: 12.5px; color: var(--muted); }

@media print {
  @page { margin: 14mm; }
  .no-print, .topbar, .doc-toolbar { display: none !important; }
  body { background: #fff; }
  main { margin: 0; max-width: none; }
  .card { border: none; box-shadow: none; margin: 0; padding: 0; animation: none; }
  .document { padding: 0; }
  .doc-table td.k, .doc-table tr.total td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media (max-width: 680px) {
  .grid, .grid.three, .doc-grid { grid-template-columns: 1fr; }
  .doc-header { flex-direction: column; }
  .doc-meta, .doc-meta .row { text-align: left; justify-content: flex-start; }
}
