/* =========================================================
   Gestion des Dossiers — feuille de style principale
   ========================================================= */

:root {
  --primary: #1e40af;
  --primary-dark: #1e3a8a;
  --primary-light: #eff6ff;
  --accent: #0d9488;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e2e8f0;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --success: #15803d;
  --success-bg: #f0fdf4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, .10);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ---------- En-tête ---------- */
.app-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  box-shadow: var(--shadow);
}

.app-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: #fff;
  letter-spacing: .2px;
}

.app-header .brand svg { flex: 0 0 auto; }

.app-header nav a {
  color: rgba(255,255,255,.9);
  font-weight: 500;
  font-size: .92rem;
  margin-left: 1.4rem;
}
.app-header nav a:hover { color: #fff; text-decoration: none; }

/* ---------- Layout général ---------- */
main.container { padding-top: 1.75rem; padding-bottom: 3rem; }

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 .3rem;
  color: var(--text);
}
.page-subtitle {
  color: var(--muted);
  font-size: .92rem;
  margin: 0 0 1.5rem;
}

/* ---------- Cartes / stats ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: .9rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat-card .stat-label {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: .35rem;
}
.stat-card .stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-dark);
}
.stat-card .stat-value.accent { color: var(--accent); }

.repartition-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}
.repartition-list li {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 999px;
  padding: .25rem .7rem;
  font-size: .8rem;
  font-weight: 600;
}

/* ---------- Panneau ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.5rem;
}
.panel h2 {
  font-size: 1.05rem;
  margin: 0 0 1rem;
  color: var(--text);
}

/* ---------- Formulaire de recherche ---------- */
.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: .7rem;
  align-items: flex-end;
}
.search-form .field { display: flex; flex-direction: column; gap: .35rem; }
.search-form .field.grow { flex: 1 1 260px; }
.search-form label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}

input[type=text], input[type=search], input[type=number], input[type=tel], select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .55rem .7rem;
  font-size: .95rem;
  background: #fff;
  color: var(--text);
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, .15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border: none;
  border-radius: 8px;
  padding: .6rem 1.15rem;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .05s;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }
.btn-outline {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: #f8fafc; text-decoration: none; }
.btn-danger-outline {
  background: #fff;
  color: var(--danger);
  border: 1px solid #fecaca;
}
.btn-danger-outline:hover { background: var(--danger-bg); text-decoration: none; }

/* ---------- Alertes / flash messages ---------- */
.alert {
  border-radius: 8px;
  padding: .8rem 1rem;
  margin-bottom: 1.2rem;
  font-size: .92rem;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: var(--success); border-color: #bbf7d0; }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: #fecaca; }
.alert-info { background: var(--primary-light); color: var(--primary-dark); border-color: #bfdbfe; }

/* ---------- Résultats ---------- */
.results-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .8rem;
  font-size: .88rem;
  color: var(--muted);
}

table.resultats {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
table.resultats th, table.resultats td {
  padding: .7rem .85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: .89rem;
}
table.resultats th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: .72rem;
  letter-spacing: .04em;
  white-space: nowrap;
}
table.resultats th a { color: var(--muted); }
table.resultats th a.active { color: var(--primary-dark); }
table.resultats tbody tr:hover { background: #f8fafc; }
table.resultats tbody tr:last-child td { border-bottom: none; }

.badge-position {
  display: inline-block;
  padding: .18rem .55rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary-dark);
  letter-spacing: .02em;
}
.badge-position.ancien {
  background: #fef3c7;
  color: #92400e;
}

.solde-cell { font-weight: 700; color: var(--text); white-space: nowrap; }

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-state svg { margin-bottom: .6rem; opacity: .5; }

/* ---------- Fiche dossier / formulaire d'édition ---------- */
.fiche-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.fiche-header h1 { font-size: 1.3rem; margin: 0 0 .25rem; }
.fiche-header .sub { color: var(--muted); font-size: .88rem; }

.edit-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem 1.2rem;
}
.edit-grid .field.full { grid-column: 1 / -1; }
.edit-grid .field { display: flex; flex-direction: column; gap: .35rem; }
.edit-grid label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
}
.edit-grid .hint { font-size: .76rem; color: var(--muted); }
.readonly-field {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .55rem .7rem;
  font-size: .95rem;
  color: var(--text);
  font-weight: 600;
}

.form-actions {
  display: flex;
  gap: .7rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ---------- Historique ---------- */
table.historique { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.historique th, table.historique td {
  padding: .55rem .7rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
table.historique th {
  color: var(--muted);
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: #f8fafc;
}
table.historique tr:last-child td { border-bottom: none; }
.mvt-badge {
  background: #f1f5f9;
  color: var(--muted);
  border-radius: 6px;
  padding: .15rem .5rem;
  font-size: .78rem;
  font-weight: 600;
}

.footer-note {
  text-align: center;
  color: var(--muted);
  font-size: .8rem;
  margin-top: 2.5rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 780px) {
  .app-header nav a { margin-left: .9rem; font-size: .85rem; }
  .edit-grid { grid-template-columns: 1fr; }

  table.resultats thead { display: none; }
  table.resultats, table.resultats tbody, table.resultats tr, table.resultats td {
    display: block;
    width: 100%;
  }
  table.resultats tr {
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--shadow);
  }
  table.resultats td {
    text-align: right;
    padding: .55rem .8rem;
    padding-left: 46%;
    position: relative;
    border-bottom: 1px solid var(--border);
    min-height: 1.6rem;
  }
  table.resultats td:last-child { border-bottom: none; }
  table.resultats td::before {
    content: attr(data-label);
    position: absolute;
    left: .8rem;
    width: 42%;
    text-align: left;
    font-weight: 600;
    color: var(--muted);
    font-size: .76rem;
    text-transform: uppercase;
  }
  table.historique { display: block; overflow-x: auto; white-space: nowrap; }
}

@media (max-width: 480px) {
  .app-header .brand span.full { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
