:root {
  --purple: #ED007C;
  --purple-hover: #C7005F;
  --purple-light: #D6006E;
  --purple-bg: #FDEAF3;
  --purple-bg-hover: #FBD9E9;
  --border: #F5DCE9;
  --text: #241019;
  --muted: #7A5A6C;
  --faint: #B98CA5;
  --faint2: #E3C0D3;
  --orange: #A6D218;
  --orange-total: #B8E62A;
  --green: #1f9d55;
  --green-bg: #e9fbf0;
  --green-bg-hover: #dcf7e6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Manrope', sans-serif;
  color: var(--text);
  background: #ffffff;
}

input, textarea, button {
  font-family: 'Manrope', sans-serif;
}

.app {
  display: flex;
  height: 100vh;
  background: #ffffff;
}

/* ---------- Form panel ---------- */

.form-panel {
  width: 400px;
  min-width: 400px;
  height: 100vh;
  overflow-y: auto;
  background: #ffffff;
  border-right: 1px solid var(--border);
  padding: 24px;
}

.brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--purple);
  margin-bottom: 2px;
}

.brand-sub {
  font-size: 12px;
  color: var(--faint);
  margin-bottom: 18px;
}

.logout-link {
  font-size: 11px;
  font-weight: 700;
  color: var(--purple-light);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--purple-bg);
  white-space: nowrap;
}

.logout-link:hover {
  background: var(--purple-bg-hover);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 22px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 14px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}

.btn-primary { background: var(--purple); color: #ffffff; }
.btn-primary:hover { background: var(--purple-hover); }

.btn-secondary { background: var(--purple-bg); color: var(--purple-light); }
.btn-secondary:hover { background: var(--purple-bg-hover); }

.btn-whatsapp { background: var(--green-bg); color: var(--green); }
.btn-whatsapp:hover { background: var(--green-bg-hover); }

.hint {
  font-size: 11px;
  color: var(--faint);
  margin-top: 4px;
  line-height: 1.5;
}

.action-status {
  font-size: 11px;
  font-weight: 600;
  color: var(--purple-light);
  background: var(--purple-bg);
  padding: 8px 10px;
  border-radius: 6px;
  margin-top: 8px;
  line-height: 1.4;
}

.action-status.is-error {
  color: #c0392b;
  background: #fdeeee;
}

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

.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--purple-light);
  text-transform: uppercase;
  margin-bottom: 10px;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.btn-mini {
  border: none;
  background: var(--purple-bg);
  color: var(--purple-light);
  font-size: 11px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.grid-2[hidden] {
  display: none;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.stack-tight {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

.field input,
.field select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  background: #ffffff;
  font-family: inherit;
}

.auto-note {
  font-size: 11px;
  color: var(--purple-light);
  margin: -8px 0 16px;
  min-height: 14px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 8px;
  cursor: pointer;
}

.checkbox-field:last-of-type { margin-bottom: 16px; }

.item-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  position: relative;
}

.item-row .remove-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  border: none;
  background: transparent;
  color: var(--faint2);
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
}

.item-row input[type="text"] {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.item-row input.item-description {
  font-size: 12px;
  font-weight: 400;
}

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

.item-row-grid label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 10px;
  color: var(--faint);
}

.item-row-grid input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}

.method-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.method-row input {
  flex: 1;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}

.method-row button {
  border: none;
  background: transparent;
  color: var(--faint2);
  font-size: 14px;
  cursor: pointer;
}

/* ---------- Preview panel ---------- */

.preview-scroll {
  flex: 1;
  height: 100vh;
  overflow-y: auto;
  background: #F7EAF1;
  padding: 40px;
  display: flex;
  justify-content: center;
}

.doc-page {
  width: 794px;
  height: 1120px;
  background: #ffffff;
  box-shadow: 0 4px 24px rgba(237, 0, 124, 0.12);
  padding: 0.5in;
  box-sizing: border-box;
  overflow: hidden;
}

