/* =========================================================================
   BRAISEMASTER V2 — SYSTÈME DE DESIGN
   Palette : anthracite chaleureux + accent flamme + pastels doux
   ========================================================================= */

/* Import typographies */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* ================ FONDS ================ */
  --bg: #fafaf9;              /* fond app légèrement chaud */
  --bg-alt: #f5f4f2;          /* zone secondaire */
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --bg-header: rgba(255,255,255,0.85);

  /* ================ BORDS ================ */
  --border: #eae8e4;
  --border-strong: #d6d3ce;
  --border-focus: #f97316;

  /* ================ TEXTES ================ */
  --text: #1c1917;            /* stone-900 */
  --text-2: #57534e;           /* stone-600 */
  --text-muted: #a8a29e;       /* stone-400 */
  --text-inverse: #fafaf9;

  /* ================ ACCENTS ================ */
  /* Primary : flamme BraiseMaster orange chaleureux */
  --primary: #ea580c;          /* orange-600 */
  --primary-hover: #c2410c;    /* orange-700 */
  --primary-active: #9a3412;   /* orange-800 */
  --primary-light: #fff7ed;    /* orange-50 */
  --primary-tint: #ffedd5;     /* orange-100 */
  --primary-glow: rgba(234,88,12,0.18);

  /* Secondary : indigo profond pour actions techniques */
  --secondary: #4f46e5;
  --secondary-hover: #4338ca;
  --secondary-light: #eef2ff;

  /* Brand marker (rappel identité orange BraiseMaster) */
  --brand: #ea580c;
  --brand-light: #fff7ed;

  /* États sémantiques */
  --success: #16a34a;
  --success-light: #f0fdf4;
  --success-strong: #15803d;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --info: #0284c7;
  --info-light: #f0f9ff;

  /* ================ FORMES ================ */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* ================ OMBRES ================ */
  --shadow-xs: 0 1px 2px rgba(28,25,23,0.04);
  --shadow-sm: 0 1px 3px rgba(28,25,23,0.06), 0 1px 2px rgba(28,25,23,0.04);
  --shadow: 0 4px 8px -2px rgba(28,25,23,0.06), 0 2px 4px -2px rgba(28,25,23,0.04);
  --shadow-md: 0 8px 16px -4px rgba(28,25,23,0.08), 0 3px 6px -3px rgba(28,25,23,0.04);
  --shadow-lg: 0 16px 32px -8px rgba(28,25,23,0.1), 0 4px 12px -4px rgba(28,25,23,0.06);
  --shadow-xl: 0 24px 48px -12px rgba(28,25,23,0.14);
  --shadow-glow: 0 0 0 4px var(--primary-glow);

  /* ================ TYPO ================ */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', "SF Mono", Menlo, Monaco, Consolas, monospace;

  /* ================ TRANSITIONS ================ */
  --t-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  --t: 180ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'ss01', 'cv02', 'cv11';
}

