/* ─── RESET & BASE ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-card-hover: #1b2847;
  --bg-input: #0f1729;
  --accent: #C5A55A;
  --accent-hover: #d4b86a;
  --accent-dim: rgba(197, 165, 90, 0.15);
  --accent-border: rgba(197, 165, 90, 0.25);
  --text: #e0e0e0;
  --text-muted: #8a8fa8;
  --text-faint: #5a5f78;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --green: #4ade80;
  --green-bg: rgba(74, 222, 128, 0.12);
  --orange: #fb923c;
  --orange-bg: rgba(251, 146, 60, 0.12);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.12);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --nav-h: 56px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* ─── NAVBAR ────────────────────────────────────────────── */
.navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.nav-logo { width: auto; height: 30px; object-fit: contain; }

.nav-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.nav-btn.active { color: var(--accent); background: var(--accent-dim); }
.nav-btn-icon { padding: 8px 10px; }
.nav-btn-icon svg { opacity: 0.7; }
.nav-btn.active svg, .nav-btn:hover svg { opacity: 1; }

/* ─── SUB-TABS (ex: Historique > Mouvements / Sorties factures) ────── */
.sub-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.sub-tab-btn {
  background: var(--card-bg, rgba(255, 255, 255, 0.03));
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.sub-tab-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.sub-tab-btn.active { color: var(--accent); background: var(--accent-dim); border-color: var(--accent); }

/* ─── SCREENS ───────────────────────────────────────────── */
.screen {
  display: none;
  padding: calc(var(--nav-h) + 16px) 16px 80px;
  max-width: 960px;
  margin: 0 auto;
  animation: fadeIn 200ms ease;
}

.screen.active { display: block; }

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

.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.screen-header h1,
.screen-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}


/* ─── KPI sections (Bouteilles / Magnums) ────────────────── */
.kpi-section {
  margin-bottom: 12px;
}
.kpi-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 6px;
  padding-left: 2px;
}
/* ─── KPI ROW ───────────────────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.kpi-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.kpi-value {
  display: block;
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums lining-nums;
}

/* ─── CARDS ─────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* ─── TABLES ────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -16px;
  padding: 0 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums lining-nums;
}

thead th {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-strong);
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}

th.num, td.num { text-align: right; }
th.center, td.center { text-align: center; }

/* Modele deux bacs (D2) : valeur apposees negative = ecart a signaler */
td.negative-alert { color: var(--red); font-weight: 600; }

tbody td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
tbody tr:last-child td { border-bottom: none; }

.loading-cell {
  text-align: center;
  padding: 32px !important;
}

/* ─── STATUS BADGES ─────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

.badge-ok { background: var(--green-bg); color: var(--green); }
.badge-warning { background: var(--orange-bg); color: var(--orange); }
.badge-danger { background: var(--red-bg); color: var(--red); }

/* ─── BUTTONS ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 44px;
  min-width: 44px;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: #1a1a2e;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
}
.btn-outline:hover:not(:disabled) { border-color: var(--accent-border); color: var(--text); }

.btn-warning {
  background: var(--orange);
  color: #1a1a2e;
  font-weight: 600;
}
.btn-warning:hover:not(:disabled) { background: #faa84e; }

.btn-lg { width: 100%; padding: 14px 24px; font-size: 14px; min-height: 48px; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 12px; }

/* ─── FORM ELEMENTS ─────────────────────────────────────── */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.label-optional { color: var(--text-faint); font-weight: 400; }

.input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 12px;
  min-height: 44px;
  transition: border-color var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.input-sm { min-height: 36px; padding: 6px 10px; font-size: 12px; }

/* appearance: none casse le selecteur natif des champs date (icone/segments
   non cliquables) sur Chrome/Edge ; on le restaure pour ces types, et
   color-scheme: dark rend l'icone (sinon noire, invisible sur fond sombre)
   visible sur --bg-input. */
