/* Main Application Styles */

/* Base Styles */
body {
    font-family: 'Cairo', Tahoma, Arial, sans-serif;
    direction: rtl;
    text-align: right;
}

/* Sidebar Overlay for Mobile */
#sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    -webkit-tap-highlight-color: transparent;
}

#sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Sidebar Styles */
#sidebar {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Desktop Sidebar - Optimized Design */
@media (min-width: 1024px) {
    /* Sidebar container */
    #sidebar {
        width: 13rem; /* 208px - w-52 */
        max-width: 13rem;
    }
    
    /* Main Content - Ensure proper spacing from fixed sidebar */
    #main-content {
        margin-right: 13rem !important; /* Match sidebar width */
        width: calc(100% - 13rem);
        min-height: 100vh;
    }
    
    /* Navigation area - only scroll if content overflows */
    #sidebar nav {
        overflow-y: auto;
        overflow-x: hidden;
        max-height: calc(100vh - 200px); /* Account for logo and user sections */
        scrollbar-width: thin;
        scrollbar-color: rgba(156, 163, 175, 0.3) transparent;
    }
    
    /* Custom scrollbar for webkit browsers */
    #sidebar nav::-webkit-scrollbar {
        width: 4px;
    }
    
    #sidebar nav::-webkit-scrollbar-track {
        background: transparent;
    }
    
    #sidebar nav::-webkit-scrollbar-thumb {
        background-color: rgba(156, 163, 175, 0.3);
        border-radius: 2px;
    }
    
    #sidebar nav::-webkit-scrollbar-thumb:hover {
        background-color: rgba(156, 163, 175, 0.5);
    }
    
    /* Hide scrollbar when not hovering over sidebar */
    #sidebar:not(:hover) nav {
        scrollbar-width: none;
    }
    
    #sidebar:not(:hover) nav::-webkit-scrollbar {
        display: none;
    }
    
    /* Ensure no horizontal scroll */
    #sidebar * {
        max-width: 100%;
        word-wrap: break-word;
    }
    
    /* Logo section - compact */
    #sidebar > div > div:first-child {
        padding: 1rem 1.25rem;
        min-height: auto;
    }
    
    /* User section - compact */
    #sidebar > div > div:last-child {
        padding: 0.625rem 1rem;
        min-height: auto;
    }
}

/* Force sidebar to be hidden on mobile by default */
@media (max-width: 1023px) {
    #sidebar {
        transform: translateX(100%);
        -webkit-transform: translateX(100%);
    }
    
    #sidebar.sidebar-open,
    #sidebar:not(.-translate-x-full):not(.sidebar-closed) {
        transform: translateX(0) !important;
        -webkit-transform: translateX(0) !important;
    }
    
    #sidebar.-translate-x-full,
    #sidebar.sidebar-closed {
        transform: translateX(100%) !important;
        -webkit-transform: translateX(100%) !important;
    }
}

/* Ensure sidebar is visible on desktop */
@media (min-width: 1024px) {
    #sidebar {
        transform: translateX(0) !important;
        -webkit-transform: translateX(0) !important;
    }
    
    #sidebar.sidebar-closed {
        transform: translateX(0) !important;
        -webkit-transform: translateX(0) !important;
    }
}

/* Prevent body scroll when sidebar is open on mobile */
body.sidebar-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

/* Responsive Tables */
@media (max-width: 768px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table-responsive table {
        min-width: 600px;
    }
}

