/* ════════════════════════════════════════════════════════════
   ERPValis — Design System v3
   Palette sable / teal foncé  ·  Fraunces + DM Sans + DM Mono
   ════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=DM+Mono:wght@400;500&family=Fraunces:wght@700;900&display=swap');

/* ── TOKENS ─────────────────────────────────────────────── */
:root {
  --sand:    #F5F0E8;
  --sand-d:  #EDE7D9;
  --white:   #FDFCFA;
  --ink:     #1C1917;
  --ink-2:   #57534E;
  --ink-3:   #A8A29E;
  --ink-4:   #D6D3D1;
  --bdr:     #E8E2D9;

  --teal:    #0D4F4F;
  --teal-m:  #0F6B6B;
  --teal-l:  #E0F0F0;

  --red:     #9B2335;
  --red-l:   #F9EAEC;
  --gold:    #92620A;
  --gold-l:  #FDF3DC;
  --blue:    #1B3A6B;
  --blue-l:  #EBF0F9;
  --green:   #065F46;
  --green-l: #D1FAE5;

  /* ── Alias legacy pour tout le PHP existant ── */
  --bg:             var(--sand);
  --surface:        var(--white);
  --surface2:       var(--sand-d);
  --border:         var(--bdr);
  --border-light:   var(--bdr);
  --text:           var(--ink);
  --text-secondary: var(--ink-2);
  --text-muted:     var(--ink-3);
  --primary:        var(--teal);
  --primary-dark:   var(--teal-m);
  --primary-light:  var(--teal-l);
  --success:        var(--green);
  --success-light:  var(--green-l);
  --warning:        var(--gold);
  --warning-light:  var(--gold-l);
  --danger:         var(--red);
  --danger-light:   var(--red-l);
  --info:           var(--blue);

  --topnav-h:  50px;
  --sidebar-w: 200px;
  --header-h:  50px;
  --radius:    9px;
  --radius-sm: 6px;
  --shadow:    0 1px 3px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.03);
  --shadow-lg: 0 6px 28px rgba(0,0,0,.1);
  --font:      'DM Sans', -apple-system, sans-serif;
  --serif:     'Fraunces', Georgia, serif;
  --mono:      'DM Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 13px; }
body {
  font-family: var(--font);
  background: var(--sand);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ════════════════════════════════════
   TOP NAV (barre noire en haut)
   ════════════════════════════════════ */
.topnav {
  height: var(--topnav-h);
  background: var(--ink);
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
}
.tn-brand {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 900;
  color: #fff;
  letter-spacing: -0.8px;
  white-space: nowrap;
  text-decoration: none;
}
.tn-company {
  font-size: 11px;
  color: #71717A;
  padding-left: 16px;
  flex: 1;
}
.tn-actions { display: flex; align-items: center; gap: 7px; }
.tn-btn {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.1);
  color: #E7E5E4;
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 11.5px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s;
  display: flex; align-items: center; gap: 5px;
  white-space: nowrap;
  text-decoration: none;
}
.tn-btn:hover { background: rgba(255,255,255,.14); color: #fff; }
.tn-btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.tn-btn.primary:hover { background: var(--teal-m); }
.tn-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal-m), var(--teal));
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  border: 2px solid rgba(255,255,255,.15);
  flex-shrink: 0;
  cursor: pointer;
}

/* ════════════════════════════════════
   LAYOUT SHELL
   ════════════════════════════════════ */
.app-layout {
  display: flex;
  min-height: 100vh;
  padding-top: var(--topnav-h);
}

