/* =========================================
   1. GLOBAL & LAYOUT
   ========================================= */
.crm-calc-wrapper, .crm-calc-wrapper-front {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: #444;
    background: #f8f9fa; /* خلفية رمادية فاتحة جداً لكامل الصفحة */
    padding: 20px;
    border-radius: 8px;
}

/* Modern Tabs Styling */
.nav-tab-wrapper {
    border-bottom: 1px solid #e0e0e0 !important;
    margin-bottom: 20px !important;
}
.nav-tab {
    border: none !important;
    background: transparent !important;
    color: #7f8c8d !important;
    font-weight: 600 !important;
    padding: 10px 20px !important;
    font-size: 15px !important;
    transition: all 0.2s;
}
.nav-tab:hover {
    color: #3498db !important;
}
.nav-tab-active {
    color: #2c3e50 !important;
    border-bottom: 3px solid #3498db !important; /* خط أزرق تحت النشط */
    background: transparent !important;
}

/* =========================================
   2. STATS DASHBOARD - "The KPI Cards"
   ========================================= */
.crm-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: #fff;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.02);
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
}

.stat-info h3 {
    margin: 0 0 5px;
    font-size: 14px;
    text-transform: uppercase;
    color: #95a5a6;
    letter-spacing: 1px;
}

.stat-number {
    margin: 0;
    font-size: 36px;
    font-weight: 800;
    color: #2c3e50;
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #fff;
}

