:root {
  color-scheme: light;
  --bg: #f8f9fb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-light: #f0f2f5;
  --text: #111827;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --font: 'Inter', -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { overflow-x: hidden; }

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

.login-logo { text-align: center; margin-bottom: 12px; }
.login-logo img { display: inline-block; }
.login-title { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 32px; }

#login-form { display: flex; flex-direction: column; gap: 18px; }
#login-form .btn-full { margin-top: 8px; min-height: 46px; font-size: 15px; }
#login-form .form-error { margin-top: -6px; }

/* ── Header ────────────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  height: 56px;
}

.header-logo {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.header-logo:hover { opacity: .85; }

.header-nav {
  display: flex;
  gap: 2px;
  flex: 1;
}

.nav-btn {
  background: none;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  transition: all .15s;
  white-space: nowrap;
}

.nav-btn:hover { background: var(--bg); color: var(--text); }
.nav-btn.active { background: var(--primary-light); color: var(--primary); }

.btn-icon-sm svg, .btn svg { pointer-events: none; }
.empty-icon svg { opacity: .35; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.tab-content {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 20px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-header h2 { font-size: 20px; font-weight: 700; }

.stats-row {
  display: flex;
  gap: 16px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.stat-chip {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-chip strong { color: var(--text); }

.filters-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card-list { display: flex; flex-direction: column; gap: 8px; }

.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: box-shadow .15s;
}

.list-card:hover { box-shadow: var(--shadow-md); }

.card-main { flex: 1; min-width: 0; }
.card-title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.card-meta { font-size: 12px; color: var(--text-3); margin-top: 1px; }

.card-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.card-amount { font-weight: 700; font-size: 16px; text-align: right; }
.card-amount-sub { font-size: 11px; color: var(--text-3); text-align: right; }

/* Invoice status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-draft      { background: var(--bg); color: var(--text-2); border: 1px solid var(--border); }
.badge-sent       { background: var(--primary-light); color: var(--primary); }
.badge-paid       { background: var(--success-light); color: var(--success); }
.badge-cancelled  { background: var(--danger-light); color: var(--danger); }
.badge-overdue    { background: var(--danger); color: #fff; }

/* Doc type badges */
.doc-badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .3px;
}
.dt-quote    { background: #fef3c7; color: #b45309; }
.dt-proforma { background: #e0e7ff; color: #4338ca; }
.dt-credit   { background: #fee2e2; color: #b91c1c; }
[data-theme="dark"] .dt-quote    { background: #422006; color: #fcd34d; }
[data-theme="dark"] .dt-proforma { background: #1e1b4b; color: #a5b4fc; }
[data-theme="dark"] .dt-credit   { background: #450a0a; color: #fca5a5; }

/* Action menu (par document) */
.action-wrap { position: relative; }
.action-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 120;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  padding: 4px;
}
.am-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; text-align: left;
  padding: 9px 11px; border: none; background: none;
  font-family: var(--font); font-size: 13px; color: var(--text);
  cursor: pointer; border-radius: var(--radius-sm); white-space: nowrap;
}
.am-item:hover { background: var(--bg); }
.am-item.danger { color: var(--danger); }
.am-item svg { flex-shrink: 0; opacity: .8; }

/* Barre de recherche factures */
.invoice-search { margin-bottom: 10px; }
.invoice-search input {
  width: 100%; padding: 10px 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; background: var(--surface); color: var(--text);
}
.invoice-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); outline: none; }

/* Company color dot */
.co-dot {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

/* Larger dot for company list cards */
.co-dot-lg {
  width: 48px;
  height: 48px;
  border-radius: 10px;
}

/* Clickable badge (e.g. invoice prefix → company invoices) */
.badge-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font);
  transition: filter .15s, transform .1s;
}
.badge-btn:hover { filter: brightness(.92); }
.badge-btn:active { transform: scale(.94); }

/* ── Recherche SIRENE ────────────────────────────────────────────────────────── */
.sirene-box {
  background: var(--primary-light);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 18px;
}
.sirene-label { display: block; font-size: 12px; font-weight: 600; color: var(--primary); margin-bottom: 8px; }
.sirene-row { display: flex; gap: 8px; }
.sirene-row input { flex: 1; background: var(--surface); }
.sirene-row .btn { flex-shrink: 0; }
.sirene-results {
  margin-top: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 220px;
  overflow-y: auto;
}
.sirene-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  font-family: var(--font);
  transition: background .1s;
}
.sirene-item:last-child { border-bottom: none; }
.sirene-item:hover { background: var(--primary-light); }
.sirene-item-name { font-size: 13.5px; font-weight: 600; color: var(--text); }
.sirene-item-sub { font-size: 12px; color: var(--text-3); }
.sirene-empty { padding: 12px; font-size: 13px; color: var(--text-3); text-align: center; }

/* ── Filter banner (factures filtrées par client) ───────────────────────────── */
.filter-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: var(--primary-light);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text);
}
.filter-banner-clear {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: transparent;
  color: var(--primary);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.filter-banner-clear:hover { background: var(--surface); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
  min-height: 36px;
}

.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-hover)); color: #fff; border: none; box-shadow: 0 8px 24px -10px var(--primary); }
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 12px 30px -10px var(--primary); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; min-height: 30px; }
.btn-full { width: 100%; }
.btn-icon-sm {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all .15s;
}

.btn-icon-sm:hover { border-color: var(--primary); color: var(--primary); }
.btn-icon-sm.danger:hover { border-color: var(--danger); color: var(--danger); }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field-full { grid-column: 1 / -1; }

input:not([type]), input[type="text"], input[type="email"], input[type="tel"],
input[type="number"], input[type="date"], input[type="time"], input[type="password"],
input[type="url"], input[type="search"],
textarea, select {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
  outline: none;
}

input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
textarea { resize: vertical; min-height: 60px; }
select { cursor: pointer; }

/* Cases à cocher / radios : couleur du thème (sinon blanc natif moche en sombre) */
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 16px; height: 16px; cursor: pointer; }
/* Champ fichier (ex. import catalogue) : bouton habillé au thème */
input[type="file"] { font-size: 13.5px; color: var(--text-2); max-width: 100%; }
input[type="file"]::file-selector-button {
  font: inherit; font-size: 13px; font-weight: 600; margin-right: 10px; padding: 8px 14px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; transition: border-color .15s;
}
input[type="file"]::file-selector-button:hover { border-color: var(--text-3); }

/* Champs date : largeur cohérente + icône calendrier bleue */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}
input[type="date"]::-webkit-calendar-picker-indicator {
  /* Recolore l'icône native en bleu primaire (#2563eb) */
  filter: invert(36%) sepia(89%) saturate(1837%) hue-rotate(213deg) brightness(95%) contrast(92%);
  cursor: pointer;
  opacity: 1;
}
.select-sm { padding: 6px 10px; font-size: 13px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.select-full { width: 100%; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }

.form-error {
  color: var(--danger);
  font-size: 12.5px;
  background: var(--danger-light);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}

.section-label { font-weight: 600; font-size: 13px; color: var(--text); }
.form-sep { border: none; border-top: 1px solid var(--border-light); }

.color-field { display: flex; gap: 8px; align-items: center; }
.color-field input[type="color"] { width: 40px; height: 36px; padding: 2px; border-radius: var(--radius-sm); cursor: pointer; }
.color-field input[type="text"] { flex: 1; }

.file-input { display: none; }
.file-name { font-size: 12px; color: var(--text-2); }

.logo-preview { margin-bottom: 8px; }
.logo-preview img { max-height: 60px; max-width: 180px; object-fit: contain; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px; }

/* ── Invoice lines ─────────────────────────────────────────────────────────── */
.lines-section { margin-top: 20px; }
.lines-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 600; font-size: 14px; }

.lines-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }

