/* ملف CSS المشترك للتصميم المتجاوب - Responsive Design System */

/* متغيرات اللون الموحدة */
:root {
    /* الألوان الأساسية */
    --primary-gradient: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    --success-gradient: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    --warning-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --info-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --purple-gradient: linear-gradient(135deg, #fa709a 0%, #fee140 100%);

    /* الألوان الثابتة */
    --primary-color: var(--brand);
    --success-color: #4caf50;
    --warning-color: #ffc107;
    --danger-color: #f44336;
    --info-color: #2196F3;

    /* الخلفيات */
    --bg-light: #f5f7fa;
    --bg-white: #ffffff;
    --bg-gray: #f8f9fa;

    /* النصوص */
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-light: #999999;

    /* الحدود */
    --border-light: #e0e0e0;
    --border-medium: #d0d0d0;

    /* الظلال */
    --shadow-sm: 0 2px 10px rgba(0,0,0,0.05);
    --shadow-md: 0 5px 20px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.2);
    --shadow-xl: 0 20px 60px rgba(0,0,0,0.3);

    /* نقاط التوقف */
    --breakpoint-xs: 480px;
    --breakpoint-sm: 640px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 1024px;
    --breakpoint-xl: 1280px;

    /* المسافات */
    --spacing-xs: 5px;
    --spacing-sm: 10px;
    --spacing-md: 15px;
    --spacing-lg: 20px;
    --spacing-xl: 30px;
    --spacing-2xl: 40px;

    /* الخطوط */
    --font-xs: 12px;
    --font-sm: 14px;
    --font-md: 16px;
    --font-lg: 18px;
    --font-xl: 24px;
    --font-2xl: 32px;
    --font-3xl: 48px;
}

/* إعدادات أساسية */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

/* Ensure the document direction follows the HTML attribute explicitly */
html[dir="rtl"] { direction: rtl; }
html[dir="ltr"] { direction: ltr; }
html[dir="rtl"] body { direction: rtl; }
html[dir="ltr"] body { direction: ltr; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif, 'Arial', sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* حاوية عامة */
.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 var(--spacing-lg);
}

.container-sm {
    max-width: 800px;
}

.container-lg {
    max-width: 1600px;
}

/* شبكة مرنة */
.grid {
    display: grid;
    gap: var(--spacing-lg);
}

.grid-cols-1 { grid-template-columns: repeat(1, 1fr); }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

/* Flexbox */
.flex {
    display: flex;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.flex-wrap {
    flex-wrap: wrap;
}

.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }
.gap-lg { gap: var(--spacing-lg); }
.gap-xl { gap: var(--spacing-xl); }

/* الأزرار المتجاوبة */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: var(--font-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    text-decoration: none;
    min-height: 44px; /* حد أدنى للمس */
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
}

.btn-success {
    background: var(--success-gradient);
    color: white;
}

.btn-warning {
    background: var(--warning-gradient);
    color: white;
}

.btn-info {
    background: var(--info-gradient);
    color: white;
}

.btn-sm {
    padding: 8px 16px;
    font-size: var(--font-sm);
    min-height: 36px;
}

.btn-lg {
    padding: 15px 30px;
    font-size: var(--font-lg);
    min-height: 52px;
}

/* البطاقات المتجاوبة */
.card {
    background: var(--bg-white);
    border-radius: 15px;
    padding: var(--spacing-xl);
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-md);
    border-bottom: 2px solid var(--border-light);
}

.card-title {
    font-size: var(--font-xl);
    color: var(--text-primary);
    font-weight: 600;
}

/* النماذج المتجاوبة */
.form-group {
    margin-bottom: var(--spacing-lg);
}

.form-label {
    display: block;
    margin-bottom: var(--spacing-sm);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: var(--font-sm);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-light);
    border-radius: 10px;
    font-size: var(--font-md);
    transition: border-color 0.3s ease;
    min-height: 44px; /* للمس */
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

/* الجداول المتجاوبة */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: var(--spacing-lg);
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table thead {
    background: var(--bg-gray);
}

.table th,
.table td {
    padding: var(--spacing-md);
    text-align: right;
    border-bottom: 1px solid var(--border-light);
}

.table th {
    font-weight: 600;
    color: var(--text-primary);
}

.table tbody tr:hover {
    background: var(--bg-gray);
}

/* الشارات */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: var(--font-xs);
    font-weight: 600;
    white-space: nowrap;
}

.badge-success {
    background: #d1e7dd;
    color: #0f5132;
}

.badge-warning {
    background: #fff3cd;
    color: #856404;
}

.badge-danger {
    background: #f8d7da;
    color: #842029;
}

.badge-info {
    background: #cfe2ff;
    color: #084298;
}

/* الرسائل */
.alert {
    padding: var(--spacing-md);
    border-radius: 10px;
    margin-bottom: var(--spacing-lg);
}

.alert-success {
    background: #d1e7dd;
    color: #0f5132;
    border: 1px solid #badbcc;
}

.alert-error {
    background: #f8d7da;
    color: #842029;
    border: 1px solid #f5c2c7;
}

.alert-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffecb5;
}

