/* =========================================================================
   CTA PAYE — Système Modal (CModal)
   Split-view : panneau gauche illustré + contenu droit.
   Fonctionne avec les tokens front-end (style.css) ET back-office (_layout_top).
   Z-index : 900 (sous toasts à 1000, au-dessus du header à 100).
   ========================================================================= */

/* ── Backdrop ─────────────────────────────────────────────────────────────── */
.cmodal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(10, 14, 28, .52);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity .18s cubic-bezier(.22,.61,.36,1);
  overflow-y: auto;
}
.cmodal-backdrop.is-open {
  opacity: 1;
}
/* scroll lock sur le body */
body.cmodal-open {
  overflow: hidden;
}

/* ── Boîte de dialogue ───────────────────────────────────────────────────── */
.cmodal {
  position: relative;
  display: flex;
  width: 100%;
  max-width: 900px;
  min-height: 420px;
  max-height: calc(100vh - 40px);
  background: var(--card, #fff);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 32px 80px -12px rgba(10,14,28,.36), 0 0 0 1px rgba(10,14,28,.06);
  transform: scale(.96) translateY(8px);
  transition: transform .22s cubic-bezier(.22,.61,.36,1), box-shadow .22s;
  margin: auto;
}
.cmodal-backdrop.is-open .cmodal {
  transform: scale(1) translateY(0);
}

/* ── Modal sans panneau (variante compacte) ──────────────────────────────── */
.cmodal--slim {
  max-width: 500px;
  min-height: 0;
}
.cmodal--slim .cmodal-panel { display: none; }

/* ── Panneau gauche ──────────────────────────────────────────────────────── */
.cmodal-panel {
  flex: 0 0 38%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 36px 30px 28px;
  background: var(--cmodal-panel-bg, var(--navy, #16235e));
  color: #fff;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

/* Dégradé d'accent (couleur pilotée par data-theme sur le panneau) */
.cmodal-panel[data-theme="users"]    { --cmodal-panel-bg: linear-gradient(145deg,#6441e0 0%,#7c5cff 60%,#9575ff 100%); }
.cmodal-panel[data-theme="docs"]     { --cmodal-panel-bg: linear-gradient(145deg,#1d4ed8 0%,#3b82f6 65%,#60a5fa 100%); }
.cmodal-panel[data-theme="payslips"] { --cmodal-panel-bg: linear-gradient(145deg,#c2570a 0%,#ea7011 55%,#f7941d 100%); }
.cmodal-panel[data-theme="secure"]   { --cmodal-panel-bg: linear-gradient(145deg,#0d7a64 0%,#14b8a6 60%,#2dd4bf 100%); }
.cmodal-panel[data-theme="danger"]   { --cmodal-panel-bg: linear-gradient(145deg,#991b1b 0%,#DB3238 60%,#f05a5f 100%); }
.cmodal-panel[data-theme="default"]  { --cmodal-panel-bg: linear-gradient(145deg,#101b4a 0%,#16235e 55%,#243276 100%); }
.cmodal-panel[data-theme="green"]    { --cmodal-panel-bg: linear-gradient(145deg,#065f46 0%,#059669 55%,#10b981 100%); }
.cmodal-panel[data-theme="pink"]     { --cmodal-panel-bg: linear-gradient(145deg,#9d174d 0%,#db2777 55%,#ec4899 100%); }

/* Bruit de fond subtil (texture) */
.cmodal-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.04'/%3E%3C/svg%3E");
  opacity: .5;
  pointer-events: none;
}

/* Pastille icône en haut du panneau */
.cmodal-panel__badge {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: rgba(255,255,255,.18);
  display: grid;
  place-items: center;
  margin-bottom: 20px;
  flex: 0 0 auto;
}
.cmodal-panel__badge svg {
  width: 24px;
  height: 24px;
  color: #fff;
  stroke: currentColor;
}

/* Contenu texte du panneau */
.cmodal-panel__content {
  position: relative;
  z-index: 1;
  flex: 1;
}
.cmodal-panel__title {
  font-size: 1.22rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -.025em;
  line-height: 1.2;
  margin: 0 0 10px;
}
.cmodal-panel__desc {
  font-size: .9rem;
  color: rgba(255,255,255,.75);
  line-height: 1.55;
  margin: 0 0 22px;
}
.cmodal-panel__features {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cmodal-panel__features li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: .86rem;
  color: rgba(255,255,255,.88);
  line-height: 1.45;
}
.cmodal-panel__features li::before {
  content: "";
  flex: 0 0 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 50%;
  background: rgba(255,255,255,.22)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E")
    no-repeat center;
}

/* Illustration SVG en bas du panneau */
.cmodal-panel__art {
  position: relative;
  z-index: 1;
  margin-top: 24px;
  opacity: .9;
  flex: 0 0 auto;
}
.cmodal-panel__art svg {
  width: 100%;
  height: auto;
  max-height: 140px;
  overflow: visible;
}

/* ── Partie droite (contenu principal) ───────────────────────────────────── */
.cmodal-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--card, #fff);
}

/* En-tête de la partie droite */
.cmodal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 26px 28px 18px;
  border-bottom: 1px solid var(--line, #e7e9ee);
  flex: 0 0 auto;
}
.cmodal-head-text {
  min-width: 0;
}
.cmodal-title {
  font-size: 1.08rem;
  font-weight: 800;
  color: var(--ink, #16235e);
  letter-spacing: -.022em;
  line-height: 1.2;
  margin: 0 0 3px;
}
.cmodal-subtitle {
  font-size: .875rem;
  color: var(--muted, #6b7280);
  margin: 0;
  line-height: 1.4;
}

/* Bouton fermer */
.cmodal-close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 0;
  background: transparent;
  color: var(--muted, #6b7280);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .14s, color .14s;
  margin-top: -2px;
}
.cmodal-close:hover {
  background: var(--surface, #f7f8fa);
  color: var(--ink, #16235e);
}
.cmodal-close svg {
  width: 18px;
  height: 18px;
}

/* Zone de contenu (scrollable) */
.cmodal-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  min-height: 0;
  /* Scrollbar discrète */
  scrollbar-width: thin;
  scrollbar-color: var(--line-hover, #c3c9d4) transparent;
}
.cmodal-body::-webkit-scrollbar { width: 6px; }
.cmodal-body::-webkit-scrollbar-thumb {
  background: var(--line-hover, #c3c9d4);
  border-radius: 99px;
}

/* Pied de page : boutons d'action */
.cmodal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 28px;
  border-top: 1px solid var(--line, #e7e9ee);
  flex: 0 0 auto;
  background: var(--surface, #f7f8fa);
}
.cmodal-foot--left {
  justify-content: space-between;
}

/* ── État de chargement ───────────────────────────────────────────────────── */
.cmodal-body.is-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}
.cmodal-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line, #e7e9ee);
  border-top-color: var(--navy, #16235e);
  border-radius: 50%;
  animation: cmodal-spin .7s linear infinite;
}
@keyframes cmodal-spin { to { transform: rotate(360deg); } }

/* ── Divider dans le corps ────────────────────────────────────────────────── */
.cmodal-divider {
  height: 1px;
  background: var(--line, #e7e9ee);
  margin: 20px -28px;
}

/* ── Section dans le corps ───────────────────────────────────────────────── */
.cmodal-section {
  margin-bottom: 24px;
}
.cmodal-section:last-child {
  margin-bottom: 0;
}
.cmodal-section__label {
  font-size: .73rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted, #6b7280);
  margin-bottom: 14px;
}

/* ── Alert (danger / info) dans le corps ─────────────────────────────────── */
.cmodal-alert {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: .9rem;
  line-height: 1.5;
  margin-bottom: 20px;
}
.cmodal-alert svg {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  margin-top: 1px;
}
.cmodal-alert--warn {
  background: rgba(245,158,11,.1);
  color: #92400e;
  border: 1px solid rgba(245,158,11,.25);
}
.cmodal-alert--err {
  background: rgba(219,50,56,.08);
  color: var(--red-d, #b9272d);
  border: 1px solid rgba(219,50,56,.18);
}
.cmodal-alert--info {
  background: rgba(59,130,246,.08);
  color: #1e40af;
  border: 1px solid rgba(59,130,246,.18);
}
html[data-theme="dark"] .cmodal-alert--warn { background: rgba(245,158,11,.12); color: #fbbf24; border-color: rgba(245,158,11,.2); }
html[data-theme="dark"] .cmodal-alert--err  { background: rgba(219,50,56,.14);  color: #f87171; border-color: rgba(219,50,56,.2); }
html[data-theme="dark"] .cmodal-alert--info { background: rgba(59,130,246,.12); color: #60a5fa; border-color: rgba(59,130,246,.2); }

/* ── Dark mode ───────────────────────────────────────────────────────────── */
html[data-theme="dark"] .cmodal {
  box-shadow: 0 32px 80px -12px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.06);
}
html[data-theme="dark"] .cmodal-main {
  background: var(--card, #171d30);
}
html[data-theme="dark"] .cmodal-foot {
  background: var(--surface, #161b2c);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .cmodal-backdrop { padding: 0; align-items: flex-end; }
  .cmodal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(20px) scale(1);
  }
  .cmodal-backdrop.is-open .cmodal { transform: translateY(0) scale(1); }
  .cmodal-panel { display: none; }
  .cmodal-head  { padding: 20px 20px 14px; }
  .cmodal-body  { padding: 18px 20px; }
  .cmodal-foot  { padding: 14px 20px; }
}
@media (max-width: 400px) {
  .cmodal-foot { flex-direction: column-reverse; }
  .cmodal-foot .btn { width: 100%; justify-content: center; }
}

/* ── Accessibilité : focus visible dans la modale ────────────────────────── */
.cmodal :focus-visible {
  outline: 2px solid var(--navy, #16235e);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Modal déconnexion (compact + panneau flottant light) ────────────────── */
.cmodal--logout {
  min-height: 240px;
  max-width: 600px;
  padding-left: 14px;
}
.cmodal--logout .cmodal-panel {
  flex: 0 0 220px;
  border-radius: 14px;
  margin: 14px 0;
  padding: 22px 18px 18px;
  background: linear-gradient(118deg,#eaf4ff 0%,#eeecfc 38%,#f7eef8 66%,#fef3ed 100%);
  color: #16235e;
}
.cmodal--logout .cmodal-panel::before { opacity: .06; }
.cmodal--logout .cmodal-panel__badge {
  width: 38px; height: 38px;
  border-radius: 10px;
  margin-bottom: 14px;
  background: rgba(22,35,94,.1);
}
.cmodal--logout .cmodal-panel__badge svg { color: #16235e; }
.cmodal--logout .cmodal-panel__title { color: #16235e; font-size: .97rem; margin: 0 0 6px; }
.cmodal--logout .cmodal-panel__desc  { color: #5a6282; font-size: .82rem; margin: 0 0 14px; }
.cmodal--logout .cmodal-panel__features { gap: 8px; }
.cmodal--logout .cmodal-panel__features li { color: #5a6282; font-size: .8rem; line-height: 1.4; }
.cmodal--logout .cmodal-panel__features li::before {
  flex: 0 0 16px; height: 16px;
  background-color: rgba(22,35,94,.12);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2316235e' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
}
.cmodal--logout .cmodal-panel__art { display: none; }

/* Partie droite compacte */
.cmodal--logout .cmodal-head { padding: 20px 24px 13px; }
.cmodal--logout .cmodal-body { padding: 16px 24px 12px; }

/* CTAs */
.cmodal--logout .cmodal-foot {
  padding: 14px 24px 18px 32px;
  background: transparent;
  border-top: 1px solid var(--line, #e7e9ee);
  gap: 10px;
  justify-content: flex-end;
}
.cmodal--logout .cmodal-foot .btn {
  border-radius: 10px;
  padding: 11px 28px;
  font-size: .88rem;
  font-weight: 700;
  letter-spacing: .01em;
  line-height: 1;
  transition: background .15s, box-shadow .15s, opacity .15s, border-color .15s;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}
.cmodal--logout .cmodal-foot .btn-primary {
  background: linear-gradient(135deg,#e53e45 0%,#c92b31 100%);
  box-shadow: 0 2px 0 #9e2127, 0 4px 14px rgba(219,50,56,.22);
  color: #fff;
  border: none;
}
.cmodal--logout .cmodal-foot .btn-primary:hover {
  opacity: .93;
  box-shadow: 0 2px 0 #9e2127, 0 6px 18px rgba(219,50,56,.32);
}
.cmodal--logout .cmodal-foot .btn-ghost {
  background: #eef1f5;
  color: #3a4156;
  font-weight: 400;
  border: none;
  box-shadow: none;
  padding: 11px 28px;
  border-radius: 10px;
}
.cmodal--logout .cmodal-foot .btn-ghost:hover {
  background: #d9dde4;
  color: #16235e;
  box-shadow: none;
}
@media (max-width: 500px) {
  .cmodal--logout .cmodal-foot {
    flex-direction: column-reverse;
    padding-left: 24px;
    gap: 8px;
  }
  .cmodal--logout .cmodal-foot .btn,
  .cmodal--logout .cmodal-foot .btn-ghost {
    width: 100%;
    text-align: center;
    justify-content: center;
    padding: 11px 16px;
  }
}
