/* TCI Creator Invoice Generator
 * Same structure, content and steps as the reference build.
 * Restyled to the site: cream ground, TCI purple in place of the neon green,
 * Playfair Display headings, a legible sans for the form and the invoice.
 * Light and dark modes both supported; the invoice sheet itself stays on
 * white paper in either mode, because it is a document that gets printed.
 */
@font-face{font-family:"Playfair Display";font-style:normal;font-weight:600;font-display:swap;src:url("fonts/playfair-display-latin-600-normal.woff2") format("woff2")}
@font-face{font-family:"Playfair Display";font-style:normal;font-weight:700;font-display:swap;src:url("fonts/playfair-display-latin-700-normal.woff2") format("woff2")}
@font-face{font-family:"Playfair Display";font-style:normal;font-weight:800;font-display:swap;src:url("fonts/playfair-display-latin-800-normal.woff2") format("woff2")}

:root {
  color-scheme: light;
  --ink: #201638;
  --muted: #6c6478;
  --paper: #ffffff;
  --canvas: #FDF8EC;
  --soft: #FBF5E7;
  --line: #EADFC4;
  --line-dark: #D8C9A8;
  --accent: #6553e7;
  --accent-deep: #5140cc;
  --accent-soft: #F0EAFF;
  --accent-edge: #DCD1FA;
  --accent-on: #ffffff;
  --warm: #F6EEDA;
  --danger: #A72C3F;
  --focus: rgba(101, 83, 231, .35);
  --shadow: 0 22px 60px rgba(32, 22, 56, .10);
  --radius: 18px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, Helvetica, sans-serif;
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  font-family: var(--sans);
  font-synthesis: none;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #EFEAF7;
  --muted: #A49CB6;
  --paper: #1E1830;
  --canvas: #120E1C;
  --soft: #241D38;
  --line: #372E4C;
  --line-dark: #4A3F63;
  --accent: #8574F2;
  --accent-deep: #6E5BE6;
  --accent-soft: #2A2246;
  --accent-edge: #443A66;
  --accent-on: #ffffff;
  --warm: #2A2340;
  --danger: #F08A8A;
  --focus: rgba(133, 116, 242, .4);
  --shadow: 0 22px 60px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--canvas);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

