:root {
    --primary: #2ecc71;
    --secondary: #3498db;
    --accent: #e67e22;
    --danger: #e74c3c;
    --warning: #f1c40f;
    --dark: #2c3e50;
    --light: #f4f7f6;
    --white: #ffffff;
    --shadow: 0 4px 15px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', 'Cairo', Tahoma, Geneva, Verdana, sans-serif; }
body { background: var(--light); color: var(--dark); line-height: 1.6; direction: rtl; min-height: 100vh; padding: 20px; }
.container { max-width: 1000px; margin: 0 auto; }

/* Header */
.header { background: linear-gradient(135deg, var(--primary), var(--secondary)); color: var(--white); padding: 40px 20px; border-radius: 15px; margin-bottom: 30px; text-align: center; display: flex; justify-content: space-between; align-items: center; box-shadow: var(--shadow); }
.header-content { flex: 1; }
.header h1 { font-size: 2.2rem; margin-bottom: 10px; }
.header p { opacity: 0.9; font-size: 1.1rem; }
.header-buttons { display: flex; gap: 10px; }
.header-buttons .btn { margin: 0; }

/* Sections */
.form-section { background: var(--white); padding: 30px; border-radius: 15px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); display: none; margin-bottom: 20px; }
.form-section.active { display: block; animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.section-header { margin-bottom: 25px; border-bottom: 2px solid var(--primary); padding-bottom: 10px; }
.section-header h2 { color: var(--primary); font-size: 1.8rem; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-bottom: 30px; }
.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group label { font-weight: 600; color: var(--dark); font-size: 0.95rem; }
.form-group input, .form-group select, .form-group textarea { padding: 12px; border: 2px solid #eee; border-radius: 8px; font-size: 1rem; transition: all 0.3s; background: #fafafa; }
.form-group input:focus, .form-group select:focus { border-color: var(--secondary); outline: none; background: white; }
.full-width { grid-column: 1 / -1; }

/* Calorie Cards */
.calories-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 30px; }
.calorie-card { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 25px; border-radius: 12px; text-align: center; box-shadow: var(--shadow); }
.calorie-card h3 { font-size: 1.1rem; margin-bottom: 10px; opacity: 0.9; }
.calorie-value { font-size: 2.5rem; font-weight: bold; margin: 10px 0; }
.calorie-card p { font-size: 0.9rem; opacity: 0.8; }

/* Macros Grid */
.macros-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 15px; margin-bottom: 30px; }
.macro-card { background: #f8f9fa; padding: 20px; border-radius: 10px; text-align: center; border-left: 4px solid var(--secondary); }
.macro-card h4 { font-size: 1rem; margin-bottom: 10px; color: var(--dark); }
.macro-value { font-size: 2rem; font-weight: bold; color: var(--secondary); margin: 10px 0; }
.macro-card p { font-size: 0.85rem; color: #777; }

/* Meal Planning */
.meal-setup { display: flex; gap: 15px; align-items: center; margin-bottom: 25px; }
.meal-setup label { font-weight: 600; }
.meal-setup select { padding: 10px 15px; border: 2px solid var(--secondary); border-radius: 8px; font-size: 1rem; min-width: 200px; }

.meal-section { background: #f8f9fa; padding: 20px; border-radius: 12px; margin-bottom: 20px; border-left: 5px solid var(--secondary); }
.meal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 2px solid #eee; }
.meal-title { color: var(--dark); font-size: 1.2rem; }
.meal-calories { background: var(--secondary); color: white; padding: 8px 15px; border-radius: 20px; font-weight: bold; }

.meal-items-container { margin-bottom: 15px; }
.meal-item { display: grid; grid-template-columns: 2fr 1fr 1fr auto auto; gap: 10px; align-items: center; margin-bottom: 12px; padding: 12px; background: white; border-radius: 8px; border: 1px solid #eee; }
.food-name-input, .unit-input, .grams-input, .custom-unit, .custom-quantity { padding: 8px; border: 1px solid #ddd; border-radius: 6px; font-size: 0.9rem; }
.item-stats { display: flex; gap: 8px; font-size: 0.85rem; font-weight: 600; }
.stat-cal, .stat-prot, .stat-carb, .stat-fat { background: #f0f0f0; padding: 4px 8px; border-radius: 4px; }
.btn-remove { background: var(--danger); color: white; border: none; padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 1.2rem; transition: all 0.3s; }
.btn-remove:hover { background: #c0392b; transform: scale(1.1); }

.custom-item { grid-template-columns: 1fr; }
.custom-inputs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.custom-inputs input { padding: 8px; border: 1px solid #ddd; border-radius: 6px; }

.meal-actions { display: flex; gap: 10px; }

/* Status Section */
.status-section { background: #f0f8ff; padding: 20px; border-radius: 12px; margin-top: 25px; border: 2px solid var(--secondary); }
.status-alert { padding: 15px; border-radius: 8px; margin-bottom: 20px; font-weight: 600; text-align: center; }
.status-alert.success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.status-alert.warning { background: #fff3cd; color: #856404; border: 1px solid #ffeaa7; }
.status-alert.danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; }
.status-item { background: white; padding: 15px; border-radius: 8px; border: 1px solid #eee; }
.status-item h4 { color: var(--dark); margin-bottom: 10px; font-size: 0.95rem; }
.progress-bar { background: #eee; height: 8px; border-radius: 4px; overflow: hidden; margin-bottom: 10px; }
.progress-fill { height: 100%; background: var(--secondary); width: 0%; transition: width 0.3s; }
.status-item p { font-size: 0.85rem; color: #666; }

/* Buttons */
.button-group { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 25px; }
.btn { padding: 12px 24px; border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.3s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #27ae60; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(46, 204, 113, 0.3); }
.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { background: #2980b9; }
.btn-success { background: #27ae60; color: white; }
.btn-success:hover { background: #229954; }
.btn-info { background: #3498db; color: white; }
.btn-info:hover { background: #2980b9; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c0392b; }
.btn-sm { padding: 8px 16px; font-size: 0.9rem; }

/* Summary */
.summary-card { background: #f8f9fa; padding: 20px; border-radius: 10px; margin-bottom: 15px; border-left: 4px solid var(--primary); }
.summary-card h4 { color: var(--primary); margin-bottom: 10px; }
.summary-card p { margin: 8px 0; }

/* Client Search */
.client-search { display: flex; gap: 10px; margin-bottom: 20px; }
.client-search input { flex: 1; padding: 12px; border: 2px solid var(--secondary); border-radius: 8px; font-size: 1rem; }
.client-card { background: #f8f9fa; padding: 20px; border-radius: 10px; margin-bottom: 15px; border-left: 4px solid var(--secondary); }
.client-card h3 { color: var(--dark); margin-bottom: 10px; }
.client-card p { margin: 8px 0; }

/* ============================
   PRINT STYLES - الأهم جداً
   ============================ */
@media print {
    /* إخفاء جميع العناصر غير المطلوبة */
    body { background: white; padding: 0; margin: 0; }
    .container { max-width: 100%; margin: 0; }
    .header, .button-group, .meal-actions, .meal-setup, .status-section, .section-header, 
    .calories-grid, .macros-grid, .meal-calories, .item-stats, .stat-cal, .stat-prot, .stat-carb, .stat-fat,
    .form-section:not(#step4) { display: none !important; }
    
    #step4 { display: block !important; padding: 0; box-shadow: none; margin-bottom: 0; }
    
    /* تنسيق رأس الطباعة */
    .print-header { 
        text-align: center; 
        margin-bottom: 20px; 
        border-bottom: 3px solid var(--primary); 
        padding-bottom: 15px; 
        page-break-after: avoid;
    }
    .print-logo { 
        font-size: 1.8rem; 
        font-weight: bold; 
        color: var(--primary); 
        margin-bottom: 10px; 
    }
    .print-header h1 { 
        font-size: 1.8rem; 
        color: var(--dark); 
        margin: 10px 0; 
    }
    .print-header p { 
        font-size: 0.95rem; 
        margin: 5px 0; 
        color: var(--dark);
    }
    
    /* تنسيق الجدول */
    .print-table { 
        width: 100%; 
        border-collapse: collapse; 
        margin: 20px 0; 
        page-break-inside: avoid;
    }
    .print-table th { 
        background: var(--primary); 
        color: white; 
        padding: 12px; 
        text-align: right; 
        font-weight: bold; 
        border: 1px solid #333;
    }
    .print-table td { 
        border: 1px solid #333; 
        padding: 12px; 
        text-align: right; 
        background: white;
    }
    .print-table tr:nth-child(even) { 
        background: #f8f9fa; 
    }
    .print-table tr:nth-child(odd) { 
        background: white; 
    }
    
    /* تنسيق صفوف الأصناف */
    .print-item-row { 
        display: flex; 
        justify-content: space-between; 
        margin: 5px 0; 
        padding: 5px 0; 
        border-bottom: 1px dotted #999; 
    }
    .print-item-row span:first-child { 
        font-weight: 600; 
        flex: 1;
    }
    .print-item-row span:last-child { 
        text-align: left; 
        font-weight: 500;
    }
    
    /* تنسيق العرض الخاص */
    .print-offer { 
        background: #fff3cd; 
        border: 2px solid var(--warning); 
        padding: 15px; 
        border-radius: 8px; 
        margin: 20px 0; 
        text-align: center; 
        font-weight: bold; 
        color: #856404; 
        page-break-inside: avoid;
    }
    
    /* تنسيق التذييل */
    .print-footer { 
        text-align: center; 
        margin-top: 30px; 
        padding-top: 20px; 
        border-top: 2px solid #ddd; 
        font-size: 0.9rem; 
        color: #666; 
    }
    
    /* إخفاء الحقول والأزرار */
    input, select, textarea, .btn, .btn-remove { display: none !important; }
    
    /* تحسين الطباعة */
    .meal-section { 
        page-break-inside: avoid; 
        margin-bottom: 15px; 
        border: 1px solid #ddd; 
        padding: 15px; 
        background: white;
    }
    .meal-header { 
        border-bottom: 1px solid #ddd; 
        margin-bottom: 10px; 
        display: block;
    }
    .meal-title { 
        display: inline-block; 
        font-weight: bold;
    }
    
    /* حجم الورقة */
    @page { 
        size: A4; 
        margin: 0.5cm; 
    }
}

/* Responsive */
@media (max-width: 768px) {
    .header { flex-direction: column; text-align: center; }
    .header-buttons { justify-content: center; width: 100%; margin-top: 15px; }
    .form-grid { grid-template-columns: 1fr; }
    .meal-item { grid-template-columns: 1fr; }
    .custom-inputs { grid-template-columns: repeat(2, 1fr); }
    .button-group { flex-direction: column; }
    .btn { width: 100%; }
    .status-grid { grid-template-columns: 1fr; }
}

/* Animations */
@keyframes slideIn { from { transform: translateX(-20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.meal-section { animation: slideIn 0.3s ease; }