.lines-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.lines-table th {
  background: var(--bg);
  padding: 8px 10px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .4px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.lines-table td { padding: 6px 6px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.lines-table tr:last-child td { border-bottom: none; }

.col-desc  { width: 40%; }
.col-qty   { width: 9%; }
.col-unit  { width: 9%; }
.col-price { width: 14%; }
.col-tva   { width: 11%; }
.col-total { width: 13%; }
.col-del   { width: 4%; }

.lines-table input, .lines-table select { padding: 5px 7px; font-size: 13px; }
.line-total { font-weight: 600; font-size: 13px; padding: 0 8px; color: var(--text-2); }

.totals-preview {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.total-line {
  display: flex;
  gap: 24px;
  font-size: 13px;
  color: var(--text-2);
}

.total-line.final {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-top: 4px;
  padding-top: 8px;
  border-top: 2px solid var(--border);
}

.total-line span:last-child { min-width: 100px; text-align: right; font-weight: 500; }

/* ── Modals ─────────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}

.modal-box {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.modal-lg { max-width: 780px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-3);
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}

.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.modal-footer-right { display: flex; gap: 8px; }

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-3);
}

.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── User dropdown ───────────────────────────────────────────────────────────── */
.user-menu-wrap { position: relative; }
.user-btn { font-size: 17px !important; padding: 5px 9px !important; }

.user-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 160px;
  z-index: 300;
  overflow: hidden;
}

.user-menu-name {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: none;
  border: none;
  font-size: 13px;
  color: var(--danger);
  cursor: pointer;
  font-family: var(--font);
  transition: background .1s;
}

.user-menu-item:hover { background: var(--bg); }

/* « Ma couleur » : pastille dans le menu + sélecteur de couleurs */
#btn-mycolor, #btn-manage-users { color: var(--text); display: flex; align-items: center; }
.mycolor-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px;
  background: var(--text-3); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.modal-sm { max-width: 360px; }
.mycolor-text { font-size: 13px; color: var(--text-2); margin: 0 0 16px; }
.mycolor-swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.mycolor-sw { width: 100%; aspect-ratio: 1; border-radius: 10px; border: 2px solid transparent; cursor: pointer;
  padding: 0; position: relative; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); transition: transform .08s; }
.mycolor-sw:hover { transform: scale(1.06); }
.mycolor-sw.selected { border-color: var(--surface); box-shadow: 0 0 0 2px var(--text); }
.mycolor-sw.selected::after { content: '✓'; position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; color: #fff; font-size: 15px; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,.45); }
.mycolor-reset { width: 100%; margin-top: 18px; }

/* ── Share toggle ────────────────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s;
}
.toggle-row:hover { border-color: var(--primary); }
.toggle-row input[type="checkbox"] { width: 16px; height: 16px; margin-top: 2px; flex-shrink: 0; cursor: pointer; accent-color: var(--primary); }
.toggle-text { display: flex; flex-direction: column; gap: 2px; }
.toggle-text strong { font-size: 13.5px; font-weight: 600; color: var(--text); }
.toggle-hint { font-size: 12px; color: var(--text-3); }

.badge-shared { background: #dbeafe; color: #1d4ed8; font-size: 10px; padding: 1px 6px; border-radius: 999px; font-weight: 600; }
[data-theme="dark"] .badge-shared { background: #1e3a5f; color: #93c5fd; }

/* ── User shares list ────────────────────────────────────────────────────────── */
.shares-list { display: flex; flex-direction: column; gap: 6px; }
.share-user-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; transition: border-color .15s; }
.share-user-item:hover { border-color: var(--primary); }
.share-user-item input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.share-user-item span { font-size: 13.5px; font-weight: 500; }

/* ── Month grouping ──────────────────────────────────────────────────────────── */
.month-group { margin-bottom: 8px; }
.month-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 4px 6px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 8px;
}
.month-label { font-size: 13px; font-weight: 700; color: var(--text); }
.month-meta { font-size: 12px; color: var(--text-3); font-weight: 500; }
.month-group .card-list { gap: 6px; }

