/* ==================== VARIABLES CSS ==================== */

:root {
    --bg: #f4f4f5;
    --bg-elevated: #ffffff;
    --text: #111827;
    --text-muted: #6b7280;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --border: #e5e7eb;
    --shadow: rgba(0, 0, 0, 0.1);
}

body.theme-dark {
    --bg: #020617;
    --bg-elevated: #1e293b;
    --text: #e5e7eb;
    --text-muted: #9ca3af;
    --accent: #38bdf8;
    --accent-hover: #0ea5e9;
    --border: #1f2937;
    --shadow: rgba(0, 0, 0, 0.3);
}

/* ==================== RESET ==================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

/* ==================== LAYOUT GLOBAL ==================== */

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background-color 150ms ease, color 150ms ease;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
}

/* ==================== SYSTÈME DE VUES ==================== */

.view {
    display: none;
    opacity: 0;
    transition: opacity 300ms ease-in-out;
}

.view.active {
    display: block;
    opacity: 1;
}

/* ==================== HEADER CATALOGUE ==================== */

#catalog-view header {
    background-color: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    padding: 2rem 0;
    text-align: center;
    box-shadow: 0 1px 3px var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0 2rem;
}

#catalog-view header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    color: var(--text);
}

#catalog-view header p {
    color: var(--text-muted);
    font-size: 1rem;
}

.header-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

#theme-toggle {
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background-color: transparent;
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 200ms ease;
}

#theme-toggle:hover {
    background-color: var(--bg);
}

#theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

#lang-toggle {
    padding: 0.5rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background-color: transparent;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 200ms ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#lang-toggle:hover {
    background-color: var(--bg);
    transform: scale(1.05);
}

#lang-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* ==================== HERO ==================== */

#hero {
    margin: 3rem 0;
    text-align: center;
}

#hero h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--text);
}

#hero p {
    color: var(--text-muted);
    max-width: 700px;
    margin: 0 auto;
}

/* ==================== STATS ==================== */

#stats-section {
    margin: 1rem 0 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.stats-chip {
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background-color: var(--bg-elevated);
    font-size: 0.8rem;
    color: var(--text);
}

.stats-total {
    font-weight: 600;
    background-color: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ==================== CONTRÔLES (RECHERCHE, FILTRES, TRI) ==================== */

#controls-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1.5rem;
}

#search-input {
    flex: 1;
    min-width: 200px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.9rem;
    background-color: var(--bg-elevated);
    color: var(--text);
    font-family: inherit;
}

#category-filter,
#status-filter,
#sort-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.9rem;
    background-color: var(--bg-elevated);
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
}

#search-input:focus,
#category-filter:focus,
#status-filter:focus,
#sort-select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-color: var(--accent);
}

#view-toggle {
    display: flex;
    gap: 0.25rem;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.25rem;
}

.view-toggle-btn {
    padding: 0.35rem 0.75rem;
    border: none;
    background-color: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 200ms ease, color 200ms ease;
}

.view-toggle-btn:hover {
    background-color: var(--bg);
    color: var(--text);
}

.view-toggle-btn.active {
    background-color: var(--accent);
    color: white;
}

.view-toggle-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ==================== GRILLE OUTILS ==================== */

#tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

/* ==================== ANIMATIONS ==================== */

@keyframes card-fade-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==================== CARTES OUTILS ==================== */

.tool-card {
    background-color: var(--bg-elevated);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 1px 3px var(--shadow);
    transition: all 250ms cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.tool-card.animated {
    animation: card-fade-in 180ms ease-out;
}

.tool-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

body.theme-dark .tool-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    position: relative;
}

.card-header h3 {
    margin: 0;
    flex: 1;
    font-size: 1.25rem;
    color: var(--text);
}