.alert-info {
    background: #cfe2ff;
    color: #084298;
    border: 1px solid #b6d4fe;
}

/* مساعدات الإظهار/الإخفاء */
.hidden { display: none !important; }
.visible { display: block !important; }

/* مساعدات النص */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.text-bold { font-weight: 600; }
.text-normal { font-weight: 400; }

.text-xs { font-size: var(--font-xs); }
.text-sm { font-size: var(--font-sm); }
.text-md { font-size: var(--font-md); }
.text-lg { font-size: var(--font-lg); }
.text-xl { font-size: var(--font-xl); }

/* المسافات */
.m-0 { margin: 0; }
.mt-1 { margin-top: var(--spacing-sm); }
.mt-2 { margin-top: var(--spacing-md); }
.mt-3 { margin-top: var(--spacing-lg); }
.mb-1 { margin-bottom: var(--spacing-sm); }
.mb-2 { margin-bottom: var(--spacing-md); }
.mb-3 { margin-bottom: var(--spacing-lg); }

.p-0 { padding: 0; }
.p-1 { padding: var(--spacing-sm); }
.p-2 { padding: var(--spacing-md); }
.p-3 { padding: var(--spacing-lg); }

/* ==================== استعلامات الوسائط ==================== */

/* شاشات صغيرة جداً - الهواتف الصغيرة */
@media (max-width: 479px) {
    :root {
        --spacing-lg: 15px;
        --spacing-xl: 20px;
        --spacing-2xl: 30px;
    }

    html {
        font-size: 14px;
    }

    .container {
        padding: 0 var(--spacing-md);
    }

    .card {
        padding: var(--spacing-lg);
        border-radius: 12px;
    }

    .btn {
        width: 100%;
        padding: 12px 20px;
    }

    .btn-sm {
        width: auto;
    }

    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: 1fr;
    }

    .table th,
    .table td {
        padding: var(--spacing-sm);
        font-size: var(--font-sm);
    }

    /* إخفاء بعض الأعمدة في الجداول */
    .table .hide-xs {
        display: none;
    }
}

/* الهواتف - 480px وأكبر */
@media (min-width: 480px) and (max-width: 639px) {
    .grid-cols-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* الأجهزة اللوحية الصغيرة - 640px وأكبر */
@media (min-width: 640px) and (max-width: 767px) {
    .grid-cols-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-cols-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* الأجهزة اللوحية - 768px وأكبر */
@media (min-width: 768px) and (max-width: 1023px) {
    .grid-cols-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-cols-4 {
        grid-template-columns: repeat(3, 1fr);
    }

    .table .hide-sm {
        display: none;
    }
}

/* الشاشات المتوسطة - 1024px وأكبر */
@media (min-width: 1024px) {
    .grid-cols-3 {
        grid-template-columns: repeat(3, 1fr);
    }

    .grid-cols-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* الشاشات الكبيرة - 1280px وأكبر */
@media (min-width: 1280px) {
    .container {
        padding: 0 var(--spacing-2xl);
    }
}

/* وضع الطباعة */
@media print {
    .no-print {
        display: none !important;
    }

    .card {
        box-shadow: none;
        border: 1px solid var(--border-light);
    }

    .btn {
        display: none;
    }
}

/* تحسينات الأداء */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* الوضع الداكن */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-light: #1a1a1a;
        --bg-white: #2d2d2d;
        --bg-gray: #3a3a3a;
        --text-primary: #ffffff;
        --text-secondary: #cccccc;
        --text-light: #999999;
        --border-light: #4a4a4a;
        --border-medium: #5a5a5a;
    }
}

/* تحسينات التفاعل باللمس */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 48px; /* زيادة حجم الأزرار للمس */
    }

    .form-input,
    .form-select {
        min-height: 48px;
    }

    .table td,
    .table th {
        padding: var(--spacing-md) var(--spacing-sm);
    }
}

/* تحسينات للأجهزة ذات الشاشات العالية الدقة */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* التخطيط الأفقي للأجهزة المحمولة */
@media (max-width: 768px) and (orientation: landscape) {
    .card {
        padding: var(--spacing-md);
    }

    .btn {
        padding: 10px 20px;
    }
}

/* فئات مساعدة للعرض/الإخفاء حسب حجم الشاشة */
@media (max-width: 479px) {
    .hide-mobile { display: none !important; }
}

@media (min-width: 480px) and (max-width: 767px) {
    .hide-tablet-sm { display: none !important; }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .hide-tablet { display: none !important; }
}

@media (min-width: 1024px) {
    .hide-desktop { display: none !important; }
}

@media (max-width: 767px) {
    .show-desktop-only { display: none !important; }
}

@media (min-width: 768px) {
    .show-mobile-only { display: none !important; }
}

/* RTL handling: swap typical text-left / text-right helpers when dir="rtl" */
[dir="rtl"] .text-right { text-align: left !important; }
[dir="rtl"] .text-left { text-align: right !important; }

/* Ensure tables and other directional elements adapt under RTL */
[dir="rtl"] .table th,
[dir="rtl"] .table td {
    text-align: left;
}
