/* ═══════════════════════════════════════════
   RESET & VARIABLES
   ═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --terracotta: #2a5f8f;
  --terracotta-light: #3a7ab5;
  --terracotta-dark: #1e4a6e;
  --earth: #1a2332;
  --earth-light: #2d3a4d;
  --gold: #D4A847;
  --gold-light: #e0be6e;
  --sand: #f0f4f8;
  --sand-dark: #dce4ed;
  --white: #FFFFFF;
  --gray-100: #f7f7f7;
  --gray-200: #e5e5e5;
  --gray-300: #d4d4d4;
  --gray-400: #a3a3a3;
  --gray-500: #737373;
  --gray-600: #525252;
  --gray-700: #404040;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --success-light: #f0fdf4;

  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'DM Mono', 'Courier New', monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 2px rgba(61,43,31,0.06);
  --shadow-md: 0 4px 12px rgba(61,43,31,0.08);
  --shadow-lg: 0 8px 24px rgba(61,43,31,0.12);
  --shadow-xl: 0 16px 48px rgba(61,43,31,0.16);

  --transition: 0.2s ease;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  background: var(--sand);
  color: var(--earth);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════
   APP SHELL
   ═══════════════════════════════════════════ */
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--white);
  position: relative;
}

/* ── Header ── */
.app-header {
  background: var(--earth);
  padding: calc(var(--safe-top) + 12px) 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--gold);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  color: var(--earth);
}

.logo-text {
  color: var(--gold);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 1px;
}

.logo-sub {
  color: var(--sand-dark);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.5px;
  display: block;
  margin-top: -2px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(212,168,71,0.3);
  background: transparent;
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover { background: rgba(212,168,71,0.1); }

/* ── Stepper ── */
.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 20px;
  gap: 0;
  background: var(--white);
  border-bottom: 1px solid var(--sand-dark);
}

.step {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: var(--transition);
  opacity: 0.4;
}

.step.active { opacity: 1; }
.step.completed { opacity: 0.7; }

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--sand);
  color: var(--gray-500);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.step.active .step-num {
  background: var(--terracotta);
  color: var(--white);
}

.step.completed .step-num {
  background: var(--success);
  color: var(--white);
}

.step-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
  white-space: nowrap;
}

.step.active .step-label { color: var(--earth); }

.step-connector {
  width: 32px;
  height: 2px;
  background: var(--sand-dark);
  margin: 0 8px;
  border-radius: 1px;
  transition: var(--transition);
}

.step-connector.done { background: var(--success); }

/* ── Content area ── */
.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.screen {
  display: none;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

.screen.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Bottom bar ── */
.bottom-bar {
  padding: 12px 20px calc(var(--safe-bottom) + 12px);
  background: var(--white);
  border-top: 1px solid var(--sand-dark);
  display: flex;
  gap: 10px;
}

/* ═══════════════════════════════════════════
   COMMON COMPONENTS
   ═══════════════════════════════════════════ */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
  flex: 1;
}

.btn-primary {
  background: var(--terracotta);
  color: var(--white);
}
.btn-primary:hover { background: var(--terracotta-dark); }
.btn-primary:disabled { background: var(--gray-300); cursor: not-allowed; }

.btn-secondary {
  background: var(--sand);
  color: var(--earth);
  border: 1px solid var(--sand-dark);
}
.btn-secondary:hover { background: var(--sand-dark); }

.btn-gold {
  background: var(--gold);
  color: var(--earth);
}
.btn-gold:hover { background: var(--gold-light); }

.btn-outline {
  background: transparent;
  color: var(--terracotta);
  border: 1.5px solid var(--terracotta);
}
.btn-outline:hover { background: rgba(196,98,45,0.06); }

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

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

/* Cards */
.card {
  background: var(--white);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: var(--transition);
}

.card-elevated {
  box-shadow: var(--shadow-md);
  border: none;
}

/* Form fields */
.field { margin-bottom: 16px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--sand-dark);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--earth);
  background: var(--white);
  transition: var(--transition);
  outline: none;
}

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--terracotta);
  box-shadow: 0 0 0 3px rgba(196,98,45,0.1);
}

.field input.mono, .field .mono {
  font-family: var(--font-mono);
}

.field textarea { resize: vertical; min-height: 60px; }

/* Section title */
.section-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--earth);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title svg { width: 22px; height: 22px; color: var(--terracotta); }

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-gold { background: rgba(212,168,71,0.15); color: #b08a2a; }
.badge-success { background: var(--success-light); color: var(--success); }

/* ═══════════════════════════════════════════
   SCREEN 1 — IMPORT
   ═══════════════════════════════════════════ */
.import-hero {
  text-align: center;
  padding: 20px 0 24px;
}

.import-hero h2 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  color: var(--earth);
  margin-bottom: 8px;
}

.import-hero p {
  font-size: 14px;
  color: var(--gray-500);
  line-height: 1.5;
}

/* Input method cards */
.input-methods {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.templates-open-btn { flex: 0 0 auto; width: auto; margin: 0 0 16px; }

/* Quick category selector */
.quick-categories {
  background: var(--sand);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
}
.quick-categories h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}
.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--gray-200);
  background: var(--white);
  font-size: 13px;
  font-weight: 500;
  color: var(--earth);
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}
.cat-chip:hover { border-color: var(--terracotta); background: rgba(196,98,45,0.06); }
.cat-chip.selected {
  border-color: var(--terracotta);
  background: var(--terracotta);
  color: #fff;
}
.cat-chip .cat-icon { font-size: 15px; line-height: 1; }
.quick-generate-btn {
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  background: var(--terracotta);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition);
}
.quick-generate-btn.visible { display: flex; }
.quick-generate-btn:hover { background: #b05428; }
.or-divider {
  text-align: center;
  position: relative;
  margin: 4px 0 8px;
  font-size: 12px;
  color: var(--gray-400);
  font-weight: 500;
}
.or-divider::before, .or-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 38%;
  height: 1px;
  background: var(--gray-200);
}
.or-divider::before { left: 0; }
.or-divider::after { right: 0; }

.method-card {
  background: var(--sand);
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.method-card:hover { border-color: var(--terracotta); background: var(--white); }
.method-card.selected { border-color: var(--terracotta); background: var(--white); box-shadow: var(--shadow-md); }

.method-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.method-icon.photo { background: rgba(196,98,45,0.12); color: var(--terracotta); }
.method-icon.voice { background: rgba(212,168,71,0.15); color: #b08a2a; }
.method-icon.text { background: rgba(61,43,31,0.08); color: var(--earth); }

.method-icon svg { width: 24px; height: 24px; }

.method-info h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--earth);
  margin-bottom: 4px;
}

.method-info p {
  font-size: 13px;
  color: var(--gray-500);
  line-height: 1.4;
}

/* Photo preview */
.photo-preview {
  display: none;
  margin-top: 12px;
  gap: 8px;
  flex-wrap: wrap;
}

.photo-preview.visible { display: flex; }

.photo-thumb {
  position: relative;
  width: calc(33.333% - 6px);
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--gray-100);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-thumb .remove-photo {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* Voice recorder */
.voice-area {
  display: none;
  margin-top: 12px;
}

.voice-area.visible { display: block; }

.voice-btn-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
}

.voice-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid var(--gold);
  background: var(--white);
  color: var(--gold);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  position: relative;
}

.voice-btn svg { width: 28px; height: 28px; }

.voice-btn.recording {
  border-color: var(--danger);
  color: var(--danger);
  animation: pulse-ring 1.5s ease infinite;
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(220,38,38,0.3); }
  70% { box-shadow: 0 0 0 14px rgba(220,38,38,0); }
  100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); }
}

.voice-status {
  font-size: 13px;
  color: var(--gray-500);
  text-align: center;
}

.voice-transcript {
  display: none;
  margin-top: 12px;
  padding: 12px;
  background: var(--sand);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--earth);
  line-height: 1.5;
}

.voice-transcript.visible { display: block; }

/* Text area */
.text-area {
  display: none;
  margin-top: 12px;
}

.text-area.visible { display: block; }

/* Inline checkbox toggle inside section headers (e.g. "Sans catégories") */
.inline-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--gray-500);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.inline-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--navy, #1C3876);
  cursor: pointer;
  margin: 0;
}
.inline-toggle:hover span { color: var(--earth, #3d2b1f); }

/* Supplementary instructions — shown alongside photo/voice/quick */
.instructions-area {
  display: none;
  margin-top: 12px;
}

.instructions-area.visible { display: block; }

.instructions-area .field label {
  font-size: 12px;
  color: var(--gray-500);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* AI analyzing overlay */
.analyzing-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(61,43,31,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.analyzing-overlay.visible { display: flex; }

.analyzing-box {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: 40px 32px;
  text-align: center;
  max-width: 300px;
  box-shadow: var(--shadow-xl);
}

.analyzing-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--sand-dark);
  border-top-color: var(--terracotta);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 20px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.analyzing-box h3 {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--earth);
  margin-bottom: 8px;
}

.analyzing-box p {
  font-size: 13px;
  color: var(--gray-500);
}

/* ═══════════════════════════════════════════
   SCREEN 2 — EDIT
   ═══════════════════════════════════════════ */
.edit-section { margin-bottom: 24px; }

.edit-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

/* Line items */
.line-items { display: flex; flex-direction: column; gap: 18px; }

/* Category group */
.line-group {
  background: var(--white);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.line-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--sand);
  border-bottom: 1px solid var(--sand-dark);
}
.line-group-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 13px;
  color: var(--earth);
  letter-spacing: 0.2px;
}
.line-group-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 6px;
  background: var(--earth);
  color: var(--sand);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
}
.line-group-count {
  font-size: 11px;
  color: var(--gray-400);
  font-weight: 400;
}
.line-group-add {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--sand-dark);
  color: var(--earth);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: var(--transition);
}
.line-group-add:hover { background: var(--sand-dark); }
.line-group-body { display: flex; flex-direction: column; gap: 10px; padding: 12px; }

.line-item {
  background: var(--sand);
  border-radius: var(--radius-md);
  padding: 14px;
  position: relative;
  transition: var(--transition);
  border: 1px solid transparent;
}

.line-item:focus-within { border-color: var(--terracotta); background: var(--white); }
.line-item.incomplete { border-color: var(--danger); }
.sortable-ghost { opacity: 0.35; background: var(--sand-dark) !important; }
.sortable-chosen { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.drag-handle {
  cursor: grab;
  color: var(--gray-300);
  display: flex;
  align-items: center;
  padding: 2px 4px;
  border-radius: 4px;
  touch-action: none;
  flex-shrink: 0;
}
.drag-handle:hover { color: var(--gray-400); background: var(--sand-dark); }
.drag-handle:active { cursor: grabbing; }
.line-item.incomplete .line-item-num::after {
  content: ' ⚠';
  color: var(--danger);
  font-size: 11px;
}

.line-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.line-item-num {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--gray-400);
}

.line-item-delete {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--gray-400);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.line-item-delete:hover { background: var(--danger-light); color: var(--danger); }
.line-item-save {
  width: 28px; height: 28px; border-radius: var(--radius-sm); border: none;
  background: transparent; color: var(--gray-400); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: var(--transition);
}
.line-item-save:hover { background: var(--sand); color: var(--terracotta); }