/* Touch-friendly buttons */
@media (max-width: 768px) {
    button, a.btn, .btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Mobile-First Responsive Design */
@media (max-width: 640px) {
    /* Sidebar on Mobile */
    #sidebar {
        width: 280px;
        max-width: 85vw;
        box-shadow: -4px 0 12px rgba(0, 0, 0, 0.15);
    }
    
    /* Mobile sidebar navigation */
    #sidebar nav {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Main Content Padding on Mobile */
    main {
        padding: 1rem !important;
    }
    
    /* Cards on Mobile */
    .card, .bg-white {
        border-radius: 0.75rem;
        margin-bottom: 1rem;
    }
    
    /* Forms on Mobile */
    input, select, textarea {
        font-size: 16px !important; /* Prevents zoom on iOS */
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }
    
    /* Select dropdown alignment fix */
    select {
        display: inline-block;
        vertical-align: middle;
        line-height: 1.5;
    }
    
    select option {
        padding: 0.5rem;
        line-height: 1.5;
        display: block;
    }
    
    /* Tables become scrollable on mobile */
    .table-responsive {
        margin: 0 -1rem;
        padding: 0 1rem;
    }
    
    /* Header on Mobile */
    header {
        padding: 0.75rem 1rem !important;
    }
    
    /* Top Bar Title */
    header h2 {
        font-size: 1rem !important;
        margin-right: 0.5rem !important;
    }
    
    /* Sidebar Toggle Button */
    #sidebar-toggle {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Navigation Links on Mobile */
    nav a {
        padding: 0.875rem 1rem !important;
        font-size: 0.9375rem;
        -webkit-tap-highlight-color: rgba(59, 130, 246, 0.1);
    }
    
    /* Buttons on Mobile */
    button, .btn, a.btn {
        padding: 0.875rem 1.25rem !important;
        font-size: 0.9375rem !important;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Alerts on Mobile */
    .alert {
        padding: 0.875rem 1rem !important;
        font-size: 0.875rem;
    }
    
    /* Badges on Mobile */
    .badge {
        font-size: 0.6875rem;
        padding: 0.25rem 0.5rem;
    }
    
    /* Grid adjustments for mobile */
    .grid {
        gap: 1rem !important;
    }
    
    /* Spacing adjustments */
    .space-y-6 > * + * {
        margin-top: 1rem !important;
    }
    
    .space-y-4 > * + * {
        margin-top: 0.75rem !important;
    }
    
    /* Text sizing on mobile */
    h1 { font-size: 1.5rem !important; }
    h2 { font-size: 1.25rem !important; }
    h3 { font-size: 1.125rem !important; }
    
    /* Form labels on mobile */
    label {
        font-size: 0.875rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Input groups on mobile */
    .input-group {
        margin-bottom: 1rem !important;
    }
    
    /* Modal/Dialog adjustments */
    .modal, [role="dialog"] {
        margin: 1rem;
        max-width: calc(100% - 2rem);
    }
}

/* Very small phones */
@media (max-width: 375px) {
    #sidebar {
        width: 260px;
        max-width: 90vw;
    }
    
    main {
        padding: 0.75rem !important;
    }
    
    header {
        padding: 0.625rem 0.75rem !important;
    }
    
    header h2 {
        font-size: 0.9375rem !important;
    }
}

/* Mobile-specific improvements */
@media (max-width: 768px) {
    /* Better touch targets */
    a, button {
        -webkit-tap-highlight-color: rgba(59, 130, 246, 0.1);
        touch-action: manipulation;
    }
    
    /* Smooth scrolling */
    * {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Prevent text selection on buttons */
    button, .btn {
        -webkit-user-select: none;
        -moz-user-select: none;
        user-select: none;
    }
    
    /* Better form inputs on mobile */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    input[type="datetime-local"],
    select,
    textarea {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        border-radius: 0.5rem;
        font-size: 16px !important;
    }
    
    /* Better select dropdowns */
    select {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
        background-position: left 0.75rem center;
        background-repeat: no-repeat;
        background-size: 1.25em 1.25em;
        padding-left: 2.5rem;
        padding-right: 0.75rem;
        display: inline-block;
        vertical-align: middle;
        line-height: 1.5;
        min-height: 2.5rem;
        padding-top: 0.625rem;
        padding-bottom: 0.625rem;
    }
    
    /* Improve card spacing */
    .bg-white {
        margin-bottom: 1rem;
    }
    
    /* Better pagination on mobile */
    .pagination {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .pagination a,
    .pagination span {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Select Dropdown Alignment Fix */
select {
    display: inline-block;
    vertical-align: middle;
    line-height: 1.5;
    min-height: 2.5rem;
    padding-top: 0.625rem;
    padding-bottom: 0.625rem;
}

select option {
    padding: 0.5rem;
    line-height: 1.5;
    display: block;
}

/* RTL Select Dropdown Arrow */
[dir="rtl"] select {
    background-position: left 0.75rem center;
    padding-left: 2.5rem;
    padding-right: 0.75rem;
}

/* Form Styles */
.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: all 0.3s ease;
    background: #ffffff;
}

.form-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Readonly Input Styles */
input[readonly],
input[readonly]:focus {
    background-color: #e5e7eb !important;
    color: #374151 !important;
    border-color: #9ca3af !important;
    cursor: not-allowed;
    opacity: 0.85;
}

.form-select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: all 0.3s ease;
    background: #ffffff;
    cursor: pointer;
}

.form-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    font-weight: 600;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
    cursor: pointer;
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.btn-secondary {
    background: #6b7280;
    color: white;
}

.btn-secondary:hover {
    background: #4b5563;
}

/* Card Styles */
.card {
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
}

.card-body {
    padding: 1.5rem;
}

/* Alert Styles */
.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
}

.alert-success {
    background: #d1fae5;
    border-right: 4px solid #10b981;
    color: #065f46;
}

.alert-error {
    background: #fee2e2;
    border-right: 4px solid #ef4444;
    color: #991b1b;
}

.alert-warning {
    background: #fef3c7;
    border-right: 4px solid #f59e0b;
    color: #92400e;
}

.alert-info {
    background: #dbeafe;
    border-right: 4px solid #3b82f6;
    color: #1e40af;
}

/* Badge Styles */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

/* Utility Classes */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shadow-sm {
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.shadow-md {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.shadow-lg {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Loading Spinner */
.spinner {
    border: 3px solid #f3f4f6;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Print Styles */
@media print {
    .no-print {
        display: none !important;
    }
    
    body {
        background: white;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #e5e7eb;
    }
}

/* ============================================
   نظام الأزرار الموحد
   ============================================ */

/* إزالة overlay من sidebar عند عدم الحاجة */
#sidebar-overlay:not(.active) {
    display: none !important;
    pointer-events: none !important;
}

/* نظام الأزرار الموحد */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.25rem;
    border-radius: 0.5rem;
    transition: all 0.2s;
    cursor: pointer;
    text-decoration: none;
    border: none;
    position: relative;
    z-index: 1;
}

.btn:focus {
    outline: 2px solid transparent;
    outline-offset: 2px;
}

/* أزرار الألوان */
.btn-primary {
    background-color: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background-color: #2563eb;
}

.btn-success {
    background-color: #10b981;
    color: white;
}

.btn-success:hover {
    background-color: #059669;
}

.btn-danger {
    background-color: #ef4444;
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-warning {
    background-color: #f59e0b;
    color: white;
}

.btn-warning:hover {
    background-color: #d97706;
}

.btn-secondary {
    background-color: #6b7280;
    color: white;
}

.btn-secondary:hover {
    background-color: #4b5563;
}

/* أزرار خفيفة (للجداول) */
.btn-outline-primary {
    background-color: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.btn-outline-primary:hover {
    background-color: #dbeafe;
    color: #1e3a8a;
}

.btn-outline-success {
    background-color: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.btn-outline-success:hover {
    background-color: #d1fae5;
    color: #064e3b;
}

.btn-outline-warning {
    background-color: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

.btn-outline-warning:hover {
    background-color: #fef3c7;
    color: #78350f;
}

/* أحجام الأزرار */
.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    gap: 0.25rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* أزرار كاملة العرض */
.btn-block {
    width: 100%;
}

/* ضمان أن الأزرار قابلة للنقر دائماً */
a.btn,
button.btn,
.btn {
    pointer-events: auto !important;
    cursor: pointer !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* إزالة أي تأثير من hover على صفوف الجدول */
table tbody tr:hover {
    background-color: #f9fafb;
}

table tbody tr:hover .btn {
    opacity: 1 !important;
    visibility: visible !important;
}


