/* =============================================================
   BricoUp Blog - Responsive CSS
   Améliorations responsive pour mobile, tablette et desktop
   ============================================================= */

/* ─── BASE RESET MOBILE ─── */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* Empêcher le scroll horizontal global */
body, html {
    max-width: 100vw;
    overflow-x: hidden;
}

/* ─── TOUCH TARGETS ─── */
/* Taille minimale 44px pour tous les éléments interactifs sur mobile */
@media (max-width: 767px) {
    a, button, input[type="submit"], .category-pill, .topic-card, .sommaire-link {
        min-height: 44px;
    }
    
    .category-pill {
        padding: 0.625rem 1rem;
    }
}

/* ─── HEADER / NAVIGATION ─── */
/* Menu mobile amélioré */
#mobileMenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 0;
}

#mobileMenu.open {
    max-height: 300px;
    opacity: 1;
    padding-bottom: 1rem;
}

/* Empêcher le flash du menu au chargement */
#mobileMenu.hidden {
    display: block !important;
    max-height: 0;
    opacity: 0;
    padding-bottom: 0;
    overflow: hidden;
}

@media (min-width: 768px) {
    #mobileMenu,
    #mobileMenu.hidden {
        display: none !important;
    }
}

/* Animation du bouton hamburger */
#mobileMenuBtn svg {
    transition: transform 0.3s ease;
}

#mobileMenuBtn.active svg {
    transform: rotate(90deg);
}

/* Liens du menu mobile - zones de touch étendues */
@media (max-width: 767px) {
    #mobileMenu a {
        padding: 0.75rem 1rem;
        font-size: 1rem;
        border-radius: 0.5rem;
    }
}

/* Barre de recherche responsive */
@media (max-width: 639px) {
    #searchBar .relative {
        width: 100%;
    }
    
    #searchBar input {
        font-size: 16px; /* Empêche le zoom auto iOS */
        padding: 0.75rem 3rem 0.75rem 1rem;
    }
}

/* ─── HERO SECTION ─── */
@media (max-width: 639px) {
    .hero-gradient {
        padding-top: 2rem;
        padding-bottom: 2rem;
    }
    
    .hero-gradient h1 {
        font-size: 1.875rem !important;
        line-height: 1.2;
    }
    
    .hero-gradient p {
        font-size: 1rem;
    }
    
    .hero-gradient .flex-wrap {
        flex-direction: column;
        width: 100%;
    }
    
    .hero-gradient .flex-wrap a {
        width: 100%;
        justify-content: center;
    }
}

/* ─── CATÉGORIES (PILLS) ─── */
/* Sur mobile : scroll horizontal au lieu de wrap */
@media (max-width: 767px) {
    .categories-scroll {
        display: flex;
        overflow-x: auto;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        flex-wrap: nowrap !important;
        scroll-snap-type: x mandatory;
    }
    
    .categories-scroll::-webkit-scrollbar {
        display: none;
    }
    
    .categories-scroll .category-pill {
        white-space: nowrap;
        flex-shrink: 0;
        scroll-snap-align: start;
    }
    
    /* Indicateur de scroll (fade sur le bord droit) */
    .categories-container {
        position: relative;
    }
    
    .categories-container::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 3rem;
        background: linear-gradient(to right, transparent, white);
        pointer-events: none;
        z-index: 1;
    }
}

/* ─── ARTICLE À LA UNE (FEATURED) ─── */
@media (max-width: 767px) {
    .featured-card .grid {
        grid-template-columns: 1fr;
    }
    
    .featured-card .aspect-video {
        min-height: 200px;
    }
    
    .featured-card .p-8,
    .featured-card .p-10 {
        padding: 1.25rem;
    }
    
    .featured-card h3 {
        font-size: 1.25rem !important;
    }
}

/* ─── GRILLE D'ARTICLES ─── */
@media (max-width: 639px) {
    .articles-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

@media (min-width: 640px) and (max-width: 767px) {
    .articles-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
}

/* Cards d'articles - ajustements mobile */
@media (max-width: 639px) {
    .article-card {
        padding-bottom: 0.5rem;
    }
    
    .article-card h3 {
        font-size: 1rem;
    }
    
    .article-card .aspect-video {
        aspect-ratio: 16/10;
    }
}

/* ─── NEWSLETTER ─── */
@media (max-width: 639px) {
    #newsletter h2 {
        font-size: 1.5rem !important;
    }
    
    #newsletter p {
        font-size: 0.9375rem;
    }
    
    #newsletter form {
        flex-direction: column;
    }
    
    #newsletter input,
    #newsletter button {
        width: 100%;
        font-size: 16px; /* Empêche zoom iOS */
    }
}

