/* Anti-Flicker CSS for SMK Budi Bhakti Mandirangan Website */

/* Global anti-flicker rules */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Prevent repaints and reflows */
.sidebar-box {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
}

.sidebar-header {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
}

.sidebar-content {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
}

/* Login form specific fixes */
.login-form {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
}

.login-form input {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
    outline: none;
}

.login-form button {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
    outline: none;
}

/* Search form fixes */
.search-form {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
}

.search-form input {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
    outline: none;
}

.search-form button {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
    outline: none;
}

/* Info list fixes */
.info-list {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
}

.info-list li {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
}

.info-list a {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
    text-decoration: none;
    display: block;
}

/* Gallery fixes - Enhanced anti-flicker */
.gallery {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
    position: relative;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.gallery img {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
    opacity: 1 !important;
    transition: none !important;
    animation: none !important;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    width: 100%;
    height: auto;
    display: block;
    position: relative;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Banner fixes - Enhanced anti-flicker */
.banner {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
    position: relative;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    overflow: hidden;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.banner img {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
    opacity: 1 !important;
    transition: none !important;
    animation: none !important;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    width: 100%;
    height: auto;
    display: block;
    position: relative;
}

/* Language selector fixes */
.language-selector {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
}

/* Navigation fixes */
.nav-menu {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
}

.nav-menu li {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
}

.nav-menu a {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
    text-decoration: none;
    display: block;
}

/* Content area fixes */
.content {
    contain: layout style paint;
    will-change: auto;
    isolation: isolate;
}

/* Prevent text selection flickering */
::selection {
    background: rgba(255, 215, 0, 0.3);
}

::-moz-selection {
    background: rgba(255, 215, 0, 0.3);
}

/* Disable outline on focus to prevent flickering */
input:focus,
button:focus,
a:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.5);
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Prevent flickering during page load */
body {
    opacity: 1;
    visibility: visible;
}

/* Force GPU acceleration for smooth rendering */
.main-layout,
.sidebar-left,
.sidebar-right,
.content {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-perspective: 1000px;
    perspective: 1000px;
}

/* Specific fixes for image loading flicker */
img[src*="galeri"], img[src*="banner"], img[src*="berita"] {
    opacity: 1 !important;
    visibility: visible !important;
    transition: none !important;
    animation: none !important;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    image-rendering: auto;
    image-rendering: crisp-edges;
    image-rendering: -webkit-optimize-contrast;
}

/* Prevent reflow during image load */
.sidebar-box img {
    max-width: 100%;
    height: auto;
    width: 100%;
    display: block;
    opacity: 1 !important;
    transition: none !important;
}

/* Anti-flicker for onerror handlers */
img[onerror] {
    opacity: 1 !important;
    transition: none !important;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Stabilize layout during image loading */
.gallery, .banner {
    min-height: 80px;
    background: #f5f5f5;
    position: relative;
}

.gallery::before, .banner::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f5f5f5;
    z-index: -1;
}
