/**
 * UI Enhancements CSS
 * Modern, fast, user-friendly styles for MyOrder
 * 
 * Features:
 * - Dark Mode Support
 * - Glassmorphism
 * - Micro-animations
 * - Skeleton Loaders
 * - Better Touch Targets
 * - Fluid Typography
 */

/* ============================================
   CSS CUSTOM PROPERTIES (Light Mode Default)
   ============================================ */
:root {
    /* Colors */
    --color-primary: #6366f1;
    --color-primary-light: #818cf8;
    --color-primary-dark: #4f46e5;
    --color-secondary: #ec4899;
    --color-accent: #8b5cf6;
    
    /* Backgrounds */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --bg-hover: #f1f5f9;
    
    /* Text */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;
    
    /* Borders */
    --border-color: #e2e8f0;
    --border-light: #f1f5f9;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);
    
    /* Glass */
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(255, 255, 255, 0.2);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
    --transition-slow: 300ms ease;
    
    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
}

/* ============================================
   DARK MODE
   ============================================ */
.dark {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: #1e293b;
    --bg-input: #1e293b;
    --bg-hover: #334155;
    
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --border-color: #334155;
    --border-light: #1e293b;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
    
    --glass-bg: rgba(30, 41, 59, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
}

/* Apply theme colors */
.dark body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.dark .bg-white {
    background-color: var(--bg-card) !important;
}

.dark .bg-gray-50,
.dark .bg-gray-100 {
    background-color: var(--bg-secondary) !important;
}

.dark .text-gray-900,
.dark .text-gray-800 {
    color: var(--text-primary) !important;
}

.dark .text-gray-700,
.dark .text-gray-600 {
    color: var(--text-secondary) !important;
}

.dark .text-gray-500,
.dark .text-gray-400 {
    color: var(--text-muted) !important;
}

.dark .border-gray-200,
.dark .border-gray-300 {
    border-color: var(--border-color) !important;
}

.dark input,
.dark select,
.dark textarea {
    background-color: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

.dark input::placeholder,
.dark textarea::placeholder {
    color: var(--text-muted) !important;
}

/* ============================================
   GLASSMORPHISM
   ============================================ */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
}

.glass-strong {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.dark .glass-strong {
    background: rgba(30, 41, 59, 0.95);
}

/* ============================================
   MICRO-ANIMATIONS
   ============================================ */

/* Button press effect */
.btn-press,
button,
.btn,
[role="button"] {
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.btn-press:active,
button:active,
.btn:active,
[role="button"]:active {
    transform: scale(0.97);
}

/* Card hover lift */
.card-hover {
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.card-hover:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl);
}

/* Smooth link hover */
a {
    transition: color var(--transition-fast), opacity var(--transition-fast);
}

/* Input focus */
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary) !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

/* Fade animations */
.animate-fade-in {
    animation: fadeIn 0.3s ease-out;
}

.animate-fade-up {
    animation: fadeUp 0.3s ease-out;
}

.animate-fade-down {
    animation: fadeDown 0.3s ease-out;
}

.animate-scale-in {
    animation: scaleIn 0.2s ease-out;
}

.animate-bounce-in {
    animation: bounceIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.animate-slide-up {
    animation: slideUp 0.3s ease-out;
}

.animate-slide-down {
    animation: slideDown 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes bounceIn {
    0% { opacity: 0; transform: scale(0.3); }
    50% { transform: scale(1.05); }
    70% { transform: scale(0.9); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

/* Shimmer effect for skeletons */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.shimmer {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.dark .shimmer {
    background: linear-gradient(90deg, #334155 25%, #475569 50%, #334155 75%);
    background-size: 200% 100%;
}

/* Pulse glow */
@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 5px var(--color-primary); }
    50% { box-shadow: 0 0 20px var(--color-primary); }
}

.pulse-glow {
    animation: pulseGlow 2s infinite;
}

/* Success checkmark */
@keyframes checkmark {
    0% { stroke-dashoffset: 100; }
    100% { stroke-dashoffset: 0; }
}

.success-checkmark {
    stroke-dasharray: 100;
    animation: checkmark 0.5s ease-out forwards;
}

/* ============================================
   SKELETON LOADERS
   ============================================ */
.skeleton {
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-tertiary) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

.skeleton-card {
    border-radius: var(--radius-xl);
    overflow: hidden;
}

.skeleton-image {
    background: var(--bg-tertiary);
}

.skeleton-line {
    height: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

.skeleton-avatar {
    background: var(--bg-tertiary);
}

/* ============================================
   BETTER TOUCH TARGETS
   ============================================ */
@media (pointer: coarse) {
    /* Minimum 44x44px touch targets on touch devices */
    button,
    .btn,
    a,
    input[type="checkbox"],
    input[type="radio"],
    select {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Larger tap areas */
    .tap-target {
        position: relative;
    }
    
    .tap-target::after {
        content: '';
        position: absolute;
        top: -8px;
        left: -8px;
        right: -8px;
        bottom: -8px;
    }
}

/* ============================================
   FLUID TYPOGRAPHY
   ============================================ */
.text-fluid-xs {
    font-size: clamp(0.75rem, 2vw, 0.875rem);
}

.text-fluid-sm {
    font-size: clamp(0.875rem, 2.5vw, 1rem);
}

.text-fluid-base {
    font-size: clamp(1rem, 3vw, 1.125rem);
}

.text-fluid-lg {
    font-size: clamp(1.125rem, 3.5vw, 1.25rem);
}

.text-fluid-xl {
    font-size: clamp(1.25rem, 4vw, 1.5rem);
}

.text-fluid-2xl {
    font-size: clamp(1.5rem, 5vw, 2rem);
}

.text-fluid-3xl {
    font-size: clamp(1.875rem, 6vw, 2.5rem);
}

/* ============================================
   GRADIENT UTILITIES
   ============================================ */
.gradient-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
}

.gradient-text {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.gradient-border {
    border: 2px solid transparent;
    background: linear-gradient(var(--bg-card), var(--bg-card)) padding-box,
                linear-gradient(135deg, var(--color-primary), var(--color-secondary)) border-box;
}

/* ============================================
   PULL TO REFRESH
   ============================================ */
.ptr-indicator {
    transition: transform var(--transition-normal);
}

.ptr-spinner {
    transition: transform var(--transition-normal);
}

.ptr-spinner.ptr-ready {
    background: var(--color-primary);
}

.ptr-spinner.ptr-ready .ptr-icon {
    color: white;
}

/* ============================================
   BOTTOM SHEET
   ============================================ */
.bottom-sheet {
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
}

.dark .bottom-sheet {
    background-color: var(--bg-card);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
}

.dark .bottom-sheet .sheet-header {
    border-color: var(--border-color);
}

.dark .bottom-sheet .sheet-actions {
    border-color: var(--border-color);
}

/* ============================================
   iOS SAFE AREAS
   ============================================ */
@supports (padding: env(safe-area-inset-bottom)) {
    .safe-bottom {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .safe-top {
        padding-top: env(safe-area-inset-top);
    }
}

/* ============================================
   DYNAMIC VIEWPORT HEIGHT (iOS Fix)
   ============================================ */
@supports (height: 100dvh) {
    .h-screen-dynamic {
        height: 100dvh;
    }
    
    .min-h-screen-dynamic {
        min-height: 100dvh;
    }
    
    .max-h-screen-dynamic {
        max-height: 100dvh;
    }
}

/* Fallback for browsers without dvh support */
@supports not (height: 100dvh) {
    .h-screen-dynamic {
        height: 100vh;
        height: -webkit-fill-available;
    }
}

/* ============================================
   LOADING STATES
   ============================================ */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: var(--glass-bg);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   EMPTY STATES
   ============================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1.5rem;
    text-align: center;
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    background: var(--bg-secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
    font-size: 2rem;
    color: var(--text-muted);
}

.empty-state-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-state-description {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    max-width: 300px;
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 3px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Hide scrollbar but keep functionality */
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

/* ============================================
   FOCUS VISIBLE (Keyboard Navigation)
   ============================================ */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .no-print {
        display: none !important;
    }
    
    .dark {
        --bg-primary: #ffffff;
        --text-primary: #000000;
    }
}

/* ============================================
   INSTANT PAGE LOADER
   Shows immediately before JS loads
   ============================================ */
.page-loader {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.page-loader.hidden {
    opacity: 0;
    visibility: hidden;
}

.page-loader-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: loader-spin 0.8s linear infinite;
}

@keyframes loader-spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   CONTENT LOADING STATES
   ============================================ */
.content-loading {
    opacity: 0.5;
    pointer-events: none;
    user-select: none;
}

.content-loaded {
    animation: content-fade-in 0.3s ease forwards;
}

@keyframes content-fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   INSTANT CLICK FEEDBACK
   ============================================ */
.btn-tap,
button,
[role="button"],
a {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-tap:active,
button:active:not(:disabled),
[role="button"]:active {
    transform: scale(0.97);
    transition: transform 0.1s ease;
}

/* ============================================
   OPTIMIZED CARD HOVER
   GPU accelerated
   ============================================ */
.card-optimized {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

.card-optimized:hover {
    transform: translateY(-2px) translateZ(0);
}

/* ============================================
   FAST FADE TRANSITIONS
   ============================================ */
.fade-fast-enter {
    animation: fade-fast-in 0.15s ease forwards;
}

.fade-fast-exit {
    animation: fade-fast-out 0.15s ease forwards;
}

@keyframes fade-fast-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fade-fast-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ============================================
   REDUCED MOTION SUPPORT
   Accessibility for vestibular disorders
   ============================================ */
@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;
    }
}

.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
}

/* ============================================
   SWIPE ACTIONS
   ============================================ */
.swipe-item {
    position: relative;
    background: var(--bg-card);
    touch-action: pan-y;
}

.swipe-item::before,
.swipe-item::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.swipe-item::before {
    left: 0;
    background: #22c55e;
}

.swipe-item::after {
    right: 0;
    background: #ef4444;
}

.swipe-item.swipe-left-active::after,
.swipe-item.swipe-right-active::before {
    opacity: 1;
}

/* ============================================
   NETWORK STATUS BANNER
   ============================================ */
#network-status-banner .offline-banner i,
#network-status-banner .online-banner i {
    font-size: 14px;
}

/* ============================================
   BOTTOM NAV ENHANCEMENTS
   ============================================ */
.bottom-nav,
[data-bottom-nav] {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9990;
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav a.active,
[data-bottom-nav] a.active {
    color: var(--color-primary);
}

.bottom-nav a.active i,
[data-bottom-nav] a.active i {
    transform: scale(1.1);
}

/* ============================================
   TOUCH OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Mobile-specific styles */
    button,
    a,
    [role="button"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Disable hover effects on touch */
    .card:hover,
    button:hover {
        transform: none;
    }
}

/* ============================================
   LOADING SHIMMER (optimized)
   ============================================ */
.shimmer {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        var(--bg-secondary) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.2s ease-in-out infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================
   PULL TO REFRESH INDICATOR
   ============================================ */
.ptr-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-60px);
    z-index: 9999;
    transition: transform 0.2s ease;
}

.ptr-indicator.active {
    transform: translateX(-50%) translateY(20px);
}

.ptr-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   SKELETON WITH ARIA
   ============================================ */
[aria-busy="true"] .skeleton,
.skeleton-loading {
    pointer-events: none;
    user-select: none;
}

/* ============================================
   FASTER PAINT (GPU acceleration)
   ============================================ */
.gpu-accelerate {
    transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
}

/* ============================================
   CONTENT VISIBILITY (performance)
   ============================================ */
.content-visibility-auto {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}
