/* ============================================================
   FOURNISSEUR - Gestion des commandes fournisseur
   ============================================================ */

.page_fournisseur {
  padding: 10px 16px;
  font-size: 10pt;
}

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

.header-fournisseur h1 {
  font-size: 16pt;
  color: var(--main-bg-color);
  margin: 0;
}

/* ---- KPI Cards ---- */

.frn-kpi-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.frn-kpi-card {
  flex: 1;
  min-width: 160px;
  background: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: box-shadow 0.2s, border-color 0.2s;
  border: 2px solid transparent;
  cursor: pointer;
}

.frn-kpi-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.frn-kpi-active {
  border-color: var(--main-bg-color);
}

.frn-kpi-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
}

.frn-kpi-icon.kpi-encours { background: #5c6bc0; }
.frn-kpi-icon.kpi-recevoir { background: #00acc1; }
.frn-kpi-icon.kpi-facturer { background: #ff9800; }
.frn-kpi-icon.kpi-recu { background: #43a047; }
.frn-kpi-icon.kpi-montant { background: #ab47bc; }

.frn-kpi-content {
  display: flex;
  flex-direction: column;
}

.frn-kpi-value {
  font-size: 18pt;
  font-weight: 700;
  color: #222;
  line-height: 1.1;
}

.frn-kpi-label {
  font-size: 8.5pt;
  color: #888;
  font-weight: 500;
  margin-top: 2px;
}

.frn-kpi-sub {
  font-size: 8pt;
  color: #aaa;
  margin-top: 1px;
}

/* ---- Toolbar ---- */

.frn-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.frn-toolbar-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}

.frn-toolbar input[type="text"] {
  padding: 5px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 9pt;
  min-width: 220px;
}

.frn-toolbar select {
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 9pt;
  background: #fff;
}

.frn-toolbar label {
  font-weight: 600;
  font-size: 9pt;
  color: #555;
  display: flex;
  align-items: center;
  gap: 6px;
}

.frn-mobile-filters-toggle {
  display: none;
}

.frn-mobile-filters-count {
  background: #e53935;
  color: #fff;
  font-size: 7pt;
  font-weight: 700;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 2px;
}

/* ---- Boutons ---- */

.frn-btn {
  padding: 5px 14px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #f5f5f5;
  cursor: pointer;
  font-size: 9pt;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s;
  white-space: nowrap;
}

.frn-btn:hover {
  background: #e0e0e0;
}

.frn-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.frn-btn-primary {
  background: var(--main-bg-color);
  color: #fff;
  border-color: var(--main-bg-color);
}

.frn-btn-primary:hover {
  opacity: 0.85;
}

.frn-btn-success {
  background: #43a047;
  color: #fff;
  border-color: #388e3c;
}

.frn-btn-success:hover {
  background: #388e3c;
}

.frn-btn-warning {
  background: #ff9800;
  color: #fff;
  border-color: #f57c00;
}

.frn-btn-warning:hover {
  background: #f57c00;
}

.frn-btn-danger {
  background: #e53935;
  color: #fff;
  border-color: #c62828;
}

.frn-btn-danger:hover {
  background: #c62828;
}

.frn-btn-sm {
  padding: 3px 8px;
  font-size: 8.5pt;
}

.frn-btn-icon {
  padding: 4px 8px;
}

/* ---- Layout principal ---- */

.frn-main-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.frn-table-container {
  flex: 1;
  min-width: 0;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  overflow: hidden;
}

.frn-table-scroll {
  max-height: calc(100vh - 280px);
  overflow-y: auto;
}

.frn-panel {
  width: 420px;
  flex-shrink: 0;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  max-height: calc(100vh - 220px);
  display: flex;
  flex-direction: column;
}

/* ---- Table commandes ---- */

.frn-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 9pt;
}

.frn-table thead th {
  background: #f8f9fa;
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 8.5pt;
  color: #555;
  border-bottom: 2px solid #e0e0e0;
  position: sticky;
  top: 0;
  z-index: 2;
  white-space: nowrap;
  user-select: none;
}

.frn-table thead th.frn-sortable {
  cursor: pointer;
}

.frn-table thead th.frn-sortable:hover {
  background: #eef;
}

.frn-sort-arrow {
  font-size: 8pt;
  margin-left: 3px;
  color: var(--main-bg-color);
}

.frn-table tbody tr {
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.1s;
  cursor: pointer;
}

.frn-table tbody tr:hover {
  background: rgba(92, 107, 192, 0.06);
}

.frn-table tbody tr.frn-row-selected {
  background: rgba(92, 107, 192, 0.12);
}

.frn-table tbody td {
  padding: 7px 10px;
  vertical-align: middle;
}

.frn-col-ref a {
  color: var(--main-bg-color);
  text-decoration: none;
  font-weight: 600;
}

.frn-col-ref a:hover {
  text-decoration: underline;
}

.frn-col-montant {
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
}

.frn-fournisseur-name {
  font-weight: 600;
  color: #333;
}

.frn-fournisseur-name a {
  color: #333;
  text-decoration: none;
}

.frn-fournisseur-name a:hover {
  color: var(--main-bg-color);
  text-decoration: underline;
}

.frn-empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #999;
  font-size: 10pt;
}

.frn-empty-state .fa {
  font-size: 36pt;
  display: block;
  margin-bottom: 12px;
  color: #ddd;
}

/* ---- Statuts ---- */

.frn-statut {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 8pt;
  font-weight: 600;
  white-space: nowrap;
}

.frn-statut-0 { background: #e0e0e0; color: #555; }    /* brouillon */
.frn-statut-1 { background: #bbdefb; color: #1565c0; } /* validé */
.frn-statut-2 { background: #d1c4e9; color: #4527a0; } /* approuvé */
.frn-statut-3 { background: #fff9c4; color: #f57f17; } /* en cours */
.frn-statut-4 { background: #ffe0b2; color: #e65100; } /* reçu partiel */
.frn-statut-5 { background: #c8e6c9; color: #2e7d32; } /* reçu */
.frn-statut-6 { background: #cfd8dc; color: #455a64; } /* fermé */
.frn-statut-7 { background: #ffcdd2; color: #c62828; } /* refusé */
.frn-statut-9 { background: #ffcdd2; color: #c62828; } /* annulé */

/* ---- Badges facturation ---- */

.frn-billed-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 7.5pt;
  font-weight: 600;
  white-space: nowrap;
}

.frn-billed-yes { background: #c8e6c9; color: #2e7d32; }
.frn-billed-no { background: #fff3e0; color: #e65100; }
.frn-billed-multi { background: #ffcdd2; color: #c62828; }

/* ---- Panel détail ---- */

.frn-panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.frn-panel-header-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.frn-panel-header-ref {
  font-size: 11pt;
  color: var(--main-bg-color);
  font-weight: 700;
}

.frn-panel-header-fourn {
  font-size: 9pt;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.frn-panel-close {
  width: 28px;
  height: 28px;
  border: none;
  background: #f0f0f0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 10pt;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.frn-panel-close:hover {
  background: #e0e0e0;
}

.frn-panel-body {
  padding: 14px 16px;
  flex: 1;
  overflow-y: auto;
}

.frn-panel-empty {
  text-align: center;
  padding: 40px 20px;
  color: #aaa;
  font-size: 10pt;
}

.frn-panel-empty .fa {
  font-size: 28pt;
  display: block;
  margin-bottom: 10px;
}

.frn-detail-section {
  margin-bottom: 16px;
}

.frn-detail-section-title {
  font-size: 8.5pt;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.frn-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  font-size: 9pt;
  gap: 8px;
}

.frn-detail-row-label {
  color: #888;
  flex-shrink: 0;
}

.frn-detail-row-value {
  font-weight: 600;
  color: #333;
  text-align: right;
  word-break: break-word;
}

/* ---- Lignes produits panel ---- */

.frn-lines-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 8.5pt;
}

.frn-lines-table th {
  background: #f8f9fa;
  padding: 5px 8px;
  text-align: left;
  font-weight: 600;
  color: #666;
  font-size: 8pt;
}

.frn-lines-table td {
  padding: 5px 8px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: top;
}

.frn-lines-table .frn-line-ref {
  color: var(--main-bg-color);
  text-decoration: none;
  font-weight: 600;
  font-size: 8pt;
}

.frn-lines-table .frn-line-desc {
  display: block;
  margin-top: 4px;
  padding: 4px 8px;
  background: #fff8e1;
  border-left: 3px solid #ffb300;
  border-radius: 4px;
  color: #5d4037;
  font-size: 8pt;
  font-style: normal;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Note de la commande (note privée) dans le panel détail */
.frn-order-note {
  padding: 8px 12px;
  background: #fff8e1;
  border-left: 4px solid #ffb300;
  border-radius: 6px;
  color: #5d4037;
  font-size: 9pt;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.frn-lines-table .frn-line-desc::before {
  content: "\f249";  /* fa-sticky-note */
  font-family: "Font Awesome 6 Free";
  font-weight: 400;
  margin-right: 5px;
  color: #ffa000;
  font-size: 8pt;
}

.frn-lines-table .frn-line-num {
  text-align: right;
  white-space: nowrap;
}

/* ---- Factures panel ---- */

.frn-facture-card {
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: #fafafa;
}

.frn-facture-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.frn-facture-row:last-child {
  margin-bottom: 0;
}

.frn-facture-label {
  font-size: 8pt;
  color: #888;
  width: 70px;
  flex-shrink: 0;
}

.frn-facture-value {
  font-size: 9pt;
  flex: 1;
  min-width: 0;
}

.frn-facture-value a {
  color: var(--main-bg-color);
  font-weight: 600;
  text-decoration: none;
}

.frn-facture-files {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 8.5pt;
  color: #555;
}

.frn-facture-upload {
  cursor: pointer;
  padding: 4px 8px;
  border: 1px dashed #ccc;
  border-radius: 6px;
  background: #fff;
  font-size: 8.5pt;
  color: #666;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.frn-facture-upload:hover {
  border-color: var(--main-bg-color);
  color: var(--main-bg-color);
}

.frn-warn {
  color: #c62828;
  font-size: 8.5pt;
  font-weight: 600;
  padding: 6px 8px;
  background: #ffebee;
  border-radius: 6px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.frn-info {
  color: #1565c0;
  font-size: 8.5pt;
  padding: 6px 8px;
  background: #e3f2fd;
  border-radius: 6px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---- Réception ---- */

.frn-reception-block {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 10px;
}

.frn-reception-warehouse {
  margin-bottom: 8px;
}

.frn-reception-warehouse label {
  display: block;
  font-size: 8.5pt;
  color: #666;
  margin-bottom: 4px;
  font-weight: 600;
}

/* ---- Pagination ---- */

.frn-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid #eee;
  font-size: 9pt;
  color: #666;
  flex-wrap: wrap;
  gap: 10px;
}

.frn-pagination-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.frn-pagination-btn {
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 9pt;
}

.frn-pagination-btn:hover:not(:disabled) {
  background: #f5f5f5;
}

.frn-pagination-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.frn-pagination-current {
  padding: 4px 10px;
  font-weight: 600;
}

/* ---- Modal nouvelle commande ---- */

.frn-modal-mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: frnModalFadeIn 0.15s ease;
}

@keyframes frnModalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.frn-modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
  width: 880px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: frnModalSlideIn 0.2s ease;
  /* Pas d'overflow:hidden : les dropdowns multiselect doivent pouvoir sortir du modal */
  overflow: visible;
}

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

.frn-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}

.frn-modal-header h3 {
  margin: 0;
  font-size: 12pt;
  color: #333;
}

.frn-modal-close {
  width: 30px;
  height: 30px;
  border: none;
  background: #f0f0f0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.frn-modal-close:hover {
  background: #e0e0e0;
}

.frn-modal-body {
  padding: 16px 18px;
  /* overflow visible pour laisser sortir les dropdowns multiselect (Fournisseur, Produit) */
  overflow: visible;
  flex: 1;
}

.frn-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid #eee;
  flex-shrink: 0;
}

.frn-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.frn-form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.frn-form-group label {
  font-size: 8.5pt;
  color: #666;
  font-weight: 600;
}

.frn-form-group input,
.frn-form-group select {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 9pt;
}

.frn-product-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 9pt;
  margin-bottom: 12px;
}

.frn-product-table th {
  background: #f8f9fa;
  padding: 6px 8px;
  text-align: left;
  font-weight: 600;
  color: #555;
  font-size: 8.5pt;
  border-bottom: 1px solid #e0e0e0;
}

.frn-product-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}

.frn-product-table input[type="number"],
.frn-product-table input[type="text"] {
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 8.5pt;
  width: 100%;
}

.frn-product-add-row {
  background: #f8f9fa;
}

.frn-icon-btn {
  cursor: pointer;
  font-size: 14pt;
  transition: opacity 0.15s, transform 0.1s;
}

.frn-icon-btn:hover {
  opacity: 0.75;
}

.frn-icon-btn:active {
  transform: scale(0.92);
}

.frn-icon-btn.frn-icon-add { color: #43a047; }
.frn-icon-btn.frn-icon-remove { color: #e53935; }

.frn-modal-empty {
  text-align: center;
  color: #999;
  padding: 16px;
  font-size: 9pt;
  font-style: italic;
}

.frn-modal-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 9pt;
}

.frn-modal-summary-label {
  color: #888;
}

.frn-modal-summary-value {
  font-weight: 700;
  color: #333;
  font-size: 11pt;
}

/* Multiselect dans modal */
.frn-modal .multiselect {
  font-size: 9pt;
  min-height: 32px;
}

/* Le dropdown des multiselect doit pouvoir sortir du modal et passer au-dessus de tout */
.frn-modal .multiselect__content-wrapper {
  z-index: 500;
}

/* Quand un multiselect du modal est actif, on s'assure que sa colonne se met au-dessus
   pour que le dropdown ne soit pas masqué par les inputs voisins */
.frn-modal .multiselect--active {
  z-index: 500;
}

/* ---- Spinner / loader ---- */

.frn-loading {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #888;
  font-size: 9pt;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1200px) {
  .frn-panel {
    width: 360px;
  }
}

@media (max-width: 992px) {
  .frn-main-layout {
    flex-direction: column;
  }
  .frn-panel {
    width: 100%;
    max-height: none;
    display: none;
  }

  /* Panel en overlay plein écran sur tablette */
  body.frn-mobile-panel-open .frn-panel {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 300;
    border-radius: 0;
    max-height: 100vh;
    max-height: 100dvh;
  }

  body.frn-mobile-panel-open .frn-table-container,
  body.frn-mobile-panel-open .frn-kpi-row,
  body.frn-mobile-panel-open .frn-toolbar,
  body.frn-mobile-panel-open .header-fournisseur {
    display: none !important;
  }

  .frn-mobile-back {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--main-bg-color);
    color: #fff;
    font-size: 10pt;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    border: none;
  }

  /* KPI compacts tablette */
  .frn-kpi-row {
    gap: 8px;
    margin-bottom: 10px;
  }

  .frn-kpi-card {
    padding: 8px 10px;
    gap: 8px;
    min-width: 120px;
  }

  .frn-kpi-icon {
    width: 32px;
    height: 32px;
    font-size: 14px;
    border-radius: 8px;
  }

  .frn-kpi-value {
    font-size: 14pt;
  }

  .frn-kpi-label {
    font-size: 7.5pt;
  }

  /* Toolbar */
  .frn-mobile-filters-toggle {
    display: inline-flex;
  }

  .frn-toolbar-filters {
    display: none;
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .frn-toolbar-filters-open {
    display: flex !important;
  }

  /* Modal full-screen mobile */
  .frn-modal {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .frn-form-grid {
    grid-template-columns: 1fr;
  }

  /* Cacher colonnes table moins importantes */
  .frn-hide-tablet {
    display: none !important;
  }
}

@media (max-width: 768px) {
  .page_fournisseur {
    padding: 6px 8px;
  }

  /* KPI mini grille 3 colonnes */
  .frn-kpi-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px;
    margin-bottom: 6px;
  }

  .frn-kpi-card {
    min-width: unset;
    padding: 4px 6px;
    gap: 5px;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  }

  .frn-kpi-icon {
    width: 22px;
    height: 22px;
    font-size: 10px;
    border-radius: 5px;
  }

  .frn-kpi-value {
    font-size: 10pt;
    line-height: 1;
  }

  .frn-kpi-label {
    font-size: 6.5pt;
    margin-top: 0;
  }

  .frn-kpi-sub {
    display: none;
  }

  /* Toolbar mobile */
  .frn-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .frn-toolbar-main {
    flex-wrap: wrap;
    gap: 6px;
  }

  .frn-toolbar-main input[type="text"] {
    flex: 1;
    min-width: 0;
  }

  .frn-toolbar select {
    min-width: 0;
  }

  /* Cacher colonnes table */
  .frn-hide-mobile {
    display: none !important;
  }

  .frn-table {
    font-size: 8.5pt;
  }

  .frn-table thead th {
    padding: 6px;
    font-size: 8pt;
  }

  .frn-table tbody td {
    padding: 6px;
  }

  .header-fournisseur h1 {
    font-size: 13pt;
  }

  .header-fournisseur .frn-btn-primary {
    padding: 6px 10px;
    font-size: 9pt;
  }
}
