/* Invoice generator (olano.sg/tools/invoice-generator).
   The editor uses the shared tool skin and /styles.css tokens, so it follows
   both themes. The invoice itself is drawn as a sheet of paper in both themes:
   its colours are the site's own light-theme tokens from /styles.css
   (:root[data-theme="light"]: --bg-elev, --text, --text-2, --border, --bg,
   --accent), restated here because a printed invoice is dark ink on white
   paper whichever theme the visitor browses in. */

.inv-editor {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.inv-editor .tool-question {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.inv-editor .tool-field textarea {
  min-height: 84px;
}

.inv-editor input[type="file"] {
  max-width: 100%;
  color: var(--text-2);
  font-size: 14px;
}

.inv-items {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.inv-item {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
}

.inv-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.inv-item-title {
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 650;
}

.inv-item-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

/* The GST treatment select takes its own full-width row under the numbers. */
.inv-item-grid > [data-gst-only] {
  grid-column: 1 / -1;
}

.inv-item .tool-copy:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.inv-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.inv-inline > input {
  flex: 1 1 160px;
}

.inv-side {
  display: grid;
  gap: 14px;
  min-width: 0;
  align-content: start;
}

.inv-checklist summary {
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
}

.inv-checklist .tool-list {
  margin-top: 10px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  column-gap: 14px;
}

.inv-checklist .tool-badge {
  min-width: 4.6em;
  justify-content: center;
}

.inv-messages {
  display: grid;
  gap: 8px;
}

.inv-messages:empty {
  display: none;
}

/* ---- The invoice sheet -------------------------------------------------- */

.inv-paper {
  --paper: #ffffff;
  --ink: #3c3c43;
  --ink-2: #67676c;
  --rule: #e4e4e6;
  --band: #f3f3f4;
  --mark: #e85d2a;
  container-type: inline-size;
  min-width: 0;
  aspect-ratio: 210 / 297;
  padding: 7% 7.5%;
  border-radius: var(--r-sm);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-family: var(--font-sans);
  font-size: 12.5px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.inv-paper p {
  margin: 0;
}

.inv-paper .is-placeholder {
  color: var(--ink-2);
  font-style: italic;
  opacity: 0.75;
}

.inv-pre {
  white-space: pre-line;
}

.inv-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, auto);
  gap: 18px;
  align-items: start;
}

.inv-from {
  display: grid;
  gap: 2px;
}

.inv-logo {
  display: block;
  max-width: 150px;
  max-height: 64px;
  margin-bottom: 8px;
  object-fit: contain;
}

.inv-from-name,
.inv-to-name {
  font-weight: 700;
}

.inv-from-name {
  font-size: 1.15em;
}

.inv-title-block {
  display: grid;
  gap: 8px;
  justify-items: end;
  text-align: right;
}

.inv-title {
  color: var(--mark);
  font-size: 1.85em;
  font-weight: 750;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.inv-meta {
  display: grid;
  gap: 2px;
  margin: 0;
}

.inv-meta div {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.inv-meta dt {
  color: var(--ink-2);
}

.inv-meta dd {
  margin: 0;
  font-weight: 600;
}

.inv-label {
  margin-bottom: 3px !important;
  color: var(--ink-2);
  font-size: 0.8em;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.inv-billto {
  display: grid;
  gap: 2px;
  margin-top: 26px;
}

.inv-lines {
  width: 100%;
  margin-top: 22px;
  border-collapse: collapse;
}

.inv-lines {
  overflow-wrap: normal;
}

.inv-lines th,
.inv-lines td {
  padding: 7px 6px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}

.inv-lines th {
  background: var(--band);
  color: var(--ink);
  font-size: 0.85em;
  font-weight: 700;
}

.inv-lines .is-num,
.inv-totals .is-num {
  text-align: right;
  white-space: nowrap;
}

.inv-lines th.is-num {
  white-space: normal;
}

.inv-col-desc {
  width: 46%;
  overflow-wrap: anywhere;
}

.inv-totals-wrap {
  display: grid;
  gap: 12px;
  justify-items: end;
  margin-top: 12px;
}

.inv-totals {
  min-width: min(100%, 300px);
  border-collapse: collapse;
}

.inv-totals th,
.inv-totals td {
  padding: 4px 6px;
}

.inv-totals th {
  color: var(--ink-2);
  font-weight: 500;
  text-align: left;
}

.inv-totals .is-grand th,
.inv-totals .is-grand td {
  border-top: 1px solid var(--ink);
  color: var(--ink);
  font-weight: 750;
}

.inv-sgd {
  width: min(100%, 340px);
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 6px;
}

.inv-sgd-label {
  margin-bottom: 4px !important;
  color: var(--ink-2);
  font-size: 0.85em;
  font-weight: 600;
}

.inv-sgd .inv-totals {
  width: 100%;
}

.inv-statement {
  margin-top: 8px !important;
  font-weight: 600;
  text-align: right;
}

.inv-legend {
  margin-top: 12px !important;
  color: var(--ink-2);
  font-size: 0.85em;
}

.inv-notes {
  display: grid;
  gap: 2px;
  margin-top: 26px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
}

.inv-notes .inv-label:not(:first-child) {
  margin-top: 10px !important;
}

/* A narrow sheet (phone, or a slim column): stack the header, tighten the table. */
@container (max-width: 400px) {
  .inv-head {
    grid-template-columns: minmax(0, 1fr);
  }

  .inv-title-block {
    justify-items: start;
    text-align: left;
  }

  .inv-meta div {
    justify-content: flex-start;
  }

  .inv-lines {
    font-size: 0.9em;
  }

  .inv-lines th,
  .inv-lines td {
    padding: 6px 3px;
  }

  .inv-col-desc {
    width: auto;
  }
}

@media (max-width: 760px) {
  .inv-paper {
    aspect-ratio: auto;
    padding: 22px 18px;
    font-size: 12px;
  }
}

/* ---- Print: the invoice alone, on A4 --------------------------------------- */

@page {
  size: A4;
  margin: 14mm;
}

@media print {
  :root {
    color-scheme: light !important;
  }

  html,
  body {
    background: #ffffff !important;
  }

  main > :not(.inv-print-root),
  .site-header,
  .site-footer,
  .inv-print-root > :not(#tool),
  #tool .inv-editor,
  #tool .inv-side > :not(.inv-paper) {
    display: none !important;
  }

  .inv-print-root,
  #tool {
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
    border: 0 !important;
    background: none !important;
    box-shadow: none !important;
  }

  #tool .tool-grid {
    display: block !important;
  }

  .inv-paper {
    --ink: #000000;
    --ink-2: #444444;
    aspect-ratio: auto;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    font-size: 10pt;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .inv-paper .is-placeholder {
    visibility: hidden;
  }

  .inv-lines tr,
  .inv-totals-wrap,
  .inv-notes {
    break-inside: avoid;
  }
}