/* ── Stats tab ───────────────────────────────────────────────────────────────── */
.stats-selector-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.stats-selector-label { font-size: 13px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.stats-company-select { font-size: 14px !important; padding: 9px 12px !important; min-width: 220px; }
.stats-loading { padding: 40px; text-align: center; color: var(--text-3); font-size: 14px; }
.stats-company-header {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

/* ── PDF viewer modal ────────────────────────────────────────────────────────── */
.modal-fullscreen { max-width: 94vw; width: 94vw; max-height: 94vh; height: 94vh; }
@media (max-width: 640px) {
  .modal-fullscreen { max-width: 100vw; width: 100%; max-height: 100vh; height: 100vh; border-radius: 0; }
}

/* ── Stats tab ───────────────────────────────────────────────────────────────── */
.stat-metrics { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; margin-bottom:20px; }
.stat-metric { background:var(--bg); border:1px solid var(--border); border-radius:var(--radius-sm); padding:12px; text-align:center; }
.sm-label { display:block; font-size:10.5px; color:var(--text-3); text-transform:uppercase; letter-spacing:.5px; margin-bottom:4px; }
.sm-value { display:block; font-size:18px; font-weight:700; }

.stat-section-title { font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.5px; color:var(--text-3); margin:16px 0 10px; }

.stat-chart { display:flex; align-items:flex-end; gap:3px; height:120px; padding-bottom:20px; position:relative; }
.stat-bar { flex:1; display:flex; flex-direction:column; align-items:stretch; height:100%; justify-content:flex-end; position:relative; cursor:default; }
.stat-bar-inner { flex:1; display:flex; flex-direction:column; justify-content:flex-end; }
.stat-bar-paid { background:var(--success); border-radius:3px 3px 0 0; min-height:0; opacity:.85; transition:height .3s; }
.stat-bar-pending { background:var(--warning); min-height:0; opacity:.7; transition:height .3s; }
.stat-bar-lbl { position:absolute; bottom:-18px; left:50%; transform:translateX(-50%); font-size:9px; color:var(--text-3); white-space:nowrap; }

.stat-two-col { display:grid; grid-template-columns:1fr 1fr; gap:20px; margin-top:4px; }
.stat-breakdown { display:flex; flex-direction:column; gap:8px; }
.stat-breakdown-row { display:grid; grid-template-columns:70px 1fr 50px 80px; align-items:center; gap:6px; font-size:12.5px; }
.stat-bd-label { color:var(--text-2); }
.stat-bd-bar { height:6px; background:var(--border); border-radius:3px; overflow:hidden; }
.stat-bd-fill { height:100%; border-radius:3px; transition:width .4s; }
.stat-bd-val { color:var(--text-2); font-size:12px; }
.stat-bd-amt { text-align:right; font-weight:600; font-size:12px; }

.stat-clients { display:flex; flex-direction:column; gap:6px; }
.stat-client-row { display:grid; grid-template-columns:20px 1fr 50px auto; align-items:center; gap:6px; font-size:12.5px; }
.stat-client-rank { width:20px; height:20px; border-radius:50%; background:var(--primary-light); color:var(--primary); font-size:10px; font-weight:700; display:flex; align-items:center; justify-content:center; }
.stat-client-name { color:var(--text); font-weight:500; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.stat-client-count { color:var(--text-3); font-size:11px; }
.stat-client-rev { font-weight:700; color:var(--text); text-align:right; }

@media (max-width:640px) {
  .stat-metrics { grid-template-columns:1fr 1fr; }
  .stat-two-col { grid-template-columns:1fr; }
  .stat-breakdown-row { grid-template-columns:60px 1fr 40px 70px; }
}

/* ── Company detail modal ───────────────────────────────────────────────────── */
.cod-stats-bar {
  display: flex;
  gap: 20px;
  padding: 12px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.cod-stat { display: flex; flex-direction: column; gap: 2px; }
.cod-stat-label { font-size: 10.5px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; }
.cod-stat-value { font-size: 15px; font-weight: 700; color: var(--text); }

.cod-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  background: var(--surface);
}

.cod-tab {
  padding: 10px 14px;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  font-family: var(--font);
  transition: all .15s;
}

.cod-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.cod-tab:not(.active):hover { color: var(--text); }

/* ── Dark mode ──────────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  color-scheme: dark;   /* contrôles natifs (cases à cocher, dates, fichier, scrollbars) en sombre */
  --bg: #0b0d12;
  --surface: #141a28;
  --border: #232a3b;
  --border-light: #1b2231;
  --text: #eef1f7;
  --text-2: #aab3c5;
  --text-3: #6b7488;
  --primary: #7c3aed;          /* accent violet par défaut (landing) ; remplacé par la couleur du tenant */
  --primary-hover: #2563eb;    /* 2e arrêt du dégradé (→ couleur unie si le tenant définit sa couleur) */
  --primary-light: #7c3aed22;
  --danger: #ef4444;
  --danger-light: #2d1515;
  --success: #22c55e;
  --success-light: #0f2d1c;
  --warning: #f59e0b;
  --warning-light: #2d2010;
  --shadow: 0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.35);
  --shadow-md: 0 18px 50px -20px rgba(0,0,0,.7), 0 0 0 1px #ffffff08;
}

/* Fond premium à halos (même DA que la page d'accueil), fixe derrière toute l'app */
[data-theme="dark"] body {
  background:
    radial-gradient(900px 600px at 12% -8%, #18123a 0%, transparent 58%),
    radial-gradient(820px 600px at 96% 2%, #0b2350 0%, transparent 52%),
    var(--bg);
  background-attachment: fixed;
}

/* En-tête vitré */
[data-theme="dark"] .app-header {
  background: #0d1120cc;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom-color: #ffffff12;
}

/* Login sur le fond animé (halos qui dérivent) + carte qui glow */
[data-theme="dark"] .login-screen {
  background:
    radial-gradient(700px 500px at 20% 10%, #2a1b5e 0%, transparent 60%),
    radial-gradient(700px 500px at 85% 90%, #0c2a63 0%, transparent 55%),
    var(--bg);
}
[data-theme="dark"] .login-card {
  border: 1px solid #ffffff14;
  box-shadow: 0 30px 90px -30px #000, 0 0 0 1px #ffffff08 inset;
}

/* ── Client mode toggle ─────────────────────────────────────────────────────── */
.field-label-row { display: flex; justify-content: space-between; align-items: center; }

.ctoggle-wrap {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.ctoggle {
  padding: 3px 11px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-2);
  transition: all .15s;
}

.ctoggle.active { background: var(--primary); color: #fff; }
.ctoggle:not(.active):hover { background: var(--bg); }

#manual-client-fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

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

/* ── Bottom nav ─────────────────────────────────────────────────────────────── */
.bottom-nav { display: none; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Header: hide desktop nav, keep logo + actions */
  .header-nav { display: none; }
  .app-header { padding: 0 12px; gap: 6px; }
  .header-logo { flex: 1; }

  /* Tab content: space for bottom nav */
  .tab-content { padding: 16px 12px 84px; }

  /* Bottom nav */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 150;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -2px 12px rgba(0,0,0,.08);
  }

  .bnav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 4px 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-3);
    font-size: 11px;
    font-weight: 500;
    font-family: var(--font);
    transition: color .15s;
    -webkit-tap-highlight-color: transparent;
  }

  .bnav-icon { font-size: 22px; line-height: 1; }
  .bnav-btn.active,
  .bnav-btn.sheet-open { color: var(--primary); }
  .bnav-btn:active { opacity: .7; }

  /* Feuille "Plus" (bottom sheet) */
  .more-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 160;
  }
  .more-sheet {
    position: fixed; left: 0; right: 0; bottom: 0;
    z-index: 170;
    background: var(--surface);
    border-top-left-radius: 18px;
    border-top-right-radius: 18px;
    box-shadow: 0 -8px 30px rgba(0,0,0,.25);
    padding: 6px 12px calc(14px + env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    transition: transform .22s ease;
  }
  .more-sheet.open { transform: translateY(0); }
  .more-sheet-grip {
    width: 40px; height: 4px; border-radius: 2px;
    background: var(--border); margin: 8px auto 6px;
  }
  .more-sheet-title {
    font-size: 12px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .4px; color: var(--text-3); padding: 2px 6px 8px;
  }
  .more-item {
    display: flex; align-items: center; gap: 14px; width: 100%;
    padding: 14px 8px; background: none; border: none; cursor: pointer;
    font-family: var(--font); font-size: 15px; font-weight: 500;
    color: var(--text); border-radius: 10px; text-align: left;
    -webkit-tap-highlight-color: transparent;
  }
  /* pas de bordure entre items (les coins arrondis créaient une ligne tronquée) */
  .more-item:active { background: var(--border-light); }
  .more-item.active { color: var(--primary); }
  .more-item-ic { display: flex; color: var(--text-3); }
  .more-item.active .more-item-ic { color: var(--primary); }
  /* "Factures" repliable : libellé extensible + flèche à droite */
  .more-parent .more-parent-label { flex: 1; }
  .more-caret {
    display: inline-flex; align-items: center; justify-content: center;
    margin-left: auto; padding: 6px; border-radius: 8px; color: var(--text-3);
    -webkit-tap-highlight-color: transparent;
  }
  .more-caret svg { transition: transform .2s ease; }
  .more-caret[aria-expanded="true"] svg { transform: rotate(180deg); }
  .more-caret:active { background: var(--border-light); }
  /* Sous-menu de "Factures" (Clients / Entreprises) */
  .more-subwrap { display: flex; flex-direction: column; }
  .more-item.more-sub { padding-left: 26px; font-size: 14px; color: var(--text-2); }
  .more-item.more-sub .more-item-ic { transform: scale(.88); }

  /* Tableaux ventes/achats : rendus en cartes empilées sur mobile */
  #ventes-list .data-table, #achats-list .data-table,
  #ventes-list tbody, #achats-list tbody,
  #ventes-list tr, #achats-list tr,
  #ventes-list td, #achats-list td { display: block; min-width: 0; }
  #ventes-list thead, #achats-list thead { display: none; }
  #ventes-list tr.clickable, #achats-list tr.clickable {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 10px;
  }
  #ventes-list td, #achats-list td {
    border: none !important;
    padding: 4px 0 !important;
    white-space: normal !important;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    font-size: 14px;
  }
  #ventes-list td::before, #achats-list td::before {
    content: attr(data-label);
    color: var(--text-3);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .3px;
    font-weight: 500;
  }
  #ventes-list td.num, #achats-list td.num { font-size: 17px; font-weight: 700; }
  #ventes-list td.row-actions, #achats-list td.row-actions {
    justify-content: flex-end;
    margin-top: 8px;
    padding-top: 10px !important;
    border-top: 1px solid var(--border-light) !important;
  }
  #ventes-list td.row-actions::before, #achats-list td.row-actions::before { display: none; }

  /* Détail déplié inline : la carte ouverte se prolonge par un panneau collé dessous */
  #ventes-list tr.clickable.expanded, #achats-list tr.clickable.expanded {
    border-bottom-left-radius: 0; border-bottom-right-radius: 0; margin-bottom: 0;
  }
  #ventes-list tr.detail-row, #achats-list tr.detail-row {
    margin-bottom: 10px; background: none; border: none; padding: 0;
  }
  #ventes-list tr.detail-row > td, #achats-list tr.detail-row > td {
    display: block !important; padding: 0 !important; background: none;
  }
  #ventes-list tr.detail-row > td::before, #achats-list tr.detail-row > td::before { content: none; }
  #ventes-list tr.detail-row .row-detail, #achats-list tr.detail-row .row-detail {
    background: var(--surface); border: 1px solid var(--border); border-top: none;
    border-radius: 0 0 12px 12px;
  }
  #ventes-list tr.detail-row .rd-inner, #achats-list tr.detail-row .rd-inner { padding: 4px 14px 14px; }
  /* Les lignes d'articles du détail repassent en blocs simples (pas en flex ::before) */
  #ventes-list tr.detail-row .doc-meta, #achats-list tr.detail-row .doc-meta { gap: 6px 18px; }
  #ventes-list tr.detail-row .rd-line, #achats-list tr.detail-row .rd-line { flex-wrap: wrap; gap: 2px 10px; }

  /* Forms */
  .form-grid-2 { grid-template-columns: 1fr; }
  .field-full { grid-column: 1; }

  /* Modals: bottom sheet */
  .modal { padding: 0; align-items: flex-end; }
  .modal-box { border-radius: 16px 16px 0 0; max-height: 96vh; width: 100%; max-width: 100vw; overflow: hidden; }
  .modal-body { -webkit-overflow-scrolling: touch; }
  .modal-footer { flex-direction: column-reverse; gap: 8px; }
  .modal-footer-right { width: 100%; display: flex; }
  .modal-footer-right .btn { flex: 1; }
  .modal-footer > .btn-ghost { width: 100%; }

  /* Cards */
  .list-card { flex-wrap: wrap; }
  .card-right {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-light);
    margin-top: 4px;
  }
  .card-amount { font-size: 18px; }

  /* Filters */
  .filters-row { flex-direction: column; }
  .filters-row select { width: 100%; padding: 9px 10px; font-size: 14px; }

  /* Page header */
  .page-header h2 { font-size: 18px; }

  /* Prevent iOS auto-zoom on inputs (triggered when font-size < 16px) */
  input[type="text"], input[type="email"], input[type="tel"],
  input[type="number"], input[type="date"], input[type="password"],
  input[type="url"], input[type="search"],
  textarea, select { font-size: 16px !important; }

  /* ── Invoice lines : flexbox avec order — fiable sur Safari iOS ── */
  .lines-table-wrap { overflow-x: hidden; border-radius: var(--radius-sm); }
  /* Forcer la sortie du mode table sur tous les éléments */
  .lines-table              { display: block !important; min-width: 0 !important; }
  .lines-table thead        { display: none !important; }
  .lines-table tbody        { display: block !important; }
  .lines-table tbody tr     {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    align-items: center;
  }
  .lines-table tbody tr:last-child { border-bottom: none; }
  .lines-table tbody td {
    display: block !important;
    padding: 0 !important;
    border: none !important;
    min-width: 0;
  }
  .lines-table tbody td input,
  .lines-table tbody td select {
    display: block !important;
    width: 100% !important;
    min-width: 0;
  }
  /* Ordonnancement et dimensionnement des cellules */
  /* Ligne 1 : col-desc + col-del = exactement 100% → force le retour à la ligne */
  /* 36px (del) + 6px (gap) = 42px → desc prend calc(100% - 42px)              */
  .lines-table td.col-desc  { order: 1; flex: 0 0 calc(100% - 42px); min-width: 0; }
  .lines-table td.col-del   { order: 2; flex: 0 0 36px; display: flex !important; align-items: center; justify-content: center; }
  /* Ligne 2 : Qté | Unité | Prix | TVA — 4 cases égales sur la ligne suivante */
  .lines-table td.col-qty   { order: 3; flex: 1 1 0; min-width: 0; }
  .lines-table td.col-unit  { order: 4; flex: 1 1 0; min-width: 0; }
  .lines-table td.col-price { order: 5; flex: 1 1 0; min-width: 0; }
  .lines-table td.col-tva   { order: 6; flex: 1 1 0; min-width: 0; }
  /* Ligne 3 : Total aligné à droite */
  .lines-table td.col-total { order: 7; flex: 0 0 100%; text-align: right; }
  .line-total { white-space: nowrap; }

  .lines-table input, .lines-table select { padding: 9px 5px; }
  .btn-del-line { width: 34px !important; height: 34px !important; }
  .btn-icon-sm { width: 38px; height: 38px; }

  /* Stats chips: wrap cleanly */
  .stats-row { gap: 10px; }
  .stat-chip { font-size: 12px; }

  /* Totals preview : empêche le retour à la ligne sur le montant */
  .total-line { gap: 12px; flex-wrap: nowrap; }
  .total-line span:last-child { white-space: nowrap; }

  /* Boutons action dans l'en-tête de page: pleine largeur sur mobile */
  .page-header { gap: 10px; }
  .page-header .btn { white-space: nowrap; }

  /* Empêche le débordement horizontal des contenus */
  .tab-content, .modal-body, .card-list { overflow-x: hidden; max-width: 100%; }

  /* Meilleur scroll dans les modals */
  .modal-body { padding: 16px 14px; }

  /* Client toggle sur mobile */
  .field-label-row { flex-wrap: wrap; gap: 6px; }
  .ctoggle-wrap { flex-shrink: 0; }
}

