/* ===== Reset minimal ===== */
* {
  box-sizing: border-box;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  background-color: #f4f6f8;
  color: #333;
  margin: 0;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

/* ===== Titres ===== */
h1 {
  margin-bottom: 30px;
  font-size: 1.8em;
  color: #2c3e50;
  border-bottom: 3px solid #2c7be5;
  padding-bottom: 10px;
}

h2 {
  margin-top: 0;
  color: #2c3e50;
  font-size: 1.3em;
  margin-bottom: 20px;
}

/* ===== Contrôles ===== */
.controls {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
}

.control-group label {
  font-weight: bold;
  color: #2c3e50;
  font-size: 0.95em;
}

.control-group select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 2px solid #ddd;
  border-radius: 4px;
  background-color: white;
  font-size: 0.95em;
  cursor: pointer;
  transition: border-color 0.3s;
}

.control-group select:hover {
  border-color: #2c7be5;
}

.control-group select:disabled {
  background-color: #f0f0f0;
  cursor: not-allowed;
  opacity: 0.6;
}

/* ===== Pagination ===== */
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  padding: 10px;
  background: white;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#pageInfo {
  margin: 0 10px;
  font-weight: bold;
  color: #2c3e50;
  min-width: 100px;
  text-align: center;
}

/* ===== Tableau ===== */
table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-top: 20px;
}

#content {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

table thead {
  background-color: #2c7be5;
  color: white;
  font-weight: bold;
}

table th,
table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #ddd;
}

table tbody tr {
  transition: background-color 0.2s;
}

table tbody tr:hover {
  background-color: #f9f9f9;
}

table td[contenteditable] {
  cursor: text;
  border-radius: 2px;
  transition: background-color 0.2s;
}

/* Distinctions des cellules du tableau */
table td.value-empty[contenteditable] {
  background-color: #f5f5f5;
  color: #999;
}

table td.value-empty[contenteditable]:focus {
  background-color: #e8e8e8;
  outline: 2px solid #999;
  outline-offset: -1px;
}

table td.value-zero[contenteditable] {
  background-color: #fff3cd;
  color: #333;
  font-weight: 500;
}

table td.value-zero[contenteditable]:focus {
  background-color: #ffe69c;
  outline: 2px solid #ffc107;
  outline-offset: -1px;
}

table td[contenteditable]:not(.value-empty):not(.value-zero) {
  background-color: #fffacd;
}

table td[contenteditable]:not(.value-empty):not(.value-zero):focus {
  background-color: #fff8dc;
  outline: 2px solid #2c7be5;
  outline-offset: -1px;
}

/* ===== Formulaire ===== */
.form-card {
  max-width: 700px;
  margin: 20px auto;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  background: white;
}

.form-navigation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 6px;
  border-left: 4px solid #2c7be5;
}

.record-info {
  font-weight: bold;
  color: #2c3e50;
  min-width: 80px;
  text-align: center;
  font-size: 0.95em;
}

/* ===== Légende des couleurs ===== */
.form-legend {
  display: flex;
  gap: 25px;
  margin-bottom: 20px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 6px;
  border-left: 4px solid #6c757d;
  font-size: 0.9em;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-color {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 2px;
  border: 1px solid #ddd;
}

.legend-empty {
  background-color: #f5f5f5;
  border-color: #999;
}

.legend-zero {
  background-color: #fff3cd;
  border-color: #ffc107;
}

/* ===== Champs du formulaire ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 25px;
}

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

.form-group label {
  font-weight: bold;
  color: #2c3e50;
  font-size: 0.95em;
}

.form-group input {
  padding: 10px 12px;
  border: 2px solid #ddd;
  border-radius: 4px;
  font-size: 0.95em;
  transition: border-color 0.3s, box-shadow 0.3s, background-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: #2c7be5;
  box-shadow: 0 0 5px rgba(44, 123, 229, 0.3);
}

/* Distinctions des champs du formulaire */
.form-group input.value-empty {
  background-color: #f5f5f5;
  color: #999;
}

.form-group input.value-empty:focus {
  background-color: #e8e8e8;
  border-color: #999;
}

.form-group input.value-zero {
  background-color: #fff3cd;
  color: #333;
  font-weight: 500;
}

.form-group input.value-zero:focus {
  background-color: #ffe69c;
  border-color: #ffc107;
  box-shadow: 0 0 5px rgba(255, 193, 7, 0.3);
}

/* ===== Boutons ===== */
button {
  padding: 10px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95em;
  font-weight: 500;
  transition: all 0.3s;
}

/* Boutons de navigation */
.btn-nav {
  background: #e8f0ff;
  color: #2c7be5;
  padding: 8px 12px;
  border: 1px solid #2c7be5;
  font-size: 1em;
  min-width: 44px;
}

.btn-nav:hover:not(:disabled) {
  background: #2c7be5;
  color: white;
  transform: scale(1.05);
}

.btn-nav:disabled {
  background: #f0f0f0;
  color: #ccc;
  cursor: not-allowed;
  border-color: #ccc;
}

/* Boutons d'action */
.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 25px;
  padding-top: 20px;
  border-top: 1px solid #ddd;
  flex-wrap: wrap;
}

