/* =============================================================================
   Vouchers (acc-voucher.js) — the forms, the voucher window, the registers.

   Its own sheet, not acc-app.css: that one is exported to web/. Every rule is
   scoped to the ledger (body.acc-fullscreen), except the offline bar, the toast
   tones and the typed delete box, which belong to shared chrome.

   A voucher type keeps one colour everywhere it appears — the pill on the
   register, the window's header wash, the grid header, the total: receipt
   green, payment red, journal blue, opening violet. It is the same colour the
   register's type pill already used (VOUCHER_KINDS), so the window and the row
   it was opened from read as one thing.
   ============================================================================= */

body.acc-fullscreen .mdl--vch-receipt,
body.acc-fullscreen .mdl--vchview:has(.vch-view[data-vch-kind="receipt"]){--win-accent:var(--acc-green, #067647)}
body.acc-fullscreen .mdl--vch-payment,
body.acc-fullscreen .mdl--vchview:has(.vch-view[data-vch-kind="payment"]),
body.acc-fullscreen .mdl--vchview:has(.vch-view[data-vch-kind="payroll"]){--win-accent:var(--acc-red, #b42318)}
body.acc-fullscreen .mdl--vch-journal,
body.acc-fullscreen .mdl--vchview:has(.vch-view[data-vch-kind="journal"]){--win-accent:var(--acc-blue, #2563eb)}
body.acc-fullscreen .mdl--vch-opening,
body.acc-fullscreen .mdl--vchview:has(.vch-view[data-vch-kind="opening"]){--win-accent:var(--acc-violet, #6941c6)}
/* The primary button takes the type's colour too, in its deep, text-safe shade. */
body.acc-fullscreen .mdl--vch .mdl__f .ok:not(.ok--soft){background:var(--win-accent, var(--acc-accent-deep))}
/* The quieter Save beside Save & print: outlined in the type's colour (acc-slip.css
   outlines it in the brand red, which put a red ring on a green receipt). */
body.acc-fullscreen .mdl--vch .mdl__f .ok.ok--soft{
  background:color-mix(in srgb, var(--win-accent, var(--acc-accent)) 8%, #fff);
  color:var(--win-accent, var(--acc-accent-deep));
  box-shadow:inset 0 0 0 1.5px var(--win-accent, var(--acc-accent-deep));
}
body.acc-fullscreen .mdl--vch :is(input,select):focus-visible{
  border-color:var(--win-accent, var(--acc-accent));
  box-shadow:0 0 0 3px color-mix(in srgb, var(--win-accent, var(--acc-accent)) 20%, transparent);
  outline:0;
}

/* ---------- the line grid ---------- */
body.acc-fullscreen .mdl--vch .vch-lines{max-height:min(52vh, 560px)}
body.acc-fullscreen .mdl--vch .vch-add{margin-top:10px}
@media (min-width:761px){
  body.acc-fullscreen .mdl--vch table.vch-grid{width:100%;table-layout:fixed}
  body.acc-fullscreen .mdl--vch .vch-grid .vch-c-acct{width:36%}
  body.acc-fullscreen .mdl--vch .vch-grid .vch-c-amt{width:136px}
  body.acc-fullscreen .mdl--vch .vch-grid .vch-c-applies{width:21%}
  body.acc-fullscreen .mdl--vch .vch-grid .vch-c-del{width:46px}
  /* A journal has two amount columns and a Settles picker, so the account and
     the picker give up width for the description, the one free-text box. */
  body.acc-fullscreen .mdl--vch:is(.mdl--vch-journal,.mdl--vch-opening) .vch-grid .vch-c-acct{width:27%}
  body.acc-fullscreen .mdl--vch:is(.mdl--vch-journal,.mdl--vch-opening) .vch-grid .vch-c-amt{width:118px}
  body.acc-fullscreen .mdl--vch:is(.mdl--vch-journal,.mdl--vch-opening) .vch-grid .vch-c-applies{width:17%}
  /* Salaries: six columns that must not squeeze a name to three letters. */
  body.acc-fullscreen .mdl--vch table.vch-grid--payroll{min-width:980px}
  body.acc-fullscreen .mdl--vch .vch-grid--payroll .pr-c-person{width:21%}
  body.acc-fullscreen .mdl--vch .vch-grid--payroll .pr-c-kind{width:16%}
  body.acc-fullscreen .mdl--vch .vch-grid--payroll .pr-c-acct{width:23%}
  body.acc-fullscreen .mdl--vch .vch-grid--payroll .pr-c-amt{width:132px}
  body.acc-fullscreen .mdl--vch .vch-grid--payroll .pr-c-del{width:46px}
  body.acc-fullscreen .mdl--vch.mdl--payroll{width:min(1320px, calc(100vw - 32px))}
}
body.acc-fullscreen .mdl--vch .vch-grid td{padding:6px 8px;vertical-align:middle}
body.acc-fullscreen .mdl--vch .vch-grid :is(input,select){width:100%;min-height:36px;box-sizing:border-box}
/* Line numbers, so "line 3 has no account" points at something on screen. */
body.acc-fullscreen .mdl--vch .vch-grid tbody{counter-reset:vchln}
body.acc-fullscreen .mdl--vch .vch-grid tbody tr{counter-increment:vchln}
body.acc-fullscreen .mdl--vch .vch-grid tbody td:first-child{position:relative;padding-inline-start:30px}
body.acc-fullscreen .mdl--vch .vch-grid tbody td:first-child::before{
  content:counter(vchln);position:absolute;inset-inline-start:8px;top:50%;transform:translateY(-50%);
  font-size:calc(11px * var(--acc-fs, 1));font-weight:600;color:var(--acc-ink-mute);font-variant-numeric:tabular-nums;
}
body.acc-fullscreen .mdl--vch .vch-grid thead th:first-child{padding-inline-start:30px}
/* Figures are figures: right-aligned in the reading direction, fixed-width
   digits, no spinner arrows to nudge a payment by one dollar. */
body.acc-fullscreen .mdl--vch input[type="number"]{
  text-align:end;font-variant-numeric:tabular-nums;direction:ltr;-moz-appearance:textfield;appearance:textfield;
}
body.acc-fullscreen .mdl--vch input[type="number"]::-webkit-outer-spin-button,
body.acc-fullscreen .mdl--vch input[type="number"]::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}
body.acc-fullscreen .mdl--vch .vch-grid th.num{text-align:end}
/* The remove button stays quiet until its row is the one being worked on. */
body.acc-fullscreen .mdl--vch .vch-grid td:last-child{text-align:center}
body.acc-fullscreen .mdl--vch .vch-grid .ibtn--del{opacity:.45;transition:opacity .15s;margin:0;width:30px;height:30px}
body.acc-fullscreen .mdl--vch .vch-grid tr:is(:hover,:focus-within) .ibtn--del,
body.acc-fullscreen .mdl--vch .vch-grid .ibtn--del:focus-visible{opacity:1}
@media (hover:none){ body.acc-fullscreen .mdl--vch .vch-grid .ibtn--del{opacity:1} }

/* What a refusal is about: the row (or box) turns red and nudges once. */
body.acc-fullscreen .mdl--vch tr.is-invalid td{background:var(--acc-red-soft, #fef3f2)}
body.acc-fullscreen .mdl--vch tr.is-invalid :is(input,select),
body.acc-fullscreen .mdl--vch :is(input,select).is-invalid{
  border-color:var(--acc-red, #b42318) !important;
  box-shadow:0 0 0 3px color-mix(in srgb, var(--acc-red, #b42318) 16%, transparent);
}
body.acc-fullscreen .mdl--vch .is-invalid{animation:vch-nudge .32s ease-out}
@keyframes vch-nudge{0%,100%{transform:none}30%{transform:translateX(-3px)}65%{transform:translateX(3px)}}

/* The total in words sits inside the Total panel (acc-totals.css). */

/* "This looks like a voucher already saved" — a warning, not an error. */
body.acc-fullscreen .vch-dup{
  border:1px solid #fedf89;background:#fffaeb;color:#7a2e0e;border-radius:var(--acc-r, 10px);
  padding:10px 14px;font-size:calc(13px * var(--acc-fs, 1));line-height:1.5;
}
body.acc-fullscreen .vch-dup[hidden]{display:none}
body.acc-fullscreen .vch-dup b{display:block;margin-bottom:2px;color:#93370d}

/* ---------- the footer's keys ---------- */
body.acc-fullscreen .mdl__f .vch-keys{
  margin-inline-end:auto;display:flex;flex-wrap:wrap;align-items:center;gap:6px 14px;
  font-size:calc(11.5px * var(--acc-fs, 1));color:var(--acc-ink-mute);
}
body.acc-fullscreen .vch-keys kbd{
  font:600 calc(10.5px * var(--acc-fs, 1))/1 ui-monospace, 'Cascadia Mono', Consolas, monospace;
  padding:2px 5px;border:1px solid var(--acc-line-firm, #b9c4d4);border-bottom-width:2px;border-radius:4px;
  background:var(--acc-surface, #fff);color:var(--acc-ink-soft);
}
/* A narrow form (Receive payment, 700px) gives the keys their own line above the
   buttons rather than squeezing "Record payment" onto two. */
body.acc-fullscreen .mdl--vch:not(.mdl--wide) .mdl__f{flex-wrap:wrap}
body.acc-fullscreen .mdl--vch:not(.mdl--wide) .mdl__f .vch-keys{flex:1 0 100%;margin:0 0 2px}
@media (max-width:900px), (pointer:coarse){ body.acc-fullscreen .mdl__f .vch-keys{display:none} }

/* ---------- the voucher window ---------- */
/* The record window is a 12-column grid (acc-app.css .accview); the bar and the
   words span all of it, or the bar lands in one twelfth and spills off-screen. */
body.acc-fullscreen .mdl .accview > :is(.vch-nav,.vch-words-box){grid-column:1 / -1}
body.acc-fullscreen .vch-nav{
  display:flex;align-items:center;justify-content:center;gap:4px;
  margin:0 0 14px;padding:6px;border:1px solid var(--acc-line);border-radius:12px;
  background:color-mix(in srgb, var(--vch-tone, var(--acc-accent)) 6%, var(--acc-surface, #fff));
  border-inline-start:4px solid var(--vch-tone, var(--acc-accent));
}
body.acc-fullscreen .vch-nav__b{
  width:36px;height:34px;display:grid;place-items:center;padding:0;cursor:pointer;
  border:1px solid var(--acc-line);border-radius:8px;background:var(--acc-surface, #fff);color:var(--acc-ink-soft);
  transition:background .15s, color .15s, border-color .15s;
}
body.acc-fullscreen .vch-nav__b:hover:not(:disabled){color:var(--acc-ink);border-color:var(--acc-line-firm);background:var(--acc-hover)}
body.acc-fullscreen .vch-nav__b:focus-visible{outline:2px solid var(--vch-tone, var(--acc-accent));outline-offset:1px}
body.acc-fullscreen .vch-nav__b:disabled{opacity:.35;cursor:default}
body.acc-fullscreen.acc-rtl .vch-nav__b svg,
body.acc-fullscreen [dir="rtl"] .vch-nav__b svg{transform:scaleX(-1)}
body.acc-fullscreen .vch-nav__no{min-width:160px;display:flex;flex-direction:column;align-items:center;line-height:1.2;padding:0 10px}
body.acc-fullscreen .vch-nav__no b{font-size:calc(15px * var(--acc-fs, 1));font-variant-numeric:tabular-nums;color:var(--acc-ink);direction:ltr;unicode-bidi:isolate}
body.acc-fullscreen .vch-nav__no small{font-size:calc(11.5px * var(--acc-fs, 1));color:var(--acc-ink-mute)}
body.acc-fullscreen .vch-words-box{
  display:flex;flex-wrap:wrap;gap:4px 12px;align-items:baseline;margin-top:12px;padding:10px 14px;
  border:1px dashed var(--acc-line-firm);border-radius:var(--acc-r, 10px);background:var(--acc-band, #eff4fa);
}
body.acc-fullscreen .vch-words-box span{font-size:calc(12px * var(--acc-fs, 1));color:var(--acc-ink-mute)}
body.acc-fullscreen .vch-words-box b{font-weight:600;color:var(--acc-ink-2)}

/* ---------- the registers ---------- */
/* The window's own action takes the voucher's colour, like the form's Save. */
body.acc-fullscreen .mdl--vchview .mdl__f .ok{background:var(--win-accent, var(--acc-accent-deep))}

/* A row opens its voucher on double-click, so it says it can be picked. */
body.acc-fullscreen .vch-screen tr.vch-tr{cursor:default}
body.acc-fullscreen .vch-screen tr.vch-tr:hover > td{background:var(--acc-band-hi, #e2ebf7)}
body.acc-fullscreen .vch-screen .pr-filters{padding:14px 16px 2px}
/* Ten columns do not fit a laptop, and the row's print / edit / delete were the
   ones cut off. Words wrap instead of widening the table, and the actions stay
   pinned at the row's end while the rest scrolls under them. */
body.acc-fullscreen .vch-screen .acctable td:not(.t-num):not(.t-act):not(.t-rn){white-space:normal;max-width:280px;overflow-wrap:anywhere}
body.acc-fullscreen .vch-screen .acctable :is(td,th).t-act{
  position:sticky;inset-inline-end:0;z-index:1;background:var(--acc-surface, #fff);
  box-shadow:-8px 0 8px -8px rgba(16,24,40,.18);
}
body.acc-fullscreen.acc-rtl .vch-screen .acctable :is(td,th).t-act{box-shadow:8px 0 8px -8px rgba(16,24,40,.18)}
body.acc-fullscreen .vch-screen .acctable thead th.t-act{background:var(--acc-head, #eff3f9)}
body.acc-fullscreen .vch-screen .acctable tfoot :is(td,th).t-act{background:var(--acc-total, #e8f6f2)}

/* ---------- shared chrome ---------- */
/* Offline: a bar that stays until the connection is back. */
.vch-offline{
  position:fixed;top:0;left:50%;transform:translateX(-50%);z-index:5000;max-width:calc(100vw - 32px);
  background:#b42318;color:#fff;padding:8px 18px;border-radius:0 0 10px 10px;
  font:600 13px/1.4 'IBM Plex Sans Arabic','IBM Plex Sans',system-ui,sans-serif;text-align:center;
  box-shadow:0 8px 24px rgba(16,24,40,.25);
}
.vch-offline::before{content:'';display:inline-block;width:8px;height:8px;border-radius:50%;background:#fecdca;margin-inline-end:8px;vertical-align:middle}

/* A toast says how it went: green done, amber look again, red nothing happened. */
#toast.is-ok{background:#067647;color:#fff}
#toast.is-warn{background:#b54708;color:#fff}
#toast.is-err{background:#b42318;color:#fff}
#toast.is-ok::before{content:'✓ '}
#toast.is-warn::before,#toast.is-err::before{content:'! '}

/* Delete: the number typed before the button wakes. */
.cdlg__type{margin:14px 0 4px;text-align:start}
.cdlg__type label{display:block;font-size:13px;font-weight:600;margin-bottom:6px;color:#344054}
.cdlg__type input{
  width:100%;height:42px;box-sizing:border-box;padding:0 12px;border:1px solid #d0d5dd;border-radius:8px;
  font:600 15px ui-monospace,'Cascadia Mono',Consolas,monospace;letter-spacing:.06em;text-align:center;
}
.cdlg__type input:focus{outline:0;border-color:#b42318;box-shadow:0 0 0 3px rgba(180,35,24,.16)}
.cdlg__type.is-ok input{border-color:#067647;box-shadow:0 0 0 3px rgba(6,118,71,.14)}
.cdlg__type small{display:block;margin-top:6px;color:#667085;font-size:12px}
#cdlg-ok:disabled{opacity:.45;cursor:not-allowed}

@media (prefers-reduced-motion:reduce){
  body.acc-fullscreen .mdl--vch .is-invalid{animation:none}
  body.acc-fullscreen .vch-nav__b, body.acc-fullscreen .mdl--vch .vch-grid .ibtn--del{transition:none}
}