input[type="date"].input,
input[type="datetime-local"].input,
input[type="time"].input,
input[type="month"].input,
input[type="week"].input {
  appearance: auto;
  -webkit-appearance: auto;
  color-scheme: dark;
}

select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%238a8fa8'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 32px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ─── ADJUSTMENT ────────────────────────────────────────── */
.adj-current-display {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  display: flex;
  align-items: center;
  font-variant-numeric: tabular-nums;
}

.adj-ecart {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 14px;
  display: none;
}

.adj-ecart.positive { display: block; background: var(--green-bg); color: var(--green); }
.adj-ecart.negative { display: block; background: var(--red-bg); color: var(--red); }
.adj-ecart.zero { display: block; background: rgba(255,255,255,0.05); color: var(--text-muted); }

/* ─── FILTERS ───────────────────────────────────────────── */
.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.filter-row .input { width: auto; min-width: 140px; flex: 1; }

/* ─── HISTORY TYPE ICONS ────────────────────────────────── */
.type-icon {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.type-icon .icon { font-size: 14px; }

/* ─── TOAST ─────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: calc(var(--nav-h) + 10px);
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 360px;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  pointer-events: auto;
  animation: toastIn 300ms ease, toastOut 300ms ease 3700ms forwards;
  box-shadow: var(--shadow);
  word-break: break-word;
}

.toast-success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(74,222,128,0.25); }
.toast-warning { background: var(--orange-bg); color: var(--orange); border: 1px solid rgba(251,146,60,0.25); }
.toast-error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(248,113,113,0.25); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

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

/* ─── MODAL ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  animation: modalIn 200ms ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}

.modal-body {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 20px;
}

.modal-body .recap-line {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}

.modal-body .recap-line:last-child { border-bottom: none; }
.modal-body .recap-label { color: var(--text-muted); }
.modal-body .recap-value { color: var(--text); font-weight: 600; }

.modal-body .recap-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--accent-border);
}

.modal-body .recap-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--orange);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ─── SPINNER ───────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
  display: inline-block;
}

.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

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

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.7);
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─── UTILITIES ─────────────────────────────────────────── */
.hidden { display: none !important; }
.flex-1 { flex: 1; min-width: 0; }
.text-accent { color: var(--accent); }

.movement-card, .adjustment-card { margin-bottom: 16px; }

/* ─── SETTINGS ──────────────────────────────────────────── */
.settings-note {
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  margin-top: 12px;
}

#settings-seuils .form-row {
  margin-bottom: 10px;
}

#settings-seuils .seuil-label {
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  min-height: 44px;
}

/* ─── DOSAGE SETTINGS ─────────────────────────────── */
.dosage-group-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 10px 0 6px;
  border-bottom: 1px solid var(--accent-border);
  margin-bottom: 8px;
}
.dosage-group-label:first-child {
  padding-top: 0;
}
.dosage-row {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 12px;
  align-items: center;
  margin-bottom: 6px;
}
.dosage-row .dosage-name {
  font-size: 13px;
  color: var(--text);
}
.dosage-row .dosage-format {
  font-size: 11px;
  color: var(--text-faint);
  margin-left: 4px;
}
.dosage-row .input {
  min-height: 38px;
  padding: 6px 10px;
  font-size: 13px;
  text-align: right;
}
.dosage-lejeune-note {
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--accent-border);
}

/* ─── HISTORY NOTES ─────────────────────────────────────── */
.note-text {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trajet {
  font-size: 12px;
  white-space: nowrap;
}

.trajet .arrow { color: var(--accent); margin: 0 3px; }

/* ─── PRODUCT GROUP SEPARATOR ──────────────────────────── */
.group-separator td {
  padding: 6px 10px !important;
  border-bottom: none !important;
  background: transparent !important;
}
.group-separator td::after {
  content: '';
  display: block;
  width: 100%;
  height: 1px;
  background: var(--accent-border);
}
.group-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 10px 10px 4px !important;
  border-bottom: none !important;
  background: transparent !important;
}
.group-label.first {
  padding-top: 4px !important;
}