/* ================ HEADER ================ */
.top-header {
  background: var(--bg-header);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.brand-block { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: var(--radius);
  background: linear-gradient(135deg, #f97316 0%, #dc2626 100%);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px;
  box-shadow: 0 4px 12px rgba(234,88,12,0.28), inset 0 1px 0 rgba(255,255,255,0.2);
}
.brand-name { font-weight: 700; font-size: 15.5px; letter-spacing: -0.02em; color: var(--text); }
.brand-sub { color: var(--text-muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 500; margin-top: 1px; }

.header-right { display: flex; align-items: center; gap: 10px; }
.presence-badge, .sync-badge {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: var(--radius-full);
  background: var(--bg-card); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-2); font-weight: 500;
  box-shadow: var(--shadow-xs);
}
.presence-dot { width: 8px; height: 8px; border-radius: 50%; background: #d6d3ce; }
.presence-dot.online { background: var(--success); box-shadow: 0 0 0 3px rgba(22,163,74,0.18); }

/* ================ NAVIGATION ================ */
.nav-modules {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex; gap: 2px; overflow-x: auto;
  scrollbar-width: none;
}
.nav-modules::-webkit-scrollbar { display: none; }
.nav-btn {
  background: transparent; border: none; padding: 14px 18px;
  color: var(--text-2); font-weight: 500; font-size: 13.5px;
  cursor: pointer; border-bottom: 2px solid transparent;
  white-space: nowrap; transition: color var(--t), border-color var(--t), background var(--t);
  font-family: inherit; letter-spacing: -0.005em;
  position: relative;
}
.nav-btn:hover { color: var(--text); }
.nav-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ================ SUB-NAV ================ */
.subnav {
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex; gap: 4px; overflow-x: auto;
  scrollbar-width: none;
}
.subnav::-webkit-scrollbar { display: none; }
.subnav-btn {
  background: transparent; border: 1px solid transparent;
  padding: 7px 14px; font-size: 12.5px; color: var(--text-2);
  cursor: pointer; border-radius: var(--radius);
  transition: all var(--t); font-family: inherit; font-weight: 500;
  white-space: nowrap;
}
.subnav-btn:hover { background: var(--bg-card); color: var(--text); }
.subnav-btn.active {
  background: var(--bg-card); border-color: var(--border);
  color: var(--text); font-weight: 600;
  box-shadow: var(--shadow-xs);
}

/* ================ CONTENU ================ */
.main {
  padding: 28px 24px 60px;
  max-width: 1440px; margin: 0 auto;
}

.panel { display: none; animation: fadeIn 220ms cubic-bezier(0.4, 0, 0.2, 1); }
.panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ================ TYPOGRAPHIE ================ */
.page-title {
  font-size: 26px; font-weight: 700; margin: 0 0 4px 0;
  letter-spacing: -0.025em; color: var(--text);
}
.page-sub { color: var(--text-2); font-size: 13.5px; margin: 0 0 24px 0; }
.section-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 16px;
}

/* ================ CARDS ================ */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--t), border-color var(--t);
}
.card:hover { box-shadow: var(--shadow-sm); }
.card + .card { margin-top: 14px; }
.card-title {
  font-size: 12px; font-weight: 700; margin-bottom: 14px;
  color: var(--text); text-transform: uppercase; letter-spacing: 0.06em;
}
.card-subtitle { font-size: 13px; color: var(--text-2); margin-bottom: 12px; }

/* ================ KPI ================ */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-box {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--t), transform var(--t);
  position: relative; overflow: hidden;
}
.stat-box::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--primary); opacity: 0.7;
}
.stat-box.pos::before { background: var(--success); }
.stat-box.neg::before { background: var(--danger); }
.stat-box:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.stat-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin-bottom: 8px; font-weight: 600;
}
.stat-value {
  font-size: 26px; font-weight: 700; color: var(--text);
  letter-spacing: -0.02em; line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }
.stat-value.pos { color: var(--success); }
.stat-value.neg { color: var(--danger); }

/* ================ BOUTONS ================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius);
  border: 1px solid transparent; background: transparent; color: var(--text);
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all var(--t); text-decoration: none;
  white-space: nowrap; letter-spacing: -0.005em;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:hover { background: var(--bg-alt); }
.btn-primary {
  background: var(--primary); color: #fff; border-color: var(--primary);
  box-shadow: 0 1px 2px rgba(234,88,12,0.12);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); box-shadow: 0 2px 8px rgba(234,88,12,0.2); }
.btn-secondary {
  background: var(--bg-card); border-color: var(--border); color: var(--text);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--bg-alt); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--bg-alt); color: var(--text); }
.btn-danger {
  background: var(--bg-card); border-color: var(--danger); color: var(--danger);
}
.btn-danger:hover { background: var(--danger-light); }
.btn-success {
  background: var(--success); color: #fff; border-color: var(--success);
}
.btn-success:hover { background: var(--success-strong); }
.btn-brand {
  background: linear-gradient(135deg, #ea580c 0%, #dc2626 100%);
  color: #fff; border: none;
  box-shadow: 0 2px 8px rgba(234,88,12,0.24);
}
.btn-brand:hover { box-shadow: 0 4px 16px rgba(234,88,12,0.32); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
/* Bouton contenant un titre + une description empiles (cartes de rapports) */
.btn-card {
  flex-direction: column; align-items: flex-start; justify-content: flex-start;
  white-space: normal; text-align: left; gap: 3px; line-height: 1.35;
  height: 100%;
}
.btn-card > div { width: 100%; }
.btn-lg { padding: 11px 22px; font-size: 14px; font-weight: 600; }
.btn-icon { padding: 7px 10px; }

