/* ============================================================================
   IMAGILIRE LIBRE - MODALE DICTIONNAIRE PERSONNALISÉ
   ============================================================================ */

/* ── Backdrop ─────────────────────────────────────────────────────────────── */
.dict-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 2100;
}
.dict-modal-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

/* ── Modale principale ────────────────────────────────────────────────────── */
.dict-modal {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(95vw, 640px);
    height: fit-content;
    max-height: 90dvh;
    background: var(--container-bg, #fff);
    border-radius: var(--border-radius, 6px);
    box-shadow: var(--box-shadow, 0 2px 8px rgba(0, 0, 0, 0.1));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.97);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.28s ease, opacity 0.25s ease;
    z-index: 2200;
}
.dict-modal.active {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* ── En-tête ──────────────────────────────────────────────────────────────── */
.dict-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color, #e0e5ec);
    background: var(--background-color, #f5f7fa);
}
.dict-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-color, #333);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.dict-modal-close {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--text-color, #333);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: var(--border-radius, 6px);
    transition: var(--transition, all 0.3s ease);
}
.dict-modal-close:hover {
    background: var(--border-color, #e0e5ec);
    color: var(--primary-color, #36B1B3);
}

/* ── Corps scrollable ─────────────────────────────────────────────────────── */
.dict-modal-body {
    overflow-y: auto;
    flex: 1;
    min-height: 400px;
    padding: 0;
}

/* ── Onglets ──────────────────────────────────────────────────────────────── */
.dict-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color, #e0e5ec);
    background: var(--background-color, #f5f7fa);
    overflow-x: auto;
    scrollbar-width: none;
}
.dict-tabs::-webkit-scrollbar { display: none; }

.dict-tab {
    flex: 1;
    min-width: max-content;
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    color: #666;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    justify-content: center;
    transition: var(--transition, all 0.3s ease);
    white-space: nowrap;
}
.dict-tab.active {
    color: var(--primary-color, #36B1B3);
    border-bottom-color: var(--primary-color, #36B1B3);
}
.dict-tab:hover:not(.active) {
    color: var(--text-color, #333);
    background: var(--border-color, #e0e5ec);
}

/* ── Panneaux ─────────────────────────────────────────────────────────────── */
.dict-tab-panel {
    display: none;
    padding: 1rem 1.25rem;
}
.dict-tab-panel.active {
    display: block;
}

/* ── Explainer + exemple ──────────────────────────────────────────────────── */
.dict-explainer {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    background: #e8f6f6;
    border-radius: var(--border-radius, 6px);
    padding: 0.65rem 0.9rem;
    margin-bottom: 0.6rem;
    font-size: 0.87rem;
    color: var(--text-color, #333);
}
.dict-explainer i { color: var(--primary-color, #36B1B3); margin-top: 2px; flex-shrink: 0; }
.dict-explainer p { margin: 0; }

.dict-example {
    font-size: 0.83rem;
    color: #555;
    margin-bottom: 1rem;
    padding-left: 0.2rem;
}
.dict-example-label { font-weight: 600; margin-right: 0.3rem; }
.dict-example code {
    background: var(--border-color, #e0e5ec);
    padding: 0.1rem 0.4rem;
    border-radius: var(--border-radius, 6px);
    font-family: monospace;
    font-size: 0.9em;
}

/* ── Formulaire ───────────────────────────────────────────────────────────── */
.dict-form-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 0.5rem;
}
.dict-input {
    flex: 1;
    min-width: 120px;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border-color, #e0e5ec);
    border-radius: var(--border-radius, 6px);
    font-size: 0.92rem;
    transition: var(--transition, all 0.3s ease);
    outline: none;
    background: var(--container-bg, #fff);
}
.dict-input:focus { border-color: var(--primary-color, #36B1B3); box-shadow: 0 0 0 2px rgba(54, 177, 179, 0.1); }
.dict-input-full { flex: 2; }

.dict-btn-add {
    padding: 0.55rem 1rem;
    background: var(--primary-color, #36B1B3);
    color: white;
    border: none;
    border-radius: var(--border-radius, 6px);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
    transition: var(--transition, all 0.3s ease);
    box-shadow: var(--box-shadow, 0 2px 8px rgba(0, 0, 0, 0.1));
}
.dict-btn-add:hover { background: #2a9799; transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); }
.dict-btn-add:active { background: #228688; transform: translateY(0); box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1); }

/* ── Feedback ─────────────────────────────────────────────────────────────── */
.dict-feedback {
    display: none;
    font-size: 0.83rem;
    padding: 0.4rem 0.65rem;
    border-radius: var(--border-radius, 6px);
    margin-bottom: 0.5rem;
}
.dict-feedback-success { background: #d4edda; color: var(--success-color, #2ecc71); border: 1px solid var(--success-color, #2ecc71); }
.dict-feedback-error   { background: #f8d7da; color: var(--error-color, #e74c3c); border: 1px solid var(--error-color, #e74c3c); }
.dict-feedback-warn    { background: #fff3cd; color: var(--secondary-color, #F7B731); border: 1px solid var(--secondary-color, #F7B731); }
.dict-feedback-info    { background: #d1ecf1; color: var(--primary-color, #36B1B3); border: 1px solid var(--primary-color, #36B1B3); }

/* ── Liste des mots ───────────────────────────────────────────────────────── */
.dict-list-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0.8rem 0 0.4rem;
}
.dict-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.dict-list-empty {
    font-size: 0.85rem;
    color: #aaa;
    font-style: italic;
    padding: 0.3rem 0;
}
.dict-list-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--background-color, #f5f7fa);
    border: 1px solid var(--border-color, #e0e5ec);
    border-radius: var(--border-radius, 6px);
    padding: 0.45rem 0.75rem;
    font-size: 0.88rem;
}
.dict-item-mot {
    font-weight: 600;
    color: var(--text-color, #333);
    flex-shrink: 0;
}
.dict-item-detail {
    flex: 1;
    color: #666;
    font-size: 0.83rem;
    font-style: italic;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dict-item-delete {
    background: none;
    border: none;
    color: var(--error-color, #e74c3c);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--border-radius, 6px);
    font-size: 0.8rem;
    transition: var(--transition, all 0.3s ease);
    flex-shrink: 0;
}
.dict-item-delete:hover { background: #f8d7da; color: #c0392b; }

/* ── Recherche / Filtre dans la liste ────────────────────────────────────── */
.dict-search-row {
    margin: 0.7rem 0 0.4rem;
}
.dict-search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
.dict-search-icon {
    position: absolute;
    left: 0.65rem;
    color: #bbb;
    font-size: 0.78rem;
    pointer-events: none;
    z-index: 1;
}
.dict-search-input {
    width: 100%;
    padding: 0.42rem 2rem 0.42rem 2rem;
    border: 1px solid var(--border-color, #e0e5ec);
    border-radius: var(--border-radius, 6px);
    font-size: 0.83rem;
    font-family: inherit;
    background: var(--background-color, #f5f7fa);
    color: var(--text-color, #333);
    outline: none;
    transition: var(--transition, all 0.3s ease);
}
.dict-search-input:focus {
    border-color: var(--primary-color, #36B1B3);
    box-shadow: 0 0 0 2px rgba(54, 177, 179, 0.08);
    background: var(--container-bg, #fff);
}
.dict-search-input::placeholder {
    color: #bbb;
    font-style: italic;
    font-size: 0.82rem;
}
/* Masquer le bouton natif de l'input type="search" */
.dict-search-input::-webkit-search-cancel-button,
.dict-search-input::-webkit-search-decoration { display: none; }

.dict-search-clear {
    position: absolute;
    right: 0.35rem;
    background: none;
    border: none;
    color: #bbb;
    cursor: pointer;
    padding: 0.25rem 0.3rem;
    border-radius: 4px;
    font-size: 0.72rem;
    display: none; /* affiché par JS quand il y a du texte */
    align-items: center;
    justify-content: center;
    transition: var(--transition, all 0.3s ease);
    line-height: 1;
}
.dict-search-clear:hover {
    color: var(--error-color, #e74c3c);
    background: rgba(231, 76, 60, 0.1);
}

/* ── Compteur de résultats (affiché dans le header de liste) ─────────────── */
.dict-list-count {
    font-weight: 400;
    color: var(--primary-color, #36B1B3);
    font-size: 0.75rem;
}

/* ── Message "Aucun résultat" après filtre ────────────────────────────────── */
.dict-list-no-result {
    font-size: 0.84rem;
    color: #aaa;
    font-style: italic;
    padding: 0.3rem 0;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    list-style: none;
}
.dict-list-no-result i { font-size: 0.78rem; }

/* ── Pied de modale ───────────────────────────────────────────────────────── */
.dict-modal-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border-color, #e0e5ec);
    background: var(--background-color, #f5f7fa);
}

/* ── Section Export/Import ────────────────────────────────────────────────── */
.dict-import-export-section {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: #e8f6f6;
    border-radius: var(--border-radius, 6px);
    border: 1px solid #c4e9ea;
}
.dict-import-export-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-color, #333);
    margin-bottom: 0.6rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.dict-import-export-title i {
    color: var(--primary-color, #36B1B3);
}
.dict-import-export-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.dict-btn-export,
.dict-btn-import {
    flex: 1;
    padding: 0.6rem 1rem;
    background: var(--primary-color, #36B1B3);
    color: white;
    border: none;
    border-radius: var(--border-radius, 6px);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: var(--transition, all 0.3s ease);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.dict-btn-export:hover,
.dict-btn-import:hover {
    background: #2a9799;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}
.dict-btn-export:active,
.dict-btn-import:active {
    background: #228688;
    transform: translateY(0);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
}
.dict-btn-export {
    background: var(--success-color, #2ecc71);
}
.dict-btn-export:hover {
    background: #27ae60;
}
.dict-btn-export:active {
    background: #229954;
}
.dict-import-export-hint {
    font-size: 0.75rem;
    color: #555;
    margin: 0;
    text-align: center;
    font-style: italic;
}

/* ── Feedback global ──────────────────────────────────────────────────────── */
.dict-global-feedback {
    display: none;
    font-size: 0.87rem;
    font-weight: 500;
    padding: 0.6rem 0.85rem;
    border-radius: var(--border-radius, 6px);
    margin-bottom: 0.75rem;
    text-align: center;
}

.dict-save-note {
    margin: 0;
    font-size: 0.8rem;
    color: #888;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* ── Bouton d'ouverture dans les paramètres ───────────────────────────────── */
.btn-dictionnaire-open {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    background: var(--primary-color, #36B1B3);
    color: white;
    border: none;
    border-radius: var(--border-radius, 6px);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition, all 0.3s ease);
    margin-top: 0.5rem;
    box-shadow: var(--box-shadow, 0 2px 8px rgba(0, 0, 0, 0.1));
}
.btn-dictionnaire-open:hover { 
    background: #2a9799; 
    transform: translateY(-2px); 
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}
.btn-dictionnaire-open:active {
    transform: translateY(0);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
}

/* ── Dark mode ────────────────────────────────────────────────────────────── */
body.dark-mode .dict-modal {
    background: #1e2633;
    color: #e0e6f0;
}
body.dark-mode .dict-modal-header,
body.dark-mode .dict-modal-footer,
body.dark-mode .dict-tabs {
    background: #161d28;
    border-color: #2e3a4e;
}
body.dark-mode .dict-modal-header h3 { color: #e0e6f0; }
body.dark-mode .dict-modal-close { color: #aaa; }
body.dark-mode .dict-modal-close:hover { background: #2e3a4e; color: #fff; }
body.dark-mode .dict-tab { color: #8899bb; }
body.dark-mode .dict-tab.active { color: #5dd4d6; border-bottom-color: #5dd4d6; }
body.dark-mode .dict-tab:hover:not(.active) { background: #1e2d42; }
body.dark-mode .dict-explainer { background: #1a2a40; color: #c0cfdf; }
body.dark-mode .dict-input { background: #161d28; border-color: #2e3a4e; color: #e0e6f0; }
body.dark-mode .dict-input:focus { border-color: #5dd4d6; box-shadow: 0 0 0 2px rgba(93, 212, 214, 0.2); }
body.dark-mode .dict-list-item { background: #161d28; border-color: #2e3a4e; }
body.dark-mode .dict-item-mot { color: #e0e6f0; }
body.dark-mode .dict-item-detail { color: #8899bb; }
body.dark-mode .dict-save-note { color: #607090; }
body.dark-mode .dict-import-export-section { 
    background: #1a2a40; 
    border-color: #2e3a4e; 
}
body.dark-mode .dict-import-export-title { color: #e0e6f0; }
body.dark-mode .dict-import-export-hint { color: #8899bb; }
body.dark-mode .dict-search-input {
    background: #161d28;
    border-color: #2e3a4e;
    color: #e0e6f0;
}
body.dark-mode .dict-search-input:focus {
    border-color: #5dd4d6;
    box-shadow: 0 0 0 2px rgba(93, 212, 214, 0.15);
    background: #1e2633;
}
body.dark-mode .dict-search-input::placeholder { color: #3a4a5a; }
body.dark-mode .dict-search-icon { color: #4a5a6a; }
body.dark-mode .dict-search-clear { color: #4a5a6a; }
body.dark-mode .dict-search-clear:hover {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.15);
}
body.dark-mode .dict-list-count { color: #5dd4d6; }
body.dark-mode .dict-list-no-result { color: #607090; }

/* ── Responsive tablette (portrait) ───────────────────────────────────────── */
@media (min-width: 481px) and (max-width: 768px) {
    .dict-modal {
        width: min(90vw, 580px);
        max-height: 92dvh;
        min-height: 500px;
    }
    .dict-modal-body {
        min-height: 400px;
        max-height: calc(92dvh - 180px);
    }
    .dict-modal-header,
    .dict-modal-footer {
        padding: 1rem;
        flex-shrink: 0;
    }
    .dict-tab-panel {
        padding: 1rem;
    }
    .dict-tabs {
        flex-shrink: 0;
    }
    .dict-tab {
        font-size: 0.88rem;
        padding: 0.7rem 0.85rem;
    }
    .dict-form-row {
        gap: 0.6rem;
    }
    .dict-input {
        font-size: 0.95rem;
        padding: 0.6rem 0.8rem;
    }
    .dict-btn-add {
        padding: 0.6rem 1.1rem;
        font-size: 0.9rem;
    }
    .dict-import-export-buttons {
        gap: 0.6rem;
    }
}

/* ── Responsive tablette (paysage) ────────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: landscape) {
    .dict-modal {
        width: min(85vw, 700px);
        max-height: 88dvh;
        min-height: 450px;
    }
    .dict-modal-body {
        min-height: 350px;
        max-height: calc(88dvh - 160px);
    }
    .dict-modal-header,
    .dict-modal-footer {
        padding: 0.9rem 1.1rem;
        flex-shrink: 0;
    }
    .dict-tab-panel {
        padding: 0.9rem 1.1rem;
    }
    .dict-tabs {
        flex-shrink: 0;
    }
}

/* ── Responsive tablette (portrait large) ─────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
    .dict-modal {
        width: min(88vw, 650px);
        max-height: 92dvh;
        min-height: 550px;
    }
    .dict-modal-body {
        min-height: 450px;
        max-height: calc(92dvh - 170px);
    }
    .dict-modal-header,
    .dict-modal-footer {
        flex-shrink: 0;
    }
    .dict-tabs {
        flex-shrink: 0;
    }
    .dict-tab {
        font-size: 0.9rem;
        padding: 0.75rem 1rem;
    }
    .dict-form-row {
        gap: 0.65rem;
    }
    .dict-input {
        font-size: 1rem;
        padding: 0.65rem 0.85rem;
    }
    .dict-btn-add {
        padding: 0.65rem 1.15rem;
        font-size: 0.92rem;
    }
    .dict-list-item {
        padding: 0.55rem 0.85rem;
        font-size: 0.92rem;
    }
    .dict-item-mot {
        font-size: 0.95rem;
    }
}

/* ── Responsive mobile ────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .dict-modal {
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        inset: 0;
        margin: 0;
    }
    .dict-form-row {
        flex-direction: column;
    }
    .dict-input { min-width: unset; width: 100%; }
    .dict-btn-add { width: 100%; justify-content: center; }
    .dict-tab { font-size: 0.78rem; padding: 0.65rem 0.6rem; }
    .dict-import-export-buttons {
        flex-direction: column;
    }
    .dict-btn-export,
    .dict-btn-import {
        width: 100%;
    }
}
