:root {
    --ca-primary:       #1da1f5;
    --ca-primary-dark:  #1781c4;
    --ca-primary-light: #e8f6ff;
    --ca-ink:           #1f2937;
    --ca-ink-mid:       #374151;
    --ca-ink-muted:     #6b7280;
    --ca-surface:       #ffffff;
    --ca-ground:        #f9fafb;
    --ca-border:        #e5e7eb;
    --ca-border-strong: #d1d5db;
    --ca-shadow:        var(--bs-box-shadow, 0 0.5rem 1rem rgba(0,0,0,0.15));
    --ca-male:          #3b82f6;
    --ca-female:        #f472b6;
    --ca-danger:        #e83d2c;
    --ca-danger-light:  #fdecea;
    --ca-secondary:     #8039da;

    /* Admin shell (sidebar + topbar + hero) */
    --ca-sidebar-width:       15.5rem;
    --ca-sidebar-width-mini:  4rem;
    --ca-topbar-height:       3.75rem;
}

/* Brand palette — overrides Bootstrap's theme-color CSS variables so every
   built-in component (buttons, text/bg/border utilities, badges, alerts,
   links) picks up the brand colors without recompiling Bootstrap from SCSS. */
:root {
    --bs-primary:              #1da1f5;
    --bs-primary-rgb:           29,161,245;
    --bs-primary-bg-subtle:    #e8f6ff;
    --bs-primary-border-subtle:#a5d9fb;
    --bs-primary-text-emphasis:#105987;

    --bs-secondary:              #8039da;
    --bs-secondary-rgb:           128,57,218;
    --bs-secondary-bg-subtle:    #f2ebfc;
    --bs-secondary-border-subtle:#ccb0f0;
    --bs-secondary-text-emphasis:#461f78;

    --bs-success:              #12ac70;
    --bs-success-rgb:           18,172,112;
    --bs-success-bg-subtle:    #e8f7f1;
    --bs-success-border-subtle:#a0dec6;
    --bs-success-text-emphasis:#0a5f3e;

    --bs-danger:              #e83d2c;
    --bs-danger-rgb:           232,61,44;
    --bs-danger-bg-subtle:    #fdecea;
    --bs-danger-border-subtle:#f6b1ab;
    --bs-danger-text-emphasis:#802218;

    --bs-warning:              #ffc147;
    --bs-warning-rgb:           255,193,71;
    --bs-warning-bg-subtle:    #fff9ed;
    --bs-warning-border-subtle:#ffe6b5;
    --bs-warning-text-emphasis:#8c6a27;

    --bs-info:              #2ccfd4;
    --bs-info-rgb:           44,207,212;
    --bs-info-bg-subtle:    #eafbfb;
    --bs-info-border-subtle:#abecee;
    --bs-info-text-emphasis:#187275;

    --bs-link-color:      #1da1f5;
    --bs-link-color-rgb:   29,161,245;
    --bs-link-hover-color: #1781c4;

    --bs-body-font-family: Metropolis, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

/* Base */
body {
    font-family: var(--bs-body-font-family);
    font-size: 14px;
    line-height: 1.5;
    color: var(--ca-ink);
    background-color: #f2f6fc;
}

/* Cards */
.card {
    border-color: var(--ca-border);
    box-shadow: var(--ca-shadow);
}
.card-header {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    min-height: 3.5rem;
    display: flex;
    align-items: center;
    font-weight: 500;
}

/* Bootstrap primary override */
.bg-primary,
.btn-primary {
    background-color: var(--ca-primary) !important;
    border-color: var(--ca-primary) !important;
}
.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--ca-primary-dark) !important;
    border-color: var(--ca-primary-dark) !important;
}
.text-primary {
    color: var(--ca-primary) !important;
}
a {
    color: var(--ca-primary);
}
a:hover {
    color: var(--ca-primary-dark);
}

/* Navbar */
.navbar.bg-primary {
    background-color: var(--ca-primary) !important;
}
.navbar-dark .navbar-nav .nav-link {
    color: #fff;
    opacity: 1 !important;
}
.bg-primary .nav-link.active {
    font-weight: 600;
}

/* Dropdown active state */
.dropdown-item.active,
.dropdown-item:active {
    background-color: var(--ca-primary) !important;
}

