/* Invoice generator page. Shares variables and base styles with style.css.
 * Careful: style.css styles bare header, footer, section and h2 tags, so the
 * invoice sheet below uses divs only. */

[hidden] { display: none !important; }
.wrap.wide { max-width: 1280px; }
header.slim { padding: 0; }
header.slim .top { padding: 14px 0; }
.homelink { color: #fff; text-decoration: none; }
header.slim .top nav { margin-left: auto; margin-right: 12px; display: flex; gap: 18px; }
header.slim .top nav a { color: #d6e2ee; text-decoration: none; font-size: 15px; }
header.slim .top nav a:hover, header.slim .top nav a[aria-current] { color: #fff; }
.en-note { margin: 8px 0 0; font-size: 14.5px; color: var(--warn); max-width: 46em; }
.homelink:hover { color: #8fe3da; }

.tool-intro { padding: 32px 0 4px; }
.tool-intro h1 { margin: 0 0 8px; font-size: clamp(26px, 4vw, 38px); letter-spacing: -.02em; line-height: 1.15; }
.tool-intro .lead { margin: 0; color: var(--muted); max-width: 46em; }

.tool { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 24px; align-items: start; margin-top: 22px; }

/* Form */
.inv-form fieldset { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
                     padding: 16px 18px 6px; margin: 0 0 16px; min-width: 0; }
.inv-form legend { font-weight: 700; font-size: 17px; padding: 0 8px; margin-left: -8px; }
.f { display: grid; gap: 4px; margin: 0 0 12px; font-size: 14.5px; color: var(--muted); min-width: 0; }
.f > span { font-weight: 600; color: var(--ink); }
.f input[type="text"], .f input[type="date"], .f textarea, .f select, .row input, .row select {
  font: inherit; font-size: 16px; color: var(--ink); background: #fff; padding: 10px 12px; min-width: 0; width: 100%;
  border: 1.5px solid #c3ced9; border-radius: 8px; }
.f textarea { resize: vertical; }
.f.pick { margin: 10px 0 4px; }
.pick-note { margin: 0 0 10px; }
.f select:focus { border-color: var(--teal); outline: 3px solid rgba(31,181,166,.25); }
.f input:focus, .f textarea:focus, .row input:focus, .row select:focus { border-color: var(--teal); outline: 3px solid rgba(31,181,166,.25); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--ink); font-size: 15px; }
.choices label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.choices.tpl label { border: 1.5px solid #c3ced9; border-radius: 8px; padding: 6px 12px; background: #fff; }
.choices.tpl label:has(input:checked) { border-color: var(--teal-dark); background: #e3f6f3; font-weight: 700; }
.f.accent input[type="color"] { width: 64px; height: 38px; padding: 2px; border-radius: 8px; border: 1.5px solid #c3ced9; background: #fff; }
.logo-pick { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 14px; }
button.link { background: none; border: 0; color: var(--teal-dark); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
.hint-err { color: var(--fault); font-size: 14px; }
.f input.bad-lang, .f textarea.bad-lang, .row input.bad-lang { border-color: var(--fault); background: var(--fault-bg); }
.field-warn { color: var(--fault); font-size: 13.5px; font-weight: 600; line-height: 1.35; margin-top: 2px; }
.row .field-warn { grid-column: 1 / -1; }
.no-gst .gst-only { display: none !important; }

/* Item rows */
.row { display: grid; grid-template-columns: minmax(0, 1fr) 64px 96px 112px 34px; gap: 8px; align-items: center; margin-bottom: 8px; }
.row.head { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.no-gst .row { grid-template-columns: minmax(0, 1fr) 64px 96px 34px; }
.row button.x { width: 34px; height: 38px; border: 1px solid #c3ced9; border-radius: 8px; background: #fff; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; }
.row button.x:hover { color: var(--fault); border-color: var(--fault); }
.btn-sec, .btn-main { font: inherit; font-weight: 600; border-radius: 10px; padding: 10px 16px; cursor: pointer; }
.btn-sec { background: #fff; color: var(--navy); border: 1.5px solid #b5c3d1; margin: 4px 0 14px; }
.btn-sec:hover { background: #eef2f6; }
.btn-main { background: var(--teal); color: var(--navy); border: 0; font-weight: 700; padding: 12px 22px; }
.btn-main:hover { background: #2ccbbb; }
.btn-main:disabled { background: #cfd8e1; color: #6b7886; cursor: not-allowed; }

/* Side column: checks, actions, preview */
.inv-form, .inv-side { min-width: 0; }
.inv-side { position: sticky; top: 8px; max-height: calc(100vh - 16px); overflow: auto; padding-right: 2px; }
.inv-check { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px; font-size: 14.5px; }
.inv-check .kind { font-weight: 700; margin-bottom: 6px; }
.inv-check ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.inv-check li { display: flex; gap: 8px; align-items: baseline; }
.inv-check li::before { content: ""; flex: none; width: 1.1em; text-align: center; font-weight: 800; }
.inv-check li.ok::before { content: "\2713"; color: var(--ok); }
.inv-check li.bad::before { content: "\2717"; color: var(--fault); }
.inv-check li.bad { color: var(--fault); }
.inv-check li.rec::before { content: "\25CB"; color: var(--warn); }
.inv-check li.rec { color: var(--warn); }
.inv-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inv-actions .btn-sec { margin: 0; }
.preview-wrap { position: relative; overflow: hidden; border-radius: 6px; background: #dfe6ed; margin: 4px 0 10px; }

/* The invoice sheet: fixed A4 size, scaled to fit on screen by JS */
.sheet { --accent: #0b6b62; --on-accent: #fff; width: 210mm; min-height: 297mm; padding: 14mm; background: #fff; color: #1b2430;
         font-size: 10.5pt; line-height: 1.45; transform-origin: top left; box-sizing: border-box;
         font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", "Tlwg Typo", Garuda, sans-serif; }
.sheet * { box-sizing: border-box; }
/* Base look of the on-screen sheet (Classic); the other templates override below. */
.sheet .inv-head { display: flex; justify-content: space-between; gap: 10mm; align-items: flex-start; margin-bottom: 9mm; }
.sheet h1 { margin: 0; font-size: 26pt; line-height: 1.1; color: var(--accent); letter-spacing: -.01em; }
.sheet .meta { display: grid; grid-template-columns: auto auto; gap: 1mm 6mm; margin: 4mm 0 0; font-size: 10pt; justify-content: start; }
.sheet .meta dt { color: #5b6876; margin: 0; }
.sheet .meta dd { margin: 0; font-weight: 600; }
.sheet .inv-logo img { display: block; max-width: 56mm; max-height: 28mm; object-fit: contain; }
.sheet .parties { display: grid; grid-template-columns: 1fr 1fr; gap: 10mm; margin-bottom: 8mm; }
.sheet .party h4 { margin: 0 0 1mm; font-size: 8.5pt; text-transform: uppercase; letter-spacing: .08em; color: #5b6876; font-weight: 700; }
.sheet .party .nm { font-weight: 700; font-size: 11.5pt; }
.sheet .party .ln { white-space: pre-line; overflow-wrap: anywhere; }
.sheet .party img { display: block; max-width: 36mm; max-height: 16mm; object-fit: contain; margin-bottom: 2mm; }
.sheet table.items { width: 100%; border-collapse: collapse; margin-bottom: 3mm; }
.sheet table.items th { text-align: left; font-size: 9pt; font-weight: 700; padding: 2mm; border-bottom: 2px solid var(--accent); vertical-align: bottom; }
.sheet table.items td { padding: 2.2mm 2mm; border-bottom: 1px solid #e1e7ed; vertical-align: top; }
.sheet table.items td.d { overflow-wrap: anywhere; white-space: pre-line; }
.sheet .num { text-align: right; white-space: nowrap; }
.sheet .pricenote { font-size: 9pt; color: #5b6876; margin: 0 0 4mm; }
.sheet .totals { margin-left: auto; width: 76mm; margin-bottom: 8mm; }
.sheet .totals .tr { display: flex; justify-content: space-between; gap: 6mm; padding: 1.4mm 2mm; }
.sheet .totals .tr.grand { margin-top: 1.5mm; padding: 2.4mm 2mm; border-top: 2px solid var(--accent); font-weight: 800; font-size: 12.5pt; }
.sheet .totals .stmt { font-size: 9pt; color: #5b6876; text-align: right; padding: 0 2mm; }
.sheet .block { margin-bottom: 6mm; }
.sheet .block h4 { margin: 0 0 1.5mm; font-size: 9pt; text-transform: uppercase; letter-spacing: .08em; color: #5b6876; font-weight: 700; }
.sheet .paygrid { display: grid; grid-template-columns: auto 1fr; gap: .8mm 6mm; justify-content: start; }
.sheet .paygrid span:nth-child(odd) { color: #5b6876; }
.sheet .notes-text { white-space: pre-line; overflow-wrap: anywhere; }
/* Template: Classic is the base above. */

/* Template: Modern - coloured header band, zebra rows */
.sheet[data-tpl="modern"] .inv-head { margin: -14mm -14mm 9mm; padding: 12mm 14mm; background: var(--accent); color: var(--on-accent); }
.sheet[data-tpl="modern"] h1, .sheet[data-tpl="modern"] .meta dt { color: var(--on-accent); }
.sheet[data-tpl="modern"] .meta dt { opacity: .85; }
.sheet[data-tpl="modern"] .inv-logo img { background: #fff; padding: 2mm; border-radius: 2mm; }
.sheet[data-tpl="modern"] table.items th { border-bottom: 0; background: #eef2f6; }
.sheet[data-tpl="modern"] table.items tbody tr:nth-child(even) td { background: #f7f9fb; }
.sheet[data-tpl="modern"] .totals .tr.grand { border-top: 0; background: var(--accent); color: var(--on-accent); border-radius: 1.5mm; }

/* Template: Minimal - quiet, lots of white space */
.sheet[data-tpl="minimal"] h1 { font-size: 18pt; font-weight: 500; color: #1b2430; letter-spacing: .02em; text-transform: uppercase; }
.sheet[data-tpl="minimal"] .inv-head { padding-bottom: 5mm; border-bottom: 1px solid var(--accent); }
.sheet[data-tpl="minimal"] table.items th { border-bottom: 1px solid #c3ced9; color: #5b6876; text-transform: uppercase; font-size: 8pt; letter-spacing: .06em; font-weight: 600; }
.sheet[data-tpl="minimal"] table.items td { border-bottom: 1px solid #eef2f6; }
.sheet[data-tpl="minimal"] .totals .tr.grand { border-top: 1px solid var(--accent); font-weight: 600; }

/* Template: Bold - dark header, strong title */
.sheet[data-tpl="bold"] .inv-head { margin: -14mm -14mm 9mm; padding: 12mm 14mm; background: #12263a; color: #fff; border-bottom: 2.5mm solid var(--accent); }
.sheet[data-tpl="bold"] h1 { color: #fff; font-size: 30pt; text-transform: uppercase; letter-spacing: .02em; font-weight: 800; }
.sheet[data-tpl="bold"] .meta dt { color: #b8c8d8; }
.sheet[data-tpl="bold"] .inv-logo img { background: #fff; padding: 2mm; border-radius: 2mm; }
.sheet[data-tpl="bold"] table.items th { background: #12263a; color: #fff; border-bottom: 0; }
.sheet[data-tpl="bold"] .totals .tr.grand { background: var(--accent); color: var(--on-accent); border-top: 0; }

/* Template: Compact - dense grid for long item lists */
.sheet[data-tpl="compact"] { font-size: 9.2pt; line-height: 1.35; }
.sheet[data-tpl="compact"] h1 { font-size: 19pt; }
.sheet[data-tpl="compact"] .inv-head, .sheet[data-tpl="compact"] .parties { margin-bottom: 5mm; }
.sheet[data-tpl="compact"] table.items { border: 1px solid #b5c3d1; }
.sheet[data-tpl="compact"] table.items th { background: #eef2f6; border: 1px solid #b5c3d1; padding: 1.4mm 1.8mm; }
.sheet[data-tpl="compact"] table.items td { border: 1px solid #cfd8e1; padding: 1.3mm 1.8mm; }
.sheet[data-tpl="compact"] .totals .tr.grand { font-size: 11pt; }

/* Template: Stripe - accent bar down the left edge */
.sheet { position: relative; }
.sheet[data-tpl="stripe"]::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 8mm; background: var(--accent); }
.sheet[data-tpl="stripe"] h1 { color: #1b2430; }
.sheet[data-tpl="stripe"] table.items th { border-bottom: 0; background: #eef2f6; background: color-mix(in srgb, var(--accent) 14%, #fff); }

/* Template: Elegant - serif type, centred title between thin rules */
.sheet[data-tpl="elegant"] { font-family: Georgia, "Times New Roman", "Noto Serif", "Liberation Serif", serif; font-size: 11pt; }
.sheet[data-tpl="elegant"] .inv-head { display: block; position: relative; text-align: center; border-top: 2px solid var(--accent); border-bottom: 1px solid var(--accent); padding: 3mm 0 3.5mm; }
.sheet[data-tpl="elegant"] h1 { color: #1b2430; font-style: italic; font-weight: 400; font-size: 28pt; }
.sheet[data-tpl="elegant"] .meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 2mm; margin: 1.5mm 0 0; }
.sheet[data-tpl="elegant"] .meta dd { margin-right: 5mm; }
.sheet[data-tpl="elegant"] .inv-logo { position: absolute; left: 0; top: 3mm; }
.sheet[data-tpl="elegant"] .inv-logo img { max-width: 34mm; max-height: 15mm; }
.sheet[data-tpl="elegant"] table.items th { font-style: italic; font-weight: 400; font-size: 10pt; border-top: 1px solid #1b2430; border-bottom: 1px solid #1b2430; }
.sheet[data-tpl="elegant"] table.items td { border-bottom: 1px solid #d6d6d6; }
.sheet[data-tpl="elegant"] .totals .tr.grand { border-top: 3px double var(--accent); font-weight: 700; }

/* Template: Mono - typewriter look, black and white */
.sheet[data-tpl="mono"] { --accent: #1b2430 !important; --on-accent: #fff !important; font-family: "Courier New", Courier, "Liberation Mono", monospace; font-size: 9.5pt; }
.sheet[data-tpl="mono"] h1 { color: #1b2430; font-size: 19pt; text-transform: uppercase; letter-spacing: 0; }
.sheet[data-tpl="mono"] .inv-head { padding-bottom: 4mm; border-bottom: 1px dashed #1b2430; }
.sheet[data-tpl="mono"] table.items th { border-top: 1.5px solid #1b2430; border-bottom: 1.5px solid #1b2430; }
.sheet[data-tpl="mono"] table.items td { border-bottom: 1px solid #c8c8c8; }
.sheet[data-tpl="mono"] .totals .tr.grand { border-top: 1px dashed #1b2430; }

/* Template: Soft - tinted boxes and rounded totals */
.sheet[data-tpl="soft"] .party { background: #eef6f5; background: color-mix(in srgb, var(--accent) 10%, #fff); padding: 3mm; border-radius: 2mm; }
.sheet[data-tpl="soft"] table.items th { border-bottom: 0; background: #e3efee; background: color-mix(in srgb, var(--accent) 16%, #fff); }
.sheet[data-tpl="soft"] table.items td { border-bottom: 1px solid #d3e6e4; border-bottom-color: color-mix(in srgb, var(--accent) 20%, #fff); }
.sheet[data-tpl="soft"] .totals .tr.grand { border-top: 0; border-radius: 1.6mm; background: #e3efee; background: color-mix(in srgb, var(--accent) 14%, #fff); }

/* Template: Split - coloured block behind the title */
.sheet[data-tpl="split"] .inv-head > div:first-child { background: var(--accent); color: var(--on-accent); margin: -14mm 0 0 -14mm; padding: 14mm 10mm 6mm 14mm; min-width: 92mm; min-height: 38mm; }
.sheet[data-tpl="split"] h1, .sheet[data-tpl="split"] .meta dt { color: var(--on-accent); }
.sheet[data-tpl="split"] .meta dt { opacity: .85; }

/* Template: Total bar - the amount due sits in a full-width bar */
.sheet[data-tpl="totalbar"] table.items th { color: #5b6876; border-bottom: 1.5px solid #1b2430; }
.sheet[data-tpl="totalbar"] table.items td { border-bottom: 0; }
.sheet[data-tpl="totalbar"] table.items tbody tr:nth-child(even) td { background: #f4f7fa; }
.sheet[data-tpl="totalbar"] .totals { width: 100%; margin-left: 0; }
.sheet[data-tpl="totalbar"] .totals .tr:not(.grand) { width: 76mm; margin-left: auto; }
.sheet[data-tpl="totalbar"] .totals .tr.grand { border-top: 0; background: var(--accent); color: var(--on-accent); font-size: 14pt; padding: 3mm 4mm; margin-top: 2mm; }

/* Template: Boxed - outlined boxes, like a paper form */
.sheet[data-tpl="boxed"] h1 { color: #1b2430; font-size: 23pt; }
.sheet[data-tpl="boxed"] .party { border: 1px solid #78828c; padding: 3mm; }
.sheet[data-tpl="boxed"] table.items { border: 1px solid #78828c; }
.sheet[data-tpl="boxed"] table.items th { background: #e9edf1; border: 1px solid #78828c; }
.sheet[data-tpl="boxed"] table.items td { border: 1px solid #78828c; }
.sheet[data-tpl="boxed"] .totals { border: 1px solid #78828c; padding: 1mm 0; }
.sheet[data-tpl="boxed"] .totals .tr.grand { border-top: 0; background: #e9edf1; }


@media (max-width: 980px) {
  .tool { grid-template-columns: minmax(0, 1fr); }
  .inv-side { position: static; max-height: none; overflow: visible; }
}
@media (max-width: 560px) {
  /* Phone header: name and language toggle on one row, menu links on their own row */
  header.slim .top { flex-wrap: wrap; gap: 6px 10px; }
  header.slim .top .name { min-width: 0; font-size: 16px; }
  header.slim .top nav { order: 3; width: 100%; margin: 0 0 4px; gap: 16px; }
  header.slim .top .lang { margin-left: auto; }
  .two { grid-template-columns: 1fr; }
  .row, .no-gst .row { grid-template-columns: 1fr 1fr; }
  .row .r-desc { grid-column: 1 / -1; }
  .row.head { display: none; }
  .row button.x { justify-self: end; }
}

@media print {
  @page { size: A4; margin: 0; }
  html, body { background: #fff !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  header.slim, body.invoice-page > footer, .tool-intro, .inv-form, .inv-check, .inv-actions, .inv-side > .note, noscript { display: none !important; }
  main.wrap { max-width: none; padding: 0; margin: 0; }
  .tool { display: block; margin: 0; }
  .inv-side { position: static; max-height: none; overflow: visible; padding: 0; }
  .preview-wrap { height: auto !important; overflow: visible; margin: 0; border-radius: 0; background: #fff; }
  .sheet { transform: none !important; margin: 0; box-shadow: none; min-height: 296mm; }
  .sheet table.items tr { break-inside: avoid; }
  .sheet .totals, .sheet .block { break-inside: avoid; }
}

/* Warning shown inside LINE's in-app browser, which cannot save or share files */
.inapp-warn { background: var(--warn-bg); border: 1px solid #fedf89; border-left: 4px solid #f79009; border-radius: 10px;
              padding: 12px 16px; margin: 16px 0 0; }
.inapp-warn p { margin: 0 0 10px; color: var(--ink); font-size: 15px; }
.inapp-warn a.btn-main { display: inline-block; text-decoration: none; }
