:root {
  --navy: #1e3a5f;
  --navy-deep: #16304f;
  --ink: #243447;
  --muted: #6b7c8f;
  --line: #d9e2ec;
  --soft: #eef3f8;
  --pill: #d4e4f7;
  --paper: #ffffff;
  --page: #dce4ee;
  --accent: #2f6fed;
  --danger: #b42318;
  --ok: #027a48;
  --panel: #f7f9fc;
  --shadow: 0 18px 50px rgba(22, 48, 79, 0.14);
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Instrument Sans", "DM Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #c9daf0 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #e8eef6 0%, transparent 45%),
    linear-gradient(180deg, #eef2f7 0%, #dfe7f1 100%);
}

button,
input,
textarea,
summary {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  min-height: 100vh;
}

.panel {
  background: #f7f9fc;
  border-right: 1px solid rgba(30, 58, 95, 0.08);
  padding: 28px 24px 40px;
  overflow: auto;
  position: relative;
  z-index: 5;
}

.panel-header h1 {
  margin: 4px 0 8px;
  font-family: var(--display);
  font-size: 1.75rem;
  letter-spacing: -0.03em;
  color: var(--navy);
}

.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.lede {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.95rem;
}

.field-group {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(30, 58, 95, 0.08);
}

.field-group h2,
.field-group summary {
  margin: 0 0 12px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--navy);
}

.field-group.collapsible summary {
  cursor: pointer;
  list-style: none;
}

.field-group.collapsible summary::-webkit-details-marker {
  display: none;
}

.field-group.collapsible summary::after {
  content: "+";
  float: right;
  color: var(--muted);
}

.field-group.collapsible details[open] summary::after {
  content: "–";
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

input,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: #8fb3e8;
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}

textarea {
  resize: vertical;
  line-height: 1.4;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.row-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.line-items {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

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

.line-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.line-item-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--navy);
}

.btn-text {
  border: 0;
  background: transparent;
  color: var(--danger);
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
}

.btn-text[hidden] {
  display: none;
}

.line-amount {
  background: var(--soft) !important;
  font-weight: 700;
  color: var(--navy) !important;
}

.add-line-bar {
  position: sticky;
  bottom: 0;
  z-index: 6;
  margin: 0 0 14px;
  padding: 10px 0 4px;
  background: linear-gradient(180deg, rgba(247, 249, 252, 0), #f7f9fc 35%);
}

#btn-add-line {
  width: 100%;
  min-height: 52px;
  position: relative;
  z-index: 7;
  border: 2px solid var(--navy);
  background: #fff;
  color: var(--navy);
}

.line-item-flash {
  outline: 2px solid var(--accent);
  animation: lineFlash 1.2s ease;
}

@keyframes lineFlash {
  from {
    background: #e8f0fb;
  }
  to {
    background: #fff;
  }
}

.preview-panel {
  border: 0;
}

.preview-panel > summary {
  list-style: none;
  cursor: pointer;
}

.preview-panel > summary::-webkit-details-marker {
  display: none;
}

.qty-helper {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--soft);
}

.qty-helper summary {
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 0;
}

.qty-helper[open] summary {
  margin-bottom: 10px;
}

#btn-apply-range {
  width: 100%;
}

.hint {
  margin: -4px 0 12px;
  font-size: 0.78rem;
  color: var(--muted);
}

.calc-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, #e8f0fb, #f4f7fb);
  border: 1px solid #d5e3f4;
}

.calc-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.calc-card strong {
  font-size: 1.15rem;
  color: var(--navy);
}

.actions {
  display: grid;
  gap: 10px;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 13px 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.12s, background 0.12s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(30, 58, 95, 0.12);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--navy);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--navy-deep);
}

.btn.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.ghost {
  background: transparent;
  color: var(--navy);
  border: 1px solid var(--line);
}

.form-error {
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 0.85rem;
}