/* ألوان البطاقات */
.card-blue .stat-icon { background: linear-gradient(135deg, #3498db, #2980b9); box-shadow: 0 4px 10px rgba(52, 152, 219, 0.3); }
.card-green .stat-icon { background: linear-gradient(135deg, #2ecc71, #27ae60); box-shadow: 0 4px 10px rgba(46, 204, 113, 0.3); }
.card-purple .stat-icon { background: linear-gradient(135deg, #9b59b6, #8e44ad); box-shadow: 0 4px 10px rgba(155, 89, 182, 0.3); }

/* Chart Container */
.crm-chart-container {
    background: #fff;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}
.crm-chart-container h3 { margin-bottom: 20px; color: #34495e; }

/* =========================================
   3. RULES EDITOR - "Logical Flow"
   ========================================= */
#rules_wrapper {
    background: #fff;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.rule-item {
    background: #f8fbfd;
    border: 1px solid #e1eef5;
    border-left: 5px solid #3498db; /* الخط الأزرق الجانبي */
    border-radius: 6px;
    padding: 20px;
    margin-bottom: 15px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px;
    transition: background 0.2s;
}

.rule-item:hover {
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.rule-item label {
    font-weight: 600;
    color: #555;
    font-size: 13px;
}

.rule-item input[type="number"], .rule-item input[type="text"] {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 8px;
    color: #333;
}
.rule-item input[type="number"] { width: 70px; text-align: center; font-weight: bold; }
.rule-item input[type="text"] { flex-grow: 1; min-width: 200px; }

/* =========================================
   4. MATRIX EDITOR - FIX (Space & Width)
   ========================================= */

/* 1. إخفاء أسهم الأرقام المزعجة (Spinners) لتوفير المساحة */
/* Chrome, Safari, Edge, Opera */
.tiny-input::-webkit-outer-spin-button,
.tiny-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
/* Firefox */
.tiny-input {
  -moz-appearance: textfield;
}

.matrix-editor-container {
    background: #fff;
    border-radius: 8px;
    padding: 10px;
    overflow-x: auto; /* السماح بالتمرير الأفقي */
}

.matrix-table { 
    border-spacing: 0; 
    border-collapse: separate; 
}

/* 2. إجبار الأعمدة على عرض كافٍ (Minimum Width) */
.matrix-table th, .matrix-table td {
    min-width: 60px; /* هذا هو السر: عرض أدنى ثابت لكل عمود */
    padding: 2px;    /* تقليل الحواشي */
    text-align: center;
    border-bottom: 1px solid #f1f1f1;
    border-right: 1px dashed #eee;
}

/* 3. تنسيق حقل الإدخال ليملأ المساحة بالكامل */
.tiny-input {
    width: 100% !important; /* يملأ الـ 60px كاملة */
    height: 34px;
    border: 1px solid #ddd !important;
    background: #fff !important;
    color: #000 !important;
    border-radius: 0; /* إلغاء الدوران لتوفير مساحة بصرية */
    text-align: center;
    font-weight: 700;
    font-size: 16px; /* خط كبير وواضح */
    padding: 0;      /* إلغاء الحشوة الداخلية */
}

/* تأثير التركيز */
.tiny-input:focus {
    background: #e3f2fd !important;
    border: 2px solid #2980b9 !important;
    outline: none;
    z-index: 10;
}

/* تنسيقات الرؤوس (كما هي للألوان) */
.matrix-table th { font-size: 13px; font-weight: bold; }
.matrix-table thead th { background: linear-gradient(180deg, #2c3e50 0%, #34495e 100%); color: #fff; position: sticky; top: 0; z-index: 100; }
.matrix-table .sticky-col { background: linear-gradient(90deg, #27ae60 0%, #2ecc71 100%); color: white; position: sticky; left: 0; z-index: 101; min-width: 50px; }
.matrix-table thead th:first-child { background: #2c3e50; z-index: 102; }

/* Crosshair Effect */
.hover-row { background-color: #fff9c4 !important; }
.hover-col { background-color: #fff9c4 !important; }

/* =========================================
   5. FRONTEND CALCULATOR
   ========================================= */
.crm-calc-wrapper-front { max-width: 650px; margin: 50px auto; background: transparent; padding: 0; }
.crm-calc-box { background: #ffffff; border-radius: 20px; padding: 50px 40px; box-shadow: 0 20px 60px rgba(0,0,0,0.08); border: 1px solid rgba(0,0,0,0.02); }
.input-group label { font-size: 18px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; }
.label-badge { font-size: 12px; padding: 4px 10px; border-radius: 20px; letter-spacing: 1px; font-weight: 700; }
.label-badge.verbal { background: #e8f5e9; color: #27ae60; }
.label-badge.quant { background: #e3f2fd; color: #2980b9; }
.range-wrap { display: flex; align-items: center; background: #f8f9fa; padding: 10px 15px; border-radius: 12px; border: 1px solid #eef2f5; }
.crm-range { flex: 1; margin-right: 15px; height: 6px; background: #e0e0e0; border-radius: 5px; outline: none; -webkit-appearance: none; }
.crm-range::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; background: #34495e; border-radius: 50%; cursor: grab; box-shadow: 0 2px 6px rgba(0,0,0,0.2); border: 2px solid #fff; }
.crm-number { width: 60px; border: none; background: transparent; font-size: 20px; font-weight: 800; color: #2c3e50; text-align: right; }
.button-primary-front { margin-top: 30px; width: 100%; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border: none; border-radius: 12px; font-size: 18px; font-weight: 700; cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 10px 20px rgba(118, 75, 162, 0.3); }
.button-primary-front:hover { transform: translateY(-3px); box-shadow: 0 15px 25px rgba(118, 75, 162, 0.4); }
.calc-result-container { margin-top: 40px; text-align: center; border-top: 2px dashed #eee; padding-top: 30px; display: none; }
.result-label { font-size: 13px; color: #aaa; letter-spacing: 2px; font-weight: bold; display: block; margin-bottom: 10px; }
.score-display { font-size: 80px; line-height: 1; font-weight: 900; margin-bottom: 20px; }
.suggestion-btn { display: inline-block; margin-top: 10px; margin-left: 10px; color: #3498db; text-decoration: none; font-weight: bold; border-bottom: 1px solid #3498db; }



/* تنسيق قائمة البحث الذكي */
.ui-autocomplete {
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 9999; /* لتظهر فوق كل شيء */
    padding: 0;
}

.ui-menu-item {
    list-style: none;
    padding: 0;
    margin: 0;
}

.ui-menu-item .ui-menu-item-wrapper {
    padding: 8px 12px;
    font-size: 13px;
    color: #444;
    cursor: pointer;
    border-bottom: 1px solid #f5f5f5;
    transition: background 0.1s;
}

.ui-menu-item .ui-menu-item-wrapper:hover,
.ui-menu-item .ui-menu-item-wrapper.ui-state-active {
    background: #eef7fc;
    color: #2980b9;
    border-left: 3px solid #3498db;
}

/* =========================================
   6. DYNAMIC INPUTS (Focus Editor)
   ========================================= */
.multi-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 3px;
}

.remove-sub-row {
    background: #e74c3c;
    color: #fff;
    border: none;
    border-radius: 3px;
    width: 20px;
    height: 20px;
    line-height: 18px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.remove-sub-row:hover {
    background: #c0392b;
}

.add-sub-row-btn {
    margin-top: 5px;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 3px;
    width: 100%;
    padding: 2px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}

.add-sub-row-btn:hover {
    background: #2ecc71;
}

/* تعديل بسيط ليتناسب مع الحقول المتعددة */
.matrix-table td {
    vertical-align: top;
    padding: 8px !important;
}