/* Tables */
.table thead th {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: var(--ca-ink-muted);
    background-color: var(--ca-ground);
    border-bottom: 1px solid var(--ca-border-strong);
}
.table-hover tbody tr:hover > td {
    background-color: var(--ca-primary-light);
}

/* Forms — horizontal layout label alignment */
.row .col-form-label {
    text-align: right;
}

/* Gender icons */
i.fas.fa-male.s {
    color: var(--ca-male);
}
i.fas.fa-female.s {
    color: var(--ca-female);
}

/* Wide screens */
@media (min-width: 1600px) {
    .container {
        max-width: 1570px;
    }
}

/* Form section dividers */
.form-section-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ca-ink-muted);
    border-bottom: 1px solid var(--ca-border);
    padding-bottom: 0.35rem;
    margin-bottom: 1.1rem;
    margin-top: 1.5rem;
}
.form-section-title:first-child {
    margin-top: 0;
}

/* Member group pills */
.member-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.55rem;
    background: var(--ca-primary-light);
    color: var(--ca-primary-dark);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 500;
    text-decoration: none;
    line-height: 1.4;
    transition: background 0.15s, color 0.15s;
}
.member-pill:hover {
    background: var(--ca-danger-light);
    color: var(--ca-danger);
    text-decoration: none;
}
.member-pill .pill-x {
    font-size: 0.6rem;
    opacity: 0.55;
}
@keyframes pill-flash {
    0%   { background: var(--ca-success, #198754); color: #fff; transform: scale(1.12); }
    60%  { background: var(--ca-success, #198754); color: #fff; transform: scale(1.05); }
    100% { background: var(--ca-primary-light); color: var(--ca-primary-dark); transform: scale(1); }
}
.pill-just-added {
    animation: pill-flash 1.6s ease-out forwards;
}
@media (prefers-reduced-motion: reduce) {
    .pill-just-added { animation: none; outline: 2px solid var(--ca-success, #198754); }
}

.pill-hidden {
    opacity: 0.65;
    border-style: dashed;
}

/* Group add list */
.group-add-list a {
    display: block;
    padding: 0.1rem 0;
    color: var(--ca-ink-muted);
    font-size: 0.78rem;
    text-decoration: none;
}
.group-add-list a:hover {
    color: var(--ca-primary);
}

/* Filter pill buttons */
.ca-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.22rem 0.7rem;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--ca-ink-mid);
    background: var(--ca-surface);
    border: 1px solid var(--ca-border-strong);
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.12s, background 0.12s, color 0.12s;
    line-height: 1.4;
}
.ca-filter-btn:hover,
.ca-filter-btn:focus-visible {
    border-color: var(--ca-primary);
    color: var(--ca-primary-dark);
    background: var(--ca-primary-light);
    outline: none;
}
.ca-filter-btn[aria-expanded="true"],
.ca-filter-btn.active {
    background: var(--ca-primary-light);
    border-color: var(--ca-primary);
    color: var(--ca-primary-dark);
    font-weight: 600;
}
.ca-filter-btn.dropdown-toggle::after {
    width: 0.28em;
    height: 0.28em;
    border-top: 0.28em solid currentColor;
    border-right: 0.28em solid transparent;
    border-left: 0.28em solid transparent;
    border-bottom: 0;
    margin-left: 0.1em;
    vertical-align: 0.12em;
    opacity: 0.6;
}

/* DataTables toolbar */
.dt-buttons {
    display: flex;
    gap: 0.25rem;
}
.btn-dt {
    background: none;
    border: none;
    color: var(--ca-ink-muted);
    font-size: 0.78rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    transition: background 0.12s, color 0.12s;
}
.btn-dt:hover, .btn-dt:focus {
    background: var(--ca-primary-light);
    color: var(--ca-primary-dark);
}
.btn-dt.dropdown-toggle::after {
    display: none;
}
.dt-button-collection {
    padding: 0.25rem 0;
    min-width: 10rem;
    background: var(--ca-surface);
    border: 1px solid var(--ca-border-strong);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    z-index: 1050;
}
.dt-button-collection .dt-button {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.35rem 0.875rem;
    font-size: 0.82rem;
    color: var(--ca-ink);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
}
.dt-button-collection .dt-button:hover {
    background: var(--ca-primary-light);
    color: var(--ca-primary-dark);
}
div.dataTables_filter,
div.dt-search {
    display: none !important;
}
div.dataTables_info {
    font-size: 0.75rem;
    color: var(--ca-ink-muted);
    padding-top: 0.5rem;
}

/* Compact segment dropdown */
.navbar .dropdown-menu .dropdown-item {
    padding-top: 0.15rem;
    padding-bottom: 0.15rem;
    font-size: 0.82rem;
}
.navbar .dropdown-menu .segment-filterable {
    padding-left: 1.75rem;
}
.navbar .dropdown-menu .dropdown-header {
    padding-top: 0.4rem;
    padding-bottom: 0.1rem;
}

/* Datetimepicker BS5 compat */
.bootstrap-datetimepicker-widget table td.active,
.bootstrap-datetimepicker-widget table td.active:hover {
    background-color: var(--ca-primary);
    color: #fff;
    text-shadow: none;
}
.bootstrap-datetimepicker-widget table td span.active {
    background-color: var(--ca-primary);
    color: #fff;
    text-shadow: none;
}

/* DataTables sort helpers — visually hidden but readable by screen readers */
.hide, .hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

/* Extended compta-type color swatches */
.ca-orange-subtle { background-color: rgba(253,126,20,0.18) !important; }
.ca-teal-subtle   { background-color: rgba(32,201,151,0.18) !important; }
.ca-pink-subtle   { background-color: rgba(214,51,132,0.18) !important; }
.ca-purple-subtle { background-color: rgba(111,66,193,0.18) !important; }
.ca-indigo-subtle { background-color: rgba(102,16,242,0.18) !important; }
.ca-lime-subtle   { background-color: rgba(128,189,64,0.18)  !important; }

/* iOS Safari: stretched-link requires cursor:pointer on the containing block */
tr.position-relative { cursor: pointer; }

/* Integrity details/summary */
.ca-integrity-section {
    border: 1px solid var(--ca-border);
    border-radius: 6px;
    overflow: hidden;
}
.ca-integrity-summary {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--ca-ground);
    list-style: none;
    user-select: none;
}
.ca-integrity-summary::-webkit-details-marker { display: none; }
.ca-integrity-summary::before {
    content: '\f054';
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    font-size: 0.65rem;
    color: var(--ca-ink-muted);
    margin-right: 0.25rem;
    transition: transform 0.15s;
    flex-shrink: 0;
}
.ca-integrity-section[open] > .ca-integrity-summary::before {
    transform: rotate(90deg);
}
.ca-integrity-section > :not(summary) {
    padding: 0.75rem;
}

/* Active/inactive toggle */
.ca-toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
    font-size: 0.82rem;
}
.ca-toggle-text { color: var(--ca-ink-muted); min-width: 3.2rem; text-align: right; }
.ca-toggle-switch { position: relative; display: inline-block; width: 2.4rem; height: 1.3rem; flex-shrink: 0; }
.ca-toggle-input { opacity: 0; width: 0; height: 0; position: absolute; }
.ca-toggle-slider {
    position: absolute; inset: 0;
    background: var(--ca-border-strong);
    border-radius: 999px;
    transition: background 0.2s;
    cursor: pointer;
}
.ca-toggle-slider::before {
    content: '';
    position: absolute;
    width: 1rem; height: 1rem;
    left: 0.15rem; top: 0.15rem;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.ca-toggle-input:checked + .ca-toggle-slider { background: var(--ca-primary); }
.ca-toggle-input:checked + .ca-toggle-slider::before { transform: translateX(1.1rem); }
.ca-toggle-input:focus-visible + .ca-toggle-slider { outline: 2px solid var(--ca-primary); outline-offset: 2px; }

/* Inactive profile overlay */
/* Mobile read/edit toggle — always show form on md+ regardless of Alpine state */
@media (min-width: 768px) {
  .ca-mobile-expandable { display: block !important; }
}

/* Groupes : lecture seule sur mobile — désactive les liens remove et masque le ✕ */
@media (max-width: 767.98px) {
  a.member-pill { pointer-events: none; cursor: default; }
  a.member-pill .pill-x { display: none; }
  /* Compacte les groupes sur mobile */
  .col-md-4 .d-flex.flex-wrap.gap-1.mb-3 { margin-bottom: 0.35rem !important; gap: 2px !important; }
  .col-md-4 .member-pill { font-size: 0.65rem; padding: 0.1rem 0.4rem; }
  .col-md-4 .form-section-title { margin-top: 0.5rem; margin-bottom: 0.25rem; }
  /* Masque "Ajouter un groupe" sur mobile */
  .col-md-4 .ca-integrity-section { display: none; }
  /* Masque "Voir tous les groupes" sur mobile */
  .col-md-4 .mt-2.text-end { display: none; }
}

/* Formulaire édition mobile — label+input côte à côte, compact */
@media (max-width: 767.98px) {
  .ca-mobile-expandable .row.mb-2 {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    margin-bottom: 0.4rem !important;
  }
  .ca-mobile-expandable .col-md-3.col-form-label {
    width: 32%;
    flex: 0 0 32%;
    max-width: 32%;
    font-size: 0.78rem;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
    padding-right: 0.5rem;
    color: var(--ca-ink-muted);
  }
  .ca-mobile-expandable .col-md-9 {
    width: 68%;
    flex: 0 0 68%;
    max-width: 68%;
    padding-left: 0;
  }
  /* Masque les liens localch/map dans le label adresse sur mobile */
  .ca-mobile-expandable label[for="address"] a { display: none; }
  .ca-mobile-expandable label[for="address"]::before { content: "Adresse"; }
  /* Masque fax sur mobile */
  .ca-mobile-expandable .row.mb-2:has(#fax) { display: none; }
  /* TipTap toolbar : autorise le wrap */
  .ca-mobile-expandable .tiptap-toolbar { gap: 2px !important; }
  /* Section titles plus compacts */
  .ca-mobile-expandable .form-section-title { margin-top: 0.75rem; margin-bottom: 0.25rem; }
  /* Bouton Enregistrer full-width */
  .ca-mobile-expandable .btn-primary { width: 100%; }
}

.ca-inactive-wrap { pointer-events: none; }
.ca-inactive-overlay {
    position: absolute; inset: 0;
    background: rgba(255,255,255,0.55);
    border-radius: 4px;
    z-index: 2;
    pointer-events: none;
}

/* Merge view */
[x-cloak] { display: none !important; }

.ca-merge-wrap { max-width: 900px; }
.ca-merge-title { font-size: 1.25rem; font-weight: 700; margin: 0; }

.ca-merge-table { border: 1px solid var(--ca-border); border-radius: 6px; overflow: hidden; }
.ca-merge-table thead { background: var(--ca-ground); }
.ca-merge-th-field   { width: 130px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ca-ink-muted); padding: 0.5rem 0.75rem; }
.ca-merge-th-profile { font-size: 0.82rem; font-weight: 600; padding: 0.5rem 0.75rem; }

.ca-merge-profile-head { display: flex; align-items: center; gap: 0.4rem; }
.ca-merge-profile-badge {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.4rem; height: 1.4rem; border-radius: 50%;
    background: var(--ca-primary); color: #fff;
    font-size: 0.7rem; font-weight: 700; flex-shrink: 0;
}
.ca-merge-profile-badge--b { background: var(--ca-ink-muted); }

.ca-merge-label { font-size: 0.78rem; color: var(--ca-ink-muted); font-weight: 500; padding: 0.45rem 0.75rem; white-space: nowrap; }

.ca-merge-cell {
    padding: 0.45rem 0.75rem;
    font-size: 0.82rem;
    vertical-align: middle;
    position: relative;
    border-left: 2px solid transparent;
    transition: background 0.1s, border-color 0.1s;
}
.ca-merge-cell--a:hover,
.ca-merge-cell--b:hover { background: var(--ca-primary-light); cursor: pointer; }

.ca-merge-cell.selected {
    background: var(--ca-primary-light);
    border-left-color: var(--ca-primary);
}
.ca-merge-cell-check {
    display: none;
    color: var(--ca-primary);
    font-size: 0.7rem;
    margin-right: 0.3rem;
}
.ca-merge-cell.selected .ca-merge-cell-check { display: inline; }

.ca-merge-cell--same {
    color: var(--ca-ink-muted);
    background: var(--ca-ground);
    font-size: 0.82rem;
    padding: 0.45rem 0.75rem;
}

/* Layout fixe : la colonne « Champ » est étroite, les colonnes A et B se
   partagent le reste à parts égales. Sans ça, du HTML collé dans la Note
   (emails avec largeurs fixes) élargit la table et pousse la colonne B
   hors de l'écran. */
.ca-merge-table { table-layout: fixed; width: 100%; }
.ca-merge-cell, .ca-merge-cell--same { overflow: hidden; }

/* Le contenu d'une cellule (notamment la Note en HTML riche) est confiné :
   il ne peut plus déborder ni dépasser la largeur de sa colonne. */
.ca-merge-cell-value {
    display: block;
    max-height: 14rem;
    overflow: auto;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.ca-merge-cell-value * { max-width: 100% !important; height: auto !important; }
.ca-merge-cell-value table {
    width: 100% !important;
    table-layout: fixed !important;
    display: block;
    overflow-x: auto;
}
.ca-merge-same-icon { font-size: 0.65rem; color: var(--ca-border-strong); margin-right: 0.35rem; }

.ca-merge-row--same td { opacity: 0.65; }

.ca-merge-stats { background: var(--ca-ground); border: 1px solid var(--ca-border); border-radius: 6px; padding: 0.75rem; }

.ca-merge-options { background: var(--ca-surface); border: 1px solid var(--ca-border); border-radius: 6px; padding: 1rem; }

.ca-merge-radio {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--ca-border-strong);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    transition: border-color 0.12s, background 0.12s;
}
.ca-merge-radio:hover    { border-color: var(--ca-primary); background: var(--ca-primary-light); }
.ca-merge-radio.active   { border-color: var(--ca-primary); background: var(--ca-primary-light); font-weight: 600; }
.ca-merge-radio--danger.active { border-color: var(--ca-danger); background: var(--ca-danger-light); }

.ca-merge-dialog {
    border: none; border-radius: 10px; padding: 0;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    max-width: 480px; width: 90%;
}
.ca-merge-dialog::backdrop { background: rgba(0,0,0,0.4); }
.ca-merge-dialog-body { padding: 1.5rem; }
.ca-merge-dialog-title { font-size: 1rem; font-weight: 700; margin-bottom: 0.75rem; }
.ca-merge-dialog-summary { padding-left: 1.2rem; margin: 0.5rem 0; line-height: 1.7; }

@media (max-width: 600px) {
    .ca-merge-th-field { width: 80px; }
    .ca-merge-label    { font-size: 0.72rem; padding: 0.35rem 0.4rem; }
    .ca-merge-cell     { padding: 0.35rem 0.4rem; font-size: 0.78rem; }
}

/* dashboard KPI cards — shared box/label/value tokens (per-card bg, flex, min-width stay inline) */
.ca-kpi-box {
  border-radius: 10px;
  padding: 0.85rem 1rem;
  color: #fff;
}
.ca-kpi-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.8;
}
.ca-kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  margin-top: 0.25rem;
}
.ca-kpi-meta {
  font-size: 0.78rem;
  margin-top: 0.3rem;
  opacity: 0.85;
}

/* KPI delta chip — colors the decline reading so direction isn't icon-only */
.ca-kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.05rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
  color: #fff;
}
.ca-kpi-delta--down {
  background: var(--bs-danger-text-emphasis, #802218);
}

/* resume.inc — responsive stats cards */
@media (max-width: 575.98px) {
  .ca-resume-cards {
    flex-wrap: wrap;
    gap: 0.5rem !important;
  }
  /* contributions card: full width */
  .ca-resume-cards > div:first-child {
    flex: 0 0 100% !important;
    min-width: 0 !important;
  }
  /* secondary cards: split into row of 3 (or fewer) */
  .ca-resume-cards > div:not(:first-child) {
    flex: 1 1 0 !important;
    min-width: 90px !important;
    padding: 0.6rem 0.7rem !important;
  }
  /* tighten secondary card numbers */
  .ca-resume-cards > div:not(:first-child) .ca-kpi-value {
    font-size: 1.3rem !important;
  }
}

.ca-stats-link .ca-stats-mini,
.ca-stats-link > div {
    transition: background 0.15s, border-color 0.15s;
    cursor: pointer;
}
.ca-stats-link:hover .ca-stats-mini,
.ca-stats-link:hover > div {
    background: #e8edf8 !important;
    border-color: #b3c2e0 !important;
}

/* Member general data — view/edit toggle */
.member-view-card {
    cursor: pointer;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    transition: background 0.15s;
}
.member-view-card:hover {
    background: #f0f4ff;
}
.member-view-hint {
    font-size: 0.75rem;
    opacity: 0.6;
}
.member-view-card:hover .member-view-hint {
    opacity: 1;
}
.member-view-row {
    display: flex;
    gap: 0.75rem;
    padding: 0.2rem 0;
    font-size: 0.9rem;
}
.member-view-label {
    flex: 0 0 160px;
    color: #6c757d;
    font-size: 0.8rem;
    padding-top: 0.1rem;
}
.member-view-value {
    flex: 1;
    word-break: break-word;
}

/* ===========================================================================
 * Admin shell — original layout (fixed topbar + collapsible sidebar + hero
 * header), built from scratch for MemberBase. Not derived from any
 * third-party theme: own class names (ca-* prefix), own layout mechanics
 * (flexbox, not a copied grid), own spacing/color scale.
 * =========================================================================== */

/* --- App shell (topbar + sidebar + content) --- */
.ca-app-shell {
    display: flex;
    min-height: 100vh;
}

.ca-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--ca-topbar-height);
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1rem;
    background: var(--ca-surface);
    border-bottom: 1px solid var(--ca-border);
}

