/* What the sinking fund calculator, /sinking-fund-calculator, adds to style.css and tools.css (both loaded first).
   Colours are the site's tokens only, so the page follows the site into dark mode and onto paper. What the script
   hides (a field the schedule doesn't need, a note with nothing to say, a result that can't be worked out yet) is
   hidden by tools.css: `.tool [hidden]`. */

/* The form's two groups, "How you're paid" and "What you're saving for": each takes the tool's full width, with a
   rule between them. */
.tool .sf-set { flex: 1 0 100%; min-width: 0; }
.tool .sf-set + .sf-set { margin-top: 8px; padding-top: 22px; border-top: 1px solid var(--card-line); }
/* A heading inside the tool: the two groups, and the list of paydays under the result. */
.doc .tool h2 { font-size: 1.2rem; margin: 0; padding: 0; }
/* The schedule's fields, in as many even columns as fit: three or four on a wide screen, one on a narrow phone. */
.sf-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 14px 18px; align-items: end; margin-top: 14px; }
.sf-fields label, .sf-row label { min-width: 0; }
.sf-fields input, .sf-fields select, .sf-row input { width: 100%; min-width: 0; }
/* What is typed reads as text, not as a field's name, and is large enough that a phone doesn't zoom in on it. One
   height for every field, since a browser draws a date a little taller than a name, and their names must line up. */
.tool .sf-set input, .tool .sf-set select { font-weight: 400; font-size: 1rem; height: 46px; }
.tool .sf-row .sf-remove { min-height: 46px; }
/* The line that says the rows are samples, with the button that clears them at its end, or under it on a phone.
   Its layout is set by the class alone, so that tools.css's `.tool [hidden]` still hides it once they are gone. */
.sf-samples { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.tool .sf-samples { color: var(--muted); font-size: 0.95rem; margin-top: 8px; }
.tool .sf-samples span { flex: 1 1 18rem; }
/* Beside the buttons, once the page holds all the rows it will. */
.tool .sf-full { align-self: center; color: var(--muted); font-size: 0.9rem; }

/* The rows of things to save for: a name, an amount, a due date and a Remove button. On a wide screen they line up
   like a table, and only the first row shows the fields' names; the other rows keep them for screen readers. */
.sf-rows { display: grid; gap: 10px; margin-top: 14px; }
.sf-row { display: grid; grid-template-columns: minmax(0, 1fr) 7.5rem 10.75rem auto; gap: 6px 12px; align-items: end; }
@media (min-width: 721px) {
  .sf-row + .sf-row label > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
/* What a row still needs, under it. A row that can't be counted, or that needs its money now, says so in ink, and
   the field at fault gets a heavier edge. */
.tool .sf-row .sf-msg { grid-column: 1 / -1; margin: 0 0 4px; color: var(--muted); font-size: 0.9rem; }
.tool .sf-row .sf-strong { color: var(--ink); font-weight: 600; }
.tool .sf-row input[aria-invalid="true"] { border-color: var(--gold-ink); box-shadow: inset 0 0 0 1px var(--gold-ink); }

/* On a phone or a narrow window, where the name would be squeezed, a row is two lines: the name with its Remove
   button, then the amount beside the date, with a rule between rows. */
@media (max-width: 720px) {
  .sf-rows { gap: 0; }
  .sf-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; padding-block: 14px; border-top: 1px solid var(--card-line); }
  .sf-row:first-child { padding-top: 0; border-top: 0; }
  .sf-row .sf-name { grid-area: 1 / 1 / 2 / 3; }
  .sf-row .sf-remove { grid-area: 1 / 3; }
  .sf-row .sf-amount { grid-area: 2 / 1; }
  .sf-row .sf-due { grid-area: 2 / 2 / 3 / 4; }
  .tool .sf-row .sf-msg { grid-row: 3; margin-bottom: 0; }
}

/* The result, under a rule: the headline, then a smaller line for what the headline leaves out. */
.sf-live { margin-top: 24px; border-top: 1px solid var(--card-line); }
.tool .sf-also { color: var(--muted); margin-top: 6px; }
.tool .sf-also + .sf-also { margin-top: 2px; }

/* The table of things to save for. Money and counts sit on the right, a note about the last check goes under its
   amount, a thing that needs its money now is picked out, and one that can't be counted is set back. */
.doc .sf-table { margin-top: 18px; }
.doc .sf-money { text-align: right; }
.doc .sf-table tbody th { overflow-wrap: anywhere; }
.doc .sf-table thead th, .doc .sf-table time, .doc .sf-table small { white-space: nowrap; }
.doc .sf-table small, .doc .sf-paydays small { display: block; color: var(--muted); font-size: 0.82rem; font-weight: 400; }
.doc tr.sf-now th, .doc tr.sf-now td { background: var(--gold-soft); }
.doc tr.sf-now td:last-child { font-weight: 600; color: var(--gold-ink); }
.doc tr.sf-out th, .doc tr.sf-out td { color: var(--muted); }
.doc tr.sf-total th, .doc tr.sf-total td { font-weight: 600; background: var(--wash); }
/* In a window too narrow for the table at full size but too wide for the phone's cards, the table tightens up, so
   a name isn't squeezed until its words break. */
@media (min-width: 641px) and (max-width: 760px) {
  .doc .sf-table th, .doc .sf-table td { padding-inline: 9px; font-size: 0.95rem; }
  .doc .sf-table thead th { font-size: 1rem; white-space: normal; }
}
/* Where a phone shows each row as a card, the values line up on the left with a little more room than the site
   gives them, a note may wrap, a cell with nothing in it goes, and a row's tint covers its whole card. */
@media (max-width: 640px) {
  .doc .sf-table td { grid-template-columns: 5.75em minmax(0, 1fr); }
  .doc .sf-table .sf-money { text-align: left; }
  .doc .sf-table small { white-space: normal; }
  .doc .sf-table td:empty { display: none; }
  .doc .sf-table tr.sf-now { background: var(--gold-soft); }
  .doc .sf-table tr.sf-total { background: var(--wash); }
  .doc .sf-table tr.sf-now th, .doc .sf-table tr.sf-now td, .doc .sf-table tr.sf-total th, .doc .sf-table tr.sf-total td { background: none; }
}

/* What to set aside on each of the next paydays: a narrow table that keeps its two columns on a phone. */
.doc .tool .sf-ahead h2 { margin-top: 26px; }
.sf-paydays { margin-top: 10px; max-width: 30rem; border: 1px solid var(--card-line); border-radius: var(--radius); overflow: hidden; }
.doc .sf-paydays table { min-width: 0; }
.doc .sf-paydays tbody th { font-weight: 500; }
.tool .sf-after { color: var(--muted); font-size: 0.95rem; }

/* Under the result: one line that hands off to the app, then the other free tools. */
.tool .next { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--card-line); }
.tool .next + .next { margin-top: 8px; padding-top: 0; border-top: 0; }

