@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* iOS Safari resets */
input, textarea, select, button {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border-radius: 0;
  font-family: 'Poppins', sans-serif;
  color: inherit;
}
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, h5, h6 { color: inherit; font-weight: inherit; }

:root {
  --accent: #f5c518;
  --dark: #1a1a1a;
  --gray: #6b7280;
  --light: #f9fafb;
  --border: #e5e7eb;
  --radius: 12px;
  --primary: #111827;
}

body {
  font-family: 'Poppins', sans-serif;
  background: #f3f4f6;
  color: var(--primary);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* ── LAYOUT ── */
.page-wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

.logo-wrap {
  text-align: center;
  margin-bottom: 32px;
}
.logo-wrap img {
  height: 80px;
  object-fit: contain;
}

.page-title {
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}
.page-subtitle {
  text-align: center;
  color: var(--gray);
  font-size: 14px;
  margin-bottom: 36px;
}

/* ── CARDS ── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
  padding: 28px 32px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  padding-bottom: 16px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

/* ── DOC TYPE SELECTOR ── */
.doc-type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.doc-type-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  transition: all .2s;
  font-family: 'Poppins', sans-serif;
}
.doc-type-btn:hover { border-color: #ccc; }
.doc-type-btn.active {
  border-color: var(--accent);
  background: #fffbeb;
}
.doc-type-btn svg { width: 22px; height: 22px; flex-shrink: 0; }
.doc-type-btn .btn-label { font-weight: 700; font-size: 14px; color: var(--primary); }
.doc-type-btn .btn-sub { font-size: 11px; color: var(--gray); }

/* ── FORM GRID ── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.col-span-2 { grid-column: span 2; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
}
.field label .req { color: #ef4444; margin-left: 2px; }
.field label .opt { color: var(--gray); font-weight: 400; font-size: 11px; margin-left: 4px; }

input, select, textarea {
  font-family: 'Poppins', sans-serif;
  font-size: 16px; /* prevents iOS auto-zoom */
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--primary);
  transition: border-color .2s;
  width: 100%;
}
@media (min-width: 641px) {
  input, select, textarea { font-size: 13px; }
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245,197,24,.15);
}
textarea { resize: vertical; min-height: 80px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* ── TVA TOGGLE ── */
.tva-toggle-wrap { display: flex; flex-direction: column; gap: 6px; }
.tva-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all .2s;
  user-select: none;
}
.tva-toggle.on { border-color: var(--accent); background: #fffbeb; }
.toggle-track {
  width: 40px; height: 22px;
  border-radius: 11px;
  background: #d1d5db;
  position: relative;
  flex-shrink: 0;
  transition: background .2s;
}
.tva-toggle.on .toggle-track { background: var(--accent); }
.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .2s;
}
.tva-toggle.on .toggle-thumb { transform: translateX(18px); }
.toggle-label { font-size: 13px; font-weight: 500; color: var(--gray); }
.tva-toggle.on .toggle-label { color: var(--primary); }

/* ── SERVICES TABLE ── */
.services-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.services-header h3 { font-size: 16px; font-weight: 700; }
.services-header p { font-size: 12px; color: var(--gray); }

.svc-cols {
  display: grid;
  grid-template-columns: 1fr 110px 140px 90px 40px;
  gap: 10px;
  padding: 8px 12px;
  background: var(--light);
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray);
}
.svc-row {
  display: grid;
  grid-template-columns: 1fr 110px 140px 90px 40px;
  gap: 10px;
  padding: 14px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  align-items: start;
  background: #fff;
}
.svc-desc { display: flex; flex-direction: column; gap: 6px; }
.svc-title-input { font-weight: 600 !important; }
.svc-col-label {
  display: none;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray);
  margin-bottom: 4px;
}
.svc-price-col, .svc-qty-col, .svc-pt-col { display: flex; flex-direction: column; }
.svc-pu-input { text-align: right; }

