:root {
  --sidebar-bg: #191530;
  --sidebar-bg-hover: rgba(255,255,255,0.06);
  --sidebar-line: rgba(255,255,255,0.08);
  --sidebar-text: #a9a4c4;
  --sidebar-text-dim: #736e93;
  --sidebar-text-active: #ffffff;
  /* Même famille violette que le dégradé de la carte PDF (invitation_templates.php) —
     identité visuelle cohérente entre l'admin et l'invitation vue par les invités. */
  --accent-1: #7c3aed;
  --accent-2: #4a148c;
  --accent-gradient: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  --bg: #f4f4f9;
  --card: #ffffff;
  --line: #ebe8f3;
  --text: #241f36;
  --muted: #85819c;
  --ok: #15803d;
  --ok-bg: #e5f7ec;
  --wait: #a3762a;
  --wait-bg: #fbf1de;
  --err: #c0292a;
  --err-bg: #fbe9e9;
  --info: #5b3fae;
  --info-bg: #ece7fb;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 2px rgba(36,31,54,0.04), 0 8px 24px -16px rgba(36,31,54,0.12);
}

* { box-sizing: border-box; }
/* Garantit que [hidden] masque bien l'élément même si une règle plus
   spécifique (ex. .table-card { display: flex }) définit son display. */
[hidden] { display: none !important; }

/* Transition douce d'une page à l'autre (navigation same-origin) — pris en
   charge nativement par Chrome/Edge, ignoré sans effet ailleurs. */
@view-transition {
  navigation: auto;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

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

h1, h2, h3 { font-family: "Playfair Display", Georgia, serif; font-weight: 700; }

/* ------------------------------------------------------------------ */
/* Structure : barre latérale + zone principale                        */
/* ------------------------------------------------------------------ */

.app-shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: 264px;
  flex: 0 0 264px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 1.4rem 1.1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.4rem 0.5rem 1.1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--sidebar-line);
  text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; }
.brand-icon {
  font-size: 1.5rem;
  width: 2.4rem;
  height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-gradient);
  border-radius: 12px;
  flex: 0 0 auto;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-family: "Playfair Display", Georgia, serif; font-weight: 700; font-size: 1.15rem; color: #fff; }
.brand-name b { color: var(--accent-2); font-weight: 700; }
.brand-sub {
  font-size: 0.76rem;
  color: var(--sidebar-text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.5rem;
  margin-bottom: 1rem;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04);
}
.user-avatar {
  width: 2.3rem;
  height: 2.3rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-name { color: #fff; font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.76rem; color: var(--sidebar-text-dim); }

.side-nav { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }
.side-nav-back {
  color: var(--sidebar-text-dim);
  font-size: 0.8rem;
  padding: 0.4rem 0.6rem 0.8rem;
  display: block;
}
.side-nav-back:hover { color: var(--sidebar-text); text-decoration: none; }
.side-nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-weight: 500;
  font-size: 0.92rem;
}
.side-nav-item:hover { background: var(--sidebar-bg-hover); text-decoration: none; color: #fff; }
.side-nav-item.active { background: var(--accent-gradient); color: #fff; font-weight: 600; box-shadow: 0 4px 14px -4px rgba(124,58,237,0.55); }
.side-nav-icon { font-size: 1.05rem; width: 1.4rem; text-align: center; flex: 0 0 auto; }

.sidebar-footer { border-top: 1px solid var(--sidebar-line); padding-top: 0.9rem; margin-top: 0.9rem; }
.sidebar-footer a { color: var(--sidebar-text-dim); font-size: 0.85rem; }
.sidebar-footer a:hover { color: var(--sidebar-text-active); text-decoration: none; }

.main-area { flex: 1; min-width: 0; }

.page {
  max-width: 1160px;
  margin: 0 auto;
  padding: 2rem 2.2rem 3rem;
}
.page.bare {
  max-width: 480px;
  padding: 1.5rem 1.25rem 3rem;
}
.page.bare.wide { max-width: 900px; }

/* ------------------------------------------------------------------ */
/* Animations d'apparition au chargement                              */
/* Respecte "réduire les animations" (prefers-reduced-motion) — rien   */
/* n'est animé pour les personnes qui l'ont demandé. Les lignes de     */
/* tableau (tbody tr) ne sont volontairement pas animées : elles sont  */
/* montrées/masquées en continu par la recherche/pagination            */
/* (list-pagination.js) et une animation les ferait clignoter à        */
/* chaque frappe.                                                      */
/* ------------------------------------------------------------------ */
@media (prefers-reduced-motion: no-preference) {
  @keyframes page-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }
  @keyframes card-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .page { animation: page-fade-in 320ms ease-out both; }

  .card,
  .stat,
  .table-card {
    animation: card-fade-in 380ms ease-out both;
  }

  /* Apparition en cascade dans les grilles — plafonnée pour ne pas
     retarder l'affichage des listes longues (au-delà du 6e élément,
     même délai pour tout le monde). */
  .stat-grid > .stat:nth-child(1) { animation-delay: 20ms; }
  .stat-grid > .stat:nth-child(2) { animation-delay: 55ms; }
  .stat-grid > .stat:nth-child(3) { animation-delay: 90ms; }
  .stat-grid > .stat:nth-child(4) { animation-delay: 125ms; }
  .stat-grid > .stat:nth-child(n+5) { animation-delay: 160ms; }

  .tables-grid > .table-card:nth-child(1) { animation-delay: 20ms; }
  .tables-grid > .table-card:nth-child(2) { animation-delay: 50ms; }
  .tables-grid > .table-card:nth-child(3) { animation-delay: 80ms; }
  .tables-grid > .table-card:nth-child(4) { animation-delay: 110ms; }
  .tables-grid > .table-card:nth-child(5) { animation-delay: 140ms; }
  .tables-grid > .table-card:nth-child(n+6) { animation-delay: 170ms; }
}

.page-title { font-size: 1.7rem; margin: 0 0 0.25rem; color: var(--text); }

h1 { font-size: 1.5rem; margin: 0 0 0.2rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.8rem; font-family: "Inter", sans-serif; font-weight: 700; }
.subtitle { color: var(--muted); margin: 0 0 1.2rem; }
.event-subtitle { margin-bottom: 1.6rem; }
.back-link { margin-top: 0; }

/* ------------------------------------------------------------------ */
/* Cartes, tableaux, badges                                           */
/* ------------------------------------------------------------------ */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.3rem 1.4rem;
  margin-bottom: 1.2rem;
  box-shadow: var(--shadow-card);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.6rem;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-card);
}
.stat .value { font-size: 1.75rem; font-weight: 700; font-family: "Playfair Display", Georgia, serif; color: var(--text); }
.stat .label { color: var(--muted); font-size: 0.82rem; margin-top: 0.15rem; }