/* On paper: the sheet's own title and the schedule in words in place of the page's headline and form, then the
   headline number, the two tables and the line that says where the sheet came from. */
@media print {
  .tool { margin-top: 0; }
  .sheet-title { font: 400 22pt/1.1 var(--serif); letter-spacing: -0.02em; }
  .doc .sheet-line { font-size: 10.5pt; margin-top: 3pt; color: var(--muted); }
  .sf-live { margin-top: 0; border-top: 0; }
  .tool .answer { margin-top: 12pt; }
  .tool .sf-also { font-size: 10.5pt; margin-top: 3pt; }
  /* The two tables lose their boxes, which would be left open where a long table crosses to the next sheet, and
     get a rule under their headings; their words line up with the sheet's left and right edges. */
  .doc .sf-table { margin-top: 12pt; border: 0; }
  .sf-paydays { border: 0; border-radius: 0; }
  .doc .sf-table th, .doc .sf-table td, .doc .sf-paydays th, .doc .sf-paydays td { padding: 4.5pt 8pt; font-size: 10pt; }
  .doc .sf-table thead th, .doc .sf-paydays thead th { border-bottom: 0.75pt solid var(--ink); }
  .doc .sf-table tr > :first-child, .doc .sf-paydays tr > :first-child { padding-left: 0; }
  .doc .sf-table tr > :last-child, .doc .sf-paydays tr > :last-child { padding-right: 0; }
  .doc .sf-table small, .doc .sf-paydays small { font-size: 8.5pt; }
  .doc .tool .sf-ahead h2 { font-size: 12pt; margin-top: 14pt; }
  .tool .sf-after { font-size: 10pt; }
  /* A long table may run on to a second sheet, between rows; the list of paydays stays in one piece. */
  .sf-table tr, .sf-ahead { break-inside: avoid; }
}
