/* Frontend CSS */
.cfm-frontend-dashboard {
    font-family: 'IRANSans', 'Tahoma', sans-serif;
    direction: rtl;
    background: #f5f5f5;
    min-height: 100vh;
    text-align: right;
}

/* Main container for frontend */
.cfm-frontend-dashboard .wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    direction: rtl;
    text-align: right;
}

.cfm-nav-tabs {
    display: flex;
    background: #fff;
    border-bottom: 2px solid #e0e0e0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    direction: rtl;
    justify-content: flex-start;
}

.cfm-nav-tab {
    padding: 15px 25px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
    font-family: 'IRANSans', 'Tahoma', sans-serif;
}

.cfm-nav-tab:hover {
    background: #f0f8ff;
    color: #2196F3;
}

.cfm-nav-tab.active {
    color: #2196F3;
    border-bottom-color: #2196F3;
    background: #f0f8ff;
}

.cfm-tab-content {
    padding: 20px;
    direction: rtl;
    text-align: right;
}

.cfm-tab {
    display: none;
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    direction: rtl;
    text-align: right;
}

.cfm-tab.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

.cfm-dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
    margin-bottom: 30px;
    direction: rtl;
}

.cfm-stat-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
    direction: rtl;
}

.cfm-stat-card:hover {
    transform: translateY(-5px);
}

.cfm-stat-card h3 {
    margin: 0 0 10px 0;
    font-size: 18px;
    opacity: 0.9;
    font-weight: 500;
}

.cfm-stat-value {
    font-size: 36px;
    font-weight: bold;
    margin: 0;
    font-family: 'IRANSans', 'Tahoma', sans-serif;
}

.cfm-charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 25px;
    margin-bottom: 30px;
    direction: rtl;
}

.cfm-chart-container {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    direction: rtl;
    text-align: right;
}

.cfm-chart-container h3 {
    margin-top: 0;
    color: #333;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 10px;
    font-size: 20px;
    font-weight: 600;
}

.cfm-form {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    direction: rtl;
    text-align: right;
}

.cfm-form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
    margin-bottom: 20px;
    direction: rtl;
}

.cfm-form-group {
    display: flex;
    flex-direction: column;
    direction: rtl;
    text-align: right;
}

.cfm-form-group label {
    margin-bottom: 5px;
    font-weight: bold;
    color: #333;
    text-align: right;
    direction: rtl;
}

.cfm-form input,
.cfm-form select,
.cfm-form textarea {
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    font-size: 14px;
    transition: border-color 0.3s ease;
    direction: rtl;
    text-align: right;
    font-family: 'IRANSans', 'Tahoma', sans-serif;
}

.cfm-form input:focus,
.cfm-form select:focus,
.cfm-form textarea:focus {
    outline: none;
    border-color: #2196F3;
    box-shadow: 0 0 5px rgba(33, 150, 243, 0.3);
}

.cfm-items-section {
    margin: 20px 0;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 8px;
    direction: rtl;
    text-align: right;
}

.cfm-items-section h3 {
    margin-top: 0;
    color: #333;
    font-size: 18px;
    font-weight: 600;
}

.cfm-items-header {
    display: grid;
    grid-template-columns: 2fr 1.5fr 1fr 1fr 1fr 120px;
    gap: 10px;
    padding: 10px;
    background: #e0e0e0;
    border-radius: 5px;
    font-weight: bold;
    margin-bottom: 10px;
    direction: rtl;
    text-align: right;
}

.cfm-item-row,
.cfm-purchase-item-row {
    display: grid;
    grid-template-columns: 2fr 1.5fr 1fr 1fr 1fr 120px;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
    direction: rtl;
}

.cfm-btn-primary,
.cfm-btn-secondary {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    font-family: 'IRANSans', 'Tahoma', sans-serif;
}