.ca-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    color: var(--ca-ink-mid);
}
.ca-icon-btn:hover {
    background: var(--ca-ground);
    color: var(--ca-ink);
}

.ca-brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--ca-ink);
    text-decoration: none;
    white-space: nowrap;
}
.ca-brand:hover { color: var(--ca-ink); }

.ca-topbar-search {
    max-width: 22rem;
}

.ca-sidebar-col {
    flex: 0 0 var(--ca-sidebar-width);
    width: var(--ca-sidebar-width);
    padding-top: var(--ca-topbar-height);
    overflow: hidden;
    /* No transition here — this spacer is invisible (overflow:hidden filler
       that reserves/frees width for .ca-app-content). Animating width/flex-basis
       is a layout-thrashing anti-pattern; the visible slide is the fixed panel's
       own transform below, which is compositor-only. */
}
.ca-sidebar-panel {
    position: fixed;
    top: var(--ca-topbar-height);
    left: 0;
    bottom: 0;
    width: var(--ca-sidebar-width);
    overflow-y: auto;
    border-right: 1px solid var(--ca-border);
    z-index: 1020;
    transition: transform 0.15s ease-out;
}
/* .ca-sidebar-panel is position:fixed, so it ignores its parent's margin —
   the collapse toggle must transform the fixed panel itself; .ca-sidebar-col
   is just a flex spacer that reserves/frees the width for .ca-app-content. */