.btn-primary {
  background: linear-gradient(135deg, #2c7be5, #1a68d1);
  color: white;
  box-shadow: 0 2px 4px rgba(44, 123, 229, 0.3);
  flex: 1;
  min-width: 180px;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #1a68d1, #0d4fa8);
  box-shadow: 0 4px 8px rgba(44, 123, 229, 0.4);
  transform: translateY(-2px);
}

.btn-primary:disabled {
  background: #ccc;
  cursor: not-allowed;
  box-shadow: none;
  opacity: 0.6;
}

.btn-secondary {
  background: #6c757d;
  color: white;
  flex: 1;
  min-width: 180px;
}

.btn-secondary:hover {
  background: #5a6268;
}

.btn-danger {
  background: #e74c3c;
  color: white;
  flex: 1;
  min-width: 180px;
}

.btn-danger:hover {
  background: #c0392b;
  box-shadow: 0 4px 8px rgba(231, 76, 60, 0.3);
  transform: translateY(-2px);
}

/* Bouton supprimer dans tableau */
button[onclick*="deleteRow"] {
  background: #e74c3c;
  color: white;
  padding: 4px 8px;
  font-size: 0.9em;
  flex: none;
  min-width: auto;
}

button[onclick*="deleteRow"]:hover {
  background: #c0392b;
}

/* ===== Contrôles de sauvegarde ===== */
.save-controls {
  display: flex;
  justify-content: center;
  margin-top: 30px;
  gap: 10px;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-navigation {
    flex-wrap: wrap;
  }

  .form-legend {
    flex-direction: column;
    gap: 10px;
  }

  .form-actions {
    flex-direction: column;
  }

  .btn-primary,
  .btn-secondary,
  .btn-danger {
    width: 100%;
    min-width: unset;
  }
}

@media (max-width: 768px) {
  body {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  h1 {
    font-size: 1.4em;
    margin-bottom: 15px;
  }

  h2 {
    font-size: 1.1em;
    margin-bottom: 15px;
  }

  .form-card {
    padding: 20px;
    margin: 10px auto;
  }

  table {
    font-size: 0.9em;
    width: max-content;
    min-width: 100%;
    margin-top: 10px;
  }

  table th,
  table td {
    padding: 8px;
    white-space: nowrap;
  }

  .controls {
    flex-direction: column;
    gap: 10px;
  }

  .control-group {
    width: 100%;
    min-width: 0;
  }

  .pagination-controls {
    gap: 5px;
    padding: 8px;
  }

  button {
    min-height: 44px;
    padding: 8px 12px;
    font-size: 0.9em;
  }

  .form-navigation {
    gap: 5px;
    padding: 10px;
  }

  .btn-nav {
    padding: 6px 10px;
    font-size: 0.9em;
  }

  .record-info {
    min-width: 60px;
    font-size: 0.85em;
  }

  .form-grid {
    gap: 12px;
  }

  .form-group input {
    padding: 8px 10px;
    min-height: 44px;
    font-size: 16px;
  }

  .form-actions {
    gap: 8px;
  }

  .form-legend {
    font-size: 0.85em;
    gap: 15px;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.2em;
  }

  .form-card {
    padding: 15px;
  }

  .pagination-controls {
    flex-wrap: wrap;
  }

  button {
    padding: 8px 10px;
    font-size: 0.9em;
  }

  table th,
  table td {
    padding: 6px;
    font-size: 0.85em;
  }

  .form-navigation {
    gap: 4px;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(2, 44px) minmax(64px, 1fr) repeat(2, 44px);
    width: 100%;
  }

  .btn-nav {
    width: 44px;
    min-width: 44px;
    padding: 6px;
    font-size: 0.9em;
  }

  .record-info {
    font-size: 0.8em;
  }

  .form-grid {
    gap: 10px;
  }

  .form-actions {
    gap: 6px;
  }

  .btn-primary,
  .btn-secondary,
  .btn-danger {
    min-width: auto;
  }

  .form-legend {
    font-size: 0.75em;
    gap: 10px;
  }

  .legend-color {
    width: 16px;
    height: 16px;
  }
}
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 16px;
}

.top-bar h1 {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.btn-mode-switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 12px;
  border-radius: 4px;
  background: #2c7be5;
  color: white;
  text-decoration: none;
  font-size: 0.95em;
  font-weight: 500;
}

.btn-mode-switch:hover {
  background: #1a68d1;
}

.btn-logout {
  background: #dc3545;
  color: white;
  border: none;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 4px;
}

.btn-logout:hover {
  background: #c82333;
}

@media (max-width: 640px) {
  .top-bar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .btn-mode-switch,
  .btn-logout {
    width: 100%;
    min-height: 44px;
  }
}

.filter-bar{
    display:flex;
    align-items:center;
    gap:10px;
    margin:15px 0;
}

.filter-bar input{
    flex:1;
    min-width:0;
    min-height:44px;
    padding:8px 10px;
    font-family:monospace;
}

@media (max-width: 640px) {
  .filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .filter-bar label,
  .filter-bar input {
    grid-column: 1 / -1;
  }

  .filter-bar input {
    width: 100%;
    font-size: 16px;
  }

  .filter-bar .btn-secondary {
    width: 100%;
    min-width: 0;
  }

  .pagination-controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(44px, 1fr));
    width: 100%;
  }

  .pagination-controls #pageInfo {
    grid-column: 1 / -1;
    grid-row: 1;
    min-width: 0;
    padding: 4px 0;
  }

  .pagination-controls #addBtn {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
  }

  .save-controls {
    position: sticky;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 5;
    margin-top: 18px;
  }

  .save-controls .btn-primary {
    width: 100%;
  }
}

.status-message {
  margin: 10px 0 15px;
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 0.95em;
}

.status-message:empty {
  display: none;
}

.status-message-info {
  background: #e8f0ff;
  color: #1a4f9c;
  border-left: 4px solid #2c7be5;
}

.status-message-success {
  background: #eaf7ef;
  color: #1f7a3f;
  border-left: 4px solid #28a745;
}
