:root {
  --ink: #1C2733;
  --muted: #5B6878;
  --chrome: #22364C;
  --chrome-2: #2F4A67;
  --work: #DCE2E9;
  --panel: #FFFFFF;
  --rail: #F2F4F7;
  --line: #C6CFD9;
  --line-soft: #E3E8EE;
  --field: #FAFBFC;
  --focus: #2F6FB2;
  --refund: #1D7A46;
  --due: #B42318;
  --warn: #8A5A00;
  --font: 'IBM Plex Sans', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 var(--font);
  color: var(--ink);
  background: var(--work);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100vh;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.grow { flex: 1; }
h1, h2, h3 { margin: 0; }

/* ---------- Title bar and toolbar */
.titlebar {
  background: var(--chrome);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 7px 16px;
  font-size: 13px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.mark {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px;
  background: #fff; color: var(--chrome);
  font-size: 11px; font-weight: 600; border-radius: 3px;
}
.year { color: #B9C7D6; }
.current { font-weight: 500; }
.preparer { margin-left: auto; color: #B9C7D6; }

.toolbar {
  background: #EDF0F4;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  overflow-x: auto;
}
.tool {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 1px solid transparent; border-radius: 3px;
  padding: 5px 10px; cursor: pointer; white-space: nowrap;
}
.tool svg { width: 16px; height: 16px; fill: var(--chrome-2); }
.tool:hover:not(:disabled) { background: #fff; border-color: var(--line); }
.tool:disabled { opacity: .4; cursor: default; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }

#app { min-height: 0; overflow: auto; }

/* ---------- Buttons */
.btn {
  background: #fff; border: 1px solid var(--line); border-radius: 3px;
  padding: 6px 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--chrome-2); }
.btn.primary { background: var(--chrome-2); border-color: var(--chrome-2); color: #fff; font-weight: 500; }
.btn.primary:hover { background: var(--chrome); }
.btn.danger { color: var(--due); }
.btn.danger:hover { border-color: var(--due); }
.btn.small { padding: 3px 10px; font-size: 13px; }

/* ---------- Home */
.home { max-width: 1100px; margin: 0 auto; padding: 24px 24px 40px; }
.home-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.home-head h1 { font-size: 22px; font-weight: 600; margin-right: auto; }
#search {
  width: 300px; max-width: 100%;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 3px; background: #fff;
}
.table-wrap { overflow-x: auto; }
table.clients { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); }
.clients th {
  text-align: left; font-weight: 600; font-size: 13px; color: var(--muted);
  background: #F6F8FA; padding: 8px 12px; border-bottom: 1px solid var(--line);
}
.clients td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
.clients tbody tr { cursor: pointer; }
.clients tbody tr:hover { background: #F3F7FB; }
.clients .name { font-weight: 500; }
.clients .actions { text-align: right; display: flex; gap: 6px; justify-content: flex-end; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--refund); }
.neg { color: var(--due); }
.empty { background: var(--panel); border: 1px solid var(--line); padding: 40px 24px; text-align: center; }
.empty p { margin: 0 0 14px; color: var(--muted); }
.empty.inner { border: 0; }
.notice { color: var(--muted); font-size: 13px; margin-top: 14px; }

/* ---------- Workspace */
.workspace { display: grid; grid-template-columns: 290px 1fr; height: 100%; }
.formlist { background: var(--rail); border-right: 1px solid var(--line); overflow-y: auto; padding: 6px 0 20px; }
.formlist h3 { font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 14px 4px; }
.formlist button {
  display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 8px;
  width: 100%; text-align: left; background: none; border: 0; padding: 5px 14px; cursor: pointer;
}
.formlist button:hover { background: #E7EBF0; }
.formlist button[aria-current] { background: #fff; box-shadow: inset 3px 0 var(--focus); font-weight: 500; }
.code {
  display: inline-block; text-align: center;
  font-size: 12px; font-weight: 600; color: var(--chrome-2);
  background: #DFE6EE; border-radius: 2px; padding: 1px 4px; min-width: 34px;
}
.code.big { font-size: 14px; padding: 3px 8px; background: var(--chrome-2); color: #fff; }
.count { font-size: 11px; background: var(--chrome-2); color: #fff; border-radius: 9px; padding: 0 7px; }
.count.err { background: var(--due); }

.entry { padding: 20px 28px 40px; overflow-y: auto; }
.sheet { background: var(--panel); border: 1px solid var(--line); max-width: 860px; }
.sheet-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: #F8FAFC;
}
.sheet-head h2 { font-size: 17px; font-weight: 600; }

.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); background: #F8FAFC; overflow-x: auto; padding: 0 12px; }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 7px 12px; cursor: pointer; white-space: nowrap; color: var(--muted);
}
.tab[aria-current] { border-bottom-color: var(--focus); color: var(--ink); font-weight: 500; }

/* Data entry rows: label left, field right, ledger lines between */
.rows { display: grid; grid-template-columns: 1fr; }
.row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(150px, 280px);
  align-items: center; gap: 16px;
  padding: 4px 16px; border-bottom: 1px solid var(--line-soft);
}
.row:hover { background: #FAFCFE; }
.row > span { color: var(--ink); }
.row input:not([type=checkbox]), .row select {
  width: 100%; padding: 5px 8px;
  border: 1px solid var(--line); border-radius: 2px; background: var(--field);
}
.row input:focus, .row select:focus { background: #FFFDF0; border-color: var(--focus); outline: none; box-shadow: 0 0 0 2px rgba(47,111,178,.2); }
.row.check input { justify-self: start; width: 17px; height: 17px; accent-color: var(--chrome-2); }
input.money { text-align: right; font-variant-numeric: tabular-nums; }
.sec {
  padding: 7px 16px; background: #EEF2F6; font-weight: 600; font-size: 13px;
  border-bottom: 1px solid var(--line-soft); border-top: 1px solid var(--line-soft);
}

/* ---------- Summary */
.print-head { display: none; }
table.lines { width: 100%; border-collapse: collapse; }
.lines td { padding: 5px 16px; border-bottom: 1px solid var(--line-soft); font-variant-numeric: tabular-nums; }
.lines .grp th { text-align: left; background: #EEF2F6; padding: 7px 16px; font-size: 13px; font-weight: 600; }
.lines .total td { font-weight: 600; border-bottom-color: var(--line); }
.lines .final td { font-size: 20px; font-weight: 600; padding: 14px 16px; border-bottom: 0; }
.fine { font-size: 12px; color: var(--muted); padding: 10px 16px 14px; margin: 0; }

/* ---------- Diagnostics */
.dx-list { list-style: none; margin: 0; padding: 0; }
.dx { display: grid; grid-template-columns: 84px 1fr auto; align-items: center; gap: 12px; padding: 9px 16px; border-bottom: 1px solid var(--line-soft); }
.dx .lvl { font-size: 12px; font-weight: 600; padding: 2px 6px; border-radius: 2px; text-align: center; }
.dx.error .lvl { background: #FBE4E1; color: var(--due); }
.dx.warn .lvl { background: #FBF0D9; color: var(--warn); }
.dx.info .lvl { background: #E4EDF7; color: var(--chrome-2); }
.dx.ok { grid-template-columns: 1fr; color: var(--refund); }

/* ---------- Status bar */
.statusbar {
  background: var(--chrome); color: #fff;
  display: flex; align-items: stretch; min-height: 48px; overflow-x: auto;
}
.status-cell {
  display: flex; flex-direction: column; justify-content: center;
  padding: 5px 18px; border: 0; border-right: 1px solid rgba(255,255,255,.12);
  background: none; color: inherit; text-align: left; white-space: nowrap;
}
.status-cell span { font-size: 11px; color: #B9C7D6; }
.status-cell strong { font-weight: 500; font-variant-numeric: tabular-nums; }
.dx-link { cursor: pointer; }
.dx-link:hover { background: var(--chrome-2); }
.result {
  margin-left: auto; display: flex; flex-direction: column; justify-content: center; align-items: flex-end;
  padding: 4px 22px; min-width: 190px; transition: background-color .25s;
}
.result span { font-size: 11px; opacity: .85; }
.result strong { font-size: 22px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.result.refund { background: var(--refund); }
.result.due { background: var(--due); }

/* ---------- Dialog and toast */
dialog { border: 1px solid var(--line); border-radius: 4px; padding: 0; width: min(440px, 92vw); }
dialog::backdrop { background: rgba(20, 30, 45, .45); }
.dialog-body { padding: 20px; display: grid; gap: 12px; }
.dialog-body h2 { font-size: 17px; font-weight: 600; }
.dialog-body label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.dialog-body input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 2px; color: var(--ink); }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.toast {
  position: fixed; left: 50%; bottom: 64px; transform: translate(-50%, 12px);
  background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 3px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Small screens */
@media (max-width: 780px) {
  .preparer, .year { display: none; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .formlist { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 4px; }
  .formlist h3 { display: none; }
  .formlist button { display: flex; width: auto; white-space: nowrap; padding: 6px 10px; }
  .formlist button .t { display: none; }
  .formlist button[aria-current] { box-shadow: inset 0 -3px var(--focus); }
  .entry { padding: 12px; }
  .row { grid-template-columns: 1fr; gap: 4px; padding: 8px 12px; }
  .row.check { grid-template-columns: auto 1fr; }
  .row.check input { order: -1; }
  .statusbar { flex-wrap: wrap; overflow: visible; }
  .status-cell { padding: 4px 12px; flex: 1 0 auto; }
  .result { order: -1; width: 100%; margin-left: 0; flex-direction: row; justify-content: space-between; align-items: center; padding: 6px 14px; }
  .dx-link { display: none; }
  .dx { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Print: only the return summary */
@media print {
  body { display: block; height: auto; overflow: visible; background: #fff; font-size: 12px; }
  .titlebar, .toolbar, .statusbar, .formlist, .no-print, .toast { display: none !important; }
  #app, .workspace, .entry { display: block; overflow: visible; padding: 0; height: auto; }
  .sheet { border: 0; max-width: none; }
  .sheet-head { background: none; padding: 0 0 8px; }
  .print-head { display: flex; justify-content: space-between; padding: 8px 0 14px; border-bottom: 1px solid #999; margin-bottom: 8px; }
  .print-head .right { text-align: right; }
  .lines td, .lines .grp th { padding: 3px 4px; }
  .lines .grp th { background: #eee; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
