/* ConfectionPro - Custom Styles */

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --secondary: #8b5cf6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --sidebar-bg: #1e1b4b;
  --sidebar-width: 260px;
}

/* ==================== SEARCHABLE SELECT ==================== */

/* Wrapper remplace le <select> original */
.ss-wrapper {
  position: relative;
  width: 100%;
  font-family: inherit;
  font-size: 0.875rem;
}

/* Bouton déclencheur (affiche la valeur sélectionnée) */
.ss-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: white;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 38px;
  color: #1e293b;
  user-select: none;
}

.ss-trigger:hover {
  border-color: #6366f1;
}

.ss-trigger.ss-open {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
  border-radius: 8px 8px 0 0;
}

.ss-trigger-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.875rem;
}

.ss-trigger-text.ss-placeholder {
  color: #94a3b8;
}

.ss-trigger-arrow {
  flex-shrink: 0;
  font-size: 0.65rem;
  color: #94a3b8;
  transition: transform 0.2s;
}

.ss-trigger.ss-open .ss-trigger-arrow {
  transform: rotate(180deg);
}

/* Dropdown panel */
.ss-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 9999;
  background: white;
  border: 1.5px solid #6366f1;
  border-top: none;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  max-height: 260px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Champ de recherche dans le dropdown */
.ss-search-wrap {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
}

.ss-search {
  width: 100%;
  padding: 0.35rem 0.6rem 0.35rem 1.8rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.8rem;
  outline: none;
  background: #f8fafc url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat 0.5rem center;
  transition: border-color 0.15s;
}

.ss-search:focus {
  border-color: #6366f1;
  background-color: white;
}

/* Liste des options */
.ss-list {
  overflow-y: auto;
  flex: 1;
  padding: 0.25rem 0;
}

.ss-list::-webkit-scrollbar {
  width: 4px;
}

.ss-list::-webkit-scrollbar-track {
  background: #f8fafc;
}

.ss-list::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 2px;
}

/* Option individuelle */
.ss-option {
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  font-size: 0.845rem;
  color: #1e293b;
  transition: background 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ss-option:hover {
  background: #f0f4ff;
  color: #4f46e5;
}

.ss-option.ss-selected {
  background: #eef2ff;
  color: #4f46e5;
  font-weight: 600;
}

.ss-option.ss-selected::before {
  content: '✓ ';
  font-size: 0.75rem;
}

.ss-option.ss-disabled {
  color: #94a3b8;
  cursor: default;
  font-style: italic;
}

.ss-option.ss-disabled:hover {
  background: none;
  color: #94a3b8;
}

/* Message "aucun résultat" */
.ss-empty {
  padding: 0.75rem 0.85rem;
  font-size: 0.8rem;
  color: #94a3b8;
  text-align: center;
  font-style: italic;
}

/* Mise en évidence du texte filtré */
.ss-highlight {
  background: #fef08a;
  border-radius: 2px;
  font-weight: 700;
  color: #854d0e;
}

/* Adaptation taille sm (filtres inline) */
.ss-wrapper.ss-sm .ss-trigger {
  padding: 0.3rem 0.6rem;
  min-height: 32px;
  font-size: 0.8rem;
}

.ss-wrapper.ss-sm .ss-dropdown {
  font-size: 0.8rem;
}

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

html,
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  min-height: 100%;
}

/* ==================== LAYOUT ==================== */
#app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: white;
  border-bottom: 1px solid #e2e8f0;
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.page-content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

/* ==================== SIDEBAR ==================== */
.sidebar-logo {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo .logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  color: white;
  letter-spacing: -0.025em;
}

.sidebar-logo .logo-sub {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.sidebar-section {
  padding: 0.5rem 0;
}

.sidebar-label {
  padding: 0.5rem 1.25rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.35);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  color: rgba(255, 255, 255, 0.65);
  cursor: pointer;
  transition: all 0.15s;
  border-radius: 0;
  font-size: 0.875rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  text-decoration: none;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: white;
  border-left-color: rgba(255, 255, 255, 0.3);
}

.nav-item.active {
  background: rgba(99, 102, 241, 0.25);
  color: white;
  border-left-color: var(--primary);
}

.nav-item i {
  width: 18px;
  text-align: center;
  font-size: 0.9rem;
}

.badge-sidebar {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 9999px;
  min-width: 18px;
  text-align: center;
}

/* ==================== CARDS & STATS ==================== */
.stat-card {
  background: white;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  border: 1px solid #e2e8f0;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.card {
  background: white;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #374151;
}

.card-body {
  padding: 1.25rem;
}

/* ==================== TABLES ==================== */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
  width: 100%;
}

/* Largeurs minimales par module pour éviter l'écrasement des colonnes */
.table-container table,
.table-responsive-wrap table {
  width: 100%;
  min-width: 600px;
}

#of-table table {
  min-width: 900px;
}

#commandes-table table {
  min-width: 800px;
}

#factures-table table {
  min-width: 820px;
}

#devis-table table {
  min-width: 780px;
}



#achats-table table {
  min-width: 800px;
}

#produits-table table {
  min-width: 700px;
}

#clients-table table {
  min-width: 640px;
}

#employes-table table {
  min-width: 700px;
}

#matieres-table table {
  min-width: 740px;
}

#fours-table table {
  min-width: 600px;
}

/* Wrapper générique pour tableaux inline (modals, rapports, formulaires) */
.table-responsive-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

/* Responsive : masquer colonnes peu essentielles sur petits écrans */
@media (max-width: 640px) {
  thead th {
    font-size: 0.68rem;
    padding: 0.5rem 0.6rem;
  }

  tbody td {
    font-size: 0.78rem;
    padding: 0.5rem 0.6rem;
  }

  .hide-xs {
    display: none !important;
  }
}

