/* ============================================================
   FiscalBot CI — Stylesheet Principal v3
   Style « registre » : l'interface reste à l'encre, le violet de la marque
   ne marque que les données principales et la marque du produit.
   ============================================================ */

:root {
  /* Couleurs du logo : le vert marque le produit et les données, l'orange l'action principale */
  --primary:            #0F4A22;
  --primary-light:      #E7F0EA;
  --primary-dark:       #0B3A1A;
  --accent:             #F06800;   /* orange du logo : texte à l'encre dessus (5.5:1) */
  --accent-hover:       #D95E00;
  --success:            #247B50;
  --warning:            #B45309;

  /* Surfaces et encres */
  --bg-page:            #F0F2F5;   /* fond bleu-gris de registre */
  --bg-card:            #FFFFFF;
  --surface-raised:     #F6F7F9;
  --active:             #E2E5EA;   /* pastille de navigation active */
  --border:             #E3E6EA;
  --rule:               #EEF0F3;
  --control:            #D1D5DB;
  --text-main:          #1A1A2E;
  --text-muted:         #5F6368;   /* 4.5:1 sur blanc et sur le fond */
  --ink-button:         #1D1F20;

  --sidebar-width:      240px;
  --topbar-height:      56px;
  --navbar-height:      56px;      /* alias historique utilisé par chat-wrapper */
  --border-radius-card: 8px;
  --radius-control:     6px;
  --radius-chip:        4px;
  --shadow-card:        none;
  --font-family:        'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Bootstrap aligné sur ces jetons */
  --bs-body-font-family: var(--font-family);
  --bs-body-color:       var(--text-main);
  --bs-body-bg:          var(--bg-card);   /* cartes, champs, menus ; le fond de page est posé sur body */
  --bs-secondary-color:  var(--text-muted);
  --bs-border-color:     var(--border);
  --bs-border-radius:    var(--radius-control);
  --bs-link-color:       var(--text-main);
  --bs-link-color-rgb:   26, 26, 46;
  --bs-link-hover-color: #000;
  --bs-link-hover-color-rgb: 0, 0, 0;
  --bs-code-color:       var(--text-main);
}

/* Sur ordinateur, pas de barre du haut : le titre de page est le h1 du canevas */
@media (min-width: 992px) {
  :root { --topbar-height: 0px; --navbar-height: 0px; }
}

* { box-sizing: border-box; }
p { text-wrap: pretty; }
h1, h2, h3, h4, h5, h6, .card-title { text-wrap: balance; }
::selection { background: #CFE3D5; color: var(--text-main); }
input, textarea { caret-color: var(--accent); }

body {
  font-family: var(--font-family);
  background: var(--bg-page);
  color: var(--text-main);
  margin: 0;
  padding: 0;
}

/* ============================================================
   APP LAYOUT — SIDEBAR
   ============================================================ */
.app-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-page);
  border-right: 1px solid var(--border);
  z-index: 1050;
  overflow-y: auto;
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 20px 16px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.sidebar-brand img { height: 36px; width: 36px; object-fit: contain; border-radius: var(--radius-control); flex-shrink: 0; }
.sidebar-brand-name { font-weight: 700; font-size: 15px; line-height: 1.2; color: var(--text-main); }
.sidebar-brand-tag { font-size: 12px; line-height: 1.35; color: var(--text-muted); }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1040;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s, visibility 0.3s;
}
.sidebar-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ============================================================
   APP LAYOUT — TOP BAR (téléphone et tablette uniquement)
   ============================================================ */
.app-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-page);
  border-bottom: 1px solid var(--border);
  z-index: 1030;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.topbar-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ============================================================
   APP LAYOUT — MAIN CONTENT
   ============================================================ */
.app-main {
  margin-left: var(--sidebar-width);
  padding-top: var(--topbar-height);
  background: var(--bg-page);
  min-height: 100vh;
}

/* ============================================================
   APP LAYOUT — BOTTOM NAV (mobile only, shown via responsive)
   ============================================================ */
