/* The sheet (decisions 23 and 25): «Facturas» as a page of the book, in the Atlas's own type.
   Ink, never fill. Its columns stand in families — the invoice, the client, the artists, the
   third parties, the gallery, the notes — each under its name and a fine rule of its ink (the
   four inks of atlas.css). A state is a small mark beside its word (atlas.css «.pill»); what
   is still owed is written in its family's ink, what is settled steps back to grey, and a
   closed invoice's whole row does. Every other row carries the light shade, the page's only
   fill but the pointer's. Totals close with a double rule, as in a ledger. The number stays
   in view while the sheet scrolls sideways. Light only (decision 19). Scoped to .hoja; the
   marks, the inks and the figures are atlas.css's, shared with every screen. */

.hoja {
  --h-fg: var(--ink); --h-muted: var(--muted); --h-line: var(--line); --h-rule: var(--rule);
  --h-ok: var(--green); --h-warn: var(--amber);
  --fam-h: 2rem;                   /* the height of the families' row, under which the columns' row sticks */
  --pin-w: 6.5rem;                 /* room for the pinned number: what scrolls beside it starts after this */
  display: grid; gap: 1rem; color: var(--h-fg); font-size: 0.93rem; line-height: 1.4;
}
.hoja .small { font-size: 0.85em; }

/* Toolbar: fields are a line to write on; the two buttons keep an edge. */
.hoja .toolbar { position: relative; display: flex; flex-wrap: wrap; gap: 0.5rem 1.1rem; align-items: center; }   /* «Columnas» opens against the toolbar, so it always fits */
.hoja .toolbar input[type=search] { flex: 1 1 16rem; width: auto; }
.hoja .toolbar input, .hoja .toolbar select {
  font: inherit; color: var(--h-fg); background-color: transparent; border: 0; border-bottom: 1px solid var(--edge); border-radius: 0; padding: 0.4rem 0.1rem; min-width: 0; width: auto;
}
.hoja .toolbar input:hover, .hoja .toolbar select:hover, .hoja .toolbar input:focus-visible, .hoja .toolbar select:focus-visible { border-bottom-color: var(--h-fg); }
.hoja .toolbar select { padding-right: 1.5rem; background-position: calc(100% - 0.5rem) 55%, calc(100% - 0.2rem) 55%; }
.hoja .count { margin-left: auto; font-size: 0.85rem; color: var(--h-muted); white-space: nowrap; }
.hoja .btn, .hoja a.btn {
  font: inherit; font-weight: 500; font-size: 0.9rem; color: var(--h-fg); background: var(--paper);
  border: 1px solid var(--edge); border-radius: 6px; padding: 0.38rem 0.75rem; cursor: pointer; text-decoration: none; display: inline-block; white-space: nowrap;
}
.hoja .btn:hover { border-color: var(--h-fg); }
.hoja .btn.small { padding: 0.15rem 0.55rem; font-size: 0.82rem; }
/* The two that write (as in the menu bar): in the ink of whose money it is. */
.hoja .btn.write { color: var(--ink-f); border-color: var(--ink-f); }
.hoja .btn.write:hover { box-shadow: inset 0 0 0 1px var(--ink-f); }
.hoja .pop {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 20; background: var(--paper); border: 1px solid var(--h-line); border-radius: 8px;
  padding: 0.9rem 1rem; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12); display: grid; grid-template-columns: repeat(3, minmax(9rem, 1fr)); gap: 0.9rem 1.5rem; max-width: 100%; max-height: 70vh; overflow: auto;
}
.hoja .pgroup { display: grid; gap: 0.1rem; align-content: start; }
.hoja .ptitle { font-weight: 500; font-size: 0.85rem; color: var(--ink-f); border-bottom: 2px solid var(--ink-f); padding-bottom: 0.25rem; margin-bottom: 0.25rem; }
.hoja .f-factura > .ptitle, .hoja .f-nota > .ptitle { border-bottom-color: var(--h-line); }
.hoja .pop label { display: flex; gap: 0.5rem; align-items: center; font-size: 0.88rem; padding: 0.15rem 0; cursor: pointer; margin: 0; font-weight: 400; text-transform: none; letter-spacing: 0; }
.hoja .pop label:hover { text-decoration: underline; text-underline-offset: 0.18em; }
.hoja .pop input { width: 1rem; height: 1rem; margin: 0; }
.hoja .pop > .btn { grid-column: 1 / -1; justify-self: start; }