thead th {
  background: #f8fafc;
  padding: 0.7rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.15s;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody td {
  padding: 0.7rem 1rem;
  color: #374151;
  vertical-align: middle;
}

/* ==================== BADGES & STATUS ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green {
  background: #d1fae5;
  color: #065f46;
}

.badge-blue {
  background: #dbeafe;
  color: #1e40af;
}

.badge-yellow {
  background: #fef3c7;
  color: #92400e;
}

.badge-red {
  background: #fee2e2;
  color: #991b1b;
}

.badge-gray {
  background: #f3f4f6;
  color: #4b5563;
}

.badge-purple {
  background: #ede9fe;
  color: #5b21b6;
}

.badge-orange {
  background: #ffedd5;
  color: #9a3412;
}

/* ==================== FORMS ==================== */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.375rem;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.875rem;
  color: #1e293b;
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

/* ==================== BUTTONS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #059669;
}

.btn-warning {
  background: var(--warning);
  color: white;
}

.btn-warning:hover {
  background: #d97706;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-secondary {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-info {
  background: var(--info);
  color: white;
}

.btn-info:hover {
  background: #2563eb;
}

/* iOS fix: prevent child elements (icons, spans, pseudo-elements) from stealing clicks inside buttons */
button *,
button *::before,
button *::after {
  pointer-events: none !important;
}

.btn-lg {
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
}

.btn-icon {
  padding: 0.45rem;
  width: 34px;
  height: 34px;
  justify-content: center;
}

/* ==================== MODAL ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  animation: modalIn 0.25s ease;
}

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

.modal-xl {
  max-width: 1020px;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(-10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes sheetUp {
  from {
    opacity: 0;
    transform: translateY(100%);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes shimmer {
  0% {
    background-position: -200px 0;
  }

  100% {
    background-position: calc(200px + 100%) 0;
  }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
}

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #f1f5f9;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  background: #f8fafc;
}

.close-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: #f1f5f9;
  color: #64748b;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.close-btn:hover {
  background: #e2e8f0;
}

/* ==================== ALERTS ==================== */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.alert-success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.alert-info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

/* ==================== SEARCH & FILTERS ==================== */
.search-box {
  position: relative;
}

.search-box i {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  font-size: 0.8rem;
}

.search-box input {
  padding-left: 2.25rem;
}

/* ==================== PAGE HEADER ==================== */
.page-header {
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: #1e293b;
}

.page-subtitle {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 0.15rem;
}

/* ==================== PROGRESS ==================== */
.progress-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 9999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.5s ease;
}

/* ==================== TIMELINE / STEPS ==================== */
.step-indicator {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.step {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e2e8f0;
}

.step.done {
  background: var(--success);
}

.step.active {
  background: var(--primary);
  width: 16px;
  border-radius: 4px;
}

/* ==================== LOADING ==================== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: #94a3b8;
  gap: 0.75rem;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==================== EMPTY STATE ==================== */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: #94a3b8;
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 1rem;
  color: #64748b;
  margin-bottom: 0.5rem;
}

.empty-state p {
  font-size: 0.85rem;
}

/* ==================== GRID ==================== */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

/* Stats KPI grid — identique au dashboard */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

/* ==================== NOTIFICATION TOAST ==================== */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: #1e293b;
  color: white;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 0.85rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  display: flex;
  pointer-events: auto;
  align-items: center;
  gap: 0.5rem;
  min-width: 280px;
  animation: slideIn 0.3s ease;
}

.toast.success {
  border-left: 4px solid var(--success);
}

.toast.error {
  border-left: 4px solid var(--danger);
}

.toast.info {
  border-left: 4px solid var(--info);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    z-index: 200;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

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

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ==================== AVATAR ==================== */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

/* ==================== COLOR SWATCH ==================== */
.color-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.1);
  display: inline-block;
  vertical-align: middle;
}

/* ==================== KANBAN / PIPELINE ==================== */
.pipeline {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.pipeline-stage {
  min-width: 200px;
  background: #f8fafc;
  border-radius: 10px;
  padding: 0.75rem;
  border: 1px solid #e2e8f0;
}

.pipeline-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid currentColor;
}

/* Tab styles */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 1.25rem;
}

.tab {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}

.tab:hover {
  color: var(--primary);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Divider */
.divider {
  height: 1px;
  background: #f1f5f9;
  margin: 1rem 0;
}

/* Print hide */
@media print {

  .sidebar,
  .topbar,
  .btn,
  .modal-overlay {
    display: none !important;
  }

  .main-content {
    margin-left: 0 !important;
  }
}

/* ==================== FACTURE DOCUMENT (modal + print) ==================== */

/* En-tête facture */
.fac-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.5rem 2rem;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  color: white;
}

.fac-company-name {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.fac-company-sub {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.65);
  margin-top: 0.15rem;
}

.fac-company-info {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.55);
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.fac-header-right {
  text-align: right;
}

.fac-invoice-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 0.25rem;
}

.fac-invoice-num {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
}

.fac-cmd-ref {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 0.4rem;
}

/* Bloc meta (client + infos) */
.fac-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid #e2e8f0;
}

.fac-block {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 1rem;
}

.fac-block-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
  font-weight: 700;
  margin-bottom: 0.6rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid #e2e8f0;
}

.fac-client-name {
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 0.3rem;
}

.fac-ice-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.35rem 0;
}

.fac-ice-badge {
  font-size: 0.62rem;
  background: #dbeafe;
  color: #1e40af;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.fac-ice-num {
  font-family: monospace;
  font-size: 0.88rem;
  font-weight: 700;
  color: #1e293b;
  letter-spacing: 0.06em;
}

.fac-meta-line {
  font-size: 0.78rem;
  color: #64748b;
  margin-top: 0.2rem;
}

.fac-meta-line i {
  width: 14px;
  color: #94a3b8;
}

.fac-info-grid {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.fac-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}

.fac-info-label {
  color: #64748b;
}

.fac-info-val {
  font-weight: 600;
  color: #1e293b;
}

.fac-overdue {
  color: #ef4444 !important;
}

/* Section tableau */
.fac-section {
  padding: 0 2rem;
}

.fac-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
  font-size: 0.83rem;
}

.fac-th {
  background: #1e293b;
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.65rem 0.75rem;
  text-align: left;
  white-space: nowrap;
}