.app-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: none;
  height: 60px;
  padding: 0 12px;
  z-index: 1020;
}

/* ============================================================
   SIDEBAR COMPONENTS
   ============================================================ */
.sidebar-user {
  padding: 8px 16px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--active);
  color: var(--text-main);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.sidebar-user-name { font-weight: 600; font-size: 14px; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 12px; color: var(--text-muted); }

.sidebar-nav { padding: 4px 0; flex: 1; overflow-y: auto; }
.sidebar-foot { padding: 8px 0 12px; flex-shrink: 0; }

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  margin: 0 8px 2px;
  padding: 0 10px;
  border-radius: 8px;
  text-decoration: none;
  color: #3C4043;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  font-size: 14px;
  font-weight: 400;
  border: none;
  background: none;
  width: calc(100% - 16px);
}

.sidebar-nav-item:hover {
  background: #E8EBEF;
  color: var(--text-main);
  text-decoration: none;
}

.sidebar-nav-item.active {
  background: var(--active);
  color: var(--text-main);
  font-weight: 500;
}

.sidebar-nav-item i {
  font-size: 16px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  color: var(--text-muted);
}

.sidebar-nav-item.active i { color: var(--text-main); }

.sidebar-nav-item:focus-visible,
.bottom-nav-item:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* ============================================================
   TOPBAR COMPONENTS
   ============================================================ */
.topbar-hamburger {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-main);
  flex-shrink: 0;
  line-height: 1;
}

.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--active);
  color: var(--text-main);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  text-decoration: none;
  border: none;
}

/* ============================================================
   BOTTOM NAV COMPONENTS
   ============================================================ */
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  border: none;
  background: none;
  padding: 6px 4px;
  transition: color 0.15s;
}

.bottom-nav-item.active { color: var(--text-main); font-weight: 600; }
.bottom-nav-item i { font-size: 20px; }

/* ============================================================
   PAGE TITLE — un h1 par écran, à taille d'application
   ============================================================ */
.app-main h1 {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

/* Les en-têtes de page (titre + actions) passent à la ligne au lieu d'écraser le titre */
.app-main .d-flex:has(> div > h1, > h1) { flex-wrap: wrap; gap: 12px; }

.app-main h1 .bi,
.app-main h2 .bi,
.app-main h3 .bi,
.app-main h4 .bi,
.app-main h5 .bi,
.app-main h6 .bi,
.card-header .bi {
  color: var(--text-muted) !important;
  font-size: 0.9em;
}

/* ============================================================
   KPI CARDS (ex-« gradient cards ») — un libellé et un chiffre
   ============================================================ */
.gradient-card {
  border-radius: var(--border-radius-card);
  padding: 20px;
  color: var(--text-main);
  background: var(--bg-card);
  border: 1px solid var(--border);
  height: 100%;
}

.gradient-card .card-icon { display: none; }

.gradient-card .card-value {
  font-size: 28px;
  font-weight: 600;
  margin-top: 6px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.gradient-card .card-label {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

.gradient-card .card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ============================================================
   SMALL STAT CARDS
   ============================================================ */
.stat-card-sm {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-card);
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.stat-card-sm .stat-icon-box { display: none; }

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header { margin-bottom: 24px; }

.page-header h1,
.page-header h2 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-main);
  margin: 0;
}

.page-header p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
  margin-bottom: 0;
}

/* ============================================================
   PERIOD PILL — contrôle segmenté
   ============================================================ */
.period-pill {
  display: inline-flex;
  gap: 2px;
  background: var(--active);
  border-radius: 8px;
  padding: 3px;
}