/* The table: a ruled page. */
.hoja .frame { min-width: 0; }
.hoja .scroll { overflow: auto; max-height: calc(100vh - 15rem); min-height: 16rem; scroll-padding-left: var(--pin-w); }   /* what takes focus never hides under the pinned number */
.hoja table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.hoja th, .hoja td {
  --pl: 0.8rem; --pr: 0.8rem;
  padding: 0.7rem var(--pr) 0.7rem var(--pl); border: 0; border-bottom: 1px solid var(--h-rule); background: var(--paper); text-align: left; vertical-align: middle; white-space: nowrap;
}
.hoja th.first, .hoja td.first { --pl: 1.7rem; border-left: 1px solid var(--h-line); }          /* where a family begins: a rule and room */
.hoja th:first-child, .hoja td:first-child { --pl: 0.9rem; }
/* Head: the families' row, then the columns' row, both in view while the sheet scrolls down. */
.hoja thead th, .hoja thead td { position: sticky; z-index: 2; }
.hoja tr.fam th, .hoja tr.fam td {
  top: 0; height: var(--fam-h); padding-top: 0; padding-bottom: 0.15rem; font-weight: 500; font-size: 0.92rem; color: var(--ink-f);
  text-transform: none; letter-spacing: 0; border-bottom: 0; border-left: 0;
  /* a fine rule of the family's ink under its name, from its first column to its last */
  --rule-f: var(--ink-f);
  background: linear-gradient(var(--rule-f), var(--rule-f)) var(--pl) 100% / calc(100% - var(--pl) - var(--pr)) 2px no-repeat, var(--paper);
}
.hoja tr.fam .f-factura, .hoja tr.fam .f-nota { --rule-f: var(--h-line); }
.hoja tr.fam th.pin:has(+ td) { --pr: 0rem; }       /* the number's heading and the rest of its family share one rule */
.hoja tr.fam th.pin + td { --pl: 0rem; }
.hoja tr.fam td.f-nota:last-child { background: var(--paper); }
.hoja tr.fam .lab { position: sticky; left: var(--pin-w); display: inline-block; }      /* beside the pinned number, never under it */
.hoja tr.fam th.pin .lab { position: static; }
.hoja tr.cols th { top: var(--fam-h); font-weight: 500; font-size: 0.7rem; color: var(--muted); letter-spacing: 0.06em; padding-top: 0.55rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--h-fg); }
.hoja tr.cols th.first { border-left-color: transparent; }
.hoja th .sort { all: unset; cursor: pointer; font: inherit; color: inherit; letter-spacing: inherit; }
.hoja th .sort:hover { color: var(--h-fg); }
.hoja th[aria-sort] .sort { color: var(--h-fg); }
.hoja th[aria-sort=ascending] .sort::after { content: " ↑"; }
.hoja th[aria-sort=descending] .sort::after { content: " ↓"; }
.hoja th.num, .hoja td.num { text-align: right; }
.hoja td.num div + div { margin-top: 0.1rem; }
.hoja td.wrap { white-space: normal; min-width: 14rem; max-width: 26rem; }
.hoja td.flip { width: 2rem; text-align: center; }
.hoja .chev { all: unset; cursor: pointer; color: var(--h-muted); padding: 0 0.3rem; }
.hoja th .sort:focus-visible, .hoja .chev:focus-visible { outline: 2px solid var(--h-fg); outline-offset: 2px; }
/* Rows. An open invoice is written in ink and what it still owes in its family's ink; a closed
   one steps back to grey, a void one too, its number struck. Every other invoice carries the
   light shade (hojavista «alt»: the debts under an open row would throw a count off), and the
   row under the pointer a shade deeper; the invoice that is open is held by a rule of ink at
   its left, down to the end of its debts. */