.fac-th-center {
  text-align: center !important;
}

.fac-th-right {
  text-align: right !important;
}

.fac-tr:nth-child(even) {
  background: #f8fafc;
}

.fac-tr:hover {
  background: #f0f4ff;
}

.fac-td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid #f1f5f9;
  color: #1e293b;
  vertical-align: middle;
}

.fac-td-muted {
  color: #94a3b8;
  font-size: 0.78rem;
}

.fac-td-bold {
  font-weight: 700;
}

.fac-td-mono {
  font-family: monospace;
  font-size: 0.8rem;
}

.fac-td-center {
  text-align: center;
}

.fac-td-right {
  text-align: right;
}

.fac-td-val {
  text-align: right;
}

.fac-prod-name {
  font-weight: 600;
  color: #1e293b;
}

.fac-variant-badge {
  display: inline-block;
  background: #ede9fe;
  color: #6d28d9;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  white-space: nowrap;
}

/* Totaux */
.fac-totals-wrap {
  display: flex;
  justify-content: flex-end;
  padding: 1.25rem 2rem;
  border-top: 1px solid #e2e8f0;
}

.fac-totals-box {
  width: 320px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem 1.25rem;
}

.fac-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  padding: 0.3rem 0;
  color: #64748b;
}

.fac-total-val {
  font-weight: 600;
  color: #1e293b;
}

.fac-total-divider {
  height: 1px;
  background: #e2e8f0;
  margin: 0.4rem 0;
}

.fac-total-ttc {
  font-size: 1.1rem !important;
  font-weight: 800 !important;
  color: #1e293b !important;
}

.fac-total-reste {
  font-size: 0.9rem !important;
  font-weight: 700 !important;
  color: #ef4444 !important;
  background: #fef2f2;
  padding: 0.4rem 0.6rem !important;
  border-radius: 6px;
  margin-top: 0.25rem;
}

.fac-paid-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: #10b981;
  background: #f0fdf4;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  margin-top: 0.4rem;
}

/* Note / conditions */
.fac-note-zone {
  margin: 0 2rem 1.25rem;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 0.85rem 1rem;
}

.fac-note-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: #92400e;
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.fac-note-text {
  font-size: 0.82rem;
  color: #78350f;
  line-height: 1.5;
}

/* Pied de page facture */
.fac-footer {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 2rem;
  background: #f8fafc;
  border-top: 2px solid #1e1b4b;
  font-size: 0.72rem;
  color: #94a3b8;
  margin-top: 1rem;
}

/* ==================== IMPRESSION / PDF ==================== */
@media print {

  /* Masquer tout l'UI */
  .sidebar,
  .topbar,
  .no-print,
  .no-print-mobile,
  .modal-overlay>*:not(#facture-print-zone),
  .modal-footer,
  .modal-header .close-btn {
    display: none !important;
  }

  .main-content {
    margin-left: 0 !important;
  }

  /* Reset page */
  body {
    background: white !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  /* Facture plein écran */
  #facture-print-zone {
    width: 100% !important;
    max-width: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    page-break-inside: avoid;
  }

  /* Garder couleurs de fond */
  .fac-header {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .fac-th {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .fac-tr:nth-child(even) {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .fac-total-reste {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .fac-paid-badge {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Éviter coupure dans le tableau */
  .fac-table {
    page-break-inside: auto;
  }

  .fac-tr {
    page-break-inside: avoid;
  }

  /* Masquer le header/footer du modal, garder juste le contenu */
  .modal {
    box-shadow: none !important;
    border-radius: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }
}

/* ============================================================
   Fiche Stock Produit — Onglets
   ============================================================ */
.fiche-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid #e5e7eb;
  margin-bottom: 1.25rem;
}

.fiche-tab {
  padding: 8px 18px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #6b7280;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  border-radius: 4px 4px 0 0;
  transition: color .15s, border-color .15s, background .15s;
}

.fiche-tab:hover {
  color: #374151;
  background: #f3f4f6;
}

.fiche-tab-active {
  color: #4f46e5;
  border-bottom-color: #4f46e5;
  background: #eef2ff;
  font-weight: 600;
}

/* Variante card dans la fiche stock */
.variante-card {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 14px;
  background: #fff;
  transition: box-shadow .15s;
}

.variante-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

.variante-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #d1d5db;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.stock-bar-wrap {
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  margin: 6px 0 2px;
}

.stock-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .3s;
}

/* Taille-picker boutons dans ajout variante */
.taille-btn {
  min-width: 42px;
  padding: 4px 8px;
  font-size: 0.78rem;
  border: 1.5px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  color: #374151;
  transition: border-color .15s, background .15s, color .15s;
  text-align: center;
}

.taille-btn.selected {
  border-color: #4f46e5;
  background: #eef2ff;
  color: #4f46e5;
  font-weight: 600;
}

/* Palette couleur */
.couleur-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}

.couleur-btn:hover {
  transform: scale(1.15);
}

.couleur-btn.selected {
  border-color: #4f46e5;
  transform: scale(1.18);
  box-shadow: 0 0 0 2px #eef2ff;
}

/* Wrapper item pour chaque pastille couleur */
.couleur-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.couleur-label {
  display: none;
}

/* Aperçu variantes à créer */
.variante-preview-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 99px;
  font-size: 0.75rem;
  color: #374151;
}

/* ============================================================
   Module Devis — Document & Tableau lignes
   ============================================================ */

/* Cellules du document aperçu devis */
.dv-doc-th {
  padding: 8px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  background: #6366f1;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.dv-doc-td {
  padding: 8px 10px;
  font-size: 0.83rem;
  border-bottom: 1px solid #f1f5f9;
  color: #1e293b;
  vertical-align: top;
}

.dv-doc-tr:nth-child(even) .dv-doc-td {
  background: #f8fafc;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* Badge success pour btn convertir */
.btn-success {
  background: #10b981;
  color: #fff;
  border: none;
}

.btn-success:hover {
  background: #059669;
}

/* Badge sidebar devis */
.badge-sidebar {
  display: inline-block;
  background: #ef4444;
  color: #fff;
  border-radius: 99px;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  margin-left: auto;
}

/* ==================== MOBILE REFACTORING ==================== */

/* Tap highlight reset */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Hamburger button - visible on mobile */
@media (max-width: 768px) {
  #menu-toggle {
    display: flex !important;
  }
}

/* Sidebar backdrop overlay */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: all;
}

