/* إعداد عام */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* لوحة ألوان موحّدة */
:root {
    --color-bg-gradient-start: #667eea;
    --color-bg-gradient-end: #764ba2;

    --color-primary: #3498db;
    --color-primary-dark: #2980b9;
    --color-accent: #764ba2;

    --color-success: #2ecc71;
    --color-success-dark: #27ae60;
    --color-warning: #f39c12;
    --color-error: #e74c3c;

    --text-dark: #2c3e50;
    --text-muted: #7f8c8d;

    --bg-card: #ffffff;
    --bg-muted: #f8f9fa;
    --border-color: #ecf0f1;
    --border-light: #ddd;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--color-bg-gradient-start) 0%, var(--color-bg-gradient-end) 100%);
    min-height: 100vh;
    direction: rtl;
    text-align: right;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* الهيدر */
.header {
    background: rgba(255, 255, 255, 0.95);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin-bottom: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

.header h1 {
    color: var(--text-dark);
    font-size: 2.5em;
    margin-bottom: 10px;
    font-weight: 700;
}

.header p {
    color: var(--text-muted);
    font-size: 1.2em;
}

/* التبويبات */
.nav-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    background: rgba(255, 255, 255, 0.95);
    padding: 10px;
    border-radius: 15px;
    backdrop-filter: blur(10px);
    position: sticky;
    top: 10px;
    z-index: 40;
    border: 1px solid var(--border-color);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
}

.tab-btn {
    flex: 1;
    padding: 15px 20px;
    border: none;
    background: var(--bg-muted);
    color: var(--text-dark);
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: 600;
    transition: all 0.3s ease;
    border: 1px solid var(--border-color);
}

.tab-btn:hover {
    background: #ffffff;
    transform: translateY(-2px);
}

.tab-btn.active {
    background: linear-gradient(45deg, var(--color-primary), var(--color-primary-dark));
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.4);
}

/* محتوى التبويبات */
.tab-content {
    display: none;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* أقسام النموذج */
.form-section {
    margin-bottom: 30px;
    padding: 25px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: #fafafa;
    transition: all 0.3s ease;
}

.form-section:hover {
    border-color: var(--color-primary);
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.1);
}

.form-section h2 {
    color: var(--text-dark);
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 3px solid var(--color-primary);
    font-size: 1.4em;
    font-weight: 600;
}

.form-section h3 {
    color: #34495e;
    margin-bottom: 15px;
    font-size: 1.2em;
}

/* شبكة النموذج */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

/* مجموعة الحقول */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-dark);
    font-size: 1em;
}

.required {
    color: #e74c3c;
}

/* حقول الإدخال */
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-light);
    border-radius: 8px;
    font-size: 1em;
    font-family: inherit;
    transition: all 0.3s ease;
    background: white;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
    transform: translateY(-1px);
}

.form-group input:invalid {
    border-color: #e74c3c;
}

.form-group input:valid {
    border-color: #27ae60;
}

/* التحقق البصري لرقم الهوية باستخدام خوارزمية التحقق */
.form-group input.checksum-field:valid {
    /* لا تجعل الحقل أخضر تلقائياً عند :valid، اترك القرار للأصناف أدناه */
    border-color: var(--border-light);
}
.form-group input.checksum-field.checksum-valid {
    border-color: var(--color-success) !important;
    box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.12);
}
.form-group input.checksum-field.checksum-invalid {
    border-color: var(--color-error) !important;
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.08);
}

/* نموذج الأطفال */
.child-form {
    background: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    border: 2px solid var(--border-color);
    position: relative;
}

.child-form h3 {
    background: linear-gradient(45deg, var(--color-primary), var(--color-primary-dark));
    color: white;
    margin: -20px -20px 20px -20px;
    padding: 15px 20px;
    border-radius: 8px 8px 0 0;
    font-size: 1.1em;
}

/* نموذج الزوجات */
.spouse-form {
    background: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    border: 2px solid var(--border-color);
    position: relative;
}