.card-badges {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.card-category,
.card-status {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.card-description {
    margin: 1rem 0;
    color: var(--text);
    line-height: 1.5;
}

.card-description.compact {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-tags {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* ==================== BADGES ==================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-favorite {
    background-color: rgba(250, 204, 21, 0.15);
    color: #854d0e;
}

body.theme-dark .badge-favorite {
    background-color: rgba(250, 204, 21, 0.2);
    color: #fde047;
}

.badge-priority {
    background-color: rgba(239, 68, 68, 0.12);
    color: #b91c1c;
}

body.theme-dark .badge-priority {
    background-color: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

/* ==================== BOUTONS ==================== */

.btn {
    display: inline-block;
    padding: 0.625rem 1.25rem;
    border-radius: 0.5rem;
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 250ms cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background-color: var(--accent);
    color: white;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
}

.btn-secondary:hover {
    background-color: rgba(37, 99, 235, 0.1);
}

.card-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

/* ==================== MINIATURES AMÉLIORÉES ==================== */

.card-thumbnail {
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: 0.5rem 0.5rem 0 0;
    margin: -1.5rem -1.5rem 1rem -1.5rem;
    background: linear-gradient(135deg, var(--bg) 0%, var(--bg-elevated) 100%);
    position: relative;
}

.card-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 300ms ease;
}

.tool-card:hover .card-thumbnail img {
    transform: scale(1.05);
}

.card-thumbnail-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    gap: 0.5rem;
}

.card-thumbnail-icon {
    font-size: 2.5rem;
    opacity: 0.9;
}

/* ==================== BOUTON PARTAGE REPOSITIONNÉ ==================== */

.card-share-btn {
    position: absolute;
    top: -0.5rem;
    right: -0.5rem;
    padding: 0.5rem;
    border-radius: 50%;
    border: 1px solid var(--border);
    background-color: var(--bg-elevated);
    color: var(--text);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 200ms ease;
    z-index: 5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.card-share-btn:hover {
    background-color: var(--accent);
    color: white;
    border-color: var(--accent);
    transform: scale(1.1) rotate(12deg);
}

body.theme-dark .card-share-btn {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* ==================== MENU PARTAGE AMÉLIORÉ ==================== */

.share-menu {
    position: absolute;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px var(--shadow);
    padding: 0.5rem;
    z-index: 1000;
    min-width: 180px;
    animation: share-menu-fade-in 200ms ease-out;
}

@keyframes share-menu-fade-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.share-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: none;
    background: transparent;
    color: var(--text);
    text-decoration: none;
    font-size: 0.9rem;
    width: 100%;
    text-align: left;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 150ms ease;
}

.share-option:hover {
    background-color: var(--bg);
    transform: translateX(4px);
}

/* ==================== MODE SÉLECTION ==================== */

#selection-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

#selection-counter {
    font-weight: 500;
    color: var(--text);
    transition: all 200ms ease;
}

#selection-counter.updated {
    animation: counter-pulse 400ms ease;
}

@keyframes counter-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
        color: var(--accent);
    }
}

#print-selection-btn:disabled,
#export-pdf-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.card-select {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 10;
}

.card-checkbox {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
    accent-color: var(--accent);
}

.card-checkbox-label {
    display: none;
}

/* ==================== TOAST NOTIFICATION ==================== */

.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background-color: var(--accent);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    animation: toast-slide-in 300ms ease-out;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
}

body.theme-dark .toast {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
}

@keyframes toast-slide-in {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.hiding {
    animation: toast-slide-out 300ms ease-in forwards;
}

@keyframes toast-slide-out {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

/* ==================== FICHES DÉTAILLÉES ==================== */

.tool-detail header {
    background-color: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    padding: 2rem 0;
    box-shadow: 0 1px 3px var(--shadow);
}

.tool-detail header h1 {
    font-size: 2rem;
    margin-top: 1rem;
    color: var(--text);
}

.tool-detail header h1:focus {
    outline: none;
}

.tool-detail main {
    margin-top: 2rem;
}

.tool-detail main section {
    margin-bottom: 3rem;
}

.tool-detail main h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text);
}

.tool-detail main p,
.tool-detail main ul {
    color: var(--text);
    line-height: 1.7;
}

.tool-detail main ul {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
}

.tool-detail main li {
    margin-bottom: 0.5rem;
}

/* ==================== IFRAME PLEINE PAGE (VERSION FINALE) ==================== */

#detail-view {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999 !important;
    background-color: var(--bg) !important;
    overflow: hidden !important;
}

#detail-view header {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 10001 !important;
    background-color: rgba(30, 41, 59, 0.95) !important;
    backdrop-filter: blur(10px) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    padding: 0.75rem 0 !important;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3) !important;
}