/* Statuts d'arrivée : même code couleur que les badges (.badge.ok / .badge.wait)
   utilisés partout ailleurs dans l'app — identité cohérente, pas une nouvelle teinte. */
.stat.stat-ok { border-color: #cdeeda; background: linear-gradient(180deg, var(--ok-bg), var(--card) 60%); }
.stat.stat-ok .value { color: var(--ok); }
.stat.stat-wait { border-color: #f5e3c2; background: linear-gradient(180deg, var(--wait-bg), var(--card) 60%); }
.stat.stat-wait .value { color: var(--wait); }

/* Tableau de bord : jauge du taux d'arrivée (ratio par rapport à un total —
   une jauge, pas un donut à deux parts : voir la piste "même dégradé, plus claire"). */
.meter-card { padding: 1.3rem 1.5rem; }
.meter-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.6rem; }
.meter-label { font-weight: 600; font-size: 0.95rem; }
.meter-value { font-family: "Playfair Display", Georgia, serif; font-weight: 700; font-size: 1.6rem; color: var(--accent-1); }
.meter-track {
  height: 16px;
  border-radius: 999px;
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid rgba(124, 58, 237, 0.28);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  min-width: 16px;
  border-radius: 999px;
  background: var(--accent-gradient);
  transition: width 400ms ease;
}
.meter-caption { color: var(--muted); font-size: 0.85rem; margin: 0.6rem 0 0; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.85rem 1rem; border-bottom: 1px solid var(--line); font-size: 0.92rem; }
th { color: var(--muted); font-weight: 600; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; background: #fbfafd; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfaff; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  flex: 0 0 auto;
}
.guest-cell { display: flex; align-items: center; gap: 0.7rem; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.wait { background: var(--wait-bg); color: var(--wait); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.info { background: var(--info-bg); color: var(--info); }

.btn {
  display: inline-block;
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  padding: 0.6rem 1.15rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 4px 14px -6px rgba(124,58,237,0.55);
  transition: filter 120ms ease, transform 120ms ease;
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--line); box-shadow: none; }
.btn.secondary:hover { background: #faf9fd; filter: none; }
.btn.small { padding: 0.4rem 0.8rem; font-size: 0.82rem; }
.btn.icon { padding: 0.35rem; width: 2.1rem; height: 2.1rem; display: inline-flex; align-items: center; justify-content: center; font-size: 1rem; line-height: 1; border-radius: 9px; background: #fff; color: var(--text); border: 1px solid var(--line); box-shadow: none; }
.btn.icon:hover { background: #f6f4fb; filter: none; }
.row-actions { display: inline-flex; gap: 0.35rem; align-items: center; }
.btn.danger { background: #fff; color: var(--err); border: 1px solid #f2c9c6; box-shadow: none; }
.btn.danger:hover { background: var(--err-bg); filter: none; }

.field { margin-bottom: 0.9rem; }
.field label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 0.35rem; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.15);
}
.field .hint { color: var(--muted); font-size: 0.78rem; margin-top: 0.25rem; }
.form-row { display: flex; gap: 0.8rem; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 160px; }
.form-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1rem; }

.banner { padding: 0.75rem 1.05rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: 0.9rem; }
.banner.success { background: var(--ok-bg); color: var(--ok); }
.banner.error { background: var(--err-bg); color: var(--err); }
.banner.warn { background: var(--wait-bg); color: var(--wait); }
.banner.info { background: var(--info-bg); color: var(--info); }

.pin-reveal {
  background: var(--wait-bg);
  border: 1px solid #eecd9a;
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.2rem;
  font-size: 0.95rem;
}
.pin-reveal b { font-size: 1.3rem; letter-spacing: 0.1em; }

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

/* Champ de recherche instantanée (pilule, icône + bouton d'effacement) */
.search-box { position: relative; flex: 1 1 320px; max-width: 440px; display: flex; align-items: center; }
.search-box .search-icon {
  position: absolute;
  left: 1rem;
  display: inline-flex;
  color: var(--muted);
  pointer-events: none;
}
.search-box input[type="text"] {
  width: 100%;
  padding: 0.68rem 2.6rem 0.68rem 2.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.92rem;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-card);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.search-box input[type="text"]::placeholder { color: var(--muted); }
.search-box input[type="text"]:focus {
  outline: none;
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.15);
}
.search-box .search-clear {
  position: absolute;
  right: 0.5rem;
  width: 1.7rem;
  height: 1.7rem;
  display: none;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--line);
  color: var(--muted);
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0;
  transition: background 120ms ease, color 120ms ease;
}
.search-box .search-clear:hover { background: #ddd6ee; color: var(--text); }
.search-box.has-value .search-clear { display: inline-flex; }

.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 0.86rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.filter-toggle input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--accent-1); cursor: pointer; }