/* ── Module Stock ───────────────────────────────────────────────────────────── */
.stock-summary { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.stock-summary .ss-item { display: inline-flex; align-items: center; gap: 5px; }
.stock-summary .ss-low { color: #d97706; }
.stock-summary .ss-out { color: var(--danger); }
.stock-summary .ss-val { color: var(--text); font-weight: 600; }

.stock-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 14px 0; }
.stock-search { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 12px; color: var(--text-3); }
.stock-search input { flex: 1; border: none; background: none; outline: none; padding: 10px 0; font: inherit; font-size: 15px; color: var(--text); }
.stock-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text-2); border-radius: 999px;
  padding: 7px 13px; font: inherit; font-size: 13px; cursor: pointer; transition: all .12s; }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.stock-view-toggle { display: flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.vt-btn { border: none; background: var(--surface); color: var(--text-2); padding: 8px 10px; cursor: pointer; display: flex; }
.vt-btn.active { background: var(--primary); color: #fff; }

.stock-categories { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.cat-chip { border: none; background: none; color: var(--text-2); border-radius: var(--radius-sm);
  padding: 5px 10px; font: inherit; font-size: 13px; cursor: pointer; transition: all .12s; }
.cat-chip:hover { background: var(--border-light); color: var(--text); }
.cat-chip.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.stock-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.prod-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; cursor: pointer; transition: border-color .12s, transform .12s, box-shadow .12s; }
.prod-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.prod-img { position: relative; width: 100%; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--bg); display: flex; align-items: center; justify-content: center; margin-bottom: 9px; }
/* Placeholder en couche de fond : visible pendant le chargement / si image absente */
.prod-img-ph { position: absolute; inset: 0; z-index: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-3); opacity: .4; transition: opacity .2s ease; }
.prod-img img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: contain;
  opacity: 0; transition: opacity .3s ease; }