/* ════════════════════════════════════
   SIDEBAR
   ════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--bdr);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: var(--topnav-h); left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand { padding: 14px 14px 10px; border-bottom: 1px solid var(--bdr); }
.sidebar-brand .logo { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.sidebar-brand .logo-icon {
  width: 28px; height: 28px;
  background: var(--teal);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif);
  font-size: 13px; font-weight: 900; color: #fff;
  flex-shrink: 0;
}
.sidebar-brand .logo-text { font-family: var(--serif); font-weight: 700; font-size: 13px; color: var(--ink); letter-spacing: -.3px; }
.sidebar-brand .logo-sub  { font-size: 10px; color: var(--ink-3); }

.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-section { margin-bottom: 2px; }
.nav-section-title {
  font-size: 9px; font-weight: 600;
  letter-spacing: 1px; text-transform: uppercase;
  color: var(--ink-3); padding: 6px 14px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  color: var(--ink-2); text-decoration: none;
  font-size: 12px; font-weight: 500;
  transition: all .12s;
  border-left: 2px solid transparent;
  cursor: pointer;
  /* reset button styles */
  border-top: none; border-right: none; border-bottom: none;
  background: none; width: 100%; text-align: left;
  font-family: var(--font);
}
.nav-item:hover  { background: var(--sand); color: var(--ink); }
.nav-item.active { background: var(--teal-l); color: var(--teal); font-weight: 600; border-left-color: var(--teal); }
.nav-icon { width: 13px; height: 13px; opacity: .6; flex-shrink: 0; }
.nav-item.active .nav-icon { opacity: 1; }
.nav-badge {
  margin-left: auto;
  background: var(--red); color: #fff;
  font-size: 9px; font-weight: 700;
  padding: 1px 5px; border-radius: 8px;
  min-width: 16px; text-align: center;
}

.sidebar-footer { padding: 10px 14px; border-top: 1px solid var(--bdr); }
.sidebar-user   { display: flex; align-items: center; gap: 9px; }
.sidebar-user .avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal-m), var(--teal));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 10px; font-weight: 700; flex-shrink: 0;
}
.sidebar-user .user-info .name    { font-size: 12px; font-weight: 600; color: var(--ink); }
.sidebar-user .user-info .company { font-size: 10px; color: var(--ink-3); }

/* ════════════════════════════════════
   MAIN CONTENT
   ════════════════════════════════════ */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--topnav-h));
}

.top-bar {
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--bdr);
  display: flex; align-items: center;
  padding: 0 22px;
  position: sticky;
  top: var(--topnav-h);
  z-index: 50;
  gap: 14px; flex-shrink: 0;
}
.top-bar-title {
  font-family: var(--serif);
  font-size: 18px; font-weight: 900;
  color: var(--ink); letter-spacing: -.5px; flex: 1;
}
.top-bar-actions { display: flex; gap: 7px; align-items: center; }

.page-content { padding: 20px 22px; flex: 1; }

/* ════════════════════════════════════
   CARDS
   ════════════════════════════════════ */
.card { background: var(--white); border: 1px solid var(--bdr); border-radius: var(--radius); }
.card-header {
  padding: 13px 18px; border-bottom: 1px solid var(--bdr);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--ink); }
.card-body  { padding: 18px; }

/* ════════════════════════════════════
   STAT CARDS
   ════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.stat-card {
  background: var(--white); border: 1px solid var(--bdr); border-radius: var(--radius);
  padding: 15px 17px; position: relative; overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 5px 16px rgba(0,0,0,.06); }
.stat-card::before {
  content: ''; position: absolute;
  bottom: 0; left: 0; right: 0; height: 2.5px;
}
.stat-card.primary::before { background: var(--teal); }
.stat-card.success::before { background: var(--green); }
.stat-card.warning::before { background: var(--gold); }
.stat-card.danger::before  { background: var(--red); }

.stat-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-3); margin-bottom: 8px; }
.stat-value { font-size: 20px; font-weight: 500; letter-spacing: -1px; color: var(--ink); font-family: var(--mono); line-height: 1; }
.stat-sub   { font-size: 10.5px; color: var(--ink-3); margin-top: 5px; }
.stat-icon  { position: absolute; top: 14px; right: 14px; opacity: .07; font-size: 28px; }

/* ════════════════════════════════════
   TABLES
   ════════════════════════════════════ */
