/* =====================================================================
   نظام إدارة الاستحواذ العقاري - الستايل الرئيسي
   RTL Arabic Design System
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800;900&family=Tajawal:wght@300;400;500;700;900&display=swap');

:root {
    /* الألوان الأساسية */
    --primary: #1e40af;
    --primary-dark: #1e3a8a;
    --primary-light: #3b82f6;
    --primary-bg: #eff6ff;
    
    --secondary: #0891b2;
    --accent: #8b5cf6;
    
    --success: #059669;
    --success-bg: #d1fae5;
    --warning: #d97706;
    --warning-bg: #fef3c7;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --info: #0284c7;
    --info-bg: #e0f2fe;
    
    /* الرمادي */
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    
    /* الخلفيات */
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    
    /* النص */
    --text: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    
    /* الظلال */
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
    --shadow: 0 1px 3px 0 rgba(0,0,0,0.1), 0 1px 2px 0 rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    
    /* الأبعاد */
    --radius-sm: 6px;
    --radius: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --sidebar-width: 260px;
    --topbar-height: 64px;
}

/* =====================================================================
   Reset & Base
   ===================================================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    direction: rtl;
    scroll-behavior: smooth;
}

body {
    font-family: 'Tajawal', 'Cairo', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--primary-dark);
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
}

input, select, textarea {
    font-family: inherit;
    font-size: 15px;
}

img {
    max-width: 100%;
    height: auto;
}

/* =====================================================================
   التخطيط الرئيسي
   ===================================================================== */

.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-left: 1px solid var(--border);
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 50;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 900;
    font-size: 18px;
}

.sidebar-title {
    font-weight: 700;
    font-size: 16px;
    color: var(--gray-800);
}

.sidebar-subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

.sidebar-nav {
    padding: 16px 12px;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 12px;
    margin-bottom: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--gray-700);
    font-weight: 500;
    transition: all 0.2s;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--gray-100);
    color: var(--primary);
}

.nav-item.active {
    background: var(--primary-bg);
    color: var(--primary);
    font-weight: 600;
}

.nav-item-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.main-content {
    flex: 1;
    margin-right: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-900);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: var(--radius);
    transition: background 0.2s;
    cursor: pointer;
}

.user-menu:hover {
    background: var(--gray-100);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
}

.user-info {
    text-align: right;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-800);
}

.user-role {
    font-size: 11px;
    color: var(--text-muted);
}

.page-content {
    padding: 24px;
    flex: 1;
}

.mobile-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
}

/* =====================================================================
   الزر
   ===================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s;
    white-space: nowrap;
    border: 1px solid transparent;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    color: white;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-success:hover {
    background: #047857;
    color: white;
}

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

.btn-danger:hover {
    background: #b91c1c;
    color: white;
}

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

.btn-outline {
    background: transparent;
    color: var(--gray-700);
    border-color: var(--border);
}

.btn-outline:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
}

.btn-ghost {
    background: transparent;
    color: var(--gray-700);
}

.btn-ghost:hover {
    background: var(--gray-100);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
}

.btn-icon {
    padding: 8px;
    width: 36px;
    height: 36px;
}

.btn-block {
    width: 100%;
}

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

/* =====================================================================
   البطاقات
   ===================================================================== */

.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}

.card-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--gray-800);
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--gray-50);
}

/* =====================================================================
   الإحصائيات
   ===================================================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: all 0.2s;
}

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

.stat-card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    font-size: 22px;
}

.stat-card-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 500;
}

.stat-card-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--gray-900);
    line-height: 1.2;
}

.stat-card-change {
    font-size: 12px;
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* =====================================================================
   الجداول
   ===================================================================== */

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

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

.table th {
    text-align: right;
    padding: 14px 16px;
    font-weight: 700;
    color: var(--gray-700);
    font-size: 13px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--gray-800);
    vertical-align: middle;
}

.table tbody tr {
    transition: background 0.15s;
}

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

.table tbody tr:last-child td {
    border-bottom: none;
}

/* =====================================================================
   الشارات (Badges)
   ===================================================================== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-primary { background: var(--primary-bg); color: var(--primary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }
.badge-info    { background: var(--info-bg); color: var(--info); }
.badge-gray    { background: var(--gray-100); color: var(--gray-700); }

.badge-dot::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* SLA Colors */
.sla-green  { background: var(--success-bg); color: var(--success); }
.sla-yellow { background: var(--warning-bg); color: var(--warning); }
.sla-red    { background: var(--danger-bg); color: var(--danger); animation: pulse 2s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* =====================================================================
   النماذج (Forms)
   ===================================================================== */

.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-weight: 600;
    font-size: 14px;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-label.required::after {
    content: ' *';
    color: var(--danger);
}

.form-control {
    display: block;
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--gray-900);
    transition: all 0.2s;
    font-size: 15px;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.form-control:disabled,
.form-control.readonly {
    background: var(--gray-50);
    cursor: not-allowed;
}

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

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-error {
    font-size: 13px;
    color: var(--danger);
    margin-top: 4px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    margin-top: 20px;
    flex-wrap: wrap;
}

/* =====================================================================
   التنبيهات (Alerts)
   ===================================================================== */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    border-right: 4px solid;
}