/* ================ FORMS ================ */
.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-row label {
  font-size: 11.5px; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.form-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=email], input[type=tel], input[type=password], select, textarea {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px; color: var(--text); font-size: 13.5px;
  font-family: inherit;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  width: 100%; line-height: 1.5;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3.5px var(--primary-glow);
}
input[readonly] { background: var(--bg-alt); color: var(--text-2); }
input::placeholder, textarea::placeholder { color: var(--text-muted); font-weight: 400; }

/* ================ MODALES ================ */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(28,25,23,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 300;
  align-items: center; justify-content: center;
  padding: 24px;
  animation: overlayFade 180ms ease-out;
}
@keyframes overlayFade { from { opacity: 0; } to { opacity: 1; } }
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  max-width: 640px; width: 100%; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
  animation: modalUp 260ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalUp { from { transform: translateY(12px) scale(0.98); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
.modal-header {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
  background: var(--bg-alt);
}

/* ================ TOASTS ================ */
.toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 400; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--text); color: #fff;
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 13px; box-shadow: var(--shadow-xl);
  animation: toastIn 240ms cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 380px; font-weight: 500;
  border-left: 3px solid var(--primary);
}
.toast.error { background: #7f1d1d; border-left-color: var(--danger); }
.toast.success { background: #14532d; border-left-color: var(--success); }
@keyframes toastIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ================ UTILS ================ */
.text-muted { color: var(--text-muted); }
.text-2 { color: var(--text-2); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: var(--radius-full);
  font-size: 11px; font-weight: 600;
  background: var(--bg-alt); color: var(--text-2);
  border: 1px solid var(--border);
  font-family: var(--font);
  letter-spacing: -0.005em;
}
.badge.success { background: var(--success-light); color: var(--success-strong); border-color: rgba(22,163,74,0.2); }
.badge.warning { background: var(--warning-light); color: #b45309; border-color: rgba(217,119,6,0.2); }
.badge.danger { background: var(--danger-light); color: #991b1b; border-color: rgba(220,38,38,0.2); }
.badge.info { background: var(--info-light); color: #075985; border-color: rgba(2,132,199,0.2); }
.badge.brand { background: var(--brand-light); color: var(--brand); border-color: rgba(234,88,12,0.2); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .icon {
  font-size: 44px; margin-bottom: 12px; opacity: 0.6;
  display: inline-block;
}
.empty-state p { margin: 4px 0; }
.empty-state strong { color: var(--text-2); }

/* ================ TABLES ================ */
.table { width: 100%; border-collapse: collapse; background: var(--bg-card); }
.table th {
  padding: 12px 14px; text-align: left; font-size: 11px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}
.table td {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text);
}
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--bg-alt); }
.table tbody tr:last-child td { border-bottom: none; }

/* ================ SCROLLBARS ================ */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 6px;
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ================ MOBILE ================ */
@media (max-width: 768px) {
  .top-header { padding: 10px 16px; }
  .brand-sub { display: none; }
  .main { padding: 20px 14px 40px; }
  .card { padding: 14px; }
  .stat-grid { grid-template-columns: 1fr !important; gap: 10px; }
  .form-cols { grid-template-columns: 1fr !important; }
  .table { min-width: 600px; }
  .card > table.table,
  #mp-list-host, #pf-list-host, #marchandises-list-host,
  #livraisons-list-host, #inventaires-list-host, #fab-history-host,
  #fact-list-host, #rapport-viewer {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal { max-width: 100vw !important; max-height: 100vh !important; border-radius: 0 !important; }
  .doc-line { grid-template-columns: 1fr !important; }
  .nav-modules button { padding: 12px 12px !important; font-size: 12.5px !important; }
  .page-title { font-size: 22px; }
}

/* ================ VERSION TAG ================ */
.version-tag {
  display: inline-block; padding: 2px 7px;
  background: var(--primary-light); color: var(--primary);
  border-radius: var(--radius-xs); font-size: 10px; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
  border: 1px solid rgba(234,88,12,0.2);
}

/* =========================================================================
   DOCUMENT PRINTABLE — style Authentik BBQ (conservé)
   ========================================================================= */
.doc-page {
  background: #fff; color: #1a1d21;
  max-width: 800px; margin: 0 auto;
  padding: 40px 44px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 12px; line-height: 1.4;
}
.doc-logo { text-align: center; margin-bottom: 22px; }
.doc-logo img { max-height: 130px; max-width: 300px; }
.doc-partners { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 28px; }
.doc-partner-block { }
.doc-partner-header {
  background: #e9ecef; color: #6c757d;
  padding: 4px 10px; font-size: 10px; font-weight: 500;
  border-radius: 3px 3px 0 0;
}
.doc-partner-body { padding: 12px 10px 4px 10px; font-size: 11.5px; }
.doc-partner-body .name { font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.doc-title-row {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 12px; padding-bottom: 8px;
}
.doc-title { font-size: 20px; font-weight: 700; margin: 0; }
.doc-meta { font-size: 11.5px; text-align: right; color: #495057; }
.doc-meta .label { color: #6c757d; }
.doc-meta .value { color: #1a1d21; font-weight: 500; }
.doc-table { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.doc-table thead th {
  background: #e9ecef; color: #495057;
  padding: 6px 8px; font-size: 10.5px; font-weight: 500;
  text-align: left; border-bottom: 1px solid #ced4da;
}
.doc-table thead th.num { text-align: right; }
.doc-table tbody td {
  padding: 8px; font-size: 11.5px;
  border-bottom: 1px solid #dee2e6; vertical-align: top;
}
.doc-table tbody td.num { text-align: right; font-family: var(--font-mono); }
.doc-table tbody td .code { color: #adb5bd; font-size: 10px; margin-top: 2px; }
.doc-totals {
  margin-left: auto; width: 320px;
  border-collapse: collapse;
}
.doc-totals td { padding: 4px 8px; font-size: 11.5px; }
.doc-totals tr.grand td {
  font-weight: 700; font-size: 13px;
  border-top: 2px solid #1a1d21; padding-top: 8px;
}
.doc-totals td:first-child { text-align: right; color: #495057; }
.doc-totals td:last-child { text-align: right; font-family: var(--font-mono); }
.doc-message {
  margin: 22px 0; font-size: 11px; color: #495057;
  font-style: italic;
}
.doc-bottom { display: grid; grid-template-columns: 1.4fr 1fr; gap: 22px; margin-top: 26px; padding-top: 12px; border-top: 1px solid #dee2e6; }
.doc-mentions { font-size: 10px; color: #495057; line-height: 1.45; }
.doc-bank { font-size: 11px; }
.doc-bank .h { font-weight: 700; margin-bottom: 4px; }
.doc-footer { text-align: center; font-size: 9.5px; color: #adb5bd; margin-top: 20px; padding-top: 8px; border-top: 1px dashed #dee2e6; }

@media print {
  body * { visibility: hidden; }
  #modal-doc-preview, #modal-doc-preview * { visibility: visible; }
  #modal-doc-preview {
    position: fixed; inset: 0; background: #fff !important;
    display: block !important; padding: 0 !important;
  }
  #modal-doc-preview .modal {
    max-width: none !important; max-height: none !important;
    box-shadow: none !important; border: none !important;
  }
  #modal-doc-preview .modal-header, #modal-doc-preview .modal-footer { display: none !important; }
  #modal-doc-preview .modal-body { padding: 0 !important; background: #fff !important; overflow: visible !important; }
  .doc-page { box-shadow: none !important; padding: 20mm !important; max-width: none !important; }
  .no-print { display: none !important; visibility: hidden !important; }
  @page { margin: 0; size: A4; }
}