/* ====================================================================
   Extension Codes-Barres : styles harmonisés au thème sombre du Gestionnaire
==================================================================== */

#codes_barres {
  color: var(--text-main, #f5f5ff);
}

.cb-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 0;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.1));
}
.cb-subbtn {
  background: var(--bg-secondary, #262828);
  color: var(--text-main, #f5f5ff);
  border: 1px solid var(--border-color, rgba(255,255,255,0.1));
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 120ms, border-color 120ms;
}
.cb-subbtn:hover { background: var(--bg-header-table, #3a3d3d); }
.cb-subbtn.is-active {
  background: var(--accent-orange, #E68161);
  border-color: var(--accent-orange, #E68161);
  color: #fff;
  font-weight: 600;
}

.cb-content { padding: 0.5rem 0; }

/* Onglets pill par type d'entite (Tous, Cartouches, Materiel, ...) */
.cb-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0 12px 0;
  border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.cb-tab {
  background: var(--bg-secondary, #262828);
  color: var(--text-main, #f5f5ff);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.cb-tab:hover { background: var(--bg-header-table, #3a3d3d); }
.cb-tab.is-active {
  background: var(--accent-orange, #F26B36);
  border-color: var(--accent-orange, #F26B36);
  color: #fff;
}

/* Compteur résultats */
.cb-counter {
  background: var(--bg-secondary, #262828);
  color: var(--text-secondary, rgba(255, 255, 255, 0.65));
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
  margin-left: auto;
}

/* Spinner inline */
.cb-spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid rgba(242, 107, 54, 0.25);
  border-top-color: #F26B36;
  border-radius: 50%;
  animation: cb-spin 0.6s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes cb-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .cb-spinner { animation: none; border-top-color: transparent; } }

/* Pagination */
.cb-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px 0;
  flex-wrap: wrap;
}
.cb-page-indic {
  color: var(--text-main, #f5f5ff);
  font-weight: 600;
  font-size: 0.92rem;
}
.cb-pagination .cb-btn[disabled] { opacity: 0.4; cursor: not-allowed; }

@media (max-width: 600px) {
  .cb-tabs { padding-bottom: 8px; }
  .cb-tab { padding: 6px 12px; font-size: 0.82rem; }
  .cb-counter { width: 100%; text-align: center; margin-left: 0; }
}
.cb-loading, .cb-muted { color: var(--text-secondary, rgba(255,255,255,0.5)); }
.cb-error {
  background: rgba(244, 67, 54, 0.15);
  border-left: 4px solid var(--error-color, #F44336);
  padding: 1rem;
  border-radius: 4px;
}

.cb-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}
.cb-input {
  background: var(--bg-secondary, #262828);
  color: var(--text-main, #f5f5ff);
  border: 1px solid var(--border-color, rgba(255,255,255,0.1));
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
  flex: 1;
  min-width: 220px;
  outline: none;
}
.cb-input:focus { border-color: var(--accent-orange, #E68161); }
textarea.cb-input { min-height: 60px; resize: vertical; }

.cb-chips { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.cb-chip {
  background: var(--bg-secondary, #262828);
  color: var(--text-main, #f5f5ff);
  border: 1px solid var(--border-color, rgba(255,255,255,0.1));
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.cb-chip:hover { background: var(--bg-header-table, #3a3d3d); }
.cb-chip.is-active {
  background: var(--accent-orange, #E68161);
  border-color: var(--accent-orange, #E68161);
  color: #fff;
}

.cb-table-wrap { overflow-x: auto; }
.cb-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-secondary, #262828);
  border-radius: 8px;
  overflow: hidden;
}
.cb-table thead { background: var(--bg-header-table, #3a3d3d); }
.cb-table th, .cb-table td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.08));
  font-size: 0.92rem;
}
.cb-table th { font-weight: 700; }
.cb-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.cb-table code { font-family: ui-monospace, monospace; font-size: 0.85rem; color: var(--accent-primary, #32b8c6); }

.cb-icon {
  background: transparent;
  border: 1px solid var(--border-color, rgba(255,255,255,0.15));
  border-radius: 6px;
  padding: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  color: inherit;
  transition: transform 120ms, background 120ms;
}
.cb-icon--ok      { 
  background: rgba(242, 107, 54, 0.15); 
  border-color: #F26B36; 
  color: #F26B36;
}
.cb-icon--missing { 
  background: rgba(63, 74, 75, 0.15);
  border-color: #3F4A4B;
  color: #3F4A4B;
  opacity: 0.7;
}
.cb-icon:hover    { transform: scale(1.08); background: rgba(255,255,255,0.1); }

.cb-btn-mini {
  background: var(--bg-header-table, #3a3d3d);
  border: 1px solid var(--border-color, rgba(255,255,255,0.2));
  color: #fff;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.9rem;
}
.cb-btn-mini:hover { background: var(--accent-orange, #F26B36); }

/* Badges de type */
.cb-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.cb-badge--cartouche { background: rgba(0, 188, 212, 0.15); color: #00bcd4; border: 1px solid rgba(0, 188, 212, 0.3); }
.cb-badge--materiel   { background: rgba(33, 150, 243, 0.15); color: #2196f3; border: 1px solid rgba(33, 150, 243, 0.3); }
.cb-badge--pc-stock   { background: rgba(76, 175, 80, 0.15);  color: #4caf50; border: 1px solid rgba(76, 175, 80, 0.3); }
.cb-badge--pc-sortie  { background: rgba(255, 152, 0, 0.15);  color: #ff9800; border: 1px solid rgba(255, 152, 0, 0.3); }
.cb-badge--placard    { background: rgba(156, 39, 176, 0.15); color: #9c27b0; border: 1px solid rgba(156, 39, 176, 0.3); }
.cb-badge--other      { background: rgba(158, 158, 158, 0.15); color: #9e9e9e; border: 1px solid rgba(158, 158, 158, 0.3); }

/* Amélioration colonnes */
.cb-table .col-name    { min-width: 180px; }
.cb-table .col-stock   { text-align: center; font-weight: 700; }
.cb-table .col-barcode { font-family: monospace; }
.cb-table .row--no-barcode { opacity: 0.85; }
.cb-table .row--no-barcode:hover { opacity: 1; }

.cb-btn {
  background: var(--bg-secondary, #262828);
  color: var(--text-main, #f5f5ff);
  border: 1px solid var(--border-color, rgba(255,255,255,0.15));
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
}
.cb-btn:hover { background: var(--bg-header-table, #3a3d3d); }
.cb-btn--primary {
  background: var(--accent-orange, #E68161);
  border-color: var(--accent-orange, #E68161);
  color: #fff;
}
.cb-btn--primary:hover { filter: brightness(1.1); }
.cb-btn--secondary {
  background: var(--accent-primary, #32b8c6);
  border-color: var(--accent-primary, #32b8c6);
  color: #fff;
}

.cb-form { max-width: 720px; }

/* Fieldset fournisseur */
.cb-fieldset {
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
  border-radius: 10px;
  padding: 12px 14px;
  margin: 12px 0;
  background: rgba(50, 184, 198, 0.04);
}
.cb-fieldset legend {
  padding: 0 8px;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--accent-primary, #32b8c6);
}
.cb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.85rem;
  margin-top: 1rem;
}
.cb-grid label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; }
.cb-grid__full { grid-column: 1 / -1; display: flex; align-items: center; gap: 0.85rem; }

.cb-card {
  margin-top: 1rem;
  padding: 1rem 1.25rem;
  background: var(--bg-secondary, #262828);
  border: 1px solid var(--accent-orange, #E68161);
  border-radius: 8px;
}
.cb-card h4 { margin-bottom: 0.5rem; }

/* Icône code-barre injectée dans les tableaux Gestionnaire */
.cb-row-icon {
  display: inline-flex;
  align-items: center;
  user-select: none;
}

/* ====================================================================
   Modale code-barre legacy : éviter coupure de l'image SVG
==================================================================== */
#barcode-modal .modal-content {
  max-width: min(420px, 92vw) !important;
}
#barcode-modal #barcode-svg,
#barcode-modal svg,
#barcode-modal img.barcode {
  display: block;
  max-width: 100%;
  width: 100%;
  height: auto;
  object-fit: contain;
}
#barcode-modal .modal-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

/* Modale QR Code (CODE128 supprimé) */
.cb-modal-canvas {
  position: relative;
  background: #ffffff;
  border-radius: 16px;
  padding: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}
.cb-modal-qr {
  display: block;
  width: 300px;
  height: 300px;
  min-width: 250px;
  min-height: 250px;
  max-width: 100%;
  object-fit: contain;
  cursor: zoom-in;
  transition: transform 200ms ease-out;
}
.cb-modal-qr:active { transform: scale(0.97); }
.cb-modal-qr-fallback {
  display: block;
  margin: 0 auto;
  max-width: 100%;
}

.cb-modal-code {
  text-align: center;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  color: #F26B36;
  font-weight: 700;
  font-size: 16px;
  margin: 16px 0 0 0;
  padding: 10px 14px;
  background: rgba(242, 107, 54, 0.1);
  border-radius: 8px;
  word-break: break-all;
  user-select: all;
}

@media (max-width: 480px) {
  .cb-modal-qr { width: 280px; height: 280px; }
  .cb-modal-canvas { padding: 20px; border-radius: 12px; }
}
#barcode-modal .cb-delete-btn {
  background: transparent;
  border: 1px solid var(--danger-color, #c0392b);
  color: var(--danger-color, #c0392b);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 120ms, color 120ms;
}
#barcode-modal .cb-delete-btn:hover {
  background: var(--danger-color, #c0392b);
  color: #fff;
}
#barcode-modal .cb-delete-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ====================================================================
   Toast notifications (fallback de window.showToast legacy)
==================================================================== */
#cb-toast-host {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  right: 16px;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.cb-toast {
  pointer-events: auto;
  background: var(--bg-secondary, #262828);
  color: var(--text-main, #f5f5ff);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
  border-left: 4px solid #F26B36;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  min-width: 240px;
  max-width: 360px;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 200ms ease, transform 200ms cubic-bezier(0.32, 0.72, 0.16, 1);
}
.cb-toast.is-visible {
  opacity: 1;
  transform: translateX(0);
}
.cb-toast--success { border-left-color: var(--success-color, #4CAF50); }
.cb-toast--error   { border-left-color: var(--error-color,   #F44336); }
.cb-toast--warning { border-left-color: var(--accent-orange, #F26B36); }
.cb-toast--info    { border-left-color: var(--accent-primary, #32b8c6); }

@media (max-width: 600px) {
  #cb-toast-host { right: 12px; left: 12px; }
  .cb-toast { min-width: 0; max-width: none; }
}

/* Mobile : ajuster sub-nav */
@media (max-width: 600px) {
  .cb-subnav { gap: 0.3rem; }
  .cb-subbtn { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
}

/* ====================================================================
   Banniere suggestion installation certificat (HTTPS LAN)
==================================================================== */
.cb-cert-banner {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8500;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(90deg, #F26B36 0%, #E0570F 100%);
  color: #fff;
  font-size: 0.92rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.cb-cert-banner__icon { font-size: 1.2em; flex: 0 0 auto; }
.cb-cert-banner__text { flex: 1 1 auto; line-height: 1.35; }
.cb-cert-banner__text strong { font-weight: 700; }
.cb-cert-banner__btn {
  background: #fff;
  color: #C04C20;
  padding: 6px 14px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
  flex: 0 0 auto;
  transition: background 120ms;
}
.cb-cert-banner__btn:hover { background: rgba(255, 255, 255, 0.85); text-decoration: none; }
.cb-cert-banner__close {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.cb-cert-banner__close:hover { background: rgba(255, 255, 255, 0.15); }

@media (max-width: 600px) {
  .cb-cert-banner { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .cb-cert-banner__text { flex: 1 1 100%; }
  .cb-cert-banner__btn { flex: 1 1 auto; text-align: center; }
}

/* ====================================================================
   FAB Codes-Barres + Bottom Sheet (mobile-first)
==================================================================== */

.cb-fab {
  position: fixed;
  right: 16px;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px)); /* au-dessus bottom-nav legacy */
  z-index: 9000;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 64px;
  height: 64px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #F26B36;
  color: #fff;
  box-shadow: 0 8px 24px rgba(242, 107, 54, 0.55), 0 2px 6px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  animation: cb-fab-pulse 2.2s ease-in-out infinite;
}
.cb-fab:hover  { background: #ff7a44; transform: scale(1.06); }
.cb-fab:active { transform: scale(0.96); }
.cb-fab:focus-visible { outline: 3px solid #ffd0bb; outline-offset: 2px; }
.cb-fab__label {
  font-size: 9px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  opacity: 0.95;
  margin-top: -2px;
}

@keyframes cb-fab-pulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(242, 107, 54, 0.55), 0 2px 6px rgba(0,0,0,0.3); }
  50%      { box-shadow: 0 10px 28px rgba(242, 107, 54, 0.85), 0 0 0 8px rgba(242,107,54,0.18); }
}
@media (prefers-reduced-motion: reduce) {
  .cb-fab { animation: none; }
}

/* Bottom Sheet */
.cb-sheet {
  position: fixed; inset: 0;
  z-index: 9500;
  pointer-events: none;
}
.cb-sheet.is-open { pointer-events: auto; }
.cb-sheet__backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 200ms ease;
}
.cb-sheet.is-open .cb-sheet__backdrop { opacity: 1; }

.cb-sheet__panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-secondary, #262828);
  color: var(--text-main, #f5f5ff);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 12px 18px calc(20px + env(safe-area-inset-bottom, 0px)) 18px;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.6);
  transform: translateY(100%);
  transition: transform 240ms cubic-bezier(0.32, 0.72, 0.16, 1);
  max-height: 80vh;
  overflow: auto;
}
.cb-sheet.is-open .cb-sheet__panel { transform: translateY(0); }

.cb-sheet__handle {
  width: 44px; height: 4px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  margin: 0 auto 12px;
}
.cb-sheet__title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 14px;
  text-align: center;
}

.cb-sheet__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.cb-sheet__action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 18px 12px;
  background: var(--bg-main, #1f2121);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
  border-radius: 14px;
  color: var(--text-main, #f5f5ff);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 120ms, transform 80ms, border-color 120ms;
  min-height: 96px;
}
.cb-sheet__action:hover  { background: var(--bg-header-table, #3a3d3d); border-color: #F26B36; }
.cb-sheet__action:active { transform: scale(0.97); }
.cb-sheet__ico { font-size: 2rem; line-height: 1; }
.cb-sheet__lbl { font-size: 0.95rem; }
.cb-sheet__action small {
  color: var(--text-secondary, rgba(255, 255, 255, 0.55));
  font-size: 0.7rem;
  font-weight: 400;
}

.cb-sheet__cancel {
  width: 100%;
  padding: 14px;
  background: transparent;
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.18));
  border-radius: 12px;
  color: var(--text-main, #f5f5ff);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}
.cb-sheet__cancel:hover { background: rgba(255, 255, 255, 0.05); }

/* Mobile : FAB plus large + bottom-sheet pleine largeur */
@media (max-width: 600px) {
  .cb-fab { width: 68px; height: 68px; right: 14px; bottom: calc(78px + env(safe-area-inset-bottom, 0px)); }
  .cb-fab__label { font-size: 10px; }
  .cb-sheet__grid { grid-template-columns: repeat(2, 1fr); }
  .cb-sheet__action { min-height: 110px; }
}

/* Tablette + desktop : sheet centré à droite plutôt que pleine largeur */
@media (min-width: 900px) {
  .cb-sheet__panel {
    left: auto;
    right: 24px;
    bottom: 24px;
    width: 420px;
    border-radius: 18px;
    transform: translateY(120%);
  }
  .cb-sheet.is-open .cb-sheet__panel { transform: translateY(0); }
}