.period-pill button {
  border: none;
  background: none;
  height: 28px;
  padding: 0 14px;
  border-radius: var(--radius-control);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.period-pill button:hover { color: var(--text-main); }

.period-pill button.active {
  background: var(--bg-card);
  color: var(--text-main);
}

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-body {
  background: var(--primary-dark);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.auth-container { width: 100%; max-width: 460px; }

.auth-card {
  border-radius: 12px;
  overflow: hidden;
  border: none !important;
}

.auth-logo-img {
  width: 200px;
  height: auto;
  display: block;
  margin: 0 auto 0.5rem;
  border-radius: 12px;
}

.auth-title { font-size: 22px; font-weight: 600; margin: 0 0 20px; color: var(--text-main); }
.auth-body .text-white-50, .auth-body .opacity-75 { color: rgba(255,255,255,0.88) !important; opacity: 1 !important; }

.auth-byline {
  color: rgba(255,255,255,0.92);
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 1rem;
}

/* ============================================================
   CHAT
   ============================================================ */
.chat-wrapper {
  display: flex;
  height: calc(100vh - var(--topbar-height));
  overflow: hidden;
}

.chat-sidebar {
  width: 280px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.chat-sidebar-header {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-conv-list {
  overflow-y: auto;
  flex: 1;
  padding: 0 8px 8px;
}

.conv-item {
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.conv-item:hover { background: var(--surface-raised); }
.conv-item.active { background: var(--active); }

.conv-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.conv-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 12px;
}

.btn-delete-conv { opacity: 0; transition: opacity 0.15s; }
.conv-item:hover .btn-delete-conv,
.btn-delete-conv:focus-visible { opacity: 1; }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-page);
}

.chat-header {
  padding: 10px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-main h1.chat-title { font-size: 16px; font-weight: 600; margin: 0; line-height: 1.3; }

/* Marque du produit : le robot, en violet plein */
.ai-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.welcome-screen {
  max-width: 640px;
  margin: auto;
  text-align: center;
  padding: 32px 16px;
}

.welcome-icon {
  width: 72px; height: 72px;
  border-radius: 12px;
  object-fit: cover;
  display: block;
  margin: 0 auto 20px;
}

.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  text-align: left;
}

.suggestion-btn {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-main);
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
}

.suggestion-btn:hover,
.suggestion-btn:focus-visible {
  border-color: var(--text-main);
  background: var(--surface-raised);
}

/* Messages */
.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 85%;
}

.message-row.message-user {
  flex-direction: row-reverse;
  margin-left: auto;
}

.message-row.message-assistant { margin-right: auto; }

.msg-avatar {
  flex-shrink: 0;
  margin-bottom: 4px;
}

.ai-avatar-sm {
  width: 28px; height: 28px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
  color: white;
}

.user-avatar-sm {
  width: 28px; height: 28px;
  background: var(--active);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
}

.message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: 12px;
  max-width: 100%;
}

.message-row.message-user .message-bubble {
  background: var(--active);
  border-color: var(--active);
  color: var(--text-main);
  border-radius: 12px 12px 4px 12px;
}

.message-row.message-assistant .message-bubble {
  border-radius: 12px 12px 12px 4px;
}

.message-content {
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.message-sources {
  padding-top: 8px;
  border-top: 1px solid var(--rule);
}

.source-badge {
  display: inline-flex;
  align-items: center;
  background: var(--surface-raised);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  padding: 2px 8px;
  font-size: 12px;
  margin: 4px 4px 0 0;
  white-space: nowrap;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
}

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 999px;
}

.typing-dots span {
  width: 7px; height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Chat input area */
.chat-input-area {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 14px 20px;
}

.chat-textarea {
  resize: none;
  border-radius: var(--radius-control) 0 0 var(--radius-control) !important;
  font-size: 15px;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
}

.chat-send-btn {
  border-radius: 0 var(--radius-control) var(--radius-control) 0 !important;
  padding: 0 18px;
}

/* ============================================================
   DOCUMENTS
   ============================================================ */
.upload-dropzone {
  border: 1px dashed var(--control);
  border-radius: 8px;
  background: var(--bg-card);
  padding: 2.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.upload-dropzone:hover,
.upload-dropzone.drag-over {
  border-color: var(--text-main);
  background: var(--surface-raised);
}

/* ============================================================
   CALCULATEUR — le résultat est la donnée principale : la teinte y va
   ============================================================ */
.calc-result-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary-dark);
  font-variant-numeric: tabular-nums;
}