.prod-img img.loaded { opacity: 1; }
.prod-img:has(img.loaded) .prod-img-ph { opacity: 0; }   /* image chargée → on masque le placeholder */
.prod-img.ph { color: var(--text-3); }
.prod-ref { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.prod-name { font-size: 13px; font-weight: 500; color: var(--text); line-height: 1.35; margin: 2px 0 9px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 35px; }
.prod-bottom { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.prod-price { font-weight: 700; font-size: 14px; color: var(--text); }
.pill { font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill-in { color: #16a34a; } .pill-low { color: #d97706; } .pill-out { color: var(--danger); }

.stock-table-wrap { overflow-x: auto; }
.stock-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.stock-table th { text-align: left; padding: 9px 12px; color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); }
.stock-table td { padding: 9px 12px; border-bottom: 1px solid var(--border-light); color: var(--text); }
.stock-table tbody tr { cursor: pointer; } .stock-table tbody tr:hover { background: var(--border-light); }

/* Fiche produit (modale) */
.product-edit { display: flex; gap: 18px; align-items: flex-start; }
.product-edit-img { width: 140px; height: 140px; flex-shrink: 0; margin: 0; }
.product-edit-fields { flex: 1; min-width: 0; }
.product-edit .check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.product-edit .check input { width: 16px; height: 16px; }
.stock-adjust { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.stock-adjust-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.stock-adjust-head > span:first-child { font-size: 13px; color: var(--text-2); text-transform: uppercase; letter-spacing: .4px; }
.stock-current { font-size: 22px; font-weight: 800; color: var(--text); }
.stock-adjust-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stock-adjust-row input[type=number] { width: 84px; }
.stock-moves { margin-top: 14px; }
.moves-title { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.move-row { display: flex; gap: 12px; align-items: center; font-size: 13px; padding: 5px 0; border-bottom: 1px solid var(--border-light); }
.move-delta { font-weight: 700; width: 48px; font-variant-numeric: tabular-nums; }
.move-delta.pos { color: #16a34a; } .move-delta.neg { color: var(--danger); }
.move-reason { flex: 1; color: var(--text-2); } .move-date { color: var(--text-3); }
.btn-danger-ghost { color: var(--danger); background: none; border: 1px solid transparent; }
.btn-danger-ghost:hover { border-color: var(--danger); background: var(--danger-light); }
.modal-footer-spacer { flex: 1; }
@media (max-width: 640px) {
  .product-edit { flex-direction: column; align-items: center; }
  .product-edit-fields { width: 100%; }
}

/* Ventes */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.data-table th { text-align: left; padding: 10px 12px; color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 11px 12px; border-bottom: 1px solid var(--border-light); color: var(--text); }
.data-table td.num { font-weight: 600; font-variant-numeric: tabular-nums; }
.data-table .row-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.badge-ok { font-size: 12px; font-weight: 600; color: #16a34a; background: rgba(22,163,74,.12); padding: 3px 9px; border-radius: 999px; }
.sale-lines { margin: 4px 0 10px; }
.sale-line { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border-light); }
.sl-name { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sl-ref { color: var(--text-3); font-size: 12px; }
.sale-line input { width: auto; }
.sale-line .sl-qty { width: 64px; flex-shrink: 0; } .sale-line .sl-price { width: 92px; flex-shrink: 0; }
.sl-total { width: 90px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.sale-empty { color: var(--text-3); font-size: 13px; padding: 10px 0; }
.sale-total-row { display: flex; justify-content: flex-end; align-items: baseline; gap: 12px; font-size: 14px; color: var(--text-2); margin: 6px 0 4px; }
.sale-total-row span { font-size: 20px; font-weight: 800; color: var(--text); }

/* Tracking (expéditions) */
.page-sub { font-size: 13px; font-weight: 400; color: var(--text-3); }
.ship-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-top: 8px; }
.ship-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; cursor: pointer; transition: border-color .12s, transform .12s, box-shadow .12s; }
.ship-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.ship-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.ship-mode { font-size: 13px; color: var(--text-2); font-weight: 600; }
.ship-badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.st-prevu { background: var(--border-light); color: var(--text-2); }
.st-transit { background: rgba(37,99,235,.16); color: var(--primary); }
.st-arrive { background: rgba(217,119,6,.16); color: #d97706; }
.st-receptionne { background: rgba(22,163,74,.16); color: #16a34a; }
.ship-carrier { font-size: 15px; font-weight: 600; color: var(--text); }
.ship-track { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; margin-top: 2px; }
.ship-eta { font-size: 12px; color: var(--text-3); margin-top: 8px; }

/* Détail vente/achat */
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover { background: var(--border-light); }
.doc-meta { display: flex; gap: 20px; flex-wrap: wrap; font-size: 14px; color: var(--text-2); margin-bottom: 14px; }
.doc-meta b { color: var(--text-3); font-weight: 500; margin-right: 5px; text-transform: uppercase; font-size: 11px; letter-spacing: .4px; }
.doc-lines { width: 100%; border-collapse: collapse; font-size: 14px; }
.doc-lines th { text-align: left; padding: 8px 10px; color: var(--text-2); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); }
.doc-lines th.num, .doc-lines td.num { text-align: right; white-space: nowrap; }
.doc-lines td { padding: 9px 10px; border-bottom: 1px solid var(--border-light); color: var(--text); }

/* Détail vente/achat déplié INLINE (accordéon) */
.data-table tr.clickable.expanded { background: var(--border-light); }
tr.detail-row > td { padding: 0; background: var(--bg); border-bottom: 1px solid var(--border); }
/* Dépliage fluide : la hauteur (max-height en px mesurés) s'anime en ease-out */
.row-detail { overflow: hidden; max-height: 0; opacity: 0;
  transition: max-height .28s cubic-bezier(.33, 1, .68, 1), opacity .2s ease; }
.row-detail.open { opacity: 1; }
.rd-inner { padding: 16px 18px; }
.row-detail-msg { color: var(--text-3); font-size: 14px; padding: 6px 0; }
@media (prefers-reduced-motion: reduce) { .row-detail { transition: none; } }
.rd-lines { display: flex; flex-direction: column; margin: 2px 0 6px; }
.rd-line { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 8px 0; border-top: 1px solid var(--border-light); font-size: 14px; }
.rd-line:first-child { border-top: none; }
.rd-name { color: var(--text); }
.rd-fig { color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rd-fig b { color: var(--text); font-weight: 700; }
.doc-actions-inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

/* Autocomplétion produit */
.ac { position: relative; }
.ac-results { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); max-height: 260px; overflow-y: auto; }
.ac-item { padding: 9px 12px; cursor: pointer; font-size: 14px; border-bottom: 1px solid var(--border-light); }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--primary-light); color: var(--primary); }
.ac-empty { padding: 10px 12px; color: var(--text-3); font-size: 13px; }

/* Tableau de bord statistiques */
/* Sections de l'onglet Statistiques */
.stats-section { margin-bottom: 30px; }
.stats-subtitle { font-size: 15px; font-weight: 700; color: var(--text); margin: 0 0 14px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.stats-who { font-weight: 700; }
.stats-hint { font-size: 12.5px; font-weight: 500; color: var(--text-3); }

/* Mes stats perso (3 périodes) */
.my-stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.my-stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.my-stat-period { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-2); margin-bottom: 12px; font-weight: 600; }
.my-stat-row { display: flex; justify-content: space-between; align-items: baseline; padding: 7px 0; border-top: 1px solid var(--border); }
.my-stat-row:first-of-type { border-top: none; }
.my-stat-row span { font-size: 13px; color: var(--text-2); }
.my-stat-row b { font-size: 17px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.my-stat-row b.pos { color: #16a34a; }
.my-stat-row b.neg { color: var(--danger); }

/* Stat publique cuvettes */
.cuvette-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 560px) { .cuvette-grid { gap: 10px; } }
.cuvette-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 14px; text-align: center; }
.cuvette-num { font-size: 30px; font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; line-height: 1; }
.cuvette-label { font-size: 12.5px; color: var(--text-2); margin-top: 8px; text-transform: uppercase; letter-spacing: .4px; }

.stats-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin: 8px 0 22px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.kpi-card.k-rev { border-left-color: #3b82f6; }
.kpi-card.k-sales { border-left-color: #8b5cf6; }
.kpi-card.k-buy { border-left-color: #f59e0b; }
.kpi-card.k-profit { border-left-color: #16a34a; }
.kpi-label { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-2); }
.kpi-value { font-size: 26px; font-weight: 800; color: var(--text); margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.kpi-caption { font-size: 12.5px; color: var(--text-3); }
.kpi-caption b { color: var(--text-2); }
.stats-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .stats-charts { grid-template-columns: 1fr; } }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.chart-card h3 { font-size: 14px; font-weight: 600; color: var(--text); margin: 0 0 12px; }
.chart-box { position: relative; height: 280px; }

/* Sous-menu de nav (Factures > Clients / Entreprises) */
.nav-group { position: relative; }
.nav-group-btn { display: inline-flex; align-items: center; gap: 4px; }
.nav-caret { opacity: .55; transition: transform .2s; }
.nav-group:hover .nav-caret { transform: rotate(180deg); }
.nav-dropdown { position: absolute; top: 100%; left: 0; min-width: 168px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); display: none; flex-direction: column; gap: 2px; z-index: 60; }
.nav-group:hover .nav-dropdown, .nav-group:focus-within .nav-dropdown { display: flex; }
.nav-dd-item { text-align: left; padding: 9px 12px; border: none; background: none; color: var(--text-2);
  font: inherit; font-size: 14px; border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap; transition: background .12s, color .12s; }
.nav-dd-item:hover { background: var(--primary-light); color: var(--primary); }
.nav-dd-item.active { color: var(--primary); font-weight: 600; }

/* ── Fiche produit : photo + détourage ─────────────────────────────────────── */
.pf-photo-controls { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.pf-photo-status { font-size: 12px; color: var(--text-3); }
.pf-cutout-toggle { display: flex; align-items: center; gap: 7px; margin: 2px 0 10px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.pf-url-input { font-size: 13px !important; }
/* damier derrière l'aperçu pour visualiser la transparence d'une photo détourée */
#pf-img:not(.ph) {
  background-color: var(--surface);
  background-image:
    linear-gradient(45deg, var(--border-light) 25%, transparent 25%),
    linear-gradient(-45deg, var(--border-light) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--border-light) 75%),
    linear-gradient(-45deg, transparent 75%, var(--border-light) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* ── Outils : grille + carte ──────────────────────────────────────────────── */
.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.tool-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  text-align: left; padding: 20px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  font-family: var(--font); color: var(--text);
  transition: box-shadow .15s, border-color .15s, transform .12s;
}
.tool-card:hover { box-shadow: var(--shadow-md); border-color: var(--primary); transform: translateY(-2px); }
.tool-ic {
  display: flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--primary-light); color: var(--primary);
}
.tool-name { font-size: 16px; font-weight: 700; }
.tool-desc { font-size: 13px; color: var(--text-2); line-height: 1.4; }

/* ── Studio intégré (plein cadre sous la barre mmsoa) ─────────────────────── */
.tab-studio { max-width: none; margin: 0; padding: 0; }
.studio-frame {
  display: block; width: 100%; border: none; background: var(--bg);
  height: calc(100dvh - 56px);     /* 56px = hauteur de l'en-tête mmsoa */
}
@media (max-width: 640px) {
  /* on laisse la place à la barre de navigation du bas */
  .studio-frame { height: calc(100dvh - 56px - 60px); }
}

/* Note d'info dans la fiche produit (désactivation auto sur rupture) */
.pf-auto-note { font-size: 12.5px; color: var(--text-2); line-height: 1.45;
  background: var(--bg); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: 9px 11px; }

/* ── Champ mot de passe avec œil (login) ──────────────────────────────────── */
.pw-field { position: relative; }
.pw-field input { width: 100%; padding-right: 42px; }
.pw-toggle {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  background: none; border: none; cursor: pointer;
  color: var(--text-3); border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
}
.pw-toggle:hover { color: var(--text-2); }
.pw-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Auteur d'un mouvement de stock (vente) */
.move-by { color: var(--text-3); font-weight: 500; }

/* Création d'un produit à la volée (achat) */
.ac-create { color: var(--primary); font-weight: 600; }
.sl-new {
  font-size: 10.5px; font-weight: 600; letter-spacing: .2px;
  background: var(--primary-light); color: var(--primary);
  padding: 1px 7px; border-radius: 999px; margin-left: 4px;
}

/* ── Footer modal toujours horizontal (produit) ───────────────────────────── */
.modal-footer-row .modal-footer-right { display: flex; gap: 8px; }
@media (max-width: 640px) {
  .modal-footer-row { flex-direction: row !important; align-items: center; gap: 8px; padding: 12px 14px; flex-wrap: nowrap; }
  .modal-footer-row .modal-footer-right { width: auto; gap: 8px; }
  .modal-footer-row .modal-footer-right .btn { flex: 0 0 auto; width: auto; }
  .modal-footer-row > .btn-danger-ghost { width: auto; padding-left: 8px; padding-right: 8px; }
}

/* ── Toast (notification éphémère) ────────────────────────────────────────── */
.app-toast {
  position: fixed; left: 50%; bottom: 26px;
  transform: translateX(-50%) translateY(18px);
  z-index: 400; max-width: 90vw;
  background: #111827; color: #fff;
  padding: 11px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 500; text-align: center;
  box-shadow: 0 8px 28px rgba(0,0,0,.28);
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.app-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
@media (max-width: 640px) { .app-toast { bottom: calc(74px + env(safe-area-inset-bottom, 0px)); } }

/* ── Gestion utilisateurs (admin) ─────────────────────────────────────────── */
.tool-card { text-decoration: none; }
.users-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.users-loading { color: var(--text-3); font-size: 13px; padding: 10px 2px; }
.user-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.user-row-main { flex: 1; min-width: 0; }
.user-row-name { font-weight: 600; font-size: 14px; }
.user-you { font-size: 10.5px; font-weight: 600; background: var(--primary-light); color: var(--primary);
  padding: 1px 6px; border-radius: 999px; margin-left: 4px; }
.user-row-meta { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.user-role { font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: var(--bg); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.user-role.is-admin { background: var(--primary-light); color: var(--primary); border-color: transparent; }
.user-role-btn { cursor: pointer; font-family: var(--font); transition: filter .12s; }
.user-role-btn:hover { filter: brightness(1.08); border-color: var(--primary); }
.user-row-actions { display: flex; gap: 6px; }
.users-add { border-top: 1px solid var(--border); padding-top: 16px; }
.users-add-title { font-weight: 600; font-size: 13.5px; margin-bottom: 10px; }
.users-add-grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-bottom: 12px; }
@media (max-width: 640px) { .users-add-grid { grid-template-columns: 1fr; } }

/* ── Nom d'utilisateur coloré (vendeur / saisi par / mouvements / users) ───── */
.seller-name { font-weight: 600; }

/* ── Outils : Fichiers ────────────────────────────────────────────────────── */
.files-quota { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 12px; color: var(--text-3); }
.quota-track { width: 160px; height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.quota-bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s; }
.upload-progress { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.up-track { flex: 1; height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.up-bar { height: 100%; width: 0; background: var(--primary); border-radius: 999px; transition: width .15s; }
.up-label { font-size: 12.5px; color: var(--text-2); white-space: nowrap; }
.files-list { display: flex; flex-direction: column; gap: 8px; }
.file-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); }
.file-ic { display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 9px; background: var(--primary-light); color: var(--primary); }
.file-main { flex: 1; min-width: 0; }
.file-name { font-weight: 600; font-size: 14px; word-break: break-word; }
.file-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.file-share-badge { display: inline-flex; align-items: center; gap: 5px; background: var(--primary-light); color: var(--primary);
  padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.file-revoke { background: none; border: none; color: inherit; cursor: pointer; font-weight: 700; padding: 0 2px; opacity: .7; }
.file-revoke:hover { opacity: 1; }
.file-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.fs-filename { font-weight: 600; font-size: 14px; margin-bottom: 14px; word-break: break-word; }
.fs-link-row { display: flex; gap: 8px; }
.fs-link-row input { flex: 1; font-size: 13px; }
.fs-result-meta { font-size: 12.5px; color: var(--text-3); margin-top: 8px; }
@media (max-width: 640px) { .quota-track { width: 110px; } .file-row { flex-wrap: wrap; } .file-actions { width: 100%; justify-content: flex-end; } }

/* Modal de partage de fichier : rythme vertical aéré */
.fs-config .field { margin-bottom: 16px; }
.fs-config .fs-pw-label { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.fs-config #fs-pw { width: 100%; margin-bottom: 16px; letter-spacing: 6px; font-weight: 600; font-size: 16px; }
.fs-config .btn-full { width: 100%; }

/* Footer détail (vente/achat) : compact sur mobile (2 boutons / ligne, plus petits) */
@media (max-width: 640px) {
  .modal-footer-compact { flex-direction: row !important; flex-wrap: wrap; gap: 8px; padding: 12px 14px; justify-content: stretch; }
  .modal-footer-compact .modal-footer-spacer { display: none; }
  .modal-footer-compact .btn { flex: 1 1 calc(50% - 4px); width: auto; min-width: 0; padding: 10px 8px; font-size: 14px; }
  .modal-footer-compact .badge-ok { flex: 1 1 100%; text-align: center; }
}

/* Picto note sur une vente + note dans le détail */
.note-pin { display: inline-flex; align-items: center; color: var(--warning); margin-right: auto; }
.doc-note { flex-basis: 100%; margin-top: 2px; color: var(--text-2); }
.doc-note b { color: var(--warning); }

/* Verrou de défilement quand un modal/feuille est ouvert (anti-scroll d'arrière-plan iOS) */
body.modal-open { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }
.modal-body { overscroll-behavior: contain; }

/* Import catalogue (Excel/CSV) */
.import-hint { font-size: 13px; color: var(--text-2); margin: 0 0 14px; line-height: 1.5; }
.import-hint em { font-style: normal; color: var(--text); }
.import-template { display: inline-block; font-size: 13px; margin-bottom: 14px; color: var(--primary); text-decoration: none; }
.import-template:hover { text-decoration: underline; }
#import-file { display: block; width: 100%; font-size: 14px; padding: 8px 0; }
.import-result { margin-top: 16px; font-size: 14px; }
.imp-ok { color: #16a34a; font-weight: 700; }
.imp-err { color: var(--danger); margin-top: 8px; font-size: 13px; line-height: 1.5; }

/* Scan code-barres */
.scan-reader { width: 100%; max-width: 360px; margin: 0 auto 12px; border-radius: 12px; overflow: hidden; background: #000; min-height: 60px; }
.scan-reader video { width: 100% !important; height: auto !important; display: block; }
.scan-msg { color: var(--text-2); padding: 22px 16px; text-align: center; font-size: 14px; }
.scan-manual input { width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 16px; }
.scan-result { margin-top: 14px; }
.scan-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.scan-name { font-weight: 700; font-size: 16px; }
.scan-sub { color: var(--text-2); font-size: 14px; margin-top: 4px; }
.scan-sub b { color: var(--text); }
.scan-acts { display: flex; gap: 8px; margin-top: 14px; }
.scan-none { text-align: center; color: var(--text-2); padding: 16px; }

/* Scanner continu : modes, flash, panier */
.modal-scan-box { max-width: 460px; }
.scan-mode-seg { display: flex; gap: 4px; padding: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; }
.scan-mode-btn { flex: 1; padding: 8px 10px; border: none; background: none; color: var(--text-2); font-weight: 600; font-size: 14px; border-radius: 7px; cursor: pointer; font-family: var(--font); }
.scan-mode-btn.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.scan-flash { min-height: 0; transition: min-height .15s; }
.scan-flash.ok, .scan-flash.ko { min-height: 44px; display: flex; flex-direction: column; justify-content: center; padding: 8px 14px; border-radius: 10px; margin: 10px 0; animation: scanpop .25s ease; }
.scan-flash.ok { background: var(--success-light); color: var(--success); }
.scan-flash.ko { background: var(--danger-light); color: var(--danger); }
.scan-flash b { font-size: 14px; }
.scan-flash span { font-size: 12px; opacity: .85; }
@keyframes scanpop { from { transform: scale(.96); opacity: .4; } to { transform: scale(1); opacity: 1; } }
.scan-cart { display: flex; flex-direction: column; gap: 6px; max-height: 230px; overflow-y: auto; }
.scan-cart-empty { color: var(--text-3); text-align: center; font-size: 13px; padding: 14px; }
.scan-line { display: flex; align-items: center; gap: 10px; padding: 9px 11px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.scan-line-main { flex: 1; min-width: 0; }
.scan-line-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-line-sub { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.scan-qty { display: flex; align-items: center; gap: 4px; flex: none; }
.scan-qty-btn { width: 26px; height: 26px; border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: 7px; font-size: 16px; line-height: 1; cursor: pointer; }
.scan-qty-btn:hover { border-color: var(--primary); color: var(--primary); }
.scan-qty-n { min-width: 24px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.scan-qty-rm { width: 24px; height: 26px; border: none; background: none; color: var(--text-3); font-size: 17px; cursor: pointer; }
.scan-qty-rm:hover { color: var(--danger); }
.scan-foot { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.scan-foot-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 14px; color: var(--text-2); }
.scan-foot-row b { font-size: 17px; color: var(--text); }
.scan-dir-seg { display: flex; gap: 4px; padding: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; }
.scan-dir-btn { flex: 1; padding: 7px; border: none; background: none; color: var(--text-2); font-weight: 600; font-size: 13px; border-radius: 7px; cursor: pointer; font-family: var(--font); }
.scan-dir-btn.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

/* ── Commandes (cartes) ── */
.ord-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.ord-card.ord-new { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.ord-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ord-who { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ord-name { font-weight: 700; font-size: 15px; color: var(--text); }
.ord-phone { font-size: 13px; color: var(--primary); text-decoration: none; }
.ord-phone:hover { text-decoration: underline; }
.ord-status { flex: none; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; text-transform: uppercase; letter-spacing: .02em; }
.ord-st-new { background: var(--primary-light); color: var(--primary); }
.ord-st-seen { background: var(--bg); color: var(--text-3); border: 1px solid var(--border); }
.ord-st-converted { background: var(--success-light, #dcfce7); color: var(--success, #16a34a); }
.ord-meta { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.ord-lines { margin: 10px 0; border-top: 1px solid var(--border); }
.ord-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; color: var(--text); }
.ord-line-name { min-width: 0; }
.ord-qty { flex: none; font-weight: 700; color: var(--text-2); font-variant-numeric: tabular-nums; }
.ord-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ord-total { font-weight: 700; font-size: 16px; color: var(--text); }
.ord-actions { display: flex; align-items: center; gap: 8px; }
.ord-done-tag { font-size: 13px; color: var(--success, #16a34a); font-weight: 600; }
.btn-outline.danger { color: var(--danger); }
.btn-outline.danger:hover { border-color: var(--danger); background: var(--danger-light); }

.home-panel-total { float: right; color: var(--primary); font-weight: 700; }

/* ── Statistiques (refonte) ── */
.stats-head-actions { display: flex; align-items: center; gap: 8px; }
.stats-ratios { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 14px 0 4px; }
.ratio-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.ratio-label { font-size: 12px; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; }
.ratio-val { font-size: 20px; font-weight: 700; color: var(--text); margin-top: 4px; }
.stats-tables { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.stats-tcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stats-tcard h3 { font-size: 15px; margin-bottom: 10px; }
.st-head, .st-row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; }
.st-head { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.st-head span:first-child { text-align: left; }
.st-row { padding: 8px 0; border-bottom: 1px solid var(--border-light, var(--border)); font-size: 13.5px; }
.st-row:last-child { border-bottom: none; }
.st-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.st-q { color: var(--text-2); font-variant-numeric: tabular-nums; }
.st-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.stats-empty { color: var(--text-3); font-size: 13px; padding: 14px 0; }

/* ── Bandeau mode démo ── */
#demo-banner {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 14px; z-index: 300;
  display: flex; align-items: center; gap: 16px; max-width: calc(100% - 24px);
  padding: 10px 12px 10px 18px; border-radius: 999px;
  background: linear-gradient(135deg, #7c3aed, #2563eb); color: #fff;
  box-shadow: 0 12px 40px -10px rgba(124,58,237,.7); font-size: 13.5px;
}
#demo-banner b { font-weight: 700; }
#demo-banner a { flex: none; background: #fff; color: #2563eb; font-weight: 700; text-decoration: none;
  padding: 7px 14px; border-radius: 999px; font-size: 13px; white-space: nowrap; }
#demo-banner a:hover { filter: brightness(.97); }
#demo-banner .db-txt { min-width: 0; }
/* Mobile : rectangle compact AU-DESSUS de la barre de nav (plus de pilule géante). */
@media (max-width: 760px) {
  #demo-banner {
    left: 10px; right: 10px; transform: none; max-width: none;
    bottom: calc(64px + env(safe-area-inset-bottom));
    border-radius: 14px; padding: 10px 12px; gap: 10px; font-size: 12.5px;
  }
  #demo-banner .db-txt { flex: 1; line-height: 1.3; }
  #demo-banner a { padding: 8px 12px; font-size: 12.5px; }
}

/* ── Identité société (marque blanche) ── */
.brand-logo-row { display: flex; align-items: center; gap: 14px; }
.brand-logo-prev { width: 72px; height: 72px; flex: none; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.brand-logo-prev img { width: 100%; height: 100%; object-fit: contain; }
.brand-logo-ph { font-size: 11px; color: var(--text-3); text-align: center; padding: 4px; }
.brand-color-row { display: flex; align-items: center; gap: 12px; }
.brand-color-row input[type=color] { width: 52px; height: 38px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); cursor: pointer; }

/* Tableau de bord d'accueil */
.home-view { padding-top: 4px; }
.home-head h2 { margin: 0 0 14px; }
.home-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.home-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 22px; }
.hk { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.hk-label { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-2); }
.hk-val { font-size: 24px; font-weight: 800; color: var(--text); margin-top: 6px; font-variant-numeric: tabular-nums; }
.hk-rev { border-left-color: #3b82f6; } .hk-profit { border-left-color: #16a34a; }
.hk-sales { border-left-color: #8b5cf6; } .hk-warn { border-left-color: #f59e0b; } .hk-danger { border-left-color: #ef4444; }
.home-panels { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 800px) { .home-panels { grid-template-columns: 1fr; } }
.home-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.home-panel h3 { font-size: 14px; font-weight: 600; margin: 0 0 12px; }
.home-chart-box { height: 240px; position: relative; }
.home-top { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
.home-top li { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.home-top li b { font-variant-numeric: tabular-nums; }

/* Agenda & notes */
.agenda-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 820px) { .agenda-grid { grid-template-columns: 1fr; } }
.ag-list { display: flex; flex-direction: column; gap: 10px; }
.ag-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; transition: border-color .12s; }
.ag-card:hover { border-color: var(--text-3); }
.ag-date { font-size: 12px; font-weight: 600; color: var(--primary); text-transform: uppercase; letter-spacing: .3px; }
.ag-title { font-weight: 700; margin-top: 3px; }
.ag-meta { font-size: 13px; color: var(--text-2); margin-top: 3px; }
.ag-note { font-size: 13px; color: var(--text-2); margin-top: 5px; white-space: pre-wrap; }
.ag-by { font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* Agenda : assignation */
.ag-assign { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.ag-team { background: var(--primary-light); color: var(--primary); padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 11px; }

/* Agenda — calendrier interactif */
.cal-topbar { display:flex; align-items:center; gap:8px; margin-bottom:12px; flex-wrap:wrap; }
.cal-nav { width:32px; height:32px; border:1px solid var(--border); background:var(--surface); color:var(--text-2); border-radius:9px; cursor:pointer; font-size:18px; line-height:1; }
.cal-nav:hover { color:var(--text); border-color:var(--text-3); }
.cal-title { font-size:17px; margin:0 6px; min-width:160px; }
.cal-views { display:flex; border:1px solid var(--border); border-radius:9px; overflow:hidden; margin-left:auto; }
.cal-view { padding:6px 12px; background:var(--surface); color:var(--text-2); border:none; font:inherit; font-size:13px; cursor:pointer; }
.cal-view.active { background:var(--primary); color:#fff; }
.cal-legend { display:flex; gap:14px; flex-wrap:wrap; margin-bottom:10px; }
.cal-leg { display:flex; align-items:center; gap:6px; font-size:12px; color:var(--text-2); }
.cal-dot { width:9px; height:9px; border-radius:50%; }
.cal-dot.evt-client { background:#3b82f6; } .cal-dot.evt-internal { background:#8b5cf6; }
.cal-dot.evt-delivery { background:#16a34a; } .cal-dot.evt-other { background:#9ca3af; }
.calendar { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); overflow:hidden; }
.cal-dow { display:grid; grid-template-columns:repeat(7,1fr); background:var(--bg); border-bottom:1px solid var(--border); }
.cal-dow div { text-align:center; font-size:12px; font-weight:600; color:var(--text-2); padding:8px 0; }
.cal-grid { display:grid; grid-template-columns:repeat(7,1fr); }
.cal-cell { min-height:92px; border-right:1px solid var(--border-light); border-bottom:1px solid var(--border-light); padding:4px; display:flex; flex-direction:column; gap:2px; cursor:pointer; overflow:hidden; }
.cal-cell:hover { background:var(--bg); }
.cal-out { background:rgba(127,127,127,.05); }
.cal-out .cal-num { color:var(--text-3); }
.cal-num { align-self:flex-end; font-size:12px; font-weight:600; width:22px; height:22px; display:flex; align-items:center; justify-content:center; border-radius:50%; color:var(--text); }
.cal-today .cal-num { background:var(--primary); color:#fff; }
.cal-chip { display:block; width:100%; text-align:left; border:none; border-radius:4px; padding:2px 5px; font-size:11px; font-family:var(--font); cursor:pointer; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; color:#fff; }
.cal-chip b { opacity:.85; font-weight:600; margin-right:2px; }
.cal-chip.evt-client { background:#3b82f6; } .cal-chip.evt-internal { background:#8b5cf6; }
.cal-chip.evt-delivery { background:#16a34a; } .cal-chip.evt-other { background:#6b7280; }
.cal-more { font-size:10px; color:var(--text-3); padding-left:3px; }
.cal-week { display:grid; grid-template-columns:repeat(7,1fr); }
.cal-wcol { min-height:240px; border-right:1px solid var(--border-light); padding:6px; display:flex; flex-direction:column; gap:4px; cursor:pointer; }
.cal-wcol:hover { background:var(--bg); }
.cal-whead { display:flex; flex-direction:column; align-items:center; margin-bottom:4px; gap:2px; }
.cal-wdow { font-size:10px; text-transform:uppercase; color:var(--text-3); }
.cal-wempty { text-align:center; color:var(--text-3); margin-top:8px; }
.notes-section { margin-top:26px; }
@media (max-width:680px){ .cal-cell { min-height:66px; } .cal-title { min-width:0; font-size:15px; } .cal-chip { font-size:10px; } }

/* Agenda — sélection multiple de participants */
.ev-people { display:flex; flex-wrap:wrap; gap:8px; max-height:150px; overflow:auto; padding:2px; }
.ev-person { display:flex; align-items:center; gap:6px; font-size:13px; background:var(--bg); border:1px solid var(--border); border-radius:8px; padding:6px 10px; cursor:pointer; }
.ev-person input { width:16px; height:16px; cursor:pointer; }
.ev-person:hover { border-color:var(--text-3); }
.hint { font-size:12px; color:var(--text-3); margin-top:6px; }

/* Messagerie interne */
.msg-layout { display:grid; grid-template-columns:280px 1fr; gap:16px; height:calc(100dvh - 140px); }
@media (max-width:760px){ .msg-layout { grid-template-columns:1fr; height:auto; } .msg-main { min-height:60vh; } }
.msg-side { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); display:flex; flex-direction:column; overflow:hidden; }
.msg-side-head { display:flex; align-items:center; justify-content:space-between; padding:12px 14px; border-bottom:1px solid var(--border); }
.msg-side-head h2 { font-size:16px; margin:0; }
.conv-list { overflow-y:auto; flex:1; }
.conv-item { display:flex; align-items:center; gap:8px; width:100%; text-align:left; border:none; background:none; padding:11px 14px; border-bottom:1px solid var(--border-light); cursor:pointer; font-family:var(--font); }
.conv-item:hover { background:var(--bg); }
.conv-item.active { background:var(--primary-light); }
.conv-main { flex:1; min-width:0; }
.conv-name { font-weight:600; font-size:14px; color:var(--text); display:flex; align-items:center; gap:6px; }
.conv-item.has-unread .conv-name { font-weight:700; }
.conv-item.has-unread .conv-last { color:var(--text); font-weight:500; }
.conv-last { font-size:12.5px; color:var(--text-3); margin-top:2px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.conv-badge { flex:none; min-width:18px; height:18px; padding:0 5px; border-radius:9px; background:var(--primary); color:#fff; font-size:11px; font-weight:700; display:flex; align-items:center; justify-content:center; }

/* Pastille de présence en ligne / hors ligne */
.pdot { flex:none; width:8px; height:8px; border-radius:50%; display:inline-block; }
.pdot-on  { background:var(--success, #22c55e); box-shadow:0 0 0 2px color-mix(in srgb, var(--success, #22c55e) 28%, transparent); }
.pdot-off { background:var(--text-3); opacity:.5; }
.msg-thread-head .pdot { margin-right:6px; vertical-align:middle; }
.ev-person .pdot { margin-right:5px; }

/* Pastilles de non-lus sur la nav (Outils) et la tuile Messagerie */
.nav-badge { display:inline-flex; align-items:center; justify-content:center; min-width:17px; height:17px; padding:0 5px; margin-left:5px; border-radius:9px; background:var(--danger, #ef4444); color:#fff; font-size:10.5px; font-weight:700; vertical-align:middle; }
.tool-card { position:relative; }
.tool-badge { position:absolute; top:12px; right:12px; min-width:20px; height:20px; padding:0 6px; border-radius:10px; background:var(--danger, #ef4444); color:#fff; font-size:11px; font-weight:700; display:flex; align-items:center; justify-content:center; }
.conv-empty { color:var(--text-3); padding:20px; text-align:center; font-size:14px; }
.msg-main { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); display:flex; flex-direction:column; overflow:hidden; min-height:440px; }
.msg-thread-head { padding:13px 16px; border-bottom:1px solid var(--border); font-weight:600; }
.msg-scroll { flex:1; overflow-y:auto; padding:14px 16px; display:flex; flex-direction:column; gap:8px; }
.msg { max-width:72%; align-self:flex-start; }
.msg-mine { align-self:flex-end; text-align:right; }
.msg-sender { font-size:11px; margin-bottom:2px; }
.msg-bubble { display:inline-block; padding:8px 12px; border-radius:12px; background:var(--bg); border:1px solid var(--border); font-size:14px; white-space:pre-wrap; text-align:left; }
.msg-mine .msg-bubble { background:var(--primary); color:#fff; border-color:var(--primary); }
.msg-time { font-size:10px; color:var(--text-3); margin-top:2px; }
.msg-composer { display:flex; gap:8px; padding:12px; border-top:1px solid var(--border); }
.msg-composer input { flex:1; padding:10px 13px; border:1px solid var(--border); border-radius:var(--radius); background:var(--bg); color:var(--text); font-size:15px; }