.hoja tr.inv { cursor: pointer; --st: var(--h-warn); }
.hoja tr.inv td { transition: background-color 0.12s; }
.hoja tr.inv.alt td { background: var(--panel); }
.hoja tr.inv:hover td { background: var(--hover); }
.hoja tr.inv.open td { border-bottom: 0; padding-bottom: calc(0.7rem + 1px); }      /* no line, so the rule at the left runs unbroken into its debts */
.hoja tr.inv.open td:first-child { --st: var(--h-fg); }
.hoja tr.inv.cerrada { --st: var(--h-ok); color: var(--h-muted); }
.hoja tr.inv.anulada { --st: var(--edge); color: var(--h-muted); }
.hoja tr.inv.anulada td:first-child b { text-decoration: line-through; font-weight: 400; }
/* The number stays in view, like a page's margin; its edge carries the invoice's state. */
.hoja th.pin, .hoja td.pin { position: sticky; left: 0; }
.hoja thead th.pin { z-index: 4; }
.hoja tr.cols th.pin, .hoja tr.inv td.pin, .hoja tfoot td.pin { box-shadow: 1px 0 0 var(--h-line); }
.hoja tr.inv td.pin { z-index: 1; }
.hoja tr.inv td:first-child { box-shadow: inset 2px 0 0 var(--st); }                 /* the state's edge, whatever the first column is */
.hoja tr.inv td.pin:first-child { box-shadow: inset 2px 0 0 var(--st), 1px 0 0 var(--h-line); }
.hoja tr.block > td { --pl: 0rem; --pr: 0rem; padding: 0; white-space: normal; border-left: 0; border-bottom: 1px solid var(--h-fg); }
/* The open invoice stays in view while the wide table scrolls sideways. */
.hoja .bloque { position: sticky; left: 0; box-sizing: border-box; width: var(--page); max-width: 100%; display: grid; padding: 0.2rem 1rem 1.1rem 0.9rem; box-shadow: inset 2px 0 0 var(--h-fg); }
/* Only the invoice just opened fades in; a redraw (a search, a sort) leaves the open ones still. */
@keyframes hoja-open { from { opacity: 0; transform: translateY(-4px); } }
@media (prefers-reduced-motion: no-preference) {
  .hoja .bloque.fresh { animation: hoja-open 0.16s ease-out; }
}
/* Totals close the page with a double rule, as in a ledger. */
.hoja tfoot td { position: sticky; bottom: 0; font-weight: 500; border-top: 3px double var(--h-fg); border-bottom: 0; z-index: 1; }
.hoja tfoot td.first { border-left-color: transparent; }
.hoja tfoot td.pin { z-index: 3; }
.hoja .empty { padding: 2.5rem 1.2rem; text-align: center; color: var(--h-muted); }
.hoja .empty b { color: var(--h-fg); font-weight: 500; font-size: 1.05rem; }

.hoja .chips { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.hoja .chip {
  display: inline-flex; gap: 0.4rem; align-items: center; padding: 0.18rem 0.6rem; background: var(--paper); border: 1px solid var(--h-line); border-radius: 999px;
  font-size: 0.8rem; font-variant-numeric: tabular-nums; color: var(--h-fg); text-decoration: none; white-space: nowrap;
}
.hoja .chip:hover { border-color: var(--h-fg); }
.hoja .chip .n { color: var(--h-muted); }
.hoja .chip.plan { border-style: dashed; color: var(--h-muted); }

/* The open invoice: its debts, one under the other, each named in its family's ink. */
.hoja .cabecera { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem 1rem; padding: 0.55rem 0 0.7rem; }
.hoja .acts { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }
.hoja .deuda {
  display: grid; grid-template-columns: minmax(12rem, 1.2fr) minmax(14rem, 2fr) auto; gap: 0.5rem 1.25rem; align-items: start;
  padding: 0.7rem 0; border-top: 1px solid var(--h-line);
}
.hoja .who { display: grid; gap: 0.25rem; }
.hoja .figs { font-size: 0.85rem; font-variant-numeric: tabular-nums; color: var(--h-muted); }
.hoja .figs b { color: var(--h-fg); font-weight: 500; white-space: nowrap; }
.hoja .figs .pill { margin-left: 0.45rem; }

@media (max-width: 700px) {
  .hoja .deuda { grid-template-columns: 1fr; }
  .hoja .deuda > .btn { justify-self: start; }
  .hoja .scroll { max-height: none; }
  .hoja .count { margin-left: 0; }
  /* The head scrolls away with the page here: where a family begins, its rule takes the family's ink. */
  .hoja tr.inv td.first { border-left: 2px solid var(--ink-f); }
  .hoja .pop { grid-template-columns: repeat(2, minmax(0, 1fr)); left: 0; right: 0; }
}
