/* The Worksheet. Tokens match the extension; see DESIGN.md. */

@font-face {
  font-family: "Tally Sans";
  src: url("/fonts/tally-sans-regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Tally Sans";
  src: url("/fonts/tally-sans-bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ground: #ffffff;
  --head: #f1f4f2;
  --line: #c9d1cc;
  --line-soft: #e2e7e3;
  --ink: #1c2a22;
  --ink-soft: #54635a;
  --brand: #1a7f4b;
  --brand-strong: #146239;
  --brand-tint: #e6f3ec;
  --brand-ink: #ffffff;
  --control: #86948b;
  --font: "Tally Sans", Carlito, Calibri, "Segoe UI", system-ui, sans-serif;
  --gutter: 48px;
  --cols: 10;
  --row: 40px;
  --pad: 12px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 16px;
  scrollbar-color: #86948b var(--head);
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 18px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
}

::selection {
  background: var(--brand);
  color: var(--brand-ink);
}

a {
  color: var(--brand-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: -999px;
}

.skip:focus {
  left: 8px;
  top: 8px;
  z-index: 20;
  padding: 8px 12px;
  background: var(--ground);
}

/* ------------------------------------------------------------ app bar */

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 28px;
  min-height: 56px;
  padding: 0 20px;
  background: var(--brand);
  color: var(--brand-ink);
}

.bar a {
  color: inherit;
  text-decoration: none;
}

.bar-name {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0;
  font-size: 20px;
  font-weight: 700;
}

.bar nav {
  display: flex;
  flex-wrap: wrap;
}

.bar nav a {
  padding: 16px 12px;
  font-size: 17px;
}

.bar nav a:hover {
  background: rgb(255 255 255 / 0.14);
}

.bar nav a[aria-current="page"] {
  background: var(--ground);
  color: var(--brand-strong);
  font-weight: 700;
}

.bar :focus-visible {
  outline-color: var(--brand-ink);
  outline-offset: -3px;
}

/* -------------------------------------------------------- formula bar */

.fx {
  display: flex;
  align-items: center;
  min-height: 38px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 16px;
}

.fx-name {
  width: var(--gutter);
  border-right: 1px solid var(--line);
  line-height: 38px;
  text-align: center;
  font-size: 13px;
}

.fx-mark {
  padding: 0 14px;
  font-style: italic;
}

.fx-value {
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* -------------------------------------------------------------- sheet */

.letters,
.r {
  display: grid;
  grid-template-columns: var(--gutter) repeat(var(--cols), minmax(0, 1fr));
}

.letters {
  position: sticky;
  top: 0;
  z-index: 4;
}

.letters b,
.r > b {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--head);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 400;
  line-height: 30px;
  text-align: center;
}

.r > b {
  grid-column: 1;
  line-height: var(--row);
}

/* Grid lines are drawn behind the content, one per column. */
.r {
  min-height: var(--row);
  border-bottom: 1px solid var(--line-soft);
  background-image: linear-gradient(to right, transparent calc(100% - 1px), var(--line-soft) calc(100% - 1px));
  background-position: var(--gutter) 0;
  background-size: calc((100% - var(--gutter)) / var(--cols)) 100%;
  background-repeat: repeat;
}

.r > :not(b) {
  padding: 0 var(--pad);
  line-height: var(--row);
}

.span-all {
  grid-column: 2 / -1;
}

/* Merged cells: the headline covers rows 2 and 3. */
.r.big {
  border-bottom-color: transparent;
  background-image: none;
}

.r.big > b {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

h1 {
  margin: 0;
  font-size: clamp(2.5rem, 5.6vw, 5.25rem);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.hero h1 {
  padding-top: 18px;
  padding-bottom: 14px;
  line-height: 1.08;
}

/* The two row numbers of the merged headline rows. */
.r.big > b {
  flex-direction: column;
  justify-content: space-around;
}

.r.big > b i {
  font-style: normal;
}

.green {
  display: block;
  color: var(--brand);
}

.r.tall {
  --row: 64px;
  background-image: none;
}

.lede {
  grid-column: 2 / span 6;
  align-self: center;
  margin: 0;
  font-size: 21px;
  line-height: 1.35 !important;
}

.cta {
  display: flex;
  grid-column: span 4;
  align-items: stretch;
  padding: 0 !important;
}

.install {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  outline: 3px solid var(--brand);
  outline-offset: -3px;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  transition: background-color 150ms;
}

a.install:hover {
  background: var(--brand-strong);
}

a.install:focus-visible {
  outline: 3px solid var(--ink);
}

/* Not published yet: the selected cell, without an action. */
.install.is-soon {
  background: var(--brand-tint);
  color: var(--brand-strong);
}

/* The sample export. Its cells span several columns, so they carry their
   own borders instead of the column lines behind them. */

/* Frozen panes: the header row stays under the column letters, with the
   darker line a sheet draws below a frozen row. */
.head {
  position: sticky;
  top: 31px;
  z-index: 3;
  box-shadow: 0 1px 0 var(--control);
}

.sample .r {
  background-image: none;
}

.sample [role="cell"],
.sample [role="columnheader"],
.sample .r::after {
  border-right: 1px solid var(--line-soft);
}

.sample .r:not(.note)::after {
  grid-column: span 1;
  content: "";
}

.note p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 16px;
}

.c-title {
  grid-column: 2 / span 3;
}

.c-start,
.c-end {
  grid-column: span 2;
}

.sample [role="cell"],
.sample [role="columnheader"] {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sample [role="cell"] {
  cursor: cell;
}

.num {
  text-align: right;
}

.head {
  border-bottom-color: var(--line);
  background-color: var(--head);
}

.head [role="columnheader"] {
  padding: 0;
}

.head button {
  width: 100%;
  height: 100%;
  padding: 0 var(--pad);
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-align: inherit;
  cursor: pointer;
}

.head button:hover {
  background: var(--line-soft);
}

.head button:focus-visible {
  outline-offset: -2px;
}

/* The sort mark is drawn, not typed. */
.head [aria-sort="ascending"] button::after,
.head [aria-sort="descending"] button::after {
  display: inline-block;
  margin-left: 8px;
  border: 5px solid transparent;
  content: "";
}

.head [aria-sort="ascending"] button::after {
  border-top: 0;
  border-bottom: 7px solid var(--brand);
  transform: translateY(-2px);
}

.head [aria-sort="descending"] button::after {
  border-top: 7px solid var(--brand);
  border-bottom: 0;
  transform: translateY(-1px);
}

.total {
  font-weight: 700;
}

.is-selected {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
  background: var(--brand-tint);
}

/* ------------------------------------------------------------ sections */

/* The sheet continues below the sample: the row-number gutter runs down the
   page, every heading, paragraph and table row is a numbered row, and
   tables are cell ranges across the full width. */

main {
  counter-reset: row 15;
}

.block {
  position: relative;
  padding: 0 0 0 var(--gutter);
  background: linear-gradient(
    to right,
    var(--head) calc(var(--gutter) - 1px),
    var(--line) calc(var(--gutter) - 1px),
    var(--line) var(--gutter),
    transparent var(--gutter)
  );
}

.block h2,
.block .prose,
.block .close,
.grid tr {
  counter-increment: row;
}

.block h2::before,
.block .prose::before,
.block .close::before,
.grid tr > :first-child::before {
  position: absolute;
  left: 0;
  width: var(--gutter);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: inherit;
  text-align: center;
  content: counter(row);
}

h2 {
  margin: 0;
  padding: 56px var(--pad) 14px;
  border-bottom: 1px solid var(--line-soft);
  font-size: clamp(1.75rem, 3vw, 2.5rem);
  line-height: 1.12;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.block h2::before {
  line-height: 2.2;
}

.prose {
  margin: 0;
  padding: 12px var(--pad);
  border-bottom: 1px solid var(--line-soft);
}

.prose {
  max-width: none;
}

.prose .prose-text {
  display: block;
  max-width: 68ch;
}

.table-scroll {
  border-bottom: 1px solid var(--line-soft);
}

/* Fixed layout with widths in tenths, so every column edge of a table
   falls on a line of the lettered grid above. */
.grid {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.grid th,
.grid td {
  padding: 9px var(--pad);
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
}

.grid tbody tr:last-child > * {
  border-bottom: 0;
}

.grid thead th {
  border-bottom-color: var(--line);
  background: var(--head);
}

.grid tbody th {
  font-weight: 700;
}

.grid thead th:first-child {
  width: 20%;
}

.grid thead th:nth-child(2):not(:last-child) {
  width: 30%;
}

.grid thead th.narrow {
  width: 10%;
}

.grid thead th.narrow + th {
  width: 20%;
}

.grid .num {
  text-align: right;
}

.close {
  display: flex;
  min-height: 64px;
  margin: 0;
  padding: 0 0 0 0;
}

.close .install {
  max-width: 440px;
}

/* Sheet tabs: the sections of the page. */

.tabs {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  overflow-x: auto;
  padding-left: var(--gutter);
  border-top: 1px solid var(--line);
  background: var(--head);
}

.tabs a {
  flex: none;
  padding: 9px 18px;
  border-right: 1px solid var(--line);
  color: var(--ink);
  font-size: 16px;
  text-decoration: none;
  white-space: nowrap;
}

.tabs a:first-child {
  border-left: 1px solid var(--line);
}

.tabs a:hover {
  background: var(--line-soft);
}

.tabs a.is-current {
  margin-top: -1px;
  border-bottom: 3px solid var(--brand);
  background: var(--ground);
  color: var(--brand-strong);
  font-weight: 700;
}

.tabs a:focus-visible {
  outline-offset: -2px;
}

/* -------------------------------------------------------------- footer */

.foot {
  padding: 28px 20px 36px calc(var(--gutter) + var(--pad));
  color: var(--ink-soft);
  font-size: 15px;
}

.foot p {
  max-width: 80ch;
  margin: 0 0 6px;
}

.doc .foot {
  margin-top: 64px;
  border-top: 1px solid var(--line);
}

/* ------------------------------------------------------- reading pages */

.prose-page {
  max-width: 44rem;
  padding: 48px 20px 0 calc(var(--gutter) + var(--pad));
}

.prose-page h1 {
  margin-bottom: 8px;
  font-size: clamp(2.25rem, 4.4vw, 3.25rem);
}

.prose-page h2 {
  margin: 40px 0 10px;
  font-size: 1.5rem;
  letter-spacing: 0;
}

.prose-page h3 {
  margin: 24px 0 4px;
  font-size: 1.125rem;
}

.prose-page p,
.prose-page ul,
.prose-page ol {
  margin: 0 0 14px;
}

.prose-page ul,
.prose-page ol {
  padding-left: 1.25em;
}

.prose-page li {
  margin-bottom: 6px;
}

.prose-page li::marker {
  color: var(--brand);
}

.meta {
  color: var(--ink-soft);
}

code {
  padding: 1px 5px;
  border: 1px solid var(--line-soft);
  background: var(--head);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.86em;
  overflow-wrap: anywhere;
}

/* -------------------------------------------------------------- narrow */

@media (max-width: 860px) {
  :root {
    --gutter: 32px;
    --cols: 4;
    --pad: 10px;
  }

  body {
    font-size: 17px;
  }

  .bar {
    padding: 0 12px;
  }

  .bar nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
  }

  .bar nav a {
    flex: none;
    padding: 10px 10px 12px;
  }

  /* Tables wrap inside the viewport: nothing is read by scrolling sideways. */
  .grid th,
  .grid td {
    padding: 8px;
  }

  .grid td:first-child,
  .grid tbody th {
    white-space: normal;
  }

  /* Three columns: A and B wide, C for the hours. The column lines behind
     empty rows are dropped, since the columns are no longer equal. */
  .letters,
  .r {
    grid-template-columns: var(--gutter) minmax(0, 1.5fr) minmax(0, 1.5fr) minmax(0, 0.8fr);
  }

  .r {
    background-image: none;
  }

  .letters b:nth-child(n + 5) {
    display: none;
  }

  .letters,
  .head {
    position: static;
  }

  /* Titles carry the client names: they wrap instead of being cut. */
  .sample .c-title {
    padding-top: 8px;
    padding-bottom: 8px;
    line-height: 1.3;
    white-space: normal;
  }

  .sample .r > :not(b):not(.c-title) {
    /* Centred inside a full-height cell, so the cell rule is not broken. */
    align-content: center;
  }

  /* Row 5 keeps its number; the sentence and the action stack inside it. */
  .r.tall {
    grid-template-rows: auto auto;
  }

  .r.tall > b {
    display: flex;
    grid-row: 1 / 3;
    align-items: center;
    justify-content: center;
  }

  .lede {
    grid-column: 2 / -1;
    padding: 14px var(--pad) !important;
  }

  .cta {
    grid-column: 2 / -1;
    min-height: 60px;
  }

  /* The sample shows Title, Start and Hours; End and Calendar are in the
     file but not on a narrow screen. */
  .sample {
    font-size: 15px;
  }

  .sample .c-title,
  .sample .c-start,
  .sample .c-hours {
    grid-column: auto;
  }

  .sample .c-end,
  .sample .c-cal,
  .sample .r::after {
    display: none;
  }

  .note p {
    padding-top: 8px !important;
    padding-bottom: 8px !important;
    line-height: 1.35 !important;
  }

  .head {
    top: 31px;
  }

  h2 {
    padding-top: 40px;
  }

  .grid th,
  .grid td {
    padding: 8px;
  }

  /* Column A of the narrow grid is 1.5 of 3.8 parts wide. */
  .grid thead th:first-child {
    width: 39.47%;
  }

  .grid thead th:nth-child(2):not(:last-child) {
    width: 30%;
  }

  .grid thead th.narrow {
    width: 16%;
  }

  .grid thead th.narrow + th {
    width: 30%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  * {
    transition: none !important;
  }
}