body.ca-sidebar-collapsed .ca-sidebar-col {
    flex-basis: 0;
    width: 0;
}
body.ca-sidebar-collapsed .ca-sidebar-panel {
    transform: translateX(-100%);
}
@media (max-width: 991.98px) {
    .ca-sidebar-col { flex-basis: 0; width: 0; }
    .ca-sidebar-panel { transform: translateX(-100%); }
    body.ca-sidebar-collapsed .ca-sidebar-col { flex-basis: var(--ca-sidebar-width); width: var(--ca-sidebar-width); }
    body.ca-sidebar-collapsed .ca-sidebar-panel { transform: translateX(0); }
}

/* Backdrop overlay — shown on mobile when the sidebar slides open */
.ca-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1015; /* below sidebar (1020) but above content */
    transition: opacity 0.15s ease-out;
    opacity: 0;
}
.ca-sidebar-overlay--active {
    display: block;
    opacity: 1;
}

.ca-sidebar-body {
    flex: 1 1 auto;
    overflow-y: auto;
}

.ca-sidebar-body .nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.5rem;
    color: var(--ca-ink-mid);
    font-size: 0.88rem;
    font-weight: 500;
}
.ca-sidebar-body .nav-link:hover {
    background: var(--ca-ground);
    color: var(--ca-ink);
}
.ca-sidebar-body .nav-link.active {
    background: var(--ca-primary-light);
    color: var(--ca-primary-dark);
    font-weight: 600;
}
.ca-sidebar-body .nav-link[aria-expanded="true"] .ca-sidebar-caret {
    transform: rotate(180deg);
}