/* ─── PRODUCT OPTION STOCK DISPLAY ──────────────────────── */
.stock-hint {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}



/* ─── MULTI-LINE MOVEMENT FORM ─────────────────────────── */
.movement-lines-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.ml-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.line-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  animation: lineSlideIn 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes lineSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.line-row .form-group {
  margin-bottom: 0;
}

.line-product {
  flex: 3;
  min-width: 0;
}

.line-qty {
  flex: 1;
  min-width: 70px;
  max-width: 100px;
}

.line-notes {
  flex: 2;
  min-width: 0;
}

.line-notes-input::placeholder {
  font-style: italic;
  font-size: 12px;
}

.line-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
  flex-shrink: 0;
}

.line-remove:hover {
  color: var(--red);
  border-color: rgba(248, 113, 113, 0.3);
  background: var(--red-bg);
}

.line-remove.invisible {
  visibility: hidden;
}

.btn-add-line {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  justify-content: center;
  padding: 10px;
  margin: 10px 0 16px;
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--accent-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-add-line:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

/* Recap batch lines in modal */
.recap-batch-table {
  width: 100%;
  font-size: 13px;
  border-collapse: collapse;
  margin: 8px 0;
}

.recap-batch-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.recap-batch-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.recap-batch-table .num { text-align: right; }
.recap-batch-total {
  font-weight: 600;
  color: var(--accent);
}

/* ─── ACTION ICON BUTTONS ──────────────────────────────── */
.actions-col {
  width: 80px;
  min-width: 80px;
}

.actions-cell {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--accent-dim);
  border-color: var(--accent-border);
  color: var(--accent);
}

.btn-edit:hover {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-dim);
}

.btn-delete:hover {
  color: var(--red);
  border-color: rgba(248, 113, 113, 0.3);
  background: var(--red-bg);
}

.btn-icon svg {
  flex-shrink: 0;
}

/* ─── EDIT MODAL INFO ──────────────────────────────────── */
.edit-info {
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--accent);
}

/* ─── FOOTER ────────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 11px;
}

.app-footer a {
  color: var(--text-faint);
  text-decoration: none;
  transition: color var(--transition);
}

.app-footer a:hover { color: var(--text-muted); }

/* ─── RESPONSIVE ────────────────────────────────────────── */
@media (max-width: 600px) {
  .nav-title { display: none; }
  .nav-links { gap: 2px; }
  .nav-btn { padding: 8px 10px; font-size: 12px; }
  .kpi-row { grid-template-columns: 1fr; gap: 8px; }
  .kpi-card { padding: 12px; }
  .kpi-value { font-size: 24px; }
  .form-row { grid-template-columns: 1fr; gap: 8px; }
  .screen { padding-left: 12px; padding-right: 12px; }
  .filter-row { flex-direction: column; }
  .filter-row .input { width: 100%; min-width: unset; }
  .modal { padding: 18px; margin: 12px; }
  .line-row { flex-wrap: wrap; }
  .line-product { flex: 1 1 100%; }
  .line-qty { flex: 0 0 70px; }
  .line-notes { flex: 1; min-width: 80px; }
  table { font-size: 12px; }
  thead th, tbody td { padding: 8px 6px; }
}

@media (min-width: 601px) and (max-width: 768px) {
  .kpi-row { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 769px) {
  .screen { padding-left: 24px; padding-right: 24px; }
  .card { padding: 20px; }
}

/* ─── Column filter on click ─────────────────────────────── */
th.filterable {
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: color 0.2s, background 0.2s;
}
th.filterable:hover {
  color: var(--accent);
}
th.filterable::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-left: 6px;
  vertical-align: middle;
  opacity: 0;
  background: var(--accent);
  transition: opacity 0.2s;
}
th.filterable.filter-active {
  color: var(--accent);
  background: rgba(197, 165, 90, 0.08);
}
th.filterable.filter-active::after {
  opacity: 1;
}
tr.filtered-out {
  display: none;
}
.filter-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  background: rgba(197, 165, 90, 0.12);
  border: 1px solid rgba(197, 165, 90, 0.25);
  border-radius: 12px;
  padding: 2px 10px;
  margin-left: 12px;
  cursor: pointer;
  vertical-align: middle;
  transition: background 0.2s;
}
.filter-badge:hover {
  background: rgba(197, 165, 90, 0.22);
}


