/* =====================================================
   shared.css — 月川科技 TsukiKawa Tech 共用樣式
   ===================================================== */

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== CSS Variables ===== */
:root {
  --primary:       #ffd900;
  --primary-dark:  #c9aa00;
  --primary-light: #fffde7;
  --primary-border:#fde047;
  --primary-text:  #1e293b;   /* text on --primary bg */
  --header-bg:     #1e293b;
  --danger:        #ef4444;
  --success:       #22c55e;
  --border:        #e2e8f0;
  --text:          #1e293b;
  --muted:         #64748b;
  --bg:            #f8fafc;
  --white:         #ffffff;
  --shadow:        0 4px 24px rgba(0,0,0,.08);
  --radius:        10px;
}

/* ===== Body ===== */
body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ===== App Header ===== */
.app-header {
  background: #fff;
  color: var(--text);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
  border-bottom: 3px solid var(--primary);
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-header h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: .3px; color: var(--text); }
.app-header p  { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.app-header-logo {
  height: 36px; width: 36px; object-fit: contain;
  border-radius: 6px; flex-shrink: 0;
  display: block;
  transition: opacity .15s;
}
.app-header-logo:hover { opacity: .8; }
.header-actions { display: flex; gap: 10px; }

/* Hamburger */
.header-menu-btn {
  display: none;
  background: transparent;
  border: 1.5px solid rgba(255,255,255,.5);
  border-radius: 7px;
  color: #fff;
  cursor: pointer;
  padding: 7px 10px;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  justify-content: center;
}
.header-menu-btn span {
  display: block; width: 20px; height: 2px;
  background: #fff; border-radius: 2px; transition: all .25s;
}
.header-menu-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.header-menu-btn.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.header-menu-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Dropdown */
.header-dropdown {
  display: none;
  position: absolute; top: 100%; right: 16px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  border-top: 3px solid var(--primary);
  overflow: hidden;
  z-index: 200;
  min-width: 180px;
}
.header-dropdown.open { display: block; }
.header-dropdown button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 13px 18px;
  background: none; border: none; border-bottom: 1px solid var(--border);
  font-size: .88rem; font-weight: 600; color: var(--text);
  cursor: pointer; text-align: left; transition: background .15s;
  font-family: inherit;
}
.header-dropdown button:last-child { border-bottom: none; }
.header-dropdown button:hover { background: var(--primary-light); }

@media (max-width: 600px) {
  .app-header { padding: 14px 16px; position: relative; }
  .header-actions { display: none; }
  .header-menu-btn { display: flex; }
}

/* ===== Buttons ===== */
.btn {
  padding: 9px 18px; border-radius: 8px; border: none;
  font-size: .88rem; font-weight: 600; cursor: pointer;
  transition: all .15s; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; font-family: inherit;
}
/* On dark header */
.btn-outline {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,.55);
  color: #fff;
}
.btn-outline:hover { background: rgba(255,255,255,.12); }

/* White bg (on dark header → gold text) */
.btn-white { background: #fff; color: var(--primary-text); font-weight: 700; }
.btn-white:hover { background: var(--primary-light); }

/* Primary = gold */
.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 700;
}
.btn-primary:hover { background: var(--primary-dark); }

/* Danger */
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .85; }

/* Ghost */
.btn-ghost {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--bg); }

/* Sizes */
.btn-sm { padding: 5px 12px; font-size: .8rem; }

/* Refresh animation */
.btn-refresh .refresh-icon { display: inline-block; transition: transform .55s; font-style: normal; }
.btn-refresh.spinning .refresh-icon { transform: rotate(360deg); }
.btn-refresh.success {
  border-color: var(--primary) !important;
  color: var(--primary) !important;
}

