:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 20px 45px rgba(15, 23, 42, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: 96px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 20px 32px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: linear-gradient(135deg, #2563eb, #0f172a);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.app-layout {
  height: calc(100vh - 96px);
  display: grid;
  grid-template-columns: minmax(380px, 620px) 1fr;
  gap: 28px;
  padding: 28px;
  align-items: start;
  overflow: hidden;
}

.form-panel {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 8px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.section-title span {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #eff6ff;
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 800;
}

.section-title h2 {
  margin: 0;
  font-size: 18px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 14px;
}

.field label {
  font-size: 13px;
  font-weight: 700;
  color: #374151;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 13px;
  font-size: 14px;
  outline: none;
  background: #ffffff;
  color: var(--text);
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

textarea {
  resize: vertical;
}

.hint {
  color: var(--muted);
  font-size: 12px;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.choice {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 15px;
  cursor: pointer;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.choice input {
  display: none;
}

.choice strong {
  font-size: 16px;
}

.choice small {
  color: var(--muted);
}

.choice.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 8px 0 18px;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #374151;
  font-size: 14px;
}

.items-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.items-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.item-row {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
  background: #f9fafb;
}

.item-grid {
  display: grid;
  grid-template-columns: 2fr 0.8fr 0.8fr 1fr 0.8fr auto;
  gap: 10px;
  align-items: end;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 800;
  font-size: 14px;
  transition: 0.2s ease;
  background: #111827;
  color: #ffffff;
}

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

.btn.primary {
  background: var(--primary);
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.ghost {
  background: #eff6ff;
  color: var(--primary);
}

.btn.danger {
  background: #fee2e2;
  color: var(--danger);
}

.btn.small {
  padding: 10px 13px;
  font-size: 13px;
}

.btn.delete {
  background: #fee2e2;
  color: var(--danger);
  height: 43px;
}

.btn.full {
  width: 100%;
}

.preview-panel {
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.preview-actions {
  margin-bottom: 16px;
}

.pdf-wrapper {
  flex: 1;
  overflow: auto;
  padding: 12px;
  background: #e5e7eb;
  border-radius: var(--radius);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.pdf-document {
  flex: 0 0 auto;
}

.pdf-document {
  width: 794px;
  min-height: 1123px;
  background: #ffffff;
  margin: 0 auto;
  padding: 44px;
  color: #111827;
  box-shadow: 0 15px 30px rgba(0,0,0,0.12);
}

.pdf-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 30px;
  padding-bottom: 26px;
  border-bottom: 3px solid #111827;
}

.preview-logo {
  max-width: 120px;
  max-height: 80px;
  object-fit: contain;
  margin-bottom: 12px;
}

.pdf-header h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.pdf-header p {
  margin: 0;
  color: #4b5563;
  line-height: 1.5;
  font-size: 13px;
}

.document-badge {
  text-align: right;
  min-width: 220px;
}

.document-badge h1 {
  margin: 0 0 8px;
  font-size: 38px;
  letter-spacing: 2px;
  color: var(--primary);
}

.document-badge p {
  font-size: 14px;
}

.pdf-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 28px;
}

.pdf-parties div,
.work-address {
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 16px;
  background: #f9fafb;
}

.pdf-parties h3,
.work-address h3,
.pdf-notes h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: #111827;
}

.pdf-parties p,
.work-address p {
  margin: 0;
  color: #4b5563;
  line-height: 1.5;
  font-size: 13px;
}

.work-address {
  margin-top: 16px;
}

.pdf-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 28px;
  font-size: 13px;
}

.pdf-table th {
  background: #111827;
  color: white;
  text-align: left;
  padding: 12px 10px;
}

.pdf-table td {
  border-bottom: 1px solid #e5e7eb;
  padding: 12px 10px;
  vertical-align: top;
}

.pdf-table th:first-child,
.pdf-table td:first-child {
  text-align: left;
}

.pdf-table th:nth-child(2),
.pdf-table td:nth-child(2),
.pdf-table th:nth-child(3),
.pdf-table td:nth-child(3),
.pdf-table th:nth-child(4),
.pdf-table td:nth-child(4),
.pdf-table th:nth-child(5),
.pdf-table td:nth-child(5),
.pdf-table th:nth-child(6),
.pdf-table td:nth-child(6) {
  text-align: center;
}

.totals-zone {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
  margin-top: 28px;
}

.pdf-notes {
  font-size: 13px;
  color: #4b5563;
  line-height: 1.5;
}

.pdf-notes p {
  margin: 0 0 10px;
}

.legal-note {
  font-size: 12px;
  color: #374151;
}

.totals-box {
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  overflow: hidden;
}

.totals-box div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 14px;
  border-bottom: 1px solid #e5e7eb;
  font-size: 13px;
}

.totals-box div:last-child {
  border-bottom: none;
}

.totals-box .net {
  background: #111827;
  color: white;
  font-size: 16px;
}

.payment-info {
  margin-top: 24px;
  padding: 14px;
  background: #eff6ff;
  border-radius: 14px;
  color: #1e3a8a;
  font-size: 13px;
}

.signature-zone {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 60px;
  margin-top: 50px;
}

.signature-zone p {
  color: #374151;
  font-size: 13px;
}

.signature-line {
  height: 70px;
  border-bottom: 1px solid #111827;
}



.hidden {
  display: none !important;
}

@media (max-width: 1150px) {
  body {
    height: auto;
    overflow: auto;
  }

  .topbar {
    height: auto;
  }

  .app-layout {
    height: auto;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .form-panel,
  .preview-panel {
    height: auto;
    overflow: visible;
  }
}

@media (max-width: 760px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    padding: 20px;
  }

  .app-layout {
    padding: 18px;
  }

  .grid-2,
  .grid-3,
  .choice-grid,
  .item-grid {
    grid-template-columns: 1fr;
  }

  .items-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .pdf-wrapper {
    padding: 12px;
    overflow: auto;
    justify-content: flex-start;
  }

  .pdf-document {
    width: 794px;
    min-width: 794px;
    min-height: 1123px;
    padding: 44px;
  }

  .pdf-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
  }

  .pdf-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .totals-zone {
    display: grid;
    grid-template-columns: 1fr 280px;
  }

  .signature-zone {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .document-badge {
    text-align: right;
  }
}

.text-size-panel {
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 18px;
}

.text-size-panel h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.text-size-panel p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.pdf-size-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.pdf-size-presets .btn {
  width: 100%;
}

.pdf-size-presets .size-preset-active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.2);
}