body.theme-dark #detail-view header {
    background-color: rgba(2, 6, 23, 0.95) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
}

#detail-view header .container {
    max-width: 100% !important;
    padding: 0 1.5rem !important;
    display: flex !important;
    align-items: center !important;
    gap: 1rem !important;
}

#detail-view header h1 {
    display: none !important;
}

#detail-view .header-actions {
    display: flex !important;
    align-items: center !important;
    gap: 0.75rem !important;
}

#detail-view .back-to-catalog,
#detail-view .print-fiche-btn {
    padding: 0.5rem 1rem !important;
    border-radius: 0.375rem !important;
    font-size: 0.9rem !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: all 200ms ease !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
}

#detail-view .back-to-catalog {
    background-color: var(--accent) !important;
    color: white !important;
    border: none !important;
}

#detail-view .back-to-catalog:hover {
    background-color: var(--accent-hover) !important;
    transform: translateX(-2px) !important;
}

#detail-view .print-fiche-btn {
    background-color: transparent !important;
    color: white !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
}

#detail-view .print-fiche-btn:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    transform: translateY(-1px) !important;
}

.iframe-fullpage-container {
    position: fixed !important;
    top: 60px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: calc(100vh - 60px) !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
}

.iframe-fullpage {
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    background-color: var(--bg) !important;
}

/* ==================== ÉTAT VIDE ==================== */

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state p:first-child {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.empty-state p {
    margin-bottom: 0.25rem;
}

/* ==================== FOOTER ==================== */

footer {
    margin-top: 4rem;
    padding: 2rem 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.back-to-top-link {
    display: inline-flex;
    align-items: center;
    margin-top: 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--accent);
    text-decoration: none;
}

.back-to-top-link:hover {
    text-decoration: underline;
}

.back-to-top-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 0.25rem;
}

/* ==================== ACCESSIBILITÉ ==================== */

*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* ==================== IMPRESSION AMÉLIORÉE (VERTICAL + HORIZONTAL) ==================== */

@media print {
    header, footer, #controls-bar, #selection-bar, .card-actions, .btn,
    #detail-view .header-actions {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
        margin: 0;
        padding: 0;
    }
    
    #detail-view {
        position: static !important;
        width: 100% !important;
        height: auto !important;
    }
    
    .iframe-fullpage-container {
        position: static !important;
        top: 0 !important;
        height: auto !important;
        min-height: 100vh;
    }
    
    .iframe-fullpage {
        width: 100% !important;
        height: auto !important;
        min-height: 100vh;
    }
    
    @page {
        size: auto;
        margin: 1cm;
    }
    
    .tool-card {
        page-break-inside: avoid;
        border: 1px solid #ddd;
        margin-bottom: 1rem;
    }
    
    .card-thumbnail {
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        text-align: center;
        padding: 0 1rem;
    }
    
    .header-controls {
        flex-direction: row;
        justify-content: center;
    }
    
    #controls-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    #search-input {
        min-width: auto;
    }
    
    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .card-badges {
        margin-top: 0.25rem;
    }
    
    .card-actions {
        flex-direction: column;
    }
    
    #catalog-view header h1 {
        font-size: 2rem;
    }
    
    #hero h2 {
        font-size: 1.5rem;
    }
    
    .tool-detail header h1 {
        font-size: 1.75rem;
    }
    
    .container {
        padding: 1rem;
    }
    
    .card-thumbnail {
        aspect-ratio: 16 / 9;
    }
    
    .toast {
        right: 1rem;
        left: 1rem;
        bottom: 1rem;
    }
    
    #detail-view header {
        padding: 0.5rem 0 !important;
    }
    
    #detail-view header .container {
        padding: 0 1rem !important;
        gap: 0.5rem !important;
    }
    
    .iframe-fullpage-container {
        top: 55px !important;
        height: calc(100vh - 55px) !important;
    }
    
    #detail-view .back-to-catalog,
    #detail-view .print-fiche-btn {
        padding: 0.4rem 0.8rem !important;
        font-size: 0.85rem !important;
    }
    
    #detail-view .back-to-catalog .btn-text,
    #detail-view .print-fiche-btn .btn-text {
        display: none !important;
    }
}
