* {
  box-sizing: border-box;
}

/* Styles de base (autonome)
   Ce fichier était initialement dépendant d'un thème externe (dossier absent).
   On embarque ici un socle minimal pour garantir un rendu correct. */

:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --surface-color: #ffffff;
  --background-color: #f5f7fb;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --border-color: #e5e7eb;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 1px 3px rgba(15, 23, 42, 0.12);
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--background-color);
  color: var(--text-primary);
  line-height: 1.55;
}

header,
footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
}

header h1 {
  margin: 0 0 0.35rem 0;
  font-size: 1.9rem;
}

header p {
  margin: 0;
  color: var(--text-secondary);
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

/* Conteneur principal (hérite de .container du thème global) */

main.container {
  margin-top: 1.5rem;
  margin-bottom: 2rem;
}

.card {
  background: var(--surface-color, #ffffff);
  border-radius: 8px;
  padding: 1.25rem 1.5rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-md, 0 1px 3px rgba(15, 23, 42, 0.12));
  border: 1px solid var(--border-color, #e5e7eb);
}

.card h2 {
  margin-top: 0;
}

label {
  font-size: 0.95rem;
}

input[type='file'],
select,
button {
  font-family: inherit;
}

input[type='file'] {
  margin: 0.5rem 0 1rem;
}

button {
  border-radius: 4px;
  border: 1px solid var(--primary-color, #2563eb);
  background: var(--primary-color, #2563eb);
  color: #fff;
  padding: 0.35rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

button:hover:not([disabled]) {
  background: var(--primary-hover, #1d4ed8);
}

button.secondary {
  border-color: #9ca3af;
  background: #fff;
  color: #111827;
}

button.secondary:hover:not([disabled]) {
  background: #f3f4f6;
}

.muted {
  color: #6b7280;
}

.small {
  font-size: 0.8rem;
}

/* Footer : conservé depuis le thème global, pas de redéfinition ici */

/* Utilitaire pour masquer des sections */

.hidden {
  display: none;
}

/* Tableau d'aperçu */

#previewContainer {
  margin-top: 0.75rem;
}

.preview-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

#previewContainer h3 {
  margin: 0;
}

.preview-stats {
  white-space: nowrap;
}

.table-wrapper {
  max-height: 260px;
  overflow: auto;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  background: #fff;
}

.table-wrapper table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.table-wrapper th,
.table-wrapper td {
  border: 1px solid #e5e7eb;
  padding: 0.3rem 0.45rem;
  text-align: left;
}

.table-wrapper thead {
  background: #f3f4f6;
  position: sticky;
  top: 0;
  z-index: 1;
}

.table-wrapper thead th {
  font-weight: 600;
  font-size: 0.8rem;
  color: #374151;
}

.table-wrapper tbody tr:nth-child(even) {
  background: #f9fafb;
}

.table-wrapper tbody tr:hover {
  background: #e5f0ff;
}

.table-wrapper td {
  max-width: 260px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Les tableaux de stats doivent laisser respirer le contenu (pas de coupure en largeur)
   et ne pas scroller en interne (on laisse scroller toute la page). */
.stats-section .table-wrapper {
  max-height: none;
  overflow-y: visible;
}

.stats-section .table-wrapper td,
.stats-section .table-wrapper th {
  max-width: none;
  white-space: normal;
  text-overflow: clip;
}

.table-wrapper th.col-index,
.table-wrapper td.col-index {
  width: 2.5rem;
  text-align: right;
  color: #6b7280;
}

/* Mapping */

.mapping-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.mapping-container {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.mapping-row {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(200px, 1fr) minmax(180px, 260px);
  gap: 0.5rem;
  align-items: center;
}

.mapping-row label {
  font-weight: 500;
}

.mapping-row select {
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  font-size: 0.9rem;
}

.mapping-example {
  font-size: 0.8rem;
  color: #4b5563;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mapping-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
  gap: 0.75rem;
}

/* Filtres & graphiques */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.filters select {
  margin-left: 0.3rem;
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  font-size: 0.9rem;
}

#charts {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.charts-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

.chart-row-full .chart-card-wide {
  min-height: 320px;
}

.chart-card {
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 6px;
  padding: 0.75rem 0.75rem 0.5rem;
  background: var(--surface-color, #f9fafb);
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(15, 23, 42, 0.08));
}

.chart-card h3 {
  margin-top: 0;
  font-size: 1rem;
}

.summary {
  margin-top: 1rem;
}

.summary p {
  margin: 0.1rem 0;
}

/* Stats tables */

.stats-section {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.stats-card {
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 6px;
  padding: 0.75rem 0.75rem 0.5rem;
  background: var(--surface-color, #f9fafb);
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(15, 23, 42, 0.08));
}

.stats-card h3 {
  margin-top: 0;
  font-size: 1rem;
}

.small-table {
  max-height: 220px;
}

.mini-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8rem;
}

.mini-table th,
.mini-table td {
  padding: 0.3rem 0.55rem;
}

.mini-table thead th {
  background: #e5e7eb;
  font-weight: 600;
  border-bottom: 1px solid #d1d5db;
}

.mini-table tbody tr:nth-child(even) {
  background: #f9fafb;
}

.mini-table tbody tr:hover {
  background: #e5f0ff;
}

.mini-table tfoot td {
  font-weight: 600;
  border-top: 1px solid #d1d5db;
}

.mini-table th.num,
.mini-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 700px) {
  header {
    padding: 1rem 1rem 1.25rem;
  }

  .stats-section {
    grid-template-columns: 1fr;
  }

  main {
    padding: 0 0.75rem 2rem;
  }

  .mapping-row {
    grid-template-columns: 1fr;
    align-items: flex-start;
  }

  .mapping-example {
    white-space: normal;
  }
}