/* ─── THÈMES POPULAIRES ─── */
@media (max-width: 639px) {
    .topics-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .topic-card {
        padding: 1rem;
    }
    
    .topic-card span:first-child {
        font-size: 1.5rem;
    }
    
    .topic-card .font-semibold {
        font-size: 0.8125rem;
    }
}

/* ─── CTA PLATFORM ─── */
@media (max-width: 767px) {
    .cta-platform {
        padding: 1.5rem !important;
    }
    
    .cta-platform .grid {
        grid-template-columns: 1fr;
    }
    
    .cta-platform h2 {
        font-size: 1.375rem;
    }
}

/* ─── FOOTER ─── */
@media (max-width: 639px) {
    footer .grid {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    footer .col-span-2 {
        grid-column: span 1;
    }
    
    footer .flex-col.md\\:flex-row {
        text-align: center;
    }
}

@media (min-width: 640px) and (max-width: 767px) {
    footer .grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ═══════════════════════════════════════════════════
   ARTICLE PAGE - RESPONSIVE
   ═══════════════════════════════════════════════════ */

/* ─── SOMMAIRE MOBILE (Slide-in Panel) ─── */
.sommaire-mobile-btn {
    display: none;
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #8a5a44, #6d4636);
    color: white;
    border: none;
    border-radius: 1rem;
    cursor: pointer;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(138, 90, 68, 0.4);
    transition: all 0.3s ease;
    align-items: center;
    justify-content: center;
}

.sommaire-mobile-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(138, 90, 68, 0.5);
}

.sommaire-mobile-btn:active {
    transform: scale(0.95);
}

.sommaire-mobile-btn .badge-count {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #f97316;
    border-radius: 50%;
    font-size: 0.6875rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

@media (max-width: 1023px) {
    .sommaire-mobile-btn {
        display: flex;
    }
}

/* Overlay + Panel */
.sommaire-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.sommaire-overlay.open {
    opacity: 1;
    visibility: visible;
}

.sommaire-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 75vh;
    background: white;
    border-radius: 1.5rem 1.5rem 0 0;
    z-index: 1002;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
}

.sommaire-panel.open {
    transform: translateY(0);
}

/* Poignée du panel */
.sommaire-panel-handle {
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 0.75rem auto;
}

.sommaire-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem 1rem;
    border-bottom: 1px solid #e5e7eb;
}

.sommaire-panel-content {
    padding: 1rem 1.5rem 2rem;
}

.sommaire-panel .sommaire-link {
    padding: 0.75rem 1rem;
    font-size: 0.9375rem;
    min-height: 44px;
    display: flex;
    align-items: center;
}

