*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f8f9fa;
  color: #333;
}

.container {
  max-width: 900px;
  margin: 2rem auto;
  padding: 1rem;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
  width: 100%;
}

h1 {
  text-align: center;
  margin-bottom: 1.5rem;
}

input[type="text"], input[type="file"] {
  width: 100%;
  box-sizing: border-box;
  padding: 0.75rem;
  margin-bottom: 1rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 1rem;
  overflow: hidden;
}

.filters label {
  background-color: #e9ecef;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
}

.filters input[type="checkbox"] {
  margin-right: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

thead {
  background-color: #343a40;
  color: #fff;
}

th, td {
  text-align: left;
  padding: 0.75rem;
  border: 1px solid #dee2e6;
}

tbody tr:hover {
  background-color: #f1f3f5;
  cursor: pointer;
}

.highlight {
  background-color: yellow;
  font-weight: bold;
}

.collapsible {
  background-color: #eee;
  color: #444;
  cursor: pointer;
  padding: 5px;
  width: 100%;
  border: none;
  text-align: left;
  outline: none;
  font-size: 16px;
}

.filters.collapsed {
  display: none;
}

.fav-actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 1rem 0;
}

.fav-actions-bar .favButton {
  flex: 1 1 auto;
  min-width: 140px;
  text-align: center;
  padding: 8px 12px;
  cursor: pointer;
}

@media (max-width: 600px) {
  table {
    font-size: 0.8rem;
  }

  th, td {
    padding: 0.4rem 0.5rem;
  }

  .container {
    margin: 0.5rem;
    padding: 0.75rem;
    width: auto;
    border-radius: 6px;
  }

  input[type="text"] {
    font-size: 1rem;
  }

  /* Responsive card layout for favorites table on smartphones */
  #resultsContainer table,
  #resultsContainer thead,
  #resultsContainer tbody,
  #resultsContainer tr,
  #resultsContainer td {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }

  #resultsContainer thead {
    display: none;
  }

  #resultsContainer tbody tr {
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    margin-bottom: 12px;
    padding: 12px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    position: relative;
    box-sizing: border-box;
  }

  #resultsContainer td {
    padding: 2px 0;
    border: none;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: normal;
  }

  #resultsContainer td.fav-natinf {
    font-size: 1.1rem;
    font-weight: bold;
    color: #007bff;
    display: inline-block;
    margin-right: 8px;
  }

  #resultsContainer td.fav-nature {
    display: inline-block;
    font-size: 0.85rem;
    color: #495057;
    background: #e9ecef;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
  }

  #resultsContainer td.fav-qualification {
    display: block;
    margin: 8px 0;
    font-size: 0.95rem;
    line-height: 1.4;
    color: #212529;
  }

  #resultsContainer td.fav-category {
    display: block;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #f1f3f5;
  }

  #resultsContainer td.fav-action {
    position: absolute;
    top: 10px;
    right: 10px;
    width: auto;
    padding: 0;
  }

  #resultsContainer .remove-fav {
    background: #fff0f0;
    border: 1px solid #ffcaca;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    cursor: pointer;
  }
}

#closeBtn {
  position:absolute;
  top: 10px;
  left: 10px;
  background: #007bff33;
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: background 0.3s ease;
}

#refreshBtn {
  position:absolute;
  top: 10px;
  right: 10px;
  background: #007bff33;
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: background 0.3s ease;
}

#Montant {
  position: absolute;
  top: 10px;
  right: 60px;
  background: #007bff33;
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 20px;
  text-align: center;
  line-height: 40px;
  text-decoration: none;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: background 0.3s ease;
}

#favBtn {
  position: absolute;
  top: 10px;
  right: 110px;
  background: #28a74633;
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 20px;
  text-align: center;
  line-height: 40px;
  text-decoration: none;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: background 0.3s ease;
}

#install {
  //position: absolute;
  //top: 10px;
  //right: 110px;
  background: #28a746;
  color: white;
  border: none;
  border-radius: 10%;
  //width: 40px;
  height: 25px;
  font-size: 16px;
  text-align: center;
  //line-height: 40px;
  text-decoration: none;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: background 0.3s ease;
}