.cfm-btn-primary {
    background: linear-gradient(135deg, #2196F3, #1976D2);
    color: white;
}

.cfm-btn-primary:hover {
    background: linear-gradient(135deg, #1976D2, #1565C0);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.cfm-btn-secondary {
    background: linear-gradient(135deg, #FF9800, #F57C00);
    color: white;
}

.cfm-btn-secondary:hover {
    background: linear-gradient(135deg, #F57C00, #E65100);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.cfm-remove-item {
    background: #f44336;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
}

.cfm-remove-item:hover {
    background: #d32f2f;
}

.cfm-total-section {
    text-align: center;
    padding: 20px;
    background: #e8f5e8;
    border-radius: 8px;
    margin: 20px 0;
    direction: rtl;
    text-align: center;
}

.cfm-total-section h3 {
    margin: 0;
    color: #2e7d32;
    font-size: 20px;
    font-family: 'IRANSans', 'Tahoma', sans-serif;
}

.cfm-form-actions {
    text-align: center;
    padding-top: 20px;
    border-top: 2px solid #e0e0e0;
    direction: rtl;
}

.cfm-settings-tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
    direction: rtl;
    justify-content: flex-start;
}

.cfm-settings-tab {
    padding: 10px 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 2px solid transparent;
    font-family: 'IRANSans', 'Tahoma', sans-serif;
}

.cfm-settings-tab.active {
    color: #2196F3;
    border-bottom-color: #2196F3;
}

.cfm-reports-filters {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    direction: rtl;
    text-align: right;
}

#reports-table {
    overflow-x: auto;
    direction: rtl;
}

.cfm-reports-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    direction: rtl;
}

.cfm-reports-table th,
.cfm-reports-table td {
    padding: 12px;
    text-align: right;
    border-bottom: 1px solid #e0e0e0;
    font-family: 'IRANSans', 'Tahoma', sans-serif;
}

.cfm-reports-table th {
    background: #f5f5f5;
    font-weight: bold;
    color: #333;
}

.cfm-reports-table tbody tr:hover {
    background: #f0f8ff;
}

/* Improved responsive design */
/* Responsive Design */
@media (max-width: 768px) {
    .cfm-frontend-dashboard .wrap {
        padding: 10px;
    }
    
    .cfm-nav-tabs {
        flex-wrap: wrap;
    }
    
    .cfm-nav-tab {
        flex: 1;
        min-width: 120px;
        text-align: center;
        font-size: 14px;
        padding: 12px 15px;
    }
    
    .cfm-dashboard-stats {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .cfm-charts-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .cfm-form-row {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .cfm-items-header,
    .cfm-item-row,
    .cfm-purchase-item-row {
        display: flex;
        flex-direction: column;
        gap: 5px;
    }
    
    .cfm-settings-tabs {
        flex-wrap: wrap;
    }
    
    .cfm-stat-value {
        font-size: 28px;
    }
    
    .cfm-chart-container h3 {
        font-size: 18px;
    }
}

/* Loading and Success Messages */
.cfm-loading {
    text-align: center;
    padding: 20px;
    direction: rtl;
}

.cfm-loading p {
    margin-top: 10px;
    color: #666;
    font-size: 14px;
}

.cfm-spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #2196F3;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

.cfm-loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #2196F3;
    border-radius: 50%;
    display: inline-block;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.cfm-message {
    padding: 10px 15px;
    border-radius: 5px;
    margin: 10px 0;
}

.cfm-message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.cfm-message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Additional RTL improvements */
.cfm-frontend-dashboard * {
    box-sizing: border-box;
}

/* Ensure proper text direction for mixed content */
.cfm-frontend-dashboard .ltr {
    direction: ltr;
    text-align: left;
}

.cfm-frontend-dashboard .rtl {
    direction: rtl;
    text-align: right;
}

/* Date Format Validation Styles */
.cfm-form input.is-invalid,
.cfm-form select.is-invalid,
.cfm-form textarea.is-invalid,
input.is-invalid,
select.is-invalid,
textarea.is-invalid {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 0.25rem rgba(220, 53, 69, 0.25) !important;
    background-color: #fff5f5;
}

/* Jalali DatePicker Styles */
.ui-datepicker {
    direction: rtl !important;
    text-align: right !important;
    font-family: 'IRANSans', 'Tahoma', sans-serif !important;
    z-index: 99999 !important;
}

.ui-datepicker .ui-datepicker-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
    border: none !important;
}

.ui-datepicker .ui-datepicker-title {
    color: white !important;
    font-weight: bold !important;
}

.ui-datepicker .ui-datepicker-prev,
.ui-datepicker .ui-datepicker-next {
    background: rgba(255,255,255,0.2) !important;
    border: none !important;
    border-radius: 50% !important;
}

.ui-datepicker .ui-datepicker-prev:hover,
.ui-datepicker .ui-datepicker-next:hover {
    background: rgba(255,255,255,0.3) !important;
}

.ui-datepicker td {
    text-align: center !important;
}

.ui-datepicker .ui-state-default {
    border: none !important;
    background: transparent !important;
    color: #333 !important;
}

.ui-datepicker .ui-state-hover {
    background: #e3f2fd !important;
    color: #1976d2 !important;
}

.ui-datepicker .ui-state-active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
}

.cfm-field-error-message {
    color: #dc3545;
    font-size: 0.85em;
    margin-top: 5px;
    display: block;
    font-weight: 500;
    direction: rtl;
    text-align: right;
}

.cfm-form-error-message {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    padding: 12px 16px;
    margin-bottom: 20px;
    font-weight: 500;
    direction: rtl;
    text-align: right;
}

/* Animation for error messages */
.cfm-field-error-message,
.cfm-form-error-message {
    animation: fadeInError 0.3s ease-in;
}

@keyframes fadeInError {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Modal Styles for Frontend */
.cfm-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999999;
    display: none;
    justify-content: center;
    align-items: center;
}

.cfm-modal {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    direction: rtl;
    text-align: right;
}

.cfm-modal-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px 8px 0 0;
}