.calc-step {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.calc-step:last-child { border-bottom: none; font-weight: 600; }

/* ============================================================
   BOOTSTRAP — surfaces, boutons, badges, tableaux, champs
   ============================================================ */

/* Surfaces à plat : une bordure, pas d'ombre au repos */
.shadow-sm, .shadow, .shadow-lg { box-shadow: none !important; }

.card {
  --bs-card-border-color: var(--border);
  --bs-card-border-radius: var(--border-radius-card);
  --bs-card-inner-border-radius: calc(var(--border-radius-card) - 1px);
  --bs-card-cap-bg: transparent;
  border-radius: var(--border-radius-card);
}
.card.border-0 { border: 1px solid var(--border) !important; }
.card-header { border-bottom-color: var(--rule); }
.card-footer { border-top-color: var(--rule); }

/* Tuiles de statistiques saturées → panneau blanc, chiffre à l'encre */
.card.bg-primary, .card.bg-success, .card.bg-warning, .card.bg-info,
.card.bg-danger, .card.bg-secondary, .card.bg-dark {
  background: var(--bg-card) !important;
  color: var(--text-main) !important;
}
.card.bg-primary small, .card.bg-success small, .card.bg-warning small, .card.bg-info small,
.card.bg-danger small, .card.bg-secondary small, .card.bg-dark small { color: var(--text-muted); }
.card.text-white .bi { color: var(--text-muted); }
/* Un chiffre clé est un libellé et un nombre : pas d'icône au-dessus */
.card .card-body > .bi.fs-2:first-child { display: none !important; }
.card .fs-3, .card .fs-4 { font-variant-numeric: tabular-nums; }

/* Boutons : un principal noir, le reste neutre ; le rouge reste pour détruire */
.btn {
  --bs-btn-border-radius: var(--radius-control);
  --bs-btn-font-weight: 500;
  border-radius: var(--radius-control);
}
.btn:focus-visible { box-shadow: 0 0 0 3px rgba(15,74,34,0.35) !important; }

.btn-primary, .btn-success, .btn-warning {
  --bs-btn-color: var(--text-main);
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-color: var(--text-main);
  --bs-btn-hover-bg: var(--accent-hover);
  --bs-btn-hover-border-color: var(--accent-hover);
  --bs-btn-active-color: var(--text-main);
  --bs-btn-active-bg: var(--accent-hover);
  --bs-btn-active-border-color: var(--accent-hover);
  --bs-btn-disabled-color: var(--text-main);
  --bs-btn-disabled-bg: #F5B98A;
  --bs-btn-disabled-border-color: #F5B98A;
  font-weight: 600;
}

.btn-dark {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--ink-button);
  --bs-btn-border-color: var(--ink-button);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #000;
  --bs-btn-hover-border-color: #000;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #000;
  --bs-btn-active-border-color: #000;
  --bs-btn-disabled-color: #fff;
  --bs-btn-disabled-bg: #6B6B6B;
  --bs-btn-disabled-border-color: #6B6B6B;
}

.btn-secondary, .btn-info, .btn-light,
.btn-outline-primary, .btn-outline-success, .btn-outline-warning,
.btn-outline-info, .btn-outline-secondary, .btn-outline-dark, .btn-outline-light {
  --bs-btn-color: var(--text-main);
  --bs-btn-bg: var(--bg-card);
  --bs-btn-border-color: var(--control);
  --bs-btn-hover-color: var(--text-main);
  --bs-btn-hover-bg: var(--surface-raised);
  --bs-btn-hover-border-color: #9CA3AF;
  --bs-btn-active-color: var(--text-main);
  --bs-btn-active-bg: var(--active);
  --bs-btn-active-border-color: #9CA3AF;
  --bs-btn-disabled-color: var(--text-muted);
  --bs-btn-disabled-bg: var(--bg-card);
  --bs-btn-disabled-border-color: var(--border);
}