#donBtn {
  position: absolute;
  top: 10px;
  left: 10px;
  background: #28a746;
  color: white;
  border: none;
  border-radius: 10%;
  height: 25px;
  font-size: 16px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: background 0.3s ease;
}

#closeBtn:hover {
  background: #0056b3;
}

#chatBtn:hover {
  background: #1e7e34;
}

#refreshBtn:hover {
  background: #0056b3;
}

#Montant:hover {
  background: #0056b3;
}

.pastilles {
  margin-bottom: 1em;
}
.pastille {
  display: inline-block;
  background: #444;
  color: white;
  border-radius: 12px;
  padding: 4px 10px;
  margin-right: 6px;
  font-size: 0.9em;
}
.pastille.immobilisation { background: #f39c12; }
.pastille.fourriere { background: #ddb263; }
.pastille.points { background: #2980b9; }
.pastille.montant { background: #27ae60; }
.pastille.pve { background: #9b59b6; }
.pastille.alavole { background: #2ccfd4; }
.pastille.retention { background: #c0392b; }
.pastille.afd { background: #1caf13; }

.remove-fav {
  display: inline-block;
  background: #f8f6f5;
  color: white;
  border-radius: 12px;
  padding: 10px 10px;
  margin-right: 6px;
  font-size: 0.9em;
  width: 100%;
  height: 100%;
}

.favButton {
  display: inline-block;
  background: #f8f6f5;
  color: black;
  border-radius: 12px;
  padding: 4px 10px;
  margin-right: 6px;
  font-size: 0.9em;
}

/* --- Styles pour les catégories de favoris --- */
.category-container {
  margin: 0.75rem 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.category-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  width: 100%;
  max-width: 100%;
  padding: 2px 0;
  box-sizing: border-box;
}

.category-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: #e9ecef;
  color: #495057;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  user-select: none;
  box-sizing: border-box;
  flex: 0 0 auto;
}

.category-pill:hover {
  background-color: #dee2e6;
}

.category-pill.active {
  background-color: #007bff;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 123, 255, 0.3);
}

.category-pill .category-count {
  background-color: rgba(0, 0, 0, 0.1);
  color: inherit;
  font-size: 0.75rem;
  padding: 2px 7px;
  border-radius: 10px;
}

.category-pill.active .category-count {
  background-color: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.category-pill.action-pill {
  background-color: #28a745;
  color: #fff;
  font-weight: 500;
}

.category-pill.action-pill:hover {
  background-color: #218838;
}

.category-pill.manage-pill {
  background-color: #6c757d;
  color: #fff;
  font-weight: 500;
}

.category-pill.manage-pill:hover {
  background-color: #5a6268;
}

.category-select {
  padding: 5px 8px;
  border: 1px solid #ced4da;
  border-radius: 6px;
  background-color: #fff;
  font-size: 0.85rem;
  color: #333;
  cursor: pointer;
  max-width: 150px;
  width: 100%;
  box-sizing: border-box;
}

.category-select:focus {
  border-color: #80bdff;
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* Modale de gestion des catégories */
.custom-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(2px);
  padding: 1rem;
  box-sizing: border-box;
}

.custom-modal {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  box-sizing: border-box;
}

.custom-modal h2 {
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-close-icon {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: #666;
}

.modal-category-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.modal-category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: #f8f9fa;
  border-radius: 6px;
  margin-bottom: 8px;
  border: 1px solid #e9ecef;
  gap: 8px;
}

.modal-category-name {
  font-weight: 500;
  word-break: break-word;
}

.modal-category-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.modal-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s ease;
}

.modal-btn-primary {
  background-color: #007bff;
  color: white;
}
.modal-btn-primary:hover { background-color: #0056b3; }

.modal-btn-secondary {
  background-color: #6c757d;
  color: white;
}
.modal-btn-secondary:hover { background-color: #545b62; }

.modal-btn-danger {
  background-color: #dc3545;
  color: white;
}
.modal-btn-danger:hover { background-color: #bd2130; }

.modal-btn-icon {
  background: #e9ecef;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}
.modal-btn-icon:hover { background: #dee2e6; }