.doc-page.pdf-capture {
  box-shadow: none;
}

#docPageInner {
  transform-origin: top left;
}

.doc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.doc-logo {
  height: 58px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.doc-brand-text {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  padding: 0 12px;
}

.doc-brand-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--purple);
  letter-spacing: 0.2px;
}

.doc-brand-tagline {
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.2px;
  line-height: 1.6;
  margin: 4px auto 0;
  max-width: 360px;
}

.doc-header-right {
  flex-shrink: 0;
  text-align: right;
}

.doc-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--purple);
}

.doc-mono {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}

.doc-muted {
  color: var(--faint);
  font-size: 12px;
  margin-top: 2px;
}

.gradient-bar {
  height: 5px;
  width: 100%;
  background: linear-gradient(90deg, #ED007C 0%, #C7005F 50%, #A6D218 100%);
  margin-top: 20px;
}

.doc-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 24px;
  break-inside: avoid;
}

.doc-box {
  background: var(--purple-bg);
  border-radius: 10px;
  padding: 18px 20px;
}

.doc-box-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--purple-light);
  text-transform: uppercase;
  margin-bottom: 10px;
}

.doc-box-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.doc-adresse {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.doc-emetteur-row {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.doc-mini-label {
  font-size: 10px;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.doc-emetteur-row .doc-mono {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text);
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 24px;
}

.doc-table thead tr {
  background: var(--purple);
}

.doc-table tbody tr {
  break-inside: avoid;
}

.doc-table th {
  padding: 11px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: #ffffff;
  text-transform: uppercase;
}

.doc-table th.col-n { width: 36px; }
.doc-table th.col-qte { width: 56px; text-align: center; }
.doc-table th.col-prix { width: 90px; text-align: right; }
.doc-table th.col-total { width: 100px; text-align: right; }

.doc-table td {
  padding: 11px 10px;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.doc-table td.cell-n { color: var(--muted); }
.doc-table td.cell-designation { font-weight: 600; }
.doc-table td.cell-description { font-size: 12px; color: var(--faint); }
.doc-table td.cell-qte { text-align: center; }
.doc-table td.cell-prix {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}
.doc-table td.cell-total {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 700;
  text-align: right;
}

.doc-totals-wrap {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
  break-inside: avoid;
}

.doc-totals { width: 280px; }

.doc-totals-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  font-size: 13px;
  color: var(--muted);
}

.doc-totals-row .doc-mono {
  margin-top: 0;
  color: var(--text);
}

.doc-totals-row-tva {
  border-bottom: 1px solid var(--border);
}

.doc-total-final {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding: 13px 18px;
  background: var(--purple);
  border-radius: 10px;
}

.doc-total-final span:first-child {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #ffffff;
  text-transform: uppercase;
}

.doc-total-final .doc-mono {
  margin-top: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--orange-total);
}

.doc-lettres {
  margin-top: 22px;
  padding: 15px 20px;
  background: var(--purple-bg);
  border-left: 3px solid var(--orange);
  border-radius: 0 8px 8px 0;
  break-inside: avoid;
}

.doc-lettres-label {
  font-size: 12px;
  color: var(--faint);
  margin-right: 6px;
}

.doc-lettres-text {
  font-size: 14px;
  font-style: italic;
  color: var(--text);
  font-weight: 500;
}

.doc-methods {
  margin-top: 22px;
  break-inside: avoid;
}

.doc-methods-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--faint);
  text-transform: uppercase;
  margin-bottom: 10px;
}

.doc-methods-list {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.doc-method-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--purple-bg);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--purple-light);
}

.doc-method-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--orange);
  display: inline-block;
}

.doc-footer {
  display: grid;
  grid-template-columns: 1.3fr 1fr 0.8fr;
  gap: 16px;
  align-items: end;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  break-inside: avoid;
}

