/* The Invoice screen (production-booking task 20, reworked in ui-clarity
   task 10; js/views/invoice.js). Reuses .panel and its collapsible toggle
   (app.css), .eyebrow / .ref / .fig, the menu button (menu.css), the Project
   page's .pf-chip, .pf-facts, .pf-notice(s), .pf-action-error, .pf-hint and
   its dialog (project-folder.css), the editor's line grid and picker for
   Extras (.billing-block, app.css, responsive.css), the detail's blocks for
   the accepted estimate, and .status-chip (calendar.css).

   The header sits on the page; everything below it is a panel (U2). The
   amount due is the screen's one big figure, in Delight, where the eye
   lands. One terracotta button: the header's primary (Send…, Mark paid…),
   or Save extras while the extras are unsaved, which takes it over.

   Written phone first:
     - under 768px: one column; the amount due under the overview, then the
       primary full width with Actions ▾ and Documents ▾ beside it; the
       panels stacked, the sum last;
     - 768–1099: the amount due and the actions on the right of the
       overview, as the Project page's header;
     - 1100 and up: the panels the wide main column and the sum beside them,
       held in view while the extras are edited. */

/* ── The header ───────────────────────────────────────────────────────────── */

.inv-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    'over'
    'due'
    'acts';
  gap: var(--space-7);
  margin-bottom: var(--space-7);
}
.inv-overview {
  grid-area: over;
  min-width: 0;
}
.inv-number {
  margin-bottom: var(--space-4);
}
.inv-title {
  font-family: var(--font-family-display);
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-3xl);
  line-height: var(--line-height-tight);
  letter-spacing: var(--letter-spacing-tight);
  color: var(--color-text-primary);
}
.inv-client {
  margin-top: var(--space-3);
  font-size: var(--font-size-base);
  line-height: var(--line-height-snug);
  color: var(--color-text-secondary);
  overflow-wrap: anywhere;
}
.inv-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  margin-top: var(--space-5);
}
.inv-status-note {
  font-size: var(--font-size-sm);
  line-height: var(--line-height-snug);
  color: var(--color-text-secondary);
}
.inv-status-note.is-alert {
  color: var(--color-status-error-text);
}
.inv-overview .send-status {
  margin-top: var(--space-3);
}

/* The amount due: a mono caps label over the figure. */
.inv-due {
  grid-area: due;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.inv-due-label {
  color: var(--color-text-secondary);
}
.inv-due-figure {
  font-family: var(--font-family-display);
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-2xl);
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.inv-due-note {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}
.inv-due.is-void .inv-due-figure {
  color: var(--color-text-tertiary);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

/* The primary, then Actions ▾ and Documents ▾. On a phone the primary has
   the full width and the menus share the row under it. */
.inv-acts {
  grid-area: acts;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-self: start;
}
.inv-acts > .btn {
  flex: 1 1 100%;
  justify-content: center;
}
.inv-acts > .menu {
  flex: 1 1 0;
  min-width: 0;
}
.inv-acts > .menu > .menu-btn {
  flex: 1 1 auto;
  justify-content: center;
}

@media (min-width: 768px) {
  .inv-head {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      'over due'
      'over acts';
    column-gap: var(--space-8);
    row-gap: var(--space-6);
    align-items: start;
  }
  .inv-due {
    align-items: flex-end;
    text-align: right;
  }
  .inv-acts {
    flex-wrap: nowrap;
    justify-content: flex-end;
  }
  .inv-acts > .btn,
  .inv-acts > .menu,
  .inv-acts > .menu > .menu-btn {
    flex: 0 0 auto;
  }
}
@media (min-width: 1100px) {
  .inv-title {
    font-size: var(--font-size-4xl);
  }
  .inv-due-figure {
    font-size: var(--font-size-3xl);
  }
}

/* ── Notices ──────────────────────────────────────────────────────────────── */

/* Void, with the way to its replacement beside the words. */
.inv-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4) var(--space-6);
}
.inv-screen .pf-notice strong {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
}
.inv-screen .pf-notice.is-alert strong {
  color: inherit;
}
.inv-link {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--color-text-link);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.inv-link:hover {
  color: var(--color-text-primary);
}
.inv-link:focus-visible {
  border-radius: var(--radius-sm);
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--shadow-focus);
}

/* ── The panels ───────────────────────────────────────────────────────────── */

.inv-body,
.inv-main,
.inv-side {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--panel-gap);
  align-items: start;
}
@media (min-width: 1100px) {
  .inv-body.has-side {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  }
  /* The sum stays in view while a long list of extras is edited. */
  .inv-side {
    position: sticky;
    top: var(--space-7);
  }
}

/* A panel body that holds prose and fields, not rows. */
.inv-panel-body {
  padding-top: var(--panel-pad-y);
  padding-bottom: var(--panel-pad-y);
}
.inv-panel-body > :last-child {
  margin-bottom: 0;
}

/* ── Deposit ──────────────────────────────────────────────────────────────── */