.ca-sidebar-link-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    flex-shrink: 0;
    color: var(--ca-ink-muted);
}
.ca-sidebar-body .nav-link.active .ca-sidebar-link-icon { color: var(--ca-primary-dark); }

.ca-sidebar-caret {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--ca-ink-muted);
    transition: transform 0.15s ease-out;
}

.ca-sidebar-submenu {
    display: flex;
    flex-direction: column;
    padding-left: 1.9rem;
    margin: 0.1rem 0 0.35rem;
}
.ca-sidebar-submenu .nav-link {
    padding: 0.4rem 0.6rem;
    font-size: 0.83rem;
    font-weight: 400;
    color: var(--ca-ink-muted);
}
.ca-sidebar-submenu .nav-link.active {
    color: var(--ca-primary-dark);
    font-weight: 600;
    background: transparent;
}
.ca-sidebar-submenu .ca-sidebar-submenu {
    padding-left: 1rem;
}

.ca-sidebar-footer {
    flex-shrink: 0;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--ca-border);
}
.ca-sidebar-footer-org {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ca-ink-muted);
}
.ca-sidebar-footer-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ca-ink);
}

.ca-app-content {
    flex: 1 1 auto;
    min-width: 0;
    padding-top: var(--ca-topbar-height);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
/* mt-auto on .ca-app-footer only pushes it to the bottom if it's a sibling
   flex item of a flex-column container that grows — <main> is that item. */
.ca-app-content > main {
    flex: 1 1 auto;
}

.ca-app-footer {
    padding: 1rem 0;
    color: var(--ca-ink-muted);
    border-top: 1px solid var(--ca-border);
}
.ca-app-footer a { color: var(--ca-ink-muted); text-decoration: underline; }

/* --- Hero header (page title band) --- */
.ca-hero {
    background: linear-gradient(160deg, var(--ca-primary-dark) 0%, var(--ca-primary) 100%);
    color: #fff;
    padding-top: 2.25rem;
    padding-bottom: 10rem;
}
.ca-hero-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 2.25rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}
.ca-hero-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.65rem;
    font-size: 1.5rem;
    opacity: 0.6;
}
.ca-hero-subtitle {
    /* Plain white text on the lighter end of the .ca-hero gradient only
       reaches ~2.8:1 even at full opacity (below WCAG AA 4.5:1) — a solid
       scrim (as used for .btn-outline-light below) would be too heavy for
       a full-width line of running text, so a text-shadow carries the
       real contrast instead. */
    color: rgba(255,255,255,0.95);
    text-shadow: 0 1px 3px rgba(0,0,0,0.45);
    font-size: 1.15rem;
    margin-top: 0.25rem;
}
.ca-hero-overlap {
    margin-top: -8rem;
}

