:root {
    --bg-app: #121212;
    --bg-card: #1e1e1e;
    --bg-input: #2c2c2c;
    --bg-header: rgba(30, 30, 30, 0.95);
    --text-main: #e0e0e0;
    --text-muted: #a0a0a0;
    --border: #333;
    
    /* Couleurs fonctionnelles */
    --col-bad: #ff5252;
    --col-bad-bg: rgba(255, 82, 82, 0.15);
    --col-warn: #ffab40;
    --col-warn-bg: rgba(255, 171, 64, 0.15);
    --col-good: #69f0ae;
    --col-good-bg: rgba(105, 240, 174, 0.15);
    --col-info: #448aff;
    --col-info-bg: rgba(68, 138, 255, 0.15);

    --radius: 14px; /* Un poil moins rond */
    --header-height: 56px; /* Plus compact */
    --nav-height: 64px;
}

[data-theme="light"] {
    --bg-app: #f0f2f5;
    --bg-card: #ffffff;
    --bg-input: #eef0f2;
    --bg-header: rgba(255, 255, 255, 0.95);
    --text-main: #1a1a1a;
    --text-muted: #666;
    --border: #e0e0e0;
    
    --col-bad-bg: #fff0f0;
    --col-warn-bg: #fff8e1;
    --col-good-bg: #e8f5e9;
    --col-info-bg: #e3f2fd;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { 
    margin: 0; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 
    background: var(--bg-app); 
    color: var(--text-main); 
    padding-top: var(--header-height); 
    padding-bottom: 110px; /* Espace suffisant pour le dock */
}

/* Header Clean & Compact */
.app-header {
    position: fixed; top: 0; left: 0; width: 100%; height: var(--header-height);
    background: var(--bg-header); border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 12px; z-index: 100;
    transition: background 0.3s;
}
.header-left { display: flex; align-items: center; gap: 4px; }
.header-right { display: flex; align-items: center; gap: 4px; }

.app-header h1 { margin: 0 0 0 6px; font-size: 1.15rem; letter-spacing: -0.5px; font-weight: 800; }

/* Boutons Icones */
.icon-btn { 
    background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--text-main); 
    width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
    border-radius: 50%; transition: background 0.2s;
}
.icon-btn:active { background: var(--bg-input); transform: scale(0.95); }

#back-btn { margin-left: -4px; color: var(--text-main); }

/* Container */
.container { max-width: 800px; margin: 0 auto; padding: 16px 12px; min-height: 80vh; }

/* Section Headers */
.section-header { 
    display: flex; align-items: center; justify-content: space-between; 
    margin: 28px 0 16px; /* Marges réduites */
}
.section-header h2 { margin: 0; font-size: 1.1rem; font-weight: 800; letter-spacing: -0.5px; }

/* Home Grid Layouts (Ajusté : moins zoomé) */
.grid-cats { 
    display: grid; 
    /* 105px est le sweet spot pour mobile */
    grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); 
    gap: 10px; 
}

/* --- CARDS & HOVER EFFECTS --- */
.cat-card {
    background: var(--bg-card); padding: 16px 8px; border-radius: var(--radius);
    text-align: center; text-decoration: none; color: var(--text-main);
    border: 1px solid var(--border); 
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 100px; /* Hauteur réduite */
    
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94), 
                box-shadow 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                border-color 0.2s;
}

@media (hover: hover) {
    .cat-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 8px 16px rgba(0,0,0,0.15);
        border-color: var(--text-muted);
        z-index: 1;
    }
}
.cat-card:active { transform: scale(0.96); background: var(--bg-input); }

.cat-emoji { font-size: 2.2rem; margin-bottom: 6px; display: block; } /* Emoji ajusté */
.cat-name { 
    font-weight: 600; font-size: 0.85rem; /* Texte ajusté */
    line-height: 1.25; display: block;
    overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* Favoris - Cards */
.fav-grid { 
    display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); 
    gap: 10px; 
}
.fav-card {
    background: var(--bg-card); padding: 14px; border-radius: var(--radius);
    border: 1px solid var(--border); text-decoration: none; color: var(--text-main);
    display: flex; flex-direction: column; justify-content: space-between;
    min-height: 100px; box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94), 
                box-shadow 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
@media (hover: hover) {
    .fav-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 8px 16px rgba(0,0,0,0.15);
        border-color: var(--text-muted);
    }
}
.fav-card:active { transform: scale(0.98); }

