/* Arabic RTL Support and Custom Styles for Potato Seeds Reservation System */

/* RTL specific adjustments */
[dir="rtl"] .space-x-reverse > * + * {
    margin-left: 0.5rem;
    margin-right: 0;
}

[dir="rtl"] .space-x-4.space-x-reverse > * + * {
    margin-left: 1rem;
    margin-right: 0;
}

[dir="rtl"] .space-x-6.space-x-reverse > * + * {
    margin-left: 1.5rem;
    margin-right: 0;
}

/* Arabic font optimization */
body {
    font-family: 'Tajawal', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
}

/* Navigation active state */
.nav-btn.active {
    background-color: rgba(34, 197, 94, 0.2);
    border: 2px solid rgba(34, 197, 94, 0.3);
}

/* Custom animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in-up {
    animation: fadeInUp 0.6s ease-out forwards;
}

/* Custom form styles */
.form-input {
    transition: all 0.3s ease;
    border: 2px solid #e5e7eb;
}

.form-input:focus {
    border-color: #10b981;
    outline: none;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.form-input.error {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* Custom buttons */
.btn-primary {
    background: linear-gradient(135deg, #10b981, #059669);
    transition: all 0.3s ease;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #059669, #047857);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(16, 185, 129, 0.3);
}

.btn-secondary {
    background: linear-gradient(135deg, #6b7280, #4b5563);
    color: white;
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #4b5563, #374151);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(107, 114, 128, 0.3);
}

/* Variety cards */
.variety-card {
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.variety-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
    border-color: #10b981;
}

.variety-card.selected {
    border-color: #10b981;
    background: linear-gradient(135deg, #f0fdf4, #dcfce7);
}

/* Quantity controls */
.quantity-control {
    display: flex;
    align-items: center;
    background: #f9fafb;
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
    overflow: hidden;
}

.quantity-btn {
    background: #10b981;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.quantity-btn:hover {
    background: #059669;
}

.quantity-btn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.quantity-input {
    border: none;
    background: transparent;
    text-align: center;
    width: 4rem;
    padding: 0.5rem;
    font-weight: 600;
}

/* Cart summary */
.cart-summary {
    background: linear-gradient(135deg, #f0fdf4, #dcfce7);
    border: 2px solid #10b981;
    border-radius: 1rem;
    padding: 1.5rem;
    margin-top: 2rem;
}

/* Status badges */
.status-pending {
    background: #fef3c7;
    color: #92400e;
}

.status-approved {
    background: #d1fae5;
    color: #065f46;
}

.status-rejected {
    background: #fee2e2;
    color: #991b1b;
}

.status-delivered {
    background: #dbeafe;
    color: #1e40af;
}

/* Progress steps */
.progress-step {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
}

.progress-step.active .step-circle {
    background: #10b981;
    color: white;
}

.progress-step.completed .step-circle {
    background: #059669;
    color: white;
}

.step-circle {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: #e5e7eb;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-left: 1rem;
}

/* Loading states */
.loading {
    position: relative;
    overflow: hidden;
}

.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
    animation: shimmer 1.5s infinite;
}

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

/* PWA & Mobile-First Styles */

/* Mobile responsiveness */
@media (max-width: 768px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    .grid {
        grid-template-columns: 1fr;
    }
    
    .text-4xl {
        font-size: 1.5rem;
        line-height: 1.3;
    }
    
    .text-3xl {
        font-size: 1.35rem;
        line-height: 1.3;
    }
    
    .text-2xl {
        font-size: 1.25rem;
        line-height: 1.3;
    }
    
    .text-xl {
        font-size: 1.125rem;
        line-height: 1.3;
    }
    
    .hidden-mobile {
        display: none;
    }
    
    /* Header optimization for mobile */
    header {
        padding-top: 0.75rem !important;
        padding-bottom: 0.75rem !important;
    }
    
    header h1 {
        font-size: 1.125rem !important;
        line-height: 1.3 !important;
    }
    
    header p {
        font-size: 0.75rem !important;
        display: none; /* Hide subtitle on very small screens */
    }
    
    header .bg-green-500 {
        padding: 0.5rem !important;
    }
    
    /* Navigation optimization */
    nav {
        height: auto !important;
        min-height: 48px !important;
    }
    
    nav .flex {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    
    nav .flex::-webkit-scrollbar {
        display: none;
    }
    
    nav button {
        white-space: nowrap;
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem !important;
    }
    
    /* Mobile-optimized tables */
    table {
        font-size: 0.75rem;
    }
    
    table th, table td {
        padding: 0.5rem !important;
    }
    
    /* Mobile-friendly buttons */
    button, .btn {
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
        font-size: 0.875rem;
    }
    
    /* Modals on mobile */
    .fixed .rounded-lg {
        max-width: 95vw;
        max-height: 85vh;
        margin: 1rem;
    }
    
    .fixed .max-w-4xl {
        max-width: 95vw !important;
    }
    
    .fixed .max-w-2xl {
        max-width: 95vw !important;
    }
    
    /* Card optimization */
    .rounded-xl, .rounded-lg {
        border-radius: 0.5rem !important;
    }
    
    /* Spacing optimization */
    .space-y-6 > * + * {
        margin-top: 1rem !important;
    }
    
    .space-y-4 > * + * {
        margin-top: 0.75rem !important;
    }
    
    /* Form inputs */
    input, select, textarea {
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
    
    /* Stats cards */
    .grid.grid-cols-4 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem !important;
    }
}

/* PWA-specific styles */
@media (display-mode: standalone) {
    /* Hide browser-specific elements when running as PWA */
    .external-link-icon {
        display: none;
    }
    
    /* Add safe area padding for notched devices */
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* Touch-optimized interactions */
@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets */
    a, button, input, select, textarea {
        min-height: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .hover\:bg-green-700:hover,
    .hover\:bg-blue-700:hover {
        transform: none;
    }
    
    /* Add active states instead */
    button:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
}

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

.animate-slide-up {
    animation: slide-up 0.5s ease-out;
}

/* Landscape mode optimizations for mobile */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }
    
    nav {
        height: auto;
        min-height: 48px;
    }
}

/* High-DPI screens optimization */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Crisp icons and text */
    * {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Reduced 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;
    }
}

/* Accessibility improvements */
.focus-visible:focus {
    outline: 2px solid #10b981;
    outline-offset: 2px;
}

/* Error states */
.error-message {
    background: #fee2e2;
    color: #991b1b;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid #fecaca;
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

.success-message {
    background: #d1fae5;
    color: #065f46;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid #a7f3d0;
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

/* Custom scrollbar for webkit browsers */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ===== MOBILE-SPECIFIC IMPROVEMENTS ===== */
/* Fix header overlap and spacing on mobile */
@media (max-width: 640px) {
    /* Prevent header elements overlap */
    .max-w-7xl {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
    
    /* Ensure headers don't overflow */
    body {
        overflow-x: hidden;
    }
    
    /* Make sure admin/distributor headers are sticky and visible */
    .bg-white.shadow-sm.border-b {
        position: sticky !important;
        top: 0 !important;
        z-index: 999 !important;
        background-color: white !important;
    }
    
    /* Force smaller elements on mobile - override Tailwind */
    .flex.justify-between.items-center {
        flex-wrap: nowrap !important;
        gap: 0.25rem !important;
    }
    
    /* Force smaller buttons on mobile */
    .flex.items-center button {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
        padding-top: 0.5rem !important;
        padding-bottom: 0.5rem !important;
        font-size: 0.75rem !important;
    }
    
    /* Smaller font sizes for mobile */
    h1 {
        font-size: 0.75rem !important;
        line-height: 1rem !important;
        max-width: 100px !important;
    }
    
    h2 {
        font-size: 0.75rem !important;
        line-height: 1rem !important;
    }
    
    /* Compact buttons - target all buttons in header */
    .bg-white.shadow-sm.border-b button {
        padding: 0.5rem !important;
        font-size: 0.75rem !important;
        min-width: auto !important;
    }
    
    /* Hide button text, show only icons on mobile */
    .bg-white.shadow-sm.border-b button span {
        display: none !important;
    }
    
    /* Ensure icons are visible */
    .bg-white.shadow-sm.border-b button i {
        margin: 0 !important;
        font-size: 1rem !important;
    }
    
    /* Hide text labels on very small screens */
    .truncate {
        max-width: 100px;
    }
    
    /* Navigation buttons smaller text */
    .admin-nav-btn, .dist-nav-btn {
        font-size: 0.75rem !important;
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
    
    /* Table responsive */
    table {
        font-size: 0.75rem !important;
    }
    
    th, td {
        padding: 0.5rem 0.25rem !important;
    }
    
    /* Modal adjustments */
    .fixed > div {
        max-width: 95vw !important;
        margin: 0.5rem !important;
    }
    
    /* Input fields */
    input, select, textarea {
        font-size: 0.875rem !important;
        padding: 0.5rem !important;
    }
    
    /* Cards spacing */
    .variety-card {
        padding: 0.75rem !important;
    }
    
    /* Stats cards */
    .bg-white.rounded-lg.shadow {
        padding: 0.75rem !important;
    }
    
    /* Form groups */
    .space-y-6 {
        gap: 0.75rem !important;
    }
    
    /* Prevent text wrapping issues */
    .whitespace-nowrap {
        font-size: 0.75rem !important;
    }
}

/* Extra small screens (< 380px) */
@media (max-width: 380px) {
    /* Even more compact */
    h1 {
        font-size: 0.75rem !important;
    }
    
    button {
        padding: 0.5rem 0.375rem !important;
    }
    
    /* Hide greeting text */
    span.text-gray-700 {
        display: none !important;
    }
    
    /* Logout button icon only */
    .fa-sign-out-alt {
        margin: 0 !important;
    }
}