.preview-wrap {
  padding: 24px;
  overflow: auto;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.status {
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
}

.status.warn {
  color: #9a6700;
  border-color: #f2d791;
  background: #fff8e8;
}

.status.ok {
  color: var(--ok);
  border-color: #abefc6;
  background: #ecfdf3;
}

.preview-stage {
  display: flex;
  justify-content: center;
}

.action-hint {
  margin: 10px 0 0;
  line-height: 1.4;
}

.pdf-safari-overlay {
  position: fixed;
  inset: 0;
  z-index: 20000;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.pdf-safari-card {
  width: min(920px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  padding: 18px 16px 16px;
  box-shadow: 0 18px 50px rgba(22, 48, 79, 0.25);
}

.pdf-safari-card h2 {
  margin: 0 0 8px;
  color: var(--navy);
  font-size: 1.15rem;
}

.pdf-safari-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.pdf-safari-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.pdf-safari-actions .btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pdf-safari-frame {
  width: 100%;
  height: min(70vh, 640px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f9fc;
}

#btn-clear-profile {
  width: 100%;
  margin-top: 4px;
}

.field-hint {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  font-weight: 500;
  color: #8a9bb0;
}

input.is-invalid,
textarea.is-invalid {
  border-color: #d92d20;
  box-shadow: 0 0 0 3px rgba(217, 45, 32, 0.12);
}

/* Fixed desktop A4 width — must ignore phone viewport or height math breaks */
.pdf-export-host {
  position: fixed !important;
  left: 0 !important;
  top: 0 !important;
  right: auto !important;
  bottom: auto !important;
  width: 794px !important;
  max-width: 794px !important;
  min-width: 794px !important;
  height: auto !important;
  z-index: 10000;
  display: block !important;
  padding: 0 !important;
  margin: 0 !important;
  background: #ffffff !important;
  overflow: visible !important;
  pointer-events: none;
}

.pdf-export-host::before {
  content: "Generating PDF…";
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10001;
  padding: 8px 14px;
  border-radius: 999px;
  background: #fff;
  color: #1e3a5f;
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.invoice-export,
.pdf-export-host .invoice,
.pdf-export-host .invoice.invoice-export {
  transform: none !important;
  margin: 0 !important;
  box-shadow: none !important;
  width: 794px !important;
  min-width: 794px !important;
  max-width: 794px !important;
  min-height: 0 !important;
  height: auto !important;
  padding: 48px 52px 40px !important;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

/* Colorful templates need extra top padding for the accent band (do not collapse to classic). */
.pdf-export-host .invoice.template-ember,
.pdf-export-host .invoice.template-ocean,
.pdf-export-host .invoice.template-wine,
.invoice-export.template-ember,
.invoice-export.template-ocean,
.invoice-export.template-wine {
  padding: 56px 52px 40px !important;
}

.inv-closing {
  break-inside: avoid;
  page-break-inside: avoid;
}

.pdf-export-host .invoice-page2 {
  min-height: 1123px !important;
  display: flex;
  flex-direction: column;
}

.pdf-export-host .invoice-page2 .inv-closing {
  margin-top: 28px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.pdf-export-host .invoice-page2 .inv-footer {
  margin-top: auto;
}

.inv-continue-note {
  display: none;
  margin: 18px 0 0;
  text-align: right;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.pdf-export-host .invoice-page1 .inv-continue-note {
  display: block;
}

.inv-page2-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 16px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.inv-page2-header h2 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  color: var(--navy);
}

.inv-page2-header .muted {
  font-size: 0.85rem;
}

.inv-page2-meta {
  text-align: right;
}

.inv-page2-meta .page-label {
  margin: 0 0 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.inv-page2-meta .inv-number {
  margin: 0 0 8px;
}

/* —— Template picker —— */
.template-picker {
  margin: 4px 0 0;
  padding: 0;
  border: 0;
}

.template-picker legend {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.template-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.template-option {
  margin: 0;
  cursor: pointer;
}

.template-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.template-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.template-option input:focus-visible + .template-card {
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.18);
}

.template-option input:checked + .template-card {
  border-color: #8fb3e8;
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.12);
}

.template-card strong {
  color: var(--navy);
  font-size: 0.92rem;
}

.template-card em {
  font-style: normal;
  font-size: 0.75rem;
  color: var(--muted);
}

.template-swatch {
  display: block;
  height: 10px;
  border-radius: 999px;
  margin-bottom: 4px;
}

.template-card-classic .template-swatch {
  background: linear-gradient(90deg, #1e3a5f, #6b7c8f);
}

.template-card-ember .template-swatch {
  background: linear-gradient(90deg, #92400e, #f59e0b);
}

.template-card-ocean .template-swatch {
  background: linear-gradient(90deg, #1e3a8a, #38bdf8);
}

.template-card-wine .template-swatch {
  background: linear-gradient(90deg, #9f1239, #f9a8d4);
}

.inv-hero-band {
  display: none;
}

/* —— Invoice page (A4-ish) —— */
.invoice {
  width: 794px;
  min-height: 1123px;
  background: #ffffff;
  color: #243447;
  box-shadow: var(--shadow);
  padding: 48px 52px 40px;
  position: relative;
  transform: none;
}

.inv-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: var(--navy);
}

/*
 * Colorful templates — solid colors only (no CSS-var gradients).
 * html2canvas 1.4.x often drops gradients stored in custom properties,
 * which made PDF export look broken vs the live preview.
 */
.invoice.template-ember,
.invoice.template-ocean,
.invoice.template-wine {
  padding-top: 56px;
  border: 1px solid transparent;
}

.invoice.template-ember .inv-topbar,
.invoice.template-ocean .inv-topbar,
.invoice.template-wine .inv-topbar {
  height: 8px;
}

.invoice.template-ember .inv-hero-band,
.invoice.template-ocean .inv-hero-band,
.invoice.template-wine .inv-hero-band {
  display: block;
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  height: 56px;
  pointer-events: none;
}

/* Ember — warm amber & copper */
.invoice.template-ember {
  color: #3f2a1d;
  background-color: #fffdf8;
  border-color: #f5d59a;
}

.invoice.template-ember .inv-topbar {
  background: #b45309;
}

.invoice.template-ember .inv-hero-band {
  background: #fff7ed;
}

.invoice.template-ember .inv-seller h1,
.invoice.template-ember .inv-date strong,
.invoice.template-ember .client-name,
.invoice.template-ember .thanks,
.invoice.template-ember .total,
.invoice.template-ember .pay-title,
.invoice.template-ember .pay-box dt,
.invoice.template-ember .upi strong,
.invoice.template-ember.invoice-page2 .inv-page2-header h2 {
  color: #b45309;
}

.invoice.template-ember .inv-title {
  color: #f0c674;
}

.invoice.template-ember .inv-number {
  background: #ffedd5;
  color: #9a3412;
}

.invoice.template-ember .inv-table th {
  background: #b45309;
  color: #ffffff;
}

.invoice.template-ember .inv-table td {
  color: #3f2a1d;
  border-bottom-color: #f5d59a;
}

.invoice.template-ember .pay-box {
  background: #fff7ed;
  border: 1px solid #f5d59a;
}

.invoice.template-ember .pay-box hr,
.invoice.template-ember.invoice-page2 .inv-page2-header {
  border-top-color: #f5d59a;
  border-bottom-color: #f5d59a;
}

/* Ocean — sapphire & sky */
.invoice.template-ocean {
  color: #1e293b;
  background-color: #f8fbff;
  border-color: #bfdbfe;
}

.invoice.template-ocean .inv-topbar {
  background: #1d4ed8;
}

.invoice.template-ocean .inv-hero-band {
  background: #eff6ff;
}

.invoice.template-ocean .inv-seller h1,
.invoice.template-ocean .inv-date strong,
.invoice.template-ocean .client-name,
.invoice.template-ocean .thanks,
.invoice.template-ocean .total,
.invoice.template-ocean .pay-title,
.invoice.template-ocean .pay-box dt,
.invoice.template-ocean .upi strong,
.invoice.template-ocean.invoice-page2 .inv-page2-header h2 {
  color: #1d4ed8;
}

.invoice.template-ocean .inv-title {
  color: #93c5fd;
}

.invoice.template-ocean .inv-number {
  background: #dbeafe;
  color: #1e3a8a;
}

.invoice.template-ocean .inv-table th {
  background: #1d4ed8;
  color: #ffffff;
}

.invoice.template-ocean .inv-table td {
  color: #1e293b;
  border-bottom-color: #bfdbfe;
}

.invoice.template-ocean .pay-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}

.invoice.template-ocean .pay-box hr,
.invoice.template-ocean.invoice-page2 .inv-page2-header {
  border-top-color: #bfdbfe;
  border-bottom-color: #bfdbfe;
}

/* Wine — burgundy & blush */
.invoice.template-wine {
  color: #3f1d2e;
  background-color: #fffafb;
  border-color: #fecdd3;
}

.invoice.template-wine .inv-topbar {
  background: #9f1239;
}

.invoice.template-wine .inv-hero-band {
  background: #fff1f2;
}

.invoice.template-wine .inv-seller h1,
.invoice.template-wine .inv-date strong,
.invoice.template-wine .client-name,
.invoice.template-wine .thanks,
.invoice.template-wine .total,
.invoice.template-wine .pay-title,
.invoice.template-wine .pay-box dt,
.invoice.template-wine .upi strong,
.invoice.template-wine.invoice-page2 .inv-page2-header h2 {
  color: #9f1239;
}

.invoice.template-wine .inv-title {
  color: #fda4af;
}

.invoice.template-wine .inv-number {
  background: #fce7f3;
  color: #9d174d;
}

.invoice.template-wine .inv-table th {
  background: #9f1239;
  color: #ffffff;
}

.invoice.template-wine .inv-table td {
  color: #3f1d2e;
  border-bottom-color: #fecdd3;
}

.invoice.template-wine .pay-box {
  background: #fff1f2;
  border: 1px solid #fecdd3;
}

.invoice.template-wine .pay-box hr,
.invoice.template-wine.invoice-page2 .inv-page2-header {
  border-top-color: #fecdd3;
  border-bottom-color: #fecdd3;
}

.inv-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 36px;
}

.inv-seller h1 {
  margin: 0 0 10px;
  font-family: var(--display);
  font-size: 1.55rem;
  letter-spacing: 0.02em;
  color: var(--navy);
}

.muted {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.92rem;
  white-space: pre-line;
}

.inv-meta {
  text-align: right;
  min-width: 220px;
}

.inv-title {
  margin: 0;
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #c5d0dc;
  line-height: 1;
}

.inv-number {
  display: inline-block;
  margin: 10px 0 14px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--pill);
  color: var(--navy);
  font-weight: 700;
  font-size: 0.95rem;
}

.inv-date {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.inv-date strong {
  color: var(--navy);
  font-weight: 700;
}

.inv-billto {
  margin-bottom: 28px;
  max-width: 360px;
}

.label {
  margin: 0 0 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.client-name {
  margin: 0 0 6px;
  font-weight: 700;
  color: var(--navy);
  font-size: 1.05rem;
}

.inv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 28px;
}

.inv-table th {
  background: var(--navy);
  color: #fff;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-align: left;
  padding: 12px 14px;
}

.inv-table th:nth-child(2),
.inv-table td:nth-child(2) {
  text-align: center;
  width: 70px;
}

.inv-table th:nth-child(3),
.inv-table td:nth-child(3),
.inv-table th:nth-child(4),
.inv-table td:nth-child(4) {
  text-align: right;
  width: 120px;
}

.inv-table td {
  padding: 16px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
  color: var(--navy);
  font-weight: 600;
}

.inv-bottom {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 28px;
  align-items: start;
  margin-bottom: 48px;
}

.pay-box {
  background: var(--soft);
  border-radius: 12px;
  padding: 18px 20px;
}

.pay-title {
  margin: 0 0 12px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--navy);
}

.pay-box dl {
  margin: 0;
}

.pay-box dl > div {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.pay-box dt {
  margin: 0;
  font-weight: 700;
  color: var(--navy);
}

.pay-box dd {
  margin: 0;
  color: var(--muted);
}

.pay-box hr {
  border: 0;
  border-top: 1px solid #d5dde8;
  margin: 12px 0;
}

.upi {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.upi strong {
  color: var(--navy);
}

.total-block {
  text-align: right;
}

.total-block .label {
  margin-bottom: 6px;
}

.total {
  margin: 0 0 28px;
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.02em;
}

.signature {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.signature img {
  width: 150px;
  height: auto;
  display: block;
}

.sign-name {
  margin: 0;
  font-weight: 700;
  color: var(--muted);
  font-size: 0.95rem;
}

.inv-footer {
  text-align: center;
  margin-top: auto;
  padding-top: 24px;
}

.thanks {
  margin: 0 0 8px;
  font-weight: 700;
  color: var(--navy);
}

.small {
  font-size: 0.8rem;
}

@media (max-width: 1100px) {
  .app {
    display: block;
  }

  /* PDF export must stay desktop A4 width on phones */
  .pdf-export-host,
  .pdf-export-host .invoice,
  .pdf-export-host .invoice-export {
    width: 794px !important;
    min-width: 794px !important;
    max-width: 794px !important;
    transform: none !important;
  }

  .panel {
    border-right: 0;
    border-bottom: 1px solid rgba(30, 58, 95, 0.08);
    max-height: none;
    overflow: visible;
    width: 100%;
  }

  .preview-wrap {
    position: relative;
    z-index: 1;
    width: 100%;
    padding-top: 8px;
  }

  .preview-panel > summary.preview-toolbar {
    display: flex;
    width: 100%;
    box-sizing: border-box;
  }

  .preview-panel:not([open]) > summary.preview-toolbar::after {
    content: "Show";
    margin-left: auto;
    color: var(--accent);
    font-size: 0.8rem;
  }

  .preview-panel[open] > summary.preview-toolbar::after {
    content: "Hide";
    margin-left: auto;
    color: var(--accent);
    font-size: 0.8rem;
  }

  .preview-stage {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
    width: 100%;
    max-width: 100%;
  }

  .preview-stage .invoice {
    transform: none;
    width: 100% !important;
    max-width: 100%;
    min-height: 0 !important;
    padding: 24px 18px 28px;
  }

  .inv-title {
    font-size: 1.6rem;
  }

  .inv-bottom {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .total-block {
    text-align: left;
  }
}

@media (max-width: 640px) {
  .row,
  .row-3 {
    grid-template-columns: 1fr;
  }

  #btn-add-line,
  .btn.primary,
  .btn.ghost {
    min-height: 48px;
  }

  .add-line-bar {
    position: sticky;
    bottom: 0;
  }
}

@media print {
  @page {
    size: A4;
    margin: 0;
  }

  html,
  body {
    background: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .panel,
  .preview-toolbar,
  .action-hint,
  .form-error {
    display: none !important;
  }

  .preview-wrap {
    padding: 0;
  }

  .preview-stage .invoice,
  .invoice {
    box-shadow: none !important;
    width: 210mm !important;
    min-height: auto !important;
    height: auto !important;
    transform: none !important;
    margin: 0 !important;
  }
}
