/**
 * Interactive Diagrams - Styles pour hub et visionneuse
 * OPLC - Outils Pour La Classe
 *
 * Sections:
 *   1. CSS Variables
 *   2. Hub - Layout & Header
 *   3. Hub - Filter Bar
 *   4. Hub - Type Sections & Grid
 *   5. Hub - Diagram Cards
 *   6. Viewer - Layout
 *   7. Viewer - SVG Container (zoom/pan)
 *   8. Viewer - Info Panel
 *   9. Viewer - Zoom Controls
 *  10. Viewer - Legend Toggle
 *  11. Viewer - Discovery Counter
 *  12. Timeline Mode
 *  13. Map Mode
 *  14. Science Mode (hotspots & annotations)
 *  15. Animations
 *  16. Accessibility
 *  17. Responsive (mobile)
 *  18. Print
 */

/* ========================================
   1. CSS VARIABLES
   ======================================== */

:root {
    --idg-accent: #059669;
    --idg-accent-dark: #047857;
    --idg-accent-light: #D1FAE5;
    --idg-accent-hover: #10B981;
    --idg-text: #111827;
    --idg-text-secondary: #6B7280;
    --idg-text-muted: #9CA3AF;
    --idg-bg: #F9FAFB;
    --idg-card-bg: #FFFFFF;
    --idg-border: #E5E7EB;
    --idg-border-hover: #D1D5DB;
    --idg-radius: 1rem;
    --idg-radius-sm: 0.5rem;
    --idg-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    --idg-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --idg-timeline-color: #F59E0B;
    --idg-map-color: #3B82F6;
    --idg-science-color: #059669;
    --idg-panel-z: 200;
    --idg-controls-z: 100;
    --idg-transition: 0.25s ease;
}

/* ========================================
   2. HUB - Layout & Header
   ======================================== */

.diagram-hub {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

.diagram-hub-back {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--idg-text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    transition: color var(--idg-transition);
}

.diagram-hub-back:hover {
    color: var(--idg-accent);
}

.diagram-hub-back:focus-visible {
    outline: 2px solid var(--idg-accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.diagram-hub-header {
    text-align: center;
    margin-bottom: 1.75rem;
}

.diagram-hub-header h1 {
    font-size: 1.6rem;
    font-weight: 900;
    color: var(--idg-text);
    margin-bottom: 0.25rem;
}

.diagram-hub-header p {
    color: var(--idg-text-secondary);
    font-size: 1rem;
}

/* ========================================
   3. HUB - Filter Bar
   ======================================== */

.diagram-filters {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 2rem;
    align-items: center;
}

.diagram-filter-select {
    padding: 0.5rem 1rem;
    border: 2px solid var(--idg-border);
    border-radius: 2rem;
    background: var(--idg-card-bg);
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--idg-text);
    cursor: pointer;
    transition: border-color var(--idg-transition), background var(--idg-transition);
    appearance: none;
    -webkit-appearance: none;
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%236B7280' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
}

.diagram-filter-select:hover {
    border-color: var(--idg-accent-hover);
}

.diagram-filter-select:focus-visible {
    outline: 2px solid var(--idg-accent);
    outline-offset: 2px;
    border-color: var(--idg-accent);
}

/* ========================================
   4. HUB - Type Sections & Grid
   ======================================== */

.diagram-type-section {
    margin-bottom: 2.25rem;
}

.diagram-type-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--idg-text);
    padding-left: 0.25rem;
}

.diagram-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

/* ========================================
   5. HUB - Diagram Cards
   ======================================== */

.diagram-card {
    background: var(--idg-card-bg);
    border-radius: var(--idg-radius);
    padding: 1.25rem;
    border: 2px solid var(--idg-border);
    transition: transform var(--idg-transition), box-shadow var(--idg-transition), border-color var(--idg-transition);
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    position: relative;
}

.diagram-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--idg-shadow-lg);
    border-color: var(--idg-accent);
}

.diagram-card:focus-visible {
    outline: 2px solid var(--idg-accent);
    outline-offset: 2px;
}

.diagram-card-icon {
    font-size: 2rem;
    line-height: 1;
}

.diagram-card-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--idg-text);
}

.diagram-card-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    width: fit-content;
}

.diagram-card-badge.timeline {
    background: #FEF3C7;
    color: #92400E;
}

.diagram-card-badge.map {
    background: #DBEAFE;
    color: #1E40AF;
}

.diagram-card-badge.science {
    background: var(--idg-accent-light);
    color: var(--idg-accent-dark);
}