.field input[type="range"] {
  padding: 0;
  box-shadow: none;
  cursor: pointer;
}

/* Variables de taille du PDF */
.pdf-document {
  --global-multiplier: 1;
  --header-multiplier: 1;
  --party-multiplier: 1;
  --table-multiplier: 1;
  --notes-multiplier: 1;
  --totals-multiplier: 1;
}

/* Entête */
.pdf-header h2 {
  font-size: calc(24px * var(--global-multiplier) * var(--header-multiplier));
}

.pdf-header p {
  font-size: calc(13px * var(--global-multiplier) * var(--header-multiplier));
}

.document-badge h1 {
  font-size: calc(38px * var(--global-multiplier) * var(--header-multiplier));
}

.document-badge p {
  font-size: calc(14px * var(--global-multiplier) * var(--header-multiplier));
}

/* Blocs émetteur / client */
.pdf-parties h3,
.work-address h3 {
  font-size: calc(14px * var(--global-multiplier) * var(--party-multiplier));
}

.pdf-parties p,
.work-address p {
  font-size: calc(13px * var(--global-multiplier) * var(--party-multiplier));
}

/* Tableau */
.pdf-table {
  font-size: calc(13px * var(--global-multiplier) * var(--table-multiplier));
}

.pdf-table th,
.pdf-table td {
  padding: calc(12px * var(--global-multiplier) * var(--table-multiplier))
           calc(10px * var(--global-multiplier) * var(--table-multiplier));
}

/* Notes */
.pdf-notes {
  font-size: calc(13px * var(--global-multiplier) * var(--notes-multiplier));
}

.pdf-notes h3 {
  font-size: calc(14px * var(--global-multiplier) * var(--notes-multiplier));
}

.legal-note {
  font-size: calc(12px * var(--global-multiplier) * var(--notes-multiplier));
}

/* Totaux */
.totals-box div {
  font-size: calc(13px * var(--global-multiplier) * var(--totals-multiplier));
  padding: calc(11px * var(--global-multiplier) * var(--totals-multiplier))
           calc(14px * var(--global-multiplier) * var(--totals-multiplier));
}

.totals-box .net {
  font-size: calc(16px * var(--global-multiplier) * var(--totals-multiplier));
}

/* Conditions de paiement */
.payment-info {
  font-size: calc(13px * var(--global-multiplier));
}

/* Signature */
.signature-zone p {
  font-size: calc(13px * var(--global-multiplier));
}



.pdf-header,
.pdf-parties,
.work-address,
.totals-zone,
.payment-info,
.signature-zone,
.pdf-footer,
.pdf-table tr {
  page-break-inside: avoid;
  break-inside: avoid;
}
.pdf-document {
  transform-origin: top left;
}

.form-panel::-webkit-scrollbar,
.pdf-wrapper::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.form-panel::-webkit-scrollbar-thumb,
.pdf-wrapper::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

.form-panel::-webkit-scrollbar-track,
.pdf-wrapper::-webkit-scrollbar-track {
  background: transparent;
}

.logo-upload-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.logo-upload-row input {
  flex: 1;
}

