/**
 * Component Selector Modal — palette médiévale TerraAntiqua
 * Modale plein écran sur mobile, large sur desktop.
 *
 * IMPORTANT — défense contre les overrides de pages :
 * plusieurs pages (characterInventory, groupInventory, characterProfile…)
 * définissent un `.modal { z-index:1000; background:rgba(0,0,0,.5); ... }`
 * qui rentre en conflit avec Bootstrap (backdrop à 1050 → la modale passe
 * derrière). Les règles ci-dessous restaurent les valeurs Bootstrap pour
 * `.csm-modal` uniquement, sans toucher aux autres modales du projet.
 */

/* Force z-index Bootstrap (au-dessus du backdrop 1050) et reset les overrides */
.modal.csm-modal {
    z-index: 1055 !important;
    background-color: transparent !important;
}

/* Reset modal-content override des pages (qui forcent fond bronze + width fixe) */
.csm-modal .modal-dialog {
    z-index: 1056;
    /* Réaffirme la largeur Bootstrap modal-xl écrasée par certaines pages */
    max-width: 1140px !important;
    width: auto !important;
    margin: 1.75rem auto !important;
}

.csm-modal .modal-content.csm-content {
    background-color: #fffbf5 !important;
    color: #3E2723 !important;
    border: 2px solid #b45f06 !important;
    border-radius: 6px !important;
    /* width:100% pour remplir le modal-dialog (et non auto qui shrink-to-fit) */
    width: 100% !important;
    margin: 0 !important;
    top: auto !important;
    transform: none !important;
    padding: 0 !important;
}

.csm-modal .csm-header {
    background-color: #b45f06;
    color: #fff2cc;
    border-bottom: 2px solid #7a3f04;
    border-radius: 4px 4px 0 0;
}

.csm-modal .csm-header .modal-title {
    color: #fff2cc;
    font-weight: 600;
}

.csm-modal .csm-header .btn-close {
    filter: invert(1) brightness(1.2);
}

/* Bootstrap 4 fallback : le bouton .close affiche un &times; texte */
.csm-modal .csm-header .csm-close {
    background: transparent;
    border: none;
    color: #fff2cc;
    font-size: 1.6em;
    line-height: 1;
    opacity: 0.85;
    cursor: pointer;
    padding: 0 8px;
}
.csm-modal .csm-header .csm-close:hover { opacity: 1; }
/* En BS5, .btn-close a son propre style (icône SVG) — masquer le span fallback */
.csm-modal .csm-header .btn-close .csm-close-x { display: none; }

/* ── Toolbar : recherche + filtres ──────────────────────────────────────── */
.csm-toolbar {
    padding: 12px 16px;
    background-color: #fff2cc;
    border-bottom: 1px solid #b45f06;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.csm-search-wrap {
    position: relative;
    flex: 1 1 240px;
    min-width: 200px;
}

.csm-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #b45f06;
    pointer-events: none;
}

.csm-search {
    width: 100%;
    padding: 8px 12px 8px 32px;
    border: 1px solid #b45f06;
    border-radius: 4px;
    background-color: #fffbf5;
    color: #3E2723;
    font-size: 0.95em;
    outline: none;
}

.csm-search:focus {
    border-color: #7a3f04;
    box-shadow: 0 0 0 2px rgba(180, 95, 6, 0.15);
}

.csm-cat-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.csm-cat-btn {
    background-color: #fffbf5;
    border: 1px solid #b45f06;
    color: #7a3f04;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.csm-cat-btn:hover {
    background-color: #ffd68e;
}

.csm-cat-btn.active {
    background-color: #b45f06;
    color: #fff2cc;
    border-color: #7a3f04;
    font-weight: 600;
}

/* ── Body : grille de composants ────────────────────────────────────────── */
.csm-body {
    background-color: #fffbf5;
    padding: 16px;
}

.csm-loading {
    text-align: center;
    padding: 40px 20px;
    color: #8b4a05;
    font-style: italic;
}

.csm-loading.csm-error {
    color: #9d1d1d;
    font-style: normal;
}

.csm-cat-block {
    margin-bottom: 18px;
}

.csm-cat-block:last-child {
    margin-bottom: 0;
}

.csm-cat-header {
    font-size: 1em;
    font-weight: 600;
    color: #7a3f04;
    border-bottom: 2px solid #b45f06;
    padding-bottom: 4px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.csm-cat-count {
    font-size: 0.75em;
    background-color: #b45f06;
    color: #fff2cc;
    padding: 1px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.csm-items-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 6px;
}

/* ── Item (label cliquable) ─────────────────────────────────────────────── */
.csm-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background-color: #fffbf5;
    border: 1px solid #f0e0c0;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.1s;
    margin: 0;
    user-select: none;
}

.csm-item:hover {
    background-color: #fff2cc;
    border-color: #b45f06;
}

.csm-item:has(.csm-checkbox:checked) {
    background-color: #ffd68e;
    border-color: #7a3f04;
}

.csm-checkbox {
    width: 16px;
    height: 16px;
    accent-color: #b45f06;
    cursor: pointer;
    flex-shrink: 0;
}

.csm-item-icon {
    color: #b45f06;
    font-size: 1em;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.csm-item-name {
    flex: 1 1 auto;
    font-size: 0.88em;
    color: #3E2723;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.csm-item-badges {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
}

.csm-badge {
    font-size: 0.7em;
    padding: 1px 6px;
    border-radius: 8px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

.csm-cost {
    background-color: #fff2cc;
    color: #8b4a05;
    border: 1px solid #b8860b;
}

.csm-rarity-RARE {
    background-color: #0f500f;
    color: #fff2cc;
}

.csm-rarity-TRES_RARE {
    background-color: #b45f06;
    color: #fff2cc;
}

.csm-rarity-RARISSIME {
    background-color: #dea844;
    color: #3E2723;
}

/* ── Footer ─────────────────────────────────────────────────────────────── */
.csm-footer {
    background-color: #fff2cc;
    border-top: 1px solid #b45f06;
}

.csm-count-info {
    flex: 1 1 auto;
    font-size: 0.9em;
    color: #7a3f04;
    font-weight: 600;
}

.csm-count {
    background-color: #b45f06;
    color: #fff2cc;
    padding: 2px 10px;
    border-radius: 10px;
    font-weight: 700;
    margin-right: 4px;
}

/* Boutons : reprendre les classes globales du projet */
.csm-footer .btn-neutral-light {
    background-color: #fffbf5;
    border: 1px solid #b45f06;
    color: #7a3f04;
}

.csm-footer .btn-neutral-light:hover {
    background-color: #ffd68e;
}

/* ── Mobile : grille en 1 colonne ───────────────────────────────────────── */
@media (max-width: 768px) {
    .csm-items-grid {
        grid-template-columns: 1fr;
    }
    .csm-toolbar {
        padding: 10px;
    }
    .csm-cat-filters {
        width: 100%;
        justify-content: flex-start;
    }
}
