/* ===================================================
   STYLES SPÉCIFIQUES MINI-GRAMMAIRE
   Page liste : grille de codes cliquables.
   Page détail : cartes de règles et exemples (style ui/test).
=================================================== */

/* VARIABLES CSS (palette de couleurs et ombres) */
:root {
    --g:        #2d6a4f;   /* Grammaire → vert */
    --g-light:  #d8f3dc;
    --p:        #7b2d8b;   /* Ponctuation → violet */
    --p-light:  #f3d8f9;
    --s:        #c77c1a;   /* Syntaxe → orange */
    --s-light:  #fdf0d5;
    --u:        #1a6bb5;   /* Usage → bleu */
    --u-light:  #d5e9fd;
    --v:        #b5341a;   /* Vocabulaire → rouge */
    --v-light:  #fdd5d5;
    --ink:      #1a1a2e;   /* couleur principale du texte et nav */
    --card:     #ffffff;   /* fond blanc des cartes */
    --border:   #e0dbd0;   /* bordure grise légère */
}

/* BARRE DE RECHERCHE */
.search-wrap {
    position: relative;
    margin: 0 auto 1.5rem;
    max-width: 480px;
}

.search-wrap svg {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.4;
    pointer-events: none;
}

#searchInput {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.8rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem;
    background: var(--card);
    color: var(--ink);
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}

#searchInput:focus {
    border-color: var(--ink);
    box-shadow: 0 0 0 3px rgba(26,26,46,0.08);
}

#noResults {
    display: none;
    text-align: center;
    padding: 2.5rem;
    opacity: 0.5;
    font-size: 1rem;
}

/* ===================================================
   PAGE LISTE — grille des codes par catégorie
=================================================== */
.codes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
    align-items: start;
    justify-content: center;
}

.code-category-card {
    background: var(--card);
    border-radius: 14px;
    box-shadow: var(--shadow);
    overflow: hidden;
    align-self: start;
    transition: transform .2s, box-shadow .2s;
}

.code-category-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 32px rgba(26,26,46,0.13);
}

.card-header {
    padding: 0.9rem 1.1rem;
    font-family: 'Playfair Display', serif;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: #fff;
}

.card-header.g { background: var(--g); }
.card-header.p { background: var(--p); }
.card-header.s { background: var(--s); }
.card-header.u { background: var(--u); }
.card-header.v { background: var(--v); }

.card-body {
    padding: 0.8rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Puce de code cliquable */
.code-chip {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    padding: 0.4rem 0.7rem;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 0.03em;
    text-decoration: none;
    transition: transform .15s, box-shadow .15s;
    border: 1px solid transparent;
}

.code-chip:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(26,26,46,0.15);
}

.code-chip-code {
    line-height: 1.2;
}

.code-chip-category {
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    opacity: 0.85;
    line-height: 1.25;
}

.code-chip.highlight { outline: 2px solid var(--ink); }
.code-chip.hidden { display: none; }

