/**
 * UI/UX Improvements - Phase 1A (Safe Enhancements)
 * Date: 2026-02-11
 * Can be disabled via feature flags in config/features.php
 */

/* ==========================================================================
   1. Loading States & Feedback
   ========================================================================== */

/* Button Loading State */
.btn-with-loading {
    position: relative;
    transition: all 0.3s ease;
}

.btn-with-loading:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-with-loading .btn-loading-icon {
    margin-left: 8px;
}

/* Page Loading Indicator */
.page-loading-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #ff6b35 0%, #f89820 100%);
    z-index: 9999;
    animation: loading-progress 2s ease-in-out infinite;
}

@keyframes loading-progress {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* ==========================================================================
   2. Accessibility Enhancements (Invisible improvements)
   ========================================================================== */

/* Screen Reader Only Text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus Indicators (Better visibility) */
*:focus-visible {
    outline: 2px solid #ff6b35;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Skip Navigation Link */
.skip-navigation {
    position: absolute;
    top: -40px;
    left: 0;
    background: #ff6b35;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
    border-radius: 0 0 4px 0;
}

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

/* ==========================================================================
   3. Touch-Friendly Enhancements (Mobile)
   ========================================================================== */

/* Minimum Touch Target Size (44x44px per Apple HIG) */
@media (max-width: 768px) {
    .btn,
    .form-control,
    a.c-pointer,
    button {
        min-height: 44px;
        min-width: 44px;
    }

    /* Increase spacing between clickable elements */
    .btn + .btn {
        margin-left: 8px;
    }
}

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

/* ==========================================================================
   4. Performance Optimizations
   ========================================================================== */

/* Lazy Loaded Images - Fade In Effect */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Reduce Motion for Users Who Prefer It */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ==========================================================================
   5. Better Visual Feedback
   ========================================================================== */

/* Interactive Elements Hover States */
.btn,
.card,
a.c-pointer {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover:not(:disabled),
.card:hover,
a.c-pointer:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.btn:active:not(:disabled),
a.c-pointer:active {
    transform: translateY(0);
}

/* Add to Cart Success Feedback */
@keyframes added-to-cart {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

.cart-icon-pulse {
    animation: added-to-cart 0.4s ease;
}

/* ==========================================================================
   6. Form Improvements
   ========================================================================== */

/* Input Focus State */
.form-control:focus {
    border-color: #ff6b35;
    box-shadow: 0 0 0 0.2rem rgba(255, 107, 53, 0.25);
}

/* Required Field Indicator */
.form-group.required label::after {
    content: " *";
    color: #c40000;
}

/* Form Error States */
.form-control.is-invalid {
    border-color: #c40000;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23c40000'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23c40000' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.invalid-feedback {
    display: block;
    color: #c40000;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* ==========================================================================
   7. Notification Improvements
   ========================================================================== */

/* Toast Notifications */
.toast-notification {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    animation: slide-up 0.3s ease;
}

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

.toast-notification.success {
    border-left: 4px solid #067d62;
}

.toast-notification.error {
    border-left: 4px solid #c40000;
}

.toast-notification.warning {
    border-left: 4px solid #f89820;
}

/* ==========================================================================
   8. Mobile-Specific Improvements
   ========================================================================== */

@media (max-width: 768px) {
    /* Prevent Text Size Adjustment on iOS */
    html {
        -webkit-text-size-adjust: 100%;
    }

    /* Remove tap highlight on iOS */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    /* Sticky Elements on Mobile */
    .sticky-mobile {
        position: sticky;
        top: 60px; /* Below header */
        z-index: 100;
        background: white;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
}

/* ==========================================================================
   9. Better Typography
   ========================================================================== */

/* Improve Readability */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Prevent Orphans */
p {
    text-wrap: pretty; /* Modern browsers */
}

/* ==========================================================================
   10. Print Styles (Bonus)
   ========================================================================== */

@media print {
    .no-print,
    header,
    footer,
    .btn,
    .cart-icon {
        display: none !important;
    }

    body {
        font-size: 12pt;
        color: black;
        background: white;
    }

    a[href]::after {
        content: " (" attr(href) ")";
    }
}

/* ==========================================================================
   11. Dark Mode Support (Future-Ready)
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    /* Only apply if user hasn't chosen light mode explicitly */
    body:not([data-theme="light"]) {
        /* Will be implemented in Phase 2 */
    }
}

/* ==========================================================================
   12. Cart Pulse Animation (When Item Added)
   ========================================================================== */

@keyframes cart-pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

.cart-pulse {
    animation: cart-pulse 0.6s ease-in-out;
}

/* ==========================================================================
   13. Toast Notifications
   ========================================================================== */

.toast-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    max-width: 350px;
    opacity: 0;
    transform: translateX(400px);
    transition: all 0.3s ease-in-out;
    font-size: 14px;
    font-weight: 500;
}

.toast-notification.show {
    opacity: 1;
    transform: translateX(0);
}

.toast-success {
    background-color: #067d62;
    color: white;
}

.toast-error {
    background-color: #c40000;
    color: white;
}

.toast-warning {
    background-color: #f89820;
    color: white;
}

.toast-info {
    background-color: #007185;
    color: white;
}

/* ==========================================================================
   14. Lazy Loading Image Fade-In
   ========================================================================== */

img.lazyload {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

img.lazyloaded {
    opacity: 1;
}

/* ==========================================================================
   15. Keyboard Navigation Enhancements
   ========================================================================== */

body.keyboard-nav *:focus {
    outline: 2px solid #ff6b35 !important;
    outline-offset: 2px !important;
}

/* Hide focus outline when using mouse */
body:not(.keyboard-nav) *:focus {
    outline: none;
}