/* ===== Layout ===== */
.main-content { max-width: 1200px; margin: 0 auto; padding: 28px 20px 60px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.card-pair {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 20px; margin-bottom: 20px; align-items: start;
}
.card-pair .card { margin-bottom: 0; }
@media (max-width: 900px) {
  .two-col, .card-pair { grid-template-columns: 1fr; }
}

/* ===== Card ===== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-header {
  padding: 16px 22px;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; user-select: none;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to right, var(--primary-light), transparent);
  transition: background .15s;
}
.card-header:hover { background: linear-gradient(to right, #fef9c3, transparent); }
.section-badge, .badge {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: var(--primary-text);
  font-size: .78rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.card-header h2 { font-size: 1rem; font-weight: 700; flex: 1; color: var(--text); }
.card-header .toggle-icon { color: var(--muted); font-size: 1.1rem; transition: transform .25s; }
.card-header.collapsed .toggle-icon { transform: rotate(-90deg); }
.card-body { padding: 22px; }
.card-body.collapsed { display: none; }

/* ===== Forms ===== */
.form-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.col-span-2  { grid-column: span 2; }
.col-span-3  { grid-column: span 3; }
@media (max-width: 640px) {
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .col-span-2, .col-span-3 { grid-column: 1; }
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }

label {
  font-size: .82rem; font-weight: 600; color: var(--muted);
}
input, select, textarea {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: .9rem; font-family: inherit;
  color: var(--text); background: var(--white);
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255,217,0,.18);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.6; }

/* ===== Logo Upload ===== */
.logo-upload-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 20px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
  position: relative;
}
.logo-upload-area:hover, .logo-upload-area.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}
.logo-upload-area img { display: block; max-height: 80px; max-width: 200px; object-fit: contain; margin: 0 auto; }
.logo-upload-area p { font-size: .82rem; color: var(--muted); margin-top: 8px; }

/* ===== Color Swatches ===== */
.color-row, .color-picker-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.color-swatch-group, .color-swatch-list { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch, .color-swatch {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; transition: transform .15s, border-color .15s;
}
.swatch:hover, .color-swatch:hover { transform: scale(1.15); }
.swatch.active, .color-swatch.active { border-color: var(--text); transform: scale(1.1); }
/* Color input pill */
input[type="color"] {
  width: 36px; height: 36px; padding: 2px;
  border-radius: 8px; cursor: pointer;
  border: 1.5px solid var(--border);
}

/* ===== Preview Wrap ===== */
.preview-wrap {
  background: #e5e7eb; border-radius: 10px;
  padding: 24px; min-height: 400px; overflow-x: auto;
}

/* ===== Modal ===== */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 500;
  align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; border-radius: 14px; color: var(--text);
  box-shadow: 0 8px 40px rgba(0,0,0,.18);
  width: 90%; max-width: 520px; max-height: 85vh;
  overflow-y: auto; padding: 28px;
}
.modal h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 0; color: var(--text); }
/* Quote-style modal */
.modal-box {
  background: #fff; border-radius: 12px; color: var(--text);
  width: 560px; max-width: 96vw; max-height: 82vh;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,.22);
  overflow: hidden;
  border-top: 3px solid var(--primary);
}
.modal-header {
  padding: 16px 20px; border-bottom: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 1rem; font-weight: 700; color: var(--text); }
.modal-close {
  background: none; border: none; font-size: 1.3rem;
  cursor: pointer; color: var(--muted); line-height: 1;
}
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1.5px solid var(--border); text-align: right; }

/* Save list shared */
.save-list { display: flex; flex-direction: column; gap: 8px; }
.save-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 9px; margin-bottom: 10px; gap: 10px;
  transition: border-color .15s;
}
.save-item:hover { border-color: var(--primary); }
.save-item-info { flex: 1; min-width: 0; }
.save-item-info strong, .save-item-title { font-size: .9rem; font-weight: 700; display: block; }
.save-item-info span, .save-item-meta  { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.save-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.empty-saves, .save-empty { text-align: center; color: var(--muted); font-size: .88rem; padding: 24px; }

/* ===== Utilities ===== */
.divider { border: none; border-top: 1.5px solid var(--border); margin: 18px 0; }
.hint    { font-size: .78rem; color: var(--muted); margin-top: 4px; }

/* ===== Sidebar ===== */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 200;
  transition: opacity .25s;
}
.sidebar-overlay.open { display: block; }

.sidebar {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 264px;
  background: #fff;
  box-shadow: -4px 0 28px rgba(0,0,0,.14);
  z-index: 300;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .26s cubic-bezier(.4,0,.2,1);
  border-left: 3px solid var(--primary);
}
.sidebar.open { transform: translateX(0); }

