/* Invoice generator. The layout follows the original Modus demo. Colors, type,
   panels, buttons and form controls come from site.css and demo.css. */

.invoicer {
  /* The status green nudged toward the ink, so small text in it stays readable. */
  --ok-text: color-mix(in srgb, var(--ok) 78%, var(--ink));

  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(16px, 2.2vw, 22px);
  max-width: 1360px;
}

/* ---------- the fictional agency's console header ---------- */

.app-top {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
  justify-content: space-between;
}

.app-brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.app-mark,
.inv-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  border: var(--line) solid currentColor;
  border-radius: 9px;
  font-family: var(--font-mono);
  font-weight: 500;
}

.app-name {
  font-size: 1.05rem;
  font-stretch: 85%;
  font-weight: 600;
  line-height: 1.25;
}

.app-sub {
  font-size: 0.85rem;
  color: var(--ink-3);
}

.masthead {
  display: grid;
  gap: 10px;

  h2 {
    font-size: clamp(2rem, 4.4vw, 3rem);
    font-stretch: 70%;
    font-weight: 400;
  }

  p:last-child {
    max-width: 46em;
    color: var(--ink-2);
  }
}

/* ---------- the two steps ---------- */

.invoice-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(16px, 2.2vw, 22px);
  align-items: start;

  @media (min-width: 1080px) {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  }
}

.step-head {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rule);

  h3 {
    font-size: 1.3rem;
    font-stretch: 78%;
    font-weight: 600;
  }
}

/* ---------- step 1: source data ---------- */

.file-chip {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper-2);
}

.file-type {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 38px;
  border: 1px solid var(--ink-3);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.file-text {
  min-width: 0;
}

.file-name {
  font-size: 0.92rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.file-meta {
  font-size: 0.82rem;
  color: var(--ink-3);
}

.file-ok {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-left: auto;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ok-text);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0 0;

  /* The number reads first on screen, the label first for screen readers. */
  > div {
    display: flex;
    flex-direction: column-reverse;
    justify-content: flex-end;
    padding: 10px 12px;
    border: 1px solid var(--rule);
    border-radius: 10px;
    background: var(--paper-2);
  }

  dt {
    margin-top: 2px;
    font-family: var(--font-mono);
    font-size: 0.64rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-3);
  }

  dd {
    margin: 0;
    font-size: 1.35rem;
    font-stretch: 75%;
    font-weight: 600;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
  }

  @media (max-width: 520px) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: end;
  margin-top: 18px;

  .btn {
    justify-content: center;
    min-height: 40px;
    padding-block: 9px;
  }

  @media (max-width: 640px) {
    grid-template-columns: minmax(0, 1fr);
  }
}

.margin-box {
  position: relative;
  width: fit-content;

  .input {
    width: 7.5em;
    padding-right: 30px;
  }
}

.margin-unit {
  position: absolute;
  top: 50%;
  right: 12px;
  translate: 0 -50%;
  color: var(--ink-3);
  pointer-events: none;
}

.edit-hint {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 14px 0 8px;

  svg {
    flex: none;
    color: var(--accent-ink);
  }
}

.timesheet-scroll {
  position: relative;
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--rule);
  border-radius: 12px;
}

.timesheet {
  font-size: 0.85rem;

  th,
  td {
    padding: 8px 10px;
  }

  thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--paper-2);
  }

  td {
    vertical-align: middle;
  }

  td:first-child {
    min-width: 10.5em;
  }

  tbody tr:hover td {
    background: color-mix(in srgb, var(--ink) 4%, var(--paper));
  }

  tbody tr.is-selected td {
    background: color-mix(in srgb, var(--accent) 10%, var(--paper));
  }

  .num {
    text-align: right;
    white-space: nowrap;
  }
}

.worker {
  display: block;
  font-weight: 600;
  line-height: 1.3;
}

.worker-role {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-3);
}

.client-cell {
  min-width: 9em;
  font-size: 0.8rem;
  color: var(--ink-2);
}