.diagram-card-meta {
    font-size: 0.8rem;
    color: var(--idg-text-secondary);
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.diagram-card-matiere {
    font-weight: 600;
}

.diagram-card-niveau {
    color: var(--idg-text-muted);
}

.diagram-card-desc {
    font-size: 0.85rem;
    color: var(--idg-text-secondary);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.diagram-card-progress {
    margin-top: auto;
    padding-top: 0.5rem;
}

.diagram-card-progress-text {
    font-size: 0.75rem;
    color: var(--idg-accent);
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.diagram-card-progress-bar {
    height: 4px;
    background: #E5E7EB;
    border-radius: 2px;
    overflow: hidden;
}

.diagram-card-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--idg-accent), var(--idg-accent-hover));
    border-radius: 2px;
    transition: width 0.4s ease;
}

/* Type accent borders */
.diagram-card.type-timeline { border-left: 4px solid var(--idg-timeline-color); }
.diagram-card.type-map      { border-left: 4px solid var(--idg-map-color); }
.diagram-card.type-science   { border-left: 4px solid var(--idg-science-color); }

.diagram-card.type-timeline:hover { border-color: var(--idg-timeline-color); }
.diagram-card.type-map:hover      { border-color: var(--idg-map-color); }
.diagram-card.type-science:hover   { border-color: var(--idg-science-color); }

/* Empty state */
.diagram-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--idg-text-muted);
}

.diagram-empty-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 0.75rem;
}

.diagram-empty-text {
    font-size: 1.05rem;
    font-weight: 600;
}

/* ========================================
   6. VIEWER - Layout
   ======================================== */

.diagram-viewer {
    position: fixed;
    inset: 0;
    background: var(--idg-card-bg);
    display: flex;
    flex-direction: column;
    z-index: 50;
}

.diagram-viewer-header {
    background: linear-gradient(135deg, var(--idg-accent), var(--idg-accent-dark));
    color: white;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.diagram-viewer-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    text-decoration: none;
    font-size: 1.1rem;
    flex-shrink: 0;
    transition: background var(--idg-transition);
}

.diagram-viewer-back:hover {
    background: rgba(255, 255, 255, 0.35);
}

.diagram-viewer-back:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

.diagram-viewer-header h1 {
    flex: 1;
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.diagram-viewer-type-badge {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

/* ========================================
   7. VIEWER - SVG Container (zoom/pan)
   ======================================== */

.svg-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: var(--idg-bg);
    touch-action: none;
}

.svg-container-inner {
    width: 100%;
    height: 100%;
    transform-origin: 0 0;
    transition: transform 0.15s ease;
    will-change: transform;
}

.svg-container-inner svg {
    width: 100%;
    height: 100%;
    display: block;
}

.svg-container-inner svg [data-id] {
    cursor: pointer;
    transition: opacity 0.2s, filter 0.2s;
}

.svg-container-inner svg [data-id]:hover {
    opacity: 0.85;
    filter: brightness(1.1);
}

.svg-container-inner svg [data-id].active {
    filter: brightness(1.2) drop-shadow(0 0 6px rgba(5, 150, 105, 0.5));
}

.svg-container-inner svg [data-id]:focus-visible {
    outline: 2px solid var(--idg-accent);
    outline-offset: 2px;
}

.svg-container.is-panning {
    cursor: grabbing;
}

.svg-container.is-pannable {
    cursor: grab;
}

/* Loading overlay inside SVG container */
.svg-container .diagram-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--idg-bg);
    color: var(--idg-text-secondary);
    gap: 0.75rem;
    z-index: 10;
}

.diagram-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--idg-border);
    border-top-color: var(--idg-accent);
    border-radius: 50%;
    animation: idg-spin 0.8s linear infinite;
}

/* ========================================
   8. VIEWER - Info Panel
   ======================================== */

.info-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--idg-card-bg);
    border-radius: 1.5rem 1.5rem 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    max-height: 55vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: var(--idg-panel-z);
    padding: 0;
}

.info-panel.open {
    transform: translateY(0);
}

.info-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem 0.75rem;
    position: sticky;
    top: 0;
    background: var(--idg-card-bg);
    z-index: 1;
}

.info-panel-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--idg-text);
    margin: 0;
    flex: 1;
    padding-right: 0.5rem;
}

.info-panel-close {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: #F3F4F6;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--idg-transition);
    color: var(--idg-text-secondary);
    font-family: inherit;
}

.info-panel-close:hover {
    background: var(--idg-border);
}

.info-panel-close:focus-visible {
    outline: 2px solid var(--idg-accent);
    outline-offset: 2px;
}

.info-panel-body {
    padding: 0 1.5rem 1.5rem;
}

.info-panel-emoji {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 0.5rem;
    display: block;
}

