* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: #f4f6f8; color: #1f2933; }
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* Barre de chargement de navigation (haut de page) */
.route-loading {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0;
  background: #2563eb;
  z-index: 1000;
  opacity: 0;
  transition: width 0.2s ease-out, opacity 0.15s ease-out;
}
.route-loading.active {
  width: 70%;
  opacity: 1;
  transition: width 4s cubic-bezier(0.1, 0.8, 0.6, 1), opacity 0.15s ease-in;
}

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #1f2937; color: #e5e7eb; display: flex; flex-direction: column; }
.sidebar h1 { font-size: 18px; padding: 18px 16px; margin: 0; border-bottom: 1px solid #374151; }
.sidebar nav { flex: 1; padding: 8px 0; }
.sidebar nav a { display: block; padding: 10px 16px; color: #d1d5db; }
.sidebar nav a:hover { background: #374151; color: #fff; text-decoration: none; }
.sidebar nav a.active { background: #2563eb; color: #fff; }
.sidebar .user { padding: 12px 16px; border-top: 1px solid #374151; font-size: 13px; }
.sidebar .user .logout { margin-top: 8px; background: #b91c1c; color: #fff; border: 0; padding: 6px 10px; border-radius: 4px; width: 100%; }

.main { flex: 1; padding: 24px; overflow: auto; }
.main h2 { margin-top: 0; }

/* Login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #1f2937; }
.login-card { background: #fff; padding: 32px; border-radius: 8px; width: 360px; box-shadow: 0 10px 25px rgba(0,0,0,0.3); }
.login-card h1 { margin: 0 0 16px; font-size: 22px; }
.login-card label { display: block; margin: 12px 0 4px; font-size: 13px; color: #4b5563; }
.login-card input { width: 100%; padding: 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 14px; }
.login-card button { margin-top: 18px; width: 100%; padding: 10px; background: #2563eb; color: #fff; border: 0; border-radius: 4px; font-size: 15px; }
.login-card .err { color: #b91c1c; margin-top: 10px; font-size: 13px; min-height: 16px; }
.login-card .hint { margin-top: 14px; font-size: 12px; color: #6b7280; text-align: center; }

/* Cards */
.card { background: #fff; border-radius: 8px; padding: 16px 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); margin-bottom: 16px; }
.card h3 { margin-top: 0; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.kpi { background: #fff; padding: 16px 20px; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.kpi .label { font-size: 12px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; }
.kpi .value { font-size: 28px; font-weight: 600; margin-top: 6px; }

/* Tables */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 14px; }
.btn { padding: 8px 14px; border-radius: 4px; border: 0; background: #2563eb; color: #fff; font-size: 14px; }
.btn:hover { background: #1d4ed8; }
.btn.secondary { background: #6b7280; }
.btn.danger { background: #b91c1c; }
.btn.success { background: #059669; }
.btn.warn { background: #f59e0b; color: #fff; }

table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.06); table-layout: fixed; }
.table-wrap { overflow: auto; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); background: #fff; }
.table-wrap table { min-width: 800px; box-shadow: none; border-radius: 0; }
table th, table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #e5e7eb; font-size: 14px; overflow: hidden; }
table th { background: #f9fafb; font-weight: 600; color: #374151; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; position: relative; white-space: nowrap; }
table tr:hover td { background: #f9fafb; }
table tr:last-child td { border-bottom: 0; }
/* Troncature 2 lignes max */
.cell-txt { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; line-height: 1.4; }
/* Resize handle */
.col-resize-handle { position: absolute; right: 0; top: 0; width: 5px; height: 100%; cursor: col-resize; z-index: 2; }
.col-resize-handle:hover { background: rgba(37,99,235,0.35); }
/* Filtre colonne */
thead tr.filter-row th { background: #f3f4f6; padding: 3px 6px; }
.col-filter { width: 100%; padding: 3px 6px; border: 1px solid #d1d5db; border-radius: 3px; font-size: 11px; color: #374151; background: #fff; box-sizing: border-box; }
.col-filter:focus { outline: none; border-color: #2563eb; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 500; background: #e5e7eb; color: #374151; }
.badge.ok { background: #d1fae5; color: #065f46; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.err { background: #fee2e2; color: #991b1b; }
.badge-btn { border: none; cursor: pointer; font: inherit; }

.empty { padding: 40px; text-align: center; color: #6b7280; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; padding: 24px; border-radius: 8px; width: 420px; max-width: 90%; }
.modal h3 { margin-top: 0; }
.modal label { display: block; margin: 10px 0 4px; font-size: 13px; }
.modal input, .modal select { width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 14px; }
.modal-actions { margin-top: 18px; display: flex; gap: 8px; justify-content: flex-end; }
.import-result { margin-top: 14px; font-size: 13px; color: #374151; }
.import-result .err { margin-top: 6px; color: #b91c1c; }
.columns-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 6px 12px; max-height: 55vh; overflow: auto; padding: 4px 0; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; color: #374151; }
.check-row input { width: auto; }

/* Settings */
.settings-grid { display: grid; grid-template-columns: minmax(360px, 2fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.settings-section label { display: block; margin: 10px 0 4px; font-size: 13px; color: #4b5563; }
.settings-section select { width: 220px; max-width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 14px; background: #fff; }
.settings-section h4 { margin: 18px 0 8px; font-size: 14px; color: #374151; }
.settings-columns { max-height: 340px; border: 1px solid #e5e7eb; border-radius: 6px; padding: 10px; background: #f9fafb; }
.form-actions { margin-top: 14px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.settings-list { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 0 0 16px; font-size: 14px; }
.settings-list dt { color: #6b7280; }
.settings-list dd { margin: 0; color: #1f2933; overflow-wrap: anywhere; }
.settings-table-wrap { overflow: auto; }
.settings-table { box-shadow: none; border: 1px solid #e5e7eb; }
.settings-table th { width: 220px; text-transform: none; letter-spacing: 0; font-size: 14px; }
.settings-table td { overflow-wrap: anywhere; }

/* Tabs */
.tab-bar { display: flex; gap: 2px; border-bottom: 2px solid #e5e7eb; margin-bottom: 20px; }
.tab-link { padding: 10px 20px; font-size: 14px; font-weight: 500; color: #6b7280; text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tab-link:hover { color: #1f2937; text-decoration: none; }
.tab-link.active { color: #2563eb; border-bottom-color: #2563eb; }

/* Toast */
.toast { position: fixed; top: 20px; right: 20px; padding: 12px 18px; border-radius: 6px; background: #1f2937; color: #fff; font-size: 14px; z-index: 200; box-shadow: 0 6px 20px rgba(0,0,0,0.25); }
.toast.success { background: #059669; }
.toast.error { background: #b91c1c; }

/* Pagination */
.pagination { margin-top: 12px; display: flex; gap: 8px; align-items: center; }
.pagination button { padding: 6px 10px; border-radius: 4px; border: 1px solid #d1d5db; background: #fff; }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 900px) {
  .settings-grid { grid-template-columns: 1fr; }
}

/* Machine detail */
.machine-detail-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.machine-detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; margin-bottom: 16px; }
.detail-list { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.detail-list dt { color: #6b7280; font-weight: 500; align-self: start; padding-top: 1px; }
.detail-list dd { margin: 0; color: #1f2933; overflow-wrap: anywhere; }
.status-form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
tbody tr.clickable-row { cursor: pointer; }

/* Form elements in cards */
.card input, .card select, .card textarea {
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 14px;
}
.card label { display: block; margin: 10px 0 4px; font-size: 13px; color: #4b5563; }

/* ============================================================
   Classes utilitaires extraites des styles inline de app.js
   ============================================================ */

/* Alignement */
.tc { text-align: center; }
.tc-fw6 { text-align: center; font-weight: 600; }
.tc-muted { text-align: center; color: #6b7280; }
.tc-fw6-error { text-align: center; font-weight: 600; color: #b91c1c; }
.self-end { align-self: flex-end; }

/* Marges */
.m0 { margin: 0; }
.mt0 { margin-top: 0; }
.mt6 { margin-top: 6px; }
.mt8 { margin-top: 8px; }
.mt10 { margin-top: 10px; }
.mt12 { margin-top: 12px; }
.mt14 { margin-top: 14px; }
.mt20 { margin-top: 20px; }
.mb0 { margin-bottom: 0; }
.mb8 { margin-bottom: 8px; }
.mb12 { margin-bottom: 12px; }
.mb16 { margin-bottom: 16px; }
.mb-heading { margin: 0 0 8px; }
.ml8 { margin-left: 8px; }
.list-indent { margin: 4px 0; padding-left: 20px; }
.list-indent-tight { margin: 4px 0 0 0; padding-left: 18px; }
.p4-list { margin: 4px 0; padding-left: 20px; }

/* Paddings */
.pad4-8 { padding: 4px 8px; }
.pad4-8-left { padding: 4px 8px; text-align: left; }
.pad4-8-mono { padding: 4px 8px; font-family: monospace; }
.pad4-8-muted { padding: 4px 8px; color: #6b7280; }
.p16 { padding: 16px; }
.py8 { padding: 8px 0; }

/* Typographie */
.fw6 { font-weight: 600; }
.text-2xs-muted { font-size: 11px; color: #6b7280; }
.text-xs { font-size: 12px; }
.text-xs-muted { color: #6b7280; font-size: 12px; }
.text-xs-muted-nowrap { font-size: 12px; color: #6b7280; white-space: nowrap; }
.text-xs-overflow { font-size: 12px; max-width: 220px; word-break: break-all; }
.text-error-xs { color: #b91c1c; font-size: 12px; }
.text-sm { font-size: 13px; }
.text-muted { color: #6b7280; font-size: 13px; }
.text-muted-mb12 { color: #6b7280; font-size: 13px; margin-bottom: 12px; }
.text-muted-mt0 { color: #6b7280; font-size: 13px; margin-top: 0; }
.text-sm-light-muted { font-size: 13px; font-weight: normal; color: #6b7280; }
.text-base-plus { font-size: 15px; }
.text-lg { font-size: 16px; }
.text-ok { color: #059669; }
.text-ok-fw6 { color: #059669; font-weight: 600; }
.text-ok-mb8 { color: #059669; margin-bottom: 8px; }
.text-red { color: #dc2626; }
.text-red-fw6 { color: #dc2626; font-weight: 600; }
.text-orange { color: #d97706; }
.text-orange-fw6 { color: #d97706; font-weight: 600; }
.text-error { color: #b91c1c; }
.text-error-mb8 { color: #b91c1c; margin-bottom: 8px; }
.text-warn { color: #b45309; }
.text-warn-mb8 { color: #b45309; margin-bottom: 8px; }
.text-subtle { color: #9ca3af; }
.text-neutral { color: #374151; }
.text-green-dark { color: #166534; }
.text-amber-dark { color: #92400e; }
.heading-link { font-size: 13px; font-weight: normal; margin-left: 8px; }
.label-sm { font-size: 13px; display: block; margin-bottom: 3px; }
.label-sm-b4 { display: block; font-size: 13px; margin-bottom: 4px; }
.lh-sm { line-height: 1.8; }
.nowrap { white-space: nowrap; }
.pre-wrap { white-space: pre-wrap; }
.pre-wrap-mt8 { white-space: pre-wrap; margin-top: 8px; }
.opacity-70 { opacity: 0.7; }
.cursor-pointer { cursor: pointer; }
.cursor-noselect { cursor: pointer; user-select: none; }
.float-right-anim { float: right; transition: transform .2s; }

/* Flexbox */
.flex1 { flex: 1; margin: 0; }
.flex1-plain { flex: 1; }
.flex-1-min200 { flex: 1; min-width: 200px; }
.flex-g8 { display: flex; gap: 8px; }
.flex-g8-wrap { display: flex; gap: 8px; flex-wrap: wrap; }
.flex-sb-wrap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.flex-end { display: flex; gap: 8px; justify-content: flex-end; }
.flex-g10 { display: flex; gap: 10px; }
.flex-g24-mb16 { display: flex; gap: 24px; margin-bottom: 16px; }
.flex-center-g8 { display: flex; align-items: center; gap: 8px; }
.flex-wrap-g8 { flex-wrap: wrap; gap: 8px; }
.mt6-flex-center-wrap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.mt8-flex-center-g12 { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.mt12-flex-g8-wrap { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.mt16-flex-g10 { margin-top: 16px; display: flex; gap: 10px; }

/* Grilles */
.cards-auto-300 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.cards-5-mb12 { grid-template-columns: repeat(5, 1fr); margin-bottom: 12px; }
.cards-5-mb20 { grid-template-columns: repeat(5, 1fr); margin-bottom: 20px; }

@media (max-width: 900px) {
  .cards-5-mb12, .cards-5-mb20 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .cards-5-mb12, .cards-5-mb20 { grid-template-columns: 1fr; }
}
.grid-2-col-mb12 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin-bottom: 12px; }
.grid-3-col-mb8 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-bottom: 8px; }

/* Dimensions */
.w7em { width: 7em; }
.w70 { width: 70px; }
.w80 { width: 80px; }
.w110 { width: 110px; }
.w340-xs { width: 340px; font-size: 12px; }
.wauto-mb16 { width: auto; margin-bottom: 16px; }
.max-600 { max-width: 600px; }
.max-600-full { max-width: 600px; width: 100%; }
.max-520-full { max-width: 520px; width: 100%; }
.col-default { width: 160px; min-width: 60px; }
.scrollable-mt8 { margin-top: 8px; max-height: 200px; overflow-y: auto; border: 1px solid #e5e7eb; border-radius: 4px; }
.scrollable-lg { max-height: 360px; overflow-y: auto; }
.w-full-xs-mb16 { width: 100%; box-sizing: border-box; margin-bottom: 16px; font-size: 12px; }

/* Champs de saisie */
.input-sm { width: 100%; padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 13px; box-sizing: border-box; }
.input-sm-disabled { width: 100%; padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 13px; background: #f9fafb; color: #6b7280; box-sizing: border-box; }
.input-md { padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 14px; }
.input-base { padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 14px; }
.input-full { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 14px; margin-bottom: 8px; }
.input-full-md { width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 14px; }
.textarea-sm { width: 100%; padding: 8px; border: 1px solid #d1d5db; border-radius: 4px; min-height: 60px; }
.textarea-md { width: 100%; padding: 8px; border: 1px solid #d1d5db; border-radius: 4px; min-height: 80px; }
.textarea-mb12 { width: 100%; padding: 8px; border: 1px solid #d1d5db; border-radius: 4px; margin-bottom: 12px; }
.textarea-mono { width: 100%; box-sizing: border-box; padding: 8px; border: 1px solid #d1d5db; border-radius: 4px; font-family: monospace; font-size: 13px; resize: vertical; }

/* Boutons petits */
.btn.sm { font-size: 12px; padding: 2px 8px; }
.btn.xs { font-size: 11px; padding: 2px 6px; }
.btn-sm { font-size: 12px; padding: 2px 8px; }
.btn-xs { font-size: 11px; padding: 2px 6px; }

/* Liens KPI cliquables */
a.kpi { text-decoration: none; color: inherit; cursor: pointer; }

/* Combinaisons fréquentes */
.mt8-muted { margin-top: 8px; color: #6b7280; }
.mt8-text-muted { margin-top: 8px; color: #6b7280; font-size: 13px; }
.mt8-text-xs-muted { font-size: 12px; color: #6b7280; margin-top: 8px; }
.mt8-text-xs-muted-2 { margin-top: 8px; color: #6b7280; font-size: 12px; }
.dialog-title { margin: 0 0 8px; font-size: 16px; }
.dialog-body { margin: 0 0 16px; font-size: 14px; color: #374151; }
.form-error { color: #b91c1c; font-size: 13px; min-height: 18px; margin-bottom: 12px; }
.td-overflow { font-size: 12px; color: #6b7280; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Tableau interne */
.bg-faint { background: #f9fafb; }
.border-top-faint { border-top: 1px solid #f3f4f6; }
.table-compact { width: 100%; border-collapse: collapse; font-size: 12px; }

/* Boîtes colorées */
.anomaly-panel { background: #fffbeb; border: 1px solid #fde68a; }
.anomaly-ok { background: #d1fae5; border: 1px solid #6ee7b7; padding: 12px 20px; color: #065f46; }
.anomaly-heading { margin-top: 0; color: #92400e; }
.anomaly-link { color: #92400e; font-weight: 600; text-decoration: none; }
.anomaly-note-text { margin: 0; color: #92400e; font-size: 14px; }
.anomaly-warn-banner { margin-top: 12px; padding: 8px 12px; background: #fef3c7; border-radius: 6px; font-size: 13px; color: #92400e; }
.warn-box-nm { background: #fef3c7; border: 1px solid #f59e0b; margin-bottom: 0; }

/* Barre client global */
.client-bar { display: flex; align-items: center; gap: 10px; padding: 10px 0 14px; border-bottom: 1px solid #e5e7eb; margin-bottom: 14px; }
.client-bar-label { font-weight: 600; white-space: nowrap; }
.client-select { min-width: 150px; }

/* Labels de case à cocher */
.check-label { display: inline-flex; align-items: center; gap: 3px; margin: 2px 8px 2px 0; font-size: 12px; cursor: pointer; white-space: nowrap; }
.check-label-emph { display: inline-flex; align-items: center; gap: 3px; margin: 2px 8px 2px 0; font-size: 12px; cursor: pointer; white-space: nowrap; font-weight: 600; color: #92400e; }

/* Boîte modale de confirmation */
.confirm-dialog-inner { background: #fff; border-radius: 8px; padding: 28px 32px; width: 360px; box-shadow: 0 8px 32px rgba(0,0,0,.18); }

/* Panneau de résultat de validation de livraison */
.result-panel { border-left: 4px solid transparent; }
.result-panel--ok { border-left-color: #059669; }
.result-panel--warn { border-left-color: #f59e0b; }
.result-panel--error { border-left-color: #b91c1c; }

/* Barre de conclusion de simulation */
.conclusion-bar { margin-top: 10px; padding-top: 8px; border-top: 1px solid #bae6fd; }

/* Panneau de résultat de simulation */
.simulate-panel { margin-bottom: 12px; padding: 12px; border-radius: 6px; background: #f0f9ff; border: 1px solid #bae6fd; font-size: 13px; }

/* Barre de filtre production */
.toolbar-row { margin-bottom: 12px; margin-top: 12px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