:root[data-theme="light"] body,
:root:not([data-theme="dark"]) body {
  background:
    radial-gradient(ellipse at 0% 0%, #FFF7E2 0%, transparent 55%),
    radial-gradient(ellipse at 100% 100%, #F7EFD9 0%, transparent 55%),
    linear-gradient(135deg, #FFFDF6, #FDF8EC 48%, #F6EEDA);
}

:root[data-theme="dark"] body {
  background:
    radial-gradient(ellipse at 0% 0%, #1E1733 0%, transparent 55%),
    radial-gradient(ellipse at 100% 100%, #181228 0%, transparent 55%),
    linear-gradient(135deg, #141020, #120E1C 48%, #0F0B18);
}

button, input, textarea, select { font: inherit; }
button, a, summary, label, select { -webkit-tap-highlight-color: transparent; }
button, summary, select,
input[type="checkbox"], input[type="radio"], input[type="file"] { cursor: pointer; }

button:focus-visible, a:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

a { color: inherit; }

.sr-only {
  position: absolute !important; width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important; overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important;
}

[hidden] { display: none !important; }
.pay-group { display: contents; }

#tci-invoice {
  width: min(1560px, 100%);
  margin: 0 auto;
  padding: clamp(26px, 4vw, 56px) clamp(14px, 3vw, 40px) 80px;
}

/* ---------- page heading ---------- */

.page-heading {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, .8fr);
  align-items: end;
  gap: clamp(26px, 6vw, 90px);
  margin-bottom: clamp(28px, 4vw, 48px);
}

.eyebrow {
  display: flex; align-items: center; gap: 9px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: .73rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
}

.eyebrow-dot {
  width: 9px; height: 9px;
  background: var(--accent);
  border: 2px solid var(--accent-edge);
  border-radius: 50%;
}

.page-heading h1 {
  max-width: 760px; margin: 0;
  font-family: var(--serif);
  font-size: clamp(2.6rem, 5.4vw, 5.4rem);
  font-weight: 700; line-height: 1.02; letter-spacing: -.03em;
  color: var(--ink);
}

.heading-copy { padding-bottom: 6px; }

.heading-copy > p {
  max-width: 560px; margin: 0 0 22px;
  color: var(--muted);
  font-size: clamp(1rem, 1.25vw, 1.15rem); line-height: 1.6;
}

.privacy-note {
  display: flex; align-items: flex-start; gap: 9px;
  max-width: 520px; margin: 0;
  color: var(--muted); font-size: .84rem;
}

.privacy-note svg {
  flex: 0 0 17px; width: 17px; margin-top: 3px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

.mobile-view-toggle { display: none; }

/* ---------- workspace ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(440px, .85fr) minmax(560px, 1.15fr);
  align-items: start;
  gap: 22px;
}

.editor-card,
.preview-column {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(32, 22, 56, .02);
}

.editor-card { overflow: hidden; background: var(--paper); }

.editor-topline {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 20px 24px 14px;
}

.editor-topline > div:first-child { display: flex; align-items: baseline; gap: 11px; }

.section-kicker { color: var(--muted); font-size: .7rem; font-weight: 700; letter-spacing: .13em; }
.editor-topline strong { font-size: .78rem; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.text-button {
  padding: 6px; color: var(--muted); background: transparent; border: 0;
  font-size: .8rem; font-weight: 600;
}
.text-button:hover { color: var(--danger); }

.progress-track { height: 3px; background: var(--line); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .25s ease; }

.step-tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }

.step-tab {
  position: relative; display: flex; flex-direction: column; align-items: flex-start;
  gap: 4px; min-width: 0; padding: 15px 18px;
  color: var(--muted); background: var(--soft);
  border: 0; border-right: 1px solid var(--line);
  text-align: left; font-size: .84rem; font-weight: 600;
}
.step-tab:last-child { border-right: 0; }
.step-tab span { color: var(--muted); font-size: .65rem; font-weight: 700; letter-spacing: .11em; }
.step-tab::after {
  position: absolute; right: 14px; bottom: 12px; width: 6px; height: 6px;
  content: ""; background: transparent; border-radius: 50%;
}
.step-tab.is-active { color: var(--ink); background: var(--paper); }
.step-tab.is-active span { color: var(--accent); }
.step-tab.is-active::before {
  position: absolute; right: 13px; bottom: -1px; left: 13px; height: 3px;
  content: ""; background: var(--accent);
}
.step-tab.has-content::after { background: var(--accent); }

.form-step { padding: clamp(20px, 3vw, 30px); }

.step-heading { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 28px; }

.step-heading > span {
  display: grid; flex: 0 0 38px; place-items: center; height: 38px;
  color: var(--accent); background: var(--accent-soft);
  border: 1px solid var(--accent-edge); border-radius: 50%;
  font-size: .7rem; font-weight: 800;
}

.step-heading h2 {
  margin: 0 0 4px;
  font-family: var(--serif); font-weight: 700;
  font-size: clamp(1.3rem, 1.9vw, 1.65rem); line-height: 1.18; letter-spacing: -.015em;
}

.step-heading p { margin: 0; color: var(--muted); font-size: .88rem; }

.form-grid { display: grid; gap: 18px 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: 1.1fr 1fr 1fr; }
.span-two { grid-column: span 2; }

.field {
  display: flex; min-width: 0; flex-direction: column; gap: 7px;
  color: var(--ink); font-size: .84rem; font-weight: 600;
}
.field > span:first-child { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field b { color: var(--danger); font-weight: 600; }
.field em {
  color: var(--muted); font-size: .65rem; font-style: normal; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
}

.field input,
.field textarea,
.field select {
  width: 100%; min-height: 46px; padding: 11px 12px;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--line-dark); border-radius: 10px; outline: 0;
  transition: border-color .15s, box-shadow .15s;
}

.field textarea { min-height: 82px; resize: vertical; line-height: 1.45; }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: .75; }
.field input:hover, .field textarea:hover, .field select:hover { border-color: var(--accent-edge); }

.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

.field input.is-invalid, .field textarea.is-invalid, .field select.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(167, 44, 63, .12);
}

.field small { color: var(--muted); font-size: .72rem; font-weight: 400; line-height: 1.35; }
.field small.is-error { color: var(--danger); font-weight: 600; }

.divider { height: 1px; margin: 26px 0; background: var(--line); }

.upload-row {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  margin-top: 20px; padding: 14px 16px;
  background: var(--soft); border: 1px dashed var(--line-dark); border-radius: 10px;
}
.upload-row > div { display: flex; flex-direction: column; }
.upload-row strong { font-size: .84rem; }
.upload-row > div span { color: var(--muted); font-size: .72rem; }

.upload-button {
  display: inline-flex; min-height: 38px; align-items: center; justify-content: center;
  padding: 8px 13px; color: var(--ink); background: var(--paper);
  border: 1px solid var(--line-dark); border-radius: 8px;
  font-size: .76rem; font-weight: 700; text-align: center;
}
.upload-button:hover { border-color: var(--accent); color: var(--accent); }
.upload-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-button.wide { width: 100%; min-height: 46px; font-size: .82rem; }

.step-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 32px; padding-top: 22px; border-top: 1px solid var(--line);
}
.step-actions.final { margin-top: 26px; }

.primary-button, .secondary-button, .danger-button, .download-button {
  display: inline-flex; min-height: 46px; align-items: center; justify-content: center;
  gap: 9px; padding: 11px 18px; border-radius: 10px;
  font-size: .84rem; font-weight: 700;
}

.primary-button, .download-button {
  color: var(--accent-on);
  background: linear-gradient(110deg, #6237ce 0%, #8b2fae 55%, #bf365c 100%);
  border: 0;
}
.primary-button:hover, .download-button:hover {
  background: linear-gradient(110deg, #502bb7, #79229b 55%, #a82b4e);
}

.secondary-button {
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--line-dark);
}
.secondary-button:hover { border-color: var(--accent); color: var(--accent); }

.danger-button { color: #fff; background: var(--danger); border: 1px solid var(--danger); }

.primary-button svg, .download-button svg {
  width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

.segmented-fieldset { min-width: 0; margin: 0 0 24px; padding: 0; border: 0; }
.segmented-fieldset legend { margin-bottom: 8px; color: var(--ink); font-size: .84rem; font-weight: 600; }

.segmented { display: grid; grid-template-columns: repeat(2, 1fr); padding: 4px; background: var(--soft); border-radius: 10px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span {
  display: flex; min-height: 40px; align-items: center; justify-content: center;
  padding: 8px 12px; color: var(--muted);
  border: 1px solid transparent; border-radius: 8px;
  font-size: .82rem; font-weight: 600;
}
.segmented input:checked + span {
  color: var(--accent); background: var(--paper); border-color: var(--accent-edge);
  box-shadow: 0 1px 3px rgba(32, 22, 56, .08);
}

.quick-add { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-bottom: 20px; }
.quick-add > span {
  margin-right: 2px; color: var(--muted); font-size: .69rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
}
.quick-add button {
  min-height: 31px; padding: 6px 11px; color: var(--ink); background: var(--soft);
  border: 1px solid var(--line); border-radius: 999px; font-size: .7rem; font-weight: 600;
}
.quick-add button:hover { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-edge); }

.items-head, .line-item {
  display: grid;
  grid-template-columns: minmax(150px, 2.25fr) minmax(68px, .8fr) minmax(54px, .55fr) minmax(92px, 1fr) 34px;
  gap: 8px; align-items: start;
}

.items-head {
  padding: 0 4px 7px; color: var(--muted);
  font-size: .63rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}

.line-items { display: flex; flex-direction: column; gap: 10px; }

.line-item { padding: 12px; background: var(--soft); border: 1px solid var(--line); border-radius: 12px; }

.line-item input {
  width: 100%; min-width: 0; min-height: 42px; padding: 9px;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--line-dark); border-radius: 8px; outline: 0; font-size: .78rem;
}
.line-item input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.line-item input.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(167, 44, 63, .12); }

.rate-input { position: relative; }
.rate-input span { position: absolute; top: 50%; left: 9px; color: var(--muted); font-size: .75rem; transform: translateY(-50%); }
.rate-input input { padding-left: 22px; }

.remove-item {
  display: grid; width: 34px; height: 42px; place-items: center; padding: 0;
  color: var(--muted); background: transparent; border: 0; border-radius: 8px; font-size: 1.2rem;
}
.remove-item:hover { color: var(--danger); background: var(--paper); }

.add-item-button {
  width: 100%; margin-top: 10px; padding: 11px;
  color: var(--ink); background: var(--paper);
  border: 1px dashed var(--line-dark); border-radius: 10px;
  font-size: .78rem; font-weight: 700;
}
.add-item-button:hover { color: var(--accent); border-color: var(--accent); }

.option-card {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  margin-top: 12px; padding: 17px 16px;
  background: var(--soft); border: 1px solid var(--line); border-radius: 12px;
}
.option-card.compact { margin-top: 22px; }

.switch-copy, .option-card > div:first-child { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.switch-copy strong, .option-card > div:first-child strong { font-size: .88rem; }
.switch-copy span, .option-card > div:first-child span { color: var(--muted); font-size: .73rem; }

.switch { position: relative; display: inline-flex; flex: 0 0 46px; width: 46px; height: 26px; }
.switch.small { flex-basis: 40px; width: 40px; height: 23px; }
.switch input { position: absolute; opacity: 0; }
.switch > span[aria-hidden] {
  width: 100%; height: 100%; background: var(--line-dark);
  border: 1px solid var(--line-dark); border-radius: 999px; transition: .2s;
}
.switch > span[aria-hidden]::after {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  content: ""; background: #fff; border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18); transition: .2s;
}
.switch.small > span[aria-hidden]::after { top: 3px; width: 15px; height: 15px; }
.switch input:checked + span[aria-hidden] { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span[aria-hidden]::after { background: #fff; transform: translateX(20px); }
.switch.small input:checked + span[aria-hidden]::after { transform: translateX(18px); }
.switch input:focus-visible + span[aria-hidden] { outline: 3px solid var(--focus); outline-offset: 2px; }

.conditional-box {
  margin: 8px 0 18px; padding: 17px 16px;
  background: var(--paper); border: 1px solid var(--line);
  border-top: 3px solid var(--accent); border-radius: 12px;
}

.gst-result {
  display: flex; align-items: center; gap: 10px; margin-top: 14px;
  padding: 11px 12px; background: var(--accent-soft); border-radius: 8px;
}
.tax-badge {
  flex: 0 0 auto; padding: 5px 8px; color: var(--accent-on); background: var(--accent);
  border-radius: 6px; font-size: .64rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
}
.gst-result p { margin: 0; color: var(--ink); font-size: .73rem; }

.international-tax { margin-top: 15px; }

.inline-switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--line);
}
.inline-switch-row > div { display: flex; flex-direction: column; }
.inline-switch-row strong { font-size: .78rem; }
.inline-switch-row span { color: var(--muted); font-size: .69rem; }

.suffix-input { position: relative; }
.suffix-input input { padding-right: 34px; }
.suffix-input > span { position: absolute; top: 50%; right: 12px; color: var(--muted); transform: translateY(-50%); }

.caution-note {
  margin: 14px 0 0; padding: 10px 12px;
  color: var(--ink); background: var(--warm);
  border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; font-size: .71rem;
}

.subsection-title {
  margin: 30px 0 12px;
  font-family: var(--serif); font-weight: 700; font-size: 1.1rem; letter-spacing: -.01em;
}

.payment-choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }

.check-card {
  position: relative; display: flex; min-height: 70px; align-items: center; gap: 10px;
  padding: 12px; background: var(--soft); border: 1px solid var(--line); border-radius: 12px;
}
.check-card:has(input:checked) { background: var(--accent-soft); border-color: var(--accent-edge); }
.check-card input { position: absolute; opacity: 0; }
.check-box {
  display: grid; flex: 0 0 22px; width: 22px; height: 22px; place-items: center;
  color: transparent; background: var(--paper); border: 1px solid var(--line-dark);
  border-radius: 6px; font-size: .7rem; font-weight: 800;
}
.check-card input:checked + .check-box { color: var(--accent-on); background: var(--accent); border-color: var(--accent); }
.check-card input:focus-visible + .check-box { outline: 3px solid var(--focus); outline-offset: 2px; }
.check-card > span:last-child { display: flex; flex-direction: column; }
.check-card strong { font-size: .78rem; }
.check-card small { color: var(--muted); font-size: .68rem; }

.final-fields { margin-top: 20px; }

/* ---------- preview ---------- */

.preview-column { position: sticky; top: 16px; overflow: hidden; background: var(--soft); }

.preview-toolbar {
  display: flex; min-height: 74px; align-items: center; justify-content: space-between;
  gap: 16px; padding: 13px 16px 13px 20px;
  color: #fff; background: linear-gradient(135deg, #2B1B4A 0%, #3B2058 48%, #4A1F46 100%);
}
.preview-toolbar > div { display: flex; flex-direction: column; }
.preview-toolbar span { color: #C9BCE6; font-size: .63rem; font-weight: 700; letter-spacing: .13em; }
.preview-toolbar strong { font-size: 1.08rem; }

.download-button { min-height: 42px; padding: 9px 14px; font-size: .76rem; }

.invoice-stage {
  max-height: calc(100vh - 120px); overflow: auto;
  padding: clamp(16px, 3vw, 28px);
  scrollbar-color: var(--line-dark) transparent; scrollbar-width: thin;
}

/* The invoice sheet is paper. It stays light in dark mode, because it prints. */
.invoice-sheet {
  position: relative; width: 100%; min-height: 1000px; overflow: hidden;
  padding: clamp(28px, 4vw, 46px);
  color: #111; background: #fff; box-shadow: var(--shadow);
  font-family: var(--sans);
}

.invoice-accent {
  position: absolute; top: 0; right: 0; left: 0; height: 8px;
  background: linear-gradient(110deg, #6237ce 0%, #8b2fae 55%, #bf365c 100%);
}

.invoice-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 30px; padding-bottom: 25px; border-bottom: 2px solid #111;
}

.invoice-identity { display: flex; min-width: 0; align-items: flex-start; gap: 14px; }

.invoice-logo-wrap {
  display: grid; flex: 0 0 50px; width: 50px; height: 50px; place-items: center;
  overflow: hidden; background: #f4f4f1; border: 1px solid #dadbd6;
}
.invoice-logo-wrap img { width: 100%; height: 100%; object-fit: contain; }

.invoice-from-label, .invoice-section-label {
  margin: 0 0 6px; color: #777; font-size: .59rem; font-weight: 700; letter-spacing: .15em;
}

.invoice-identity h2 {
  max-width: 340px; margin: 0; overflow-wrap: anywhere;
  font-family: var(--serif); font-weight: 700;
  font-size: clamp(1.2rem, 2.2vw, 1.7rem); line-height: 1.1; letter-spacing: -.02em;
}

.muted-line { margin: 4px 0 0; color: #666; font-size: .7rem; }

.invoice-title-block { flex: 0 0 auto; text-align: right; }
.invoice-title-block > span { display: block; margin-bottom: 3px; color: #777; font-size: .52rem; font-weight: 700; letter-spacing: .11em; }
.invoice-title-block h3 {
  margin: 0; font-family: var(--serif); font-weight: 700;
  font-size: clamp(1.6rem, 3.4vw, 2.6rem); line-height: 1; letter-spacing: -.03em;
}

.invoice-meta-grid { display: grid; grid-template-columns: 1.15fr 1fr 1fr 1fr; border-bottom: 1px solid #cecec8; }
.invoice-meta-grid > div {
  display: flex; min-width: 0; flex-direction: column; gap: 4px;
  padding: 15px 13px; border-right: 1px solid #cecec8;
}
.invoice-meta-grid > div:first-child { padding-left: 0; }
.invoice-meta-grid > div:last-child { padding-right: 0; border-right: 0; }

.invoice-meta-grid span, .reference-strip span, .amount-words span,
.invoice-notes > span, .msme-note > span, .tds-estimate span {
  color: #777; font-size: .53rem; font-weight: 700; letter-spacing: .12em;
}
.invoice-meta-grid strong { min-width: 0; overflow-wrap: anywhere; font-size: .7rem; }

.invoice-status strong {
  width: max-content; padding: 3px 6px;
  color: #4A2A8F; background: #EFE9FF; border: 1px solid #DCD1FA;
  font-size: .58rem; letter-spacing: .06em;
}

.address-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 38px; padding: 24px 0; }
.address-grid section { min-width: 0; }
.address-grid strong { display: block; margin-bottom: 5px; overflow-wrap: anywhere; font-size: .76rem; }
.address-grid p { margin: 0 0 3px; color: #4f4f4c; font-size: .66rem; line-height: 1.45; white-space: pre-line; }

.tax-identifiers { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 9px 0 0; }
.tax-identifiers div { display: flex; gap: 5px; }
.tax-identifiers dt { color: #777; font-size: .57rem; font-weight: 700; }
.tax-identifiers dd { margin: 0; overflow-wrap: anywhere; font-size: .59rem; font-weight: 700; }

.reference-strip {
  display: flex; gap: 34px; margin-bottom: 21px; padding: 11px 13px;
  background: #F6F2FF; border-left: 4px solid #6553e7;
}
.reference-strip div { display: flex; min-width: 0; flex-direction: column; }
.reference-strip strong { overflow-wrap: anywhere; font-size: .66rem; }

.export-endorsement {
  margin: -8px 0 18px; padding: 8px 10px;
  color: #33265C; background: #F6F2FF; border: 1px solid #DCD1FA;
  font-size: .59rem; font-weight: 700; letter-spacing: .04em; text-align: center;
}

.invoice-items-wrap { overflow: hidden; border: 1px solid #d0d0ca; }
.invoice-items { width: 100%; table-layout: fixed; border-collapse: collapse; }
.invoice-items th {
  padding: 10px 8px; color: #fff; background: #2B1B4A;
  font-size: .55rem; letter-spacing: .08em; text-align: left;
}
.invoice-items th:first-child, .invoice-items td:first-child { width: 45%; padding-left: 12px; }
.invoice-items th:nth-child(2), .invoice-items td:nth-child(2) { width: 13%; }
.invoice-items th:nth-child(3), .invoice-items td:nth-child(3) { width: 9%; text-align: center; }
.invoice-items th:nth-child(4), .invoice-items th:nth-child(5),
.invoice-items td:nth-child(4), .invoice-items td:nth-child(5) { width: 16.5%; text-align: right; }
.invoice-items td {
  padding: 12px 8px; overflow-wrap: anywhere;
  border-bottom: 1px solid #e1e1dc; font-size: .64rem; vertical-align: top;
}
.invoice-items tr:last-child td { border-bottom: 0; }
.invoice-items .empty-item td { padding: 26px 12px; color: #888; text-align: center; }

.invoice-calculation {
  display: grid; grid-template-columns: 1fr minmax(220px, .8fr);
  gap: 35px; align-items: start; padding: 20px 0 23px;
}
.amount-words p { max-width: 330px; margin: 5px 0 0; font-size: .65rem; font-weight: 700; line-height: 1.45; }

.totals { margin: 0; }
.totals > div { display: flex; justify-content: space-between; gap: 18px; padding: 5px 0; color: #555; font-size: .65rem; }
.totals dd { margin: 0; color: #111; font-weight: 700; text-align: right; }
.totals .grand-total {
  align-items: baseline; margin-top: 7px; padding: 11px 0 0;
  color: #111; border-top: 2px solid #111; font-weight: 800;
}
.totals .grand-total dd { font-family: var(--serif); font-size: 1.2rem; letter-spacing: -.02em; }

.tds-estimate {
  display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 23px;
  padding: 13px; background: #F6F2FF; border: 1px solid #DCD1FA;
}
.tds-estimate > div { display: flex; flex-direction: column; }
.tds-estimate strong { font-size: .76rem; }
.tds-estimate p { grid-column: 1 / -1; margin: 0; color: #666; font-size: .55rem; }

.invoice-footer-grid {
  display: grid; grid-template-columns: 1.25fr .75fr; gap: 35px;
  padding-top: 22px; border-top: 1px solid #cecec8;
}

.payment-details dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 18px; margin: 0; }
.payment-details dl div { min-width: 0; }
.payment-details dt { color: #777; font-size: .55rem; }
.payment-details dd { margin: 1px 0 0; overflow-wrap: anywhere; font-size: .63rem; font-weight: 700; }

.signature-block { align-self: end; padding-top: 17px; text-align: center; }
.signature-image-wrap { display: grid; height: 54px; place-items: end center; margin-bottom: -1px; }
.signature-image-wrap img { width: auto; max-width: 130px; height: auto; max-height: 50px; object-fit: contain; }
.signature-line { width: 100%; border-top: 1px solid #111; }
.signature-block strong { display: block; margin-top: 6px; overflow-wrap: anywhere; font-size: .64rem; }
.signature-block > span { display: block; margin-top: 2px; color: #777; font-size: .5rem; font-weight: 700; letter-spacing: .1em; }

.invoice-notes, .msme-note { margin-top: 19px; padding-top: 13px; border-top: 1px solid #e0e0da; }
.invoice-notes p, .msme-note p { margin: 4px 0 0; color: #555; font-size: .58rem; line-height: 1.45; white-space: pre-line; }
.msme-note p { color: #222; }

.rcm-note { margin-top: 14px; padding: 8px 10px; background: #F6F2FF; font-size: .58rem; font-weight: 700; }

.invoice-branding {
  display: flex; justify-content: space-between; gap: 20px; margin-top: 30px; padding-top: 10px;
  color: #8b8b87; border-top: 1px solid #e4e4df; font-size: .48rem; font-weight: 700; letter-spacing: .09em;
}

.pdf-tip {
  margin: 0; padding: 13px 20px 16px;
  color: var(--muted); background: var(--soft);
  border-top: 1px solid var(--line); font-size: .7rem; text-align: center;
}

/* ---------- guide, FAQ, source ---------- */

.guide-section, .faq-section { margin-top: clamp(60px, 8vw, 120px); }

.guide-heading {
  display: grid; grid-template-columns: .7fr 1.3fr; align-items: start; gap: 40px;
  padding-bottom: 30px; border-bottom: 2px solid var(--accent-edge);
}

.guide-heading h2, .faq-section h2 {
  margin: 0; font-family: var(--serif); font-weight: 700;
  font-size: clamp(1.8rem, 3.2vw, 3.4rem); line-height: 1.08; letter-spacing: -.02em;
}

.guide-grid { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }

.guide-card { min-height: 220px; padding: 28px 28px 32px 0; border-right: 1px solid var(--line); }
.guide-card + .guide-card { padding-left: 28px; }
.guide-card:last-child { padding-right: 0; border-right: 0; }
.guide-card > span { display: block; margin-bottom: 44px; color: var(--accent); font-size: .72rem; font-weight: 700; }
.guide-card h3 { margin: 0 0 8px; font-family: var(--serif); font-weight: 700; font-size: 1.2rem; letter-spacing: -.01em; }
.guide-card p { max-width: 390px; margin: 0; color: var(--muted); font-size: .9rem; }

.faq-section {
  display: grid; grid-template-columns: minmax(260px, .65fr) minmax(460px, 1.35fr);
  gap: clamp(36px, 7vw, 100px); align-items: start;
}
.faq-section h2 { font-size: clamp(1.8rem, 3vw, 3rem); }
.faq-intro { max-width: 350px; margin: 14px 0 0; color: var(--muted); font-size: .95rem; }

.faq-list { border-top: 2px solid var(--accent-edge); }
.faq-list details { border-bottom: 1px solid var(--line); }
.faq-list summary {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 21px 4px; font-family: var(--serif); font-weight: 700;
  font-size: 1.02rem; letter-spacing: -.01em; list-style: none;
}
.faq-list summary::-webkit-details-marker { display: none; }
.faq-list summary span { color: var(--accent); font-size: 1.15rem; font-weight: 400; transition: transform .2s; }
.faq-list details[open] summary span { transform: rotate(45deg); }
.faq-list details p { max-width: 760px; margin: -5px 40px 22px 4px; color: var(--muted); font-size: .91rem; }

.source-note {
  display: grid; grid-template-columns: 170px 1fr; gap: 24px;
  margin-top: 70px; padding: 24px 0;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.source-note strong { font-family: var(--serif); font-weight: 700; font-size: .95rem; }
.source-note p { max-width: 940px; margin: 0; color: var(--muted); font-size: .8rem; }
.source-note a { color: var(--accent); font-weight: 600; text-underline-offset: 3px; }

/* ---------- toast + dialog ---------- */

.toast {
  position: fixed; z-index: 80; right: 20px; bottom: 20px;
  max-width: min(390px, calc(100vw - 40px)); padding: 13px 15px;
  color: #fff; background: #2B1B4A; border-left: 5px solid var(--accent);
  border-radius: 10px; box-shadow: 0 15px 40px rgba(0, 0, 0, .25);
  font-size: .82rem; font-weight: 600;
  opacity: 0; pointer-events: none; transform: translateY(14px); transition: .2s;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { border-left-color: #FF6D5E; }

dialog { width: min(430px, calc(100vw - 32px)); padding: 0; background: transparent; border: 0; }
dialog::backdrop { background: rgba(20, 14, 32, .68); backdrop-filter: blur(3px); }

.dialog-card {
  padding: 28px; color: var(--ink); background: var(--paper);
  border-radius: 16px; box-shadow: 0 30px 80px rgba(0, 0, 0, .3); text-align: center;
}
.dialog-icon {
  display: grid; width: 44px; height: 44px; place-items: center; margin: 0 auto 16px;
  color: var(--accent); background: var(--accent-soft); border-radius: 50%; font-size: 1.25rem;
}
.dialog-card h2 { margin: 0 0 7px; font-family: var(--serif); font-weight: 700; font-size: 1.3rem; letter-spacing: -.01em; }
.dialog-card p { margin: 0 0 23px; color: var(--muted); font-size: .86rem; }
.dialog-card > div { display: flex; justify-content: center; gap: 9px; }

/* ---------- responsive ---------- */

@media (max-width: 1240px) {
  .workspace { grid-template-columns: minmax(400px, .9fr) minmax(480px, 1.1fr); }
  .form-grid.three { grid-template-columns: repeat(2, 1fr); }
  .form-grid.three .field:first-child { grid-column: span 2; }
  .invoice-sheet { padding: 32px; }
  .invoice-calculation { grid-template-columns: .8fr 1.2fr; }
}

@media (max-width: 980px) {
  .page-heading { grid-template-columns: 1fr; gap: 26px; }
  .workspace { grid-template-columns: 1fr; }

  .mobile-view-toggle {
    position: sticky; z-index: 30; top: 0;
    display: grid; grid-template-columns: 1fr 1fr;
    margin: 0 0 12px; padding: 4px;
    background: #2B1B4A; border-radius: 12px; box-shadow: 0 8px 22px rgba(0, 0, 0, .16);
  }
  .mobile-view {
    min-height: 43px; padding: 9px 12px; color: #C9BCE6; background: transparent;
    border: 0; border-radius: 9px; font-size: .8rem; font-weight: 700;
  }
  .mobile-view.is-active { color: #fff; background: linear-gradient(110deg, #6237ce, #8b2fae 55%, #bf365c); }
  .mobile-total { margin-left: 6px; color: inherit; font-size: .69rem; }

  .preview-column { position: static; display: none; }
  body[data-mobile-view="preview"] .editor-column { display: none; }
  body[data-mobile-view="preview"] .preview-column { display: block; }
  .invoice-stage { max-height: none; }
  .guide-heading { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  #tci-invoice { padding: 26px 12px 60px; }
  .page-heading { padding: 0 2px; }
  .page-heading h1 { font-size: clamp(2.3rem, 12vw, 3.4rem); }
  .heading-copy > p { font-size: 1rem; }
  .editor-card, .preview-column { border-radius: 14px; }
  .editor-topline { padding: 16px 16px 12px; }
  .section-kicker { display: none; }
  .step-tabs { overflow-x: auto; grid-template-columns: repeat(4, minmax(80px, 1fr)); }
  .step-tab { padding: 12px 11px; font-size: .73rem; }
  .step-tab::after { right: 8px; }
  .form-step { padding: 20px 14px; }
  .step-heading { margin-bottom: 22px; }
  .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
  .form-grid.three .field:first-child, .span-two { grid-column: span 1; }
  .upload-row { align-items: stretch; flex-direction: column; }
  .items-head { display: none; }
  .line-item { grid-template-columns: 1fr 1fr 38px; }
  .line-item [data-field="description"] { grid-column: 1 / -1; }
  .line-item [data-field="sac"] { grid-column: span 1; }
  .line-item [data-field="qty"] { grid-column: span 1; }
  .line-item .rate-input { grid-column: 1 / 3; }
  .line-item .remove-item { grid-column: 3; }
  .payment-choice-grid { grid-template-columns: 1fr; }
  .step-actions { align-items: stretch; flex-direction: column-reverse; }
  .step-actions > span:empty { display: none; }
  .step-actions button { width: 100%; }
  .preview-toolbar { position: sticky; z-index: 3; top: 55px; }
  .invoice-stage { padding: 10px; overflow-x: auto; }
  .invoice-sheet { min-width: 650px; min-height: 920px; padding: 32px; transform-origin: top left; }
  .pdf-tip { font-size: .68rem; }
  .guide-heading { gap: 8px; }
  .guide-grid { grid-template-columns: 1fr; }
  .guide-card, .guide-card + .guide-card {
    min-height: 0; padding: 24px 0; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .guide-card:last-child { border-bottom: 0; }
  .guide-card > span { margin-bottom: 20px; }
  .faq-section { grid-template-columns: 1fr; gap: 20px; }
  .source-note { grid-template-columns: 1fr; gap: 8px; }
  .dialog-card > div { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
  }
}

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

@media print {
  html, body { width: 100%; min-width: 0; margin: 0; padding: 0; background: #fff; }

  .page-heading, .mobile-view-toggle, .editor-column, .preview-toolbar,
  .pdf-tip, .guide-section, .faq-section, .source-note, .toast, dialog {
    display: none !important;
  }

  #tci-invoice { width: 100%; max-width: none; margin: 0; padding: 0; }
  .workspace { display: block; }

  .preview-column {
    position: static; display: block !important; overflow: visible;
    border: 0; border-radius: 0; box-shadow: none; background: #fff;
  }

  .invoice-stage { max-height: none; overflow: visible; padding: 0; }

  .invoice-sheet {
    width: 100%; min-width: 0; min-height: 0; padding: 7mm; overflow: visible;
    box-shadow: none; print-color-adjust: exact; -webkit-print-color-adjust: exact;
  }

  .invoice-items tr, .invoice-calculation, .tds-estimate,
  .invoice-footer-grid, .invoice-notes, .msme-note { break-inside: avoid; }
}

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

.page-heading > div:first-child { padding-top: 2px; }

/* The accuracy note is the last thing on the page: no trailing rule, no gap. */
#tci-invoice { padding-bottom: 18px; }
.source-note { margin-top: 56px; padding: 22px 0 0; border-bottom: 0; }


/* --- tci-heading-match (v1.1.5) ---------------------------------
   Page heading sized to match the Rate Card Calculator heading.
   Caps at 3rem (48px) and scales down on narrow screens.        */
.page-heading h1 {
  font-size: clamp(2rem, 1.15rem + 2.8vw, 3rem);
  line-height: 1.12;
}