.doc-footer-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.doc-footer-info {
  font-size: 12px;
  color: var(--faint);
  margin-top: 6px;
  line-height: 1.6;
}

.doc-footer-thanks {
  text-align: center;
}

.doc-signature {
  display: block;
  max-height: 42px;
  max-width: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  margin: 0 auto 4px;
}

.doc-signature[hidden] {
  display: none;
}

.doc-footer-merci {
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
}

.doc-footer-direction {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-top: 6px;
}

.doc-footer-qr {
  text-align: right;
}

.doc-qr-canvas {
  display: inline-block;
  line-height: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.doc-qr-canvas img,
.doc-qr-canvas canvas {
  width: 74px;
  height: 74px;
  display: block;
}

.doc-qr-caption {
  font-size: 9px;
  color: var(--faint);
  margin-top: 4px;
}

.doc-bottom-bar {
  height: 34px;
  margin-top: 28px;
  background: linear-gradient(90deg, #ED007C 0%, #C7005F 50%, #A6D218 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  break-inside: avoid;
}

.doc-bottom-bar span {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 1.4px;
  color: rgba(255, 255, 255, 0.9);
  text-transform: uppercase;
}

/* ---------- Page de connexion ---------- */

.login-body {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  background: linear-gradient(135deg, #4A002E 0%, #ED007C 45%, #A6D218 100%);
  background-size: 200% 200%;
  animation: loginGradientShift 14s ease infinite;
}

@keyframes loginGradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.login-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
  pointer-events: none;
}

.login-orb-1 {
  width: 380px;
  height: 380px;
  top: -120px;
  left: -100px;
  background: #FF4FA3;
}

.login-orb-2 {
  width: 420px;
  height: 420px;
  bottom: -140px;
  right: -120px;
  background: #A6D218;
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 380px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 20px;
  padding: 40px 34px;
  box-shadow: 0 24px 60px rgba(74, 0, 46, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.login-logo-wrap {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--purple-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  box-shadow: 0 6px 16px rgba(237, 0, 124, 0.15);
}

.login-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.login-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--purple);
}

.login-sub {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--faint);
  text-transform: uppercase;
  margin-top: 4px;
  margin-bottom: 26px;
}

.login-error {
  width: 100%;
  background: #fdeeee;
  color: #c0392b;
  font-size: 12px;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 18px;
  box-sizing: border-box;
  text-align: left;
}

.login-field {
  width: 100%;
  text-align: left;
  margin-bottom: 16px;
}

.login-field-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

.login-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  background: #FDF6FA;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-input-wrap:focus-within {
  border-color: var(--purple-light);
  box-shadow: 0 0 0 3px rgba(214, 0, 110, 0.15);
}

.login-input-icon {
  font-size: 13px;
  opacity: 0.7;
}

.login-input-wrap input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 11px 0;
  font-size: 14px;
  color: var(--text);
  outline: none;
}

.login-submit {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 13px 14px;
  margin-top: 6px;
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
  cursor: pointer;
  background: linear-gradient(90deg, #ED007C 0%, #C7005F 100%);
  box-shadow: 0 10px 24px rgba(237, 0, 124, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.login-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(237, 0, 124, 0.42);
}

.login-submit-arrow {
  transition: transform 0.15s ease;
}

.login-submit:hover .login-submit-arrow {
  transform: translateX(3px);
}

.login-footer-note {
  font-size: 11px;
  color: var(--faint);
  margin-top: 20px;
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  .no-print { display: none !important; }
  body { background: #ffffff !important; }
  .preview-scroll {
    overflow: visible !important;
    height: auto !important;
    padding: 0 !important;
    background: #ffffff !important;
    display: block !important;
  }
  .doc-page {
    box-shadow: none !important;
    width: 210mm !important;
    height: 297mm !important;
    padding: 12.7mm !important;
    margin: 0 !important;
    overflow: hidden !important;
  }
  @page { size: A4; margin: 0; }
}