.info-panel-desc {
    color: #4B5563;
    line-height: 1.6;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.info-panel-facts {
    list-style: none;
    padding: 0;
    margin: 0;
}

.info-panel-facts li {
    padding: 0.5rem 0 0.5rem 1.75rem;
    border-bottom: 1px solid #F3F4F6;
    position: relative;
    line-height: 1.45;
    color: #374151;
    font-size: 0.92rem;
}

.info-panel-facts li:last-child {
    border-bottom: none;
}

.info-panel-facts li::before {
    content: '\1F4A1';
    position: absolute;
    left: 0;
    top: 0.5rem;
}

/* Desktop: slide from right */
@media (min-width: 769px) {
    .info-panel {
        position: fixed;
        bottom: auto;
        top: 0;
        left: auto;
        right: 0;
        width: 380px;
        height: 100vh;
        border-radius: 0;
        max-height: 100vh;
        transform: translateX(100%);
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    }

    .info-panel.open {
        transform: translateX(0);
    }
}

/* ========================================
   9. VIEWER - Zoom Controls
   ======================================== */

.zoom-controls {
    position: absolute;
    bottom: 1.25rem;
    right: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    z-index: var(--idg-controls-z);
}

.zoom-controls button {
    width: 42px;
    height: 42px;
    border: 1px solid var(--idg-border);
    border-radius: var(--idg-radius-sm);
    background: var(--idg-card-bg);
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--idg-transition), border-color var(--idg-transition);
    font-family: inherit;
    color: var(--idg-text);
}

.zoom-controls button:hover {
    background: var(--idg-accent-light);
    border-color: var(--idg-accent);
}

.zoom-controls button:focus-visible {
    outline: 2px solid var(--idg-accent);
    outline-offset: 2px;
}

/* ========================================
   10. VIEWER - Legend Toggle
   ======================================== */

.legend-toggle {
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: var(--idg-controls-z);
    padding: 0.5rem 0.9rem;
    border: 1px solid var(--idg-border);
    border-radius: 2rem;
    background: var(--idg-card-bg);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: all var(--idg-transition);
    color: var(--idg-text);
}

.legend-toggle:hover {
    background: var(--idg-accent-light);
    border-color: var(--idg-accent);
}

.legend-toggle[aria-pressed="true"] {
    background: var(--idg-accent);
    color: white;
    border-color: var(--idg-accent);
}

.legend-toggle:focus-visible {
    outline: 2px solid var(--idg-accent);
    outline-offset: 2px;
}

/* ========================================
   11. VIEWER - Discovery Counter
   ======================================== */

.discovery-counter {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: var(--idg-controls-z);
    background: var(--idg-card-bg);
    border: 1px solid var(--idg-border);
    border-radius: 2rem;
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--idg-accent);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.discovery-counter-icon {
    font-size: 1rem;
}

.discovery-counter.complete {
    background: var(--idg-accent-light);
    border-color: var(--idg-accent);
    animation: idg-celebrate 0.5s ease;
}

/* ========================================
   12. TIMELINE MODE
   ======================================== */

.timeline-nav {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--idg-bg);
    border-top: 1px solid var(--idg-border);
    overflow-x: auto;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
}

.timeline-nav button {
    padding: 0.45rem 0.9rem;
    border: 2px solid var(--idg-border);
    border-radius: 2rem;
    background: var(--idg-card-bg);
    cursor: pointer;
    font-size: 0.82rem;
    font-family: inherit;
    font-weight: 600;
    color: var(--idg-text);
    white-space: nowrap;
    flex-shrink: 0;
    transition: all var(--idg-transition);
}

.timeline-nav button:hover {
    border-color: var(--idg-timeline-color);
    background: #FEF3C7;
}

.timeline-nav button.active {
    background: var(--idg-timeline-color);
    color: white;
    border-color: var(--idg-timeline-color);
}

.timeline-nav button:focus-visible {
    outline: 2px solid var(--idg-timeline-color);
    outline-offset: 2px;
}

/* ========================================
   13. MAP MODE
   ======================================== */

.region-highlight {
    transition: fill-opacity 0.2s, stroke 0.2s;
}

.region-highlight:hover,
.region-highlight.hover {
    fill-opacity: 0.7;
    stroke: var(--idg-map-color);
    stroke-width: 2;
}

.region-highlight.active {
    fill-opacity: 0.85;
    stroke: var(--idg-map-color);
    stroke-width: 3;
    filter: drop-shadow(0 0 4px rgba(59, 130, 246, 0.4));
}

.region-highlight.discovered {
    fill-opacity: 0.5;
}