.line-item .field { margin-bottom: 10px; }
.line-item .field:last-child { margin-bottom: 0; }

.line-item .field label {
  font-size: 11px;
  margin-bottom: 4px;
}

.line-item .field input, .line-item .field select, .line-item .field textarea {
  padding: 8px 10px;
  font-size: 13px;
  background: var(--white);
}
.line-item .field textarea {
  width: 100%;
  min-height: 0;
  resize: none;
  overflow: hidden;
  font-family: var(--font-body);
  line-height: 1.4;
  display: block;
  box-sizing: border-box;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.line-item-total {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--terracotta);
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px dashed var(--sand-dark);
}

/* Totals */
.totals-card {
  background: var(--earth);
  border-radius: var(--radius-lg);
  padding: 20px;
  color: var(--sand);
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 14px;
}

.total-row.grand {
  font-size: 18px;
  font-weight: 700;
  color: var(--gold);
  padding-top: 12px;
  margin-top: 8px;
  border-top: 1px solid var(--earth-light);
}

.total-row .label { color: var(--sand-dark); }
.total-row .value { font-family: var(--font-mono); font-weight: 500; }
.total-row.grand .label { color: var(--gold-light); }

/* Avance / Reste à payer */
.avance-row { border-top: 1px dashed rgba(255,255,255,.2); margin-top: 6px; padding-top: 6px; }
.avance-row .label { font-size: 12px; }
.avance-input-wrap { display: flex; align-items: center; gap: 4px; }
.avance-input-wrap input {
  width: 80px; padding: 3px 6px; border-radius: 6px; border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.12); color: #fff; font-size: 12px; font-family: var(--font-mono);
  text-align: right;
}
.avance-input-wrap input::placeholder { color: rgba(255,255,255,.4); }
.avance-currency { font-size: 11px; opacity: .7; }
.reste-row { border-top: 1px solid rgba(255,255,255,.3); margin-top: 4px; }

/* Per-client financial KPIs */
.client-kpis {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin: 10px 0 12px;
}
.client-kpi {
  background: var(--white); border: 1px solid var(--sand-dark);
  border-radius: var(--radius-lg); padding: 10px 12px;
  border-left: 3px solid transparent;
}
.client-kpi.green  { border-left-color: #22c55e; }
.client-kpi.blue   { border-left-color: #3b82f6; }
.client-kpi.orange { border-left-color: #f97316; }
.client-kpi.gray   { border-left-color: #94a3b8; }
.client-kpi.red    { border-left-color: var(--danger); }
.client-kpi-val { font-size: 14px; font-weight: 700; font-family: var(--font-mono); color: var(--charcoal); line-height: 1.2; }
.client-kpi-lbl { font-size: 10px; color: var(--gray-500); margin-top: 2px; }

/* ═══════════════════════════════════════════
   SCREEN 3 — PDF / EXPORT
   ═══════════════════════════════════════════ */
.export-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.pdf-preview-frame {
  width: 100%;
  height: 500px;
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-md);
  background: var(--white);
}

/* ── Signature client ── */
.signature-section { margin-bottom: 20px; }
.signature-canvas {
  display: block;
  width: 100%;
  height: 160px;
  background: var(--white);
  border: 1.5px dashed var(--sand-dark);
  border-radius: var(--radius-md);
  touch-action: none;
  cursor: crosshair;
}
.signature-actions { display: flex; gap: 8px; margin-top: 8px; }
.signature-actions .btn { flex: 1; }
.signature-preview-img {
  display: block;
  max-width: 260px;
  max-height: 100px;
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-md);
  background: var(--white);
  padding: 6px;
}
.signature-saved-note {
  font-size: 12px;
  color: var(--success);
  font-weight: 600;
  margin-top: 8px;
  line-height: 1.5;
}
.signature-redo-btn {
  border: none;
  background: none;
  color: var(--terracotta);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  font-size: 12px;
  padding: 0 0 0 4px;
}

/* ═══════════════════════════════════════════
   API KEY MODAL
   ═══════════════════════════════════════════ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(61,43,31,0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 300;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.visible { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 24px 20px calc(var(--safe-bottom) + 24px);
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--gray-300);
  border-radius: 2px;
  margin: 0 auto 20px;
}

.modal h3 {
  font-family: var(--font-display);
  font-size: 20px;
  margin-bottom: 8px;
}

.modal p {
  font-size: 13px;
  color: var(--gray-500);
  margin-bottom: 16px;
  line-height: 1.5;
}

/* ═══════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--earth);
  color: var(--white);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  z-index: 400;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-lg);
  max-width: 90%;
  text-align: center;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error { background: var(--danger); }

/* ═══════════════════════════════════════════
   PIN GATE
   ═══════════════════════════════════════════ */
#pin-gate {
  position: fixed;
  inset: 0;
  background: var(--earth);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 40px 24px;
  gap: 0;
}
#pin-gate .pin-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 40px;
  gap: 8px;
}
#pin-gate .pin-logo-icon {
  width: 64px;
  height: 64px;
  background: var(--gold);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 32px;
  color: var(--earth);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
#pin-gate .pin-logo-name {
  color: var(--gold);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 3px;
}
#pin-gate .pin-logo-sub {
  color: rgba(220,200,150,0.55);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
#pin-gate .pin-title {
  color: rgba(220,200,150,0.8);
  font-size: 13px;
  margin-bottom: 24px;
  letter-spacing: 0.5px;
}
.pin-dots {
  display: flex;
  gap: 14px;
  margin-bottom: 32px;
}
.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(212,168,71,0.5);
  background: transparent;
  transition: background 0.15s, border-color 0.15s;
}
.pin-dot.filled {
  background: var(--gold);
  border-color: var(--gold);
}
.pin-dots.shake {
  animation: pinShake 0.4s ease;
}
@keyframes pinShake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.pin-dots.error .pin-dot.filled {
  background: var(--danger);
  border-color: var(--danger);
}
.pin-numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 260px;
  margin-bottom: 16px;
}
.pin-key {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  color: #fff;
  font-size: 22px;
  font-weight: 500;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.12s, transform 0.1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.pin-key:active { background: rgba(212,168,71,0.25); transform: scale(0.94); }
.pin-key.del { font-size: 16px; color: rgba(255,255,255,0.6); }
.pin-key.empty { visibility: hidden; }
#pin-input-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}
.pin-error-msg {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  text-align: center;
  transition: opacity 0.2s;
}
#pin-locked {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: rgba(220,200,150,0.7);
  font-size: 14px;
  text-align: center;
  display: none;
}
#pin-locked svg { opacity: 0.6; }

/* ═══════════════════════════════════════════
   SCROLLBAR
   ═══════════════════════════════════════════ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--sand-dark); border-radius: 2px; }

/* ═══════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════ */

/* ── Tablet (481-767px): narrow card, slight lift ───────────────────── */
@media (min-width: 481px) and (max-width: 767px) {
  body { background: var(--sand); }
  .app { box-shadow: var(--shadow-xl); min-height: 100vh; }
}

/* ── Desktop (≥ 768px): full two-column layout ───────────────────────
   Philosophy: mobile = single column card; desktop = wide card with
   a left sidebar (meta/notes/totals) and a right main area (lines / preview).
   No JS required — pure CSS grid + targeted overrides.              */
@media (min-width: 768px) {
  /* On desktop the window scrolls, not .content.
     overflow-y: auto on .content would make it the sticky scroll container
     instead of the window, which breaks position:sticky on children. */
  .content { overflow: visible; }

  /* -- Body / shell -- */
  body {
    background: var(--sand);
    padding: 28px 32px;
    min-height: 100dvh;
    box-sizing: border-box;
  }

  .app {
    max-width: 1200px;
    margin: 0 auto;
    min-height: unset;
    box-shadow: 0 8px 40px rgba(61,43,31,0.12);
    border-radius: var(--radius-xl);
    /* No overflow:hidden/clip here — both create a BFC that breaks position:sticky.
       clip-path clips visually to the rounded rect without affecting sticky layout. */
    clip-path: inset(0 round var(--radius-xl));
  }

  /* -- Header: slightly taller logo -- */
  .logo-icon { width: 40px; height: 40px; font-size: 20px; }
  .logo-text  { font-size: 20px; }

  /* -- Stepper: more breathing room -- */
  .stepper { padding: 18px 32px; gap: 8px; }
  .step-label { font-size: 14px; }
  .step-connector { width: 48px; }

  /* -- Screens: wider padding by default -- */
  .screen { padding: 28px 32px; }

  /* ── Screen 2 (Edit) — two-column grid ───────────────────────────── */
  #screen2.active {
    display: grid;
    grid-template-columns: 300px 1fr;
    column-gap: 28px;
    align-items: start;
    padding: 28px 32px;
  }

  /* Sticky sidebar: all left-column sections travel together */
  #screen2 .edit-sidebar {
    grid-column: 1;
    position: sticky;
    top: 80px;
  }

  /* Lines column — right side */
  #screen2 .edit-lines-col {
    grid-column: 2;
    min-width: 0;
  }

  /* Info row: wrap onto two lines so nothing overflows the 300px column */
  #screen2 .info-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  #screen2 .info-type { flex: 0 0 calc(50% - 4px); min-width: 0; }
  #screen2 .info-num  { flex: 0 0 calc(50% - 4px); min-width: 0; }
  #screen2 .info-date { flex: 0 0 100%; min-width: 0; }

  /* ── Screen 3 (Export/Preview) — two-column grid ─────────────────── */
  #screen3.active {
    display: grid;
    grid-template-columns: 280px 1fr;
    column-gap: 28px;
    align-items: start;
    padding: 28px 32px;
  }

  /* Title spans both columns */
  #screen3 > .section-title { grid-column: 1 / -1; margin-bottom: 8px; }

  /* Action buttons — vertical stack in left col */
  #screen3 .export-actions {
    grid-column: 1;
    margin-bottom: 0;
    position: sticky;
    top: 80px; /* below sticky header */
  }

  /* iframe — right col, row 2 (alongside the action buttons), tall */
  #screen3 .pdf-preview-frame {
    grid-column: 2;
    grid-row: 2;
    height: calc(100dvh - 180px);
    min-height: 500px;
  }

  /* -- Bottom bar -- */
  /* On desktop the bottom-bar is not sticky — it's part of the normal flow.
     We override the sticky behaviour and give it more generous horizontal padding. */
  .bottom-bar {
    padding: 16px 32px calc(16px + var(--safe-bottom, 0px));
    gap: 12px;
  }

  /* Buttons inside the bottom bar: limit width so they don't stretch absurdly */
  .bottom-bar .btn,
  .bottom-bar .btn-save-draft {
    flex: 0 1 auto;
    min-width: 140px;
  }

  /* The primary "Suivant" button still grows to fill remaining space */
  .bottom-bar #btnNext { flex: 1; max-width: 360px; }


  /* -- Quick categories: 4 columns on desktop -- */
  .category-chips { grid-template-columns: repeat(4, 1fr); }

  /* -- Method cards: 3 stay on same row (already 3-col at 481px+) -- */

  /* -- Line item cards: wider → show fields in 2 columns -- */
  .line-item .field-row { gap: 16px; }

  /* -- Misc spacing bumps -- */
  .section-title { font-size: 19px; }
  .edit-section { margin-bottom: 28px; }
  .card { padding: 24px; }
}

