/*
 * Template: SoaiMadagasikara - CSS Mobile
 * Description: Styles optimisés pour mobile et tablette (Joomla 6.0)
 * Author: Votre Nom
 * Version: 2.0.0
 * Joomla: 6.0+ / Bootstrap: 5.3+
 */

/* =============================================
   MENU MOBILE HAMBURGER (Modernisé)
   ============================================= */
.menu-toggle {
    display: none;
    background: transparent;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    position: relative;
    width: 40px;
    height: 40px;
    margin: 0.5rem 0;
    z-index: 1001;
}

.menu-toggle span {
    display: block;
    height: 3px;
    width: 25px;
    background-color: var(--madagascar-green);
    margin: 5px auto;
    transition: var(--bs-transition);
    transform-origin: center;
    border-radius: 1px;
}

.menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -6px);
}

/* Navigation mobile moderne */
@media (max-width: 767px) {
    .menu-toggle {
        display: block;
        position: absolute;
        right: 1rem;
        top: 50%;
        transform: translateY(-50%);
        z-index: 1001;
    }
    
    /* Masquer le menu par défaut */
    .main-nav ul {
        display: none !important;
    }
    
    /* Afficher le menu quand actif - VERTICAL */
    .main-nav ul.active {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: linear-gradient(135deg, var(--madagascar-red) 0%, var(--madagascar-green) 100%);
        backdrop-filter: blur(20px);
        flex-direction: column !important; /* FORCE LA DIRECTION VERTICALE */
        justify-content: flex-start;
        align-items: stretch;
        padding-top: 80px;
        padding-bottom: 20px;
        overflow-y: auto;
        z-index: 1000;
        animation: slideInFromTop 0.3s ease-out;
    }
    
    .main-nav li {
        width: 100%;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        margin: 0 !important;
        background: transparent !important;
    }
    
    .main-nav a {
        padding: 1rem 2rem;
        font-size: 1.1rem;
        border-bottom: none;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        min-height: 50px;
        width: 100%;
        color: white !important;
        background: transparent !important;
    }
    
    /* Lien actif/courant - pas de fond blanc */
    .main-nav li.active,
    .main-nav li.current,
    .main-nav li[class*="active"],
    .main-nav li[class*="current"] {
        background: rgba(255, 255, 255, 0.2) !important;
    }
    
    .main-nav li.active a,
    .main-nav li.current a,
    .main-nav a[aria-current="page"],
    .main-nav a.active {
        background: transparent !important;
        color: white !important;
        font-weight: 600;
    }
    
    .main-nav a:hover {
        background: rgba(255, 255, 255, 0.15) !important;
        transform: translateX(10px);
    }
}

