/* The trapdoor table: a ledger in ink on a white page, hairline rules, the selection in pale ledger green and a dark
   green bar for the actions. */
:root {
  --page: #ffffff;          /* the page and the rows */
  --ink: #16181b;
  --muted: #6b7079;
  --faint: #959aa3;         /* the column heads */
  --rule: #edeef1;          /* the lines between rows */
  --rule-strong: #dfe2e6;   /* the line under the heads */
  --hover: #f7f8f9;         /* a row under the pointer */
  --press: #edeff2;         /* the details button under the pointer */
  --box: #c3c8cf;           /* an empty box */
  --box-hover: #959ca6;     /* an empty box under the pointer */
  --check: #12804e;         /* the boxes ticked, the focus */
  --band: #e0f3e7;          /* the selection */
  --band-edge: #b5dec5;     /* its outline */
  --band-deep: #bfe6cf;     /* the light that runs through it on Export */
  --pit: #0c1a13;           /* the dark under the table */
  --bar: #0f1713;           /* the bar of actions */
  --bar-ink: #eef4f0;
  --bar-muted: #8fa398;
  --bar-accent: #8de4b4;    /* Undo and the time left for it */
  --danger: #ff9384;        /* Delete */
  --overdue: #c4441b;
  --sent: #4c5868;
  --draft: #8c919a;
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Archivo Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* held from the top: rows that go or come back change the height, and a table kept in the middle would jump */
.stage {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  align-content: start;
  padding: clamp(32px, 12vh, 118px) 16px 48px;
}

.ledger {
  width: min(740px, 100%);
}

.ledger__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px 14px;
}