.table-wrapper { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table thead th {
  padding: 8px 13px; text-align: left;
  font-weight: 700; font-size: 9.5px;
  text-transform: uppercase; letter-spacing: .6px;
  color: var(--ink-3); background: var(--sand);
  border-bottom: 1px solid var(--bdr);
  white-space: nowrap; user-select: none; cursor: pointer;
}
.data-table thead th:hover { color: var(--ink); }
.data-table tbody tr { border-bottom: 1px solid var(--bdr); transition: background .1s; cursor: pointer; }
.data-table tbody tr:hover    { background: var(--sand); }
.data-table tbody tr.selected { background: var(--teal-l); }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table td { padding: 9px 13px; color: var(--ink); }
.data-table tfoot td { padding: 9px 13px; font-weight: 700; background: var(--sand); border-top: 1px solid var(--bdr); font-size: 12px; }
.data-table .num    { font-family: var(--mono); font-size: 11.5px; }
.data-table .amount { font-family: var(--mono); text-align: right; }
.data-table .actions { text-align: right; white-space: nowrap; }

/* ════════════════════════════════════
   BADGES / STATUS
   ════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: .2px;
}
.status-draft     { background: var(--sand-d);  color: var(--ink-2); }
.status-sent      { background: var(--blue-l);  color: var(--blue); }
.status-accepted  { background: var(--green-l); color: var(--green); }
.status-refused   { background: var(--red-l);   color: var(--red); }
.status-invoiced  { background: var(--green-l); color: var(--green); }
.status-paid      { background: var(--green-l); color: var(--green); }
.status-partial   { background: var(--gold-l);  color: var(--gold); }
.status-cancelled { background: var(--sand-d);  color: var(--ink-3); }
.badge-unfactured { background: var(--red-l);   color: var(--red); }
.badge-factured   { background: var(--green-l); color: var(--green); }

/* ════════════════════════════════════
   BUTTONS
   ════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 13px; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 12px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--bdr);
  background: var(--white); color: var(--ink-2);
  transition: all .15s; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary   { background: var(--teal);  color: #fff; border-color: var(--teal); }
.btn-primary:hover  { background: var(--teal-m); border-color: var(--teal-m); }
.btn-secondary { background: var(--white); color: var(--ink-2); border-color: var(--bdr); }
.btn-secondary:hover { background: var(--sand); }
.btn-success   { background: var(--green); color: #fff; border-color: var(--green); }
.btn-success:hover  { background: #047857; }
.btn-danger    { background: var(--red);   color: #fff; border-color: var(--red); }
.btn-danger:hover   { opacity: .88; }
.btn-warning   { background: var(--gold);  color: #fff; border-color: var(--gold); }
.btn-warning:hover  { opacity: .88; }
.btn-sm  { padding: 4px 10px; font-size: 11.5px;  display:inline-flex; align-items:center; gap:5px; }
.btn-xs  { padding: 2px 7px;  font-size: 11px; }
.btn-icon { padding: 6px; }

/* ════════════════════════════════════
   FORMS
   ════════════════════════════════════ */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 11px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.form-control {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--bdr); border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 12.5px;
  color: var(--ink); background: var(--white);
  transition: border-color .15s; outline: none;
}
.form-control:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13,79,79,.08); }
.form-control::placeholder { color: var(--ink-3); }
select.form-control { cursor: pointer; }
.form-row   { display: grid; gap: 14px; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* ════════════════════════════════════
   SEARCH BAR
   ════════════════════════════════════ */
.search-bar {
  display: flex; align-items: center; gap: 4px;
  background: var(--sand); border: 1px solid var(--bdr);
  border-radius: var(--radius-sm); padding: 5px 10px;
  flex: 1; max-width: 320px;
}
.search-bar input { border: none; background: none; outline: none; font-family: var(--font); font-size: 12.5px; color: var(--ink); flex: 1; }
.search-bar svg { color: var(--ink-3); flex-shrink: 0; }

/* ════════════════════════════════════
   MODALS
   ════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.32); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; backdrop-filter: blur(3px);
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 680px; max-height: 90vh;
  display: flex; flex-direction: column;
  animation: slideUp .2s ease;
}
.modal-xl { max-width: 1100px; }
.modal-sm { max-width: 440px; }
.modal-header {
  padding: 14px 18px; border-bottom: 1px solid var(--bdr);
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.modal-title { font-family: var(--serif); font-size: 16px; font-weight: 900; letter-spacing: -.3px; color: var(--ink); }
.modal-body   { padding: 18px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--bdr); display: flex; justify-content: flex-end; gap: 7px; flex-shrink: 0; }
.modal-close  { background: none; border: none; cursor: pointer; color: var(--ink-3); padding: 3px; display: flex; align-items: center; border-radius: 4px; }
.modal-close:hover { color: var(--ink); background: var(--sand); }

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

/* ════════════════════════════════════
   LINES TABLE (lignes document)
   ════════════════════════════════════ */
.lines-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.lines-table th {
  padding: 7px 9px; text-align: left;
  font-size: 9.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--ink-3); background: var(--sand); border-bottom: 1px solid var(--bdr);
}
.lines-table td { padding: 5px 7px; border-bottom: 1px solid var(--bdr); vertical-align: middle; }
.lines-table td input, .lines-table td select {
  width: 100%; padding: 4px 7px;
  border: 1px solid transparent; border-radius: 4px;
  font-family: var(--font); font-size: 12px;
  background: transparent; outline: none; transition: all .1s;
}
.lines-table td input:focus, .lines-table td select:focus {
  background: var(--white); border-color: var(--teal); box-shadow: 0 0 0 2px rgba(13,79,79,.08);
}
.lines-table .col-ref      { width: 90px; }
.lines-table .col-desc     { min-width: 200px; }
.lines-table .col-qty      { width: 80px; }
.lines-table .col-unit     { width: 60px; }
.lines-table .col-price    { width: 100px; }
.lines-table .col-tva      { width: 70px; }
.lines-table .col-discount { width: 70px; }
.lines-table .col-total    { width: 110px; text-align: right; font-family: var(--mono); }
.lines-table .col-lot      { width: 110px; }
.lines-table .col-del      { width: 40px; text-align: center; }
.lines-table .line-total   { font-family: var(--mono); text-align: right; font-weight: 500; }
.lines-table .btn-del-line { background: none; border: none; color: var(--ink-3); cursor: pointer; padding: 4px; border-radius: 4px; display: flex; }
.lines-table .btn-del-line:hover { color: var(--red); background: var(--red-l); }