/* --- Mobile layout compaction (< 768 px) ---------------------------------- */
@media (max-width: 767.98px) {
    /* Reduce hero band height and overlap pull-up on small screens */
    .ca-hero {
        padding-top: 1.25rem;
        padding-bottom: 5rem;
    }
    .ca-hero-title {
        font-size: 1.5rem;
        gap: 0.5rem;
    }
    .ca-hero-icon {
        width: 2rem;
        height: 2rem;
        font-size: 1.1rem;
    }
    .ca-hero-subtitle { font-size: 1rem; }
    .ca-hero-overlap { margin-top: -4rem; }

    /* Tighten container side gutters — Bootstrap's px-4 (1.5 rem each side)
       wastes ~48 px on a 375-px screen; px-2 (0.5 rem) reclaims most of it. */
    .container-xl.px-4,
    .container-xl.px-4.ca-hero-overlap {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }

    /* Card body: tighten inner padding */
    .card-body {
        padding: 0.75rem;
    }

    /* Topbar search is already d-none d-lg-block; ensure brand text truncates
       cleanly next to the toggle so the topbar never wraps */
    .ca-brand {
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: calc(100vw - 4rem);
    }

    /* Table-responsive: enable horizontal scroll on all tables inside cards */
    .card .table-responsive { overflow-x: auto; }
    .card table { min-width: 0; }
}