@media (max-width: 760px) {
  .logo-upload-row {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Empêche les longues désignations de sortir du tableau */
.pdf-table {
  table-layout: fixed;
}

.pdf-table th:first-child,
.pdf-table td:first-child {
  width: 52%;
}

.pdf-table th:not(:first-child),
.pdf-table td:not(:first-child) {
  width: auto;
  white-space: nowrap;
}

.pdf-table td:first-child {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.4;
}

.item-title-preview {
  font-weight: 800;
  margin-bottom: 4px;
}

.item-details-preview {
  margin: 4px 0 0;
  padding-left: 16px;
}

.item-details-preview li {
  margin-bottom: 2px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.dash-list {
  list-style: none;
}

.dash-list li::before {
  content: "- ";
}

.item-designation-block {
  margin-bottom: 12px;
}

.item-grid-prices {
  grid-template-columns: 0.8fr 0.8fr 1fr 0.8fr auto;
}

.item-designation-block textarea {
  min-height: 90px;
}

.item-group-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.subitems-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.subitem-grid {
  display: grid;
  grid-template-columns: 2fr 0.7fr 0.8fr 0.9fr 0.7fr auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  background: #ffffff;
}

.group-row td {
  background: #f3f4f6;
  color: #111827;
  font-weight: 800;
  padding-top: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e5e7eb;
}

.subitem-row-preview td {
  border-bottom: 1px solid #e5e7eb;
}

.subitem-description-preview {
  padding-left: 26px !important;
  white-space: normal !important;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (max-width: 760px) {
  .item-group-header,
  .subitem-grid {
    grid-template-columns: 1fr;
  }
}

.item-group-header textarea {
  min-height: 56px;
  line-height: 1.4;
}

.group-row td {
  white-space: normal !important;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.4;
}

.payment-quick-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -6px 0 16px;
}

.payment-info {
  line-height: 1.5;
}

.footer-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.custom-footer {
  margin-top: 34px;
  text-align: left;
  color: #111827;
  font-size: calc(12px * var(--global-multiplier));
  line-height: 1.6;
  border-top: 1px solid #e5e7eb;
  padding-top: 18px;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.custom-footer div,
.custom-footer strong {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.custom-footer div {
  margin-bottom: 3px;
}

.custom-footer strong {
  font-weight: 800;
}

.footer-line {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.footer-dash,
.footer-bullet,
.footer-number {
  padding-left: 12px;
}

.custom-footer,
.custom-footer * {
  max-width: 100%;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  white-space: normal !important;
}

.footer-line {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  white-space: normal !important;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 24px;
}

.example-modal {
  width: min(980px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: #ffffff;
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.35);
  padding: 26px;
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid #e5e7eb;
}

.modal-header h2 {
  margin: 0;
  font-size: 24px;
  color: #111827;
}

.modal-header p {
  margin: 6px 0 0;
  color: #6b7280;
  font-size: 14px;
}

.modal-close {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 14px;
  background: #f3f4f6;
  color: #111827;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  transition: 0.2s ease;
}

.modal-close:hover {
  background: #fee2e2;
  color: #dc2626;
}

.example-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.example-card {
  border: 1px solid #e5e7eb;
  background: #ffffff;
  border-radius: 18px;
  padding: 18px;
  cursor: pointer;
  text-align: left;
  display: grid;
  grid-template-columns: 48px 1fr;
  column-gap: 14px;
  row-gap: 4px;
  align-items: center;
  transition: 0.2s ease;
}

.example-card:hover {
  border-color: #2563eb;
  background: #eff6ff;
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.14);
}

.example-icon {
  grid-row: span 2;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: #f1f5f9;
  display: grid;
  place-items: center;
  font-size: 24px;
}

.example-card strong {
  color: #111827;
  font-size: 16px;
}

.example-card small {
  color: #6b7280;
  font-size: 13px;
}

@media (max-width: 760px) {
  .example-modal {
    padding: 20px;
  }

  .modal-header {
    align-items: center;
  }

  .example-grid {
    grid-template-columns: 1fr;
  }
}

.back-home-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.privacy-message {
  margin: 6px 0 0;
  color: #166534;
  font-size: 12px;
  font-weight: 600;
}

@media (max-width: 520px) {
  .pdf-size-presets {
    grid-template-columns: 1fr;
  }
}

/* Champs numériques sans flèches */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Meilleure lisibilité des petits champs */
.subitem-grid input[type="number"] {
  text-align: center;
  padding: 10px 6px;
}

/* Empêcher les titres de groupe de déborder dans le PDF */
.pdf-table {
  width: 100%;
  table-layout: fixed;
}

.group-row td {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.group-title-preview {
  display: block;
  width: 100%;
  max-width: 100%;

  white-space: normal;
  overflow-wrap: anywhere;
  word-wrap: break-word;
  word-break: break-word;

  line-height: 1.4;
}

.group-row,
.group-row td,
.group-title-preview {
  box-sizing: border-box;
}