/* Qty stepper */
.qty-stepper {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.qty-stepper input {
  border: none !important;
  box-shadow: none !important;
  text-align: center;
  flex: 1;
  min-width: 0;
  padding: 9px 4px;
  font-weight: 600;
  font-size: 14px;
}
.qty-stepper input:focus { outline: none; }
.qty-btn {
  width: 36px;
  height: 38px;
  border: none;
  background: var(--light);
  color: var(--primary);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
  font-family: 'Poppins', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.qty-btn:hover { background: #e5e7eb; }
.qty-btn:active { background: var(--accent); }

.svc-total {
  display: flex;
  align-items: center;
  height: 38px;
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
}
.btn-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 8px;
  color: #9ca3af;
  transition: all .2s;
  font-size: 16px;
  margin-top: 2px;
}
.btn-remove:hover { background: #fee2e2; color: #ef4444; }

/* ── TOTALS ── */
.totals-wrap {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.totals-box { min-width: 280px; }
.totals-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 4px 0;
  color: var(--gray);
}
.totals-row.total-ttc {
  font-size: 16px;
  font-weight: 800;
  color: var(--primary);
  padding-top: 10px;
  margin-top: 6px;
  border-top: 2px solid var(--border);
}
.totals-row.total-ttc span:last-child { color: var(--accent); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 10px;
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .2s;
  text-decoration: none;
}
.btn-primary {
  background: var(--accent);
  color: var(--primary);
  width: 100%;
  justify-content: center;
  font-size: 16px;
  padding: 16px;
}
.btn-primary:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-outline {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--border);
}
.btn-outline:hover { border-color: #aaa; background: var(--light); }
.btn-add {
  width: 100%;
  justify-content: center;
  background: #fff;
  color: var(--primary);
  border: 1.5px dashed var(--border);
  margin-top: 4px;
}
.btn-add:hover { border-color: var(--accent); background: #fffbeb; }

/* ── TAUX TVA ── */
.taux-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-radius: 10px;
  margin-top: 8px;
}
.taux-row label { font-size: 13px; font-weight: 600; color: #92400e; white-space: nowrap; }
.taux-row input { max-width: 80px; }
.taux-row span { font-size: 13px; color: #92400e; }

/* ── PREVIEW PAGE ── */
.preview-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

/* A4 document */
.doc-a4 {
  background: #fff;
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  box-shadow: 0 4px 32px rgba(0,0,0,.12);
  display: flex;
  flex-direction: column;
  font-family: 'Poppins', sans-serif;
}
.doc-accent-bar { height: 5px; background: var(--accent); flex-shrink: 0; }
.doc-body { flex: 1; padding: 36px 44px 28px; }
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
}
.doc-header img { height: 72px; object-fit: contain; }
.doc-title-block { text-align: right; }
.doc-title-block h1 {
  font-size: 30px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
  border-bottom: 3px solid var(--accent);
  padding-bottom: 3px;
  margin-bottom: 4px;
}
.doc-title-block .doc-num { font-size: 15px; font-weight: 600; color: #333; }

.doc-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin-bottom: 28px;
}
.doc-meta-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #9ca3af;
  margin-bottom: 6px;
}
.doc-client-name { font-size: 16px; font-weight: 700; color: var(--primary); margin-bottom: 3px; }
.doc-client-info { font-size: 12px; color: var(--gray); line-height: 1.6; }
.doc-meta-right { text-align: right; }
.doc-meta-right .meta-item { margin-bottom: 10px; }
.doc-meta-right .meta-val { font-size: 13px; font-weight: 600; color: #333; }

/* Services table */
.doc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc-table thead tr { background: var(--accent); color: var(--primary); }
.doc-table th { padding: 10px 13px; font-weight: 700; }
.doc-table th:first-child { text-align: left; }
.doc-table th:not(:first-child) { text-align: right; }
.doc-table td { padding: 10px 13px; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc-table td:not(:first-child) { text-align: right; }
.doc-table tbody tr:nth-child(even) { background: #fafafa; }
.svc-title { font-weight: 700; font-size: 13px; color: var(--primary); margin-bottom: 3px; }
.svc-desc-text { font-size: 12px; color: var(--gray); white-space: pre-wrap; line-height: 1.5; }

.doc-table tfoot td { padding: 8px 13px; font-size: 13px; color: var(--gray); }
.doc-table tfoot .row-ht td { border-top: 2px solid var(--border); }
.doc-table tfoot .row-total td {
  border-top: 2px solid var(--accent);
  font-size: 15px;
  font-weight: 800;
  color: var(--primary);
  padding-top: 10px;
}

.doc-words {
  font-size: 12px;
  color: #555;
  margin-top: 20px;
  font-style: italic;
}
.doc-words strong { font-style: normal; color: var(--primary); }

/* Footer */
.doc-footer {
  flex-shrink: 0;
  border-top: 3px solid var(--accent);
  background: #f8f8f6;
  padding: 16px 44px;
  text-align: center;
}
.doc-footer .footer-name { font-size: 13px; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.doc-footer .footer-line { font-size: 12px; color: var(--gray); margin-bottom: 3px; }
.doc-footer .footer-legal { font-size: 12px; color: #9ca3af; }

/* ── PRINT ── */
@media print {
  body { background: white; }
  .preview-actions, .no-print { display: none !important; }
  .doc-a4 { box-shadow: none; width: 100%; min-height: unset; }
  @page { size: A4 portrait; margin: 0; }
}

/* ── RESPONSIVE ── */
@media (max-width: 640px) {
  /* Fix input font size on mobile — must match label size */
  input, select, textarea { font-size: 14px; }
  .field label { font-size: 13px; }

  .form-grid { grid-template-columns: 1fr; }
  .form-grid.cols-3 { grid-template-columns: 1fr 1fr; }
  .col-span-2 { grid-column: span 1; }
  .doc-type-grid { grid-template-columns: 1fr 1fr; }

  /* Hide desktop column headers */
  .svc-cols { display: none; }

  /* Mobile service row: stacked layout */
  .svc-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
  }

  /* Title + desc full width */
  .svc-desc { width: 100%; }

  /* P.U and Qté side by side */
  .svc-row-bottom {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
  }

  /* Show labels on mobile */
  .svc-col-label { display: block; }

  /* P.T full width below */
  .svc-pt-col {
    width: 100%;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }
  .svc-pt-col .svc-col-label { margin-bottom: 0; font-size: 12px; }
  .svc-total { height: auto; font-size: 15px; }

  /* Remove button top-right */
  .btn-remove {
    position: absolute;
    top: 10px;
    right: 10px;
  }
  .svc-row { position: relative; }

  .doc-a4 { width: 100%; }
  .doc-meta { grid-template-columns: 1fr; }
}