/* ─── TABLES RESPONSIVE ─── */
/* Conversion des tables en cards sur mobile */
@media (max-width: 767px) {
    .context-table,
    .context-table thead,
    .context-table tbody,
    .context-table tr,
    .context-table th,
    .context-table td {
        display: block;
    }
    
    .context-table thead {
        display: none;
    }
    
    .context-table tr {
        background: white;
        margin-bottom: 1rem;
        border-radius: 0.75rem;
        border: 1px solid #e5e7eb;
        overflow: hidden;
    }
    
    .context-table td {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid #f3f4f6;
        position: relative;
    }
    
    .context-table td:first-child {
        background: linear-gradient(135deg, #fef9f6, #fff7ed);
        font-weight: 600;
        font-size: 1rem;
        padding: 1rem;
        border-bottom: 2px solid #f97316;
    }
    
    .context-table td:nth-child(2)::before {
        content: 'Spécificités';
        display: block;
        font-weight: 600;
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: #8a5a44;
        margin-bottom: 0.25rem;
    }
    
    .context-table td:nth-child(3)::before {
        content: 'Fiches associées';
        display: block;
        font-weight: 600;
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: #8a5a44;
        margin-bottom: 0.5rem;
    }
    
    .context-table td:last-child {
        border-bottom: none;
    }
    
    /* Comparison table mobile */
    .comparison-table,
    .comparison-table thead,
    .comparison-table tbody,
    .comparison-table tr,
    .comparison-table th,
    .comparison-table td {
        display: block;
    }
    
    .comparison-table thead {
        display: none;
    }
    
    .comparison-table tr {
        margin-bottom: 0.75rem;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        overflow: hidden;
    }
    
    .comparison-table td {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid #f3f4f6;
    }
    
    .comparison-table td:first-child {
        background: #f8f9fa;
        font-weight: 600;
    }
    
    .comparison-table td:nth-child(2)::before {
        content: 'DIY : ';
        font-weight: 600;
        color: #8a5a44;
    }
    
    .comparison-table td:nth-child(3)::before {
        content: 'Pro : ';
        font-weight: 600;
        color: #8a5a44;
    }
    
    .comparison-table td:last-child {
        border-bottom: none;
    }
}

/* ─── DOMAIN CARDS ─── */
@media (max-width: 639px) {
    .domain-card {
        padding: 1.25rem;
        border-radius: 0.75rem;
    }
    
    .domain-card h3 {
        font-size: 1.125rem;
    }
    
    .domain-card .prose p {
        font-size: 0.9375rem;
        line-height: 1.6;
    }
}

/* ─── FICHE LINKS ─── */
@media (max-width: 639px) {
    .fiche-link {
        font-size: 0.875rem;
        padding: 0.75rem 1rem;
        width: 100%;
    }
    
    .flex-wrap .fiche-link {
        flex-basis: 100%;
    }
}

/* ─── ARTICLE HEADER ─── */
@media (max-width: 639px) {
    .article-header h1 {
        font-size: 1.75rem !important;
        line-height: 1.2;
    }
    
    .article-header p {
        font-size: 0.9375rem;
    }
    
    .level-badge {
        font-size: 0.8125rem;
        padding: 0.375rem 0.75rem;
    }
}

/* ─── BREADCRUMB ─── */
@media (max-width: 639px) {
    nav.breadcrumb {
        font-size: 0.8125rem;
    }
    
    nav.breadcrumb span:last-child {
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
        max-width: 200px;
    }
}

/* ─── AVANTAGES/INCONVÉNIENTS CARDS ─── */
@media (max-width: 639px) {
    .grid.md\\:grid-cols-2 {
        grid-template-columns: 1fr;
    }
}

/* ─── RESSOURCES SECTION ─── */
@media (max-width: 767px) {
    #ressources .grid {
        grid-template-columns: 1fr;
    }
    
    #ressources a {
        padding: 1rem;
    }
}

/* ─── ARTICLE FOOTER (différent du footer principal) ─── */
@media (max-width: 639px) {
    footer .grid.md\\:grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ═══════════════════════════════════════════════════
   ANIMATIONS & TRANSITIONS
   ═══════════════════════════════════════════════════ */

/* Réduire les animations sur mobile pour performance */
@media (max-width: 767px) {
    .animate-fadeInUp {
        animation-duration: 0.4s;
    }
    
    /* Désactiver les animations complexes si préférence utilisateur */
    @media (prefers-reduced-motion: reduce) {
        *, *::before, *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
}

/* ═══════════════════════════════════════════════════
   UTILITAIRES RESPONSIVE
   ═══════════════════════════════════════════════════ */

/* Safe area pour iPhone X+ (notch) */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .sommaire-mobile-btn {
        bottom: calc(1.5rem + env(safe-area-inset-bottom));
    }
    
    .sommaire-panel {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    footer {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Landscape mode adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    .hero-gradient {
        padding-top: 1rem;
        padding-bottom: 1rem;
    }
    
    .sommaire-panel {
        max-height: 90vh;
    }
}

/* Print styles */
@media print {
    header, footer, .sommaire-mobile-btn, .sommaire-overlay, .sommaire-panel,
    #newsletter, .cta-platform, #mobileMenuBtn, #searchToggle {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        color: black;
        background: white;
    }
    
    .domain-card {
        break-inside: avoid;
        border: 1px solid #ccc;
        box-shadow: none;
    }
    
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
    
    a[href^="#"]::after,
    a[href^="javascript"]::after {
        content: "";
    }
}

/* ═══════════════════════════════════════════════════
   FOCUS STYLES (Accessibilité)
   ═══════════════════════════════════════════════════ */

/* Focus visible pour navigation clavier */
:focus-visible {
    outline: 3px solid #f97316;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Supprimer l'outline pour les clics souris */
:focus:not(:focus-visible) {
    outline: none;
}

/* Skip link pour accessibilité */
.skip-link {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    background: #8a5a44;
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 0 0 0.5rem 0.5rem;
    z-index: 9999;
    font-weight: 600;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
}