/* Modal fullscreen on small screens — native bottom sheet style */
@media (max-width: 640px) {
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
    background: rgba(15, 23, 42, 0.35);
  }

  .modal {
    border-radius: 24px 24px 0 0;
    max-height: 92vh;
    max-width: 100%;
    animation: sheetUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.15);
    overscroll-behavior-y: contain;
  }

  .modal-lg,
  .modal-xl {
    max-width: 100%;
  }

  .modal-header {
    padding: 0.75rem 1rem 0.5rem;
    border-radius: 24px 24px 0 0;
    position: relative;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
  }

  /* Handle visuel style iOS/Android */
  .modal-header::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
    margin: 0 auto 8px;
  }

  .modal-title {
    font-size: 1.05rem;
    text-align: center;
  }

  .modal-header .close-btn {
    position: absolute;
    right: 0.75rem;
    top: 0.75rem;
  }

  .modal-body {
    padding: 0.75rem 1rem 1rem;
  }

  .modal-footer {
    padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
    flex-direction: column;
    gap: 0.5rem;
    border-radius: 0;
  }

  .modal-footer .btn {
    width: 100%;
    justify-content: center;
    height: 48px;
    font-size: 0.95rem;
    border-radius: 12px;
  }

  .no-print-mobile {
    display: none !important;
  }
}

/* Global mobile layout */
@media (max-width: 640px) {
  .page-content {
    padding: 0.75rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .topbar {
    height: 52px;
    padding: 0 0.75rem;
  }

  .card {
    padding: 0.75rem;
  }

  .card-header {
    padding: 0.75rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .m-card-actions {
    margin-top: 10px;
  }

  .grid-4,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .page-header {
    gap: 0.5rem;
  }

  .page-header h2 {
    font-size: 1.1rem;
  }

  /* Toast full width on mobile */
  .toast-container {
    left: 0.75rem;
    right: 0.75rem;
    top: 60px;
  }

  .toast {
    min-width: unset;
    width: 100%;
  }

  /* Search boxes full width */
  .search-box {
    width: 100% !important;
  }

  /* KPI cards full width */
  .grid-4>.kpi-card,
  .stats-grid>.kpi-card {
    min-width: unset;
  }

  /* Empty state padding reduce */
  .empty-state {
    padding: 2rem 1rem;
  }

  /* Pipeline scroll snap */
  .pipeline {
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }

  .pipeline-stage {
    scroll-snap-align: start;
    min-width: 160px;
  }

  /* Touch targets minimum 44px */
  .btn,
  .nav-item,
  .form-input,
  .form-select,
  .ss-trigger,
  .taille-btn,
  .couleur-btn {
    min-height: 44px;
  }

  .btn-icon {
    min-width: 44px;
    min-height: 44px;
  }

  /* Palette couleurs mobile UX pro */
  .variante-color-wrap {
    flex-direction: column !important;
    gap: 1rem !important;
    align-items: stretch !important;
  }

  .variante-color-wrap>div {
    width: 100% !important;
    flex: none !important;
  }

  #couleur-palette {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)) !important;
    gap: 0.6rem !important;
  }

  .couleur-item {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 3px !important;
  }

  .couleur-btn {
    width: 40px !important;
    height: 40px !important;
    min-height: auto !important;
    border-radius: 50% !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12) !important;
    flex-shrink: 0 !important;
  }

  .couleur-label {
    display: block !important;
    font-size: 0.62rem !important;
    color: #94a3b8 !important;
    text-transform: capitalize !important;
    text-align: center !important;
    line-height: 1.1 !important;
    max-width: 100% !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* Tables min-width reduction */
  .table-container table,
  .table-responsive-wrap table {
    min-width: 500px;
  }

  #of-table table {
    min-width: 600px;
  }

  #commandes-table table {
    min-width: 560px;
  }

  #factures-table table {
    min-width: 560px;
  }

  #devis-table table {
    min-width: 540px;
  }

  #achats-table table {
    min-width: 560px;
  }

  #produits-table table {
    min-width: 520px;
  }

  #clients-table table {
    min-width: 480px;
  }

  #employes-table table {
    min-width: 520px;
  }

  #matieres-table table {
    min-width: 540px;
  }

  #fours-table table {
    min-width: 460px;
  }
}

/* Very small screens */
@media (max-width: 380px) {
  .modal-body {
    padding: 0.75rem;
  }

  .modal-header {
    padding: 0.75rem;
  }

  .page-content {
    padding: 0.5rem;
  }

  .card {
    padding: 0.625rem;
  }
}

