* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f4f6fb;
  color: #1c2330;
  line-height: 1.55;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 1.25rem 2rem;
  background: #0f2454;
  color: #fff;
  border-bottom: 4px solid #f08a24;
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.04em;
}

.topbar .subtitle {
  font-size: 0.9rem;
  opacity: 0.8;
}

.container {
  max-width: 720px;
  margin: 3rem auto;
  padding: 0 1.5rem;
}

/* Variante large pour la home : deux colonnes (Bienvenue | Mandat) */
.container.container-home {
  max-width: 1100px;
}

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .home-grid {
    grid-template-columns: 1fr;
  }
}

/* Sur la home, la carte hero a aussi un margin-top à 0 pour rester alignée à la mandate card.
   Chained selector pour battre `.card + .card` qui vient plus bas dans la feuille. */
.home-grid > .card + .card { margin-top: 0; }

.card {
  background: #fff;
  border-radius: 12px;
  padding: 2.5rem;
  box-shadow: 0 4px 24px rgba(15, 36, 84, 0.08);
}

.card h1 {
  margin-top: 0;
  font-size: 1.6rem;
  color: #0f2454;
}

.card.success h1 { color: #1c7a3e; }
.card.error h1 { color: #b1232a; }

.card h2 {
  margin-top: 0;
  font-size: 1.2rem;
  color: #0f2454;
}

.card + .card {
  margin-top: 1.25rem;
}

.card.hero h1 {
  font-size: 1.9rem;
  margin-bottom: 0.6rem;
}

.lead {
  font-size: 1.1rem;
  color: #1c2330;
  margin: 0;
}

/* Hero + CTA fusionnés pour que le bouton soit visible above-the-fold */
.hero-cta {
  text-align: center;
  border-top: 4px solid #f08a24;
}

.hero-cta .lead {
  margin: 0.5rem auto 1.4rem;
  max-width: 32rem;
}

.btn-large {
  font-size: 1.05rem;
  padding: 1rem 2.2rem;
  margin-top: 0;
}

.text-center { text-align: center; }

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.cta-row .btn-primary,
.cta-row .btn-secondary { margin-top: 0; }

.checklist {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 1.25rem;
}

.checklist li {
  position: relative;
  padding: 0.4rem 0 0.4rem 1.8rem;
  border-bottom: 1px dashed #eef1f7;
}

.checklist li:last-child { border-bottom: none; }

.checklist li::before {
  content: "✓";
  position: absolute;
  left: 0.2rem;
  top: 0.4rem;
  color: #1c7a3e;
  font-weight: 700;
  font-size: 1.05rem;
}

.process-steps {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
  counter-reset: process-step;
}

.process-steps li {
  display: grid;
  grid-template-columns: 3rem 1fr;
  gap: 1rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid #eef1f7;
}

.process-steps li:last-child { border-bottom: none; }

.step-icon {
  font-size: 1.6rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  background: #f4f6fb;
  border-radius: 50%;
}

.step-body strong {
  display: block;
  font-size: 1rem;
  color: #0f2454;
  margin-bottom: 0.2rem;
}

.step-body p {
  margin: 0;
  font-size: 0.95rem;
  color: #3a4255;
}

.cta-card {
  text-align: center;
  border-top: 4px solid #f08a24;
}

.cta-card h2 { color: #0f2454; }
.cta-card .btn-primary { margin-top: 1rem; }

.btn-primary,
.btn-secondary {
  display: inline-block;
  margin-top: 1.5rem;
  padding: 0.85rem 1.6rem;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
}

.btn-primary {
  background: #0f2454;
  color: #fff;
}

.btn-primary:hover { background: #163275; }

.btn-secondary {
  background: #e6ebf5;
  color: #0f2454;
}

.btn-secondary:hover { background: #d3dcee; }

.meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1.2rem;
  margin: 1.5rem 0;
}

.meta dt { color: #5a6478; }
.meta dd { margin: 0; font-weight: 600; }

.warning,
.info {
  margin: 1.25rem 0;
  padding: 0.85rem 1rem;
  border-left: 4px solid;
  border-radius: 4px;
  font-size: 0.95rem;
}

.warning {
  background: #fff6e0;
  border-left-color: #f08a24;
  color: #6b4a10;
}

.info {
  background: #e8f1ff;
  border-left-color: #2266c9;
  color: #1a3a72;
}

details {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: #f7f9fd;
  border-radius: 8px;
}

details summary {
  cursor: pointer;
  color: #0f2454;
  font-weight: 600;
}

pre {
  margin: 0.75rem 0 0;
  padding: 0.75rem;
  background: #0f2454;
  color: #d9e3f7;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.85rem;
}

.footer {
  text-align: center;
  padding: 2rem 0 3rem;
  color: #6b7384;
}

/* === Admin dashboard === */

body.admin .topbar {
  position: relative;
}

.admin-nav {
  margin-left: auto;
  display: flex;
  gap: 1.5rem;
  font-size: 0.9rem;
}

.admin-nav a {
  color: #fff;
  text-decoration: none;
  opacity: 0.85;
}

.admin-nav a:hover { opacity: 1; }

.admin-container {
  max-width: 1200px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.admin-header h1 {
  color: #0f2454;
  margin: 0;
  font-size: 1.4rem;
}

.admin-filters {
  display: flex;
  gap: 0.5rem;
}

.filter-chip {
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid #d3dcee;
  color: #1c2330;
  text-decoration: none;
  font-size: 0.85rem;
}

.filter-chip.active {
  background: #0f2454;
  color: #fff;
  border-color: #0f2454;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-pending      { background: #e8f1ff; color: #1a3a72; }
.badge-validated    { background: #d6f1de; color: #1c7a3e; }
.badge-error        { background: #fde0e0; color: #b1232a; }
.badge-needs_relink { background: #ffe9d6; color: #8a3a08; }
.badge-expired      { background: #e6ebf5; color: #6b7384; }
.badge-transferred  { background: #c4ead0; color: #0f5a2a; }
.event-badge        { background: #f0e6fa; color: #4a2470; }

.zeendoc-card {
  background: #f5fbf7;
  border-left: 4px solid #1c7a3e;
}
.zeendoc-card h2 { color: #1c7a3e; }

.row-transferred { background: #f9fdfa; }

.admin-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}
.admin-actions .btn-primary,
.admin-actions .btn-secondary { margin-top: 0; }

.filter-toggle {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: #5a6478;
}
.filter-toggle label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
}

.token-card {
  background: #fff;
  border-left: 4px solid #2266c9;
}
.token-card-expired { border-left-color: #b1232a; background: #fff7f7; }
.token-card h2 { color: #0f2454; }

.token-full {
  display: inline-block;
  max-width: 100%;
  margin-top: 0.5rem;
  padding: 0.45rem 0.65rem;
  background: #f4f6fb;
  border: 1px solid #d3dcee;
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  word-break: break-all;
  -webkit-user-select: all;
  user-select: all;
  cursor: text;
}

/* Reveal/hide toggle for sensitive tokens (no JS, uses <details>) */
.token-reveal {
  display: inline-block;
  max-width: 100%;
}

.token-reveal summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.1rem 0;
}

.token-reveal summary::-webkit-details-marker { display: none; }
.token-reveal summary::marker { content: ""; }

.token-prefix {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  color: #4a2470;
}

.reveal-btn {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  background: #e6ebf5;
  color: #0f2454;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.token-reveal:not([open]) .reveal-btn::before { content: "🔒 Afficher"; }
.token-reveal[open] .reveal-btn::before       { content: "🔓 Masquer"; }
.token-reveal[open] .reveal-btn               { background: #d6f1de; color: #1c7a3e; }

.token-reveal summary:hover .reveal-btn       { filter: brightness(0.96); }

.text-ok    { color: #1c7a3e; font-weight: 600; }
.text-error { color: #b1232a; font-weight: 600; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(15, 36, 84, 0.06);
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid #eef1f7;
  font-size: 0.9rem;
}

.admin-table thead {
  background: #f4f6fb;
  color: #5a6478;
  font-size: 0.78rem;
  text-transform: uppercase;
}

.admin-table tbody tr:hover { background: #f9fbff; }
.admin-table tbody tr.row-error { background: #fff7f7; }

.admin-table code {
  font-size: 0.82rem;
  color: #4a2470;
}

.btn-tiny {
  display: inline-block;
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
  background: #e6ebf5;
  color: #0f2454;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
}

.btn-tiny:hover { background: #d3dcee; }

.muted { color: #6b7384; font-size: 0.85rem; }
.empty { color: #6b7384; font-style: italic; padding: 2rem; text-align: center; }
.back-link { color: #5a6478; text-decoration: none; font-size: 0.9rem; }
.back-link:hover { color: #0f2454; }

.pagination {
  margin-top: 1.25rem;
  display: flex;
  gap: 0.75rem;
}

.inline-form {
  margin: 0;
}

.inline-form button {
  margin-top: 0;
}

.search-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem 1rem;
  background: #fff;
  padding: 1rem 1.25rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 4px rgba(15, 36, 84, 0.06);
  align-items: end;
}

.search-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: #5a6478;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.search-form input,
.search-form select {
  font-size: 0.95rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid #d3dcee;
  border-radius: 6px;
  background: #f7f9fd;
  color: #1c2330;
  text-transform: none;
}

.search-form button {
  margin-top: 0;
}

.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
  border-left: 2px solid #d3dcee;
}

.timeline-event {
  position: relative;
  padding: 0.5rem 0 1rem 1.25rem;
  margin-left: 0.5rem;
}

.timeline-event::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 0.85rem;
  width: 10px;
  height: 10px;
  background: #0f2454;
  border-radius: 50%;
}

.timeline-event.timeline-error::before { background: #b1232a; }

.timeline-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
}

.timeline-error-body {
  margin-top: 0.4rem;
  padding: 0.5rem 0.75rem;
  background: #fde0e0;
  color: #6b1014;
  border-radius: 4px;
  font-size: 0.82rem;
}

.error-cell {
  color: #b1232a;
  font-size: 0.82rem;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}
