/* ============================================
   BUG FIXES AND UX POLISH
   ============================================ */

/* Fix: Better focus states for accessibility */
*:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
}

/* Fix: Ensure mobile menu toggle is visible */
@media (max-width: 992px) {
    .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
}

/* Fix: Better modal accessibility - focus trap */
.modal[style*="display: flex"],
.popup[style*="display: flex"] {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
}

/* Fix: Improve color contrast for accessibility */
@media (prefers-color-scheme: light) {
    .text-gray-400,
    .text-gray-300 {
        color: #4a5568 !important;
    }
}

[data-theme="light"] .text-gray-400,
[data-theme="light"] .text-gray-300 {
    color: #4a5568 !important;
}

/* Fix: Better loading states */
.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--color-accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spinner 0.6s linear infinite;
}

@keyframes spinner {
    to { transform: rotate(360deg); }
}

/* Fix: Better error states */
.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.success-message {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: #22c55e;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
}

/* Fix: Better image loading */
img {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
}

img.loaded {
    background: none;
}

/* Fix: Smooth transitions for theme switching */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Fix: Better button states */
button:disabled,
.btn-primary:disabled,
.btn-outline:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button:active:not(:disabled),
.btn-primary:active:not(:disabled),
.btn-outline:active:not(:disabled) {
    transform: scale(0.98);
}

/* Fix: Better form validation states */
input:invalid:not(:placeholder-shown),
textarea:invalid:not(:placeholder-shown),
select:invalid:not(:placeholder-shown) {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.05);
}

input:valid:not(:placeholder-shown),
textarea:valid:not(:placeholder-shown),
select:valid:not(:placeholder-shown) {
    border-color: var(--color-accent);
    background: rgba(0, 230, 118, 0.05);
}

/* Fix: Better portfolio filter active state */
.portfolio-filters button.active {
    background: var(--color-accent) !important;
    color: var(--color-dark) !important;
    border-color: var(--color-accent) !important;
    box-shadow: 0 4px 12px rgba(0, 230, 118, 0.3);
}

/* Fix: Prevent layout shift on image load */
.portfolio-image,
.team-image,
.product-image {
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

/* Fix: Better skeleton loading */
.skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.1) 25%,
        rgba(255, 255, 255, 0.2) 50%,
        rgba(255, 255, 255, 0.1) 75%
    );
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
}

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

/* Fix: Better scroll behavior */
html {
    scroll-behavior: smooth;
    scroll-padding-top: 80px; /* Account for fixed navbar */
}

/* Fix: Prevent text selection on buttons */
button,
.btn-primary,
.btn-outline,
.service-card,
.portfolio-item {
    user-select: none;
    -webkit-user-select: none;
}

/* Fix: Better hover states */
.service-card,
.portfolio-item,
.testimonial-card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.service-card:hover,
.portfolio-item:hover,
.testimonial-card:hover {
    transform: translateY(-4px);
}

/* Fix: Better mobile overlay */
.mobile-menu-overlay {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Fix: Better modal backdrop */
.modal,
.popup {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Fix: Ensure admin panel is accessible */
.admin-panel {
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Fix: Better notification positioning */
.notification {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 10000;
    min-width: 300px;
    max-width: 400px;
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Fix: Better calculator button states */
.calc-option.selected {
    background: var(--color-accent) !important;
    color: var(--color-dark) !important;
    border-color: var(--color-accent) !important;
}

/* Fix: Smooth page transitions */
@media (prefers-reduced-motion: no-preference) {
    .page-transition {
        animation: fadeIn 0.3s ease-in;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Fix: Better print styles */
@media print {
    .navbar,
    .footer,
    .admin-login,
    .scroll-to-top,
    .mobile-menu-overlay,
    .modal-overlay {
        display: none !important;
    }
}

/* Fix: High contrast mode support */
@media (prefers-contrast: high) {
    * {
        border-width: 2px !important;
    }

    button,
    .btn-primary,
    .btn-outline {
        border: 2px solid currentColor !important;
    }
}

/* Fix: Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Fix: Better touch feedback */
@media (hover: none) and (pointer: coarse) {
    button:active,
    .btn-primary:active,
    .btn-outline:active {
        opacity: 0.8;
    }
}

/* Fix: Prevent FOUC (Flash of Unstyled Content) */
.fonts-loading {
    opacity: 0;
}

.fonts-loaded {
    opacity: 1;
    transition: opacity 0.3s ease-in;
}

/* Fix: Better range slider styling */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: var(--glass-bg);
    border-radius: 4px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--color-accent);
    border-radius: 50%;
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--color-accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}