/* ═══════════════════════════════════════════
   HISTORY PANEL
   ═══════════════════════════════════════════ */
/* ═══════════════════════════════════════════
   GESTION (client management panel)
   ═══════════════════════════════════════════ */
.mgmt-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 200;
  flex-direction: column;
}
.mgmt-overlay.visible { display: flex; }

.mgmt-panel {
  background: var(--sand);
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.18s ease;
  overflow: hidden;
}

/* ── Panel header ── */
.mgmt-header {
  background: var(--earth);
  padding: calc(var(--safe-top) + 14px) 20px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.mgmt-back-btn {
  height: 32px;
  padding: 0 10px;
  border: none; background: rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  color: var(--gold);
  display: flex; align-items: center; gap: 4px;
  cursor: pointer; flex-shrink: 0;
  font-size: 13px; font-weight: 600; font-family: var(--font-body);
  transition: var(--transition);
}
.mgmt-title {
  flex: 1;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}
.mgmt-close-btn {
  width: 32px; height: 32px;
  border: none; background: transparent;
  color: rgba(212,168,71,0.7);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border-radius: var(--radius-sm);
  transition: var(--transition); flex-shrink: 0;
}
.mgmt-close-btn:hover { color: var(--gold); background: rgba(255,255,255,0.1); }
.mgmt-back-btn:hover { background: rgba(255,255,255,0.2); }
.mgmt-header-title {
  flex: 1;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mgmt-header-close {
  width: 32px; height: 32px;
  border: none; background: transparent;
  color: rgba(212,168,71,0.7);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border-radius: var(--radius-sm);
  transition: var(--transition); flex-shrink: 0;
}
.mgmt-header-close:hover { color: var(--gold); background: rgba(255,255,255,0.1); }

/* ── Search bar ── */
.mgmt-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 16px 0;
  padding: 9px 12px;
  background: var(--white);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--sand-dark);
  flex-shrink: 0;
}
.mgmt-search svg { color: var(--gray-400); flex-shrink: 0; }
.mgmt-search input {
  border: none; background: transparent;
  font-family: var(--font-body); font-size: 14px;
  color: var(--earth); width: 100%; outline: none;
}
.mgmt-search input::placeholder { color: var(--gray-400); }

/* ── Stats bar ── */
.mgmt-stats {
  display: flex;
  gap: 0;
  margin: 12px 16px 0;
  background: var(--white);
  border-radius: var(--radius-md);
  border: 1px solid var(--sand-dark);
  overflow: hidden;
  flex-shrink: 0;
}
.mgmt-stat {
  flex: 1;
  padding: 10px 8px;
  text-align: center;
  border-right: 1px solid var(--sand-dark);
}
.mgmt-stat:last-child { border-right: none; }
.mgmt-stat-num, .mgmt-stat-val {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--earth);
  display: block;
}
.mgmt-stat-lbl {
  font-size: 10px;
  color: var(--gray-500);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ── Scrollable body ── */
.mgmt-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px calc(var(--safe-bottom) + 20px);
}

/* ── Section label ── */
.mgmt-section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 8px 4px 6px;
}