/* Status switch sitting directly on the hero gradient (user fiche "Actif"
   toggle): Bootstrap's checked track (#0d6efd) is the same blue family as
   the gradient itself, so the whole track disappears — only the white knob
   stayed visible. Invert to a white track + colored knob so both states
   read clearly against the gradient. */
.ca-hero .form-switch .form-check-input:checked {
    background-color: #fff;
    border-color: #fff;
    --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%230d6efd'/%3e%3c/svg%3e");
}

/* Outline buttons sitting directly on the hero gradient via the overlap
   (e.g. the member fiche's tab switcher, rendered right at the top of this
   overlapping container): plain .btn-outline-light text/border contrast
   against the lighter end of the gradient computes to ~2.8:1, below WCAG AA.
   A dark scrim behind the button brings it to ~4.7:1 while keeping the
   outline look (as opposed to a solid fill). */
.ca-hero-overlap .btn-outline-light {
    background-color: rgba(0, 0, 0, 0.25);
}
.ca-hero-overlap .btn-outline-light:hover,
.ca-hero-overlap .btn-outline-light:focus {
    background-color: #fff;
}

/* Perceived-performance cue for full-page navigations (hx-boost="false"
   links: sidebar, topbar, hub tab bars). These reload the whole document,
   so htmx's own loading states don't apply — a slim top bar gives instant
   feedback that the click registered, instead of a silent pause until the
   new page paints. */