/* Mobile form layouts - stack everything */
@media (max-width: 640px) {

  /* Override any inline grid that uses fixed pixel columns in modals */
  .modal-body [style*="display:grid"][style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Make sure grid-2 inside modals also stacks */
  .modal-body .grid-2 {
    grid-template-columns: 1fr;
  }

  /* Action bars full width buttons */
  .action-bar {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
  }

  .action-bar .btn {
    flex: 1;
    min-width: 120px;
  }
}

/* Active states for touch */
.btn:active,
.nav-item:active,
.fiche-tab:active {
  transform: scale(0.98);
  opacity: 0.9;
}

/* Bottom safe area for mobile browsers */
.modal-footer {
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}

/* Table horizontal scroll indicator */
.table-container,
.table-responsive-wrap {
  scrollbar-width: thin;
}

/* ==================== FORM LIGNES (Commande, Devis, Achat) ==================== */

/* Commande ligne */
.ligne-cmd {
  display: grid;
  grid-template-columns: 2fr 1.6fr 70px 110px 90px 36px;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
  align-items: center;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
}

.ligne-cmd-header {
  display: grid;
  grid-template-columns: 2fr 1.6fr 70px 110px 90px 36px;
  gap: 0.4rem;
  padding: 0 0 0.3rem;
  margin-bottom: 0.1rem;
  border-bottom: 1px solid #e2e8f0;
}

/* Achat ligne */
.ligne-achat {
  display: grid;
  grid-template-columns: 2fr 90px 100px 50px;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  align-items: center;
}

.ligne-achat-header {
  display: grid;
  grid-template-columns: 2fr 90px 100px 50px;
  gap: 0.5rem;
  padding: 0 0 0.3rem;
  margin-bottom: 0.1rem;
  border-bottom: 1px solid #e2e8f0;
}

/* Devis ligne */
.ligne-devis {
  display: grid;
  grid-template-columns: 1fr 1fr 1.5fr;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  align-items: end;
}

.ligne-devis-prix {
  display: grid;
  grid-template-columns: 1fr 0.7fr 0.7fr 0.9fr auto;
  gap: 0.5rem;
  align-items: end;
}

@media (max-width: 640px) {

  .ligne-cmd-header,
  .ligne-achat-header {
    display: none;
  }

  .ligne-cmd {
    grid-template-columns: 1fr;
    padding: 0.75rem;
    gap: 0.5rem;
  }

  .ligne-cmd>div:nth-child(3),
  .ligne-cmd>div:nth-child(4),
  .ligne-cmd>div:nth-child(5),
  .ligne-cmd>div:nth-child(6) {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
  }

  .ligne-achat {
    grid-template-columns: 1fr;
    padding: 0.75rem;
    gap: 0.5rem;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
  }

  .ligne-devis {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .ligne-devis-prix {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }
}

/* ==================== MOBILE TABLES & SPECIFICS ==================== */

@media (max-width: 640px) {

  /* Pointage table */
  #table-pointage td {
    white-space: nowrap;
  }

  #table-pointage input[type="time"] {
    width: 90px !important;
    min-height: 40px;
  }

  #table-pointage select {
    width: 110px !important;
    min-height: 40px;
  }

  /* Fiche stock matrix cells smaller */
  #fiche-tab-content td {
    padding: 4px 2px !important;
  }

  #fiche-tab-content td>div {
    padding: 4px 6px !important;
    min-width: 36px !important;
  }

  #fiche-tab-content td span:first-child {
    font-size: 0.85rem !important;
  }

  /* Dashboard charts stack */
  .dashboard-grid {
    grid-template-columns: 1fr !important;
  }

  /* Parametrage grids */
  .param-grid {
    grid-template-columns: 1fr !important;
  }

  /* Fac-totals full width */
  .fac-totals-box {
    width: 100% !important;
    max-width: 100%;
  }

  /* Facture / Devis mobile adaptation */
  .fac-header {
    flex-direction: column;
    gap: 1rem;
    padding: 1.25rem;
  }

  .fac-header-right {
    text-align: left;
  }

  .fac-invoice-num {
    font-size: 1.6rem;
  }

  .fac-meta {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }

  .fac-block {
    padding: 0.875rem;
  }

  .fac-section {
    padding: 0 1rem;
    overflow-x: visible !important;
  }

  .fac-table,
  .fac-table tbody,
  .fac-table tr,
  .fac-table td {
    display: block;
    width: 100% !important;
    min-width: 0 !important;
  }

  .fac-table {
    min-width: 0 !important;
  }

  .fac-table tbody,
  #factures-table tbody,
  #devis-table tbody {
    display: block;
    margin-top: 12px;
  }

  .fac-table thead {
    display: none;
  }

  .fac-tr {
    margin-bottom: 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 0.75rem;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  }

  .fac-td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.85rem;
    word-break: break-word;
  }

  .fac-td:first-child {
    padding-top: 0.6rem;
  }

  .fac-td:last-child {
    border-bottom: none;
  }

  .fac-td-val {
    margin-left: auto;
    text-align: right;
  }

  .fac-td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #64748b;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .fac-totals-wrap {
    padding: 1rem;
    justify-content: stretch;
  }

  .fac-totals-box {
    width: 100% !important;
    border-radius: 12px;
    padding: 1rem;
  }

  .fac-total-row {
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .fac-total-ttc {
    font-size: 1rem !important;
  }

  .fac-note-zone {
    margin: 0 1rem 1rem;
  }

  .fac-footer {
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
    text-align: center;
  }

  .fac-paid-badge {
    font-size: 0.8rem;
    padding: 0.5rem;
  }

  .fac-ice-num {
    font-size: 0.8rem;
  }

  .fac-paiement-row {
    flex-wrap: wrap;
    padding: 0.5rem;
  }

  .fac-paiement-row>div:first-child {
    min-width: 0;
    flex: 1;
  }

  .fac-paiement-row span:last-child {
    margin-left: 0;
    margin-top: 0.25rem;
  }

  /* Pipeline stage smaller */
  .pipeline-stage {
    min-width: 140px;
    padding: 0.75rem;
  }
}

/* ============================================================
   MOBILE NATIVE APP DESIGN SYSTEM
   ============================================================ */

/* ── Bottom Navigation ─────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.04);
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  will-change: transform;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 100%;
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.65rem;
  font-weight: 600;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.bottom-nav-item i {
  font-size: 1.15rem;
}

.bottom-nav-item.active {
  color: #6366f1;
}

.bottom-nav-item:active {
  transform: scale(0.92);
}

/* Mobile Plus Menu Grid */
.m-plus-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.m-plus-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 1.25rem 0 0.75rem;
  padding-left: 0.25rem;
}

.m-plus-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem 0.25rem;
  border-radius: 16px;
  background: #fff;
  border: 1.5px solid #f1f5f9;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  animation: tilePopIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.m-plus-tile:nth-child(1) {
  animation-delay: 0.02s;
}

.m-plus-tile:nth-child(2) {
  animation-delay: 0.04s;
}

.m-plus-tile:nth-child(3) {
  animation-delay: 0.06s;
}

