/**
 * ========================================
 * الستايل الاحترافي الموحد - يوجي (محدث)
 * Professional Global Styles - Vidoo (Updated)
 * Optimized for Mobile & Desktop
 * ========================================
 */

/* ========================================
   CSS Variables - متغيرات CSS
   ======================================== */
:root {
    /* الألوان الأساسية */
    --primary: #1877f2;
    --primary-dark: #0d5bbd;
    --primary-light: #e7f0ff;
    --primary-rgb: 24, 119, 242;

    --secondary: #6366f1;
    --secondary-dark: #4f46e5;
    --secondary-light: #eef2ff;

    --accent: #10b981;
    --accent-dark: #059669;
    --accent-light: #d1fae5;

    /* ألوان الحالة */
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --info: #3b82f6;
    --info-light: #dbeafe;

    /* ألوان النص */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --text-light: #94a3b8;

    /* ألوان الخلفية */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-dark: #0f172a;

    /* الحدود */
    --border-color: #e2e8f0;
    --border-light: #f1f5f9;
    --border-dark: #cbd5e1;

    /* الظلال */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

    /* الزوايا */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-2xl: 24px;
    --radius-full: 9999px;

    /* الانتقالات */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;

    /* الخطوط */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-arabic: 'El Messiri', 'Cairo', 'Tajawal', var(--font-sans);

    /* المسافات */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 16px;
    --spacing-xl: 24px;
    --spacing-2xl: 32px;
    --spacing-3xl: 48px;

    /* أحجام النص */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --text-4xl: 2.25rem;
    --text-5xl: 3rem;
}

/* ========================================
   Reset & Base Styles
   ======================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-arabic);
    font-size: var(--text-base);
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    direction: rtl;
    text-align: right;
    overflow-x: hidden;
    min-height: 100vh;
    width: 100%;
}

img,
video,
svg,
iframe {
    max-width: 100%;
    height: auto;
    display: block;
}

input,
select,
textarea,
button {
    font-family: inherit;
    font-size: inherit;
}

input,
select,
textarea {
    max-width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
}

/* ========================================
   Typography - الطباعة
   ======================================== */
h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    line-height: 1.3;
    color: var(--text-primary);
    margin-bottom: var(--spacing-lg);
}

h1 { font-size: clamp(1.875rem, 5vw, var(--text-4xl)); }
h2 { font-size: clamp(1.5rem, 4vw, var(--text-3xl)); }
h3 { font-size: clamp(1.25rem, 3.5vw, var(--text-2xl)); }
h4 { font-size: clamp(1.125rem, 3vw, var(--text-xl)); }
h5 { font-size: clamp(1rem, 2.5vw, var(--text-lg)); }
h6 { font-size: var(--text-base); }

p {
    margin-bottom: var(--spacing-lg);
    color: var(--text-secondary);
    line-height: 1.6;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
    -webkit-tap-highlight-color: rgba(var(--primary-rgb), 0.1);
}

a:hover {
    color: var(--primary-dark);
}

/* ========================================
   Buttons - الأزرار
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: 0.75rem 1.5rem;
    font-size: var(--text-sm);
    font-weight: 600;
    line-height: 1.4;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
    touch-action: manipulation;
    min-height: 44px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* Primary Button */
.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.3);
}

.btn-primary:hover,
.btn-primary:focus {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.4);
    color: #fff;
}

.btn-primary:active {
    transform: translateY(0);
}

/* Secondary Button */
.btn-secondary {
    background: var(--secondary);
    color: #fff;
}

.btn-secondary:hover {
    background: var(--secondary-dark);
    color: #fff;
}

/* Outline Button */
.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: #fff;
}

/* Success Button */
.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover {
    background: var(--accent-dark);
    color: #fff;
}

/* Danger Button */
.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
    color: #fff;
}

/* Button Sizes */
.btn-sm {
    padding: 0.5rem 1rem;
    font-size: var(--text-xs);
    min-height: 36px;
}

.btn-lg {
    padding: 1rem 2rem;
    font-size: var(--text-base);
    min-height: 52px;
}