/* ─── Batch action bar ───────────────────────────────────── */
.batch-bar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  margin-bottom: 8px;
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-size: 14px;
}
.batch-bar.visible { display: flex; }
.btn-danger {
  background: #dc3545;
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.btn-danger:hover { background: #c82333; }

/* Checkbox column */
.check-col { width: 32px; text-align: center; }
.check-cell { width: 32px; text-align: center; padding: 4px !important; }
.row-check { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ─── Responsive table improvements ──────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
table {
  width: 100%;
  table-layout: auto;
}

/* Prevent content from forcing horizontal scroll */
.note-text {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}
.trajet {
  white-space: nowrap;
  font-size: 0.85em;
}
.type-cell { white-space: nowrap; font-size: 0.85em; }
.prod-cell { white-space: nowrap; }
.date-cell { white-space: nowrap; }
.qty-cell { white-space: nowrap; }

@media (max-width: 600px) {
  /* Make tables more compact on mobile */
  table { font-size: 11px; }
  thead th, tbody td { padding: 6px 4px; }
  .actions-cell { white-space: nowrap; }
  .btn-icon { padding: 4px; min-width: 28px; }
  .note-text { max-width: 60px; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .kpi-card { padding: 10px; }
  .kpi-value { font-size: 20px; }
  .kpi-label { font-size: 10px; }
  .trajet .arrow { margin: 0 2px; }
  .batch-bar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .filter-row { gap: 6px; }
  .screen-header h1 { font-size: 20px; }
}

@media (max-width: 400px) {
  table { font-size: 10px; }
  thead th, tbody td { padding: 4px 3px; }
  .note-text { max-width: 40px; }
  .screen { padding-left: 8px; padding-right: 8px; }
}

/* ─── Clickable Cuvée/Consommable Links ───────────────── */
.cuvee-link {
  color: #C5A55A;
  text-decoration: none;
  cursor: pointer;
  border-bottom: 1px dashed rgba(197, 165, 90, 0.4);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.cuvee-link:hover {
  color: #ddc07a;
  border-bottom-color: rgba(197, 165, 90, 0.8);
}
.cuvee-link:active {
  color: #b89545;
}


/* ═══════════════════════════════════════════════════════════════
   COMMANDES MODULE - Kanban + Forms
   ═══════════════════════════════════════════════════════════════ */

/* ─── KPI Row ──────────────────────────────────────────────── */
.cmd-kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.cmd-kpi-card {
  border-radius: 10px;
  padding: 14px 16px;
  text-align: center;
  border: 1px solid rgba(255,255,255,0.06);
}
.cmd-kpi-card .kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #a0a0a0;
  margin-bottom: 4px;
}
.cmd-kpi-card .kpi-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}
.cmd-kpi-card .kpi-sub {
  font-size: 11px;
  color: #a0a0a0;
  margin-top: 2px;
}
.cmd-kpi-orange { background: rgba(255,152,0,0.08); }
.cmd-kpi-orange .kpi-value { color: #ff9800; }
.cmd-kpi-red { background: rgba(244,67,54,0.08); }
.cmd-kpi-red .kpi-value { color: #f44336; }
.cmd-kpi-green { background: rgba(76,175,80,0.08); }
.cmd-kpi-green .kpi-value { color: #4caf50; }
.cmd-kpi-blue { background: rgba(33,150,243,0.08); }
.cmd-kpi-blue .kpi-value { color: #2196f3; }

/* ─── Kanban Board ──────────────────────────────────────────── */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  min-height: 400px;
}
.kanban-col {
  background: rgba(255,255,255,0.02);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  min-height: 300px;
}
.kanban-col-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  border-radius: 10px 10px 0 0;
  letter-spacing: 0.3px;
}
.kanban-header-orange { background: rgba(255,152,0,0.15); color: #ffb74d; }
.kanban-header-green  { background: rgba(76,175,80,0.15); color: #81c784; }
.kanban-header-blue   { background: rgba(33,150,243,0.15); color: #64b5f6; }
.kanban-count {
  background: rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
}
.kanban-cards {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ─── Kanban Card ───────────────────────────────────────────── */
.cmd-card {
  background: #16213e;
  border-radius: 8px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.06);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.cmd-card:hover {
  border-color: rgba(197,165,90,0.3);
  transform: translateY(-1px);
}
.cmd-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.cmd-card-ref {
  font-size: 11px;
  color: #C5A55A;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.cmd-card-client {
  font-weight: 600;
  font-size: 14px;
  color: #e0e0e0;
  margin-bottom: 6px;
}
.cmd-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.badge-urgent {
  background: rgba(244,67,54,0.2);
  color: #f44336;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}
.badge-btl {
  font-size: 11px;
  color: #a0a0a0;
}
.badge-deadline {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}
.deadline-ok     { background: rgba(76,175,80,0.15); color: #81c784; }
.deadline-soon   { background: rgba(255,152,0,0.15); color: #ffb74d; }
.deadline-late   { background: rgba(244,67,54,0.2); color: #f44336; }

.cmd-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.cmd-card-actions .btn {
  font-size: 11px;
  padding: 4px 10px;
}
.btn-advance {
  background: rgba(76,175,80,0.15);
  color: #81c784;
  border: 1px solid rgba(76,175,80,0.3);
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  padding: 4px 10px;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-advance:hover { background: rgba(76,175,80,0.25); }
.btn-back {
  background: transparent;
  color: #888;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  padding: 4px 8px;
  transition: color 0.15s;
}
.btn-back:hover { color: #ccc; }

/* ─── Commande Form ──────────────────────────────────────── */
.form-card {
  max-width: 800px;
}
.form-row {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
}
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.btn-sm {
  font-size: 12px;
  padding: 4px 12px;
}

/* Toggle urgence */
.toggle-urgence {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
}
.toggle-btn {
  flex: 1;
  padding: 8px 12px;
  background: transparent;
  color: #a0a0a0;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}
.toggle-btn.active {
  background: rgba(197,165,90,0.15);
  color: #C5A55A;
  font-weight: 600;
}
.toggle-btn:hover:not(.active) {
  background: rgba(255,255,255,0.04);
}

/* Commande line row */
.cmd-line-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  background: rgba(255,255,255,0.02);
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.04);
}
.cmd-line-row select,
.cmd-line-row input {
  flex: 1;
}
.cmd-line-row .cmd-line-qty {
  max-width: 90px;
}
.cmd-line-remove {
  background: transparent;
  border: none;
  color: #f44336;
  cursor: pointer;
  font-size: 18px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s;
}
.cmd-line-remove:hover {
  background: rgba(244,67,54,0.15);
}

/* New client fields */
.new-client-fields {
  background: rgba(197,165,90,0.05);
  border: 1px dashed rgba(197,165,90,0.2);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

/* ─── Detail Modal ────────────────────────────────────────── */
.detail-section {
  margin-bottom: 16px;
}
.detail-section h4 {
  font-size: 12px;
  text-transform: uppercase;
  color: #C5A55A;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.detail-item {
  font-size: 13px;
}
.detail-item .dlabel {
  color: #888;
  font-size: 11px;
}
.detail-item .dvalue {
  color: #e0e0e0;
  font-weight: 500;
}
.detail-lines-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.detail-lines-table th {
  text-align: left;
  color: #888;
  font-weight: 500;
  padding: 4px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 11px;
  text-transform: uppercase;
}
.detail-lines-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.hist-timeline {
  font-size: 12px;
}
.hist-entry {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.hist-entry:last-child { border-bottom: none; }
.hist-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.hist-dot-orange { background: #ff9800; }
.hist-dot-green  { background: #4caf50; }
.hist-dot-blue   { background: #2196f3; }

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .kanban-board {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .kanban-col {
    min-height: 150px;
  }
  .cmd-kpi-row {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 600px) {
  .form-row {
    flex-direction: column;
    gap: 8px;
  }
  .cmd-kpi-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .cmd-kpi-card .kpi-value {
    font-size: 22px;
  }
  .screen-header {
    flex-wrap: wrap;
    gap: 8px;
  }
}


/* ═══════════════════════════════════════════════════════════════
   COMMANDES V2: Fiche, Chat, Files, Badges
   ═══════════════════════════════════════════════════════════════ */

/* ─── Nav Badge ────────────────────────────────────────────── */
.nav-badge {
  background: #f44336;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 5px;
  margin-left: 6px;
  min-width: 16px;
  text-align: center;
  display: inline-block;
  line-height: 14px;
  animation: badge-pulse 2s infinite;
}
.nav-badge.hidden { display: none; }
@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ─── Unseen dot on kanban cards ──────────────────────────── */
.unseen-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f44336;
  display: inline-block;
  animation: badge-pulse 1.5s infinite;
  flex-shrink: 0;
}

/* ─── Fiche Commande Screen ──────────────────────────────── */
.fiche-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.fiche-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.fiche-statut-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.statut-a-preparer { background: rgba(255,152,0,0.2); color: #ffb74d; }
.statut-prete { background: rgba(76,175,80,0.2); color: #81c784; }
.statut-expediee { background: rgba(33,150,243,0.2); color: #64b5f6; }

.fiche-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 16px;
  margin-top: 8px;
}
.fiche-col-main { display: flex; flex-direction: column; gap: 12px; }
.fiche-col-chat { display: flex; flex-direction: column; gap: 12px; }

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: #C5A55A;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.card-header-row .card-title { margin-bottom: 0; }
.fiche-info-card .form-row { margin-bottom: 8px; }

/* ─── Chat ────────────────────────────────────────────────── */
.chat-card {
  display: flex;
  flex-direction: column;
  min-height: 300px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  max-height: 350px;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.chat-msg {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
}
.chat-msg-patron {
  background: rgba(197,165,90,0.1);
  border-left: 3px solid #C5A55A;
  align-self: flex-start;
  max-width: 90%;
}
.chat-msg-preparateur {
  background: rgba(33,150,243,0.1);
  border-left: 3px solid #2196f3;
  align-self: flex-end;
  max-width: 90%;
}
.chat-msg-author {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}
.chat-msg-patron .chat-msg-author { color: #C5A55A; }
.chat-msg-preparateur .chat-msg-author { color: #64b5f6; }
.chat-msg-date {
  font-size: 10px;
  color: #888;
  float: right;
  margin-left: 8px;
}
.chat-msg-text {
  color: #ddd;
  line-height: 1.4;
}
.chat-input-row {
  display: flex;
  gap: 8px;
}
.chat-input {
  flex: 1;
}
.chat-empty {
  text-align: center;
  color: #666;
  font-size: 12px;
  padding: 30px 0;
}

/* ─── Files ───────────────────────────────────────────────── */
.file-drop-zone {
  border: 2px dashed rgba(197,165,90,0.2);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  color: #666;
  font-size: 12px;
  margin-bottom: 10px;
  transition: border-color 0.2s, background 0.2s;
}
.file-drop-zone.drag-over {
  border-color: #C5A55A;
  background: rgba(197,165,90,0.05);
}
.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: rgba(255,255,255,0.02);
  border-radius: 6px;
  margin-bottom: 6px;
  border: 1px solid rgba(255,255,255,0.04);
}
.file-item-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
a.file-item-name {
  font-size: 13px;
  color: #C5A55A;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
  cursor: pointer;
  display: block;
}
a.file-item-name:hover {
  color: #ddc07a;
  text-decoration: underline;
}
.file-item-meta {
  font-size: 10px;
  color: #888;
  white-space: nowrap;
}
.file-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.file-item-actions button {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.08);
  color: #aaa;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: color 0.15s;
}
.file-item-actions button:hover { color: #fff; }
.file-item-actions .file-delete:hover { color: #f44336; }

/* ─── Role Bar ────────────────────────────────────────────── */
.role-bar {
  position: fixed;
  bottom: 12px;
  right: 12px;
  background: #16213e;
  border: 1px solid rgba(197,165,90,0.3);
  border-radius: 8px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.role-label {
  font-size: 11px;
  color: #C5A55A;
  font-weight: 600;
}
.role-select {
  font-size: 12px;
  padding: 4px 8px;
  min-width: 120px;
}

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .fiche-grid {
    grid-template-columns: 1fr;
  }
  .fiche-col-chat {
    order: -1;
  }
  .chat-messages {
    max-height: 200px;
  }
}
@media (max-width: 600px) {
  .fiche-header-left,
  .fiche-header-right {
    flex-wrap: wrap;
    gap: 6px;
  }
  .role-bar {
    bottom: 60px;
    right: 8px;
  }
}

/* ─── Danger Button ───────────────────────────────────────── */
.btn-danger {
  background: rgba(244,67,54,0.15);
  color: #f44336;
  border: 1px solid rgba(244,67,54,0.3);
}
.btn-danger:hover {
  background: rgba(244,67,54,0.25);
}

/* ─── System Messages in Chat ─────────────────────────────── */
.chat-msg-system {
  background: rgba(255,255,255,0.03);
  border-left: 3px solid #555;
  align-self: stretch;
  max-width: 100%;
  font-style: italic;
}
.chat-msg-system .chat-msg-author {
  color: #888;
  font-size: 9px;
}
.chat-msg-system .chat-msg-text {
  color: #999;
  font-size: 12px;
}
.chat-msg-system .sys-icon {
  margin-right: 4px;
  font-style: normal;
}

/* ─── Notion Link ─────────────────────────────────────────── */
.notion-link {
  font-size: 12px;
  font-weight: 600;
  color: #C5A55A;
  text-decoration: none;
  padding: 3px 8px;
  border: 1px solid rgba(197,165,90,0.3);
  border-radius: 5px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.notion-link:hover {
  background: rgba(197,165,90,0.12);
  color: #ddc07a;
}
.notion-link.disabled {
  color: #666;
  border-color: rgba(255,255,255,0.08);
  cursor: default;
  pointer-events: none;
}

/* ─── File Attach Button (gold) ───────────────────────────── */
#fiche-file-btn,
#cmd-drop-zone + label {
  color: #C5A55A;
  border-color: rgba(197,165,90,0.3);
  cursor: pointer;
}
#fiche-file-btn:hover,
#cmd-drop-zone + label:hover {
  background: rgba(197,165,90,0.1);
  border-color: #C5A55A;
  color: #ddc07a;
}

/* ─── Fullscreen Drop Overlay ─────────────────────────────── */
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(197,165,90,0.08);
  border: 3px dashed #C5A55A;
  border-radius: 12px;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drop-overlay.hidden { display: none; }
.drop-overlay-content {
  font-size: 20px;
  font-weight: 600;
  color: #C5A55A;
  background: rgba(22,33,62,0.9);
  padding: 20px 40px;
  border-radius: 10px;
}
#screen-fiche-commande {
  position: relative;
}

/* Bannière alertes stock bas */
.alert-banner {
  background: #fff3cd;
  color: #7a5b00;
  border: 1px solid #ffe08a;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 8px 0;
  font-weight: 600;
}

/* Champ éditable seuil d'alerte dans les tableaux dashboard */
.seuil-input {
  width: 64px;
  padding: 4px 6px;
  text-align: center;
  border: 1px solid var(--border, #d9d9d9);
  border-radius: 6px;
  font-size: 0.9em;
  background: #fff;
}
.seuil-input:focus {
  outline: none;
  border-color: #7a5b00;
}
