:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d21;
  --muted: #6b7280;
  --primary: #1f6feb;
  --primary-hover: #1a5fd0;
  --danger: #d92d20;
  --success: #12b76a;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.hidden { display: none !important; }

.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 13px; }

/* Écran de connexion */
.screen { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}
.login-box h1 { margin: 0 0 4px; }
.login-box .muted { margin: 0 0 20px; }
.login-box input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
}

/* Barre du haut */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; }
#nav { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  background: none;
  border: none;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  color: var(--muted);
}
.nav-btn:hover { background: var(--bg); color: var(--text); }
.nav-btn.active { background: var(--primary); color: #fff; }
.topbar-actions { display: flex; gap: 8px; }

/* Contenu */
.view { padding: 24px; max-width: 1100px; margin: 0 auto; }
.view h2 { margin-top: 0; }

/* Boutons & champs */
.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-block { width: 100%; }

input[type="text"], input[type="email"], input[type="tel"], input[type="number"],
input[type="password"], input[type="date"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* Tableaux */
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: #fafbfc; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }

/* Barre de recherche */
.searchbar { display: flex; gap: 8px; margin-bottom: 16px; }
.searchbar input { flex: 1; }

/* Cartes */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

/* Grille de formulaire */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.grid .full { grid-column: 1 / -1; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1d21;
  color: #fff;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 1000;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== Extras FSD Devis ===== */
.center { text-align: center; }
.small { font-size: 12px; }
.num { text-align: right; white-space: nowrap; }
.col-actions { text-align: right; white-space: nowrap; }
.col-qte { width: 56px; }
.col-qte input { padding: 5px 6px; }
.l-desig { font-weight: 600; margin-bottom: 3px; }
.l-detail {
  width: 100%; border: 1px dashed var(--border); border-radius: 4px; padding: 4px 6px;
  font-size: 12px; color: var(--muted); background: #fafbfc; resize: vertical; min-height: 26px;
  font-family: inherit;
}
.l-detail:focus { border-color: var(--primary); background: #fff; }

/* En-tête de vue */
.view-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.view-header h2 { margin: 0; }
.header-actions { display: flex; gap: 8px; }
.btn-sm { padding: 5px 9px; font-size: 13px; }

/* Formulaires */
.form-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
#ed-pdf { background: #e8f0fe; border-color: var(--primary); color: var(--primary); font-weight: 600; }
#ed-send { background: #12b76a; border-color: #12b76a; color: #fff; font-weight: 600; }
#ed-send:hover { background: #0e9a58; }

/* Barre de filtres (suivi) */
.filter-bar { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.filter-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-tab {
  padding: 7px 14px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 20px; font-size: 13px; cursor: pointer; color: var(--muted);
  text-transform: capitalize;
}
.filter-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Badges statut */
.badge { display: inline-block; padding: 3px 9px; border-radius: 10px; font-size: 12px; font-weight: 600; text-transform: capitalize; }
.badge-secondary { background: #edeff2; color: #4b5563; }
.badge-info { background: #e0f0ff; color: #1f6feb; }
.badge-success { background: #d8f7e5; color: #12b76a; }
.badge-danger { background: #fde3e0; color: #d92d20; }

/* Dropzone import screenshot */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px;
  text-align: center; color: var(--muted); cursor: pointer; margin-bottom: 16px;
  background: var(--surface); transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: #f0f6ff; }
.dropzone p { margin: 0; }
#cat-progress { margin-bottom: 16px; }
#cat-progress pre { background: var(--bg); padding: 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; overflow-x: auto; white-space: pre-wrap; }

/* Éditeur de devis */
#devis-editor { padding: 24px; }
.editor-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.editor-header h3 { margin: 0; }
.editor-status { display: flex; align-items: center; gap: 8px; }
.editor-status select { width: auto; min-width: 110px; }
.editor-client { margin-bottom: 16px; }
.editor-toolbar { display: flex; gap: 10px; margin-bottom: 8px; }
.editor-toolbar .line-add { flex: 1; }
.editor-toolbar .line-add input { width: 100%; }
.track-results { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; margin-bottom: 12px; overflow: hidden; }
.track-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.track-item:last-child { border-bottom: none; }
.track-item:hover { background: var(--bg); }
.track-code { font-family: monospace; font-size: 12px; color: var(--muted); min-width: 60px; }
.track-desc { flex: 1; }
.track-pu { font-weight: 600; white-space: nowrap; }

.editor-lines { margin-top: 8px; }
.editor-extras {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 16px 0;
}
.editor-totals { margin: 12px 0 8px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); max-width: 320px; margin-left: auto; }
.tot-line { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; }
.tot-line.tot-grand { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; font-size: 17px; font-weight: 700; color: var(--primary); }
.editor-comment { margin-bottom: 12px; }

/* Backup (paramètres) */
.backup-actions { display: flex; gap: 10px; flex-wrap: wrap; }