.fav-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.fav-title { font-weight: 700; font-size: 0.95rem; line-height: 1.3; }
.fav-star { font-size: 0.9rem; color: gold; }
.fav-desc { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Badge unifié */
.badge { 
    padding: 4px 8px; border-radius: 6px; font-size: 0.7rem; font-weight: 700; 
    text-transform: uppercase; display: inline-block; letter-spacing: 0.5px;
}
.badge.bad { background: var(--col-bad-bg); color: var(--col-bad); border: 1px solid var(--col-bad-bg); }
.badge.warn { background: var(--col-warn-bg); color: var(--col-warn); border: 1px solid var(--col-warn-bg); }
.badge.good { background: var(--col-good-bg); color: var(--col-good); border: 1px solid var(--col-good-bg); }
.badge.info { background: var(--col-info-bg); color: var(--col-info); border: 1px solid var(--col-info-bg); }

/* Fiches & Listes */
.sheet-list { display: flex; flex-direction: column; gap: 8px; }
.sheet-item {
    background: var(--bg-card); padding: 14px; border-radius: var(--radius);
    text-decoration: none; color: var(--text-main); display: flex; align-items: center;
    border: 1px solid var(--border); justify-content: space-between;
    border-left-width: 4px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s;
}
@media (hover: hover) {
    .sheet-item:hover {
        transform: translateX(4px);
        background: var(--bg-input);
        box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    }
}
.sheet-item.level-bad { border-left-color: var(--col-bad); }
.sheet-item.level-warn { border-left-color: var(--col-warn); }
.sheet-item.level-good { border-left-color: var(--col-good); }
.sheet-item.level-info { border-left-color: var(--col-info); }

.sheet-meta h3 { margin: 0 0 4px 0; font-size: 0.95rem; }
.sheet-meta p { margin: 0; font-size: 0.85rem; color: var(--text-muted); }
.sheet-arrow { font-size: 1.2rem; opacity: 0.3; transition: opacity 0.2s; }
.sheet-item:hover .sheet-arrow { opacity: 1; }

/* Fiche Détail */
.sheet-header { margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.sheet-title { font-size: 1.5rem; margin: 6px 0 10px 0; line-height: 1.2; font-weight: 800; }
.sheet-cat { font-size: 0.8rem; text-transform: uppercase; color: var(--text-muted); letter-spacing: 1px; font-weight: 600; }

/* Groupes de catégories (Tri) */
.group-header {
    margin: 28px 0 10px 0; padding-left: 8px;
    font-size: 0.85rem; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
    display: flex; align-items: center; gap: 8px;
}
.group-header.lvl-bad { color: var(--col-bad); }
.group-header.lvl-warn { color: var(--col-warn); }
.group-header.lvl-good { color: var(--col-good); }

.section-card {
    background: var(--bg-card); border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
    border: 1px solid var(--border); box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}
.section-title {
    margin: -16px -16px 12px -16px; padding: 12px 16px;
    font-size: 0.85rem; font-weight: 800; letter-spacing: 0.8px; text-transform: uppercase;
    border-bottom: 1px solid rgba(0,0,0,0.05); border-radius: var(--radius) var(--radius) 0 0;
    display: flex; align-items: center; gap: 8px;
}

/* Couleurs Sections */
.sec-red_flags { border-color: rgba(255, 82, 82, 0.3); background: linear-gradient(to bottom right, var(--bg-card), var(--col-bad-bg)); }
.sec-red_flags .section-title { background: var(--col-bad); color: #fff; border: none; }
.sec-quick_questions .section-title { color: var(--col-warn); background: var(--col-warn-bg); }
.sec-action .section-title { color: var(--col-good); background: var(--col-good-bg); }
.sec-posology { border-color: rgba(68, 138, 255, 0.3); background: linear-gradient(to bottom right, var(--bg-card), var(--col-info-bg)); }
.sec-posology .section-title { color: var(--col-info); background: var(--col-info-bg); }
.sec-script .section-title { background: #673ab7; color: #fff; }
.sec-orientation .section-title { background: var(--bg-input); color: var(--text-muted); }
.sec-notes .section-title { background: var(--bg-input); }

ul.check-list { list-style: none; padding: 0; margin: 0; }
ul.check-list li { 
    padding: 7px 0; display: flex; align-items: flex-start;
    line-height: 1.5; color: var(--text-main); font-size: 0.95rem;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
[data-theme="light"] ul.check-list li { border-bottom-color: rgba(0,0,0,0.03); }
ul.check-list li:last-child { border-bottom: none; }
ul.check-list li::before { content: "•"; color: var(--text-muted); margin-right: 10px; font-weight: bold; }

/* === DOCK FLOTTANT CORRIGÉ (Compact & Solide) === */
.sticky-actions {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    width: 90%; max-width: 400px; /* Moins large, plus dock */
    height: 60px; /* Hauteur standard */
    
    /* Background plus opaque pour éviter les glitchs visuels */
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px; /* Arrondi cohérent */
    box-shadow: 0 8px 32px rgba(0,0,0,0.4); /* Ombre forte pour détacher le dock */
    
    display: flex; justify-content: space-around; /* Mieux réparti */
    align-items: center;
    z-index: 90; padding: 0 8px;
}
[data-theme="light"] .sticky-actions {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(0,0,0,0.1);
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.action-btn {
    background: none; border: none; color: var(--text-muted); 
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    cursor: pointer; width: 60px; height: 100%; position: relative;
    transition: all 0.2s;
}
.action-btn span { font-size: 1.4rem; margin-bottom: 0; transition: transform 0.2s; }

/* Indicateur Actif (Point simple et propre) */
.action-btn.active { color: var(--col-info); }
.action-btn.active span { transform: translateY(-2px); }
.action-btn.active::after {
    content: '';
    position: absolute; bottom: 8px;
    width: 4px; height: 4px; background: var(--col-info);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--col-info);
}

/* FAB Adjusté pour le Dock */
.fab-fav {
    position: fixed; bottom: 92px; right: 20px; /* Ajusté */
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--bg-card); border: 1px solid var(--border); color: var(--text-muted);
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; z-index: 95;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    -webkit-tap-highlight-color: transparent;
}
.fab-fav svg { width: 26px; height: 26px; stroke-width: 2px; stroke: currentColor; fill: transparent; transition: all 0.3s; }
.fab-fav:active { transform: scale(0.92); box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
@media (hover: hover) { .fab-fav:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(0,0,0,0.2); } }
.fab-fav.is-fav { border-color: #ffca28; color: #ffca28; background: var(--bg-card); box-shadow: 0 8px 30px rgba(255, 202, 40, 0.25); }
.fab-fav.is-fav svg { fill: #ffca28; stroke: #ffca28; transform: scale(1.1) rotate(15deg); }

/* Search Overlay */
#search-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); z-index: 200; backdrop-filter: blur(8px);
    display: flex; justify-content: center; padding-top: 20px; align-items: flex-start;
}
#search-overlay.hidden { display: none; }
.search-modal { 
    width: 95%; max-width: 600px; display: flex; flex-direction: column; 
    max-height: 80vh; background: var(--bg-card); 
    border-radius: var(--radius); border: 1px solid var(--border);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5); overflow: hidden;
}
.search-input-wrapper { display: flex; align-items: center; border-bottom: 1px solid var(--border); padding: 4px 12px; }
#search-input { flex: 1; padding: 18px 10px; font-size: 1.1rem; border: none; background: transparent; color: var(--text-main); outline: none; }
#search-close-btn { background: none; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; padding: 10px; }
#search-results { overflow-y: auto; flex: 1; }
.search-result-item {
    padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
    display: flex; justify-content: space-between; align-items: center;
}
.search-result-item:hover, .search-result-item.selected { background: var(--bg-input); }
.search-footer {
    background: var(--bg-input); padding: 8px 16px; font-size: 0.75rem; color: var(--text-muted);
    border-top: 1px solid var(--border); display: flex; justify-content: space-between;
}
@media (max-width: 600px) { .search-footer { display: none; } }

/* TOASTS */
#toast-container {
    position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
    z-index: 1000; pointer-events: none;
    display: flex; flex-direction: column; gap: 10px;
}
.toast {
    background: var(--bg-card); border: 1px solid var(--col-info); color: var(--text-main);
    padding: 10px 20px; border-radius: 30px; font-size: 0.9rem; font-weight: 600;
    box-shadow: 0 8px 20px rgba(0,0,0,0.3); animation: slideUpFade 0.3s ease-out;
}
@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ANIMATIONS */
.fade-in { animation: fadeIn 0.2s ease-out; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}