:root {
  --brand: #b5121b;
  --brand-strong: #8d0f16;
  --brand-soft: #fff1f2;
  --ink: #121820;
  --muted: #667085;
  --line: #dfe3e8;
  --line-strong: #c8cdd4;
  --surface: #ffffff;
  --canvas: #eef1f4;
  --soft: #f7f8fa;
  --success: #087a55;
  --warning: #a15c00;
  --danger: #b42318;
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 18px 50px rgba(16, 24, 40, 0.12);
  --radius-sm: 9px;
  --radius: 14px;
  --radius-lg: 20px;
}

* { box-sizing: border-box; }
html {
  max-width: 100%;
  color-scheme: light;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  min-width: 320px;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, select, summary, .file-button { cursor: pointer; }
button, summary, .button, .chip, .app-tab { touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(181, 18, 27, 0.2);
  outline-offset: 2px;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); font-weight: 500; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 12px clamp(16px, 2.2vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; min-width: max-content; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, #111 0 48%, var(--brand) 49% 100%);
  color: #fff;
  box-shadow: 0 5px 16px rgba(181, 18, 27, 0.22);
  transform: skew(-6deg);
}
.brand-mark span { font-size: 22px; font-weight: 900; transform: skew(6deg); }
.brand strong { display: block; font-size: 16px; letter-spacing: -0.015em; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 760;
  line-height: 1;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button-primary { background: var(--brand); color: #fff; box-shadow: 0 5px 14px rgba(181, 18, 27, 0.2); }
.button-primary:hover { background: var(--brand-strong); }
.button-dark { background: #171b23; color: #fff; }
.button-whatsapp { background: #16a963; color: #fff; }
.button-quiet { border-color: var(--line); background: #fff; color: #29303a; }
.button-quiet:hover { border-color: var(--line-strong); background: var(--soft); }
.button-danger { border-color: #f2c6c2; background: #fff5f4; color: var(--danger); }
.button-small { min-height: 34px; padding: 7px 10px; font-size: 12px; }
.button[disabled] { cursor: not-allowed; opacity: 0.55; transform: none; }
.push-right { margin-left: auto; }

.status-pill, .save-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #98a2b3; }
.status-synced { border-color: #a7e4cc; background: #effcf6; color: var(--success); }
.status-synced .status-dot { background: var(--success); box-shadow: 0 0 0 3px rgba(8, 122, 85, 0.12); }
.status-busy { border-color: #f1d39a; background: #fffbeb; color: var(--warning); }
.status-busy .status-dot { background: #f79009; animation: pulse 1s infinite; }
.status-error { border-color: #f4c7c3; background: #fff3f2; color: var(--danger); }
.status-error .status-dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.35; } }

.app-main { width: min(1880px, 100%); margin: 0 auto; padding: 18px clamp(12px, 1.7vw, 28px) 46px; }
.app-tabs { display: flex; gap: 8px; margin: 0 0 14px; overflow-x: auto; scrollbar-width: none; }
.app-tabs::-webkit-scrollbar { display: none; }
.app-tab {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-weight: 760;
  white-space: nowrap;
}
.app-tab span { color: #98a2b3; font-size: 10px; }
.app-tab.active { border-color: #1f252d; background: #1f252d; color: #fff; box-shadow: var(--shadow-sm); }
.app-tab.active span { color: #f47c82; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.workspace-grid { display: grid; grid-template-columns: minmax(520px, 0.88fr) minmax(680px, 1.12fr); gap: 16px; align-items: start; }
.editor-panel, .content-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.editor-panel { padding: clamp(16px, 1.6vw, 24px); }
.content-panel { padding: clamp(18px, 2vw, 28px); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.eyebrow { margin: 0 0 5px; color: var(--brand); font-size: 10px; font-weight: 850; letter-spacing: 0.14em; text-transform: uppercase; }
.panel-heading h1 { margin: 0; font-size: clamp(22px, 2vw, 30px); letter-spacing: -0.035em; line-height: 1.14; }

.form-section { margin: 0 0 12px; border: 1px solid var(--line); border-radius: var(--radius); overflow: clip; background: #fff; }
.form-section[open] { box-shadow: 0 8px 24px rgba(16, 24, 40, 0.045); }
.form-section > summary {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 16px;
  background: #fbfbfc;
  list-style: none;
  font-weight: 800;
}
.form-section > summary::-webkit-details-marker { display: none; }
.form-section > summary::after { content: "+"; margin-left: auto; color: #98a2b3; font-size: 20px; font-weight: 500; }
.form-section[open] > summary::after { content: "−"; }
.form-section summary small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 500; }
.section-number { display: grid; place-items: center; flex: 0 0 auto; width: 27px; height: 27px; border-radius: 8px; background: var(--brand-soft); color: var(--brand); font-size: 11px; }
.section-body { padding: 16px; border-top: 1px solid var(--line); }

.form-grid { display: grid; gap: 12px; }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: block; margin: 0 0 12px; color: #3c4552; font-size: 12px; font-weight: 760; }
label em { color: var(--brand); font-style: normal; }
input, select, textarea {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input, select { min-height: 41px; }
textarea { min-height: 72px; resize: vertical; line-height: 1.48; }
input:hover, select:hover, textarea:hover { border-color: #aeb5bf; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(181, 18, 27, 0.1); }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); background: #fff8f7; }
.inline-actions, .button-row, .toolbar, .input-action { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.input-action { flex-wrap: nowrap; }
.input-action input { min-width: 0; margin: 6px 0 0; }
.input-action .button { flex: 0 0 auto; margin-top: 6px; }

.preset-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; color: var(--muted); font-size: 11px; font-weight: 700; }
.chip { min-height: 30px; padding: 6px 9px; border: 1px solid #ead6d8; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-size: 11px; font-weight: 750; }
.items-editor { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; border: 1px solid var(--line); border-radius: 11px; }
.items-table { width: 100%; min-width: 720px; border-collapse: collapse; table-layout: fixed; }
.items-table th { padding: 10px 8px; border-bottom: 1px solid var(--line); background: #f7f8fa; color: var(--muted); font-size: 10px; letter-spacing: 0.06em; text-align: left; text-transform: uppercase; }
.items-table th:nth-child(1) { width: 36%; }
.items-table th:nth-child(2) { width: 11%; }
.items-table th:nth-child(3) { width: 17%; }
.items-table th:nth-child(4) { width: 16%; }
.items-table th:nth-child(5) { width: 15%; }
.items-table th:nth-child(6) { width: 5%; }
.items-table td { padding: 7px; border-bottom: 1px solid #edf0f2; vertical-align: middle; }
.items-table tr:last-child td { border-bottom: 0; }
.items-table input, .items-table select { min-height: 36px; margin: 0; padding: 7px 8px; font-size: 12px; }
.item-amount { font-size: 12px; font-weight: 850; text-align: right; font-variant-numeric: tabular-nums; }
.remove-item { width: 28px; height: 28px; border: 0; border-radius: 8px; background: #fff1f0; color: var(--danger); font-size: 18px; line-height: 1; }
.financial-grid { margin-top: 14px; }
.editor-footer { display: flex; align-items: center; gap: 8px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }

.preview-panel { position: sticky; top: 88px; min-width: 0; border: 1px solid #d4d9df; border-radius: var(--radius-lg); background: #dfe3e7; box-shadow: var(--shadow-sm); overflow: hidden; }
.preview-toolbar { display: flex; justify-content: space-between; gap: 14px; padding: 13px 16px; border-bottom: 1px solid #cbd1d7; background: rgba(255, 255, 255, 0.93); }
.preview-toolbar strong { font-size: 13px; }
.preview-hints { display: flex; align-items: flex-end; justify-content: center; flex-direction: column; gap: 3px; color: var(--muted); font-size: 10px; text-align: right; }
.health-good { color: var(--success); font-weight: 800; }
.health-warn { color: var(--warning); font-weight: 800; }
.paper-stage { --preview-scale: 1; display: grid; justify-items: center; gap: 22px; width: 100%; padding: 18px; overflow-x: auto; }
.paper-shell { position: relative; width: calc(210mm * var(--preview-scale)); height: calc(297mm * var(--preview-scale)); flex: 0 0 auto; }
.invoice-page {
  position: absolute;
  inset: 0 auto auto 0;
  width: 210mm;
  height: 297mm;
  overflow: hidden;
  transform: scale(var(--preview-scale));
  transform-origin: top left;
  background: #fff;
  color: #111;
  box-shadow: 0 12px 34px rgba(16, 24, 40, 0.2);
  font-family: Arial, Helvetica, sans-serif;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.invoice-page.pad-layout { background: #fff url("assets/pad_background.jpeg") center top / 210mm 297mm no-repeat; }
.invoice-page.clean-layout { border-top: 6mm solid var(--brand); }
.page-inner { position: relative; display: flex; flex-direction: column; height: 100%; }
.pad-layout .page-inner { padding: 37mm 14mm 24mm; }
.clean-layout .page-inner { padding: 10mm 14mm 11mm; }
.print-body { min-height: 0; }
.print-footer { margin-top: auto; }

.clean-company-header { display: grid; grid-template-columns: 1fr auto; gap: 14mm; align-items: start; padding-bottom: 5mm; border-bottom: 1.2mm solid #161616; margin-bottom: 4mm; }
.clean-company-name { margin: 0; font-size: 8mm; letter-spacing: -0.04em; text-transform: uppercase; }
.clean-company-name span { color: var(--brand); }
.clean-company-info { max-width: 105mm; margin-top: 2mm; color: #333; font-size: 2.7mm; line-height: 1.45; overflow-wrap: anywhere; }
.custom-logo { max-width: 56mm; max-height: 18mm; object-fit: contain; }
.document-identity { display: grid; grid-template-columns: minmax(0, 1fr) 67mm; gap: 5mm; align-items: start; margin-bottom: 4mm; }
.pad-layout .document-identity { grid-template-columns: minmax(0, 1fr) 70mm; }
.document-title { margin: 0; font-size: 8.2mm; letter-spacing: -0.04em; line-height: 1; text-transform: uppercase; }
.document-title span { display: block; margin-top: 2mm; color: var(--muted); font-size: 2.7mm; font-weight: 600; letter-spacing: 0; text-transform: none; }
.doc-meta { width: 100%; border-collapse: collapse; table-layout: fixed; }
.doc-meta th, .doc-meta td { padding: 1.7mm 2mm; border: 0.25mm solid #8b8b8b; font-size: 2.65mm; overflow-wrap: anywhere; }
.doc-meta th { width: 25mm; background: #f1f1f1; text-align: left; }
.doc-meta td { font-weight: 700; }
.continuation-head { display: flex; justify-content: space-between; gap: 8mm; align-items: flex-end; margin-bottom: 4mm; padding-bottom: 3mm; border-bottom: 1mm solid var(--brand); }
.continuation-head strong { font-size: 5mm; text-transform: uppercase; }
.continuation-head span { color: #444; font-size: 2.8mm; }

.print-info-grid { display: grid; grid-template-columns: 1.05fr 0.95fr; gap: 3mm; margin-bottom: 3mm; }
.print-info-box { min-height: 26mm; padding: 2.8mm; border: 0.25mm solid #555; background: rgba(255, 255, 255, 0.93); }
.print-label { display: block; margin-bottom: 1.7mm; color: var(--brand); font-size: 2.45mm; font-weight: 900; letter-spacing: 0.08em; text-transform: uppercase; }
.print-info-box p { margin: 0 0 1mm; font-size: 2.75mm; line-height: 1.35; overflow-wrap: anywhere; }
.print-info-box p:last-child { margin-bottom: 0; }
.service-block { margin: 0 0 3mm; padding: 2.6mm 2.8mm; border-left: 1.2mm solid var(--brand); background: rgba(248, 248, 248, 0.95); font-size: 2.7mm; line-height: 1.38; overflow-wrap: anywhere; }
.service-block strong { margin-right: 1mm; }

.print-items { width: 100%; border-collapse: collapse; table-layout: fixed; background: rgba(255, 255, 255, 0.96); }
.print-items th, .print-items td { border: 0.25mm solid #272727; padding: 1.8mm 1.7mm; font-size: 2.72mm; line-height: 1.3; vertical-align: top; overflow-wrap: anywhere; }
.print-items th { background: #171717; color: #fff; font-size: 2.45mm; letter-spacing: 0.04em; text-transform: uppercase; }
.print-items .col-sl { width: 8mm; text-align: center; }
.print-items .col-qty { width: 17mm; text-align: center; }
.print-items .col-unit { width: 19mm; text-align: center; }
.print-items .col-rate { width: 27mm; text-align: right; }
.print-items .col-amount { width: 29mm; text-align: right; }
.print-items td:nth-last-child(-n+2) { font-variant-numeric: tabular-nums; }
.continued-note { margin: 2mm 0 0; color: #555; font-size: 2.45mm; text-align: right; }

.summary-grid { display: grid; grid-template-columns: minmax(0, 1fr) 70mm; gap: 3.5mm; margin-top: 3.5mm; align-items: start; }
.amount-words, .payment-details { padding: 2.6mm; border: 0.25mm solid #555; background: rgba(255, 255, 255, 0.95); font-size: 2.62mm; line-height: 1.4; overflow-wrap: anywhere; }
.payment-details { margin-top: 2.5mm; white-space: pre-line; }
.summary-table { width: 100%; border-collapse: collapse; background: rgba(255, 255, 255, 0.97); }
.summary-table td { padding: 1.65mm 2mm; border: 0.25mm solid #444; font-size: 2.72mm; }
.summary-table td:first-child { font-weight: 700; }
.summary-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.summary-table .grand td { background: #171717; color: #fff; font-size: 3.2mm; font-weight: 900; }
.summary-table .due td { background: #fff0f0; color: #9e1118; font-weight: 900; }
.terms-signature { display: grid; grid-template-columns: minmax(0, 1fr) 60mm; gap: 5mm; margin-top: 3.5mm; align-items: end; }
.terms-box { font-size: 2.48mm; line-height: 1.42; white-space: pre-line; overflow-wrap: anywhere; }
.signature-box { position: relative; min-height: 23mm; text-align: center; }
.signature-img { display: block; width: 42mm; max-height: 13mm; margin: 0 auto; object-fit: contain; }
.seal-img { position: absolute; right: 4mm; bottom: 6mm; width: 21mm; height: 21mm; object-fit: contain; opacity: 0.82; }
.signature-line { position: relative; z-index: 2; width: 48mm; margin: 1mm auto 0; padding-top: 1.2mm; border-top: 0.25mm solid #111; font-size: 2.7mm; font-weight: 800; }
.prepared-by { margin-top: 1mm; color: #555; font-size: 2.4mm; }
.clean-footer { display: flex; justify-content: space-between; gap: 5mm; margin-top: 4mm; padding-top: 2mm; border-top: 0.25mm solid #aaa; color: #555; font-size: 2.3mm; }
.pad-page-number { position: absolute; right: 14mm; bottom: 27mm; color: #444; font-size: 2.2mm; }
.page-overflow { outline: 1.2mm solid #f79009; outline-offset: -1.2mm; }

.settings-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(380px, 0.8fr); gap: 16px; align-items: start; }
.cloud-panel { position: sticky; top: 88px; }
.notice { margin-bottom: 16px; padding: 13px 14px; border: 1px solid #f0d5d6; border-radius: 11px; background: #fff7f7; color: #5f3033; font-size: 12px; line-height: 1.5; }
.cloud-result { min-height: 52px; margin-top: 14px; padding: 12px; border: 1px dashed var(--line-strong); border-radius: 11px; background: var(--soft); color: var(--muted); font-size: 12px; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
.cloud-result.ok { border-color: #a7e4cc; background: #effcf6; color: var(--success); }
.cloud-result.warn { border-color: #f1d39a; background: #fffbeb; color: var(--warning); }
.cloud-result.error { border-color: #f4c7c3; background: #fff4f3; color: var(--danger); }
.setup-guide { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; color: var(--muted); font-size: 12px; }
.setup-guide summary { color: #333; font-weight: 800; }
.setup-guide li { margin: 7px 0; line-height: 1.45; }
.upload-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 8px 0 18px; }
.upload-card { padding: 12px; border: 1px dashed var(--line-strong); border-radius: 11px; background: #fafbfc; }
.upload-card strong, .upload-card span { display: block; }
.upload-card span { margin: 4px 0 9px; color: var(--muted); font-size: 10px; font-weight: 500; }
.upload-card input { min-height: auto; padding: 0; border: 0; font-size: 10px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat-card { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fafbfc; }
.stat-card span { display: block; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; }
.stat-card strong { display: block; margin-top: 6px; font-size: 21px; letter-spacing: -0.03em; }
.filter-bar { display: grid; grid-template-columns: minmax(240px, 1fr) 190px 190px; gap: 9px; margin: 0 0 14px; }
.filter-bar input, .filter-bar select { margin: 0; }
.search-field { margin: 0; }
.records-list { display: grid; gap: 9px; }
.record-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.record-main { min-width: 0; }
.record-topline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.record-topline h2 { margin: 0; max-width: 100%; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.record-meta { display: flex; gap: 10px; margin-top: 5px; color: var(--muted); font-size: 11px; flex-wrap: wrap; }
.record-amount { margin-top: 7px; font-weight: 850; font-variant-numeric: tabular-nums; }
.record-actions { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; min-height: 23px; padding: 4px 7px; border-radius: 999px; background: #f0f2f4; color: #475467; font-size: 9px; font-weight: 850; text-transform: uppercase; }
.badge.paid { background: #eafaf3; color: var(--success); }
.badge.unpaid, .badge.overdue { background: #fff0ef; color: var(--danger); }
.badge.partially-paid { background: #fff8e8; color: var(--warning); }
.empty-state { padding: 38px 20px; border: 1px dashed var(--line-strong); border-radius: 14px; background: #fafbfc; color: var(--muted); text-align: center; }
.empty-state strong { display: block; margin-bottom: 5px; color: #303846; font-size: 15px; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; width: min(360px, calc(100vw - 36px)); pointer-events: none; }
.toast { padding: 12px 14px; border-radius: 11px; background: #191f27; color: #fff; box-shadow: var(--shadow-lg); font-size: 12px; font-weight: 700; animation: toast-in 0.2s ease-out; }
.toast.success { background: #0b684b; }
.toast.error { background: #9f1f16; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.confirm-dialog { width: min(430px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 16px; box-shadow: var(--shadow-lg); }
.confirm-dialog::backdrop { background: rgba(18, 24, 32, 0.55); backdrop-filter: blur(2px); }
.confirm-dialog form { padding: 22px; }
.confirm-dialog h2 { margin: 0 0 8px; font-size: 20px; }
.confirm-dialog p { margin: 0 0 18px; color: var(--muted); line-height: 1.5; }

.share-dialog {
  width: min(590px, calc(100% - 28px));
  max-height: min(760px, calc(100dvh - 28px));
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow-lg);
}
.share-dialog::backdrop { background: rgba(18, 24, 32, 0.62); backdrop-filter: blur(3px); }
.share-dialog form { padding: 22px; }
.share-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.share-heading h2 { margin: 0; font-size: 22px; letter-spacing: -0.025em; }
.dialog-close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #475467;
  font-size: 23px;
  line-height: 1;
}
.share-document-label { margin: 9px 0 16px; color: var(--muted); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; }
.share-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.share-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 11px;
  align-items: center;
  min-height: 86px;
  padding: 13px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
.share-option:not(:disabled):hover { border-color: #0c8f54; background: #f1fbf6; transform: translateY(-1px); }
.share-option:disabled { cursor: wait; opacity: 0.52; }
.share-option strong, .share-option small { display: block; }
.share-option strong { font-size: 13px; line-height: 1.25; }
.share-option small { margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.share-format { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 11px; color: #fff; font-size: 10px; font-weight: 900; letter-spacing: 0.05em; }
.share-format-image { background: #0b8f57; }
.share-format-pdf { background: var(--brand); }
.share-progress { min-height: 44px; margin-top: 13px; padding: 11px 12px; border: 1px solid #d8e9df; border-radius: 10px; background: #f3faf6; color: #296247; font-size: 11px; font-weight: 700; line-height: 1.45; }
.share-progress.busy { border-color: #f1d39a; background: #fffbeb; color: var(--warning); }
.share-progress.error { border-color: #f4c7c3; background: #fff4f3; color: var(--danger); }
.share-note { margin: 12px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }

.export-workspace {
  position: fixed;
  top: 0;
  left: -12000px;
  z-index: -1000;
  width: 210mm;
  margin: 0;
  padding: 0;
  pointer-events: none;
  background: #fff;
}
.export-workspace .paper-shell { width: 210mm; height: 297mm; margin: 0; overflow: hidden; }
.export-workspace .invoice-page { position: relative; inset: auto; transform: none; box-shadow: none; }

@media (max-width: 1380px) {
  .workspace-grid { grid-template-columns: minmax(480px, 0.95fr) minmax(620px, 1.05fr); }
  .header-actions .status-pill { display: none; }
}
@media (max-width: 1160px) {
  .app-header { position: static; align-items: flex-start; flex-direction: column; }
  .header-actions { justify-content: flex-start; width: 100%; }
  .header-actions .status-pill { display: inline-flex; }
  .workspace-grid, .settings-grid { grid-template-columns: 1fr; }
  .preview-panel, .cloud-panel { position: static; }
  .preview-panel { order: 2; }
}
@media (max-width: 760px) {
  html { scroll-padding-bottom: 42vh; }
  body { font-size: 14px; }
  .app-header {
    min-height: auto;
    padding: calc(10px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 10px calc(10px + env(safe-area-inset-left));
  }
  .brand small { display: none; }
  .header-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .header-actions .status-pill { grid-column: 1 / -1; width: max-content; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .header-actions .button { width: 100%; }
  .app-main { padding: 10px calc(9px + env(safe-area-inset-right)) calc(34px + env(safe-area-inset-bottom)) calc(9px + env(safe-area-inset-left)); }
  .app-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; overflow: visible; }
  .app-tab { min-width: 0; min-height: 44px; justify-content: center; padding: 8px 4px; font-size: 12px; }
  .app-tab span { display: none; }
  .button { min-height: 44px; padding: 10px 12px; }
  .button-small { min-height: 44px; padding: 9px 11px; font-size: 12px; }
  .chip { min-height: 44px; padding: 9px 11px; }
  input, select, textarea { min-height: 46px; padding: 11px 12px; font-size: 16px; }
  textarea { min-height: 88px; }
  .editor-panel, .content-panel { padding: 13px; border-radius: 15px; }
  .panel-heading { align-items: flex-start; flex-direction: column; margin-bottom: 15px; }
  .panel-heading h1 { font-size: 23px; }
  .form-grid-2, .form-grid-3, .upload-grid, .filter-bar { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-body { padding: 12px; }
  .form-section > summary { min-height: 52px; padding: 12px; }
  .preset-row .push-right { margin-left: 0; }
  .preset-row { align-items: stretch; }
  .preset-row > span { flex: 0 0 100%; }
  .preset-row .chip, .preset-row .button { flex: 1 1 calc(50% - 4px); }
  .items-editor { margin: 0; overflow: visible; border: 0; border-radius: 0; }
  .items-table { display: block; min-width: 0; }
  .items-table thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
  .items-table tbody { display: grid; gap: 10px; }
  .items-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: var(--shadow-sm); }
  .items-table td { display: block; min-width: 0; padding: 0; border: 0; }
  .items-table td:nth-child(1), .items-table td:nth-child(6) { grid-column: 1 / -1; }
  .items-table td:nth-child(6) { display: flex; justify-content: flex-end; }
  .items-table td::before { content: attr(data-label); display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
  .items-table td:nth-child(6)::before { display: none; }
  .items-table input, .items-table select { min-height: 44px; padding: 10px 11px; font-size: 16px; }
  .item-amount { min-height: 44px; padding: 9px 11px !important; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--soft); font-size: 16px; text-align: left; }
  .item-amount::before { margin-bottom: 3px !important; }
  .remove-item { width: 44px; height: 44px; font-size: 23px; }
  .upload-card input { max-width: 100%; min-height: 44px; padding: 8px 0; font-size: 16px; }
  .input-action { max-width: 100%; }
  .preview-toolbar { align-items: flex-start; flex-direction: column; }
  .preview-hints { align-items: flex-start; text-align: left; }
  .paper-stage { padding: 10px; gap: 14px; overflow-x: hidden; }
  .record-card { grid-template-columns: 1fr; }
  .record-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .record-actions .button { width: 100%; }
  #recordsList .record-actions .button-danger:last-child { grid-column: 1 / -1; }
  .toast-region { left: calc(10px + env(safe-area-inset-left)); right: calc(10px + env(safe-area-inset-right)); bottom: calc(10px + env(safe-area-inset-bottom)); width: auto; }
  .confirm-dialog form { padding: 18px; }
  .share-dialog { width: calc(100% - 18px); max-height: calc(100dvh - 18px); }
  .share-dialog form { padding: 17px; }
  .share-options { grid-template-columns: 1fr; }
  .share-option { min-height: 78px; }
  .dialog-close { width: 44px; height: 44px; }
}

@media (max-width: 420px) {
  .brand-mark { width: 38px; height: 38px; }
  .brand strong { font-size: 15px; }
  .editor-panel, .content-panel { padding: 11px; }
  .section-body { padding: 10px; }
  .panel-heading h1 { font-size: 21px; }
  .editor-footer, .button-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .editor-footer .button, .button-row .button { width: 100%; }
  .editor-footer .button-danger:last-child, .button-row .button:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .stats-grid { gap: 8px; }
  .stat-card { padding: 12px; }
}

@media (hover: none) {
  .button:hover { transform: none; }
}

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

@page { size: A4 portrait; margin: 0; }
@media print {
  html, body { width: 210mm; margin: 0 !important; padding: 0 !important; background: #fff !important; }
  body { max-width: none !important; overflow: visible !important; }
  .no-print, .app-header, .app-tabs, .editor-panel, .preview-toolbar, .tab-panel:not(#createTab), .toast-region, .confirm-dialog, .share-dialog, .export-workspace { display: none !important; }
  .app-main, #createTab, .workspace-grid, .preview-panel, .paper-stage { display: block !important; width: 210mm !important; max-width: none !important; margin: 0 !important; padding: 0 !important; border: 0 !important; border-radius: 0 !important; box-shadow: none !important; background: #fff !important; overflow: visible !important; }
  .paper-shell { width: 210mm !important; height: 297mm !important; margin: 0 !important; break-after: page; page-break-after: always; overflow: hidden !important; }
  .paper-shell:last-child { break-after: auto; page-break-after: auto; }
  .invoice-page { position: relative !important; width: 210mm !important; height: 297mm !important; transform: none !important; box-shadow: none !important; overflow: hidden !important; }
  .page-overflow { outline: none !important; }
}