.spouse-form h3 {
    background: linear-gradient(45deg, var(--color-accent), #9b59b6);
    color: white;
    margin: -20px -20px 20px -20px;
    padding: 15px 20px;
    border-radius: 8px 8px 0 0;
    font-size: 1.1em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.spouse-form h3 .btn-danger {
    margin: 0;
    padding: 6px 12px;
    font-size: 0.85em;
}

/* الأزرار */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    text-align: center;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.btn-primary {
    background: linear-gradient(45deg, var(--color-primary), var(--color-primary-dark));
    color: white;
}

.btn-secondary {
    background: linear-gradient(45deg, #95a5a6, #7f8c8d);
    color: white;
}

.btn-danger {
    background: linear-gradient(45deg, var(--color-error), #c0392b);
    color: white;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.9em;
}

/* إجراءات النموذج */
.form-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid var(--border-color);
}

/* قسم البحث */
.search-section {
    margin-bottom: 30px;
}

.search-form {
    display: flex;
    gap: 15px;
    align-items: end;
    background: var(--bg-muted);
    padding: 20px;
    border-radius: 10px;
    border: 2px solid var(--border-color);
}

.search-form .form-group {
    flex: 1;
    margin-bottom: 0;
}

/* تفاصيل الفرد */
.member-details {
    animation: slideIn 0.5s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

.detail-section {
    background: var(--bg-muted);
    padding: 25px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 2px solid var(--border-color);
}

.detail-section h3 {
    color: var(--text-dark);
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--color-primary);
    font-size: 1.3em;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
}

.detail-grid > div {
    padding: 10px;
    background: white;
    border-radius: 8px;
    border: 1px solid var(--border-light);
}

.detail-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 2px solid #ecf0f1;
}

/* قائمة الأطفال */
.children-list {
    display: grid;
    gap: 20px;
}

.child-detail {
    background: white;
    padding: 20px;
    border-radius: 10px;
    border: 2px solid #ecf0f1;
}

.child-detail h4 {
    background: linear-gradient(45deg, var(--color-success-dark), var(--color-success));
    color: white;
    margin: -20px -20px 15px -20px;
    padding: 12px 20px;
    border-radius: 8px 8px 0 0;
    font-size: 1em;
}

/* تنسيق عرض الزوجات */
.spouse-detail {
    background: white;
    padding: 20px;
    border-radius: 10px;
    border: 2px solid #e8f4f8;
    margin-bottom: 15px;
}

.spouse-detail h4 {
    background: linear-gradient(45deg, var(--color-accent), var(--color-primary));
    color: white;
    margin: -20px -20px 15px -20px;
    padding: 12px 20px;
    border-radius: 8px 8px 0 0;
    font-size: 1em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.spouse-detail h4::before {
    content: "💍";
    font-size: 1.1em;
}

/* بطاقات العائلة */
.family-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.family-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.family-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border-color: var(--color-primary);
}

.card-header {
    background: linear-gradient(45deg, var(--color-primary), var(--color-primary-dark));
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h3 {
    margin: 0;
    font-size: 1.2em;
}

.member-id {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.9em;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

.card-info {
    display: grid;
    gap: 10px;
}

.card-info > div {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: var(--bg-muted);
    border-radius: 6px;
    font-size: 0.95em;
}

.card-info i {
    color: var(--color-primary);
    width: 20px;
    text-align: center;
}

.card-actions {
    padding: 15px 20px;
    background: #f8f9fa;
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* الرسائل */
.message-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
    max-width: 400px;
}

.message {
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideInLeft 0.3s ease-out;
    position: relative;
    border-left: 4px solid var(--color-primary);
}

@keyframes slideInLeft {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

.message-success {
    border-left-color: var(--color-success-dark);
    color: var(--color-success-dark);
}

.message-error {
    border-left-color: var(--color-error);
    color: var(--color-error);
}

.message-warning {
    border-left-color: var(--color-warning);
    color: var(--color-warning);
}

.message-info {
    border-left-color: var(--color-primary);
    color: var(--color-primary);
}

.message-close {
    position: absolute;
    top: 5px;
    left: 5px;
    background: none;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    color: #7f8c8d;
    width: 25px;
    height: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.message-close:hover {
    background: #ecf0f1;
    color: var(--text-dark);
}

/* عدم وجود بيانات */
.no-data {
    text-align: center;
    color: var(--text-muted);
    font-size: 1.2em;
    padding: 40px;
    background: var(--bg-muted);
    border-radius: 10px;
    border: 2px dashed var(--border-light);
}

/* التجاوب */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .nav-tabs {
        flex-direction: column;
        position: static; /* إلغاء التثبيت على الموبايل */
        top: auto;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .detail-grid {
        grid-template-columns: 1fr;
    }
    
    .search-form {
        flex-direction: column;
    }
    
    .family-cards {
        grid-template-columns: 1fr;
    }
    
    .card-actions {
        flex-direction: column;
    }
    
    .message-container {
        left: 10px;
        right: 10px;
        max-width: none;
    }
}

/* عناصر رمز الوصول (قائمة العائلة) */
.access-grid {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 10px;
    align-items: end;
    margin-bottom: 10px;
}

/* ضع زر عرض المحذوفات في صف جديد على سطح المكتب */
.access-grid .show-deleted-btn {
    grid-column: 1 / -1;
    justify-self: start; /* في RTL يبدأ من اليمين */
}

.password-field {
    position: relative;
}

.password-field input[type="password"],
.password-field input[type="text"] {
    padding-inline-end: 44px; /* مساحة لأيقونة العين في اتجاه RTL */
}

.toggle-visibility {
    position: absolute;
    left: 10px; /* في RTL توضع على اليسار */
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #7f8c8d;
    font-size: 1.1em;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.toggle-visibility:hover {
    background: #ecf0f1;
    color: #2c3e50;
}

.hint-text {
    display: block;
    margin-top: 6px;
    color: #7f8c8d;
    font-size: 0.9em;
}

/* تحسين العرض على الجوال لرمز الوصول */
@media (max-width: 768px) {
    .access-grid {
        grid-template-columns: 1fr;
        align-items: stretch;
    }
    .access-grid .btn {
        width: 100%;
    }
}

/* تأثيرات إضافية */
.form-section:before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(45deg, var(--color-primary), var(--color-primary-dark));
    border-radius: 0 12px 12px 0;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.form-section:hover:before {
    opacity: 1;
}

/* تحسين الخطوط */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* تحسين المدخلات */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

/* تحسين التمرير */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--color-primary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary-dark);
}

/* تحسينات إمكانية الوصول والتركيز */
:where(.btn, input, select, textarea):focus-visible {
    outline: 3px solid rgba(52, 152, 219, 0.35);
    outline-offset: 2px;
}

::placeholder {
    color: #9aa0a6;
}

/* احترام تفضيلات تقليل الحركة */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* تحسينات الأجهزة اللمسية */
@media (pointer: coarse) {
    .btn,
    .form-group input,
    .form-group select,
    .form-group textarea {
        min-height: 44px;
    }
    .btn {
        padding: 14px 20px;
    }
}

/* تحسين العرض للأجهزة الصغيرة جدًا */
@media (max-width: 576px) {
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
}

/* تصحيح ملاحظة المظهر لحقل الأرقام */
input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

/* السجلات المحذوفة */
.deleted-members-section {
    margin-top: 30px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.deleted-members-section h2 {
    color: var(--color-error);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.deleted-card {
    border: 2px solid var(--color-error);
    background: linear-gradient(145deg, #fff5f5, #ffffff);
    opacity: 0.9;
    position: relative;
}

.deleted-card::before {
    content: "محذوف";
    position: absolute;
    top: 10px;
    left: 10px;
    background: var(--color-error);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
}

.deletion-badge {
    background: var(--color-error);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    margin-top: 5px;
    display: inline-block;
}

.deleted-card .card-header h3 {
    color: var(--color-error);
    text-decoration: line-through;
}

.deleted-card .card-actions {
    border-top: 2px solid #ffebee;
    padding-top: 15px;
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

.deleted-card .btn-success {
    background: linear-gradient(45deg, var(--color-success), var(--color-success-dark));
    border: none;
    flex: 1;
}

.deleted-card .btn-success:hover {
    background: linear-gradient(45deg, var(--color-success-dark), var(--color-success));
    transform: translateY(-2px);
}

.deleted-card .btn-danger {
    background: linear-gradient(45deg, #dc3545, #c82333);
    border: none;
    flex: 1;
}

.deleted-card .btn-danger:hover {
    background: linear-gradient(45deg, #c82333, #dc3545);
    transform: translateY(-2px);
}

/* زر عرض المحذوفات */
.show-deleted-btn {
    background: linear-gradient(45deg, var(--color-warning), #e67e22);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 10px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.show-deleted-btn:hover {
    background: linear-gradient(45deg, #e67e22, var(--color-warning));
    transform: translateY(-2px);
}

/* تحسينات للاستجابة على الموبايل */
@media (max-width: 768px) {
    .deleted-card .card-actions {
        flex-direction: column;
        gap: 8px;
    }
    
    .deletion-badge {
        font-size: 0.75em;
        padding: 3px 6px;
    }
}