.m-plus-tile:nth-child(4) {
  animation-delay: 0.08s;
}

.m-plus-tile:nth-child(5) {
  animation-delay: 0.10s;
}

.m-plus-tile:nth-child(6) {
  animation-delay: 0.12s;
}

.m-plus-tile:nth-child(7) {
  animation-delay: 0.14s;
}

.m-plus-tile:nth-child(8) {
  animation-delay: 0.16s;
}

.m-plus-tile:nth-child(9) {
  animation-delay: 0.18s;
}

.m-plus-tile:nth-child(10) {
  animation-delay: 0.20s;
}

.m-plus-tile:nth-child(11) {
  animation-delay: 0.22s;
}

.m-plus-tile:active {
  transform: scale(0.92);
  border-color: #c7d2fe;
}

.m-plus-tile-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.m-plus-tile-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: #475569;
  text-align: center;
  line-height: 1.2;
}

@keyframes tilePopIn {
  from {
    opacity: 0;
    transform: scale(0.7) translateY(10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ── Mobile Page Layout ────────────────────────────────────── */
.mobile-page {
  padding: 0.75rem 0.75rem calc(80px + env(safe-area-inset-bottom));
  min-height: 100vh;
  background: #f8fafc;
}

.mobile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0rem 0 0.75rem;
}

.mobile-header h1 {
  font-size: 1.35rem;
  font-weight: 800;
  color: #1e293b;
  margin: 0;
}

.mobile-header .subtitle {
  font-size: 0.8rem;
  color: #94a3b8;
}

.mobile-back {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #475569;
  cursor: pointer;
}

/* ── Chips / Filters ───────────────────────────────────────── */
.m-chips {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.m-chips::-webkit-scrollbar {
  display: none;
}

.m-chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.m-chip {
  flex-shrink: 0;
  padding: 0.45rem 0.9rem;
  border-radius: 99px;
  background: #fff;
  border: 1.5px solid #e2e8f0;
  font-size: 0.78rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.m-chip.active {
  background: #6366f1;
  color: #fff;
  border-color: #6366f1;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.m-chip:active {
  transform: scale(0.92);
}

/* ── Mobile Cards ──────────────────────────────────────────── */
.m-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.m-card {
  background: #fff;
  border-radius: 20px;
  padding: 1rem 1.125rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  border: 1px solid #f1f5f9;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.15s ease;
  position: relative;
  overflow: hidden;
  animation: cardIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.m-card:nth-child(1) {
  animation-delay: 0.02s;
}

.m-card:nth-child(2) {
  animation-delay: 0.05s;
}

.m-card:nth-child(3) {
  animation-delay: 0.08s;
}

.m-card:nth-child(4) {
  animation-delay: 0.11s;
}

.m-card:nth-child(5) {
  animation-delay: 0.14s;
}

.m-card:nth-child(6) {
  animation-delay: 0.17s;
}

.m-card:nth-child(7) {
  animation-delay: 0.20s;
}

.m-card:nth-child(8) {
  animation-delay: 0.23s;
}

.m-card:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
}

.m-card:active {
  transform: scale(0.982);
  background: #f8fafc;
}

.m-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.4rem;
}

.m-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.3;
}

.m-card-subtitle {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 0.15rem;
}

.m-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.m-card-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: #64748b;
}

.m-card-row i {
  width: 16px;
  text-align: center;
  color: #94a3b8;
  font-size: 0.75rem;
}

.m-card-amount {
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
}

.m-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #f1f5f9;
}

.m-card-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
}



/* ── FAB ───────────────────────────────────────────────────── */
.m-fab {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  border: none;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4), 0 8px 24px rgba(99, 102, 241, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  z-index: 90;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease;
}

.m-fab:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5), 0 12px 32px rgba(99, 102, 241, 0.25);
}

.m-fab:active {
  transform: scale(0.92);
}

.m-fab-secondary {
  bottom: calc(148px + env(safe-area-inset-bottom));
  background: #fff;
  color: #6366f1;
  border: 2px solid #6366f1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* ── Bottom Sheet ──────────────────────────────────────────── */
.bs-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.bs-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.bs-sheet {
  background: #fff;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.bs-overlay.active .bs-sheet {
  transform: translateY(0);
}

.bs-handle {
  width: 36px;
  height: 4px;
  background: #e2e8f0;
  border-radius: 99px;
  margin: 10px auto 4px;
  flex-shrink: 0;
}

.bs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem 0.75rem;
  flex-shrink: 0;
}

.bs-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1e293b;
  margin: 0;
}

.bs-header .close-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #f1f5f9;
  border: none;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.bs-body {
  padding: 0 1rem 1.5rem;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.bs-footer {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid #f1f5f9;
  flex-shrink: 0;
}

.bs-footer .btn {
  flex: 1;
  justify-content: center;
}

/* ── Mobile Grid (variantes stock) ─────────────────────────── */
.mobile-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.mobile-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

/* ── Mobile Section / Card interne ─────────────────────────── */
.m-section {
  background: #fff;
  border-radius: 14px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  border: 1px solid #f1f5f9;
}

.m-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.m-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0;
  font-size: 0.85rem;
}

.m-info-row .label {
  color: #64748b;
}

.m-info-row .value {
  font-weight: 600;
  color: #1e293b;
}

.m-divider {
  height: 1px;
  background: #f1f5f9;
  margin: 0.5rem 0;
}

/* ── Mobile Empty State ────────────────────────────────────── */
.m-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
}

.m-empty i {
  font-size: 2.5rem;
  color: #cbd5e1;
  margin-bottom: 1rem;
}

.m-empty h3 {
  font-size: 1rem;
  color: #64748b;
  margin-bottom: 0.3rem;
}

.m-empty p {
  font-size: 0.8rem;
  color: #94a3b8;
}

/* ── Mobile Tabs (scrollable) ──────────────────────────────── */
.m-tabs {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
  scrollbar-width: none;
}

.m-tabs::-webkit-scrollbar {
  display: none;
}

