/* =========================================
   1. المتغيرات ونظام الألوان (Final, Polished Palette)
   ========================================= */
:root {
    /* Base Colors */
    --primary-color: #991b1b;       /* أحمر داكن (للقرارات والأكشن) */
    --primary-hover: #7f1d1d;
    --accent-color: #fbbf24;        /* ذهبي/برتقالي (للتركيز والحيوية) */
    --secondary-btn: #3b82f6;       /* أزرق ثانوي لزر 'عرض الخطط' */
    --secondary-btn-hover: #2563eb;
    --data-btn: #475569;            /* سُكني للبيانات الخام */
    
    /* Utility Colors */
    --bg-color: #f7f7f9;            /* خلفية ناعمة للصفحة */
    --card-bg: #ffffff;             /* خلفية البطاقات */
    --text-primary: #1e293b;        /* نص أساسي غامق */
    --text-secondary: #64748b;      /* نص ثانوي للشروحات */
    --border-color: #e2e8f0;        /* حدود خفيفة */
    --input-bg: #ffffff;            
    --danger-color: #ef4444;
    --success-color: #10b981;
    
    /* Spacing & Typography */
    --radius: 12px;
    --spacing-unit: 20px;
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.08); /* ظل واضح وناعم */
    --font-family: 'Almarai', sans-serif;
}

/* =========================================
   2. التأسيس والخطوط (Base & Typography)
   ========================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    direction: rtl;
    line-height: 1.7;
    padding: 30px 20px 60px; /* زيادة المساحة السفلية */
}

.container { max-width: 900px; margin: 0 auto; }

header { text-align: center; margin-bottom: 50px; }

.badge { 
    background-color: var(--accent-color); color: var(--text-primary); 
    padding: 6px 18px; border-radius: 20px; 
    font-size: 0.9rem; font-weight: 800; 
    margin-bottom: 15px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

header h1 { color: var(--primary-color); font-size: 2.5rem; margin-bottom: 5px; font-weight: 800; }
header p { color: var(--text-secondary); font-size: 1.1rem; }

/* =========================================
   3. البطاقات (Form Sections)
   ========================================= */
.form-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 35px;
    margin-bottom: var(--spacing-unit);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
}

.form-section:hover {
    transform: translateY(-4px); 
    box-shadow: var(--shadow-md);
}

.form-section h3 {
    font-size: 1.35rem; /* حجم خط أوضح */
    color: var(--primary-color);
    margin-bottom: 25px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
    font-weight: 800;
}

/* =========================================
   4. الإدخال والتفاعل
   ========================================= */
.form-group { margin-bottom: 25px; }

label { display: block; font-weight: 700; margin-bottom: 8px; color: var(--text-primary); font-size: 1rem; }
.sub-label { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 8px; margin-top: -4px; }

input, textarea, [list] {
    width: 100%; padding: 14px 18px; background-color: var(--input-bg);
    border: 2px solid var(--border-color); border-radius: var(--radius);
    font-family: var(--font-family); font-size: 1rem; color: var(--text-primary);
    transition: all 0.3s ease;
}

textarea { min-height: 100px; }

input:focus, textarea:focus, [list]:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.35); /* توهج ذهبي نقي */
}

/* Grids */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; gap: 20px; } }

/* Dynamic Rows */
.competitor-row { display: grid; grid-template-columns: 1.5fr 2fr auto; gap: 10px; margin-bottom: 10px; }

.btn-remove { 
    background: #fef2f2; color: var(--primary-color); border: 1px solid #fca5a5;
    border-radius: var(--radius); width: 42px; cursor: pointer; font-size: 1.2rem; 
    transition: all 0.2s;
}

.btn-remove:hover { 
    background: #fee2e2; 
    transform: scale(1.05);
}

/* =========================================
   5. منطقة إدارة المشاريع (Management Area)
   ========================================= */

.management-area {
    margin-bottom: 35px; padding: 25px; background: var(--card-bg);
    border-radius: var(--radius); border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.btn-secondary {
    background-color: var(--secondary-btn);
    color: white;
    font-family: var(--font-family);
    font-weight: 700;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius);
    width: 100%;
}

.btn-secondary:hover {
    background-color: var(--secondary-btn-hover);
    transform: translateY(-2px);
}

#plansList { border-top: 1px solid var(--border-color); padding-top: 20px; margin-top: 20px; }

.plan-card {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px; margin-bottom: 12px; background: #f8f8fa;
    border-radius: var(--radius); border: 1px solid #e2e8f0;
    border-right: 4px solid var(--accent-color);
}

.plan-actions button {
    margin-left: 10px; padding: 8px 12px; border-radius: 6px; 
    font-size: 0.85rem; font-weight: 700; cursor: pointer; border: none;
    transition: all 0.2s;
}

.btn-load { background: var(--success-color); color: white; }
.btn-delete { background: var(--danger-color); color: white; }

/* =========================================
   6. الأزرار النهائية والتنزيل (Main Actions)
   ========================================= */
.actions { margin-top: 40px; text-align: center; }

.btn-primary {
    background-color: var(--primary-color); color: white;
    font-family: var(--font-family); font-weight: 800;
    font-size: 1.15rem; padding: 18px 50px; border: none;
    border-radius: var(--radius); cursor: pointer;
    box-shadow: 0 4px 8px rgba(153, 27, 27, 0.4);
    transition: all 0.3s;
    width: 100%; max-width: 450px;
}
.btn-primary:hover { 
    background-color: var(--primary-hover); 
    transform: translateY(-4px); 
    box-shadow: 0 14px 20px rgba(153, 27, 27, 0.5); /* ظل واضح */
}

.download-buttons { display: flex; gap: 15px; justify-content: flex-end; }

.btn-small {
    font-weight: bold; font-size: 0.95rem; padding: 10px 20px; border: none; 
    border-radius: var(--radius); cursor: pointer; transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-pdf { background: var(--primary-color); color: white; }
.btn-json { background: var(--accent-color); color: var(--text-primary); }

.btn-data {
    background: var(--data-btn); /* سُكني للبيانات الخام */
    color: white;
}
.btn-data:hover {
    background: var(--data-btn-hover);
    transform: translateY(-1px);
}

/* =========================================
   7. المرافق والـ Markdown
   ========================================= */
#resultsArea { 
    background: white; padding: 40px; border-radius: var(--radius); 
    border: 1px solid var(--border-color); box-shadow: var(--shadow-md); 
    margin-top: 40px;
}
.markdown-body h3 { color: var(--accent-color); font-size: 1.4rem; margin-top: 25px; margin-bottom: 15px; border-right: 4px solid var(--accent-color); padding-right: 10px; }
.markdown-body strong { color: var(--primary-color); font-weight: 800; }
.hidden { display: none !important; }

.spinner {
    width: 40px; height: 40px; border: 4px solid #e2e8f0; border-top: 4px solid var(--primary-color); 
    border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 15px;
}
@keyframes spin { to { transform: rotate(360deg); } }