.ledger__title {
  margin: 0;
  font-size: 27px;
  font-weight: 720;
  font-stretch: 118%;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.ledger__note {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---------------------------------------------------------------- the table */
.frame {
  position: relative;
  isolation: isolate;
}

/* under the table: the holes the rows fall through */
.pit {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.table {
  position: relative;
  z-index: 1;
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.table th {
  height: 42px;
  padding: 0 12px;
  border-bottom: 1px solid var(--rule-strong);
  background: var(--page);
  color: var(--faint);
  font-size: 13px;
  font-weight: 560;
  letter-spacing: 0.01em;
  text-align: left;
  white-space: nowrap;
}

/* the rows are solid: sliding up, they cover the hole */
.table td {
  height: 52px;
  padding: 0 12px;
  border-bottom: 1px solid var(--rule);
  background: var(--page);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 0.18s ease;
}

.table .pick {
  width: 52px;
  padding: 0 0 0 8px;
  overflow: visible;
}

.table .col-inv {
  width: 104px;
}

.table .col-due {
  width: 86px;
}

.table .num {
  width: 118px;
  text-align: right;
}

.table .state-cell {
  width: 112px;
}

.table .more {
  width: 46px;
  padding: 0 8px 0 0;
  text-align: right;
}

.row {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .row:hover td {
    background: var(--hover);
  }
}

.client__name {
  font-weight: 620;
}

.client__meta {
  display: none;
}

.col-inv {
  color: var(--muted);
}

.amount {
  font-weight: 540;
}

/* an open row and its details read as one */
.row.is-open td {
  border-bottom-color: transparent;
}

/* ---------------------------------------------------------------- the boxes */
.check {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.check input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.check__box {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--box);
  border-radius: 5px;
  background: var(--page);
  pointer-events: none;
  transition: background-color 0.16s ease, border-color 0.16s ease;
}

.check__box svg {
  width: 14px;
  height: 14px;
  overflow: visible;
  fill: none;
  stroke: var(--page);
  stroke-width: 2.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.check__tick,
.check__dash {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 0.16s ease-in;
}

.row.is-picked .check__box,
.check.is-on .check__box,
.check.is-some .check__box {
  border-color: var(--check);
  background: var(--check);
}

.row.is-picked .check__tick,
.check.is-on .check__tick,
.check.is-some .check__dash {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.24s ease-out 0.05s;
}

@media (hover: hover) {
  .row:hover .check__box,
  .check:hover .check__box {
    border-color: var(--box-hover);
  }

  .row.is-picked:hover .check__box,
  .row.is-picked .check:hover .check__box,
  .check.is-on:hover .check__box,
  .check.is-some:hover .check__box {
    border-color: var(--check);
  }
}

.check input:focus-visible + .check__box {
  outline: 2px solid var(--check);
  outline-offset: 3px;
}

/* ---------------------------------------------------------------- the states */
.state-slot {
  position: relative;
  display: inline-flex;
  height: 22px;
  overflow: hidden;
  vertical-align: middle;
}

.state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  font-size: 14px;
  font-weight: 580;
  white-space: nowrap;
}

.state.is-coming {
  position: absolute;
  left: 0;
  top: 0;
}

.state svg {
  flex: none;
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.state--paid {
  color: var(--ink);
}

.state--paid svg {
  color: var(--check);
  stroke-width: 2.5;
}

.state--overdue {
  color: var(--overdue);
}

.state--sent {
  color: var(--sent);
}

.state--draft {
  color: var(--draft);
}

/* ---------------------------------------------------------------- the details */
.more__btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  transition: color 0.2s ease, background-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.more__btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.more__btn:active {
  transform: scale(0.9);
  transition: color 0.2s ease, background-color 0.2s ease, transform 0.1s ease-out;
}

@media (hover: hover) {
  .row:hover .more__btn {
    color: var(--ink);
  }

  .more__btn:hover {
    background: var(--press);
  }
}

.row.is-open .more__btn {
  color: var(--ink);
}

.more__btn:focus-visible {
  outline: 2px solid var(--check);
  outline-offset: 1px;
}

.detail td {
  height: auto;
  padding: 0;
  border-bottom: 1px solid var(--rule);
  background: var(--page);
  white-space: normal;
}

.detail__clip {
  overflow: hidden;
}

/* lined up with the columns above: what it is under Client, the lines under Invoice to Amount, what happened
   under Status (the widths come from the heads) */
.detail__body {
  display: grid;
  grid-template-columns: var(--w-pick, 52px) var(--w-client, 1fr) var(--w-mid, 308px) var(--w-end, 158px);
  padding: 0 0 18px;
  font-size: 14px;
  line-height: 20px;
}

.detail__part {
  min-width: 0;
  margin: 0;
  padding: 0 12px;
}

.detail__info {
  grid-column: 2;
}

.detail__project {
  margin: 0;
  font-weight: 620;
}

.detail__who {
  margin: 2px 0 0;
  color: var(--muted);
}

.detail__lines {
  grid-column: 3;
}

.detail__line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  color: var(--muted);
}

.detail__line + .detail__line {
  margin-top: 2px;
}

.detail__line b {
  color: var(--ink);
  font-weight: 540;
  white-space: nowrap;
}

.detail__trail {
  grid-column: 4;
  list-style: none;
  color: var(--muted);
}

.detail__trail li + li {
  margin-top: 2px;
}

.detail__trail li:last-child {
  color: var(--ink);
}

/* ---------------------------------------------------------------- the selection */
.band {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  mix-blend-mode: multiply;
}

.band__shape,
.band path {
  fill: var(--band);
  stroke: var(--band-edge);
  stroke-width: 1;
}

.band.is-plain path {
  stroke: none;
}

.band__stop {
  stop-color: var(--band);
}

.band__stop--deep {
  stop-color: var(--band-deep);
}

/* ---------------------------------------------------------------- the trapdoor */
/* the dark under the table, between rows that fall or slide: deepest under the edge above (the script draws it) */
.pit__gaps {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.pit__stop {
  stop-color: var(--pit);
  stop-opacity: 0.16;
}

.pit__stop--top {
  stop-opacity: 0.62;
}

.slab {
  position: absolute;
  left: 0;
  right: 0;
}

/* the door: the rows as they were, white like them, the selection on them */
.slab__leaf {
  position: absolute;
  inset: 0;
  background: var(--page);
  transform-origin: 50% 0;
  backface-visibility: hidden;
}

.slab__tint {
  position: absolute;
  inset: 0 4px;
  border-radius: var(--radius, 12px);
  background: var(--band);
  box-shadow: inset 0 0 0 1px var(--band-edge);
}

.slab--plain .slab__tint {
  display: none;
}

.slab__shade {
  position: absolute;
  z-index: 2;
  inset: 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--pit) 18%, transparent), color-mix(in srgb, var(--pit) 66%, transparent));
  opacity: 0;
}

.table--ghost td {
  background: transparent;
}

.table--ghost tr:last-child td {
  border-bottom-color: transparent;
}

/* ---------------------------------------------------------------- the foot: what is outstanding, or the bar */
.foot {
  position: relative;
  z-index: 1;
  height: 66px;
  background: var(--page);
}

.sum {
  position: absolute;
  inset: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.sum__due .roll {
  color: var(--ink);
  font-weight: 600;
}

.roll {
  position: relative;
  display: inline-block;
  overflow: hidden;
  vertical-align: bottom;
}

.roll > span {
  display: inline-block;
}

.roll > .roll__old {
  position: absolute;
  left: 0;
  top: 0;
}

.bar {
  position: absolute;
  left: 0;
  top: 9px;
  height: 48px;
  visibility: hidden;
}

.bar.is-shown {
  visibility: visible;
}

.bar__bg {
  position: absolute;
  left: 0;
  top: 0;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--bar);
  box-shadow: 0 16px 30px -16px color-mix(in srgb, var(--bar) 70%, transparent), 0 2px 6px -2px color-mix(in srgb, var(--bar) 30%, transparent);
  transform-origin: 24px 50%;
}

.bar__set {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 48px;
  padding: 0 6px;
  color: var(--bar-ink);
  font-size: 14px;
  white-space: nowrap;
  visibility: hidden;
}

.bar__count {
  margin: 0 8px 0 4px;
  font-weight: 620;
  font-variant-numeric: tabular-nums;
}

.bar__sum {
  margin-left: 6px;
  color: var(--bar-muted);
  font-weight: 500;
}

.bar__rule {
  width: 1px;
  height: 20px;
  margin: 0 6px 0 2px;
  background: color-mix(in srgb, var(--bar-ink) 14%, transparent);
}

.bar__icon,
.bar__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 580;
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.bar__icon {
  width: 36px;
  padding: 0;
  color: var(--bar-muted);
}

.bar__icon svg,
.bar__btn svg {
  flex: none;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bar__btn--danger {
  color: var(--danger);
}

.bar__btn--undo {
  color: var(--bar-accent);
}

/* the button fades its insides, not itself: its own opacity belongs to the script */
.bar__btn > * {
  transition: opacity 0.2s ease;
}

.bar__btn[aria-disabled='true'] {
  cursor: default;
}

.bar__btn[aria-disabled='true'] > * {
  opacity: 0.38;
}

@media (hover: hover) {
  .bar__icon:hover,
  .bar__btn:hover {
    background: color-mix(in srgb, var(--bar-ink) 9%, transparent);
    color: var(--bar-ink);
  }

  .bar__btn--danger:hover {
    background: color-mix(in srgb, var(--danger) 13%, transparent);
    color: var(--danger);
  }

  .bar__btn--undo:hover {
    background: color-mix(in srgb, var(--bar-accent) 12%, transparent);
    color: var(--bar-accent);
  }

  .bar__btn[aria-disabled='true']:hover {
    background: transparent;
  }
}

/* pressed: down quickly, back at once (the transition lives only in the pressed state, so it never slows the
   script's own moves of these buttons) */
.bar__icon:active,
.bar__btn:active {
  transform: scale(0.95);
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.1s ease-out;
}

.bar__btn[aria-disabled='true']:active {
  transform: none;
}

.bar__icon:focus-visible,
.bar__btn:focus-visible {
  outline: 2px solid var(--bar-accent);
  outline-offset: -2px;
}

/* Export says Exported: the arrow into the tray gives way to a tick */
.bar__glyph {
  position: relative;
  display: grid;
  flex: none;
  width: 17px;
  height: 17px;
}

.bar__glyph svg {
  grid-area: 1 / 1;
}

.bar__glyph-b {
  opacity: 0;
}

.bar__msg {
  margin: 0 8px 0 12px;
  font-weight: 600;
}

/* how long Undo stays */
.bar__time {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 5px;
  height: 2px;
  border-radius: 1px;
  background: var(--bar-accent);
  opacity: 0.5;
  transform-origin: 0 50%;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- the phone */
@media (max-width: 620px) {
  .stage {
    padding: 28px 16px 40px;
  }

  .ledger__head {
    padding: 0 6px 12px;
  }

  .ledger__title {
    font-size: 24px;
  }

  .ledger__note {
    font-size: 13px;
  }

  /* the table keeps every figure and narrows its type instead (the width axis of the face) */
  .table {
    font-size: 14px;
    font-stretch: 90%;
  }

  .table .col-inv,
  .table .col-due {
    display: none;
  }

  .table th,
  .table td {
    padding: 0 7px;
  }

  .table td {
    height: 58px;
  }

  .table .pick {
    width: 42px;
    padding: 0 0 0 3px;
  }

  .table .num {
    width: 82px;
  }

  .table .state-cell {
    width: 88px;
  }

  .table .more {
    width: 32px;
    padding: 0 3px 0 0;
  }

  .check {
    width: 38px;
    height: 44px;
  }

  .client__name,
  .client__meta {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .client__meta {
    margin-top: 2px;
    color: var(--muted);
    font-size: 12.5px;
  }

  .state {
    gap: 5px;
    font-size: 13.5px;
  }

  .more__btn {
    width: 28px;
  }

  .detail__body {
    grid-template-columns: 42px minmax(0, 1fr);
    row-gap: 10px;
    padding-bottom: 16px;
    font-size: 13.5px;
  }

  .detail__info,
  .detail__lines,
  .detail__trail {
    grid-column: 2;
    padding: 0 10px 0 7px;
  }

  .detail__trail {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 12px;
  }

  .detail__trail li + li {
    margin-top: 0;
  }

  .sum {
    inset: 0 7px;
    font-size: 13.5px;
  }

  .bar__set {
    padding: 0 4px;
    font-size: 13.5px;
  }

  .bar__count {
    margin: 0 4px 0 2px;
  }

  .bar__btn {
    padding: 0 10px;
  }

  .bar__set[data-set='actions'] .bar__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .bar__msg {
    margin: 0 4px 0 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bar__time {
    display: none;
  }
}