.m-tab {
  flex-shrink: 0;
  padding: 0.5rem 1rem;
  border-radius: 10px;
  background: #fff;
  border: 1.5px solid #e2e8f0;
  font-size: 0.82rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  white-space: nowrap;
}

.m-tab.active {
  background: #6366f1;
  color: #fff;
  border-color: #6366f1;
}

/* ── Hide desktop on mobile ────────────────────────────────── */
@media (max-width: 768px) {
  #app {
    height: 100vh;
    height: 100dvh;
  }

  .main-content {
    margin-left: 0 !important;
    height: 100%;
    min-height: 0;
  }

  .page-content {
    min-height: 0;
  }

  .sidebar {
    display: none !important;
  }

  .topbar {
    display: none !important;
  }
}

/* Hide mobile on desktop */
@media (min-width: 769px) {
  .bottom-nav {
    display: none !important;
  }

  .m-fab {
    display: none !important;
  }
}

/* ── Pull-to-Refresh ─────────────────────────────────────────── */
.ptr-container {
  position: relative;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

.ptr-indicator {
  position: absolute;
  top: -50px;
  left: 0;
  right: 0;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: #64748b;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.ptr-indicator i {
  transition: transform 0.2s;
}

.ptr-pulling .ptr-indicator {
  opacity: 1;
}

.ptr-refreshing .ptr-indicator {
  opacity: 1;
}

.ptr-refreshing .ptr-indicator i {
  animation: ptrSpin 0.8s linear infinite;
}

@keyframes ptrSpin {
  to {
    transform: rotate(360deg);
  }
}

.ptr-refreshing .ptr-indicator span::after {
  content: 'Rafraîchissement...';
}

/* ── Page Transitions ────────────────────────────────────────── */
.page-transition {
  animation: pageIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateX(30px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.page-transition-back {
  animation: pageOut 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes pageOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }

  to {
    opacity: 0;
    transform: translateX(-30px);
  }
}

/* ── Swipe hints ─────────────────────────────────────────────── */
.swipe-hint {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6366f1;
  font-size: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.swipe-hint-left {
  left: 8px;
}

.swipe-hint-right {
  right: 8px;
}

/* ── Mobile scrollable page-content for PTR ──────────────────── */
@media (max-width: 768px) {
  #page-content {
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    position: relative;
  }
}

/* ── Mobile Search Inline (header transforms into search) ───── */
.m-search-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #f1f5f9;
  border: none;
  color: #64748b;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.m-search-icon:active {
  background: #e2e8f0;
  transform: scale(0.92);
}

/* ── Assistant IA ─────────────────────────────────────────── */
.assistant-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 64px);
  background: #f8fafc;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  min-height: 0;
}

.chat-row {
  margin-bottom: 0.75rem;
}

.chat-row:last-child {
  margin-bottom: 0;
}

.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1rem;
  gap: 0.75rem;
}

.chat-welcome-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
}

.chat-welcome h3 {
  margin: 0;
  font-size: 1.15rem;
  color: #1e293b;
}

.chat-welcome p {
  margin: 0;
  font-size: 0.85rem;
  color: #64748b;
  max-width: 280px;
  line-height: 1.5;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.5rem;
}

.chat-suggestions button {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chat-suggestions button:hover {
  border-color: #6366f1;
  color: #6366f1;
  background: #ede9fe;
}

.chat-row {
  display: flex;
  width: 100%;
}

.chat-row.user { justify-content: flex-end; }
.chat-row.bot { justify-content: flex-start; }

.chat-bubble {
  max-width: 75%;
  padding: 0.7rem 1rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-break: break-word;
}

.chat-bubble.user {
  background: #6366f1;
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-bubble.bot {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.chat-input-area {
  border-top: 1px solid #e2e8f0;
  background: #ffffff;
  padding: 0.75rem 1rem;
}

.chat-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.chat-input-wrap textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  min-height: 44px;
  max-height: 120px;
}

.chat-input-wrap textarea:focus {
  border-color: #6366f1;
}

.chat-mic-btn, .chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease, background 0.15s ease;
}

.chat-mic-btn {
  background: #f1f5f9;
  color: #64748b;
}

.chat-mic-btn:hover {
  background: #e2e8f0;
}

.chat-mic-btn.listening {
  background: #ef4444;
  color: white;
  animation: chatMicPulse 1.2s ease-in-out infinite;
}

@keyframes chatMicPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
}

.chat-send-btn {
  background: #6366f1;
  color: white;
}

.chat-send-btn:hover {
  background: #4f46e5;
}

.chat-mic-btn:active, .chat-send-btn:active {
  transform: scale(0.92);
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.6rem 1rem !important;
  min-width: 60px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: #cbd5e1;
  border-radius: 50%;
  animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

@media (max-width: 768px) {
  .assistant-container {
    height: calc(100vh - 56px - 64px);
  }
  .chat-bubble {
    max-width: 85%;
    font-size: 0.85rem;
  }
  .chat-input-area {
    padding: 0.6rem 0.75rem;
  }
}


/* ── Assistant Layout ─────────────────────────────────────── */
.assistant-layout {
  display: flex;
  height: calc(100dvh - 60px);
  background: #f8fafc;
}

.assistant-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.assistant-sidebar {
  width: 260px;
  background: #fff;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.assistant-new-btn {
  margin: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1.5px dashed #c7d2fe;
  background: #eef2ff;
  color: #4f46e5;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}

.assistant-new-btn:hover {
  background: #e0e7ff;
  border-color: #6366f1;
}

.assistant-conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.5rem 0.5rem;
}

.assistant-conv-item {
  position: relative;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 0.25rem;
  transition: background 0.15s ease;
}

.assistant-conv-item:hover {
  background: #f1f5f9;
}

.assistant-conv-item.active {
  background: #eef2ff;
}

.assistant-conv-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 1.5rem;
}

.assistant-conv-meta {
  font-size: 0.7rem;
  color: #94a3b8;
  margin-top: 2px;
}