/* ════════════════════════════════════
   TOTALS BLOCK
   ════════════════════════════════════ */
.totals-block { margin-top: 8px; margin-left: auto; width: 300px; }
.totals-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13px; border-bottom: 1px solid var(--bdr); }
.totals-row:last-child  { border-bottom: none; }
.totals-row.total-final { font-size: 15px; font-weight: 700; padding-top: 9px; }
.totals-row .amount { font-family: var(--mono); }

/* ════════════════════════════════════
   SPLIT LAYOUT
   ════════════════════════════════════ */
.split-layout {
  display: grid; grid-template-columns: 300px 1fr; gap: 16px;
  height: calc(100vh - var(--topnav-h) - var(--header-h) - 40px);
  overflow: hidden;
}
.split-list   { overflow-y: auto; }
.split-detail { overflow-y: auto; }

/* ════════════════════════════════════
   TABS
   ════════════════════════════════════ */
.tabs { display: flex; border-bottom: 1px solid var(--bdr); margin-bottom: 18px; }
.tab {
  padding: 8px 16px; font-size: 12.5px; font-weight: 500;
  color: var(--ink-2); cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: all .15s;
  text-decoration: none; white-space: nowrap;
}
.tab:hover  { color: var(--ink); }
.tab.active { color: var(--teal); border-bottom-color: var(--teal); font-weight: 600; }

/* ════════════════════════════════════
   ALERTS
   ════════════════════════════════════ */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 14px; display: flex; align-items: flex-start; gap: 9px; }
.alert-success { background: var(--green-l); color: var(--green); border: 1px solid #A7F3D0; }
.alert-danger  { background: var(--red-l);   color: var(--red);   border: 1px solid #EFC6CB; }
.alert-warning { background: var(--gold-l);  color: var(--gold);  border: 1px solid #F0D090; }
.alert-info    { background: var(--teal-l);  color: var(--teal);  border: 1px solid #A8D4D4; }

/* ════════════════════════════════════
   PAGINATION
   ════════════════════════════════════ */
.pagination { display: flex; align-items: center; gap: 4px; padding: 12px 18px; border-top: 1px solid var(--bdr); }
.page-btn {
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--bdr); border-radius: var(--radius-sm);
  background: var(--white); color: var(--ink-2); cursor: pointer; font-size: 12.5px; transition: all .1s;
}
.page-btn:hover  { background: var(--sand); }
.page-btn.active { background: var(--teal); color: #fff; border-color: var(--teal); }

/* ════════════════════════════════════
   EMPTY STATE
   ════════════════════════════════════ */
.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-3); }
.empty-state svg { opacity: .2; margin-bottom: 12px; }
.empty-state p   { font-size: 13px; }

/* ════════════════════════════════════
   PAYMENTS
   ════════════════════════════════════ */
.payment-list .payment-item { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--bdr); }
.payment-item:last-child { border-bottom: none; }
.payment-method-icon { width: 30px; height: 30px; background: var(--teal-l); color: var(--teal); border-radius: 7px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.payment-item .amount { font-family: var(--mono); font-weight: 600; margin-left: auto; }

/* ════════════════════════════════════
   DOCUMENT HEADER
   ════════════════════════════════════ */
.doc-header-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.doc-client-block { border: 1px solid var(--bdr); border-radius: var(--radius-sm); padding: 12px; min-height: 90px; background: var(--sand); }
.doc-client-block .client-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.doc-client-block .client-addr { font-size: 11.5px; color: var(--ink-2); line-height: 1.6; }

/* ════════════════════════════════════
   LOGIN PAGE
   ════════════════════════════════════ */
.login-page { min-height: 100vh; background: var(--sand); display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--white); border: 1px solid var(--bdr); border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,.08);
  padding: 40px 36px; width: 100%; max-width: 400px;
}
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; }
.login-logo .icon {
  width: 40px; height: 40px; background: var(--teal);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 18px; font-weight: 900; color: #fff; flex-shrink: 0;
}
.login-logo .title    { font-family: var(--serif); font-size: 19px; font-weight: 900; letter-spacing: -.5px; color: var(--ink); }
.login-logo .subtitle { font-size: 11.5px; color: var(--ink-3); }
.login-card h2 { font-family: var(--serif); font-size: 20px; font-weight: 900; color: var(--ink); letter-spacing: -.5px; margin-bottom: 6px; }
.login-card .subtitle { color: var(--ink-3); font-size: 12.5px; margin-bottom: 28px; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 9px; font-size: 13px; }
.login-footer { margin-top: 20px; text-align: center; font-size: 11.5px; color: var(--ink-3); }

