/* ============ PARenov - Design system ============ */
@font-face {
  font-family: 'Inter';
  src: url('fonts/InterVariable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('fonts/InterVariable-Italic.woff2') format('woff2');
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #6b7280;
  --faint: #9ca3af;
  --border: #e5e7eb;
  --border-2: #d1d5db;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff4ff;
  --primary-border: #bfd3f8;
  --navy: #0c1428;
  --green: #067647;
  --green-bg: #ecfdf3;
  --green-border: #abefc6;
  --red: #b42318;
  --red-bg: #fef3f2;
  --red-border: #fecdca;
  --orange: #b54708;
  --orange-bg: #fffaeb;
  --orange-border: #fedf89;
  --gray-bg: #f2f4f7;
  --gray-border: #e0e3e8;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 1px 3px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; font-feature-settings: 'cv11';
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.icn { flex-shrink: 0; vertical-align: -3px; }

/* ============ Layout ============ */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 18px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0; color: #fff;
  background: linear-gradient(135deg, #2563eb, #1e40af);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(37, 99, 235, .35);
}
.brand-name { font-size: 16.5px; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.brand-name em { font-style: normal; color: var(--primary); }
.brand-sub { font-size: 11px; color: var(--faint); font-weight: 500; letter-spacing: .02em; margin-top: 1px; }

.sidebar nav { flex: 1; padding: 6px 12px; overflow-y: auto; }
.nav-section {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  color: var(--faint); padding: 16px 12px 6px;
}
.sidebar nav a {
  color: var(--text-2); padding: 8px 12px; display: flex; align-items: center; gap: 11px;
  border-radius: 8px; font-weight: 500; font-size: 13.5px; margin-bottom: 1px;
  transition: background .12s, color .12s;
}
.sidebar nav a .icn { color: var(--faint); transition: color .12s; }
.sidebar nav a:hover { background: #f3f4f6; color: var(--text); text-decoration: none; }
.sidebar nav a:hover .icn { color: var(--text-2); }
.sidebar nav a.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.sidebar nav a.active .icn { color: var(--primary); }
.nav-badge {
  margin-left: auto; background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border);
  font-size: 11px; font-weight: 600; padding: 0 7px; border-radius: 99px; line-height: 17px;
}

.sidebar-user {
  border-top: 1px solid var(--border); padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary-soft); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
  border: 1px solid var(--primary-border);
}
.sidebar-user .who { flex: 1; min-width: 0; }
.sidebar-user .who b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .who span { font-size: 11.5px; color: var(--faint); }
.sidebar-user > a { color: var(--faint); padding: 6px; border-radius: 7px; display: flex; transition: all .12s; }
.sidebar-user > a:hover { color: var(--red); background: var(--red-bg); text-decoration: none; }

.content { flex: 1; padding: 28px clamp(24px, 3vw, 60px) 56px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; font-weight: 700; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-top: 3px; }

/* ============ Cards ============ */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 22px 24px; margin-bottom: 18px; box-shadow: var(--shadow-sm);
}
.card h2 {
  font-size: 14.5px; font-weight: 600; margin-bottom: 16px; letter-spacing: -.01em;
  display: flex; align-items: center; gap: 8px;
}
.card h2 .icn { color: var(--faint); }

/* ============ Boutons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border-2);
  background: var(--surface); color: var(--text); cursor: pointer;
  font-size: 13.5px; font-weight: 600; font-family: inherit; line-height: 1.45;
  transition: all .13s; box-shadow: var(--shadow-sm); white-space: nowrap;
}
.btn:hover { background: #f9fafb; border-color: #b8bec9; text-decoration: none; }
.btn .icn { margin: 0 -1px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(16,24,40,.1), inset 0 1px 0 rgba(255,255,255,.12); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { color: var(--red); border-color: var(--red-border); }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* Actions compactes dans les tableaux */
.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.row-actions form { display: inline-flex; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer;
  font-size: 12.5px; font-weight: 600; font-family: inherit; white-space: nowrap; transition: all .13s;
}
.icon-btn:hover { border-color: var(--border-2); color: var(--text); background: #f9fafb; text-decoration: none; }
.icon-btn-primary { color: var(--primary); border-color: var(--primary-border); }
.icon-btn-primary:hover { background: var(--primary-soft); color: var(--primary-dark); }
.icon-btn-green { color: var(--green); border-color: var(--green-border); }
.icon-btn-green:hover { background: var(--green-bg); }
.icon-btn-danger { color: var(--red); border-color: var(--red-border); }
.icon-btn-danger:hover { background: var(--red-bg); }

/* ============ Tableaux ============ */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--border); font-weight: 600;
  background: #fafbfc;
}
th:first-child { border-top-left-radius: 8px; }
th:last-child { border-top-right-radius: 8px; }
td { padding: 12px; border-bottom: 1px solid #f0f1f4; vertical-align: middle; font-size: 13.5px; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: #f9fafb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td {
  font-weight: 700; border-top: 2px solid var(--border); border-bottom: none;
  background: #fafbfc; font-size: 13px;
}
tfoot tr:hover { background: #fafbfc; }
.table-wrap { overflow-x: auto; margin: 0 -24px -6px; padding: 0 24px; }
td a strong { font-weight: 600; }

/* ============ Badges & statuts ============ */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2.5px 9px; border-radius: 99px;
  font-size: 12px; font-weight: 600; border: 1px solid transparent;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-gray { background: var(--gray-bg); color: #475467; border-color: var(--gray-border); }
.badge-blue { background: var(--primary-soft); color: var(--primary-dark); border-color: var(--primary-border); }
.badge-green { background: var(--green-bg); color: var(--green); border-color: var(--green-border); }
.badge-red { background: var(--red-bg); color: var(--red); border-color: var(--red-border); }
.badge-orange { background: var(--orange-bg); color: var(--orange); border-color: var(--orange-border); }

.statut-form { display: inline-flex; }
.statut-select {
  width: auto; padding: 3.5px 24px 3.5px 10px; border-radius: 99px; font-size: 12px; font-weight: 600;
  cursor: pointer; appearance: none; -webkit-appearance: none; font-family: inherit; line-height: 1.5;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='6'%3E%3Cpath d='M1 1l3.5 3.5L8 1' stroke='%23667085' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
.statut-select:focus { outline: 2px solid var(--primary-border); outline-offset: 1px; }
.statut-brouillon { background-color: var(--gray-bg); color: #475467; border: 1px solid var(--gray-border); }
.statut-envoye, .statut-envoyee { background-color: var(--primary-soft); color: var(--primary-dark); border: 1px solid var(--primary-border); }
.statut-accepte, .statut-payee { background-color: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.statut-refuse, .statut-retard { background-color: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }
.statut-expire { background-color: var(--orange-bg); color: var(--orange); border: 1px solid var(--orange-border); }
.statut-annulee { background-color: var(--gray-bg); color: #475467; border: 1px solid var(--gray-border); }

/* ============ Formulaires ============ */
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: #344054; }
input, select, textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border-2); border-radius: 8px;
  font-size: 13.5px; font-family: inherit; background: var(--surface); color: var(--text);
  transition: border-color .13s, box-shadow .13s; box-shadow: var(--shadow-sm);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-group { margin-bottom: 14px; min-width: 0; }
/* iOS/WebKit : les champs date ont une largeur intrinsèque qui déborde des grilles */
input[type="date"] {
  -webkit-appearance: none; appearance: none;
  display: block; min-width: 0; max-width: 100%;
  min-height: 38px; background-color: var(--surface);
}
input::-webkit-date-and-time-value { text-align: left; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
textarea { min-height: 74px; resize: vertical; }
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-count { margin-left: auto; font-size: 13px; font-variant-numeric: tabular-nums; }
.date-range { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.date-range input { width: 148px; }

/* Carte-tableau unifiée : le tableau va jusqu'aux bords de la carte */
.card-flush { padding: 0; overflow: hidden; }
.card-flush .filter-bar { padding: 14px 18px; margin-bottom: 0; border-bottom: 1px solid var(--border); }
.card-flush .table-wrap { margin: 0; padding: 0; }
.card-flush th:first-child, .card-flush td:first-child { padding-left: 20px; border-radius: 0; }
.card-flush th:last-child, .card-flush td:last-child { padding-right: 20px; border-radius: 0; }
.card-flush tbody tr:last-child td { border-bottom: 1px solid #f0f1f4; }

/* Pied de tableau : sélecteur de lignes + pagination */
.table-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 18px; background: #fafbfc; border-top: 1px solid var(--border);
}
.pp-form { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.pp-form select { width: auto; padding: 4px 26px 4px 9px; font-size: 13px; box-shadow: none; }
.pager { display: flex; align-items: center; gap: 5px; }
.pager-info { font-size: 13px; color: var(--muted); margin-right: 8px; font-variant-numeric: tabular-nums; }
.pbtn {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 28px;
  border: 1px solid var(--border-2); border-radius: 7px; background: var(--surface);
  color: var(--text-2); transition: all .13s;
}
a.pbtn:hover { background: var(--primary-soft); border-color: var(--primary-border); color: var(--primary); text-decoration: none; }
.pbtn-off { opacity: .38; }
.search-box { position: relative; }
.search-box .icn { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search-box input { padding-left: 34px; }

/* ============ Flash ============ */
.flash {
  padding: 11px 16px; border-radius: 10px; margin-bottom: 20px; font-weight: 500; font-size: 13.5px;
  display: flex; align-items: center; gap: 9px;
}
.flash-success { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.flash-error { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }

/* ============ Stats / dashboard ============ */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 20px; box-shadow: var(--shadow-sm); position: relative;
}
.stat-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-chip {
  width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
}
.stat-chip.chip-green { background: var(--green-bg); color: var(--green); }
.stat-chip.chip-blue { background: var(--primary-soft); color: var(--primary); }
.stat-chip.chip-red { background: var(--red-bg); color: var(--red); }
.stat-chip.chip-gray { background: var(--gray-bg); color: var(--text-2); }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.stat-sub .up { color: var(--green); font-weight: 600; }
.stat-sub .down { color: var(--red); font-weight: 600; }

/* Graphique en barres */
.chart { display: flex; align-items: stretch; gap: 0; height: 190px; position: relative; padding-top: 18px; }
.chart-grid { position: absolute; inset: 18px 0 22px; }
.chart-grid i { position: absolute; left: 0; right: 0; border-top: 1px dashed #e8eaef; }
.chart-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 0; position: relative; z-index: 1; }
.chart-val { font-size: 11.5px; color: var(--muted); margin-bottom: 5px; font-variant-numeric: tabular-nums; font-weight: 550; }
.chart-bar {
  width: 58%; max-width: 46px; border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #3b7cf6, var(--primary));
  transition: filter .15s;
}
.chart-col:hover .chart-bar { filter: brightness(1.12); }
.chart-bar.empty { background: var(--gray-bg); }
.chart-lbl { font-size: 12px; color: var(--muted); margin-top: 8px; height: 14px; }

/* ============ États vides ============ */
.empty {
  text-align: center; padding: 42px 20px; color: var(--muted);
}
.empty .icn { color: #cfd4dc; margin-bottom: 12px; }
.empty p { max-width: 420px; margin: 0 auto 16px; font-size: 13.5px; }
.empty b { color: var(--text-2); display: block; font-size: 15px; margin-bottom: 4px; font-weight: 600; }

/* ============ Lignes de document ============ */
#lignes-table input { padding: 6px 9px; box-shadow: none; }
#lignes-table textarea.ligne-desc {
  margin-top: 4px; padding: 6px 9px; font-size: 12.5px; color: var(--text-2);
  min-height: 48px; resize: vertical; box-shadow: none; line-height: 1.45; overflow: hidden;
}
#lignes-table td { padding: 6px 5px; }

/* Champ combiné : input + suffixe (unité, % / €) */
.joined { display: flex; align-items: stretch; }
.joined > input {
  border-top-right-radius: 0; border-bottom-right-radius: 0; border-right: none;
  flex: 1; min-width: 0; position: relative;
}
.joined > input:focus { z-index: 1; }
.suffix {
  display: flex; align-items: center; flex-shrink: 0;
  background: #eef0f4; border: 1px solid var(--border-2);
  border-radius: 0 8px 8px 0; overflow: hidden;
}
.joined:focus-within .suffix { border-color: var(--primary); }
.suffix select {
  appearance: none; -webkit-appearance: none; border: none; border-radius: 0;
  background: transparent; box-shadow: none; cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--text-2); width: auto;
  padding: 6px 20px 6px 9px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='6'%3E%3Cpath d='M1 1l3.5 3.5L8 1' stroke='%23475467' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 7px center;
}
.suffix select:hover { background-color: #e4e7ee; }
.suffix select:focus { outline: none; }

/* Sélecteur d'unité : le select natif (liste complète) est invisible
   au-dessus d'un badge qui n'affiche que le code court */
.unit-wrap { position: relative; display: flex; }
.unit-wrap .unit-code {
  display: flex; align-items: center; padding: 0 20px 0 9px;
  font-size: 12px; font-weight: 600; color: var(--text-2); white-space: nowrap;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='6'%3E%3Cpath d='M1 1l3.5 3.5L8 1' stroke='%23475467' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 7px center;
}
.unit-wrap:hover .unit-code { background-color: #e4e7ee; }
.unit-wrap select {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.totaux { margin-left: auto; width: 330px; margin-top: 16px; }
.totaux td { padding: 6px 10px; border: none; font-variant-numeric: tabular-nums; }
.totaux tr:first-child td { border-top: 1px solid var(--border); padding-top: 12px; }
.totaux .grand-total td { font-size: 16.5px; font-weight: 700; border-top: 1px solid var(--border); padding-top: 10px; }

/* ============ Connexion (portail) ============ */
.portal {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 26px; padding: 40px 20px; position: relative; overflow: hidden;
  background: linear-gradient(180deg, #fbfcfe 0%, #f2f4f8 100%);
}
/* Motif : barres parallèles obliques */
.deco { position: absolute; display: flex; flex-direction: column; gap: 20px; transform: rotate(-24deg); pointer-events: none; }
.deco i { display: block; height: 22px; border-radius: 99px; }
.deco-tr { top: 70px; right: -130px; align-items: flex-end; }
.deco-tr i:nth-child(1) { width: 300px; background: #0c1428; }
.deco-tr i:nth-child(2) { width: 470px; background: #2563eb; }
.deco-tr i:nth-child(3) { width: 380px; background: #a8c2f7; }
.deco-tr i:nth-child(4) { width: 250px; background: #e2e9f8; }
.deco-bl { bottom: 90px; left: -150px; align-items: flex-start; }
.deco-bl i:nth-child(1) { width: 240px; background: #e2e9f8; }
.deco-bl i:nth-child(2) { width: 420px; background: #c3d4f5; }
.deco-bl i:nth-child(3) { width: 330px; background: #eef2fa; }
/* mobile : les barres restent dans les coins, sans chevaucher la marque */
@media (max-width: 700px) {
  .deco { gap: 12px; }
  .deco i { height: 14px; }
  .deco-tr { top: -30px; right: -190px; }
  .deco-tr i:nth-child(1) { width: 190px; }
  .deco-tr i:nth-child(2) { width: 300px; }
  .deco-tr i:nth-child(3) { width: 240px; }
  .deco-tr i:nth-child(4) { width: 150px; }
  .deco-bl { bottom: -20px; left: -190px; }
  .deco-bl i:nth-child(2) { width: 280px; }
}
.portal-brand {
  display: flex; flex-direction: column; align-items: center; gap: 12px; position: relative; z-index: 1;
}
.portal-brand .brand-mark { width: 52px; height: 52px; border-radius: 14px; box-shadow: 0 8px 22px rgba(37, 99, 235, .3); }
.portal-brand .brand-name { font-size: 22px; letter-spacing: -.02em; color: var(--text); }
.portal-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px; padding: 36px 36px 30px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 16px 44px rgba(16, 24, 40, .09);
  position: relative; z-index: 1;
}
.portal-card h1 { font-size: 21px; font-weight: 700; letter-spacing: -.02em; }
.portal-card .lead { color: var(--muted); font-size: 13.5px; margin: 5px 0 26px; }
.portal-card .form-group { margin-bottom: 16px; }
.portal-card label { font-size: 12.5px; color: var(--muted); margin-bottom: 7px; }

/* Champs avec icône intégrée */
.field { position: relative; }
.field > .icn {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--faint); pointer-events: none; transition: color .15s;
}
.field:focus-within > .icn { color: var(--primary); }
.field input {
  padding: 12.5px 44px 12.5px 42px; font-size: 14px; border-radius: 12px;
  background: #f5f6f9; border-color: transparent; box-shadow: none;
}
.field input:hover { background: #f0f2f6; }
.field input:focus { background: #fff; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(37, 99, 235, .1); }
.toggle-pw {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  border: none; background: none; color: var(--faint); cursor: pointer;
  padding: 7px; border-radius: 9px; display: flex; transition: all .15s;
}
.toggle-pw:hover { color: var(--text-2); background: #e9ecf2; }
.capslock-hint {
  display: flex; align-items: center; gap: 6px; margin-top: 7px;
  color: var(--orange); font-size: 12.5px; font-weight: 500;
}
.capslock-hint[hidden] { display: none; }

/* Bouton de connexion */
.btn-auth {
  width: 100%; padding: 12.5px; font-size: 14.5px; border-radius: 12px; margin-top: 8px;
  background: linear-gradient(180deg, #2f6bef, var(--primary-dark));
  transition: transform .15s, box-shadow .15s, filter .15s;
}
.btn-auth:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(37, 99, 235, .35); }
.btn-auth:active { transform: translateY(0); }
.btn-auth .icn { transition: transform .15s; }
.btn-auth:hover .icn { transform: translateX(3px); }
.portal-foot {
  position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 7px;
  color: var(--faint); font-size: 12.5px;
}
.portal-foot .secure { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 500; }

/* Paiements */
.paiement-resume { display: flex; gap: 34px; flex-wrap: wrap; }
.paiement-resume > div { display: flex; flex-direction: column; gap: 2px; }
.paiement-resume span { font-size: 12.5px; }
.paiement-resume b { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.txt-green { color: var(--green); }
.txt-red { color: var(--red); }
.txt-orange { color: var(--orange); }
.paiement-form summary { list-style: none; display: inline-flex; width: auto; cursor: pointer; }
.paiement-form summary::-webkit-details-marker { display: none; }

/* ============ Autocomplétion d'adresse ============ */
.addr-anchor { position: relative; }
.client-search-wrap { position: relative; flex: 1; min-width: 0; }
.addr-list {
  position: absolute; z-index: 60; left: 0; right: 0; top: 100%; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); overflow: hidden auto; max-height: 262px;
}
.addr-item { padding: 8px 13px; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.addr-item b { font-size: 13.5px; font-weight: 600; }
.addr-item span { font-size: 12px; color: var(--muted); }
.addr-item:hover, .addr-item.active { background: var(--primary-soft); }
.addr-item.active b { color: var(--primary-dark); }

/* ============ Checklist mot de passe ============ */
.mdp-regles { list-style: none; margin: 9px 0 0; padding: 0; display: grid; gap: 5px; }
.mdp-regles li {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--muted); transition: color .15s;
}
.mdp-regles li::before {
  content: ''; width: 15px; height: 15px; border-radius: 50%; flex-shrink: 0;
  border: 1.5px solid var(--border-2); box-sizing: border-box; transition: all .15s;
}
.mdp-regles li.ok { color: var(--green); font-weight: 500; }
.mdp-regles li.ok::before {
  border-color: var(--green);
  background: var(--green) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='8'%3E%3Cpath d='M1 4l2.5 2.5L9 1' stroke='white' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/9px no-repeat;
}

/* ============ Modales ============ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; padding: 20px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(12, 20, 40, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none; transition: opacity .16s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 420px;
  padding: 26px 26px 22px; box-shadow: 0 24px 70px rgba(3, 7, 22, .35);
  transform: translateY(12px) scale(.96); transition: transform .18s cubic-bezier(.2, .9, .3, 1.2);
}
.modal-overlay.open .modal { transform: none; }
.modal-chip {
  width: 44px; height: 44px; border-radius: 12px; margin-bottom: 14px;
  display: flex; align-items: center; justify-content: center;
}
.modal-chip.danger { background: var(--red-bg); color: var(--red); }
.modal-chip.primary { background: var(--primary-soft); color: var(--primary); }
.modal-lg { max-width: 560px; }
.modal-title { font-size: 16.5px; font-weight: 700; letter-spacing: -.01em; }
.garder-toggle {
  display: flex; gap: 11px; align-items: flex-start; margin: 4px 0 0; cursor: pointer;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: #fafbfc;
  font-weight: 500;
}
.garder-toggle input { width: auto; margin-top: 3px; accent-color: var(--primary); }
.garder-toggle b { font-size: 13.5px; }
.garder-toggle .muted { font-size: 12.5px; font-weight: 400; }
.modal-msg { color: var(--muted); font-size: 13.5px; margin-top: 7px; line-height: 1.55; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.btn-danger-solid {
  background: #d92d20; border: 1px solid #d92d20; color: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .1), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.btn-danger-solid:hover { background: #b42318; border-color: #b42318; }

/* ============ Divers ============ */
.doc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.muted { color: var(--muted); }
.mt { margin-top: 14px; }
.actions-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.actions-bar form { display: inline-flex; }
.meta-list { display: grid; gap: 9px; font-size: 13.5px; }
.meta-list > div { display: flex; align-items: center; gap: 9px; color: var(--text-2); }
.meta-list .icn { color: var(--faint); }

/* Recadrage du logo : cadre de sélection libre sur l'image entière */
.logo-current { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.logo-preview { height: 56px; max-width: 220px; object-fit: contain; border-radius: 8px; border: 1px solid var(--border); padding: 6px; background: #fff; }
.crop-stage {
  position: relative; border-radius: 10px; overflow: hidden;
  background: repeating-conic-gradient(#f0f1f5 0% 25%, #fff 0% 50%) 0 0/16px 16px;
  border: 1px solid var(--border); touch-action: none; user-select: none;
  box-shadow: var(--shadow-sm);
}
.crop-stage img { display: block; pointer-events: none; max-width: none; }
.crop-sel {
  position: absolute; cursor: move;
  border: 1.5px solid #fff; outline: 1.5px solid var(--primary);
  box-shadow: 0 0 0 9999px rgba(12, 20, 40, .45);
}
.crop-h {
  position: absolute; width: 13px; height: 13px; background: #fff;
  border: 2px solid var(--primary); border-radius: 4px; box-shadow: var(--shadow-sm);
}
.crop-h.nw { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-h.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-h.sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-h.se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.crop-tools { display: flex; gap: 14px; align-items: center; margin-top: 10px; flex-wrap: wrap; }

/* Grands écrans : toute l'interface (sidebar comprise) monte en échelle
   pour ne pas paraître minuscule sur un moniteur externe */
@media (min-width: 1750px) {
  body { zoom: 1.12; }
}
@media (min-width: 2300px) {
  body { zoom: 1.28; }
}
.menu-toggle {
  display: none; margin-left: auto; border: 1px solid var(--border); background: var(--surface);
  border-radius: 9px; padding: 7px 9px; color: var(--text-2); cursor: pointer;
}

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 40;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .brand { display: flex; width: 100%; padding: 12px 16px; }
  .brand-sub { display: none; }
  .menu-toggle { display: inline-flex; }
  .sidebar nav { display: none; padding: 4px 12px 12px; }
  .sidebar.nav-open nav { display: block; }
  .sidebar nav a { padding: 12px; font-size: 15px; }
  .nav-section { display: none; }
  .sidebar-user { display: none; }
  .sidebar.nav-open .sidebar-user { display: flex; }
  .content { padding: 18px 14px 44px; }
  .page-head h1 { font-size: 19px; }
  .doc-grid { grid-template-columns: 1fr; }
  /* iOS zoome sur les champs < 16px : on force la taille minimale partout,
     y compris sur les sélecteurs plus spécifiques (connexion, lignes, suffixes) */
  input, select, textarea,
  .field input, .portal-card input,
  #lignes-table input, #lignes-table textarea.ligne-desc,
  .statut-select, .suffix select, .pp-form select,
  .search-box input, .date-range input {
    font-size: 16px !important;
  }
  .totaux { width: 100%; }
  .paiement-resume { gap: 22px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .filter-bar .search-box input { width: 100% !important; }
  .search-box { width: 100%; }
  .date-range { width: 100%; }
  .date-range input { flex: 1; }
  .crop-stage { max-width: 100%; }
  .crop-stage img { max-width: 100%; }
}
@media (max-width: 700px) {
  /* ---- Grilles de formulaire : une seule colonne, même avec un gabarit inline ---- */
  .form-grid { grid-template-columns: 1fr !important; }
  .form-grid > .form-group { grid-column: auto !important; }

  /* ---- Les listes-cartes : la carte conteneur s'efface, chaque rangée devient une carte ---- */
  .card-flush { background: transparent; border: none; box-shadow: none; overflow: visible; }
  .card-flush .filter-bar {
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: var(--shadow-sm); margin-bottom: 12px;
  }
  .card-flush .table-wrap { margin: 0; padding: 0; overflow: visible; }
  .card-flush .table-foot {
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: var(--shadow-sm); margin-top: 12px;
  }
  .card-flush .empty { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
  .filter-bar select { max-width: none !important; width: 100%; }
  .filter-bar .btn { width: 100%; }
  .filter-bar > a.btn { margin-left: 0 !important; }

  .rtable thead { display: none; }
  .rtable, .rtable tbody, .rtable tfoot, .rtable tr { display: block; width: 100%; }
  .rtable tbody tr, .rtable tfoot tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: var(--shadow-sm); padding: 8px 16px; margin-bottom: 10px;
  }
  .rtable tbody tr:hover { background: var(--surface); }
  .rtable td {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    border: none; padding: 7px 0 !important; text-align: right; font-size: 14px;
  }
  .rtable td[data-label]::before {
    content: attr(data-label); font-size: 11px; text-transform: uppercase;
    letter-spacing: .05em; color: var(--faint); font-weight: 600; text-align: left; flex-shrink: 0;
  }
  .rtable td:first-child { font-size: 15px; padding-top: 9px !important; justify-content: flex-start; text-align: left; }
  .rtable td.masque-mobile { display: none; }
  .rtable .row-actions {
    justify-content: stretch; border-top: 1px solid var(--border); margin-top: 4px;
    padding: 10px 0 9px !important; gap: 8px;
  }
  .rtable .row-actions > *, .rtable .row-actions form { flex: 1; }
  .rtable .row-actions .icon-btn { width: 100%; justify-content: center; padding: 8px; font-size: 13px; }
  .rtable tfoot tr { background: #fafbfc; }
  .rtable .tfoot-titre { justify-content: flex-start; text-align: left; font-size: 13px; }

  /* ---- Lignes de devis/facture : chaque ligne devient un bloc de saisie ---- */
  #lignes-table { display: block; }
  #lignes-table thead { display: none; }
  #lignes-table tbody { display: block; }
  #lignes-table tr.ligne {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: var(--shadow-sm); padding: 14px; margin-bottom: 12px;
  }
  #lignes-table tr.ligne:hover { background: var(--surface); }
  #lignes-table tr.ligne td { display: block; padding: 0 !important; border: none; }
  #lignes-table td[data-label]::before {
    content: attr(data-label); display: block; font-size: 11px; text-transform: uppercase;
    letter-spacing: .05em; color: var(--faint); font-weight: 600; margin-bottom: 5px;
  }
  #lignes-table tr.ligne td:nth-child(1) { grid-column: 1 / -1; }
  #lignes-table tr.ligne td.ligne-total {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    font-weight: 700; border-top: 1px solid var(--border); padding-top: 10px !important; margin-top: 2px;
  }
  #lignes-table tr.ligne td.ligne-total::before {
    content: 'Total HT'; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--faint); font-weight: 600;
  }
  #lignes-table tr.ligne td:last-child {
    display: flex; align-items: flex-end; justify-content: flex-end;
    border-top: 1px solid var(--border); padding-top: 10px !important; margin-top: 2px;
  }
  #lignes-table tr.ligne td:last-child .icon-btn { padding: 8px 14px; }
  #lignes-table input, #lignes-table textarea.ligne-desc { padding: 8px 10px; }

  /* ---- Vue document : boutons d'action pleine largeur ---- */
  .actions-bar { width: 100%; }
  .actions-bar form, .actions-bar .btn { flex: 1 1 46%; }
  .actions-bar form .btn { width: 100%; }

  /* ---- Dashboard : graphe compact ---- */
  .chart { height: 150px; }
  .chart-val { display: none; }

  /* ---- Modales confortables ---- */
  .modal { max-height: 90vh; overflow-y: auto; }
  .paiement-resume { width: 100%; justify-content: space-between; }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: stretch; }
  .actions-bar .btn, .page-head > a.btn { justify-content: center; }
  .table-foot { flex-direction: column; align-items: stretch; }
  .pager { justify-content: space-between; }
}