@keyframes slideInFromTop {
    from {
        opacity: 0;
        transform: translateY(-100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =============================================
   BOUTON RETOUR EN HAUT (Bootstrap 5.3)
   ============================================= */
.back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 3rem;
    height: 3rem;
    background-color: var(--bs-primary);
    color: var(--bs-white);
    border: none;
    border-radius: var(--bs-border-radius-2xl);
    font-size: 1.25rem;
    cursor: pointer;
    transition: var(--bs-transition);
    z-index: 1000;
    box-shadow: var(--bs-box-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-to-top:hover {
    background-color: var(--madagascar-green);
    transform: translateY(-3px);
    box-shadow: var(--bs-box-shadow-lg);
    color: var(--bs-white);
}

/* =============================================
   NOTIFICATIONS MODERNES
   ============================================= */
.notification {
    box-shadow: var(--bs-box-shadow);
    border-left: 4px solid rgba(255,255,255,0.3);
    border-radius: var(--bs-border-radius);
}

.notification-success {
    background-color: var(--bs-success);
    border-left-color: var(--bs-success);
}

.notification-error {
    background-color: var(--bs-danger);
    border-left-color: var(--bs-danger);
}

.notification-warning {
    background-color: var(--bs-warning);
    color: var(--bs-dark);
    border-left-color: var(--bs-warning);
}

.notification-info {
    background-color: var(--bs-info);
    border-left-color: var(--bs-info);
}

/* =============================================
   LAZY LOADING (Performance optimisée)
   ============================================= */
img.lazy {
    opacity: 0;
    transition: opacity 0.3s ease;
    filter: blur(5px);
}

img.lazy.fade-in {
    opacity: 1;
    filter: blur(0);
}

/* Loading placeholder */
img[loading="lazy"] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* =============================================
   AMÉLIORATIONS SUBMENU (Touch-friendly)
   ============================================= */
.navigation ul ul {
    transition: all 0.2s ease;
}

/* Touch optimizations */
@media (hover: none) and (pointer: coarse) {
    .main-nav li {
        position: relative;
    }
    
    .main-nav li > a::after {
        content: '+';
        position: absolute;
        right: 1rem;
        font-size: 1.2rem;
        transition: transform 0.2s ease;
    }
    
    .main-nav li.open > a::after {
        transform: rotate(45deg);
    }
    
    .main-nav a,
    .btn,
    .form-control {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    .btn {
        padding: 0.75rem 1rem;
    }
}

/* =============================================
   RESPONSIVE AVANCÉ
   ============================================= */

/* Header mobile optimisé */
@media (max-width: 767px) {
    .header {
        padding: 0.75rem 0;
        position: relative;
    }
    
    .header .container {
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
        padding: 0 1rem;
    }
    
    .logo h1 {
        font-size: 1.3rem;
        white-space: nowrap;
    }
    
    .logo h1 .title-green,
    .logo h1 .title-red {
        display: inline-block;
    }
    
    .header-modules,
    .search-modules {
        position: static;
        transform: none;
        margin: 0;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
}

/* Hero section mobile - Fix débordement */
@media (max-width: 767px) {
    .hero-section {
        padding: 2rem 1rem !important;
        min-height: auto !important;
        overflow: hidden;
    }
    
    .hero-section .container {
        max-width: 100%;
        padding: 0 1rem;
    }
    
    .hero-section h1 {
        font-size: 1.75rem !important;
        line-height: 1.3;
        margin-bottom: 1rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .hero-section h2 {
        font-size: 1.3rem !important;
        word-wrap: break-word;
    }
    
    .hero-section p {
        font-size: 0.95rem;
        line-height: 1.6;
        margin-bottom: 1.5rem;
    }
    
    .hero-section .btn {
        font-size: 0.9rem;
        padding: 0.75rem 1.5rem;
        width: 100%;
        margin-bottom: 0.75rem;
    }
}

/* Contenu mobile */
@media (max-width: 767px) {
    .main-content {
        padding: 1rem 0;
    }
    
    .top-positions,
    .bottom-positions {
        padding: 1rem 0;
    }
    
    .sidebar-left,
    .sidebar-right {
        margin-top: 2rem;
        background: var(--bs-light);
        padding: 1rem;
        border-radius: var(--bs-border-radius);
        border: 1px solid var(--bs-border-color);
    }
    
    .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .btn + .btn {
        margin-left: 0;
    }
    
    /* Typography mobile */
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
}

/* Tablettes (768px - 991px) */
@media (min-width: 768px) and (max-width: 991px) {
    .container {
        max-width: 720px;
    }
    
    .logo h1 {
        font-size: 1.75rem;
    }
    
    .navigation a {
        padding: 0.875rem 1.25rem;
    }
}

/* Touch optimizations */
@media (hover: none) and (pointer: coarse) {
    .navigation a,
    .btn,
    .form-control {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    .btn {
        padding: 0.75rem 1rem;
    }
}

/* Performance mobile */
@media (max-width: 767px) {
    * {
        transition-duration: 0.2s !important;
    }
    
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeSpeed;
    }
    
    html {
        scroll-behavior: auto;
    }
}

/* Mode sombre mobile */
@media (max-width: 767px) {
    [data-bs-theme="dark"] .sidebar-left,
    [data-bs-theme="dark"] .sidebar-right {
        background: var(--bs-dark);
        color: var(--bs-light);
        border-color: var(--bs-border-color);
    }
    
    [data-bs-theme="dark"] .menu-toggle span {
        background: var(--bs-light);
    }
}

/* Accessibilité mobile */
@media (max-width: 767px) {
    a:focus,
    button:focus,
    .btn:focus {
        outline: 3px solid var(--bs-primary);
        outline-offset: 2px;
    }
    
    .small-text {
        font-size: 1rem;
    }
}

/* Ultra petit écran (< 480px) */
@media (max-width: 479px) {
    .back-to-top {
        bottom: 1rem;
        right: 1rem;
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1rem;
    }
    
    .notification {
        right: 0.5rem;
        left: 0.5rem;
        padding: 0.75rem 1rem;
    }
    
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}