.alert-success { background: var(--success-bg); color: #065f46; border-color: var(--success); }
.alert-danger  { background: var(--danger-bg); color: #991b1b; border-color: var(--danger); }
.alert-warning { background: var(--warning-bg); color: #92400e; border-color: var(--warning); }
.alert-info    { background: var(--info-bg); color: #075985; border-color: var(--info); }

.alert-icon { font-size: 20px; flex-shrink: 0; }
.alert-content { flex: 1; font-size: 14px; font-weight: 500; }

/* =====================================================================
   شريط التقدم
   ===================================================================== */

.progress {
    background: var(--gray-200);
    border-radius: 999px;
    height: 8px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 999px;
    transition: width 0.3s;
}

/* =====================================================================
   مراحل المشروع (Stage Indicator)
   ===================================================================== */

.stages-track {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--gray-100);
    border-radius: var(--radius);
    margin-bottom: 20px;
    overflow-x: auto;
}

.stage-item {
    flex: 1;
    min-width: 80px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    position: relative;
    cursor: default;
}

.stage-item.completed {
    background: var(--success-bg);
    color: var(--success);
}

.stage-item.current {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow);
}

/* =====================================================================
   Checklist
   ===================================================================== */

.procedure-group {
    margin-bottom: 20px;
}

.procedure-group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--gray-100);
    border-radius: var(--radius);
    margin-bottom: 10px;
    font-weight: 700;
    color: var(--gray-800);
}

.procedure-group-stage {
    font-size: 11px;
    padding: 2px 8px;
    background: var(--primary);
    color: white;
    border-radius: 999px;
}

.procedure-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    background: var(--surface);
    transition: all 0.2s;
}

.procedure-item:hover {
    border-color: var(--gray-300);
}

.procedure-item.done {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.procedure-item.skipped {
    background: var(--gray-50);
    opacity: 0.7;
}

.procedure-checkbox {
    margin-top: 2px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary);
}

.procedure-text {
    flex: 1;
}

.procedure-title {
    font-weight: 500;
    color: var(--gray-800);
    margin-bottom: 4px;
}

.procedure-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--text-muted);
}

.procedure-item.done .procedure-title {
    text-decoration: line-through;
    color: var(--text-muted);
}

.procedure-actions {
    display: flex;
    gap: 6px;
}

/* =====================================================================
   الأدوات المساعدة
   ===================================================================== */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-lg { font-size: 18px; }
.text-xl { font-size: 22px; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }

.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }

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

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }

.p-2 { padding: 8px; }
.p-4 { padding: 16px; }

.w-full { width: 100%; }

.hidden { display: none; }

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.rounded { border-radius: var(--radius); }
.rounded-full { border-radius: 9999px; }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* =====================================================================
   الاستجابة للموبايل
   ===================================================================== */

@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(100%);
        box-shadow: var(--shadow-xl);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-right: 0;
    }
    
    .mobile-toggle {
        display: flex;
    }
    
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 45;
        display: none;
    }
    
    .sidebar-overlay.open {
        display: block;
    }
}

@media (max-width: 640px) {
    .page-content { padding: 16px; }
    .topbar { padding: 0 16px; }
    .topbar-title { font-size: 16px; }
    .user-info { display: none; }
    .card-body { padding: 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 14px; }
    .stat-card-value { font-size: 22px; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
}

/* =====================================================================
   صفحة تسجيل الدخول
   ===================================================================== */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    position: relative;
    overflow: hidden;
}

.login-page::before,
.login-page::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    opacity: 0.1;
    background: white;
}

.login-page::before {
    width: 500px;
    height: 500px;
    top: -200px;
    left: -200px;
}

.login-page::after {
    width: 400px;
    height: 400px;
    bottom: -150px;
    right: -150px;
}

.login-box {
    background: white;
    border-radius: var(--radius-xl);
    padding: 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-xl);
    position: relative;
    z-index: 1;
}

.login-logo {
    width: 72px;
    height: 72px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 32px;
    font-weight: 900;
}

.login-title {
    text-align: center;
    font-size: 24px;
    font-weight: 800;
    color: var(--gray-900);
    margin-bottom: 6px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 30px;
    font-size: 14px;
}