/* ════════════════════════════════════
   CHART
   ════════════════════════════════════ */
.chart-container { position: relative; }

/* ════════════════════════════════════
   UTILITIES
   ════════════════════════════════════ */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.font-mono   { font-family: var(--mono); }
.text-muted  { color: var(--ink-3); }
.text-small  { font-size: 11.5px; }
.flex        { display: flex; }
.flex-1      { flex: 1; }
.items-center { align-items: center; }
.gap-2       { gap: 8px; }
.gap-3       { gap: 12px; }
.mb-3        { margin-bottom: 12px; }
.mb-4        { margin-bottom: 16px; }
.mt-3        { margin-top: 12px; }
.d-none      { display: none; }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--bdr); border-top-color: var(--teal);
  border-radius: 50%; animation: spin .6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ════════════════════════════════════
   TOAST
   ════════════════════════════════════ */
#toast-container { position: fixed; bottom: 22px; right: 22px; z-index: 9999; display: flex; flex-direction: column; gap: 7px; }
.toast {
  background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 12.5px; box-shadow: var(--shadow-lg);
  animation: slideUp .2s ease; max-width: 320px;
}
.toast.toast-success { background: var(--green); }
.toast.toast-error   { background: var(--red); }
.toast.toast-warning { background: var(--gold); }


/* ════════════════════════════════════
   DASHBOARD GRIDS
   ════════════════════════════════════ */
.dash-grid-main { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; min-width: 0; overflow: hidden; }
.dash-grid-half { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; }

/* ════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════ */
/* ════════════════════════════════════
   HAMBURGER BUTTON
   ════════════════════════════════════ */
.tn-hamburger {
  display: none;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 7px 9px;
  border-radius: 6px;
  transition: background .15s;
  flex-shrink: 0;
  line-height: 0;
  margin-right: 4px;
}
.tn-hamburger:hover { background: rgba(255,255,255,.12); }

/* ════════════════════════════════════
   TABLET — ≤ 1024px
   ════════════════════════════════════ */
