:root {
  --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: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.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[type="text"], input[type="email"], input[type="tel"],
input[type="number"], input[type="date"], input[type="password"],
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; }

/* 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); }

/* ── 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"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2d3142;
  --border-light: #252836;
  --text: #f1f5f9;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #1e2d4a;
  --danger: #ef4444;
  --danger-light: #2d1515;
  --success: #22c55e;
  --success-light: #0f2d1c;
  --warning: #f59e0b;
  --warning-light: #2d2010;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.5);
}

[data-theme="dark"] .login-screen {
  background: linear-gradient(135deg, #0a1229 0%, #1a2d6b 100%);
}

/* ── 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 { color: var(--primary); }
  .bnav-btn:active { opacity: .7; }

  /* 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"],
  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; }
}
