:root {
  --bg: #EEF2F1;
  --surface: #FFFFFF;
  --ink: #16232B;
  --muted: #5B6B72;
  --line: #DCE4E2;
  --primary: #0F6E5D;
  --primary-dark: #0B5347;
  --secondary: #2C5F8A;
  --danger: #B23A2E;
  --warning: #C98A1F;
  --success: #1F8A5F;
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 14px;
}

a { text-decoration: none; color: inherit; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }

.mono { font-family: 'IBM Plex Mono', monospace; }

.app { display: flex; min-height: 100vh; }

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--primary-dark);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 24px; }
.brand-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(255,255,255,0.12);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.brand-name { color: #fff; font-weight: 700; font-size: 14px; line-height: 1.2; }
.brand-sub { color: rgba(255,255,255,0.6); font-size: 11px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  color: rgba(255,255,255,0.65);
  font-size: 14px; font-weight: 500;
  padding: 10px 12px; border-radius: 12px;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active { background: rgba(255,255,255,0.14); color: #fff; }
.sidebar-footer { margin-top: auto; color: rgba(255,255,255,0.4); font-size: 11px; padding: 16px 10px 0; }

.mobile-nav { display: none; }

/* ---------------- Main ---------------- */
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-header h1 { margin: 0; font-size: 21px; font-weight: 700; }
.page-header .subtitle { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

/* ---------------- Cards / tables ---------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.stat-value { font-family: 'IBM Plex Mono', monospace; font-size: 28px; font-weight: 700; margin-top: 6px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead tr { background: var(--bg); }
th { text-align: left; padding: 10px 14px; font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
td { padding: 10px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }

/* ---------------- Badges ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.tube-dot { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 0 2px #fff; display: inline-block; flex-shrink: 0; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; cursor: pointer;
  font-size: 13.5px; font-weight: 600;
  padding: 9px 15px; border-radius: 12px;
  background: var(--primary); color: #fff;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: rgba(15,110,93,0.09); color: var(--primary); }
.btn.secondary:hover { background: rgba(15,110,93,0.16); }
.btn.ghost { background: var(--bg); color: var(--ink); }
.btn.danger { background: rgba(178,58,46,0.09); color: var(--danger); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.small { padding: 6px 10px; font-size: 12px; border-radius: 9px; }

/* ---------------- Forms ---------------- */
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.password-wrap { position: relative; }
.password-wrap .input { padding-right: 42px; }
.pwd-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 16px; line-height: 1;
  padding: 6px 8px; color: var(--muted); border-radius: 8px;
}
.pwd-toggle:hover { background: var(--bg); }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; color: var(--ink); background: #fff;
}
.input:focus, select.input:focus, textarea.input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 12px; }

details.accordion { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 20px; }
details.accordion > summary {
  cursor: pointer; list-style: none; padding: 14px 18px; font-weight: 600; font-size: 14px;
  display: flex; align-items: center; gap: 8px;
}
details.accordion > summary::-webkit-details-marker { display: none; }
details.accordion > summary:before { content: '+'; color: var(--primary); font-size: 18px; font-weight: 700; }
details.accordion[open] > summary:before { content: '−'; }
.accordion-body { padding: 4px 18px 18px; border-top: 1px solid var(--line); }

.exam-picker { max-height: 280px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; padding: 6px; margin-bottom: 14px; }
.exam-picker-cat { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); padding: 8px 8px 4px; }
.exam-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; font-size: 13.5px; }
.exam-row:hover { background: rgba(0,0,0,0.03); }
.exam-row .name { flex: 1; }
.exam-row .price { color: var(--muted); font-family: 'IBM Plex Mono', monospace; font-size: 12px; }

/* ---------------- Misc blocks ---------------- */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 4px 8px; border-radius: 8px; background: var(--bg); color: var(--ink); }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--bg); margin-bottom: 8px; }
.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); font-size: 13.5px; }
.flash { padding: 10px 14px; border-radius: 12px; margin-bottom: 16px; font-size: 13.5px; font-weight: 500; }
.flash.success { background: rgba(31,138,95,0.1); color: var(--success); }
.flash.error { background: rgba(178,58,46,0.1); color: var(--danger); }