.line-total {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.cell-input {
  width: 5.4em;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-align: right;

  &:hover {
    border-color: var(--ink-3);
  }

  &:focus-visible {
    border-color: var(--accent);
    background: var(--paper);
    outline-offset: 1px;
  }
}

/* ---------- step 2: the invoice ---------- */

.empty-state {
  display: grid;
  gap: 8px;
  align-content: center;
  justify-items: center;
  min-height: 360px;
  padding: 32px 16px;
  text-align: center;
  color: var(--ink-3);

  &[hidden] {
    display: none;
  }

  h4 {
    font-size: 1.15rem;
    font-stretch: 85%;
    font-weight: 600;
    color: var(--ink);
  }

  p {
    max-width: 22em;
    font-size: 0.92rem;
  }

  strong {
    color: var(--accent-ink);
  }
}

.empty-ring {
  display: grid;
  place-items: center;
  width: 66px;
  height: 66px;
  margin-bottom: 10px;
  border: var(--line) dashed var(--ink-3);
  border-radius: 50%;
  color: var(--accent-ink);
}

.build {
  display: grid;
  gap: 16px;
  padding: 18px 20px 22px;
  font-size: 0.82rem;

  &[hidden] {
    display: none;
  }

  .readout-head {
    margin-bottom: 0;
  }

  .bar {
    height: 8px;
    border-color: var(--screen-dim);
    background: transparent;
  }

  .bar > span {
    width: 0;
    background: var(--screen-hi);

    @media (prefers-reduced-motion: no-preference) {
      transition: width 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    }
  }
}

.build-log {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;

  li {
    display: flex;
    gap: 12px;
    align-items: center;
    color: var(--screen-dim);
  }

  li::before {
    content: "";
    flex: none;
    width: 14px;
    height: 14px;
    border: 1.5px solid var(--screen-dim);
    border-radius: 4px;
  }

  .is-active,
  .is-done {
    color: var(--screen-ink);
  }

  .is-active::before {
    border-color: var(--screen-hi);
    border-top-color: transparent;
    border-radius: 50%;

    @media (prefers-reduced-motion: no-preference) {
      animation: spin 0.7s linear infinite;
    }
  }

  /* A tick drawn from two borders of a narrow box. */
  .is-done::before {
    width: 6px;
    height: 11px;
    margin-inline: 4px;
    border: solid var(--screen-ink);
    border-width: 0 2px 2px 0;
    border-radius: 0;
    rotate: 45deg;
    translate: 0 -2px;
  }
}

@keyframes spin {
  to {
    rotate: 1turn;
  }
}

.paper-shell {
  &[hidden] {
    display: none;
  }

  @media (prefers-reduced-motion: no-preference) {
    animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1);
  }
}

.paper-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--ink-3);

  strong {
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--accent-ink);
  }
}

/* An invoice is a printed page, so it stays a white sheet in both color
   schemes. In dark mode it is printed in the blueprint's navy. */
.paper {
  --sheet-ink: var(--ink);
  --sheet-ink-2: var(--ink-2);
  --sheet-ink-3: var(--ink-3);
  --sheet-rule: var(--rule);
  --sheet-accent: var(--accent-ink);

  padding: clamp(18px, 4vw, 34px);
  border-top: 6px solid var(--accent);
  border-radius: 10px;
  background: var(--sheet);
  color: var(--sheet-ink);
  font-size: 0.82rem;
  box-shadow: 6px 6px 0 var(--shade);
  print-color-adjust: exact;

  @media (prefers-color-scheme: dark) {
    --sheet-ink: var(--paper);
    --sheet-ink-2: color-mix(in srgb, var(--paper) 82%, var(--sheet));
    --sheet-ink-3: color-mix(in srgb, var(--paper) 68%, var(--sheet));
    --sheet-rule: color-mix(in srgb, var(--paper) 16%, var(--sheet));
    --sheet-accent: color-mix(in srgb, var(--accent) 55%, var(--paper));
  }
}

.inv-top {
  display: flex;
  flex-wrap: wrap;
  gap: 20px 24px;
  align-items: flex-start;
  justify-content: space-between;
}

.inv-company {
  display: flex;
  gap: 11px;
  align-items: center;
}

.inv-company-name {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.25;
}

.inv-company-tag {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--sheet-ink-3);
}

.inv-address {
  margin-top: 12px;
  font-size: 0.74rem;
  font-style: normal;
  line-height: 1.6;
  color: var(--sheet-ink-2);
}

.inv-title {
  text-align: right;

  h4 {
    font-size: 2rem;
    font-stretch: 70%;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.14em;
    text-transform: uppercase;
  }
}

.inv-meta,
.party-detail {
  border-collapse: collapse;
  font-size: 0.74rem;

  th,
  td {
    padding: 2px 0;
    white-space: nowrap;
  }

  th {
    font-weight: 400;
    color: var(--sheet-ink-3);
  }

  td {
    padding-left: 16px;
    font-weight: 600;
    text-align: right;
    font-variant-numeric: tabular-nums;
  }
}