.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: var(--primary-light);
  border-bottom: 2px solid var(--primary);
  flex-shrink: 0;
}
.sidebar-head-title { font-size: .92rem; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; }
.sidebar-close {
  background: transparent; border: none;
  color: var(--muted); cursor: pointer;
  font-size: 1.2rem; padding: 3px 7px; border-radius: 5px;
  transition: color .15s, background .15s; line-height: 1;
}
.sidebar-close:hover { color: var(--text); background: var(--primary); }

.sidebar-nav {
  flex: 1; overflow-y: auto; padding: 10px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-section {
  font-size: .7rem; font-weight: 700; color: var(--muted);
  letter-spacing: 1.2px; text-transform: uppercase;
  padding: 10px 12px 4px;
}
.sidebar-hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }

.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 13px; border-radius: 8px;
  font-size: .88rem; font-weight: 600; color: var(--text);
  background: transparent; border: none; cursor: pointer;
  text-align: left; text-decoration: none;
  transition: background .15s, color .15s;
  font-family: inherit; width: 100%; line-height: 1.3;
}
.sidebar-item:hover { background: var(--primary-light); }
.sidebar-item.active { background: var(--primary); color: var(--primary-text); }
.sidebar-item-danger { color: var(--danger); }
.sidebar-item-danger:hover { background: #fee2e2; color: var(--danger); }

/* Sidebar toggle button (in header) */
.sidebar-toggle {
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: 7px; color: var(--text); cursor: pointer;
  padding: 7px 11px; font-size: 1.15rem; line-height: 1;
  transition: background .15s, border-color .15s; flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--primary-light); border-color: var(--primary); }

/* Header left group */
.header-left { display: flex; align-items: center; gap: 12px; }

/* ===== Import JSON Modal ===== */
.import-drop-area {
  border: 2px dashed var(--border); border-radius: 10px;
  padding: 22px 16px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s; margin-bottom: 12px;
}
.import-drop-area:hover, .import-drop-area.drag-over {
  border-color: var(--primary); background: var(--primary-light);
}
.import-drop-area .import-icon { font-size: 2rem; margin-bottom: 6px; }
.import-drop-area p { font-size: .82rem; color: var(--muted); }

.ai-prompt-box {
  background: #1e293b; border-radius: 8px; padding: 14px 16px;
  font-size: .78rem; color: #94a3b8; line-height: 1.7;
  font-family: 'Courier New', monospace; max-height: 180px;
  overflow-y: auto; white-space: pre-wrap; word-break: break-all;
  margin-bottom: 10px; border: 1px solid #334155;
}

/* ===== Document Preview (DocEngine) ===== */
.doc-preview {
  background: #fff;
  font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
  font-size: 13px;
  color: #1e293b;
  line-height: 1.75;
  max-width: 760px;
  margin: 0 auto;
  box-shadow: 0 4px 32px rgba(0,0,0,.18);
}