/* Pagination des listes (invités, contrôle d'accès) */
.list-toolbar-meta { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; margin-bottom: 1rem; color: var(--muted); font-size: 0.9rem; }
.list-toolbar-meta label { display: flex; align-items: center; gap: 0.5rem; }
.page-size-select {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.list-pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1.1rem; }
.list-pager button:disabled { opacity: 0.4; cursor: not-allowed; }
.list-pager .page-info { color: var(--muted); font-size: 0.85rem; }

.empty-state { color: var(--muted); text-align: center; padding: 2.4rem 1rem; }

/* Contrôle d'accès : résultats de la recherche d'invité par nom */
.checkin-result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}
.checkin-result-row:last-child { border-bottom: none; }
.checkin-result-form { display: flex; align-items: center; gap: 0.6rem; flex: 0 0 auto; }
.checkin-override-inline { display: flex; align-items: center; gap: 0.3rem; font-size: 0.78rem; font-weight: 400; color: var(--muted); white-space: nowrap; }
.checkin-override-inline input { width: auto; }

details.create-panel { margin-bottom: 1.2rem; }
details.create-panel > summary {
  cursor: pointer;
  list-style: none;
  display: inline-block;
}
details.create-panel > summary::-webkit-details-marker { display: none; }
details.create-panel .card { margin-top: 0.8rem; margin-bottom: 0; }

/* Tables : plan de placement (une carte par table, invités listés dedans) */
.tables-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.table-card { display: flex; flex-direction: column; gap: 0.7rem; }
.table-card-head { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.table-card-head h3 { margin: 0; font-size: 1.05rem; }
.table-card-empty { color: var(--muted); font-size: 0.85rem; font-style: italic; margin: 0; }
.table-guest-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; max-height: 240px; overflow-y: auto; }
.table-guest-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.4rem 0.6rem; background: #faf9fd; border-radius: 8px; font-size: 0.88rem; }
.table-guest-list .party-size { color: var(--muted); font-size: 0.76rem; white-space: nowrap; }
.table-card-actions { margin-top: auto; display: flex; justify-content: flex-end; }

.section-title { font-family: "Playfair Display", Georgia, serif; font-size: 1.05rem; font-weight: 700; margin: 0 0 0.6rem; }

.unassigned-guests { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.unassigned-guests .chip { background: var(--wait-bg); color: var(--wait); border-radius: 999px; padding: 0.35rem 0.8rem; font-size: 0.82rem; font-weight: 500; }

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, #191530 0%, #2a2150 55%, #191530 100%);
}
.login-card { max-width: 380px; width: 100%; }
.login-card h1 { text-align: center; font-size: 1.8rem; }
.login-card h1 span { color: var(--accent-2); }
.login-card .subtitle { text-align: center; }
.login-switch { text-align: center; margin-top: 0.8rem; font-size: 0.88rem; }

.matricule { font-size: 0.78rem; color: var(--muted); }

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex: 0 0 auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 0.9rem 1rem; gap: 0.6rem 1rem; }
  .sidebar-brand { border-bottom: none; padding: 0; margin: 0; flex: 1 1 auto; min-width: 0; }
  .sidebar-user { margin: 0; padding: 0.3rem 0.5rem; }
  .side-nav { flex-direction: row; flex-wrap: wrap; width: 100%; order: 3; }
  .side-nav-back { display: none; }
  .side-nav-item { padding: 0.45rem 0.7rem; font-size: 0.85rem; }
  .sidebar-footer { border-top: none; padding: 0; margin: 0; }
}

@media (max-width: 640px) {
  .page { padding: 1.3rem 1rem 2.5rem; }
  th, td { padding: 0.6rem 0.5rem; font-size: 0.85rem; }
}