@media (max-width: 1024px) {

  /* Hamburger */
  .tn-hamburger { display: flex; align-items: center; justify-content: center; }

  /* Sidebar off-canvas */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    z-index: 200;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0,0,0,.2);
  }

  /* Main content plein écran */
  .main-content { margin-left: 0; }

  /* Topnav */
  .tn-company { display: none; }

  /* Grilles desktop → colonne */
  .split-layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }
  .split-list, .split-detail { overflow-y: visible; max-height: none; }

  /* Sur tablette : list en haut, detail en bas */
  .split-list { max-height: 45vh; overflow-y: auto; }

  .doc-header-grid { grid-template-columns: 1fr 1fr; }

  /* Stats 2 colonnes */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* Tables : scroll horizontal */
  .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .lines-table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Modals plus larges que la fenêtre → plein écran */
  .modal { max-width: 94vw; }
  .modal-xl { max-width: 96vw; }

  /* form-row-3 et form-row-4 → 2 colonnes */
  .form-row-3 { grid-template-columns: 1fr 1fr; }
  .form-row-4 { grid-template-columns: 1fr 1fr; }

  /* Totals block pleine largeur */
  .totals-block { width: 100%; }

  /* Dashboard grid */
  .dash-grid-main,
  div[style*="grid-template-columns:2fr 1fr"],
  div[style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  .dash-grid-half,
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* ════════════════════════════════════
   MOBILE — ≤ 700px
   ════════════════════════════════════ */
@media (max-width: 700px) {

  /* Topnav */
  .topnav { padding: 0 12px; gap: 6px; }
  .tn-brand { font-size: 13px; }
  .tn-btn:not(.primary) { display: none; }
  .tn-btn.primary { padding: 4px 9px; font-size: 11px; }

  /* Page content */
  .page-content { padding: 12px; }
  .top-bar { padding: 0 14px; }
  .top-bar-title { font-size: 15px; }
  .top-bar-actions { gap: 5px; }

  /* Split layout : empilé verticalement, pas de hauteur fixe */
  .split-layout {
    grid-template-columns: 1fr;
    height: auto;
    gap: 10px;
  }
  .split-list {
    max-height: 40vh;
    overflow-y: auto;
    border-bottom: 1px solid var(--bdr);
  }
  .split-detail { overflow-y: visible; }

  /* Filtres : colonne */
  .filters-bar {
    flex-direction: column;
    gap: 8px;
    align-items: stretch !important;
  }
  .filters-bar .search-bar { max-width: 100%; }
  .filters-bar select,
  .filters-bar .btn { width: 100%; justify-content: center; }

  /* Doc header : 1 colonne */
  .doc-header-grid { grid-template-columns: 1fr; }

  /* Lines table : scroll horizontal forcé */
  .lines-table-wrapper,
  .lines-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .lines-table th, .lines-table td { white-space: nowrap; }
  .col-desc { min-width: 140px !important; }

  /* Stats : 1 colonne */
  .stats-grid { grid-template-columns: 1fr; }

  /* Grilles inline → 1 colonne */
  .form-row-2,
  .form-row-3,
  .form-row-4 { grid-template-columns: 1fr; }

  /* Modals plein écran mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100vw;
    width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
  }
  .modal-xl, .modal-sm { max-width: 100%; }

  /* Email modal : panneau côte à côte → colonne */
  .modal .modal-body[style*="flex"] {
    flex-direction: column !important;
  }
  .modal .modal-body > div[style*="border-right"] {
    border-right: none !important;
    border-bottom: 1px solid var(--bdr);
  }

  /* Totals */
  .totals-block { width: 100%; }

  /* Buttons dans detail actions : wrap */
  .detail-actions {
    flex-wrap: wrap;
    gap: 5px;
  }

  /* Boutons petits sur mobile */
  .btn-sm { padding: 5px 9px; font-size: 11px; }

  /* Tables mobiles : scroll horizontal */
  .table-wrapper,
  .lines-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Réduire padding des cellules */
  .data-table td, .data-table th { padding: 7px 9px; font-size: 11.5px; }
  /* Cacher colonnes secondaires sur petits écrans */
  .data-table .hide-mobile { display: none; }

  /* Dashboard grids → 1 colonne */
  .dash-grid-main,
  .dash-grid-half,
  div[style*="grid-template-columns:2fr 1fr"],
  div[style*="grid-template-columns: 2fr 1fr"],
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Toast */
  #toast-container { right: 10px; left: 10px; bottom: 14px; }
  .toast { max-width: 100%; }

  /* Payment progress */
  .pay-progress-bar { height: 6px; }

  /* Settings tabs : scroll horizontal */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tab { flex-shrink: 0; }
}

/* ════════════════════════════════════
   SMALL MOBILE — ≤ 420px
   ════════════════════════════════════ */
@media (max-width: 420px) {
  html { font-size: 12px; }
  .tn-brand { font-size: 12px; }
  .tn-btn.primary { display: none; }
  .top-bar-title { font-size: 14px; }
  .stat-value { font-size: 17px; }
  .page-content { padding: 10px; }
  .card-body { padding: 12px; }
  .modal-header { padding: 12px 14px; }
  .modal-body   { padding: 12px 14px; }
  .modal-footer { padding: 10px 14px; }
}