/* Title — band style (gradient background) */
.doc-title-band {
  border-radius: 8px; padding: 14px 22px;
  margin-top: 8px; margin-bottom: 22px;
  display: flex; align-items: center; justify-content: space-between;
}
.doc-title-band h2 {
  font-size: 1.4rem; font-weight: 800; color: #fff; letter-spacing: 2px; margin: 0;
}
.doc-title-meta {
  text-align: right; font-size: .8rem; color: rgba(255,255,255,.9); line-height: 1.8;
}
.doc-title-meta strong { color: #fff; }
.doc-title-meta p { line-height: 1.8; margin: 0; }

/* Title — center style */
.doc-title-center {
  text-align: center; padding: 20px 0 16px;
  border-bottom: 1px solid #d1d5db; margin-bottom: 24px;
}
.doc-title-center h1 {
  font-size: 22px; font-weight: 900; letter-spacing: 3px;
  color: #0f172a; margin: 0 0 8px; line-height: 1.3;
}
.doc-title-center .doc-title-meta {
  display: flex; justify-content: center; flex-wrap: wrap;
  gap: 4px; font-size: 11px; color: #64748b; text-align: center;
}

/* Section title (unified) */
.doc-section-title {
  font-size: 11px; font-weight: 800; letter-spacing: 2px;
  color: #374151; border-bottom: 1.5px solid #d1d5db;
  padding-bottom: 7px; margin-bottom: 14px;
}

/* Key-Value grid */
.doc-kv-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 2px 20px; padding: 0 2%;
}
.doc-kv-row {
  display: flex; gap: 6px; margin-bottom: 5px;
  font-size: 12px; line-height: 1.6;
}
.doc-kv-label { color: #374151; min-width: 90px; flex-shrink: 0; }
.doc-kv-value { color: #1e293b; word-break: break-all; }
.doc-kv-full { grid-column: span 2; }

/* Info Box (colored header boxes) */
.doc-info-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 22px;
}
.doc-info-box {
  border: 1.5px solid #e2e8f0; border-radius: 8px; overflow: hidden;
}
.doc-info-box-header {
  padding: 7px 14px; font-size: .72rem; font-weight: 700;
  letter-spacing: .5px; text-transform: uppercase; color: #fff;
}
.doc-info-box-body {
  padding: 12px 14px; font-size: .83rem; line-height: 1.9; color: #1e293b;
}
.doc-info-box-body strong { font-weight: 700; }

/* Parties (dual-column party boxes) */
.doc-parties {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 22px;
}
.doc-party-box {
  border: 1.5px solid #e2e8f0; border-radius: 8px; padding: 14px 16px;
}
.doc-party-box h4 {
  font-size: .8rem; font-weight: 800; margin-bottom: 8px;
  border-bottom: 1px solid #e2e8f0; padding-bottom: 5px;
}
.doc-party-row { display: flex; gap: 6px; margin-bottom: 4px; font-size: .8rem; }
.doc-party-row .lbl { color: #64748b; min-width: 56px; flex-shrink: 0; }
.doc-party-row .val { color: #1e293b; font-weight: 500; word-break: break-all; }

/* General table */
.doc-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 16px; }
.doc-table thead tr { border-top: 1.5px solid #374151; border-bottom: 1.5px solid #374151; }
.doc-table thead th { padding: 8px 12px; font-weight: 700; color: #0f172a; text-align: left; }
.doc-table tbody td { padding: 9px 12px; border-bottom: 1px solid #e5e7eb; vertical-align: middle; }
.doc-table tbody tr:nth-child(even) td { background: #f8fafc; }
.doc-table tfoot td { padding: 11px 12px; font-weight: 800; border-top: 2px solid #1e293b; background: #f8fafc; }

/* Colored header variant */
.doc-table.doc-table-colored thead th { color: #fff; padding: 10px 12px; font-size: .78rem; letter-spacing: .3px; }

/* Clauses */
.doc-clause { margin-bottom: 14px; }
.doc-clause-title { font-size: .9rem; font-weight: 800; color: #1e293b; margin-bottom: 5px; }
.doc-clause-content { font-size: .82rem; color: #374151; line-height: 1.8; white-space: pre-wrap; word-break: break-word; }

/* Signature — dual */
.doc-sign-section { margin-top: 28px; page-break-inside: avoid; }
.doc-sign-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.doc-sign-box { border: 1.5px solid #e2e8f0; border-radius: 8px; padding: 16px; }
.doc-sign-box h4 { font-size: .82rem; font-weight: 800; margin-bottom: 12px; }
.doc-sign-line { border-bottom: 1.5px solid #94a3b8; margin: 8px 0 4px; height: 32px; }
.doc-sign-label { font-size: .75rem; color: #64748b; }
.doc-sign-name { font-size: .78rem; color: #64748b; margin-top: 6px; }

/* Signature — receipt (single party) */
.doc-receipt-sign { padding: 28px 44px 44px; page-break-inside: avoid; }

/* Remarks */
.doc-remarks {
  margin-bottom: 22px; background: #f8fafc;
  border-left: 3px solid #d1d5db;
  padding: 10px 14px; border-radius: 4px;
  font-size: .82rem; line-height: 1.8; color: #374151;
}

/* Legal */
.doc-legal {
  margin-bottom: 0; font-size: 11px; color: #64748b;
  line-height: 1.9; border-top: 1px dashed #e5e7eb; padding-top: 14px;
}

/* Attachment — gallery (page break per image) */
.doc-attachment-page { margin-top: 32px; page-break-before: always; }
.doc-attachment-header {
  border-bottom: 3px solid; padding-bottom: 10px; margin-bottom: 18px;
  display: flex; align-items: center; gap: 10px;
}
.doc-attachment-badge {
  font-size: .72rem; font-weight: 700; padding: 3px 10px;
  border-radius: 4px; letter-spacing: .5px;
}
.doc-attachment-img { border: 1.5px solid #e2e8f0; border-radius: 8px; overflow: hidden; }
.doc-attachment-img img { width: 90%; display: block; object-fit: contain; margin: 0 auto; }
.doc-attachment-caption { padding: 7px 10px; font-size: .78rem; color: #64748b; border-top: 1px solid #f0f4f8; }

/* Attachment — ID photos grid */
.doc-attach-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  margin-bottom: 24px; page-break-inside: avoid;
}
.doc-attach-label { font-size: 10px; color: #64748b; margin-bottom: 5px; }
.doc-attach-grid img { width: 100%; border-radius: 6px; border: 1px solid #e5e7eb; }

/* Remark boxes grid (for quote multi-column remarks) */
.doc-remarks-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 22px; }
.doc-remark-box { border: 1.5px solid #e2e8f0; border-radius: 8px; overflow: hidden; }
.doc-remark-header { padding: 7px 14px; font-size: .72rem; font-weight: 700; letter-spacing: .5px; color: #fff; }
.doc-remark-body { padding: 12px 14px; font-size: .82rem; line-height: 1.8; white-space: pre-wrap; }

/* Totals (for quote) */
.doc-totals-section { display: flex; justify-content: flex-end; margin-bottom: 22px; }
.doc-totals-table { min-width: 280px; border-collapse: collapse; }
.doc-totals-table td { padding: 5px 10px; font-size: .84rem; }
.doc-totals-table td:first-child { color: #64748b; text-align: right; }
.doc-totals-table td:last-child { font-weight: 600; text-align: right; min-width: 100px; }
.doc-totals-table tr.doc-grand td { font-size: 1.05rem; font-weight: 800; border-top: 2px solid #e2e8f0; padding-top: 10px; }

/* Responsive */
@media (max-width: 600px) {
  .doc-preview thead td { padding: 10px 14px 8px !important; }
  .doc-preview tbody td { padding: 0 14px 20px !important; }
  .doc-info-grid, .doc-parties, .doc-sign-grid,
  .doc-kv-grid, .doc-attach-grid, .doc-remarks-grid { grid-template-columns: 1fr; }
  .doc-kv-full { grid-column: 1; }
}

/* ===== Print ===== */
@media print {
  *, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  /* Reset html/body — overflow:hidden prevents Puppeteer trailing blank page */
  html {
    margin: 0 !important; padding: 0 !important;
    height: auto !important; min-height: unset !important;
    overflow: hidden !important; background: #fff !important;
  }
  body {
    margin: 0 !important; padding: 0 !important;
    height: auto !important; min-height: unset !important;
    background: #fff !important;
  }
  /* Hide everything not in the ancestor chain of the preview */
  body > *:not(:has(.preview-section)):not(:has(.doc-preview)) { display: none !important; }
  .card:not(:has(.preview-section)):not(:has(.doc-preview)) { display: none !important; }
  .card-header { display: none !important; }
  /* Hide buttons/controls inside preview card (keep only .preview-wrap / .preview-section) */
  .card-body > *:not(.preview-wrap):not(.preview-section) { display: none !important; }
  /* Strip all ancestor spacing so preview starts at page top with no trailing gap */
  .main-content, .container {
    padding: 0 !important; margin: 0 !important;
    max-width: 100% !important; gap: 0 !important;
  }
  .card:has(.preview-section) { margin: 0 !important; padding: 0 !important; border: none !important; box-shadow: none !important; border-radius: 0 !important; }
  .card-body { padding: 0 !important; margin: 0 !important; }
  /* Preview wrap resets */
  .preview-wrap { background: #fff !important; padding: 0 !important; margin: 0 !important; box-shadow: none !important; border-radius: 0 !important; min-height: unset !important; overflow: visible !important; }
  .doc-preview { box-shadow: none !important; }
  /* Compact signature section for print to avoid page overflow */
  .doc-sign-wrap {
    margin-top: 10px !important;
    padding-top: 10px !important;
  }
  @page { margin: 0; size: A4; }
}