/* ── Client cards (level 1) ── */
.client-card {
  background: var(--white);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: var(--transition);
}
.client-card:hover {
  border-color: var(--terracotta);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.client-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.client-info { flex: 1; min-width: 0; }
.client-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--earth);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.client-meta {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 2px;
}
.client-badges { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.client-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.client-badge.draft    { background: #fef3c7; color: #92400e; }
.client-badge.final    { background: #d1fae5; color: #065f46; }
.client-badge.facture  { background: #ede9fe; color: #4c1d95; }
.client-chevron { color: var(--gray-300); flex-shrink: 0; }

/* ── Document rows (level 2) ── */
.doc-row {
  background: var(--white);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-lg);
  padding: 13px 14px;
  margin-bottom: 8px;
  transition: var(--transition);
}
.doc-row:hover { border-color: var(--sand-dark); box-shadow: var(--shadow-sm); }
.doc-row-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.doc-num {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--earth);
}
.doc-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.doc-badge.draft               { background: #fef3c7; color: #92400e; }
.doc-badge.final,
.doc-badge.finalized           { background: #d1fae5; color: #065f46; }
.doc-badge.facture             { background: #ede9fe; color: #4c1d95; }
.doc-date {
  margin-left: auto;
  font-size: 11px;
  color: var(--gray-400);
  white-space: nowrap;
}
.doc-objet {
  font-size: 13px;
  color: var(--gray-600);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-amount {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--terracotta);
}
.doc-lieu {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--gray-500);
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-lieu svg { flex-shrink: 0; }
.doc-actions {
  display: flex;
  gap: 6px;
}
.doc-action-btn {
  flex: 1;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--sand-dark);
  background: var(--sand);
  font-size: 12px;
  font-weight: 600;
  color: var(--earth);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  transition: var(--transition);
}
.doc-action-btn:hover { background: var(--sand-dark); }
.doc-action-btn.primary { background: var(--terracotta); color: #fff; border-color: var(--terracotta); }
.doc-action-btn.primary:hover { background: var(--terracotta-dark); }
.doc-action-btn.danger { color: var(--danger); border-color: #fca5a5; }
.doc-action-btn.danger:hover { background: var(--danger-light); }

/* ── Loading / empty states ── */
.mgmt-loading, .mgmt-empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray-400);
  font-size: 14px;
}
.mgmt-loading svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── New devis button in client detail ── */
.new-devis-btn {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-lg);
  border: 2px dashed var(--sand-dark);
  background: transparent;
  color: var(--terracotta);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: var(--transition);
  margin-bottom: 8px;
}
.new-devis-btn:hover { border-color: var(--terracotta); background: rgba(196,98,45,0.04); }
/* ── Global stats row ── */
.mgmt-global-stats {
  font-size: 12px;
  color: var(--gray-400);
  padding: 4px 4px 10px;
  display: flex; gap: 6px; align-items: center;
}
/* ── Client last date ── */
.client-last {
  margin-left: 6px;
  font-size: 11px;
  color: var(--gray-400);
}

/* ── Status pills ── */
.doc-badge.status-draft     { background: #fef3c7; color: #92400e; }
.doc-badge.status-sent      { background: #dbeafe; color: #1e40af; }
.doc-badge.status-accepted  { background: #d1fae5; color: #065f46; }
.doc-badge.status-refused   { background: #fee2e2; color: #991b1b; }
.doc-badge.status-invoiced  { background: #ede9fe; color: #4c1d95; }
.doc-badge.status-paid      { background: #dcfce7; color: #14532d; }

/* ── Status select ── */
.status-select {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 6px;
  border-radius: 10px;
  border: 1px solid var(--sand-dark);
  background: var(--sand);
  color: var(--earth);
  cursor: pointer;
  outline: none;
  transition: var(--transition);
  max-width: 120px;
}
.status-select:hover  { border-color: var(--terracotta); }
.status-select:focus  { border-color: var(--terracotta); box-shadow: 0 0 0 2px rgba(196,98,45,0.15); }
.status-select.s-draft     { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.status-select.s-sent      { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.status-select.s-accepted  { background: #d1fae5; color: #065f46; border-color: #6ee7b7; }
.status-select.s-refused   { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.status-select.s-invoiced  { background: #ede9fe; color: #4c1d95; border-color: #c4b5fd; }
.status-select.s-paid      { background: #dcfce7; color: #14532d; border-color: #86efac; }

/* ── Client profile form ── */
.profile-banner {
  background: linear-gradient(135deg, var(--terracotta) 0%, #a0522d 100%);
  border-radius: var(--radius-lg);
  padding: 18px 16px 14px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.profile-banner-avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 20px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.profile-banner-info { flex: 1; min-width: 0; }
.profile-banner-name {
  font-size: 16px; font-weight: 700; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profile-banner-sub {
  font-size: 12px; color: rgba(255,255,255,0.75); margin-top: 3px;
}
.profile-edit-btn {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
  font-family: var(--font-body);
}
.profile-edit-btn:hover { background: rgba(255,255,255,0.35); }

/* ── Profile form fields ── */
.profile-form {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--white);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.profile-form-title {
  font-size: 12px; font-weight: 700;
  color: var(--gray-400); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 2px;
}
.profile-field-row {
  display: flex; flex-direction: column; gap: 3px;
}
.profile-field-label {
  font-size: 11px; font-weight: 600; color: var(--gray-500);
}
.profile-field-input {
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px; color: var(--earth);
  font-family: var(--font-body);
  background: var(--sand);
  outline: none; transition: var(--transition);
  width: 100%; box-sizing: border-box;
}
.profile-field-input:focus {
  border-color: var(--terracotta);
  background: var(--white);
  box-shadow: 0 0 0 2px rgba(196,98,45,0.12);
}
.profile-field-input.textarea { resize: vertical; min-height: 60px; }
.profile-form-actions {
  display: flex; gap: 8px; margin-top: 4px;
}
.profile-save-btn {
  flex: 1;
  padding: 10px;
  background: var(--terracotta); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 700;
  font-family: var(--font-body);
  cursor: pointer; transition: var(--transition);
}
.profile-save-btn:hover { background: var(--terracotta-dark); }
.profile-cancel-btn {
  padding: 10px 16px;
  background: var(--sand); color: var(--earth);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer; transition: var(--transition);
}
.profile-cancel-btn:hover { background: var(--sand-dark); }

/* ── Profile chips (contact info) ── */
.profile-chips {
  display: flex; flex-wrap: wrap; gap: 7px;
  margin-bottom: 12px;
}
.profile-chips-empty {
  font-size: 12px; color: var(--gray-400); font-style: italic;
  padding: 4px 0;
}
.profile-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--white); border: 1px solid var(--sand-dark);
  border-radius: 20px; padding: 5px 11px;
  font-size: 12px; color: var(--earth);
  text-decoration: none; transition: var(--transition);
}
a.profile-chip:hover { border-color: var(--terracotta); color: var(--terracotta); }
.profile-notes {
  font-size: 12px; color: var(--gray-500);
  background: #fffbf0; border: 1px solid #f0e0a0;
  border-radius: var(--radius-sm); padding: 8px 12px;
  margin-bottom: 12px; white-space: pre-wrap;
}
/* ── Profile KPIs ── */
.profile-kpis {
  display: grid; grid-template-columns: repeat(3,1fr); gap: 8px;
  margin-bottom: 12px;
}
.profile-kpi {
  background: var(--white); border: 1px solid var(--sand-dark);
  border-radius: var(--radius-md); padding: 10px 12px; text-align: center;
}
.profile-kpi.green { border-color: #bbf7d0; background: #f0fdf4; }
.profile-kpi.blue  { border-color: #bfdbfe; background: #eff6ff; }
.profile-kpi-val { font-size: 15px; font-weight: 700; color: var(--earth); }
.profile-kpi.green .profile-kpi-val { color: #15803d; font-size: 13px; }
.profile-kpi.blue  .profile-kpi-val { color: #1d4ed8; }
.profile-kpi-lbl { font-size: 10px; color: var(--gray-400); margin-top: 2px; }
/* ── Profile action buttons ── */
.profile-action-btn {
  width: 100%; padding: 11px 14px; margin-bottom: 8px;
  border-radius: var(--radius-sm); border: 1px solid var(--sand-dark);
  background: var(--white); color: var(--earth);
  font-size: 13px; font-weight: 600; font-family: var(--font-body);
  cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; gap: 8px;
}
.profile-action-btn:hover { background: var(--sand); }
.profile-action-btn.primary {
  background: var(--terracotta); color: #fff; border-color: var(--terracotta);
  margin-bottom: 8px;
}
.profile-action-btn.primary:hover { background: var(--terracotta-dark); }
/* ── Profile info (legacy, kept for compat) ── */
.profile-info-card { display: none; }
.profile-info-row, .profile-info-lbl, .profile-info-val {}

/* ── Merge button / dialog ── */
.merge-btn {
  width: 100%;
  padding: 9px;
  border-radius: var(--radius-sm);
  border: 1px dashed #fca5a5;
  background: transparent;
  color: var(--danger);
  font-size: 12px; font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer; transition: var(--transition);
  margin-top: 6px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.merge-btn:hover { background: var(--danger-light); }
.delete-client-btn {
  width: 100%;
  padding: 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #fff;
  font-size: 12px; font-weight: 700;
  font-family: var(--font-body);
  cursor: pointer; transition: var(--transition);
  margin-top: 8px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.delete-client-btn:hover { background: #b91c1c; }

/* ── Merge dialog (overlay) ── */
.merge-dialog-overlay {
  position: fixed; inset: 0; z-index: 310;
  background: rgba(0,0,0,0.55);
  display: none; align-items: center; justify-content: center;
  padding: 24px;
}
.merge-dialog-overlay.visible { display: flex; }
.merge-dialog {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: 20px;
  width: 100%; max-width: 360px;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.22s ease-out;
}
.merge-dialog-title {
  font-size: 15px; font-weight: 700; color: var(--earth);
  margin-bottom: 6px;
}
.merge-dialog-desc {
  font-size: 13px; color: var(--gray-500); margin-bottom: 14px;
}
.merge-dialog select {
  width: 100%; padding: 9px 10px;
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-sm);
  font-size: 13px; color: var(--earth);
  font-family: var(--font-body);
  background: var(--sand); outline: none;
  margin-bottom: 14px;
}
.merge-dialog-actions { display: flex; gap: 8px; }
.merge-confirm-btn {
  flex: 1; padding: 10px;
  background: var(--danger); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 700;
  font-family: var(--font-body); cursor: pointer;
  transition: var(--transition);
}
.merge-confirm-btn:hover { background: #dc2626; }
.merge-cancel-btn {
  padding: 10px 16px;
  background: var(--sand); color: var(--earth);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  font-family: var(--font-body); cursor: pointer;
  transition: var(--transition);
}
.merge-cancel-btn:hover { background: var(--sand-dark); }

/* ── Facture dialog (overlay) — reuses .merge-dialog* layout, own fields/colors ── */
.facture-dialog-label {
  display: block;
  font-size: 12px; font-weight: 600; color: var(--gray-500);
  margin-bottom: 5px;
}
.merge-dialog input[type="text"] {
  width: 100%; padding: 9px 10px;
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-sm);
  font-size: 13px; color: var(--earth);
  font-family: var(--font-body);
  background: var(--sand); outline: none;
  box-sizing: border-box;
  margin-bottom: 14px;
}
.merge-dialog input[type="text"]:focus,
.merge-dialog select:focus { border-color: var(--terracotta); }
.facture-confirm-btn {
  flex: 1; padding: 10px;
  background: var(--terracotta); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 700;
  font-family: var(--font-body); cursor: pointer;
  transition: var(--transition);
}
.facture-confirm-btn:hover { background: var(--terracotta-dark); }

/* ── Document type badge ── */
.doc-type-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}
.doc-type-badge.devis   { background: #e0f2fe; color: #0369a1; }
.doc-type-badge.facture { background: #ede9fe; color: #4c1d95; }
.doc-type-badge.recu    { background: #fce7f3; color: #831843; }
.overdue-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--danger-light);
  color: var(--danger);
  flex-shrink: 0;
  white-space: nowrap;
}

/* ── Filter tabs ── */
.doc-filter-tabs {
  display: flex;
  gap: 6px;
  padding: 4px 0 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.doc-filter-tabs::-webkit-scrollbar { display: none; }
.doc-filter-tab {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--sand-dark);
  background: var(--sand);
  color: var(--gray-500);
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.doc-filter-tab:hover { border-color: var(--terracotta); color: var(--terracotta); }
.doc-filter-tab.active {
  background: var(--terracotta);
  border-color: var(--terracotta);
  color: #fff;
}

/* ── "New client" button in clients list ── */
.new-client-btn {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-lg);
  border: 2px dashed var(--sand-dark);
  background: transparent;
  color: var(--terracotta);
  font-size: 14px; font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: var(--transition);
  margin-bottom: 10px;
}
.new-client-btn:hover { border-color: var(--terracotta); background: rgba(196,98,45,0.04); }
/* ── Doc row layout ── */
.doc-row-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
/* ── Action button variants ── */
.doc-action-btn.preview { color: var(--earth); }
.doc-action-btn.preview:hover { background: var(--sand-dark); }
.doc-action-btn.load { background: var(--terracotta); color: #fff; border-color: var(--terracotta); flex: 2; }
.doc-action-btn.load:hover { background: var(--terracotta-dark); }
.doc-action-btn.clone { background: var(--sand); }
.doc-action-btn.del { color: var(--danger); border-color: #fca5a5; }
.doc-action-btn.del:hover { background: var(--danger-light); }
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--sand);
}
.history-item:last-child { border-bottom: none; }
.history-item-info {
  flex: 1;
  min-width: 0;
}
.history-item-num {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--earth);
}
.history-item-client {
  font-size: 13px;
  color: var(--gray-600);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item-date {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 2px;
}
.history-badge {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  flex-shrink: 0;
}
.history-badge.draft {
  background: #fef3c7;
  color: #92400e;
}
.history-badge.finalized {
  background: var(--success-light);
  color: var(--success);
}
.history-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.history-item-actions button {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--sand-dark);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.history-item-actions .load-btn { color: var(--terracotta); }
.history-item-actions .load-btn:hover { background: rgba(42,95,143,0.08); }
.history-item-actions .del-btn { color: var(--danger); }
.history-item-actions .del-btn:hover { background: var(--danger-light); }

/* ── Theme picker ── */
.theme-picker { margin-bottom: 20px; }
.theme-picker-label {
  font-size: 12px; font-weight: 600; color: var(--gray-600);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px;
}
.theme-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-swatch {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  cursor: pointer; transition: var(--transition);
}
.theme-swatch-dot {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid transparent;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  transition: var(--transition);
}
.theme-swatch.active .theme-swatch-dot {
  border-color: var(--terracotta);
  box-shadow: 0 0 0 2px white, 0 0 0 4px var(--terracotta);
}
.theme-swatch-name { font-size: 10px; color: var(--gray-500); font-weight: 500; }
.theme-swatch.active .theme-swatch-name { color: var(--earth); font-weight: 700; }

/* ── Convert button (devis → facture) ── */
.doc-action-btn.convert {
  color: #4c1d95; border-color: #ddd6fe;
  font-size: 11px; white-space: nowrap;
}
.doc-action-btn.convert:hover { background: #ede9fe; }

/* ── Dashboard ── */
.dash-section { margin-bottom: 18px; }
.dash-section-title {
  font-size: 11px; font-weight: 700; color: var(--gray-400);
  text-transform: uppercase; letter-spacing: 0.6px;
  padding: 0 2px 8px;
}
.dash-kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.dash-kpi {
  background: var(--white);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-lg);
  padding: 14px 14px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.dash-kpi-val {
  font-size: 20px; font-weight: 800;
  font-family: var(--font-display);
  color: var(--earth);
  line-height: 1;
}
.dash-kpi-lbl {
  font-size: 11px; color: var(--gray-400); font-weight: 600;
}
.dash-kpi.green  { border-color: #6ee7b7; }
.dash-kpi.green .dash-kpi-val { color: #065f46; }
.dash-kpi.blue   { border-color: #93c5fd; }
.dash-kpi.blue  .dash-kpi-val { color: #1e40af; }
.dash-kpi.orange { border-color: #fcd34d; }
.dash-kpi.orange .dash-kpi-val { color: #92400e; }
.dash-kpi.purple { border-color: #c4b5fd; }
.dash-kpi.purple .dash-kpi-val { color: #4c1d95; }

/* Status bar chart */
.dash-status-bar {
  display: flex; border-radius: 6px; overflow: hidden; height: 10px;
  margin-bottom: 8px;
}
.dash-status-seg { height: 100%; transition: width 0.4s ease; }
.dash-status-seg.s-draft    { background: #fcd34d; }
.dash-status-seg.s-sent     { background: #93c5fd; }
.dash-status-seg.s-accepted { background: #6ee7b7; }
.dash-status-seg.s-refused  { background: #fca5a5; }
.dash-status-seg.s-invoiced { background: #c4b5fd; }
.dash-status-seg.s-paid     { background: #86efac; }
.dash-status-legend {
  display: flex; flex-wrap: wrap; gap: 6px 10px;
}
.dash-legend-item {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--gray-500);
}
.dash-legend-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}

/* Top clients list */
.dash-client-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--sand);
}
.dash-client-row:last-child { border-bottom: none; }
.dash-client-avatar-sm {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 12px; font-weight: 700;
  color: #fff; flex-shrink: 0;
}
.dash-client-name { flex: 1; font-size: 13px; font-weight: 600; color: var(--earth); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-client-amount { font-size: 13px; font-weight: 700; color: var(--earth); font-family: var(--font-mono); white-space: nowrap; }
.dash-client-count { font-size: 11px; color: var(--gray-400); white-space: nowrap; }

/* Recent docs list */
.dash-recent-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--sand);
  cursor: pointer;
}
.dash-recent-row:last-child { border-bottom: none; }
.dash-recent-row:hover .dash-recent-num { color: var(--terracotta); }
.dash-recent-num { font-family: var(--font-mono); font-size: 12px; font-weight: 600; color: var(--earth); min-width: 90px; flex-shrink: 0; }
.dash-recent-client { flex: 1; font-size: 12px; color: var(--gray-500); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-recent-date { font-size: 11px; color: var(--gray-400); white-space: nowrap; }

/* Dashboard button in header */
.mgmt-dash-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius-sm);
  color: #fff; cursor: pointer;
  padding: 5px 10px; font-size: 12px; font-weight: 600;
  font-family: var(--font-body);
  transition: var(--transition);
  display: flex; align-items: center; gap: 5px;
}
.mgmt-dash-btn:hover { background: rgba(255,255,255,0.3); }

/* ── Preview modal ── */
.preview-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.preview-modal-overlay.visible { opacity: 1; pointer-events: auto; }
/* previewModalOverlay peut s'ouvrir PAR-DESSUS chatOverlay (_chatViewPdf) —
   les deux partagent .preview-modal-overlay/z-index:1200, donc à égalité
   c'est l'ordre dans le DOM qui décide, et chatOverlay (déclaré après)
   gagnait toujours : l'aperçu PDF était généré mais totalement invisible,
   caché derrière le chat. */
#previewModalOverlay.visible { z-index: 1300; }
.preview-modal {
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: min(96vw, 860px);
  height: min(90vh, 960px);
  display: flex; flex-direction: column;
  overflow: hidden;
  transform: translateY(12px);
  transition: transform 0.2s;
}
.preview-modal-overlay.visible .preview-modal { transform: translateY(0); }
.preview-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--sand-dark);
  flex-shrink: 0;
}
.preview-modal-title {
  font-family: var(--font-display);
  font-size: 15px; font-weight: 700;
  color: var(--earth);
}
.preview-modal-close {
  width: 32px; height: 32px;
  border: none; background: var(--sand);
  border-radius: var(--radius-sm);
  color: var(--gray-500);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: var(--transition);
}
.preview-modal-close:hover { background: var(--sand-dark); color: var(--earth); }
.preview-dl-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 12px; height: 32px;
  background: var(--terracotta); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 700; font-family: var(--font-body);
  cursor: pointer; transition: var(--transition);
}
.preview-dl-btn:hover { background: var(--terracotta-dark); }
.preview-dl-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.preview-modal-body { flex: 1; position: relative; overflow: hidden; }
.preview-modal-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-400); font-size: 14px;
}
.preview-modal-frame {
  width: 100%; height: 100%;
  border: none;
}

/* ── Catalogue de prestations ── */
.catalogue-modal-body { overflow-y: auto; padding: 14px 16px; }
.catalogue-search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.catalogue-search-row input {
  flex: 1; padding: 9px 12px; border: 1.5px solid var(--sand-dark);
  border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 13px;
  background: var(--white); color: var(--earth);
}
.catalogue-add-btn {
  flex-shrink: 0; border: none; background: var(--terracotta); color: #fff;
  font-size: 12px; font-weight: 700; padding: 0 14px; border-radius: var(--radius-sm);
  cursor: pointer;
}
.catalogue-add-btn:hover { background: var(--terracotta-light); }
.catalogue-item-form {
  background: var(--sand); border-radius: var(--radius-md);
  padding: 12px; margin-bottom: 12px;
}
.catalogue-group-header {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--gray-500);
  padding: 10px 0 6px; border-bottom: 1px solid var(--sand-dark); margin-bottom: 6px;
}
.catalogue-item-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; background: var(--white);
  border: 1px solid var(--sand-dark); border-radius: var(--radius-sm);
  margin-bottom: 6px;
}
.catalogue-item-info { flex: 1; min-width: 0; }
.catalogue-item-desc { font-size: 13px; font-weight: 600; color: var(--earth); }
.catalogue-item-meta { font-size: 11px; color: var(--gray-500); margin-top: 1px; }
.catalogue-item-actions { display: flex; gap: 4px; flex-shrink: 0; }
.catalogue-icon-btn {
  width: 30px; height: 30px; border: 1px solid var(--sand-dark); background: var(--white);
  border-radius: var(--radius-sm); color: var(--gray-500); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: var(--transition);
}
.catalogue-icon-btn:hover { border-color: var(--terracotta); color: var(--terracotta); }
.catalogue-icon-btn.insert { background: var(--terracotta); border-color: var(--terracotta); color: #fff; font-size: 11px; font-weight: 700; width: auto; padding: 0 12px; }
.catalogue-icon-btn.insert:hover { background: var(--terracotta-light); }
.catalogue-icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.btn-save-draft {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--gold);
  background: rgba(212,168,71,0.1);
  color: var(--gold-light);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-save-draft:hover { background: rgba(212,168,71,0.2); }

.btn-finalize {
  background: rgba(22,163,74,0.1);
  color: var(--success);
  border-color: var(--success);
}
.btn-finalize:hover { background: rgba(22,163,74,0.18); }

.history-loading {
  text-align: center;
  padding: 30px;
  color: var(--gray-400);
  font-size: 13px;
}

/* ═══════════════════════════════════════════
   HOME SCREEN (screen0)
   ═══════════════════════════════════════════ */
#screen0 { padding: 22px 20px 32px; }

.home-hero {
  padding: 0 0 16px;
  text-align: left;
}
.home-hero-title {
  font-family: var(--font-body);
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 700;
  letter-spacing: -.04em;
  color: var(--earth);
  margin-bottom: 8px;
}
.home-hero-sub {
  font-size: 13px;
  color: #607080;
  line-height: 1.6;
}

.home-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 4px 6px 4px 14px;
  background: var(--white);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-lg);
  color: var(--gray-400);
}
.home-search-row input {
  min-width: 0;
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--earth);
}
.home-search-row input::placeholder { color: #607080; font-size: 13px; }
.home-search-row:focus-within { border-color: var(--terracotta); box-shadow: 0 0 0 3px #2a5f8f18; }
.home-search-submit { width: 44px; height: 44px; border: 0; border-radius: 10px; background: var(--sand); color: var(--terracotta); font-size: 22px; cursor: pointer; flex-shrink: 0; }

.home-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  padding: 18px 0;
}
.home-kpi {
  background: var(--white);
  padding: 0 12px;
  border-right: 1px solid var(--sand-dark);
}
.home-kpi:first-child { padding-left: 0; }
.home-kpi:last-child { border: 0; padding-right: 0; }
.home-kpi-val {
  font-size: 18px;
  font-weight: 700;
  color: var(--earth);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.home-kpi-lbl {
  font-size: 11px;
  color: var(--gray-500);
  margin-top: 2px;
  font-weight: 500;
}

.home-actions {
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.home-recent {
  padding: 16px 0 0;
}
.home-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.home-section-heading .home-section-title { margin: 0; font-size: 16px; text-transform: none; letter-spacing: -.02em; color: var(--earth); }
.home-text-link { border: 0; background: none; color: var(--terracotta); font: 600 12px var(--font-body); cursor: pointer; min-height: 44px; padding: 6px 0; }
.home-manual-action, .home-resume-action { display: flex; justify-content: center; align-items: center; gap: 8px; min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--terracotta); font: 600 13px var(--font-body); cursor: pointer; }
.home-manual-action:hover, .home-resume-action:hover { background: var(--sand); }
.home-resume-action[hidden] { display: none; }
.home-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-500);
  margin-bottom: 10px;
}
.home-recent-item {
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--white);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-md);
  margin-bottom: 6px;
  cursor: pointer;
  transition: var(--transition);
}
.home-recent-item:hover { border-color: var(--terracotta); background: var(--sand); }
.home-recent-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--sand-dark);
  color: var(--gray-600);
  flex-shrink: 0;
}
.home-recent-badge.devis   { background: #dbeafe; color: #1d4ed8; }
.home-recent-badge.facture { background: #dcfce7; color: #15803d; }
.home-recent-badge.recu    { background: #fef9c3; color: #a16207; }
.home-recent-info { flex: 1; min-width: 0; }
.home-recent-client { font-size: 13px; font-weight: 600; color: var(--earth); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.home-recent-meta { font-size: 11px; color: var(--gray-500); margin-top: 1px; }
.home-recent-amount { font-size: 13px; font-weight: 700; color: var(--earth); font-family: var(--font-mono); flex-shrink: 0; }
#homeRecentList { border: 1px solid var(--sand-dark); border-radius: 14px; overflow: hidden; }
#homeRecentList .home-recent-item { border: 0; border-radius: 0; margin: 0; padding: 16px 12px; flex-wrap: wrap; }
#homeRecentList .home-recent-item + .home-recent-item { border-top: 1px solid #edf1f5; }
#homeRecentList .home-recent-info { flex-basis: 100px; }
#homeRecentList .home-recent-meta { overflow-wrap: anywhere; }
#homeRecentList .home-recent-amount { margin-left: auto; font-family: var(--font-body); }
.home-empty {
  text-align: center;
  padding: 20px;
  color: #607080;
  font-size: 13px;
  line-height: 1.8;
}

.home-relance {
  padding: 20px 0 0;
}
.relance-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--danger-light);
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  margin-bottom: 6px;
}
.relance-info { flex: 1; min-width: 0; }
.relance-client { font-size: 13px; font-weight: 600; color: var(--earth); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.relance-meta { font-size: 11px; color: var(--danger); margin-top: 1px; font-weight: 600; }
.relance-amount { font-size: 13px; font-weight: 700; color: var(--earth); font-family: var(--font-mono); flex-shrink: 0; }
.relance-btn {
  flex-shrink: 0;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.relance-btn:hover { background: #b91c1c; }

/* ═══════════════════════════════════════════
   CLIENT TABS (Documents / Dépenses)
   ═══════════════════════════════════════════ */
.client-section-tabs {
  display: flex;
  gap: 0;
  margin: 10px 0 0;
  border-bottom: 2px solid var(--sand-dark);
}
.client-section-tab {
  flex: 1;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  color: var(--gray-500);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.client-section-tab.active { color: var(--terracotta); border-bottom-color: var(--terracotta); }
.client-section-tab:hover:not(.active) { color: var(--earth); background: var(--sand); }
.client-tab-badge {
  font-size: 10px; font-weight: 700;
  background: var(--sand-dark); color: var(--gray-600);
  padding: 1px 5px; border-radius: 10px;
}
.client-section-tab.active .client-tab-badge { background: var(--terracotta); color: var(--white); }

/* ═══════════════════════════════════════════
   EXPENSE ITEMS
   ═══════════════════════════════════════════ */
.expense-list { padding: 8px 0 0; }
.expense-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--white);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-md);
  margin-bottom: 6px;
  position: relative;
}
.expense-type-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
  background: var(--sand);
}
.expense-info { flex: 1; min-width: 0; }
.expense-fournisseur { font-size: 13px; font-weight: 600; color: var(--earth); }
.expense-desc { font-size: 11px; color: var(--gray-500); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-meta { font-size: 11px; color: var(--gray-400); margin-top: 2px; }
.expense-amounts { text-align: right; flex-shrink: 0; }
.expense-ttc { font-size: 13px; font-weight: 700; color: var(--earth); font-family: var(--font-mono); }
.expense-ht  { font-size: 10px; color: var(--gray-400); font-family: var(--font-mono); margin-top: 1px; }
.expense-tva-badge {
  display: inline-block; font-size: 9px; font-weight: 700;
  background: #fef9c3; color: #a16207;
  padding: 1px 5px; border-radius: 4px; margin-top: 2px;
}
.expense-photo-thumb {
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--sand-dark); background: var(--sand);
  color: var(--gray-500); display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.expense-photo-thumb:hover { background: var(--sand-dark); color: var(--terracotta); }
.expense-del-btn {
  position: absolute; top: 6px; right: 6px;
  width: 22px; height: 22px; border: none; background: none;
  color: var(--gray-400); cursor: pointer; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition); font-size: 14px; line-height: 1;
}
.expense-del-btn:hover { background: var(--danger-light); color: var(--danger); }

.expense-totals {
  display: flex; gap: 8px; margin: 10px 0 4px;
  background: var(--earth); border-radius: var(--radius-md);
  padding: 10px 14px;
}
.expense-total-item { flex: 1; text-align: center; }
.expense-total-val { font-size: 14px; font-weight: 700; color: var(--gold); font-family: var(--font-mono); }
.expense-total-lbl { font-size: 10px; color: rgba(255,255,255,0.5); margin-top: 2px; font-weight: 500; }

/* ═══════════════════════════════════════════
   EXPENSE FORM
   ═══════════════════════════════════════════ */
.expense-form {
  background: var(--white);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 10px;
}
.expense-form-title {
  font-size: 14px; font-weight: 700; color: var(--earth);
  margin-bottom: 12px; display: flex; align-items: center; gap: 6px;
}
.expense-form-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px;
}
.expense-form-row.full { grid-template-columns: 1fr; }
.expense-form-row.thirds { grid-template-columns: 1fr 1fr 1fr; }
.expense-field label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--gray-600); margin-bottom: 3px; text-transform: uppercase; letter-spacing: 0.05em;
}
.expense-field input,
.expense-field select {
  width: 100%; padding: 7px 10px; border: 1px solid var(--sand-dark);
  border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 13px;
  background: var(--white); color: var(--earth); outline: none;
  transition: var(--transition);
}
.expense-field input:focus,
.expense-field select:focus { border-color: var(--terracotta); }
.expense-form-actions { display: flex; gap: 8px; margin-top: 12px; }
.expense-form-cancel { flex: 1; padding: 9px; background: var(--sand); border: 1px solid var(--sand-dark); border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 13px; font-weight: 600; cursor: pointer; color: var(--gray-600); }
.expense-form-save   { flex: 2; padding: 9px; background: var(--terracotta); border: none; border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 13px; font-weight: 600; cursor: pointer; color: var(--white); }
.expense-form-save:hover { background: var(--terracotta-light); }

/* Photo picker inside form */
.expense-photo-picker {
  display: flex; gap: 8px; margin-bottom: 8px; align-items: center;
}
.expense-photo-btn {
  flex: 1; padding: 8px; background: var(--sand); border: 1px dashed var(--gray-300);
  border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 12px;
  font-weight: 600; cursor: pointer; color: var(--gray-600);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: var(--transition);
}
.expense-photo-btn:hover { border-color: var(--terracotta); color: var(--terracotta); }
.expense-photo-preview { width: 48px; height: 48px; object-fit: cover; border-radius: var(--radius-sm); display: none; }

/* ═══════════════════════════════════════════
   TVA DEDUCTION TABLE
   ═══════════════════════════════════════════ */
.tva-summary {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 8px; margin: 12px 0;
}
.tva-kpi {
  background: var(--white); border: 1px solid var(--sand-dark);
  border-radius: var(--radius-md); padding: 10px 12px;
}
.tva-kpi.yellow { border-left: 3px solid #eab308; }
.tva-kpi.green  { border-left: 3px solid #22c55e; }
.tva-kpi.blue   { border-left: 3px solid #3b82f6; }
.tva-kpi.red    { border-left: 3px solid var(--danger); }
.tva-kpi-val { font-size: 15px; font-weight: 700; color: var(--earth); font-family: var(--font-mono); }
.tva-kpi-lbl { font-size: 10px; color: var(--gray-500); font-weight: 600; margin-top: 2px; text-transform: uppercase; }
.tva-secondary-totals {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  font-size: 11px; color: var(--gray-500); margin: 0 0 16px;
}
.tva-secondary-totals strong { color: var(--earth); font-family: var(--font-mono); }
.tva-section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--gray-500); margin: 4px 0 8px;
}

.tva-group { margin-bottom: 14px; }
.tva-group-header {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--gray-500);
  padding: 6px 0 4px; border-bottom: 1px solid var(--sand-dark); margin-bottom: 6px;
}
.tva-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; background: var(--white);
  border: 1px solid var(--sand-dark); border-radius: var(--radius-sm);
  margin-bottom: 4px; font-size: 12px;
}
.tva-row-main { flex: 1; min-width: 0; }
.tva-row-fournisseur { font-weight: 600; color: var(--earth); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tva-row-detail { font-size: 10px; color: var(--gray-500); margin-top: 1px; }
.tva-row-amounts { text-align: right; flex-shrink: 0; }
.tva-row-ttc { font-weight: 700; font-family: var(--font-mono); color: var(--earth); }
.tva-row-tva { font-size: 10px; color: #a16207; font-family: var(--font-mono); font-weight: 600; }

.tva-filter-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.tva-filter-chip {
  padding: 4px 10px; font-size: 12px; font-weight: 600;
  background: var(--sand); border: 1px solid var(--sand-dark);
  border-radius: 20px; cursor: pointer; color: var(--gray-600);
  transition: var(--transition);
}
.tva-filter-chip.active { background: var(--terracotta); border-color: var(--terracotta); color: var(--white); }

/* ── Chantier cards ───────────────────────────────────────────────────────── */
.chantier-card {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: box-shadow var(--transition);
  border-left: 4px solid var(--terracotta);
}
.chantier-card:hover { box-shadow: var(--shadow-md); }
.chantier-card.pause  { border-left-color: var(--gray-400); }
.chantier-card.termine { border-left-color: var(--success); }
.chantier-card-header { display:flex; align-items:center; gap:10px; margin-bottom:6px; }
.chantier-card-title  { font-weight:600; font-size:14px; flex:1; color:var(--earth); }
.chantier-status-badge {
  font-size:11px; font-weight:600; padding:3px 8px; border-radius:20px; white-space:nowrap;
}
.chantier-status-badge.en_cours { background:rgba(42,95,143,.12); color:var(--terracotta); }
.chantier-status-badge.termine  { background:rgba(22,163,74,.12); color:var(--success); }
.chantier-status-badge.pause    { background:var(--gray-100); color:var(--gray-500); }
.chantier-card-meta  { font-size:12px; color:var(--gray-500); display:flex; gap:12px; flex-wrap:wrap; }
.chantier-card-client { font-weight:500; color:var(--earth-light); }

/* ── Chantier detail ──────────────────────────────────────────────────────── */
.chantier-detail-header { padding:16px 16px 12px; border-bottom:1px solid var(--sand-dark); }
.chantier-detail-title-row { display:flex; align-items:center; gap:10px; margin-bottom:8px; }
.chantier-detail-title {
  font-size:16px; font-weight:700; color:var(--earth); flex:1;
  cursor:pointer; transition:color var(--transition);
}
.chantier-detail-title:hover { color:var(--terracotta); }
.chantier-status-select {
  font-size:11px; font-weight:600; padding:4px 10px; border-radius:20px;
  border:none; cursor:pointer; appearance:none; -webkit-appearance:none;
}
.chantier-status-select.en_cours { background:rgba(42,95,143,.12); color:var(--terracotta); }
.chantier-status-select.termine  { background:rgba(22,163,74,.12); color:var(--success); }
.chantier-status-select.pause    { background:var(--gray-100); color:var(--gray-500); }
.chantier-detail-meta {
  font-size:12px; color:var(--gray-500); display:flex; gap:14px; flex-wrap:wrap;
}
.chantier-devis-ref {
  color:var(--terracotta); font-weight:500; cursor:pointer; text-decoration:underline;
}

/* ── Rentabilité ──────────────────────────────────────────────────────────── */
.chantier-rentabilite { padding: 12px 16px 0; }
.chantier-rent-pct { font-size: 11px; font-weight: 600; opacity: .75; }
.chantier-budget-gauge { margin: 4px 0 14px; }
.chantier-budget-gauge-label {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11px; color: var(--gray-500); margin-bottom: 4px;
}
.chantier-budget-gauge-label .over { color: var(--danger); font-weight: 700; }
.chantier-budget-gauge-bar {
  height: 8px; border-radius: 4px; background: var(--sand-dark); overflow: hidden;
}
.chantier-budget-gauge-fill {
  height: 100%; background: var(--success); border-radius: 4px;
  transition: width .3s ease;
}
.chantier-budget-gauge-fill.warn { background: #eab308; }
.chantier-budget-gauge-fill.over { background: var(--danger); }

/* ── Notes ────────────────────────────────────────────────────────────────── */
.chantier-section-title {
  font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.06em;
  color:var(--gray-400); padding:12px 16px 6px;
}
.note-add-area { padding:0 16px 12px; display:flex; gap:8px; }
.note-add-area textarea {
  flex:1; border:1.5px solid var(--sand-dark); border-radius:var(--radius-sm);
  padding:8px 10px; font-size:13px; font-family:var(--font-body);
  resize:none; min-height:60px; background:var(--white);
}
.note-add-area textarea:focus { outline:none; border-color:var(--terracotta); }
.note-add-btn {
  background:var(--terracotta); color:var(--white); border:none;
  border-radius:var(--radius-sm); padding:8px 14px; font-size:13px;
  font-weight:600; cursor:pointer; align-self:flex-end; white-space:nowrap;
}
.note-add-btn:hover { background:var(--terracotta-dark); }
.chantier-notes-list { padding:0 16px 16px; }
.chantier-note-item {
  background:var(--white); border-radius:var(--radius-sm); padding:10px 12px;
  margin-bottom:8px; font-size:13px; color:var(--earth);
  border-left:3px solid var(--gold); position:relative;
}
.chantier-note-meta {
  font-size:11px; color:var(--gray-400); margin-top:6px;
  display:flex; justify-content:space-between; align-items:center;
}
.note-delete-btn {
  background:none; border:none; color:var(--gray-400); cursor:pointer;
  font-size:16px; line-height:1; padding:0 2px;
}
.note-delete-btn:hover { color:var(--danger); }

/* ── Photos chantier (avant/après) ── */
.chantier-photos-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 0 16px 16px;
}
.chantier-photo-item {
  position: relative;
  background: var(--white);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.chantier-photo-item img {
  display: block;
  width: 100%;
  height: 120px;
  object-fit: cover;
  cursor: pointer;
}
.chantier-photo-caption {
  font-size: 11px;
  color: var(--gray-600);
  padding: 5px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chantier-photo-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chantier-photo-del:hover { background: var(--danger); }

/* ── Client totals row ─────────────────────────────────────────────────────── */
.client-totals-row {
  display: flex; gap: 20px; flex-wrap: wrap;
  padding: 8px 16px 12px; font-size: 13px; color: var(--gray-500);
  border-bottom: 1px solid var(--sand-dark);
}
.client-totals-row strong { color: var(--earth); }

/* ── TVA filter bar ────────────────────────────────────────────────────────── */
.tva-filter-bar {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--sand-dark);
  background: var(--white);
}
.tva-filter-group { display: flex; flex-direction: column; gap: 4px; }
.tva-filter-group label { font-size: 11px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .05em; }
.tva-filter-group input, .tva-filter-group select {
  border: 1.5px solid var(--sand-dark); border-radius: var(--radius-sm);
  padding: 6px 8px; font-size: 13px; background: var(--white); min-width: 110px;
}

/* ── Avance form ───────────────────────────────────────────────────────────── */
.avance-form {
  background: var(--white); border-radius: var(--radius-md);
  border: 1.5px solid rgba(212,168,71,.35);
  padding: 16px; margin: 12px 16px;
}
.avance-form-title {
  font-size: 13px; font-weight: 700; color: var(--gold);
  display: flex; align-items: center; gap: 6px; margin-bottom: 12px;
}

/* ── Paiements partiels (échéancier) ── */
.payments-panel {
  background: var(--white);
  border: 1.5px solid var(--sand-dark);
  border-radius: var(--radius-md);
  padding: 14px;
  margin: -2px 0 8px;
}
.payments-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--earth);
  margin-bottom: 10px;
}
.payments-panel-totals { font-size: 12px; font-weight: 400; color: var(--gray-600); }
.payments-panel-totals .due { color: var(--danger); }
.payments-list { margin-bottom: 10px; }
.payment-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--sand);
  font-size: 12px;
}
.payment-row:last-child { border-bottom: none; }
.payment-date { color: var(--gray-500); font-family: var(--font-mono); flex-shrink: 0; }
.payment-mode { color: var(--gray-600); flex: 1; text-transform: capitalize; }
.payment-amount { font-family: var(--font-mono); font-weight: 700; color: var(--success); flex-shrink: 0; }
.payment-del {
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--gray-400);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.payment-del:hover { color: var(--danger); }
.payment-form-row { display: flex; gap: 6px; flex-wrap: wrap; }
.payment-form-row input,
.payment-form-row select {
  flex: 1;
  min-width: 90px;
  padding: 7px 8px;
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 12px;
  background: var(--white);
  color: var(--earth);
}
.payment-add-btn {
  flex-shrink: 0;
  border: none;
  background: var(--terracotta);
  color: var(--white);
  font-size: 12px;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.payment-add-btn:hover { background: var(--terracotta-light); }

/* Primary navigation stays outside management content; one page scroll only. */
.primary-nav { display: grid; grid-template-columns: repeat(4, 1fr); padding: 8px 24px; background: #fff; border-bottom: 1px solid var(--sand-dark); gap: 8px; }
.primary-nav[hidden], .mgmt-search[hidden] { display: none; }
.primary-nav button { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: #607080; font: 600 13px var(--font-body); cursor: pointer; }
.primary-nav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.primary-nav button[aria-current="page"] { color: var(--terracotta-dark); background: #eaf1f7; }
.primary-nav button:hover { background: var(--sand); }
.app button:focus-visible, .app summary:focus-visible { outline: 3px solid var(--terracotta-light); outline-offset: 2px; }
.management-open > .content, .management-open > #stepperNav, .management-open > #bottomBar { display: none !important; }
.management-open .mgmt-overlay { position: relative; inset: auto; flex: 1; z-index: auto; }
.management-open .mgmt-panel { overflow: visible; background: #fff; }
.management-open .mgmt-body { overflow: visible; }
.mgmt-header { background: #fff; padding: 24px 20px 12px; gap: 8px; }
.mgmt-title { font: 700 22px var(--font-body); letter-spacing: -.03em; color: var(--earth); }
.mgmt-back-btn, .mgmt-close-btn { color: var(--terracotta); background: var(--sand); min-width: 44px; height: 44px; }
.mgmt-back-btn:hover, .mgmt-close-btn:hover { color: var(--terracotta-dark); background: #eaf1f7; }
.mgmt-tools { position: relative; }
.mgmt-tools summary { display: flex; align-items: center; gap: 8px; padding: 0 12px; min-height: 44px; border: 1px solid var(--sand-dark); border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer; list-style: none; }
.mgmt-tools summary::-webkit-details-marker { display: none; }
.mgmt-tools-menu { position: absolute; top: calc(100% + 8px); right: 0; width: 190px; padding: 6px; border: 1px solid var(--sand-dark); border-radius: 12px; background: #fff; box-shadow: var(--shadow-lg); z-index: 210; }
.mgmt-tools-menu .mgmt-dash-btn { display: flex; width: 100%; min-height: 44px; margin: 0; background: transparent !important; color: var(--earth) !important; padding: 10px; border-radius: 8px; }
.mgmt-tools-menu .mgmt-dash-btn:hover { background: var(--sand) !important; }
@media (min-width: 768px) {
  .primary-nav { position: sticky; top: calc(66px + var(--safe-top)); z-index: 90; }
  #screen0 { max-width: 920px; width: 100%; margin: 0 auto; padding: 36px 32px 40px; }
  .home-hero { padding-bottom: 24px; }
  .home-kpis { padding: 24px 0; }
  .home-kpi { padding-left: 24px; }
  .home-kpi-val { font-size: 22px; }
  .home-kpi-lbl { font-size: 12px; }
  .home-manual-action { align-self: center; padding: 0 20px; }
  .mgmt-panel { padding: 0 12px 24px; }
}
@media (max-width: 767px) {
  .app:has(.primary-nav:not([hidden])) { padding-bottom: calc(78px + var(--safe-bottom)); }
  .primary-nav { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px; z-index: 220; padding: 8px 8px calc(8px + var(--safe-bottom)); border-top: 1px solid var(--sand-dark); border-bottom: 0; gap: 4px; box-shadow: 0 -4px 20px #1a233208; }
  .primary-nav button { flex-direction: column; gap: 4px; min-height: 50px; font-size: 11px; }
  .app-header { padding-left: 20px; padding-right: 20px; }
  .mgmt-header { flex-wrap: wrap; }
  .mgmt-title { min-width: 90px; }
  .mgmt-back-btn { font-size: 12px; padding: 0 6px; }
  .relance-item { flex-wrap: wrap; }
  .relance-amount { font-size: 12px; }
}
/* ═══ Assistant conversationnel (chat, #agent roadmap) ═══ */
.quote-assistant-entry {
  display: flex; align-items: center; gap: 16px; width: 100%; padding: 22px;
  border: 1px solid #cddbe6; border-radius: 18px; background: #f3f7fa;
  color: var(--earth); text-align: left; font-family: var(--font-body); cursor: pointer;
  transition: background .2s, border-color .2s;
}
.quote-assistant-entry:hover { background: #eaf2f7; border-color: var(--terracotta); }
.quote-assistant-icon { display: grid; place-items: center; flex-shrink: 0; width: 44px; height: 44px; border-radius: 14px; background: var(--earth); color: var(--gold); font-size: 26px; }
.quote-assistant-entry strong { display: block; font-size: 17px; line-height: 1.4; margin: 5px 0; }
.quote-assistant-entry > span:nth-child(2) > span:last-child { color: #526576; font-size: 13px; line-height: 1.5; }
.quote-assistant-eyebrow { color: var(--terracotta); font-size: 10px; font-weight: 700; letter-spacing: .12em; }
.quote-assistant-arrow { margin-left: auto; color: var(--terracotta); font-size: 24px; }
.chat-modal { width: min(96vw, 1100px); max-width: 1100px; height: min(90dvh, 860px); }
#chatOverlay { z-index: 1190; visibility: hidden; }
#chatOverlay.visible { visibility: visible; }
body:has(#chatOverlay.visible) { overflow: hidden; }
.chat-header { padding: 18px 24px; background: #fff; }
.chat-heading { display: flex; align-items: center; gap: 12px; }
.chat-heading .preview-modal-title { font-family: var(--font-body); font-size: 17px; }
.chat-heading p { margin-top: 3px; font-size: 12px; color: #607080; }
.chat-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 340px; flex: 1; min-height: 0; }
.chat-conversation { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #fff; }
.chat-messages {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 28px; display: flex; flex-direction: column; gap: 20px;
}
.chat-msg { display: flex; flex-direction: column; flex-shrink: 0; }
.chat-msg-user { align-items: flex-end; }
.chat-msg-assistant { align-items: flex-start; }
.chat-bubble {
  max-width: 92%;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  font-size: 13.5px; line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.chat-msg-user .chat-bubble { background: var(--terracotta); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg-assistant .chat-bubble { background: #f4f7f9; color: var(--earth); border: 1px solid #e4ebf0; border-bottom-left-radius: 4px; white-space: normal; width: 100%; }
.chat-msg-error .chat-bubble { background: rgba(220,38,38,0.1); color: var(--danger); }
.chat-bubble-photo { max-width: 160px; border-radius: var(--radius-md); display: block; margin-bottom: 6px; }
.chat-quote-reply { width: min(100%, 410px); }
.chat-quote-reply > p { font-size: 14px; line-height: 1.6; margin-bottom: 10px; }
.chat-quote-link { display: grid; grid-template-columns: minmax(0, 1fr) auto; width: 100%; gap: 6px 12px; padding: 16px; text-align: left; background: white; border: 1px solid #dce5ec; border-radius: 12px; font-family: var(--font-body); color: var(--earth); cursor: pointer; }
.chat-quote-link:hover { border-color: var(--terracotta); background: #f9fbfd; }
.chat-quote-link-title { grid-column: 1; font-size: 14px; font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.chat-quote-link-meta { grid-column: 1; font-size: 11px; color: #607080; }
.chat-quote-link strong { grid-column: 1; font-size: 15px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.chat-quote-link small { font-size: 11px; font-weight: 400; color: #607080; }
.chat-quote-link-arrow { grid-column: 2; grid-row: 1 / 4; align-self: center; color: var(--terracotta); font-size: 20px; }
.chat-quote-version { display: none; }
.chat-quote-previous > p,
.chat-quote-previous .chat-quote-link > :not(.chat-quote-version) { display: none; }
.chat-quote-previous .chat-quote-link { display: block; width: auto; padding: 10px 0; min-height: 44px; background: transparent; border: 0; color: #526576; }
.chat-quote-previous .chat-quote-version { display: inline; font-size: 12px; text-decoration: underline; text-underline-offset: 4px; }
.chat-quote-previous .chat-quote-link:hover { color: var(--terracotta); }
/* Bouton d'aperçu en style secondaire : le CTA primaire (bleu plein) reste
   "Enregistrer le brouillon" dans le panneau — deux boutons bleus pleins se
   concurrenceraient visuellement. */
.chat-devis-view-btn {
  margin-top: 10px; width: 100%;
  background: #fff; color: var(--terracotta-dark);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius-sm); padding: 9px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; transition: var(--transition);
}
.chat-devis-view-btn:hover { background: var(--sand); border-color: var(--terracotta-light); }
.chat-welcome { margin: auto 0; padding: 8px 0; }
.chat-welcome-eyebrow { color: var(--terracotta); font-size: 10px; font-weight: 700; letter-spacing: .14em; }
.chat-welcome h2 { font: 500 clamp(26px, 3vw, 36px)/1.2 var(--font-display); letter-spacing: -.6px; margin: 12px 0 16px; }
.chat-welcome p { color: #5b6a78; font-size: 14px; line-height: 1.7; max-width: 390px; }
.chat-starters { display: grid; gap: 0; margin: 24px 0 16px; }
.chat-starters button { display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: left; min-height: 48px; padding: 12px 0; border: 0; border-bottom: 1px solid #e7ecf0; background: transparent; color: var(--terracotta); font: 13px var(--font-body); cursor: pointer; }
.chat-starters button:hover { color: var(--terracotta-dark); }
.chat-starters button > span { color: #728699; }
.chat-starters strong { font-size: 13px; }
.chat-starters small { color: #607080; font-size: 12px; }
.chat-welcome .chat-welcome-footnote { font-size: 11px; }
.chat-suggestions { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 24px; }
.chat-suggestions[hidden] { display: none; }
.chat-suggestions button { border: 1px solid #dce5ed; border-radius: 20px; padding: 8px 11px; background: white; color: var(--terracotta-dark); font: 12px var(--font-body); cursor: pointer; }
.chat-suggestions button:hover { background: var(--sand); }
.chat-quote-panel { display: flex; flex-direction: column; min-height: 0; overflow: hidden; padding: 24px; background: #f4f6f8; border-left: 1px solid #e1e7ed; }
.chat-quote-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.chat-quote-content { padding: 0 0 16px; }
.chat-quote-content h3 { font: 600 22px/1.35 var(--font-display); overflow-wrap: anywhere; }
.chat-quote-client { color: #5b6a78; font-size: 12px; line-height: 1.7; margin: 10px 0 24px; overflow-wrap: anywhere; }
.chat-quote-empty { margin-top: 36px; color: #607080; }
.chat-quote-empty > span { display: block; width: 54px; height: 66px; padding: 8px; font-size: 32px; border: 1px solid #d6dfe6; border-radius: 8px; color: #8497a7; background: white; margin-bottom: 24px; }
.chat-quote-empty h3 { font: 600 16px/1.5 var(--font-body); color: var(--earth); }
.chat-quote-empty p { margin-top: 8px; font-size: 13px; line-height: 1.7; }
.chat-quote-empty ol { padding: 24px 0 0 18px; font-size: 12px; line-height: 2.6; }
.chat-line-hint { font-size: 11px; color: #607080; margin: 24px 0 8px; }
.chat-quote-lines { list-style: none; }
.chat-quote-lines li { border-bottom: 1px solid #e7ecf0; }
.chat-line-item > summary { display: grid; grid-template-columns: minmax(0, 1fr) auto 12px; gap: 12px; align-items: center; padding: 18px 0; min-height: 56px; cursor: pointer; font-size: 13px; line-height: 1.55; list-style: none; }
.chat-line-item > summary::-webkit-details-marker { display: none; }
.chat-line-item > summary > span:first-child { overflow-wrap: anywhere; }
.chat-line-item > summary strong { font-size: 12px; font-weight: 600; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chat-line-item small { display: block; color: #607080; font-size: 10px; font-weight: 400; }
.chat-line-item .chat-line-measure { margin-top: 5px; font-size: 12px; line-height: 1.5; }
.chat-line-chevron { font-size: 16px; color: #697b8b; }
.chat-line-item[open] .chat-line-chevron { transform: rotate(180deg); }
.chat-line-expanded { padding: 0 0 12px; }
.chat-line-expanded p { color: #607080; font-size: 12px; }
.chat-line-adjust { border: 0; background: transparent; color: var(--terracotta); font: 500 12px var(--font-body); cursor: pointer; min-height: 44px; padding: 10px 0; }
.chat-line-adjust span { margin-left: 12px; }
.chat-mobile-nav { display: none; }
.chat-tax-details { margin: 8px 0 20px; }
.chat-tax-details > summary { font-size: 12px; color: #526576; cursor: pointer; padding: 12px 0; min-height: 44px; }
.chat-tax-details > summary span { float: right; }
.chat-totals { padding: 10px 0; }
.chat-totals > div { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; font-size: 12px; }
.chat-totals dd { font-variant-numeric: tabular-nums; text-align: right; }
.chat-typing { display: flex; gap: 4px; padding: 4px 0; }
.chat-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--gray-400);
  animation: chatTyping 1s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
.chat-pending { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; }
.chat-stop-btn, .chat-retry-btn { min-height: 44px; padding: 8px 0; border: 0; background: transparent; color: var(--terracotta); font: 500 13px var(--font-body); text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }
@keyframes chatTyping { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }

.chat-action-bar {
  display: flex; flex-direction: column; align-items: stretch; gap: 10px;
  padding: 20px 0 0; flex-shrink: 0;
}
.chat-action-summary { display: none; }
.chat-mobile-total { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding-bottom: 10px; }
.chat-mobile-total span { font-size: 11px; color: #607080; }
.chat-mobile-total strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.chat-tax-label { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.chat-action-bar .chat-devis-view-btn { background: white; color: var(--terracotta-dark); border: 1px solid #ccd9e3; margin: 0; padding: 11px; }
.chat-action-bar .btn { font-size: 13px; padding: 12px; white-space: normal; }
.chat-action-bar p { font-size: 10px; color: #607080; line-height: 1.6; text-align: center; }
.chat-action-bar .chat-save-error:not([hidden]) { display: block; grid-column: 1 / -1; color: var(--danger); font-size: 12px; text-align: left; }
.chat-tva-select {
  font-size: 12.5px; padding: 5px 8px;
  border: 1px solid var(--sand-dark); border-radius: var(--radius-sm);
  background: var(--white); color: var(--earth);
}

.chat-input-bar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px; margin: 4px 24px 16px; border: 1px solid #cbd8e3; border-radius: 16px;
  flex-shrink: 0;
}
.chat-input-bar:focus-within { border-color: var(--terracotta); box-shadow: 0 0 0 3px rgba(42,95,143,.08); }
.chat-composer-hint { padding: 10px 24px 16px; font-size: 10px; color: #607080; line-height: 1.5; }
.chat-photo-chip {
  position: relative; flex-shrink: 0;
}
.chat-photo-chip img { width: 40px; height: 40px; object-fit: cover; border-radius: var(--radius-sm); }
.chat-photo-chip button {
  position: absolute; top: -6px; right: -6px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--danger); color: #fff; border: none;
  font-size: 12px; line-height: 1; cursor: pointer;
}
.chat-attach-btn, .chat-send-btn {
  flex-shrink: 0; width: 38px; height: 38px;
  border: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: var(--transition);
}
.chat-attach-btn { background: var(--sand); color: var(--earth-light); }
.chat-attach-btn:hover { background: var(--sand-dark); }
.chat-send-btn { background: var(--terracotta); color: #fff; }
.chat-send-btn:hover { background: var(--terracotta-light); }
.chat-send-btn:disabled { background: var(--gray-300); cursor: not-allowed; }
#chatInput {
  flex: 1; min-width: 0; resize: none; max-height: 140px;
  border: 0; background: transparent;
  padding: 8px 2px; font-size: 14px; line-height: 1.5; font-family: var(--font-body);
  outline: none;
}
#chatInput:focus { border-color: var(--terracotta); }
.chat-modal button:disabled { opacity: .5; cursor: not-allowed; }
.chat-modal button:focus-visible, .chat-modal select:focus-visible, .chat-modal summary:focus-visible, .quote-assistant-entry:focus-visible { outline: 3px solid var(--terracotta-light); outline-offset: 3px; }
@media (max-width: 760px) {
  #chatOverlay { top: var(--chat-viewport-top, 0px); bottom: auto; height: var(--chat-viewport-height, 100dvh); }
  .chat-modal { width: 100%; height: 100%; border-radius: 0; box-shadow: none; }
  .chat-header { padding: calc(10px + var(--safe-top)) 16px 10px; }
  .chat-heading { min-width: 0; }
  .chat-heading .quote-assistant-icon, .chat-heading p { display: none; }
  .chat-heading .preview-modal-title { font-size: 15px; }
  #chatResetBtn { background: transparent; color: #697b8b; border: 0; }
  .chat-header button { min-width: 40px; min-height: 40px; }
  .chat-mobile-nav:not([hidden]) { display: block; padding: 0 20px; border-bottom: 1px solid #e7ecf0; background: white; flex-shrink: 0; }
  .chat-view-switch { display: flex; gap: 28px; }
  .chat-view-switch button { min-height: 44px; padding: 0 2px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: #697b8b; font: 500 13px var(--font-body); cursor: pointer; }
  .chat-view-switch button[aria-pressed="true"] { color: var(--earth); border-bottom-color: var(--terracotta); }
  .chat-workspace { display: flex; overflow: hidden; min-height: 0; }
  .chat-conversation { flex: 1; min-height: 0; }
  .chat-workspace[data-mobile-view="discussion"] .chat-quote-panel { display: none; }
  .chat-workspace[data-mobile-view="quote"] .chat-conversation { display: none; }
  .chat-workspace[data-mobile-view="quote"] .chat-quote-panel { display: flex; }
  .chat-messages { padding: 24px 20px; gap: 24px; background: white; }
  .chat-bubble { max-width: 90%; padding: 12px 14px; font-size: 14px; line-height: 1.6; }
  .chat-msg-user .chat-bubble { background: #eef3f7; color: var(--earth); }
  .chat-msg-assistant .chat-bubble { background: transparent; border: 0; padding: 0; }
  .chat-msg-error .chat-bubble { color: var(--danger); }
  .chat-quote-reply:not(.chat-quote-previous) .chat-quote-link { background: #f8fafc; border-color: #e3eaf0; }
  .chat-devis-view-btn { padding: 12px; min-height: 42px; }
  .chat-suggestions { display: none; }
  .chat-input-bar { margin: 8px 12px calc(12px + var(--safe-bottom)); padding: 6px; gap: 4px; border-radius: 24px; background: white; }
  #chatInput { font-size: 16px; min-height: 42px; max-height: 100px; padding: 8px 4px; }
  .chat-attach-btn, .chat-send-btn { width: 40px; height: 40px; border-radius: 50%; }
  .chat-attach-btn { background: transparent; }
  .chat-composer-hint { padding: 7px 16px calc(8px + var(--safe-bottom)); font-size: 10px; }
  .chat-quote-panel { flex: 1; min-width: 0; padding: 0 20px; border: 0; background: white; }
  .chat-quote-scroll { padding: 24px 0 12px; }
  .chat-quote-content h3 { font: 600 20px/1.4 var(--font-body); }
  .chat-quote-client { margin: 8px 0 0; font-size: 13px; }
  .chat-line-item > summary { font-size: 13px; padding: 18px 0; gap: 10px; }
  .chat-line-item > summary strong { font-size: 13px; }
  #chatActionBar { display: grid !important; grid-template-columns: auto 1fr; padding: 16px 0 calc(16px + var(--safe-bottom)); gap: 12px; border-top: 1px solid #e7ecf0; background: white; }
  #chatActionBar[style*="none"] { display: none !important; }
  .chat-mobile-total { grid-column: 1 / -1; padding: 0 0 4px; }
  .chat-mobile-total strong { font-size: 21px; }
  .chat-action-bar .chat-devis-view-btn { border: 0; background: transparent; padding: 12px 4px; font-weight: 500; }
  .chat-tax-label { font-size: 13px; }
  .chat-tva-select { min-height: 36px; min-width: 76px; }
  .chat-action-bar .btn { font-size: 13px; border-radius: 10px; min-height: 46px; }
  .chat-action-bar p, .chat-action-summary { display: none; }
  .chat-totals > div { font-size: 13px; }
  .chat-starters { margin-top: 16px; }
  .chat-welcome { margin: 0; }
  .chat-welcome h2 { font-size: 28px; }
  .quote-assistant-entry { padding: 18px 14px; gap: 12px; }
  .quote-assistant-entry strong { font-size: 15px; }
}
@media (max-width: 760px) and (max-height: 500px) {
  .chat-composer-hint { display: none; }
  .chat-mobile-nav:not([hidden]) { padding: 0 12px; }
  .chat-header { padding: 6px 12px; }
  #chatActionBar { padding-top: 8px; padding-bottom: calc(8px + var(--safe-bottom)); gap: 6px; }
}
@media (max-width: 360px) {
  #screen0 { padding-top: 18px; }
  .home-kpis { padding: 14px 0; }
  .home-recent { padding-top: 0; }
  .quote-assistant-entry { padding: 14px; }
  .quote-assistant-icon { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  #chatOverlay, .chat-modal { transition: none; }
  .chat-typing span { animation: none; opacity: .7; }
}