.btn-outline-danger {
  --bs-btn-color: #B42318;
  --bs-btn-border-color: var(--control);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #B42318;
  --bs-btn-hover-border-color: #B42318;
}

/* Badges : teintes pâles et encre de la même teinte */
.badge { font-weight: 500; border-radius: var(--radius-chip); white-space: normal; text-align: left; line-height: 1.35; padding: .35em .7em; }
.badge.bg-success, .badge.text-bg-success, .badge.bg-success-subtle { background: #DCFAE5 !important; color: #04250E !important; }
.badge.bg-danger,  .badge.text-bg-danger,  .badge.bg-danger-subtle  { background: #FFEDEA !important; color: #831C1E !important; }
.badge.bg-warning, .badge.text-bg-warning, .badge.bg-warning-subtle { background: #FFFBEB !important; color: #92400E !important; }
.badge.bg-primary, .badge.bg-info, .badge.bg-secondary, .badge.bg-dark, .badge.bg-light,
.badge.text-bg-primary, .badge.text-bg-info, .badge.text-bg-secondary, .badge.text-bg-dark {
  background: #EEF0F3 !important;
  color: var(--text-main) !important;
}

/* Fonds teintés utilitaires → neutres */
.bg-primary-soft, .bg-success-soft, .bg-warning-soft, .bg-info-soft, .bg-danger-soft {
  background: #EEF0F3;
}
.badge.bg-primary-soft { color: var(--text-main) !important; }

.text-muted, .text-secondary { color: var(--text-muted) !important; }
/* Couleurs de texte Bootstrap : l'interface reste à l'encre, les statuts gardent un ton lisible */
.text-primary, .text-info { color: var(--text-main) !important; }
.text-warning { color: #92400E !important; }
.text-success { color: var(--success) !important; }
.text-danger  { color: #B42318 !important; }
.bg-primary-subtle, .bg-info-subtle, .bg-secondary-subtle { background-color: #EEF0F3 !important; }
.border-primary-subtle, .border-info-subtle { border-color: var(--border) !important; }
.text-orange { color: #B45309 !important; }
.text-green  { color: var(--success) !important; }

/* Tableaux : des filets et l'alignement, pas de bandeau ni de zèbre */
.table {
  --bs-table-border-color: var(--rule);
  --bs-table-hover-bg: var(--surface-raised);
  --bs-table-striped-bg: transparent;
  font-variant-numeric: tabular-nums;
}
.table > thead > tr > th,
.table th {
  font-size: 12px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.table > thead.table-dark,
.table > thead.table-light,
.table > thead.table-dark > tr > th,
.table > thead.table-light > tr > th {
  --bs-table-bg: transparent;
  --bs-table-color: var(--text-muted);
  --bs-table-border-color: var(--border);
  background: transparent !important;
  color: var(--text-muted) !important;
}

/* Champs */
.form-control, .form-select {
  border-radius: var(--radius-control);
  border-color: var(--control);
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15,74,34,0.15);
}
.form-control::placeholder { color: #6B6B6B; }
.form-label { font-weight: 500; font-size: 14px; }
.form-check-input:checked { background-color: var(--ink-button); border-color: var(--ink-button); }
.form-check-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,74,34,0.15); }

/* Onglets et pastilles de navigation */
.nav-link { color: var(--text-muted); }
.nav-link:hover, .nav-link:focus { color: var(--text-main); }
.nav-tabs .nav-link.active { color: var(--text-main); }
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
  background: var(--active);
  color: var(--text-main);
}

.alert { border-radius: var(--border-radius-card); }
.page-link { color: var(--text-main); }
.active > .page-link, .page-link.active {
  background: var(--ink-button);
  border-color: var(--ink-button);
  color: #fff;
}

code { font-size: 0.85em; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); background: var(--bg-card); }
  .app-sidebar.open { transform: translateX(0); box-shadow: 0 8px 32px rgba(0,0,0,0.18); }
  .app-main { margin-left: 0; padding-bottom: 70px; }
  .app-bottom-nav { display: flex; }

  .chat-sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-height);
    bottom: 60px; /* above bottom nav */
    z-index: 1035;
    transform: translateX(-100%);
    transition: transform 0.3s;
    width: 280px;
  }
  .chat-sidebar.show { transform: translateX(0); box-shadow: 0 8px 32px rgba(0,0,0,0.18); }
  .chat-wrapper { height: calc(100vh - var(--topbar-height) - 60px); }
  .suggestions-grid { grid-template-columns: 1fr; }
  .message-row { max-width: 95%; }
}

@media (min-width: 992px) {
  .app-topbar,
  .app-bottom-nav { display: none !important; }
}

@media (max-width: 576px) {
  .chat-messages { padding: 16px; }
  .chat-input-area { padding: 12px; }
  .app-main h1 { font-size: 22px; }
  .app-main h1 .bi { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .typing-dots span { animation: none; }
  .app-sidebar, .chat-sidebar, .sidebar-overlay { transition: none; }
}

/* ============================================================
   UTILITIES & BACKWARD COMPAT
   ============================================================ */
/* Avatar utilities (kept for other views) */
.avatar-sm {
  width: 34px; height: 34px;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.avatar-lg {
  width: 70px; height: 70px;
}

.stat-icon {
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ============================================================
   MARKDOWN BODY (chat responses)
   ============================================================ */
.message-content.markdown-body { white-space: normal; }

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  font-weight: 600;
  margin-top: 1rem;
  margin-bottom: 0.4rem;
  line-height: 1.3;
  letter-spacing: 0;
  color: var(--text-main);
}
.markdown-body h1 { font-size: 1.2rem; }
.markdown-body h2 { font-size: 1.1rem; }
.markdown-body h3 { font-size: 1rem; }
.markdown-body h4 { font-size: 0.95rem; }
.markdown-body h5 { font-size: 0.9rem; }
.markdown-body h6 { font-size: 0.85rem; color: var(--text-muted); }

.markdown-body p { margin-bottom: 0.6rem; }
.markdown-body p:last-child { margin-bottom: 0; }

.markdown-body strong { font-weight: 600; }
.markdown-body em { font-style: italic; }

.markdown-body ul, .markdown-body ol { padding-left: 1.4rem; margin-bottom: 0.6rem; }
.markdown-body li { margin-bottom: 0.2rem; }
.markdown-body li > ul, .markdown-body li > ol { margin-top: 0.2rem; margin-bottom: 0.2rem; }

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.markdown-body table th,
.markdown-body table td {
  border: none;
  border-bottom: 1px solid var(--rule);
  padding: 0.45rem 0.75rem 0.45rem 0;
  text-align: left;
  vertical-align: top;
}
.markdown-body table th {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom-color: var(--border);
  white-space: nowrap;
}

.markdown-body code {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  padding: 0.1em 0.38em;
  font-size: 0.85em;
  color: var(--text-main);
  word-break: break-word;
}
.markdown-body pre {
  background: #1D1F20;
  border-radius: 8px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  margin: 0.6rem 0;
}
.markdown-body pre code {
  background: transparent;
  border: none;
  color: #F3F4F6;
  padding: 0;
  font-size: 0.85rem;
  white-space: pre;
}

.markdown-body blockquote {
  border-left: 3px solid var(--control);
  margin: 0.6rem 0;
  padding: 0.2rem 0.9rem;
  color: var(--text-main);
}
.markdown-body blockquote p { margin-bottom: 0; }

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 0.9rem 0;
}

.markdown-body a { color: var(--primary-dark); text-decoration: underline; }

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #C1C7D0; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #9BA3AF; }