.badge-g { background: var(--g); color: #fff; }
.badge-p { background: var(--p); color: #fff; }
.badge-s { background: var(--s); color: #fff; }
.badge-u { background: var(--u); color: #fff; }
.badge-v { background: var(--v); color: #fff; }

/* ===================================================
   PAGE DÉTAIL — style ui/test
=================================================== */
.detail-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

.back-link {
    display: inline-block;
    margin-bottom: 1rem;
    color: var(--ink);
    text-decoration: none;
    font-weight: 600;
    opacity: 0.75;
    transition: opacity .2s;
}

.back-link:hover { opacity: 1; }

.detail-header {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 1rem 1.25rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    color: #fff;
}

.detail-header.g { background: var(--g); }
.detail-header.p { background: var(--p); }
.detail-header.s { background: var(--s); }
.detail-header.u { background: var(--u); }
.detail-header.v { background: var(--v); }

.detail-code {
    padding: 0.3rem 0.7rem;
    border-radius: 8px;
    font-weight: 700;
    letter-spacing: 0.03em;
    background: rgba(255,255,255,0.22);
    color: #fff;
    font-size: 1rem;
}

.detail-title {
    font-family: 'Playfair Display', serif;
    font-size: 1.3rem;
    margin: 0;
    line-height: 1.2;
    flex: 1;
}

/* Bouton d'édition de l'en-tête (code/catégorie) */
.header-edit-btn {
    background: rgba(255,255,255,0.25);
    border: none;
    border-radius: 8px;
    width: 2rem;
    height: 2rem;
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .2s;
}

.header-edit-btn:hover { background: rgba(255,255,255,0.45); }

.detail-header.editing .header-edit-btn { display: none; }

.header-editor {
    display: none;
    flex-direction: column;
    gap: 0.4rem;
    flex: 1;
    padding: 0.4rem;
    background: rgba(255,255,255,0.15);
    border-radius: 8px;
}

.detail-header.editing .header-editor { display: flex; }

.header-input-code,
.header-input-category {
    width: 100%;
    box-sizing: border-box;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    border: 1.5px solid rgba(255,255,255,0.6);
    border-radius: 6px;
    padding: 0.3rem 0.5rem;
    outline: none;
    background: #fff;
    color: var(--ink);
    transition: border-color .2s;
}

.header-input-code:focus,
.header-input-category:focus { border-color: var(--ink); }

.header-editor-actions {
    display: flex;
    gap: 0.4rem;
    justify-content: flex-end;
}

/* Cartes de règles (héritées du prototype ui/test) */
.rules-list {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.rule-card {
    background: var(--card);
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.rule-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.rule-header.g { background: var(--g-light); }
.rule-header.p { background: var(--p-light); }
.rule-header.s { background: var(--s-light); }
.rule-header.u { background: var(--u-light); }
.rule-header.v { background: var(--v-light); }

.rule-code {
    flex-shrink: 0;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    letter-spacing: 0.03em;
    min-width: 38px;
    text-align: center;
}

.rule-title {
    flex: 1;
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0;
    color: var(--ink);
    line-height: 1.35;
}

/* Bouton d'édition du sous-code (dans l'en-tête de la règle) */
.entry-edit-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity .2s;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    flex-shrink: 0;
    align-self: flex-start;
}

.rule-header:hover .entry-edit-btn { opacity: 0.6; }
.entry-edit-btn:hover { opacity: 1 !important; background: rgba(0,0,0,0.1); }

.rule-card.editing .entry-edit-btn { display: none; }

/* Éditeur du sous-code : code + description (masqué par défaut) */
.entry-editor {
    display: none;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: #fffbe6;
}

.rule-card.editing .entry-editor { display: flex; }

.entry-input-code,
.entry-input-desc {
    width: 100%;
    box-sizing: border-box;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.88rem;
    border: 1.5px solid #aaa;
    border-radius: 6px;
    padding: 0.35rem 0.5rem;
    outline: none;
    transition: border-color .2s;
}

.entry-input-code { max-width: 140px; }
.entry-input-desc { resize: vertical; }

.entry-input-code:focus,
.entry-input-desc:focus { border-color: var(--ink); }

.entry-editor-actions {
    display: flex;
    gap: 0.4rem;
    justify-content: flex-end;
}

.rule-body {
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

/* Exemples fautif / corrigé (style ui/test) */
.example-item {
    border-radius: 8px;
    padding: 0.6rem 0.9rem;
    font-size: 0.92rem;
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
}

.example-item.incorrect {
    background: var(--v-light);
    color: var(--v);
    border: 1px solid rgba(181, 52, 26, 0.2);
}

.example-item.correct {
    background: var(--g-light);
    color: var(--g);
    border: 1px solid rgba(45, 106, 79, 0.2);
}

.example-mark {
    font-weight: 800;
    font-size: 1rem;
    line-height: 1.2;
    flex-shrink: 0;
}

.example-text {
    flex: 1;
    white-space: pre-line;
}

/* Bouton Modifier (visible au survol de l'exemple) */
.detail-edit-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity .2s;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    flex-shrink: 0;
    align-self: flex-start;
}

.example-item:hover .detail-edit-btn { opacity: 0.6; }
.detail-edit-btn:hover { opacity: 1 !important; background: rgba(0,0,0,0.1); }

/* Éditeur d'exemple (masqué par défaut) */
.detail-editor {
    display: none;
    flex-direction: column;
    gap: 0.4rem;
}

.detail-editor.editing {
    display: flex;
    margin-top: -0.2rem;
}

.detail-input {
    width: 100%;
    box-sizing: border-box;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    border: 1.5px solid #aaa;
    border-radius: 6px;
    padding: 0.35rem 0.5rem;
    outline: none;
    resize: vertical;
    min-height: 2.2rem;
    transition: border-color .2s;
}

.detail-input:focus { border-color: var(--ink); }

.detail-editor-actions {
    display: flex;
    gap: 0.4rem;
}

.detail-save-btn {
    background: var(--ink);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.32rem 0.8rem;
    font-size: 0.78rem;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
}

.detail-cancel-btn {
    background: transparent;
    color: #888;
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 0.32rem 0.6rem;
    font-size: 0.78rem;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
}

.detail-save-btn:hover { background: #000; }
.detail-cancel-btn:hover { background: #f0f0f0; }

/* Responsive */
@media (max-width: 768px) {
    .search-wrap { max-width: 100%; }
    .codes-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
    .detail-container { padding: 1rem 0.5rem; }
    .rule-header { padding: 0.75rem 1rem; }
    .detail-title { font-size: 1.1rem; }
    .example-item { font-size: 0.88rem; padding: 0.6rem 0.8rem; }
}

@media (max-width: 480px) {
    .search-wrap { margin-bottom: 1rem; }
    #searchInput { padding: 0.6rem 0.8rem 0.6rem 2.5rem; font-size: 0.9rem; }
    .search-wrap svg { left: 0.8rem; }
    .code-chip { font-size: 0.78rem; }
    .detail-edit-btn, .detail-save-btn, .detail-cancel-btn { font-size: 0.7rem; }
}