.inv-meta {
  margin: 14px 0 0 auto;

  th {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.08em;
    text-align: right;
    text-transform: uppercase;
  }
}

.party-detail {
  width: 100%;

  th {
    text-align: left;
  }
}

.inv-parties {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  gap: 16px 40px;
  margin: 24px 0 18px;
  padding: 16px 0;
  border-block: 1px solid var(--sheet-rule);
}

.party-head {
  margin-bottom: 6px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sheet-ink-3);
}

.party-name {
  font-size: 0.95rem;
  font-weight: 600;
}

.party-lines {
  font-size: 0.74rem;
  line-height: 1.6;
  color: var(--sheet-ink-2);
}

.items-scroll {
  overflow-x: auto;
}

.items {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;

  th {
    padding: 0 8px 8px;
    border-bottom: var(--line) solid var(--sheet-ink);
    font-family: var(--font-mono);
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-align: left;
    text-transform: uppercase;
    color: var(--sheet-ink-3);
  }

  td {
    padding: 7px 8px;
    border-bottom: 1px solid var(--sheet-rule);
    color: var(--sheet-ink-2);
  }

  tbody tr:nth-child(even) td {
    background: color-mix(in srgb, var(--sheet-ink) 3%, var(--sheet));
  }

  strong {
    font-weight: 600;
    color: var(--sheet-ink);
  }

  .line-role {
    color: var(--sheet-ink-3);
  }

  .num {
    font-family: var(--font-mono);
    text-align: right;
    white-space: nowrap;
  }

  .idx {
    width: 2.2em;
    font-family: var(--font-mono);
    color: var(--sheet-ink-3);
  }
}

.totals {
  width: min(100%, 300px);
  margin: 16px 0 0 auto;

  > div {
    display: flex;
    gap: 16px;
    justify-content: space-between;
    padding: 6px 0;
  }

  dt {
    color: var(--sheet-ink-2);
  }

  dd {
    margin: 0;
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--sheet-ink);
  }

  .totals-row:first-child {
    border-top: 1px solid var(--sheet-rule);
  }
}

.totals .totals-due {
  align-items: baseline;
  margin-top: 10px;
  padding: 12px 14px;
  border: var(--line) solid var(--sheet-accent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 8%, var(--sheet));

  dt {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sheet-accent);
  }

  dd {
    font-size: 1.45rem;
    font-variant-numeric: tabular-nums;
  }
}

.inv-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--sheet-rule);
}

.inv-terms {
  max-width: 60ch;
  font-size: 0.7rem;
  line-height: 1.6;
  color: var(--sheet-ink-3);

  strong {
    color: var(--sheet-ink);
  }
}

.inv-prepared {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 0.66rem;
  color: var(--sheet-ink-3);
  white-space: nowrap;

  &::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
  }
}

.page-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--ink-3);

  p:first-child {
    max-width: 36em;
  }
}

.made-by {
  display: flex;
  gap: 8px;
  align-items: center;
}

.made-mark {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1px solid currentColor;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
}

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

@media (max-width: 640px) {
  .file-chip {
    flex-wrap: wrap;
  }

  .inv-title {
    text-align: left;
  }

  .inv-meta {
    margin-left: 0;

    th {
      text-align: left;
    }
  }

  .paper {
    padding: 16px 14px;
  }

  .items {
    font-size: 0.72rem;

    th,
    td {
      padding-inline: 4px;
    }

    .idx {
      display: none;
    }
  }
}

/* ---------- print: only the invoice ---------- */

@media print {
  .demo-page {
    display: block;
    min-height: 0;
  }

  .demo-bar,
  .demo-intro,
  .app-top,
  .masthead,
  .source,
  .output > .step-head,
  .paper-actions,
  .page-foot {
    display: none;
  }

  .demo-main {
    padding: 0;
  }

  .invoicer,
  .invoice-grid {
    display: block;
  }

  .output {
    padding: 0;
    border: 0;
    background: none;
  }

  .paper-shell {
    animation: none;
  }

  .paper {
    padding: 18px 22px;
    border-radius: 0;
    box-shadow: none;
  }

  /* Tighter spacing fits a client with about 15 placements on one page. */
  .totals > div {
    padding-block: 3px;
  }

  .items td {
    padding-block: 3px;
    line-height: 1.35;
  }

  .inv-parties {
    margin: 16px 0 12px;
    padding-block: 12px;
  }

  .inv-foot {
    margin-top: 16px;
  }

  .items tr,
  .totals,
  .inv-foot {
    break-inside: avoid;
  }
}