.cfm-modal-header h3 {
    margin: 0;
    color: white;
    font-size: 18px;
}

.cfm-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: white;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.cfm-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.cfm-modal-body {
    padding: 20px;
}

.cfm-modal-footer {
    padding: 20px;
    border-top: 1px solid #e0e0e0;
    text-align: left;
    direction: ltr;
    background: #f8f9fa;
    border-radius: 0 0 8px 8px;
}

.cfm-modal-footer .cfm-btn-primary,
.cfm-modal-footer .cfm-btn-secondary {
    margin-left: 10px;
}

/* Actions column styling */
.cfm-actions-column {
    white-space: nowrap;
}

.cfm-actions-column .cfm-btn-primary,
.cfm-actions-column .cfm-btn-danger {
    margin-left: 5px;
    padding: 4px 8px;
    font-size: 12px;
}

.cfm-btn-danger {
    background: linear-gradient(135deg, #f44336, #d32f2f);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cfm-btn-danger:hover {
    background: linear-gradient(135deg, #d32f2f, #b71c1c);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Responsive modal */
@media (max-width: 768px) {
    .cfm-modal {
        width: 95%;
        max-height: 90vh;
    }
    
    .cfm-modal-header,
    .cfm-modal-body,
    .cfm-modal-footer {
        padding: 15px;
    }
    
    .cfm-form-row {
        grid-template-columns: 1fr;
    }
    
    .cfm-actions-column .cfm-btn-primary,
    .cfm-actions-column .cfm-btn-danger {
        display: block;
        margin: 2px 0;
        width: 100%;
    }
}

/* Ensure error messages are visible in all form contexts */
.cfm-form-group {
    position: relative;
}

.cfm-form-group .cfm-field-error-message {
    margin-top: 8px;
    margin-bottom: 0;
}