/* ---------------- Kanban (échantillons) ---------------- */
.kanban { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.kanban-col { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.kanban-col h3 { font-size: 11px; text-transform: uppercase; margin: 4px 6px 10px; display: flex; align-items: center; gap: 6px; }
.kanban-count { margin-left: auto; color: var(--muted); }
.kanban-card { background: var(--bg); border-radius: 12px; padding: 10px; margin-bottom: 8px; font-size: 12.5px; }
.kanban-card .pname { font-weight: 600; margin-bottom: 2px; }
.kanban-card .pmeta { color: var(--muted); font-size: 11px; margin-bottom: 6px; }

/* ---------------- Rapport / print ---------------- */
.report { max-width: 720px; margin: 0 auto; }
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; border-bottom: 2px solid var(--ink); padding-bottom: 14px; margin-bottom: 14px; }
.report-head > div:first-child { max-width: 380px; }
.report-head > div:last-child { flex-shrink: 0; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 13.5px; margin-bottom: 14px; }
.report-foot { display: flex; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 20px; padding-top: 12px; font-size: 12px; color: var(--muted); }

/* ---------------- Étiquettes code-barres ---------------- */
.labels-section { margin-top: 10px; padding-top: 20px; border-top: 1px dashed var(--line); }
.label-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.label-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px 6px; }
.label-card .lname { font-size: 11.5px; font-weight: 600; display: flex; align-items: center; gap: 5px; margin-bottom: 2px; }
.label-card .lmeta { font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.label-card .barcode-img { width: 100%; height: auto; display: block; image-rendering: pixelated; }

@media print {
  body.print-labels-mode .catalog-section,
  body.print-labels-mode .page-header,
  body.print-labels-mode .flash { display: none !important; }
  body.print-labels-mode .labels-section { border: none; margin: 0; padding: 0; }
  body.print-labels-mode .label-grid { grid-template-columns: repeat(3, 1fr); }
  body.print-labels-mode .label-card { break-inside: avoid; }

  body.print-invoice-mode .page-header,
  body.print-invoice-mode .stat-grid,
  body.print-invoice-mode .table-wrap,
  body.print-invoice-mode .flash { display: none !important; }
  body.print-invoice-mode .invoice-sheet { display: block !important; }
}

/* ---------------- Reçu (ticket thermique Epson) ---------------- */
.receipt-ticket {
  width: 80mm;
  background: #fff;
  color: #000;
  font-family: 'Courier New', Courier, monospace;
  font-size: 11.5px;
  line-height: 1.5;
  padding: 6mm 4mm;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}
.receipt-ticket.w58 { width: 58mm; font-size: 10.5px; }
.receipt-ticket .r-center { text-align: center; }
.receipt-ticket .r-bold { font-weight: 700; }
.receipt-ticket .r-divider { border-top: 1px dashed #000; margin: 5px 0; }
.receipt-ticket .r-line { display: flex; justify-content: space-between; gap: 6px; }
.receipt-ticket .r-item-name { flex: 1; }
.receipt-ticket .r-item-price { white-space: nowrap; }

@media print {
  body.print-receipt-mode #receiptPreviewWrap {
    background: none !important; padding: 0 !important; display: block !important;
  }
  body.print-receipt-mode .receipt-ticket {
    box-shadow: none !important; width: 80mm !important; margin: 0 !important; padding: 4mm 3mm !important;
  }
  body.print-receipt-mode .receipt-ticket.w58 { width: 58mm !important; }
  @page { size: 80mm auto; margin: 0; }
}
@media (max-width: 900px) {
  .sidebar { display: none; }
  .mobile-nav {
    display: flex; overflow-x: auto; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--primary-dark); padding: 8px; gap: 4px; z-index: 20;
  }
  .mobile-nav a { color: rgba(255,255,255,0.65); font-size: 11px; padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
  .mobile-nav a.active { background: rgba(255,255,255,0.14); color: #fff; }
  .main { padding: 18px 16px 80px; }
  .form-grid { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: 1fr; }
}

@media print {
  .no-print { display: none !important; }
  .main { padding: 0; }
  body { background: #fff; }
  .report-vcenter { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
}