.btn-block {
    width: 100%;
}

/* ========================================
   Cards - البطاقات
   ======================================== */
.card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: all var(--transition-normal);
    width: 100%;
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.card-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.card-body {
    padding: var(--spacing-lg);
}

.card-footer {
    padding: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.card-title {
    font-size: var(--text-lg);
    font-weight: 600;
    margin-bottom: var(--spacing-md);
}

/* Stat Card */
.stat-card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
    min-height: 160px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, transparent 50%, rgba(var(--primary-rgb), 0.05) 50%);
    border-radius: 0 var(--radius-lg) 0 100%;
}

.stat-card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-bottom: var(--spacing-md);
}

.stat-card-icon.primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
}

.stat-card-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--spacing-xs);
    display: block;
}

.stat-card-value {
    font-size: clamp(1.5rem, 4vw, var(--text-3xl));
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

/* ========================================
   Forms - النماذج
   ======================================== */
.form-group {
    margin-bottom: var(--spacing-xl);
    width: 100%;
}

.form-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
}

.form-control {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: var(--text-base);
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    min-height: 48px;
    -webkit-appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
}

.form-control::placeholder {
    color: var(--text-light);
    opacity: 1;
}

.form-control.is-invalid {
    border-color: var(--danger);
}

.form-control.is-valid {
    border-color: var(--success);
}

textarea.form-control {
    min-height: 120px;
    resize: vertical;
    line-height: 1.5;
}

/* Select */
.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: left 12px center;
    background-size: 16px 12px;
    padding-left: 2.5rem;
    cursor: pointer;
}

/* Checkbox & Radio */
.form-check {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
    cursor: pointer;
}

.form-check-input {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-dark);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.form-check-input:checked {
    background: var(--primary);
    border-color: var(--primary);
}

.form-check-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

/* Input Group */
.input-group {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.input-group .form-control {
    width: 100%;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    min-height: 48px;
}

/* ========================================
   Tables - الجداول
   ======================================== */
.table-wrapper {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

.table thead {
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 10;
}

.table th {
    padding: 1rem;
    text-align: right;
    font-weight: 600;
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.table td {
    padding: 1rem;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
    word-break: break-word;
}

.table tbody tr {
    transition: background var(--transition-fast);
}

.table tbody tr:hover {
    background: var(--bg-secondary);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* ========================================
   Responsive Tables
   ======================================== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: var(--spacing-lg);
}

/* ========================================
   Badges - الشارات
   ======================================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    font-size: var(--text-xs);
    font-weight: 600;
    border-radius: var(--radius-full);
    white-space: nowrap;
    line-height: 1.2;
}

.badge-primary {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.badge-success {
    background: var(--success-light);
    color: #065f46;
}

.badge-warning {
    background: var(--warning-light);
    color: #92400e;
}

.badge-danger {
    background: var(--danger-light);
    color: #991b1b;
}

.badge-info {
    background: var(--info-light);
    color: #1e40af;
}

.badge-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* ========================================
   Alerts - التنبيهات
   ======================================== */
.alert {
    padding: var(--spacing-lg);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-lg);
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-md);
    width: 100%;
}

.alert-icon {
    font-size: var(--text-xl);
    flex-shrink: 0;
    line-height: 1;
}

.alert-content {
    flex: 1;
    min-width: 0;
}

.alert-title {
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
    font-size: var(--text-base);
}

.alert-message {
    font-size: var(--text-sm);
    line-height: 1.5;
}

.alert-success {
    background: var(--success-light);
    color: #065f46;
    border: 1px solid var(--success);
}

.alert-danger {
    background: var(--danger-light);
    color: #991b1b;
    border: 1px solid var(--danger);
}

.alert-warning {
    background: var(--warning-light);
    color: #92400e;
    border: 1px solid var(--warning);
}

.alert-info {
    background: var(--info-light);
    color: #1e40af;
    border: 1px solid var(--info);
}

/* ========================================
   Modal - النوافذ المنبثقة
   ======================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: min(500px, 100%);
    max-height: calc(100vh - 2rem);
    overflow: hidden;
    transform: scale(0.9);
    transition: transform var(--transition-normal);
    display: flex;
    flex-direction: column;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-title {
    font-size: var(--text-lg);
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
}

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--bg-secondary);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    margin-right: -0.5rem;
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--spacing-lg);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
}

.modal-footer {
    padding: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
    flex-shrink: 0;
}

/* ========================================
   Responsive Design
   ======================================== */

/* Mobile First (Default) */
.container {
    width: 100%;
    padding-right: 1rem;
    padding-left: 1rem;
    margin-right: auto;
    margin-left: auto;
}

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {
    .container {
        max-width: 540px;
    }
    
    .input-group {
        flex-direction: row;
    }
    
    .input-group .form-control {
        flex: 1;
    }
    
    .modal {
        max-width: 400px;
    }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) {
    :root {
        --spacing-md: 16px;
        --spacing-lg: 24px;
        --spacing-xl: 32px;
        --spacing-2xl: 48px;
    }
    
    .container {
        max-width: 720px;
    }
    
    .stat-card {
        min-height: 180px;
    }
    
    .stat-card-icon {
        width: 56px;
        height: 56px;
        font-size: 24px;
    }
    
    .modal {
        max-width: 500px;
    }
    
    .table {
        min-width: 0;
    }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
    .container {
        max-width: 960px;
    }
    
    .modal {
        max-width: 600px;
    }
}

/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
    .container {
        max-width: 1140px;
    }
    
    .modal {
        max-width: 700px;
    }
}