.assistant-conv-delete {
  position: absolute;
  top: 50%;
  right: 0.4rem;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 0.7rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.assistant-conv-item:hover .assistant-conv-delete {
  display: flex;
}

.assistant-conv-delete:hover {
  background: #fee2e2;
  color: #ef4444;
}

/* Mobile drawer */
.assistant-sidebar-mobile-toggle {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  color: #64748b;
  font-size: 1rem;
  cursor: pointer;
}

@media (max-width: 768px) {
  .assistant-layout {
    height: calc(100dvh - 56px - 64px);
    position: relative;
  }

  .assistant-main {
    display: block;
    position: relative;
    height: 100%;
  }

  .chat-messages {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 64px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding: 0.75rem;
  }

  .chat-input-area {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    padding: 0.5rem 0.75rem;
  }

  .chat-bubble {
    max-width: 85%;
    font-size: 0.85rem;
  }

  .assistant-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 20;
    box-shadow: 2px 0 12px rgba(0,0,0,0.1);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .assistant-sidebar.open {
    transform: translateX(0);
  }

  .assistant-sidebar-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .assistant-sidebar-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 15;
  }

  .assistant-sidebar-overlay.active {
    display: block;
  }
}
/* ── Mobile Search Inline (header transforms into search) ───── */
.m-search-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #f1f5f9;
  border: none;
  color: #64748b;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.m-search-icon:active {
  background: #e2e8f0;
  transform: scale(0.92);
}

/* ── Assistant IA ─────────────────────────────────────────── */
.assistant-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 64px);
  background: #f8fafc;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  min-height: 0;
}

.chat-row {
  margin-bottom: 0.75rem;
}

.chat-row:last-child {
  margin-bottom: 0;
}

.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1rem;
  gap: 0.75rem;
}

.chat-welcome-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
}

.chat-welcome h3 {
  margin: 0;
  font-size: 1.15rem;
  color: #1e293b;
}

.chat-welcome p {
  margin: 0;
  font-size: 0.85rem;
  color: #64748b;
  max-width: 280px;
  line-height: 1.5;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.5rem;
}

.chat-suggestions button {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chat-suggestions button:hover {
  border-color: #6366f1;
  color: #6366f1;
  background: #ede9fe;
}

.chat-row {
  display: flex;
  width: 100%;
}

.chat-row.user { justify-content: flex-end; }
.chat-row.bot { justify-content: flex-start; }

.chat-bubble {
  max-width: 75%;
  padding: 0.7rem 1rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-break: break-word;
}

.chat-bubble.user {
  background: #6366f1;
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-bubble.bot {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.chat-input-area {
  border-top: 1px solid #e2e8f0;
  background: #ffffff;
  padding: 0.75rem 1rem;
}

.chat-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.chat-input-wrap textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  min-height: 44px;
  max-height: 120px;
}

.chat-input-wrap textarea:focus {
  border-color: #6366f1;
}

.chat-mic-btn, .chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease, background 0.15s ease;
}

.chat-mic-btn {
  background: #f1f5f9;
  color: #64748b;
}

.chat-mic-btn:hover {
  background: #e2e8f0;
}

.chat-mic-btn.listening {
  background: #ef4444;
  color: white;
  animation: chatMicPulse 1.2s ease-in-out infinite;
}

@keyframes chatMicPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
}

.chat-send-btn {
  background: #6366f1;
  color: white;
}

.chat-send-btn:hover {
  background: #4f46e5;
}

.chat-mic-btn:active, .chat-send-btn:active {
  transform: scale(0.92);
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.6rem 1rem !important;
  min-width: 60px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: #cbd5e1;
  border-radius: 50%;
  animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

@media (max-width: 768px) {
  .assistant-container {
    height: calc(100vh - 56px - 64px);
  }
  .chat-bubble {
    max-width: 85%;
    font-size: 0.85rem;
  }
  .chat-input-area {
    padding: 0.6rem 0.75rem;
  }
}


/* ── Assistant Layout ─────────────────────────────────────── */
body.assistant-page {
  overflow: hidden;
}

body.assistant-page #page-content {
  overflow: hidden !important;
}

body.assistant-page .main-content {
  overflow: hidden;
}

.assistant-layout {
  display: flex;
  height: calc(100dvh - 60px);
  background: #f8fafc;
}

.assistant-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

.assistant-sidebar {
  width: 260px;
  background: #fff;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.assistant-new-btn {
  margin: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1.5px dashed #c7d2fe;
  background: #eef2ff;
  color: #4f46e5;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}

.assistant-new-btn:hover {
  background: #e0e7ff;
  border-color: #6366f1;
}

.assistant-conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.5rem 0.5rem;
}

.assistant-conv-item {
  position: relative;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 0.25rem;
  transition: background 0.15s ease;
}

.assistant-conv-item:hover {
  background: #f1f5f9;
}

.assistant-conv-item.active {
  background: #eef2ff;
}

.assistant-conv-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 1.5rem;
}

.assistant-conv-meta {
  font-size: 0.7rem;
  color: #94a3b8;
  margin-top: 2px;
}

.assistant-conv-delete {
  position: absolute;
  top: 50%;
  right: 0.4rem;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 0.7rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.assistant-conv-item:hover .assistant-conv-delete {
  display: flex;
}

.assistant-conv-delete:hover {
  background: #fee2e2;
  color: #ef4444;
}

/* Mobile drawer */
.assistant-sidebar-mobile-toggle {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  color: #64748b;
  font-size: 1rem;
  cursor: pointer;
}

@media (max-width: 768px) {
  body.assistant-page {
    overflow: hidden;
  }

  .assistant-layout {
    position: relative;
    height: auto;
  }

  .assistant-main {
    position: relative;
    overflow: hidden;
  }

  .assistant-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 20;
    box-shadow: 2px 0 12px rgba(0,0,0,0.1);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .assistant-sidebar.open {
    transform: translateX(0);
  }

  .assistant-sidebar-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .assistant-sidebar-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 15;
  }

  .assistant-sidebar-overlay.active {
    display: block;
  }

  .chat-messages {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  .chat-input-area {
    z-index: 5;
  }
}