/* The %, while it can still change. */
.inv-pct {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-4) var(--space-5);
  margin-top: var(--space-6);
}
.inv-pct .field {
  inline-size: 8rem;
}
.inv-pct .field label {
  display: block;
  margin-bottom: var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}
.inv-pct .field input {
  width: 100%;
}
.inv-pct .pfd-hint {
  flex-basis: 100%;
  margin-top: 0;
}

/* The days booked: one row each, hairlines between. */
.inv-days {
  list-style: none;
}
.inv-days li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-5);
  padding: var(--row-pad-y) var(--panel-pad-x);
  font-size: var(--font-size-sm);
}
.inv-days li + li {
  border-top: 1px solid var(--color-border-hairline);
}
.inv-day-date {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
}
.inv-day-time {
  font-family: var(--font-figures);
  color: var(--color-text-secondary);
}

/* ── The accepted estimate, folded ────────────────────────────────────────── */

.inv-est-panel .panel-sum .ref {
  font-size: var(--font-size-sm);
}
/* The detail's own blocks sit one layer in (U2: page, panel, inset). */
.inv-est-body .est-block {
  background: var(--color-bg-inset);
  border-color: transparent;
  margin-bottom: var(--space-5);
}
.inv-est-body .est-block:last-child {
  margin-bottom: 0;
}

/* ── Extras ───────────────────────────────────────────────────────────────── */

.inv-extras.billing-block {
  margin-bottom: 0;
}
.inv-extras .panel-head {
  flex-wrap: wrap;
}
.inv-extras .panel-title {
  align-items: center;
}
/* The grid's first column starts on the panel's own edge, under its title. */
@media (min-width: 768px) {
  .inv-extras .gt-head > div:first-child,
  .inv-extras .gt-row > div:first-child {
    padding-left: var(--panel-pad-x);
  }
}
.inv-extras .custom-bill-inp {
  margin-top: var(--space-2);
}
.inv-empty-card {
  padding: var(--space-5) var(--panel-pad-x);
  border-bottom: 1px solid var(--color-border-hairline);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  color: var(--color-text-secondary);
}

/* The foot: what the extras are, then Save extras. */
.inv-extras-foot {
  justify-content: space-between;
}
.inv-extras-hint {
  flex: 1 1 18rem;
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  color: var(--color-text-secondary);
}
.inv-save {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-4) var(--space-5);
}
.inv-save-state {
  font-size: var(--font-size-sm);
  color: var(--color-accent-text);
}
.inv-save-state:empty {
  display: none;
}
@media (max-width: 767px) {
  .inv-save {
    flex: 1 1 100%;
  }
  .inv-save .btn {
    flex: 1 1 100%;
  }
}

/* ── The sum ──────────────────────────────────────────────────────────────── */

/* A printed invoice's sum, top to bottom: hairlines between the rows and a
   heavy rule over the line that is owed. */
.inv-preview {
  font-size: var(--font-size-sm);
  color: var(--color-accent-text);
}
.inv-sum-panel .panel-body {
  padding-top: var(--space-3);
  padding-bottom: var(--panel-pad-y);
}
.inv-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--space-6);
  padding: var(--space-4) 0;
  font-size: var(--font-size-sm);
  line-height: var(--line-height-snug);
}
.inv-row + .inv-row {
  border-top: 1px solid var(--color-border-hairline);
}
.inv-row dt {
  color: var(--color-text-primary);
}
.inv-row dd {
  font-family: var(--font-figures);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
  color: var(--color-text-primary);
}
.inv-q {
  margin-left: var(--space-2);
  color: var(--color-text-secondary);
}
.inv-num {
  display: inline-block;
  margin-left: var(--space-2);
  white-space: nowrap;
  font-family: var(--font-family-mono);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}
.inv-row.is-strong dt {
  font-weight: var(--font-weight-semibold);
}
.inv-row.is-less dd {
  color: var(--color-text-secondary);
}
.inv-row.is-sub {
  padding: var(--space-3) 0 var(--space-3) var(--space-6);
  font-size: var(--font-size-xs);
}
.inv-row.is-sub dt,
.inv-row.is-sub dd {
  color: var(--color-text-secondary);
}
.inv-row.is-due {
  margin-top: var(--space-3);
  padding-top: var(--space-5);
  border-top: 2px solid var(--color-border-strong);
}
.inv-row.is-due dt {
  font: var(--eyebrow-font);
  letter-spacing: var(--letter-spacing-wide);
  text-transform: uppercase;
  color: var(--color-text-secondary);
}
/* Headline figures read in the primary text, not terracotta (task 18). */
.inv-row.is-due dd {
  font-family: var(--font-family-display);
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-xl);
  color: var(--color-text-primary);
}
.inv-row.is-due.is-void dd {
  color: var(--color-text-tertiary);
  text-decoration: line-through;
}

/* ── The dialogs (Mark paid, Void and remake) ─────────────────────────────── */

.pf-dialog .field textarea {
  width: 100%;
}
.pf-dialog .field + .pfd-choice {
  margin-top: var(--space-6);
}