/* Mobile specific optimizations */
@media (max-width: 767px) {
    /* Typography */
    h1, h2, h3, h4, h5, h6 {
        margin-bottom: var(--spacing-md);
    }
    
    p {
        margin-bottom: var(--spacing-md);
    }
    
    /* Cards */
    .card-header,
    .card-body,
    .card-footer {
        padding: var(--spacing-md);
    }
    
    /* Buttons */
    .btn {
        min-height: 48px;
        padding: 0.875rem 1.25rem;
    }
    
    .btn-block {
        width: 100%;
    }
    
    /* Tables */
    .table th,
    .table td {
        padding: 0.75rem;
    }
    
    /* Modal */
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: var(--spacing-md);
    }
    
    /* Hide/show helpers */
    .mobile-only {
        display: block !important;
    }
    
    .desktop-only {
        display: none !important;
    }
}

/* Desktop specific */
@media (min-width: 768px) {
    .mobile-only {
        display: none !important;
    }
    
    .desktop-only {
        display: block !important;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn:hover {
        transform: none;
    }
    
    .card:hover {
        transform: none;
    }
    
    .table tbody tr:hover {
        background: inherit;
    }
    
    /* Larger tap targets for mobile */
    .btn {
        min-height: 48px;
    }
    
    .form-check {
        min-height: 24px;
    }
    
    .pagination-item {
        min-width: 48px;
        height: 48px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000;
        --text-primary: #000;
        --text-secondary: #333;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
    
    .card {
        border: 2px solid var(--border-color);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    html {
        scroll-behavior: auto;
    }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    .no-print {
        display: none !important;
    }
    
    body {
        background: #fff !important;
        color: #000 !important;
        font-size: 12pt !important;
    }
    
    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        page-break-inside: avoid;
    }
    
    .btn {
        display: none !important;
    }
    
    a {
        color: #000 !important;
        text-decoration: underline !important;
    }
    
    .table {
        page-break-inside: avoid;
    }
}

/* ========================================
   Accessibility Improvements
   ======================================== */
@media (prefers-reduced-transparency: reduce) {
    .modal-overlay {
        backdrop-filter: none;
    }
}

/* Focus styles for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Skip to main content link */
.skip-to-content {
    position: absolute;
    top: -40px;
    right: 0;
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    text-decoration: none;
    z-index: 9999;
}

.skip-to-content:focus {
    top: 0;
}