/* ========================================
   14. SCIENCE MODE (hotspots & annotations)
   ======================================== */

.hotspot {
    cursor: pointer;
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--idg-accent);
    border: 2px solid white;
    box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.5);
    animation: idg-pulse 2s ease-in-out infinite;
    transform: translate(-50%, -50%);
    z-index: 20;
}

.hotspot:hover {
    transform: translate(-50%, -50%) scale(1.25);
}

.hotspot:focus-visible {
    outline: 2px solid var(--idg-accent-dark);
    outline-offset: 3px;
}

.hotspot.discovered {
    background: #9CA3AF;
    box-shadow: none;
    animation: none;
}

.annotation {
    position: absolute;
    background: var(--idg-card-bg);
    border: 1px solid var(--idg-border);
    border-radius: var(--idg-radius-sm);
    padding: 0.4rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--idg-text);
    box-shadow: var(--idg-shadow);
    pointer-events: none;
    white-space: nowrap;
    z-index: 15;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s, transform 0.2s;
}

.annotation.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ========================================
   15. ANIMATIONS
   ======================================== */

@keyframes idg-spin {
    to { transform: rotate(360deg); }
}

@keyframes idg-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.5); }
    70%  { box-shadow: 0 0 0 10px rgba(5, 150, 105, 0); }
    100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); }
}

@keyframes idg-celebrate {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.15); }
    100% { transform: scale(1); }
}

@keyframes idg-slide-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

@keyframes idg-slide-right {
    from { transform: translateX(100%); }
    to   { transform: translateX(0); }
}

/* ========================================
   16. ACCESSIBILITY
   ======================================== */

.diagram-card:focus-visible,
.diagram-hub-back:focus-visible,
.diagram-viewer-back:focus-visible,
.zoom-controls button:focus-visible,
.legend-toggle:focus-visible,
.timeline-nav button:focus-visible,
.info-panel-close:focus-visible,
.hotspot:focus-visible {
    outline-style: solid;
    outline-width: 2px;
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .hotspot {
        animation: none;
    }

    .discovery-counter.complete {
        animation: none;
    }

    .info-panel,
    .svg-container-inner,
    .diagram-card,
    .annotation {
        transition-duration: 0.01ms !important;
    }

    .diagram-loading-spinner {
        animation-duration: 1.5s;
    }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ========================================
   17. RESPONSIVE (mobile)
   ======================================== */

@media (max-width: 768px) {
    .diagram-hub {
        padding: 1rem 0.75rem 2rem;
    }

    .diagram-hub-header h1 {
        font-size: 1.3rem;
    }

    .diagram-grid {
        grid-template-columns: 1fr;
    }

    .diagram-filters {
        gap: 0.5rem;
    }

    .diagram-filter-select {
        font-size: 0.82rem;
        padding: 0.4rem 0.75rem;
        padding-right: 1.75rem;
    }

    .diagram-viewer-header {
        padding: 0.6rem 1rem;
    }

    .diagram-viewer-header h1 {
        font-size: 1rem;
    }

    .zoom-controls {
        bottom: 0.75rem;
        right: 0.75rem;
    }

    .zoom-controls button {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
    }

    .legend-toggle {
        font-size: 0.8rem;
        padding: 0.4rem 0.75rem;
    }

    .discovery-counter {
        font-size: 0.8rem;
        padding: 0.35rem 0.7rem;
    }

    .timeline-nav {
        padding: 0.6rem 1rem;
    }

    .timeline-nav button {
        font-size: 0.78rem;
        padding: 0.4rem 0.75rem;
    }

    .info-panel {
        max-height: 60vh;
        border-radius: 1.25rem 1.25rem 0 0;
    }

    .info-panel-header {
        padding: 1rem 1.25rem 0.5rem;
    }

    .info-panel-body {
        padding: 0 1.25rem 1.25rem;
    }
}

@media (max-width: 380px) {
    .diagram-hub-header h1 {
        font-size: 1.15rem;
    }

    .diagram-card {
        padding: 1rem;
    }

    .diagram-card-icon {
        font-size: 1.75rem;
    }
}

/* ========================================
   18. PRINT
   ======================================== */

@media print {
    .diagram-viewer-header,
    .zoom-controls,
    .legend-toggle,
    .discovery-counter,
    .timeline-nav,
    .diagram-filters,
    .diagram-hub-back {
        display: none !important;
    }

    .diagram-viewer {
        position: static;
    }

    .svg-container {
        overflow: visible;
        page-break-inside: avoid;
    }

    .info-panel {
        position: static;
        transform: none;
        box-shadow: none;
        border: 1px solid #ccc;
        max-height: none;
        page-break-inside: avoid;
    }
}
