:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e2e6ea;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --ok: #16a34a;
  --err: #dc2626;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem; position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.topbar nav { display: flex; gap: 1rem; align-items: center; }

.container { max-width: 900px; margin: 1.5rem auto; padding: 0 1.5rem; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.req { color: var(--err); }
.ok { color: var(--ok); font-weight: 600; }
.err { color: var(--err); font-weight: 600; }

/* Buttons */
.btn {
  display: inline-block; padding: .5rem .9rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: #fff; color: var(--text);
  cursor: pointer; font-size: .95rem;
}
.btn:hover { text-decoration: none; background: #f9fafb; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }

/* Cards & forms */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem;
}
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .3rem; }
.field input, .field select, .field textarea {
  width: 100%; padding: .55rem .65rem; border: 1px solid var(--border);
  border-radius: 8px; font: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.field-error input, .field-error select, .field-error textarea { border-color: var(--err); }
.err-msg { color: var(--err); display: block; margin-top: .25rem; }
.parcours-bloc { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-top: 1rem; }
.parcours-bloc legend { font-weight: 700; padding: 0 .4rem; }
.actions { display: flex; gap: .75rem; margin-top: 1.25rem; }

/* Flash */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }
.flash-info { background: #dbeafe; color: #1e40af; }

/* Header user menu */
.user-menu { display: inline-flex; align-items: center; gap: .75rem; margin-left: .5rem;
  padding-left: .75rem; border-left: 1px solid var(--border); }
.user-name { font-size: .9rem; color: var(--muted); font-weight: 600; }

/* Auth pages */
.auth-wrap { max-width: 380px; margin: 3rem auto; }
.auth-card h1 { font-size: 1.3rem; }
.btn-block { width: 100%; text-align: center; }
.auth-links { margin-top: 1rem; text-align: center; }

/* Filtres */
.filtres { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; align-items: center; }
.filtres select, .filtres input[type=text] {
  padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; }
.filtres input[type=text] { min-width: 200px; }

/* Actions dans les tableaux (admin) */
.row-actions { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.inline { display: inline; }
.link-btn { background: none; border: none; color: var(--primary); cursor: pointer;
  padding: 0; font: inherit; }
.link-btn:hover { text-decoration: underline; }

.pilotage-cta { margin-top: .5rem; }

/* Notices / bandeaux */
.notice { display: block; padding: .8rem 1rem; border-radius: var(--radius);
  margin-bottom: 1rem; border-left: 4px solid var(--muted); background: #fff; }
.notice-refus { background: #fee2e2; border-left-color: var(--err); color: #991b1b; }
.notice-alerte { background: #fef3c7; border-left-color: #d97706; color: #92400e; }
.notice-alerte ul { margin: .3rem 0 0; }
.notice-attente { background: #fef3c7; border-left-color: #d97706; color: #92400e;
  text-decoration: none; font-weight: 600; }
.notice-attente:hover { text-decoration: none; filter: brightness(.97); }
.card-completer { border-left: 4px solid #d97706; }

/* Stats tiles */
.stats-grid {
  display: grid; gap: 1rem; margin-bottom: 1.5rem;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.stat-tile {
  background: var(--card); border: 1px solid var(--border);
  border-left: 4px solid var(--muted); border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.stat-label { font-size: .82rem; color: var(--muted); font-weight: 600; line-height: 1.25; }
.stat-num { font-size: 2rem; font-weight: 700; margin: .2rem 0 .1rem; }
.stat-montant { font-size: .82rem; color: var(--muted); }
.stat-ouverts { border-left-color: var(--primary); }
.stat-ouverts .stat-num { color: var(--primary); }
.stat-client { border-left-color: #d97706; }
.stat-compagnie { border-left-color: #4f46e5; }
.stat-recours { border-left-color: #9333ea; }
.stat-refus { border-left-color: var(--err); }
.stat-clotures { border-left-color: #6b7280; }
.section-title { margin-top: 1.5rem; }

/* Sélecteur de statut sur la fiche */
.statut-form {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  margin-left: auto;
}
.statut-form select, .statut-form .statut-motif {
  padding: .4rem .55rem; border: 1px solid var(--border); border-radius: 8px; font: inherit;
}
.statut-form .statut-motif { width: 160px; }

/* Table */
.table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: .7rem .9rem; border-bottom: 1px solid var(--border); }
.table th { background: #f9fafb; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: #f9fafb; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* Badges statuts */
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge-NOUVEAU { background: #dbeafe; color: #1e40af; }
.badge-NON_COMPLET { background: #fef3c7; color: #92400e; }
.badge-EN_ATTENTE_COMPAGNIE { background: #e0e7ff; color: #3730a3; }
.badge-REFUS_FRANCHISE { background: #fee2e2; color: #991b1b; }
.badge-EN_ATTENTE_RECOURS { background: #f3e8ff; color: #6b21a8; }
.badge-CLOTURE { background: #e5e7eb; color: #374151; }

/* Detail */
.detail-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.detail-head h1 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
dl dt { font-weight: 600; color: var(--muted); font-size: .85rem; margin-top: .5rem; }
dl dd { margin: 0 0 .25rem; }
dl.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.5rem; }
.pieces, .timeline { list-style: none; padding: 0; margin: 0; }
.pieces li, .timeline li { padding: .35rem 0; border-bottom: 1px solid var(--border); }

@media (max-width: 700px) { .grid-2, dl.cols { grid-template-columns: 1fr; } }