.ca-nav-loading::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 90%;
    background: var(--ca-primary-dark);
    z-index: 1100;
    animation: ca-nav-progress 0.9s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@media (prefers-reduced-motion: reduce) {
    .ca-nav-loading::before { animation-duration: 0.01ms; }
}
@keyframes ca-nav-progress {
    from { width: 0; }
    to   { width: 90%; }
}

/* Hub tab bar (people_finance.php): deliberately mirrors .ca-sidebar-body
   .nav-link (same colors/weights/radius) rather than a generic Bootstrap
   nav-tabs strip, so the hub doesn't introduce a second, contradictory
   navigation style right next to the sidebar it's duplicating. Wrapped in
   its own opaque surface (not left bare on .ca-hero's gradient) so link
   color never depends on what's behind the hero — the same class of
   contrast bug already hit twice on this gradient this session.
   Desktop hides it entirely (redundant with the visible sidebar); it only
   earns its place below 991.98px, the exact breakpoint where .ca-sidebar-col
   itself collapses (custom.css ~819) — the bar becomes the mobile substitute
   for the same 5 destinations, not a permanent duplicate next to them. */
.ca-hub-tabs {
    display: none;
    background: var(--ca-surface);
    border-radius: 10px;
    padding: 0.35rem;
    gap: 0.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
@media (max-width: 991.98px) {
    .ca-hub-tabs { display: flex; }
}
.ca-hub-tabs .nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.9rem;
    border-radius: 0.5rem;
    color: var(--ca-ink-mid);
    font-size: 0.88rem;
    font-weight: 500;
}
.ca-hub-tabs .nav-link:hover {
    background: var(--ca-ground);
    color: var(--ca-ink);
}
.ca-hub-tabs .nav-link.active {
    background: var(--ca-primary-light);
    color: var(--ca-primary-dark);
    font-weight: 600;
}
.ca-hub-tab-icon {
    color: var(--ca-ink-muted);
}
.ca-hub-tabs .nav-link.active .ca-hub-tab-icon {
    color: var(--ca-primary-dark);
}

/* Inactive .nav-pills text (cohort filters: "Perdus"/"Nouveaux" on lapsed
   members/donors) inherits --bs-link-color (#1da1f5), which computes to
   ~2.8:1 on white — below WCAG AA. Bootstrap only themes the active pill
   (bg + white text); the inactive state falls through to the link color
   unless overridden. */
.nav-pills .nav-link {
    color: var(--ca-ink-mid);
}
.nav-pills .nav-link:hover {
    color: var(--ca-ink);
}
